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 | |
Eilon Greenstein | 359d8b1 | 2009-02-12 08:38:25 +0000 | [diff] [blame^] | 53 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 54 | #include "bnx2x.h" |
| 55 | #include "bnx2x_init.h" |
| 56 | |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 57 | #define DRV_MODULE_VERSION "1.45.26" |
| 58 | #define DRV_MODULE_RELDATE "2009/01/26" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 59 | #define BNX2X_BC_VER 0x040200 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 60 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 61 | /* Time in jiffies before concluding the transmitter is hung */ |
| 62 | #define TX_TIMEOUT (5*HZ) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 63 | |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 64 | static char version[] __devinitdata = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 65 | "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 66 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 67 | |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 68 | MODULE_AUTHOR("Eliezer Tamir"); |
Eilon Greenstein | e47d7e6 | 2009-01-14 06:44:28 +0000 | [diff] [blame] | 69 | MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 70 | MODULE_LICENSE("GPL"); |
| 71 | MODULE_VERSION(DRV_MODULE_VERSION); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 72 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 73 | static int multi_mode = 1; |
| 74 | module_param(multi_mode, int, 0); |
| 75 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 76 | static int disable_tpa; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 77 | static int poll; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 78 | static int debug; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 79 | static int load_count[3]; /* 0-common, 1-port0, 2-port1 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 80 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 81 | module_param(disable_tpa, int, 0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 82 | |
| 83 | static int int_mode; |
| 84 | module_param(int_mode, int, 0); |
| 85 | MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)"); |
| 86 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 87 | module_param(poll, int, 0); |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 88 | |
| 89 | static int mrrs = -1; |
| 90 | module_param(mrrs, int, 0); |
| 91 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); |
| 92 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 93 | module_param(debug, int, 0); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 94 | MODULE_PARM_DESC(disable_tpa, "disable the TPA (LRO) feature"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 95 | MODULE_PARM_DESC(poll, "use polling (for debug)"); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 96 | MODULE_PARM_DESC(debug, "default debug msglevel"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 97 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 98 | static struct workqueue_struct *bnx2x_wq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 99 | |
| 100 | enum bnx2x_board_type { |
| 101 | BCM57710 = 0, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 102 | BCM57711 = 1, |
| 103 | BCM57711E = 2, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 106 | /* indexed by board_type, above */ |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 107 | static struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 108 | char *name; |
| 109 | } board_info[] __devinitdata = { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 110 | { "Broadcom NetXtreme II BCM57710 XGb" }, |
| 111 | { "Broadcom NetXtreme II BCM57711 XGb" }, |
| 112 | { "Broadcom NetXtreme II BCM57711E XGb" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 115 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 116 | static const struct pci_device_id bnx2x_pci_tbl[] = { |
| 117 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710, |
| 118 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57710 }, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 119 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711, |
| 120 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711 }, |
| 121 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E, |
| 122 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711E }, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 123 | { 0 } |
| 124 | }; |
| 125 | |
| 126 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); |
| 127 | |
| 128 | /**************************************************************************** |
| 129 | * General service functions |
| 130 | ****************************************************************************/ |
| 131 | |
| 132 | /* used only at init |
| 133 | * locking is done by mcp |
| 134 | */ |
| 135 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
| 136 | { |
| 137 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 138 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); |
| 139 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 140 | PCICFG_VENDOR_ID_OFFSET); |
| 141 | } |
| 142 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 143 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
| 144 | { |
| 145 | u32 val; |
| 146 | |
| 147 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 148 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); |
| 149 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 150 | PCICFG_VENDOR_ID_OFFSET); |
| 151 | |
| 152 | return val; |
| 153 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 154 | |
| 155 | static const u32 dmae_reg_go_c[] = { |
| 156 | DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3, |
| 157 | DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7, |
| 158 | DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11, |
| 159 | DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15 |
| 160 | }; |
| 161 | |
| 162 | /* copy command into DMAE command memory and set DMAE command go */ |
| 163 | static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, |
| 164 | int idx) |
| 165 | { |
| 166 | u32 cmd_offset; |
| 167 | int i; |
| 168 | |
| 169 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); |
| 170 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { |
| 171 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
| 172 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 173 | DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n", |
| 174 | idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 175 | } |
| 176 | REG_WR(bp, dmae_reg_go_c[idx], 1); |
| 177 | } |
| 178 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 179 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, |
| 180 | u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 181 | { |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 182 | struct dmae_command *dmae = &bp->init_dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 183 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 184 | int cnt = 200; |
| 185 | |
| 186 | if (!bp->dmae_ready) { |
| 187 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 188 | |
| 189 | DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)" |
| 190 | " using indirect\n", dst_addr, len32); |
| 191 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | mutex_lock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 196 | |
| 197 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 198 | |
| 199 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 200 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 201 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 202 | #ifdef __BIG_ENDIAN |
| 203 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 204 | #else |
| 205 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 206 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 207 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 208 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 209 | dmae->src_addr_lo = U64_LO(dma_addr); |
| 210 | dmae->src_addr_hi = U64_HI(dma_addr); |
| 211 | dmae->dst_addr_lo = dst_addr >> 2; |
| 212 | dmae->dst_addr_hi = 0; |
| 213 | dmae->len = len32; |
| 214 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 215 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 216 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 217 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 218 | DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 219 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 220 | "dst_addr [%x:%08x (%08x)]\n" |
| 221 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 222 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 223 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr, |
| 224 | dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 225 | 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] | 226 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 227 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 228 | |
| 229 | *wb_comp = 0; |
| 230 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 231 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 232 | |
| 233 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 234 | |
| 235 | while (*wb_comp != DMAE_COMP_VAL) { |
| 236 | DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp); |
| 237 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 238 | if (!cnt) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 239 | BNX2X_ERR("dmae timeout!\n"); |
| 240 | break; |
| 241 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 242 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 243 | /* adjust delay for emulation/FPGA */ |
| 244 | if (CHIP_REV_IS_SLOW(bp)) |
| 245 | msleep(100); |
| 246 | else |
| 247 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 248 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 249 | |
| 250 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 253 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 254 | { |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 255 | struct dmae_command *dmae = &bp->init_dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 256 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 257 | int cnt = 200; |
| 258 | |
| 259 | if (!bp->dmae_ready) { |
| 260 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 261 | int i; |
| 262 | |
| 263 | DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)" |
| 264 | " using indirect\n", src_addr, len32); |
| 265 | for (i = 0; i < len32; i++) |
| 266 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | mutex_lock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 271 | |
| 272 | memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4); |
| 273 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 274 | |
| 275 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 276 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 277 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 278 | #ifdef __BIG_ENDIAN |
| 279 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 280 | #else |
| 281 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 282 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 283 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 284 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 285 | dmae->src_addr_lo = src_addr >> 2; |
| 286 | dmae->src_addr_hi = 0; |
| 287 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); |
| 288 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); |
| 289 | dmae->len = len32; |
| 290 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 291 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 292 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 293 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 294 | DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 295 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 296 | "dst_addr [%x:%08x (%08x)]\n" |
| 297 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 298 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 299 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr, |
| 300 | dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 301 | |
| 302 | *wb_comp = 0; |
| 303 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 304 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 305 | |
| 306 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 307 | |
| 308 | while (*wb_comp != DMAE_COMP_VAL) { |
| 309 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 310 | if (!cnt) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 311 | BNX2X_ERR("dmae timeout!\n"); |
| 312 | break; |
| 313 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 314 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 315 | /* adjust delay for emulation/FPGA */ |
| 316 | if (CHIP_REV_IS_SLOW(bp)) |
| 317 | msleep(100); |
| 318 | else |
| 319 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 320 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 321 | 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] | 322 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 323 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 324 | |
| 325 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 326 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 327 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 328 | /* used only for slowpath so not inlined */ |
| 329 | static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo) |
| 330 | { |
| 331 | u32 wb_write[2]; |
| 332 | |
| 333 | wb_write[0] = val_hi; |
| 334 | wb_write[1] = val_lo; |
| 335 | REG_WR_DMAE(bp, reg, wb_write, 2); |
| 336 | } |
| 337 | |
| 338 | #ifdef USE_WB_RD |
| 339 | static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg) |
| 340 | { |
| 341 | u32 wb_data[2]; |
| 342 | |
| 343 | REG_RD_DMAE(bp, reg, wb_data, 2); |
| 344 | |
| 345 | return HILO_U64(wb_data[0], wb_data[1]); |
| 346 | } |
| 347 | #endif |
| 348 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 349 | static int bnx2x_mc_assert(struct bnx2x *bp) |
| 350 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 351 | char last_idx; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 352 | int i, rc = 0; |
| 353 | u32 row0, row1, row2, row3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 354 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 355 | /* XSTORM */ |
| 356 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + |
| 357 | XSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 358 | if (last_idx) |
| 359 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 360 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 361 | /* print the asserts */ |
| 362 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 363 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 364 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 365 | XSTORM_ASSERT_LIST_OFFSET(i)); |
| 366 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 367 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 368 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 369 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 370 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 371 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 372 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 373 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 374 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 375 | " 0x%08x 0x%08x 0x%08x\n", |
| 376 | i, row3, row2, row1, row0); |
| 377 | rc++; |
| 378 | } else { |
| 379 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 380 | } |
| 381 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 382 | |
| 383 | /* TSTORM */ |
| 384 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + |
| 385 | TSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 386 | if (last_idx) |
| 387 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 388 | |
| 389 | /* print the asserts */ |
| 390 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 391 | |
| 392 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 393 | TSTORM_ASSERT_LIST_OFFSET(i)); |
| 394 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 395 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 396 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 397 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 398 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 399 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 400 | |
| 401 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 402 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 403 | " 0x%08x 0x%08x 0x%08x\n", |
| 404 | i, row3, row2, row1, row0); |
| 405 | rc++; |
| 406 | } else { |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /* CSTORM */ |
| 412 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + |
| 413 | CSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 414 | if (last_idx) |
| 415 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 416 | |
| 417 | /* print the asserts */ |
| 418 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 419 | |
| 420 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 421 | CSTORM_ASSERT_LIST_OFFSET(i)); |
| 422 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 423 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 424 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 425 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 426 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 427 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 428 | |
| 429 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 430 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 431 | " 0x%08x 0x%08x 0x%08x\n", |
| 432 | i, row3, row2, row1, row0); |
| 433 | rc++; |
| 434 | } else { |
| 435 | break; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* USTORM */ |
| 440 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + |
| 441 | USTORM_ASSERT_LIST_INDEX_OFFSET); |
| 442 | if (last_idx) |
| 443 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 444 | |
| 445 | /* print the asserts */ |
| 446 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 447 | |
| 448 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 449 | USTORM_ASSERT_LIST_OFFSET(i)); |
| 450 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 451 | USTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 452 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 453 | USTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 454 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 455 | USTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 456 | |
| 457 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 458 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 459 | " 0x%08x 0x%08x 0x%08x\n", |
| 460 | i, row3, row2, row1, row0); |
| 461 | rc++; |
| 462 | } else { |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 467 | return rc; |
| 468 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 469 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 470 | static void bnx2x_fw_dump(struct bnx2x *bp) |
| 471 | { |
| 472 | u32 mark, offset; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 473 | __be32 data[9]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 474 | int word; |
| 475 | |
| 476 | mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 477 | mark = ((mark + 0x3) & ~0x3); |
| 478 | 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] | 479 | |
| 480 | for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) { |
| 481 | for (word = 0; word < 8; word++) |
| 482 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 483 | offset + 4*word)); |
| 484 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 485 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 486 | } |
| 487 | for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) { |
| 488 | for (word = 0; word < 8; word++) |
| 489 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 490 | offset + 4*word)); |
| 491 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 492 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 493 | } |
| 494 | printk("\n" KERN_ERR PFX "end of fw dump\n"); |
| 495 | } |
| 496 | |
| 497 | static void bnx2x_panic_dump(struct bnx2x *bp) |
| 498 | { |
| 499 | int i; |
| 500 | u16 j, start, end; |
| 501 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 502 | bp->stats_state = STATS_STATE_DISABLED; |
| 503 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 504 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 505 | BNX2X_ERR("begin crash dump -----------------\n"); |
| 506 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 507 | /* Indices */ |
| 508 | /* Common */ |
| 509 | BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)" |
| 510 | " def_t_idx(%u) def_att_idx(%u) attn_state(%u)" |
| 511 | " spq_prod_idx(%u)\n", |
| 512 | bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx, |
| 513 | bp->def_att_idx, bp->attn_state, bp->spq_prod_idx); |
| 514 | |
| 515 | /* Rx */ |
| 516 | for_each_rx_queue(bp, i) { |
| 517 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 518 | |
| 519 | BNX2X_ERR("queue[%d]: rx_bd_prod(%x) rx_bd_cons(%x)" |
| 520 | " *rx_bd_cons_sb(%x) rx_comp_prod(%x)" |
| 521 | " rx_comp_cons(%x) *rx_cons_sb(%x)\n", |
| 522 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
| 523 | le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod, |
| 524 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
| 525 | BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)" |
| 526 | " fp_u_idx(%x) *sb_u_idx(%x)\n", |
| 527 | fp->rx_sge_prod, fp->last_max_sge, |
| 528 | le16_to_cpu(fp->fp_u_idx), |
| 529 | fp->status_blk->u_status_block.status_block_index); |
| 530 | } |
| 531 | |
| 532 | /* Tx */ |
| 533 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 534 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 535 | struct eth_tx_db_data *hw_prods = fp->hw_tx_prods; |
| 536 | |
| 537 | BNX2X_ERR("queue[%d]: tx_pkt_prod(%x) tx_pkt_cons(%x)" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 538 | " 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] | 539 | 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] | 540 | fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb)); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 541 | BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)" |
| 542 | " bd data(%x,%x)\n", le16_to_cpu(fp->fp_c_idx), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 543 | fp->status_blk->c_status_block.status_block_index, |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 544 | hw_prods->packets_prod, hw_prods->bds_prod); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 545 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 546 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 547 | /* Rings */ |
| 548 | /* Rx */ |
| 549 | for_each_rx_queue(bp, i) { |
| 550 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 551 | |
| 552 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); |
| 553 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 554 | for (j = start; j != end; j = RX_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 555 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
| 556 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; |
| 557 | |
| 558 | BNX2X_ERR("rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 559 | j, rx_bd[1], rx_bd[0], sw_bd->skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 562 | start = RX_SGE(fp->rx_sge_prod); |
| 563 | end = RX_SGE(fp->last_max_sge); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 564 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 565 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
| 566 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; |
| 567 | |
| 568 | BNX2X_ERR("rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
| 569 | j, rx_sge[1], rx_sge[0], sw_page->page); |
| 570 | } |
| 571 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 572 | start = RCQ_BD(fp->rx_comp_cons - 10); |
| 573 | end = RCQ_BD(fp->rx_comp_cons + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 574 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 575 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
| 576 | |
| 577 | BNX2X_ERR("cqe[%x]=[%x:%x:%x:%x]\n", |
| 578 | j, cqe[0], cqe[1], cqe[2], cqe[3]); |
| 579 | } |
| 580 | } |
| 581 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 582 | /* Tx */ |
| 583 | for_each_tx_queue(bp, i) { |
| 584 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 585 | |
| 586 | start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10); |
| 587 | end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245); |
| 588 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 589 | struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j]; |
| 590 | |
| 591 | BNX2X_ERR("packet[%x]=[%p,%x]\n", j, |
| 592 | sw_bd->skb, sw_bd->first_bd); |
| 593 | } |
| 594 | |
| 595 | start = TX_BD(fp->tx_bd_cons - 10); |
| 596 | end = TX_BD(fp->tx_bd_cons + 254); |
| 597 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 598 | u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j]; |
| 599 | |
| 600 | BNX2X_ERR("tx_bd[%x]=[%x:%x:%x:%x]\n", |
| 601 | j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]); |
| 602 | } |
| 603 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 604 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 605 | bnx2x_fw_dump(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 606 | bnx2x_mc_assert(bp); |
| 607 | BNX2X_ERR("end crash dump -----------------\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 608 | } |
| 609 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 610 | static void bnx2x_int_enable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 611 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 612 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 613 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 614 | u32 val = REG_RD(bp, addr); |
| 615 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 616 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 617 | |
| 618 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 619 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 620 | HC_CONFIG_0_REG_INT_LINE_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 621 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 622 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 623 | } else if (msi) { |
| 624 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; |
| 625 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 626 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 627 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 628 | } else { |
| 629 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 630 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 631 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 632 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 633 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 634 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 635 | val, port, addr); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 636 | |
| 637 | REG_WR(bp, addr, val); |
| 638 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 639 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
| 640 | } |
| 641 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 642 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n", |
| 643 | val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 644 | |
| 645 | REG_WR(bp, addr, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 646 | |
| 647 | if (CHIP_IS_E1H(bp)) { |
| 648 | /* init leading/trailing edge */ |
| 649 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 650 | val = (0xee0f | (1 << (BP_E1HVN(bp) + 4))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 651 | if (bp->port.pmf) |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 652 | /* enable nig and gpio3 attention */ |
| 653 | val |= 0x1100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 654 | } else |
| 655 | val = 0xffff; |
| 656 | |
| 657 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 658 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
| 659 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 662 | static void bnx2x_int_disable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 663 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 664 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 665 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 666 | u32 val = REG_RD(bp, addr); |
| 667 | |
| 668 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 669 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 670 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 671 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
| 672 | |
| 673 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 674 | val, port, addr); |
| 675 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 676 | /* flush all outstanding writes */ |
| 677 | mmiowb(); |
| 678 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 679 | REG_WR(bp, addr, val); |
| 680 | if (REG_RD(bp, addr) != val) |
| 681 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); |
| 682 | } |
| 683 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 684 | static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 685 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 686 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 687 | int i, offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 688 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 689 | /* disable interrupt handling */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 690 | atomic_inc(&bp->intr_sem); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 691 | if (disable_hw) |
| 692 | /* prevent the HW from sending interrupts */ |
| 693 | bnx2x_int_disable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 694 | |
| 695 | /* make sure all ISRs are done */ |
| 696 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 697 | synchronize_irq(bp->msix_table[0].vector); |
| 698 | offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 699 | for_each_queue(bp, i) |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 700 | synchronize_irq(bp->msix_table[i + offset].vector); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 701 | } else |
| 702 | synchronize_irq(bp->pdev->irq); |
| 703 | |
| 704 | /* make sure sp_task is not running */ |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 705 | cancel_delayed_work(&bp->sp_task); |
| 706 | flush_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 707 | } |
| 708 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 709 | /* fast path */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 710 | |
| 711 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 712 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 713 | */ |
| 714 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 715 | static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 716 | u8 storm, u16 index, u8 op, u8 update) |
| 717 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 718 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 719 | COMMAND_REG_INT_ACK); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 720 | struct igu_ack_register igu_ack; |
| 721 | |
| 722 | igu_ack.status_block_index = index; |
| 723 | igu_ack.sb_id_and_flags = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 724 | ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 725 | (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) | |
| 726 | (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) | |
| 727 | (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT)); |
| 728 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 729 | DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n", |
| 730 | (*(u32 *)&igu_ack), hc_addr); |
| 731 | REG_WR(bp, hc_addr, (*(u32 *)&igu_ack)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp) |
| 735 | { |
| 736 | struct host_status_block *fpsb = fp->status_blk; |
| 737 | u16 rc = 0; |
| 738 | |
| 739 | barrier(); /* status block is written to by the chip */ |
| 740 | if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) { |
| 741 | fp->fp_c_idx = fpsb->c_status_block.status_block_index; |
| 742 | rc |= 1; |
| 743 | } |
| 744 | if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) { |
| 745 | fp->fp_u_idx = fpsb->u_status_block.status_block_index; |
| 746 | rc |= 2; |
| 747 | } |
| 748 | return rc; |
| 749 | } |
| 750 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 751 | static u16 bnx2x_ack_int(struct bnx2x *bp) |
| 752 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 753 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 754 | COMMAND_REG_SIMD_MASK); |
| 755 | u32 result = REG_RD(bp, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 756 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 757 | DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n", |
| 758 | result, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 759 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 760 | return result; |
| 761 | } |
| 762 | |
| 763 | |
| 764 | /* |
| 765 | * fast path service functions |
| 766 | */ |
| 767 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 768 | static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp) |
| 769 | { |
| 770 | u16 tx_cons_sb; |
| 771 | |
| 772 | /* Tell compiler that status block fields can change */ |
| 773 | barrier(); |
| 774 | tx_cons_sb = le16_to_cpu(*fp->tx_cons_sb); |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 775 | return (fp->tx_pkt_cons != tx_cons_sb); |
| 776 | } |
| 777 | |
| 778 | static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp) |
| 779 | { |
| 780 | /* Tell compiler that consumer and producer can change */ |
| 781 | barrier(); |
| 782 | return (fp->tx_pkt_prod != fp->tx_pkt_cons); |
| 783 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 786 | /* free skb in the packet ring at pos idx |
| 787 | * return idx of last bd freed |
| 788 | */ |
| 789 | static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 790 | u16 idx) |
| 791 | { |
| 792 | struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx]; |
| 793 | struct eth_tx_bd *tx_bd; |
| 794 | struct sk_buff *skb = tx_buf->skb; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 795 | u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 796 | int nbd; |
| 797 | |
| 798 | DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n", |
| 799 | idx, tx_buf, skb); |
| 800 | |
| 801 | /* unmap first bd */ |
| 802 | DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx); |
| 803 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 804 | pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_bd), |
| 805 | BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE); |
| 806 | |
| 807 | nbd = le16_to_cpu(tx_bd->nbd) - 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 808 | new_cons = nbd + tx_buf->first_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 809 | #ifdef BNX2X_STOP_ON_ERROR |
| 810 | if (nbd > (MAX_SKB_FRAGS + 2)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 811 | BNX2X_ERR("BAD nbd!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 812 | bnx2x_panic(); |
| 813 | } |
| 814 | #endif |
| 815 | |
| 816 | /* Skip a parse bd and the TSO split header bd |
| 817 | since they have no mapping */ |
| 818 | if (nbd) |
| 819 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 820 | |
| 821 | if (tx_bd->bd_flags.as_bitfield & (ETH_TX_BD_FLAGS_IP_CSUM | |
| 822 | ETH_TX_BD_FLAGS_TCP_CSUM | |
| 823 | ETH_TX_BD_FLAGS_SW_LSO)) { |
| 824 | if (--nbd) |
| 825 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 826 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 827 | /* is this a TSO split header bd? */ |
| 828 | if (tx_bd->bd_flags.as_bitfield & ETH_TX_BD_FLAGS_SW_LSO) { |
| 829 | if (--nbd) |
| 830 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /* now free frags */ |
| 835 | while (nbd > 0) { |
| 836 | |
| 837 | DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx); |
| 838 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 839 | pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_bd), |
| 840 | BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE); |
| 841 | if (--nbd) |
| 842 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 843 | } |
| 844 | |
| 845 | /* release skb */ |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 846 | WARN_ON(!skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 847 | dev_kfree_skb(skb); |
| 848 | tx_buf->first_bd = 0; |
| 849 | tx_buf->skb = NULL; |
| 850 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 851 | return new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 852 | } |
| 853 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 854 | static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 855 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 856 | s16 used; |
| 857 | u16 prod; |
| 858 | u16 cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 859 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 860 | barrier(); /* Tell compiler that prod and cons can change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 861 | prod = fp->tx_bd_prod; |
| 862 | cons = fp->tx_bd_cons; |
| 863 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 864 | /* NUM_TX_RINGS = number of "next-page" entries |
| 865 | It will be used as a threshold */ |
| 866 | used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 867 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 868 | #ifdef BNX2X_STOP_ON_ERROR |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 869 | WARN_ON(used < 0); |
| 870 | WARN_ON(used > fp->bp->tx_ring_size); |
| 871 | WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 872 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 873 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 874 | return (s16)(fp->bp->tx_ring_size) - used; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static void bnx2x_tx_int(struct bnx2x_fastpath *fp, int work) |
| 878 | { |
| 879 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 880 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 881 | u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons; |
| 882 | int done = 0; |
| 883 | |
| 884 | #ifdef BNX2X_STOP_ON_ERROR |
| 885 | if (unlikely(bp->panic)) |
| 886 | return; |
| 887 | #endif |
| 888 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 889 | txq = netdev_get_tx_queue(bp->dev, fp->index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 890 | hw_cons = le16_to_cpu(*fp->tx_cons_sb); |
| 891 | sw_cons = fp->tx_pkt_cons; |
| 892 | |
| 893 | while (sw_cons != hw_cons) { |
| 894 | u16 pkt_cons; |
| 895 | |
| 896 | pkt_cons = TX_BD(sw_cons); |
| 897 | |
| 898 | /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */ |
| 899 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 900 | 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] | 901 | hw_cons, sw_cons, pkt_cons); |
| 902 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 903 | /* if (NEXT_TX_IDX(sw_cons) != hw_cons) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 904 | rmb(); |
| 905 | prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb); |
| 906 | } |
| 907 | */ |
| 908 | bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons); |
| 909 | sw_cons++; |
| 910 | done++; |
| 911 | |
| 912 | if (done == work) |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | fp->tx_pkt_cons = sw_cons; |
| 917 | fp->tx_bd_cons = bd_cons; |
| 918 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 919 | /* Need to make the tx_bd_cons update visible to start_xmit() |
| 920 | * before checking for netif_tx_queue_stopped(). Without the |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 921 | * memory barrier, there is a small possibility that start_xmit() |
| 922 | * will miss it and cause the queue to be stopped forever. |
| 923 | */ |
| 924 | smp_mb(); |
| 925 | |
| 926 | /* TBD need a thresh? */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 927 | if (unlikely(netif_tx_queue_stopped(txq))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 928 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 929 | __netif_tx_lock(txq, smp_processor_id()); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 930 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 931 | if ((netif_tx_queue_stopped(txq)) && |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 932 | (bp->state == BNX2X_STATE_OPEN) && |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 933 | (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 934 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 935 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 936 | __netif_tx_unlock(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 940 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 941 | static void bnx2x_sp_event(struct bnx2x_fastpath *fp, |
| 942 | union eth_rx_cqe *rr_cqe) |
| 943 | { |
| 944 | struct bnx2x *bp = fp->bp; |
| 945 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 946 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 947 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 948 | DP(BNX2X_MSG_SP, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 949 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 950 | fp->index, cid, command, bp->state, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 951 | rr_cqe->ramrod_cqe.ramrod_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 952 | |
| 953 | bp->spq_left++; |
| 954 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 955 | if (fp->index) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 956 | switch (command | fp->state) { |
| 957 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP | |
| 958 | BNX2X_FP_STATE_OPENING): |
| 959 | DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", |
| 960 | cid); |
| 961 | fp->state = BNX2X_FP_STATE_OPEN; |
| 962 | break; |
| 963 | |
| 964 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING): |
| 965 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", |
| 966 | cid); |
| 967 | fp->state = BNX2X_FP_STATE_HALTED; |
| 968 | break; |
| 969 | |
| 970 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 971 | BNX2X_ERR("unexpected MC reply (%d) " |
| 972 | "fp->state is %x\n", command, fp->state); |
| 973 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 974 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 975 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 976 | return; |
| 977 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 978 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 979 | switch (command | bp->state) { |
| 980 | case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT): |
| 981 | DP(NETIF_MSG_IFUP, "got setup ramrod\n"); |
| 982 | bp->state = BNX2X_STATE_OPEN; |
| 983 | break; |
| 984 | |
| 985 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 986 | DP(NETIF_MSG_IFDOWN, "got halt ramrod\n"); |
| 987 | bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE; |
| 988 | fp->state = BNX2X_FP_STATE_HALTED; |
| 989 | break; |
| 990 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 991 | case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 992 | DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 993 | bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 994 | break; |
| 995 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 996 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 997 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 998 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG): |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 999 | DP(NETIF_MSG_IFUP, "got set mac ramrod\n"); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 1000 | bp->set_mac_pending = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1001 | break; |
| 1002 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1003 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1004 | DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n"); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1005 | break; |
| 1006 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1007 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1008 | BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1009 | command, bp->state); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1010 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1011 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1012 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1015 | static inline void bnx2x_free_rx_sge(struct bnx2x *bp, |
| 1016 | struct bnx2x_fastpath *fp, u16 index) |
| 1017 | { |
| 1018 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 1019 | struct page *page = sw_buf->page; |
| 1020 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 1021 | |
| 1022 | /* Skip "next page" elements */ |
| 1023 | if (!page) |
| 1024 | return; |
| 1025 | |
| 1026 | pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1027 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1028 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1029 | |
| 1030 | sw_buf->page = NULL; |
| 1031 | sge->addr_hi = 0; |
| 1032 | sge->addr_lo = 0; |
| 1033 | } |
| 1034 | |
| 1035 | static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp, |
| 1036 | struct bnx2x_fastpath *fp, int last) |
| 1037 | { |
| 1038 | int i; |
| 1039 | |
| 1040 | for (i = 0; i < last; i++) |
| 1041 | bnx2x_free_rx_sge(bp, fp, i); |
| 1042 | } |
| 1043 | |
| 1044 | static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp, |
| 1045 | struct bnx2x_fastpath *fp, u16 index) |
| 1046 | { |
| 1047 | struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT); |
| 1048 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 1049 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 1050 | dma_addr_t mapping; |
| 1051 | |
| 1052 | if (unlikely(page == NULL)) |
| 1053 | return -ENOMEM; |
| 1054 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1055 | 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] | 1056 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1057 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1058 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1059 | return -ENOMEM; |
| 1060 | } |
| 1061 | |
| 1062 | sw_buf->page = page; |
| 1063 | pci_unmap_addr_set(sw_buf, mapping, mapping); |
| 1064 | |
| 1065 | sge->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1066 | sge->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1067 | |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1071 | static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp, |
| 1072 | struct bnx2x_fastpath *fp, u16 index) |
| 1073 | { |
| 1074 | struct sk_buff *skb; |
| 1075 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index]; |
| 1076 | struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index]; |
| 1077 | dma_addr_t mapping; |
| 1078 | |
| 1079 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1080 | if (unlikely(skb == NULL)) |
| 1081 | return -ENOMEM; |
| 1082 | |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1083 | mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1084 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1085 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1086 | dev_kfree_skb(skb); |
| 1087 | return -ENOMEM; |
| 1088 | } |
| 1089 | |
| 1090 | rx_buf->skb = skb; |
| 1091 | pci_unmap_addr_set(rx_buf, mapping, mapping); |
| 1092 | |
| 1093 | rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1094 | rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | /* note that we are not allocating a new skb, |
| 1100 | * we are just moving one from cons to prod |
| 1101 | * we are not creating a new mapping, |
| 1102 | * so there is no need to check for dma_mapping_error(). |
| 1103 | */ |
| 1104 | static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp, |
| 1105 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1106 | { |
| 1107 | struct bnx2x *bp = fp->bp; |
| 1108 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1109 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1110 | struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons]; |
| 1111 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1112 | |
| 1113 | pci_dma_sync_single_for_device(bp->pdev, |
| 1114 | pci_unmap_addr(cons_rx_buf, mapping), |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 1115 | RX_COPY_THRESH, PCI_DMA_FROMDEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1116 | |
| 1117 | prod_rx_buf->skb = cons_rx_buf->skb; |
| 1118 | pci_unmap_addr_set(prod_rx_buf, mapping, |
| 1119 | pci_unmap_addr(cons_rx_buf, mapping)); |
| 1120 | *prod_bd = *cons_bd; |
| 1121 | } |
| 1122 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1123 | static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp, |
| 1124 | u16 idx) |
| 1125 | { |
| 1126 | u16 last_max = fp->last_max_sge; |
| 1127 | |
| 1128 | if (SUB_S16(idx, last_max) > 0) |
| 1129 | fp->last_max_sge = idx; |
| 1130 | } |
| 1131 | |
| 1132 | static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp) |
| 1133 | { |
| 1134 | int i, j; |
| 1135 | |
| 1136 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 1137 | int idx = RX_SGE_CNT * i - 1; |
| 1138 | |
| 1139 | for (j = 0; j < 2; j++) { |
| 1140 | SGE_MASK_CLEAR_BIT(fp, idx); |
| 1141 | idx--; |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp, |
| 1147 | struct eth_fast_path_rx_cqe *fp_cqe) |
| 1148 | { |
| 1149 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1150 | 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] | 1151 | le16_to_cpu(fp_cqe->len_on_bd)) >> |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1152 | SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1153 | u16 last_max, last_elem, first_elem; |
| 1154 | u16 delta = 0; |
| 1155 | u16 i; |
| 1156 | |
| 1157 | if (!sge_len) |
| 1158 | return; |
| 1159 | |
| 1160 | /* First mark all used pages */ |
| 1161 | for (i = 0; i < sge_len; i++) |
| 1162 | SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i]))); |
| 1163 | |
| 1164 | DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n", |
| 1165 | sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1166 | |
| 1167 | /* Here we assume that the last SGE index is the biggest */ |
| 1168 | prefetch((void *)(fp->sge_mask)); |
| 1169 | bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1170 | |
| 1171 | last_max = RX_SGE(fp->last_max_sge); |
| 1172 | last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT; |
| 1173 | first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT; |
| 1174 | |
| 1175 | /* If ring is not full */ |
| 1176 | if (last_elem + 1 != first_elem) |
| 1177 | last_elem++; |
| 1178 | |
| 1179 | /* Now update the prod */ |
| 1180 | for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) { |
| 1181 | if (likely(fp->sge_mask[i])) |
| 1182 | break; |
| 1183 | |
| 1184 | fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK; |
| 1185 | delta += RX_SGE_MASK_ELEM_SZ; |
| 1186 | } |
| 1187 | |
| 1188 | if (delta > 0) { |
| 1189 | fp->rx_sge_prod += delta; |
| 1190 | /* clear page-end entries */ |
| 1191 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1192 | } |
| 1193 | |
| 1194 | DP(NETIF_MSG_RX_STATUS, |
| 1195 | "fp->last_max_sge = %d fp->rx_sge_prod = %d\n", |
| 1196 | fp->last_max_sge, fp->rx_sge_prod); |
| 1197 | } |
| 1198 | |
| 1199 | static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp) |
| 1200 | { |
| 1201 | /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */ |
| 1202 | memset(fp->sge_mask, 0xff, |
| 1203 | (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64)); |
| 1204 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 1205 | /* Clear the two last indices in the page to 1: |
| 1206 | these are the indices that correspond to the "next" element, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1207 | hence will never be indicated and should be removed from |
| 1208 | the calculations. */ |
| 1209 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1210 | } |
| 1211 | |
| 1212 | static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue, |
| 1213 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1214 | { |
| 1215 | struct bnx2x *bp = fp->bp; |
| 1216 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1217 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1218 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1219 | dma_addr_t mapping; |
| 1220 | |
| 1221 | /* move empty skb from pool to prod and map it */ |
| 1222 | prod_rx_buf->skb = fp->tpa_pool[queue].skb; |
| 1223 | mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data, |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1224 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1225 | pci_unmap_addr_set(prod_rx_buf, mapping, mapping); |
| 1226 | |
| 1227 | /* move partial skb from cons to pool (don't unmap yet) */ |
| 1228 | fp->tpa_pool[queue] = *cons_rx_buf; |
| 1229 | |
| 1230 | /* mark bin state as start - print error if current state != stop */ |
| 1231 | if (fp->tpa_state[queue] != BNX2X_TPA_STOP) |
| 1232 | BNX2X_ERR("start of bin not in stop [%d]\n", queue); |
| 1233 | |
| 1234 | fp->tpa_state[queue] = BNX2X_TPA_START; |
| 1235 | |
| 1236 | /* point prod_bd to new skb */ |
| 1237 | prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1238 | prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1239 | |
| 1240 | #ifdef BNX2X_STOP_ON_ERROR |
| 1241 | fp->tpa_queue_used |= (1 << queue); |
| 1242 | #ifdef __powerpc64__ |
| 1243 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n", |
| 1244 | #else |
| 1245 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n", |
| 1246 | #endif |
| 1247 | fp->tpa_queue_used); |
| 1248 | #endif |
| 1249 | } |
| 1250 | |
| 1251 | static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1252 | struct sk_buff *skb, |
| 1253 | struct eth_fast_path_rx_cqe *fp_cqe, |
| 1254 | u16 cqe_idx) |
| 1255 | { |
| 1256 | struct sw_rx_page *rx_pg, old_rx_pg; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1257 | u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd); |
| 1258 | u32 i, frag_len, frag_size, pages; |
| 1259 | int err; |
| 1260 | int j; |
| 1261 | |
| 1262 | frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1263 | pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1264 | |
| 1265 | /* This is needed in order to enable forwarding support */ |
| 1266 | if (frag_size) |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1267 | skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1268 | max(frag_size, (u32)len_on_bd)); |
| 1269 | |
| 1270 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1271 | if (pages > |
| 1272 | 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] | 1273 | BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n", |
| 1274 | pages, cqe_idx); |
| 1275 | BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n", |
| 1276 | fp_cqe->pkt_len, len_on_bd); |
| 1277 | bnx2x_panic(); |
| 1278 | return -EINVAL; |
| 1279 | } |
| 1280 | #endif |
| 1281 | |
| 1282 | /* Run through the SGL and compose the fragmented skb */ |
| 1283 | for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) { |
| 1284 | u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j])); |
| 1285 | |
| 1286 | /* FW gives the indices of the SGE as if the ring is an array |
| 1287 | (meaning that "next" element will consume 2 indices) */ |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1288 | frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1289 | rx_pg = &fp->rx_page_ring[sge_idx]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1290 | old_rx_pg = *rx_pg; |
| 1291 | |
| 1292 | /* If we fail to allocate a substitute page, we simply stop |
| 1293 | where we are and drop the whole packet */ |
| 1294 | err = bnx2x_alloc_rx_sge(bp, fp, sge_idx); |
| 1295 | if (unlikely(err)) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1296 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1297 | return err; |
| 1298 | } |
| 1299 | |
| 1300 | /* Unmap the page as we r going to pass it to the stack */ |
| 1301 | pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1302 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | /* Add one frag and update the appropriate fields in the skb */ |
| 1305 | skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len); |
| 1306 | |
| 1307 | skb->data_len += frag_len; |
| 1308 | skb->truesize += frag_len; |
| 1309 | skb->len += frag_len; |
| 1310 | |
| 1311 | frag_size -= frag_len; |
| 1312 | } |
| 1313 | |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1318 | u16 queue, int pad, int len, union eth_rx_cqe *cqe, |
| 1319 | u16 cqe_idx) |
| 1320 | { |
| 1321 | struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue]; |
| 1322 | struct sk_buff *skb = rx_buf->skb; |
| 1323 | /* alloc new skb */ |
| 1324 | struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1325 | |
| 1326 | /* Unmap skb in the pool anyway, as we are going to change |
| 1327 | pool entry status to BNX2X_TPA_STOP even if new skb allocation |
| 1328 | fails. */ |
| 1329 | pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1330 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1331 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1332 | if (likely(new_skb)) { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1333 | /* fix ip xsum and give it to the stack */ |
| 1334 | /* (no need to map the new skb) */ |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1335 | #ifdef BCM_VLAN |
| 1336 | int is_vlan_cqe = |
| 1337 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1338 | PARSING_FLAGS_VLAN); |
| 1339 | int is_not_hwaccel_vlan_cqe = |
| 1340 | (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG))); |
| 1341 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | prefetch(skb); |
| 1344 | prefetch(((char *)(skb)) + 128); |
| 1345 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1346 | #ifdef BNX2X_STOP_ON_ERROR |
| 1347 | if (pad + len > bp->rx_buf_size) { |
| 1348 | BNX2X_ERR("skb_put is about to fail... " |
| 1349 | "pad %d len %d rx_buf_size %d\n", |
| 1350 | pad, len, bp->rx_buf_size); |
| 1351 | bnx2x_panic(); |
| 1352 | return; |
| 1353 | } |
| 1354 | #endif |
| 1355 | |
| 1356 | skb_reserve(skb, pad); |
| 1357 | skb_put(skb, len); |
| 1358 | |
| 1359 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1360 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1361 | |
| 1362 | { |
| 1363 | struct iphdr *iph; |
| 1364 | |
| 1365 | iph = (struct iphdr *)skb->data; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1366 | #ifdef BCM_VLAN |
| 1367 | /* If there is no Rx VLAN offloading - |
| 1368 | take VLAN tag into an account */ |
| 1369 | if (unlikely(is_not_hwaccel_vlan_cqe)) |
| 1370 | iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN); |
| 1371 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1372 | iph->check = 0; |
| 1373 | iph->check = ip_fast_csum((u8 *)iph, iph->ihl); |
| 1374 | } |
| 1375 | |
| 1376 | if (!bnx2x_fill_frag_skb(bp, fp, skb, |
| 1377 | &cqe->fast_path_cqe, cqe_idx)) { |
| 1378 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1379 | if ((bp->vlgrp != NULL) && is_vlan_cqe && |
| 1380 | (!is_not_hwaccel_vlan_cqe)) |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1381 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1382 | le16_to_cpu(cqe->fast_path_cqe. |
| 1383 | vlan_tag)); |
| 1384 | else |
| 1385 | #endif |
| 1386 | netif_receive_skb(skb); |
| 1387 | } else { |
| 1388 | DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages" |
| 1389 | " - dropping packet!\n"); |
| 1390 | dev_kfree_skb(skb); |
| 1391 | } |
| 1392 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1393 | |
| 1394 | /* put new skb in bin */ |
| 1395 | fp->tpa_pool[queue].skb = new_skb; |
| 1396 | |
| 1397 | } else { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1398 | /* else drop the packet and keep the buffer in the bin */ |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1399 | DP(NETIF_MSG_RX_STATUS, |
| 1400 | "Failed to allocate new skb - dropping packet!\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1401 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | fp->tpa_state[queue] = BNX2X_TPA_STOP; |
| 1405 | } |
| 1406 | |
| 1407 | static inline void bnx2x_update_rx_prod(struct bnx2x *bp, |
| 1408 | struct bnx2x_fastpath *fp, |
| 1409 | u16 bd_prod, u16 rx_comp_prod, |
| 1410 | u16 rx_sge_prod) |
| 1411 | { |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1412 | struct ustorm_eth_rx_producers rx_prods = {0}; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1413 | int i; |
| 1414 | |
| 1415 | /* Update producers */ |
| 1416 | rx_prods.bd_prod = bd_prod; |
| 1417 | rx_prods.cqe_prod = rx_comp_prod; |
| 1418 | rx_prods.sge_prod = rx_sge_prod; |
| 1419 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1420 | /* |
| 1421 | * Make sure that the BD and SGE data is updated before updating the |
| 1422 | * producers since FW might read the BD/SGE right after the producer |
| 1423 | * is updated. |
| 1424 | * This is only applicable for weak-ordered memory model archs such |
| 1425 | * as IA-64. The following barrier is also mandatory since FW will |
| 1426 | * assumes BDs must have buffers. |
| 1427 | */ |
| 1428 | wmb(); |
| 1429 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1430 | for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++) |
| 1431 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1432 | USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1433 | ((u32 *)&rx_prods)[i]); |
| 1434 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1435 | mmiowb(); /* keep prod updates ordered */ |
| 1436 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1437 | DP(NETIF_MSG_RX_STATUS, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1438 | "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n", |
| 1439 | fp->index, bd_prod, rx_comp_prod, rx_sge_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1442 | static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget) |
| 1443 | { |
| 1444 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1445 | u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1446 | u16 hw_comp_cons, sw_comp_cons, sw_comp_prod; |
| 1447 | int rx_pkt = 0; |
| 1448 | |
| 1449 | #ifdef BNX2X_STOP_ON_ERROR |
| 1450 | if (unlikely(bp->panic)) |
| 1451 | return 0; |
| 1452 | #endif |
| 1453 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1454 | /* CQ "next element" is of the size of the regular element, |
| 1455 | that's why it's ok here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1456 | hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb); |
| 1457 | if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 1458 | hw_comp_cons++; |
| 1459 | |
| 1460 | bd_cons = fp->rx_bd_cons; |
| 1461 | bd_prod = fp->rx_bd_prod; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1462 | bd_prod_fw = bd_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1463 | sw_comp_cons = fp->rx_comp_cons; |
| 1464 | sw_comp_prod = fp->rx_comp_prod; |
| 1465 | |
| 1466 | /* Memory barrier necessary as speculative reads of the rx |
| 1467 | * buffer can be ahead of the index in the status block |
| 1468 | */ |
| 1469 | rmb(); |
| 1470 | |
| 1471 | DP(NETIF_MSG_RX_STATUS, |
| 1472 | "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1473 | fp->index, hw_comp_cons, sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1474 | |
| 1475 | while (sw_comp_cons != hw_comp_cons) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1476 | struct sw_rx_bd *rx_buf = NULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1477 | struct sk_buff *skb; |
| 1478 | union eth_rx_cqe *cqe; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1479 | u8 cqe_fp_flags; |
| 1480 | u16 len, pad; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1481 | |
| 1482 | comp_ring_cons = RCQ_BD(sw_comp_cons); |
| 1483 | bd_prod = RX_BD(bd_prod); |
| 1484 | bd_cons = RX_BD(bd_cons); |
| 1485 | |
| 1486 | cqe = &fp->rx_comp_ring[comp_ring_cons]; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1487 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1488 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1489 | DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1490 | " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags), |
| 1491 | cqe_fp_flags, cqe->fast_path_cqe.status_flags, |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 1492 | le32_to_cpu(cqe->fast_path_cqe.rss_hash_result), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1493 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag), |
| 1494 | le16_to_cpu(cqe->fast_path_cqe.pkt_len)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1495 | |
| 1496 | /* is this a slowpath msg? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1497 | if (unlikely(CQE_TYPE(cqe_fp_flags))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1498 | bnx2x_sp_event(fp, cqe); |
| 1499 | goto next_cqe; |
| 1500 | |
| 1501 | /* this is an rx packet */ |
| 1502 | } else { |
| 1503 | rx_buf = &fp->rx_buf_ring[bd_cons]; |
| 1504 | skb = rx_buf->skb; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1505 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 1506 | pad = cqe->fast_path_cqe.placement_offset; |
| 1507 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1508 | /* If CQE is marked both TPA_START and TPA_END |
| 1509 | it is a non-TPA CQE */ |
| 1510 | if ((!fp->disable_tpa) && |
| 1511 | (TPA_TYPE(cqe_fp_flags) != |
| 1512 | (TPA_TYPE_START | TPA_TYPE_END))) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1513 | u16 queue = cqe->fast_path_cqe.queue_index; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1514 | |
| 1515 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) { |
| 1516 | DP(NETIF_MSG_RX_STATUS, |
| 1517 | "calling tpa_start on queue %d\n", |
| 1518 | queue); |
| 1519 | |
| 1520 | bnx2x_tpa_start(fp, queue, skb, |
| 1521 | bd_cons, bd_prod); |
| 1522 | goto next_rx; |
| 1523 | } |
| 1524 | |
| 1525 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) { |
| 1526 | DP(NETIF_MSG_RX_STATUS, |
| 1527 | "calling tpa_stop on queue %d\n", |
| 1528 | queue); |
| 1529 | |
| 1530 | if (!BNX2X_RX_SUM_FIX(cqe)) |
| 1531 | BNX2X_ERR("STOP on none TCP " |
| 1532 | "data\n"); |
| 1533 | |
| 1534 | /* This is a size of the linear data |
| 1535 | on this skb */ |
| 1536 | len = le16_to_cpu(cqe->fast_path_cqe. |
| 1537 | len_on_bd); |
| 1538 | bnx2x_tpa_stop(bp, fp, queue, pad, |
| 1539 | len, cqe, comp_ring_cons); |
| 1540 | #ifdef BNX2X_STOP_ON_ERROR |
| 1541 | if (bp->panic) |
| 1542 | return -EINVAL; |
| 1543 | #endif |
| 1544 | |
| 1545 | bnx2x_update_sge_prod(fp, |
| 1546 | &cqe->fast_path_cqe); |
| 1547 | goto next_cqe; |
| 1548 | } |
| 1549 | } |
| 1550 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1551 | pci_dma_sync_single_for_device(bp->pdev, |
| 1552 | pci_unmap_addr(rx_buf, mapping), |
| 1553 | pad + RX_COPY_THRESH, |
| 1554 | PCI_DMA_FROMDEVICE); |
| 1555 | prefetch(skb); |
| 1556 | prefetch(((char *)(skb)) + 128); |
| 1557 | |
| 1558 | /* is this an error packet? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1559 | if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1560 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1561 | "ERROR flags %x rx packet %u\n", |
| 1562 | cqe_fp_flags, sw_comp_cons); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1563 | fp->eth_q_stats.rx_err_discard_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1564 | goto reuse_rx; |
| 1565 | } |
| 1566 | |
| 1567 | /* Since we don't have a jumbo ring |
| 1568 | * copy small packets if mtu > 1500 |
| 1569 | */ |
| 1570 | if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) && |
| 1571 | (len <= RX_COPY_THRESH)) { |
| 1572 | struct sk_buff *new_skb; |
| 1573 | |
| 1574 | new_skb = netdev_alloc_skb(bp->dev, |
| 1575 | len + pad); |
| 1576 | if (new_skb == NULL) { |
| 1577 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1578 | "ERROR packet dropped " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1579 | "because of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1580 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1581 | goto reuse_rx; |
| 1582 | } |
| 1583 | |
| 1584 | /* aligned copy */ |
| 1585 | skb_copy_from_linear_data_offset(skb, pad, |
| 1586 | new_skb->data + pad, len); |
| 1587 | skb_reserve(new_skb, pad); |
| 1588 | skb_put(new_skb, len); |
| 1589 | |
| 1590 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1591 | |
| 1592 | skb = new_skb; |
| 1593 | |
| 1594 | } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) { |
| 1595 | pci_unmap_single(bp->pdev, |
| 1596 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1597 | bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1598 | PCI_DMA_FROMDEVICE); |
| 1599 | skb_reserve(skb, pad); |
| 1600 | skb_put(skb, len); |
| 1601 | |
| 1602 | } else { |
| 1603 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1604 | "ERROR packet dropped because " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1605 | "of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1606 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1607 | reuse_rx: |
| 1608 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1609 | goto next_rx; |
| 1610 | } |
| 1611 | |
| 1612 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1613 | |
| 1614 | skb->ip_summed = CHECKSUM_NONE; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1615 | if (bp->rx_csum) { |
Eilon Greenstein | 1adcd8b | 2008-08-13 15:48:29 -0700 | [diff] [blame] | 1616 | if (likely(BNX2X_RX_CSUM_OK(cqe))) |
| 1617 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1618 | else |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1619 | fp->eth_q_stats.hw_csum_err++; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1620 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1621 | } |
| 1622 | |
Eilon Greenstein | 748e543 | 2009-02-12 08:36:37 +0000 | [diff] [blame] | 1623 | skb_record_rx_queue(skb, fp->index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1624 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1625 | if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) && |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1626 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1627 | PARSING_FLAGS_VLAN)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1628 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1629 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag)); |
| 1630 | else |
| 1631 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1632 | netif_receive_skb(skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1633 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1634 | |
| 1635 | next_rx: |
| 1636 | rx_buf->skb = NULL; |
| 1637 | |
| 1638 | bd_cons = NEXT_RX_IDX(bd_cons); |
| 1639 | bd_prod = NEXT_RX_IDX(bd_prod); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1640 | bd_prod_fw = NEXT_RX_IDX(bd_prod_fw); |
| 1641 | rx_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1642 | next_cqe: |
| 1643 | sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod); |
| 1644 | sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1646 | if (rx_pkt == budget) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1647 | break; |
| 1648 | } /* while */ |
| 1649 | |
| 1650 | fp->rx_bd_cons = bd_cons; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1651 | fp->rx_bd_prod = bd_prod_fw; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1652 | fp->rx_comp_cons = sw_comp_cons; |
| 1653 | fp->rx_comp_prod = sw_comp_prod; |
| 1654 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1655 | /* Update producers */ |
| 1656 | bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod, |
| 1657 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1658 | |
| 1659 | fp->rx_pkt += rx_pkt; |
| 1660 | fp->rx_calls++; |
| 1661 | |
| 1662 | return rx_pkt; |
| 1663 | } |
| 1664 | |
| 1665 | static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie) |
| 1666 | { |
| 1667 | struct bnx2x_fastpath *fp = fp_cookie; |
| 1668 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1669 | int index = fp->index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1670 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 1671 | /* Return here if interrupt is disabled */ |
| 1672 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1673 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1674 | return IRQ_HANDLED; |
| 1675 | } |
| 1676 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1677 | DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1678 | index, fp->sb_id); |
| 1679 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1680 | |
| 1681 | #ifdef BNX2X_STOP_ON_ERROR |
| 1682 | if (unlikely(bp->panic)) |
| 1683 | return IRQ_HANDLED; |
| 1684 | #endif |
| 1685 | |
| 1686 | prefetch(fp->rx_cons_sb); |
| 1687 | prefetch(fp->tx_cons_sb); |
| 1688 | prefetch(&fp->status_blk->c_status_block.status_block_index); |
| 1689 | prefetch(&fp->status_blk->u_status_block.status_block_index); |
| 1690 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1691 | napi_schedule(&bnx2x_fp(bp, index, napi)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1692 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1693 | return IRQ_HANDLED; |
| 1694 | } |
| 1695 | |
| 1696 | static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
| 1697 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1698 | struct bnx2x *bp = netdev_priv(dev_instance); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1699 | u16 status = bnx2x_ack_int(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1700 | u16 mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1701 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1702 | /* Return here if interrupt is shared and it's not for us */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1703 | if (unlikely(status == 0)) { |
| 1704 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); |
| 1705 | return IRQ_NONE; |
| 1706 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1707 | DP(NETIF_MSG_INTR, "got an interrupt status %u\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1708 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1709 | /* Return here if interrupt is disabled */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1710 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1711 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1712 | return IRQ_HANDLED; |
| 1713 | } |
| 1714 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1715 | #ifdef BNX2X_STOP_ON_ERROR |
| 1716 | if (unlikely(bp->panic)) |
| 1717 | return IRQ_HANDLED; |
| 1718 | #endif |
| 1719 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1720 | mask = 0x2 << bp->fp[0].sb_id; |
| 1721 | if (status & mask) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1722 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 1723 | |
| 1724 | prefetch(fp->rx_cons_sb); |
| 1725 | prefetch(fp->tx_cons_sb); |
| 1726 | prefetch(&fp->status_blk->c_status_block.status_block_index); |
| 1727 | prefetch(&fp->status_blk->u_status_block.status_block_index); |
| 1728 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1729 | napi_schedule(&bnx2x_fp(bp, 0, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1730 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1731 | status &= ~mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1732 | } |
| 1733 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1734 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1735 | if (unlikely(status & 0x1)) { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 1736 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1737 | |
| 1738 | status &= ~0x1; |
| 1739 | if (!status) |
| 1740 | return IRQ_HANDLED; |
| 1741 | } |
| 1742 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1743 | if (status) |
| 1744 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n", |
| 1745 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1746 | |
| 1747 | return IRQ_HANDLED; |
| 1748 | } |
| 1749 | |
| 1750 | /* end of fast path */ |
| 1751 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 1752 | 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] | 1753 | |
| 1754 | /* Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1755 | |
| 1756 | /* |
| 1757 | * General service functions |
| 1758 | */ |
| 1759 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1760 | static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1761 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1762 | u32 lock_status; |
| 1763 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1764 | int func = BP_FUNC(bp); |
| 1765 | u32 hw_lock_control_reg; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1766 | int cnt; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1767 | |
| 1768 | /* Validating that the resource is within range */ |
| 1769 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1770 | DP(NETIF_MSG_HW, |
| 1771 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1772 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1773 | return -EINVAL; |
| 1774 | } |
| 1775 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1776 | if (func <= 5) { |
| 1777 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1778 | } else { |
| 1779 | hw_lock_control_reg = |
| 1780 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1781 | } |
| 1782 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1783 | /* Validating that the resource is not already taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1784 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1785 | if (lock_status & resource_bit) { |
| 1786 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1787 | lock_status, resource_bit); |
| 1788 | return -EEXIST; |
| 1789 | } |
| 1790 | |
Eilon Greenstein | 46230476b | 2008-08-25 15:23:30 -0700 | [diff] [blame] | 1791 | /* Try for 5 second every 5ms */ |
| 1792 | for (cnt = 0; cnt < 1000; cnt++) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1793 | /* Try to acquire the lock */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1794 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
| 1795 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1796 | if (lock_status & resource_bit) |
| 1797 | return 0; |
| 1798 | |
| 1799 | msleep(5); |
| 1800 | } |
| 1801 | DP(NETIF_MSG_HW, "Timeout\n"); |
| 1802 | return -EAGAIN; |
| 1803 | } |
| 1804 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1805 | static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1806 | { |
| 1807 | u32 lock_status; |
| 1808 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1809 | int func = BP_FUNC(bp); |
| 1810 | u32 hw_lock_control_reg; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1811 | |
| 1812 | /* Validating that the resource is within range */ |
| 1813 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1814 | DP(NETIF_MSG_HW, |
| 1815 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1816 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1817 | return -EINVAL; |
| 1818 | } |
| 1819 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1820 | if (func <= 5) { |
| 1821 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1822 | } else { |
| 1823 | hw_lock_control_reg = |
| 1824 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1825 | } |
| 1826 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1827 | /* Validating that the resource is currently taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1828 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1829 | if (!(lock_status & resource_bit)) { |
| 1830 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1831 | lock_status, resource_bit); |
| 1832 | return -EFAULT; |
| 1833 | } |
| 1834 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1835 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1836 | return 0; |
| 1837 | } |
| 1838 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1839 | /* HW Lock for shared dual port PHYs */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1840 | static void bnx2x_acquire_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1841 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1842 | mutex_lock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1843 | |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 1844 | if (bp->port.need_hw_lock) |
| 1845 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1848 | static void bnx2x_release_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1849 | { |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 1850 | if (bp->port.need_hw_lock) |
| 1851 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1852 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1853 | mutex_unlock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1856 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
| 1857 | { |
| 1858 | /* The GPIO should be swapped if swap register is set and active */ |
| 1859 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 1860 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 1861 | int gpio_shift = gpio_num + |
| 1862 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1863 | u32 gpio_mask = (1 << gpio_shift); |
| 1864 | u32 gpio_reg; |
| 1865 | int value; |
| 1866 | |
| 1867 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1868 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1869 | return -EINVAL; |
| 1870 | } |
| 1871 | |
| 1872 | /* read GPIO value */ |
| 1873 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); |
| 1874 | |
| 1875 | /* get the requested pin value */ |
| 1876 | if ((gpio_reg & gpio_mask) == gpio_mask) |
| 1877 | value = 1; |
| 1878 | else |
| 1879 | value = 0; |
| 1880 | |
| 1881 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); |
| 1882 | |
| 1883 | return value; |
| 1884 | } |
| 1885 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1886 | 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] | 1887 | { |
| 1888 | /* The GPIO should be swapped if swap register is set and active */ |
| 1889 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1890 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1891 | int gpio_shift = gpio_num + |
| 1892 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1893 | u32 gpio_mask = (1 << gpio_shift); |
| 1894 | u32 gpio_reg; |
| 1895 | |
| 1896 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1897 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1898 | return -EINVAL; |
| 1899 | } |
| 1900 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1901 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1902 | /* read GPIO and mask except the float bits */ |
| 1903 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); |
| 1904 | |
| 1905 | switch (mode) { |
| 1906 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: |
| 1907 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n", |
| 1908 | gpio_num, gpio_shift); |
| 1909 | /* clear FLOAT and set CLR */ |
| 1910 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1911 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); |
| 1912 | break; |
| 1913 | |
| 1914 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
| 1915 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n", |
| 1916 | gpio_num, gpio_shift); |
| 1917 | /* clear FLOAT and set SET */ |
| 1918 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1919 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); |
| 1920 | break; |
| 1921 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1922 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1923 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n", |
| 1924 | gpio_num, gpio_shift); |
| 1925 | /* set FLOAT */ |
| 1926 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1927 | break; |
| 1928 | |
| 1929 | default: |
| 1930 | break; |
| 1931 | } |
| 1932 | |
| 1933 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1934 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1935 | |
| 1936 | return 0; |
| 1937 | } |
| 1938 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1939 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
| 1940 | { |
| 1941 | /* The GPIO should be swapped if swap register is set and active */ |
| 1942 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 1943 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 1944 | int gpio_shift = gpio_num + |
| 1945 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1946 | u32 gpio_mask = (1 << gpio_shift); |
| 1947 | u32 gpio_reg; |
| 1948 | |
| 1949 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1950 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1951 | return -EINVAL; |
| 1952 | } |
| 1953 | |
| 1954 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 1955 | /* read GPIO int */ |
| 1956 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); |
| 1957 | |
| 1958 | switch (mode) { |
| 1959 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: |
| 1960 | DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> " |
| 1961 | "output low\n", gpio_num, gpio_shift); |
| 1962 | /* clear SET and set CLR */ |
| 1963 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 1964 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 1965 | break; |
| 1966 | |
| 1967 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: |
| 1968 | DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> " |
| 1969 | "output high\n", gpio_num, gpio_shift); |
| 1970 | /* clear CLR and set SET */ |
| 1971 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 1972 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 1973 | break; |
| 1974 | |
| 1975 | default: |
| 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); |
| 1980 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 1981 | |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1985 | static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode) |
| 1986 | { |
| 1987 | u32 spio_mask = (1 << spio_num); |
| 1988 | u32 spio_reg; |
| 1989 | |
| 1990 | if ((spio_num < MISC_REGISTERS_SPIO_4) || |
| 1991 | (spio_num > MISC_REGISTERS_SPIO_7)) { |
| 1992 | BNX2X_ERR("Invalid SPIO %d\n", spio_num); |
| 1993 | return -EINVAL; |
| 1994 | } |
| 1995 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1996 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1997 | /* read SPIO and mask except the float bits */ |
| 1998 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT); |
| 1999 | |
| 2000 | switch (mode) { |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2001 | case MISC_REGISTERS_SPIO_OUTPUT_LOW: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2002 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num); |
| 2003 | /* clear FLOAT and set CLR */ |
| 2004 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2005 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS); |
| 2006 | break; |
| 2007 | |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2008 | case MISC_REGISTERS_SPIO_OUTPUT_HIGH: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2009 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num); |
| 2010 | /* clear FLOAT and set SET */ |
| 2011 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2012 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS); |
| 2013 | break; |
| 2014 | |
| 2015 | case MISC_REGISTERS_SPIO_INPUT_HI_Z: |
| 2016 | DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num); |
| 2017 | /* set FLOAT */ |
| 2018 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2019 | break; |
| 2020 | |
| 2021 | default: |
| 2022 | break; |
| 2023 | } |
| 2024 | |
| 2025 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2026 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2027 | |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2031 | static void bnx2x_calc_fc_adv(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2032 | { |
Eilon Greenstein | ad33ea3 | 2009-01-14 21:24:57 -0800 | [diff] [blame] | 2033 | switch (bp->link_vars.ieee_fc & |
| 2034 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2035 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2036 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2037 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2038 | break; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2039 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2040 | bp->port.advertising |= (ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2041 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2042 | break; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2043 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2044 | bp->port.advertising |= ADVERTISED_Asym_Pause; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2045 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2046 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2047 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2048 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | } |
| 2052 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2053 | static void bnx2x_link_report(struct bnx2x *bp) |
| 2054 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2055 | if (bp->link_vars.link_up) { |
| 2056 | if (bp->state == BNX2X_STATE_OPEN) |
| 2057 | netif_carrier_on(bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2058 | printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name); |
| 2059 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2060 | printk("%d Mbps ", bp->link_vars.line_speed); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2061 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2062 | if (bp->link_vars.duplex == DUPLEX_FULL) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2063 | printk("full duplex"); |
| 2064 | else |
| 2065 | printk("half duplex"); |
| 2066 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2067 | if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) { |
| 2068 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2069 | printk(", receive "); |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2070 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2071 | printk("& transmit "); |
| 2072 | } else { |
| 2073 | printk(", transmit "); |
| 2074 | } |
| 2075 | printk("flow control ON"); |
| 2076 | } |
| 2077 | printk("\n"); |
| 2078 | |
| 2079 | } else { /* link_down */ |
| 2080 | netif_carrier_off(bp->dev); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2081 | 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] | 2082 | } |
| 2083 | } |
| 2084 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2085 | static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2086 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2087 | if (!BP_NOMCP(bp)) { |
| 2088 | u8 rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2089 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2090 | /* Initialize link parameters structure variables */ |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2091 | /* It is recommended to turn off RX FC for jumbo frames |
| 2092 | for better performance */ |
| 2093 | if (IS_E1HMF(bp)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2094 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2095 | else if (bp->dev->mtu > 5000) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2096 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2097 | else |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2098 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2099 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2100 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2101 | |
| 2102 | if (load_mode == LOAD_DIAG) |
| 2103 | bp->link_params.loopback_mode = LOOPBACK_XGXS_10; |
| 2104 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2105 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2106 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2107 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2108 | |
Eilon Greenstein | 3c96c68 | 2009-01-14 21:25:31 -0800 | [diff] [blame] | 2109 | bnx2x_calc_fc_adv(bp); |
| 2110 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2111 | if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) { |
| 2112 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2113 | bnx2x_link_report(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2114 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2115 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2116 | return rc; |
| 2117 | } |
| 2118 | BNX2X_ERR("Bootcode is missing -not initializing link\n"); |
| 2119 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2120 | } |
| 2121 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2122 | static void bnx2x_link_set(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2123 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2124 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2125 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2126 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2127 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2128 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2129 | bnx2x_calc_fc_adv(bp); |
| 2130 | } else |
| 2131 | BNX2X_ERR("Bootcode is missing -not setting link\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2134 | static void bnx2x__link_reset(struct bnx2x *bp) |
| 2135 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2136 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2137 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 2138 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2139 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2140 | } else |
| 2141 | BNX2X_ERR("Bootcode is missing -not resetting link\n"); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | static u8 bnx2x_link_test(struct bnx2x *bp) |
| 2145 | { |
| 2146 | u8 rc; |
| 2147 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2148 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2149 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2150 | bnx2x_release_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2151 | |
| 2152 | return rc; |
| 2153 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2154 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2155 | static void bnx2x_init_port_minmax(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2156 | { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2157 | u32 r_param = bp->link_vars.line_speed / 8; |
| 2158 | u32 fair_periodic_timeout_usec; |
| 2159 | u32 t_fair; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2160 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2161 | memset(&(bp->cmng.rs_vars), 0, |
| 2162 | sizeof(struct rate_shaping_vars_per_port)); |
| 2163 | memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2164 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2165 | /* 100 usec in SDM ticks = 25 since each tick is 4 usec */ |
| 2166 | bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2167 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2168 | /* this is the threshold below which no timer arming will occur |
| 2169 | 1.25 coefficient is for the threshold to be a little bigger |
| 2170 | than the real time, to compensate for timer in-accuracy */ |
| 2171 | bp->cmng.rs_vars.rs_threshold = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2172 | (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4; |
| 2173 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2174 | /* resolution of fairness timer */ |
| 2175 | fair_periodic_timeout_usec = QM_ARB_BYTES / r_param; |
| 2176 | /* for 10G it is 1000usec. for 1G it is 10000usec. */ |
| 2177 | t_fair = T_FAIR_COEF / bp->link_vars.line_speed; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2178 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2179 | /* this is the threshold below which we won't arm the timer anymore */ |
| 2180 | bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2181 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2182 | /* we multiply by 1e3/8 to get bytes/msec. |
| 2183 | We don't want the credits to pass a credit |
| 2184 | of the t_fair*FAIR_MEM (algorithm resolution) */ |
| 2185 | bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM; |
| 2186 | /* since each tick is 4 usec */ |
| 2187 | bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2190 | static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2191 | { |
| 2192 | struct rate_shaping_vars_per_vn m_rs_vn; |
| 2193 | struct fairness_vars_per_vn m_fair_vn; |
| 2194 | u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2195 | u16 vn_min_rate, vn_max_rate; |
| 2196 | int i; |
| 2197 | |
| 2198 | /* If function is hidden - set min and max to zeroes */ |
| 2199 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { |
| 2200 | vn_min_rate = 0; |
| 2201 | vn_max_rate = 0; |
| 2202 | |
| 2203 | } else { |
| 2204 | vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2205 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2206 | /* If fairness is enabled (not all min rates are zeroes) and |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2207 | if current min rate is zero - set it to 1. |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 2208 | This is a requirement of the algorithm. */ |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2209 | if (bp->vn_weight_sum && (vn_min_rate == 0)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2210 | vn_min_rate = DEF_MIN_RATE; |
| 2211 | vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 2212 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 2213 | } |
| 2214 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2215 | DP(NETIF_MSG_IFUP, |
| 2216 | "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n", |
| 2217 | func, vn_min_rate, vn_max_rate, bp->vn_weight_sum); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2218 | |
| 2219 | memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn)); |
| 2220 | memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn)); |
| 2221 | |
| 2222 | /* global vn counter - maximal Mbps for this vn */ |
| 2223 | m_rs_vn.vn_counter.rate = vn_max_rate; |
| 2224 | |
| 2225 | /* quota - number of bytes transmitted in this period */ |
| 2226 | m_rs_vn.vn_counter.quota = |
| 2227 | (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8; |
| 2228 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2229 | if (bp->vn_weight_sum) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2230 | /* credit for each period of the fairness algorithm: |
| 2231 | number of bytes in T_FAIR (the vn share the port rate). |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2232 | vn_weight_sum should not be larger than 10000, thus |
| 2233 | T_FAIR_COEF / (8 * vn_weight_sum) will always be greater |
| 2234 | than zero */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2235 | m_fair_vn.vn_credit_delta = |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2236 | max((u32)(vn_min_rate * (T_FAIR_COEF / |
| 2237 | (8 * bp->vn_weight_sum))), |
| 2238 | (u32)(bp->cmng.fair_vars.fair_threshold * 2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2239 | DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n", |
| 2240 | m_fair_vn.vn_credit_delta); |
| 2241 | } |
| 2242 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2243 | /* Store it to internal memory */ |
| 2244 | for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++) |
| 2245 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2246 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2247 | ((u32 *)(&m_rs_vn))[i]); |
| 2248 | |
| 2249 | for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++) |
| 2250 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2251 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2252 | ((u32 *)(&m_fair_vn))[i]); |
| 2253 | } |
| 2254 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2255 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2256 | /* This function is called upon link interrupt */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2257 | static void bnx2x_link_attn(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2258 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2259 | /* Make sure that we are synced with the current statistics */ |
| 2260 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2261 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2262 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2263 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2264 | if (bp->link_vars.link_up) { |
| 2265 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2266 | /* dropless flow control */ |
| 2267 | if (CHIP_IS_E1H(bp)) { |
| 2268 | int port = BP_PORT(bp); |
| 2269 | u32 pause_enabled = 0; |
| 2270 | |
| 2271 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
| 2272 | pause_enabled = 1; |
| 2273 | |
| 2274 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 2275 | USTORM_PAUSE_ENABLED_OFFSET(port), |
| 2276 | pause_enabled); |
| 2277 | } |
| 2278 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2279 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
| 2280 | struct host_port_stats *pstats; |
| 2281 | |
| 2282 | pstats = bnx2x_sp(bp, port_stats); |
| 2283 | /* reset old bmac stats */ |
| 2284 | memset(&(pstats->mac_stx[0]), 0, |
| 2285 | sizeof(struct mac_stx)); |
| 2286 | } |
| 2287 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 2288 | (bp->state == BNX2X_STATE_DISABLED)) |
| 2289 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2290 | } |
| 2291 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2292 | /* indicate link status */ |
| 2293 | bnx2x_link_report(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2294 | |
| 2295 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2296 | int port = BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2297 | int func; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2298 | int vn; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2299 | |
| 2300 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2301 | if (vn == BP_E1HVN(bp)) |
| 2302 | continue; |
| 2303 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2304 | func = ((vn << 1) | port); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2305 | |
| 2306 | /* Set the attention towards other drivers |
| 2307 | on the same port */ |
| 2308 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 + |
| 2309 | (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1); |
| 2310 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2311 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2312 | if (bp->link_vars.link_up) { |
| 2313 | int i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2314 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2315 | /* Init rate shaping and fairness contexts */ |
| 2316 | bnx2x_init_port_minmax(bp); |
| 2317 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2318 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2319 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 2320 | |
| 2321 | /* Store it to internal memory */ |
| 2322 | for (i = 0; |
| 2323 | i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 2324 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2325 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4, |
| 2326 | ((u32 *)(&bp->cmng))[i]); |
| 2327 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2328 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2329 | } |
| 2330 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2331 | static void bnx2x__link_status_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2332 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2333 | if (bp->state != BNX2X_STATE_OPEN) |
| 2334 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2335 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2336 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); |
| 2337 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2338 | if (bp->link_vars.link_up) |
| 2339 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2340 | else |
| 2341 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2342 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2343 | /* indicate link status */ |
| 2344 | bnx2x_link_report(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2345 | } |
| 2346 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2347 | static void bnx2x_pmf_update(struct bnx2x *bp) |
| 2348 | { |
| 2349 | int port = BP_PORT(bp); |
| 2350 | u32 val; |
| 2351 | |
| 2352 | bp->port.pmf = 1; |
| 2353 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 2354 | |
| 2355 | /* enable nig attention */ |
| 2356 | val = (0xff0f | (1 << (BP_E1HVN(bp) + 4))); |
| 2357 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 2358 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2359 | |
| 2360 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2363 | /* end of Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2364 | |
| 2365 | /* slow path */ |
| 2366 | |
| 2367 | /* |
| 2368 | * General service functions |
| 2369 | */ |
| 2370 | |
| 2371 | /* the slow path queue is odd since completions arrive on the fastpath ring */ |
| 2372 | static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
| 2373 | u32 data_hi, u32 data_lo, int common) |
| 2374 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2375 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2376 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2377 | DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/, |
| 2378 | "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] | 2379 | (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) + |
| 2380 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, |
| 2381 | HW_CID(bp, cid), data_hi, data_lo, bp->spq_left); |
| 2382 | |
| 2383 | #ifdef BNX2X_STOP_ON_ERROR |
| 2384 | if (unlikely(bp->panic)) |
| 2385 | return -EIO; |
| 2386 | #endif |
| 2387 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2388 | spin_lock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2389 | |
| 2390 | if (!bp->spq_left) { |
| 2391 | BNX2X_ERR("BUG! SPQ ring full!\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2392 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2393 | bnx2x_panic(); |
| 2394 | return -EBUSY; |
| 2395 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2396 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2397 | /* CID needs port number to be encoded int it */ |
| 2398 | bp->spq_prod_bd->hdr.conn_and_cmd_data = |
| 2399 | cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) | |
| 2400 | HW_CID(bp, cid))); |
| 2401 | bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE); |
| 2402 | if (common) |
| 2403 | bp->spq_prod_bd->hdr.type |= |
| 2404 | cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT)); |
| 2405 | |
| 2406 | bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi); |
| 2407 | bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo); |
| 2408 | |
| 2409 | bp->spq_left--; |
| 2410 | |
| 2411 | if (bp->spq_prod_bd == bp->spq_last_bd) { |
| 2412 | bp->spq_prod_bd = bp->spq; |
| 2413 | bp->spq_prod_idx = 0; |
| 2414 | DP(NETIF_MSG_TIMER, "end of spq\n"); |
| 2415 | |
| 2416 | } else { |
| 2417 | bp->spq_prod_bd++; |
| 2418 | bp->spq_prod_idx++; |
| 2419 | } |
| 2420 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2421 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2422 | bp->spq_prod_idx); |
| 2423 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2424 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2425 | return 0; |
| 2426 | } |
| 2427 | |
| 2428 | /* acquire split MCP access lock register */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2429 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2430 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2431 | u32 i, j, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2432 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2433 | |
| 2434 | might_sleep(); |
| 2435 | i = 100; |
| 2436 | for (j = 0; j < i*10; j++) { |
| 2437 | val = (1UL << 31); |
| 2438 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2439 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); |
| 2440 | if (val & (1L << 31)) |
| 2441 | break; |
| 2442 | |
| 2443 | msleep(5); |
| 2444 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2445 | if (!(val & (1L << 31))) { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2446 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2447 | rc = -EBUSY; |
| 2448 | } |
| 2449 | |
| 2450 | return rc; |
| 2451 | } |
| 2452 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2453 | /* release split MCP access lock register */ |
| 2454 | static void bnx2x_release_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2455 | { |
| 2456 | u32 val = 0; |
| 2457 | |
| 2458 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2459 | } |
| 2460 | |
| 2461 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
| 2462 | { |
| 2463 | struct host_def_status_block *def_sb = bp->def_status_blk; |
| 2464 | u16 rc = 0; |
| 2465 | |
| 2466 | barrier(); /* status block is written to by the chip */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2467 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
| 2468 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; |
| 2469 | rc |= 1; |
| 2470 | } |
| 2471 | if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) { |
| 2472 | bp->def_c_idx = def_sb->c_def_status_block.status_block_index; |
| 2473 | rc |= 2; |
| 2474 | } |
| 2475 | if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) { |
| 2476 | bp->def_u_idx = def_sb->u_def_status_block.status_block_index; |
| 2477 | rc |= 4; |
| 2478 | } |
| 2479 | if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) { |
| 2480 | bp->def_x_idx = def_sb->x_def_status_block.status_block_index; |
| 2481 | rc |= 8; |
| 2482 | } |
| 2483 | if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) { |
| 2484 | bp->def_t_idx = def_sb->t_def_status_block.status_block_index; |
| 2485 | rc |= 16; |
| 2486 | } |
| 2487 | return rc; |
| 2488 | } |
| 2489 | |
| 2490 | /* |
| 2491 | * slow path service functions |
| 2492 | */ |
| 2493 | |
| 2494 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) |
| 2495 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2496 | int port = BP_PORT(bp); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2497 | u32 hc_addr = (HC_REG_COMMAND_REG + port*32 + |
| 2498 | COMMAND_REG_ATTN_BITS_SET); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2499 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 2500 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2501 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
| 2502 | NIG_REG_MASK_INTERRUPT_PORT0; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2503 | u32 aeu_mask; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2504 | u32 nig_mask = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2505 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2506 | if (bp->attn_state & asserted) |
| 2507 | BNX2X_ERR("IGU ERROR\n"); |
| 2508 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2509 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 2510 | aeu_mask = REG_RD(bp, aeu_addr); |
| 2511 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2512 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2513 | aeu_mask, asserted); |
| 2514 | aeu_mask &= ~(asserted & 0xff); |
| 2515 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2516 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2517 | REG_WR(bp, aeu_addr, aeu_mask); |
| 2518 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2519 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2520 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2521 | bp->attn_state |= asserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2522 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2523 | |
| 2524 | if (asserted & ATTN_HARD_WIRED_MASK) { |
| 2525 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2526 | |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2527 | bnx2x_acquire_phy_lock(bp); |
| 2528 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2529 | /* save nig interrupt mask */ |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2530 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2531 | REG_WR(bp, nig_int_mask_addr, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2532 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2533 | bnx2x_link_attn(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2534 | |
| 2535 | /* handle unicore attn? */ |
| 2536 | } |
| 2537 | if (asserted & ATTN_SW_TIMER_4_FUNC) |
| 2538 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); |
| 2539 | |
| 2540 | if (asserted & GPIO_2_FUNC) |
| 2541 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); |
| 2542 | |
| 2543 | if (asserted & GPIO_3_FUNC) |
| 2544 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); |
| 2545 | |
| 2546 | if (asserted & GPIO_4_FUNC) |
| 2547 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); |
| 2548 | |
| 2549 | if (port == 0) { |
| 2550 | if (asserted & ATTN_GENERAL_ATTN_1) { |
| 2551 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); |
| 2552 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); |
| 2553 | } |
| 2554 | if (asserted & ATTN_GENERAL_ATTN_2) { |
| 2555 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); |
| 2556 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); |
| 2557 | } |
| 2558 | if (asserted & ATTN_GENERAL_ATTN_3) { |
| 2559 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); |
| 2560 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); |
| 2561 | } |
| 2562 | } else { |
| 2563 | if (asserted & ATTN_GENERAL_ATTN_4) { |
| 2564 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); |
| 2565 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); |
| 2566 | } |
| 2567 | if (asserted & ATTN_GENERAL_ATTN_5) { |
| 2568 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); |
| 2569 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); |
| 2570 | } |
| 2571 | if (asserted & ATTN_GENERAL_ATTN_6) { |
| 2572 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); |
| 2573 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | } /* if hardwired */ |
| 2578 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2579 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 2580 | asserted, hc_addr); |
| 2581 | REG_WR(bp, hc_addr, asserted); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2582 | |
| 2583 | /* now set back the mask */ |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2584 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2585 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2586 | bnx2x_release_phy_lock(bp); |
| 2587 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
| 2591 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2592 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2593 | int reg_offset; |
| 2594 | u32 val; |
| 2595 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2596 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 2597 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2598 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2599 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2600 | |
| 2601 | val = REG_RD(bp, reg_offset); |
| 2602 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; |
| 2603 | REG_WR(bp, reg_offset, val); |
| 2604 | |
| 2605 | BNX2X_ERR("SPIO5 hw attention\n"); |
| 2606 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 2607 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
| 2608 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2609 | /* Fan failure attention */ |
| 2610 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2611 | /* The PHY reset is controlled by GPIO 1 */ |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2612 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1, |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2613 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
| 2614 | /* Low power mode is controlled by GPIO 2 */ |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2615 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2, |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2616 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2617 | /* mark the failure */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2618 | bp->link_params.ext_phy_config &= |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2619 | ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2620 | bp->link_params.ext_phy_config |= |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2621 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; |
| 2622 | SHMEM_WR(bp, |
| 2623 | dev_info.port_hw_config[port]. |
| 2624 | external_phy_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2625 | bp->link_params.ext_phy_config); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2626 | /* log the failure */ |
| 2627 | printk(KERN_ERR PFX "Fan Failure on Network" |
| 2628 | " Controller %s has caused the driver to" |
| 2629 | " shutdown the card to prevent permanent" |
| 2630 | " damage. Please contact Dell Support for" |
| 2631 | " assistance\n", bp->dev->name); |
| 2632 | break; |
| 2633 | |
| 2634 | default: |
| 2635 | break; |
| 2636 | } |
| 2637 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2638 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 2639 | if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 | |
| 2640 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) { |
| 2641 | bnx2x_acquire_phy_lock(bp); |
| 2642 | bnx2x_handle_module_detect_int(&bp->link_params); |
| 2643 | bnx2x_release_phy_lock(bp); |
| 2644 | } |
| 2645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2646 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
| 2647 | |
| 2648 | val = REG_RD(bp, reg_offset); |
| 2649 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); |
| 2650 | REG_WR(bp, reg_offset, val); |
| 2651 | |
| 2652 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", |
| 2653 | (attn & HW_INTERRUT_ASSERT_SET_0)); |
| 2654 | bnx2x_panic(); |
| 2655 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
| 2659 | { |
| 2660 | u32 val; |
| 2661 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 2662 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2663 | |
| 2664 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); |
| 2665 | BNX2X_ERR("DB hw attention 0x%x\n", val); |
| 2666 | /* DORQ discard attention */ |
| 2667 | if (val & 0x2) |
| 2668 | BNX2X_ERR("FATAL error from DORQ\n"); |
| 2669 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2670 | |
| 2671 | if (attn & HW_INTERRUT_ASSERT_SET_1) { |
| 2672 | |
| 2673 | int port = BP_PORT(bp); |
| 2674 | int reg_offset; |
| 2675 | |
| 2676 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : |
| 2677 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); |
| 2678 | |
| 2679 | val = REG_RD(bp, reg_offset); |
| 2680 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); |
| 2681 | REG_WR(bp, reg_offset, val); |
| 2682 | |
| 2683 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", |
| 2684 | (attn & HW_INTERRUT_ASSERT_SET_1)); |
| 2685 | bnx2x_panic(); |
| 2686 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
| 2690 | { |
| 2691 | u32 val; |
| 2692 | |
| 2693 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { |
| 2694 | |
| 2695 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); |
| 2696 | BNX2X_ERR("CFC hw attention 0x%x\n", val); |
| 2697 | /* CFC error attention */ |
| 2698 | if (val & 0x2) |
| 2699 | BNX2X_ERR("FATAL error from CFC\n"); |
| 2700 | } |
| 2701 | |
| 2702 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { |
| 2703 | |
| 2704 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
| 2705 | BNX2X_ERR("PXP hw attention 0x%x\n", val); |
| 2706 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
| 2707 | if (val & 0x18000) |
| 2708 | BNX2X_ERR("FATAL error from PXP\n"); |
| 2709 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2710 | |
| 2711 | if (attn & HW_INTERRUT_ASSERT_SET_2) { |
| 2712 | |
| 2713 | int port = BP_PORT(bp); |
| 2714 | int reg_offset; |
| 2715 | |
| 2716 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : |
| 2717 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); |
| 2718 | |
| 2719 | val = REG_RD(bp, reg_offset); |
| 2720 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); |
| 2721 | REG_WR(bp, reg_offset, val); |
| 2722 | |
| 2723 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", |
| 2724 | (attn & HW_INTERRUT_ASSERT_SET_2)); |
| 2725 | bnx2x_panic(); |
| 2726 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
| 2730 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2731 | u32 val; |
| 2732 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2733 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
| 2734 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2735 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
| 2736 | int func = BP_FUNC(bp); |
| 2737 | |
| 2738 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 2739 | bnx2x__link_status_update(bp); |
| 2740 | if (SHMEM_RD(bp, func_mb[func].drv_status) & |
| 2741 | DRV_STATUS_PMF) |
| 2742 | bnx2x_pmf_update(bp); |
| 2743 | |
| 2744 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2745 | |
| 2746 | BNX2X_ERR("MC assert!\n"); |
| 2747 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
| 2748 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); |
| 2749 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); |
| 2750 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); |
| 2751 | bnx2x_panic(); |
| 2752 | |
| 2753 | } else if (attn & BNX2X_MCP_ASSERT) { |
| 2754 | |
| 2755 | BNX2X_ERR("MCP assert!\n"); |
| 2756 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2757 | bnx2x_fw_dump(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2758 | |
| 2759 | } else |
| 2760 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); |
| 2761 | } |
| 2762 | |
| 2763 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2764 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
| 2765 | if (attn & BNX2X_GRC_TIMEOUT) { |
| 2766 | val = CHIP_IS_E1H(bp) ? |
| 2767 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0; |
| 2768 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
| 2769 | } |
| 2770 | if (attn & BNX2X_GRC_RSV) { |
| 2771 | val = CHIP_IS_E1H(bp) ? |
| 2772 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0; |
| 2773 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
| 2774 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2775 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2776 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
| 2780 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2781 | struct attn_route attn; |
| 2782 | struct attn_route group_mask; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2783 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2784 | int index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2785 | u32 reg_addr; |
| 2786 | u32 val; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2787 | u32 aeu_mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2788 | |
| 2789 | /* need to take HW lock because MCP or other port might also |
| 2790 | try to handle this event */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2791 | bnx2x_acquire_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2792 | |
| 2793 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
| 2794 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); |
| 2795 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); |
| 2796 | 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] | 2797 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n", |
| 2798 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2799 | |
| 2800 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
| 2801 | if (deasserted & (1 << index)) { |
| 2802 | group_mask = bp->attn_group[index]; |
| 2803 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2804 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n", |
| 2805 | index, group_mask.sig[0], group_mask.sig[1], |
| 2806 | group_mask.sig[2], group_mask.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2807 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2808 | bnx2x_attn_int_deasserted3(bp, |
| 2809 | attn.sig[3] & group_mask.sig[3]); |
| 2810 | bnx2x_attn_int_deasserted1(bp, |
| 2811 | attn.sig[1] & group_mask.sig[1]); |
| 2812 | bnx2x_attn_int_deasserted2(bp, |
| 2813 | attn.sig[2] & group_mask.sig[2]); |
| 2814 | bnx2x_attn_int_deasserted0(bp, |
| 2815 | attn.sig[0] & group_mask.sig[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2816 | |
| 2817 | if ((attn.sig[0] & group_mask.sig[0] & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2818 | HW_PRTY_ASSERT_SET_0) || |
| 2819 | (attn.sig[1] & group_mask.sig[1] & |
| 2820 | HW_PRTY_ASSERT_SET_1) || |
| 2821 | (attn.sig[2] & group_mask.sig[2] & |
| 2822 | HW_PRTY_ASSERT_SET_2)) |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2823 | BNX2X_ERR("FATAL HW block parity attention\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2827 | bnx2x_release_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2828 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2829 | 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] | 2830 | |
| 2831 | val = ~deasserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2832 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 2833 | val, reg_addr); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2834 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2835 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2836 | if (~bp->attn_state & deasserted) |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2837 | BNX2X_ERR("IGU ERROR\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2838 | |
| 2839 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 2840 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 2841 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2842 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 2843 | aeu_mask = REG_RD(bp, reg_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2844 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2845 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", |
| 2846 | aeu_mask, deasserted); |
| 2847 | aeu_mask |= (deasserted & 0xff); |
| 2848 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
| 2849 | |
| 2850 | REG_WR(bp, reg_addr, aeu_mask); |
| 2851 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2852 | |
| 2853 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
| 2854 | bp->attn_state &= ~deasserted; |
| 2855 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
| 2856 | } |
| 2857 | |
| 2858 | static void bnx2x_attn_int(struct bnx2x *bp) |
| 2859 | { |
| 2860 | /* read local copy of bits */ |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 2861 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 2862 | attn_bits); |
| 2863 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 2864 | attn_bits_ack); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2865 | u32 attn_state = bp->attn_state; |
| 2866 | |
| 2867 | /* look for changed bits */ |
| 2868 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; |
| 2869 | u32 deasserted = ~attn_bits & attn_ack & attn_state; |
| 2870 | |
| 2871 | DP(NETIF_MSG_HW, |
| 2872 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", |
| 2873 | attn_bits, attn_ack, asserted, deasserted); |
| 2874 | |
| 2875 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2876 | BNX2X_ERR("BAD attention state\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2877 | |
| 2878 | /* handle bits that were raised */ |
| 2879 | if (asserted) |
| 2880 | bnx2x_attn_int_asserted(bp, asserted); |
| 2881 | |
| 2882 | if (deasserted) |
| 2883 | bnx2x_attn_int_deasserted(bp, deasserted); |
| 2884 | } |
| 2885 | |
| 2886 | static void bnx2x_sp_task(struct work_struct *work) |
| 2887 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 2888 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2889 | u16 status; |
| 2890 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2891 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2892 | /* Return here if interrupt is disabled */ |
| 2893 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2894 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2895 | return; |
| 2896 | } |
| 2897 | |
| 2898 | status = bnx2x_update_dsb_idx(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2899 | /* if (status == 0) */ |
| 2900 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2901 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2902 | DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2903 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2904 | /* HW attentions */ |
| 2905 | if (status & 0x1) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2906 | bnx2x_attn_int(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2907 | |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 2908 | 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] | 2909 | IGU_INT_NOP, 1); |
| 2910 | bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx), |
| 2911 | IGU_INT_NOP, 1); |
| 2912 | bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx), |
| 2913 | IGU_INT_NOP, 1); |
| 2914 | bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx), |
| 2915 | IGU_INT_NOP, 1); |
| 2916 | bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx), |
| 2917 | IGU_INT_ENABLE, 1); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2918 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
| 2922 | { |
| 2923 | struct net_device *dev = dev_instance; |
| 2924 | struct bnx2x *bp = netdev_priv(dev); |
| 2925 | |
| 2926 | /* Return here if interrupt is disabled */ |
| 2927 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2928 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2929 | return IRQ_HANDLED; |
| 2930 | } |
| 2931 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 2932 | 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] | 2933 | |
| 2934 | #ifdef BNX2X_STOP_ON_ERROR |
| 2935 | if (unlikely(bp->panic)) |
| 2936 | return IRQ_HANDLED; |
| 2937 | #endif |
| 2938 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 2939 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2940 | |
| 2941 | return IRQ_HANDLED; |
| 2942 | } |
| 2943 | |
| 2944 | /* end of slow path */ |
| 2945 | |
| 2946 | /* Statistics */ |
| 2947 | |
| 2948 | /**************************************************************************** |
| 2949 | * Macros |
| 2950 | ****************************************************************************/ |
| 2951 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2952 | /* sum[hi:lo] += add[hi:lo] */ |
| 2953 | #define ADD_64(s_hi, a_hi, s_lo, a_lo) \ |
| 2954 | do { \ |
| 2955 | s_lo += a_lo; \ |
Eilon Greenstein | f5ba677 | 2009-01-14 21:29:18 -0800 | [diff] [blame] | 2956 | s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2957 | } while (0) |
| 2958 | |
| 2959 | /* difference = minuend - subtrahend */ |
| 2960 | #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \ |
| 2961 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2962 | if (m_lo < s_lo) { \ |
| 2963 | /* underflow */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2964 | d_hi = m_hi - s_hi; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2965 | if (d_hi > 0) { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2966 | /* we can 'loan' 1 */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2967 | d_hi--; \ |
| 2968 | d_lo = m_lo + (UINT_MAX - s_lo) + 1; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2969 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2970 | /* m_hi <= s_hi */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2971 | d_hi = 0; \ |
| 2972 | d_lo = 0; \ |
| 2973 | } \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2974 | } else { \ |
| 2975 | /* m_lo >= s_lo */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2976 | if (m_hi < s_hi) { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2977 | d_hi = 0; \ |
| 2978 | d_lo = 0; \ |
| 2979 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2980 | /* m_hi >= s_hi */ \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2981 | d_hi = m_hi - s_hi; \ |
| 2982 | d_lo = m_lo - s_lo; \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2983 | } \ |
| 2984 | } \ |
| 2985 | } while (0) |
| 2986 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2987 | #define UPDATE_STAT64(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2988 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2989 | DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \ |
| 2990 | diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \ |
| 2991 | pstats->mac_stx[0].t##_hi = new->s##_hi; \ |
| 2992 | pstats->mac_stx[0].t##_lo = new->s##_lo; \ |
| 2993 | ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \ |
| 2994 | pstats->mac_stx[1].t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2995 | } while (0) |
| 2996 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2997 | #define UPDATE_STAT64_NIG(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2998 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2999 | DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \ |
| 3000 | diff.lo, new->s##_lo, old->s##_lo); \ |
| 3001 | ADD_64(estats->t##_hi, diff.hi, \ |
| 3002 | estats->t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3003 | } while (0) |
| 3004 | |
| 3005 | /* sum[hi:lo] += add */ |
| 3006 | #define ADD_EXTEND_64(s_hi, s_lo, a) \ |
| 3007 | do { \ |
| 3008 | s_lo += a; \ |
| 3009 | s_hi += (s_lo < a) ? 1 : 0; \ |
| 3010 | } while (0) |
| 3011 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3012 | #define UPDATE_EXTEND_STAT(s) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3013 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3014 | ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \ |
| 3015 | pstats->mac_stx[1].s##_lo, \ |
| 3016 | new->s); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3017 | } while (0) |
| 3018 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3019 | #define UPDATE_EXTEND_TSTAT(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3020 | do { \ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3021 | diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \ |
| 3022 | old_tclient->s = tclient->s; \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3023 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 3024 | } while (0) |
| 3025 | |
| 3026 | #define UPDATE_EXTEND_USTAT(s, t) \ |
| 3027 | do { \ |
| 3028 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 3029 | old_uclient->s = uclient->s; \ |
| 3030 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3031 | } while (0) |
| 3032 | |
| 3033 | #define UPDATE_EXTEND_XSTAT(s, t) \ |
| 3034 | do { \ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3035 | diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \ |
| 3036 | old_xclient->s = xclient->s; \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3037 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 3038 | } while (0) |
| 3039 | |
| 3040 | /* minuend -= subtrahend */ |
| 3041 | #define SUB_64(m_hi, s_hi, m_lo, s_lo) \ |
| 3042 | do { \ |
| 3043 | DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \ |
| 3044 | } while (0) |
| 3045 | |
| 3046 | /* minuend[hi:lo] -= subtrahend */ |
| 3047 | #define SUB_EXTEND_64(m_hi, m_lo, s) \ |
| 3048 | do { \ |
| 3049 | SUB_64(m_hi, 0, m_lo, s); \ |
| 3050 | } while (0) |
| 3051 | |
| 3052 | #define SUB_EXTEND_USTAT(s, t) \ |
| 3053 | do { \ |
| 3054 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 3055 | SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3056 | } while (0) |
| 3057 | |
| 3058 | /* |
| 3059 | * General service functions |
| 3060 | */ |
| 3061 | |
| 3062 | static inline long bnx2x_hilo(u32 *hiref) |
| 3063 | { |
| 3064 | u32 lo = *(hiref + 1); |
| 3065 | #if (BITS_PER_LONG == 64) |
| 3066 | u32 hi = *hiref; |
| 3067 | |
| 3068 | return HILO_U64(hi, lo); |
| 3069 | #else |
| 3070 | return lo; |
| 3071 | #endif |
| 3072 | } |
| 3073 | |
| 3074 | /* |
| 3075 | * Init service functions |
| 3076 | */ |
| 3077 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3078 | static void bnx2x_storm_stats_post(struct bnx2x *bp) |
| 3079 | { |
| 3080 | if (!bp->stats_pending) { |
| 3081 | struct eth_query_ramrod_data ramrod_data = {0}; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3082 | int i, rc; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3083 | |
| 3084 | ramrod_data.drv_counter = bp->stats_counter++; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 3085 | ramrod_data.collect_port = bp->port.pmf ? 1 : 0; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3086 | for_each_queue(bp, i) |
| 3087 | ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3088 | |
| 3089 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0, |
| 3090 | ((u32 *)&ramrod_data)[1], |
| 3091 | ((u32 *)&ramrod_data)[0], 0); |
| 3092 | if (rc == 0) { |
| 3093 | /* stats ramrod has it's own slot on the spq */ |
| 3094 | bp->spq_left++; |
| 3095 | bp->stats_pending = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3096 | } |
| 3097 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3098 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3099 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3100 | static void bnx2x_stats_init(struct bnx2x *bp) |
| 3101 | { |
| 3102 | int port = BP_PORT(bp); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3103 | int i; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3104 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3105 | bp->stats_pending = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3106 | bp->executer_idx = 0; |
| 3107 | bp->stats_counter = 0; |
| 3108 | |
| 3109 | /* port stats */ |
| 3110 | if (!BP_NOMCP(bp)) |
| 3111 | bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx); |
| 3112 | else |
| 3113 | bp->port.port_stx = 0; |
| 3114 | DP(BNX2X_MSG_STATS, "port_stx 0x%x\n", bp->port.port_stx); |
| 3115 | |
| 3116 | memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats)); |
| 3117 | bp->port.old_nig_stats.brb_discard = |
| 3118 | REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3119 | bp->port.old_nig_stats.brb_truncate = |
| 3120 | REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3121 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50, |
| 3122 | &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2); |
| 3123 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50, |
| 3124 | &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2); |
| 3125 | |
| 3126 | /* function stats */ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3127 | for_each_queue(bp, i) { |
| 3128 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 3129 | |
| 3130 | memset(&fp->old_tclient, 0, |
| 3131 | sizeof(struct tstorm_per_client_stats)); |
| 3132 | memset(&fp->old_uclient, 0, |
| 3133 | sizeof(struct ustorm_per_client_stats)); |
| 3134 | memset(&fp->old_xclient, 0, |
| 3135 | sizeof(struct xstorm_per_client_stats)); |
| 3136 | memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats)); |
| 3137 | } |
| 3138 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3139 | memset(&bp->dev->stats, 0, sizeof(struct net_device_stats)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3140 | memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats)); |
| 3141 | |
| 3142 | bp->stats_state = STATS_STATE_DISABLED; |
| 3143 | if (IS_E1HMF(bp) && bp->port.pmf && bp->port.port_stx) |
| 3144 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
| 3145 | } |
| 3146 | |
| 3147 | static void bnx2x_hw_stats_post(struct bnx2x *bp) |
| 3148 | { |
| 3149 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3150 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3151 | |
| 3152 | *stats_comp = DMAE_COMP_VAL; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3153 | if (CHIP_REV_IS_SLOW(bp)) |
| 3154 | return; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3155 | |
| 3156 | /* loader */ |
| 3157 | if (bp->executer_idx) { |
| 3158 | int loader_idx = PMF_DMAE_C(bp); |
| 3159 | |
| 3160 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3161 | |
| 3162 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3163 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3164 | DMAE_CMD_DST_RESET | |
| 3165 | #ifdef __BIG_ENDIAN |
| 3166 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3167 | #else |
| 3168 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3169 | #endif |
| 3170 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : |
| 3171 | DMAE_CMD_PORT_0) | |
| 3172 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3173 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0])); |
| 3174 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0])); |
| 3175 | dmae->dst_addr_lo = (DMAE_REG_CMD_MEM + |
| 3176 | sizeof(struct dmae_command) * |
| 3177 | (loader_idx + 1)) >> 2; |
| 3178 | dmae->dst_addr_hi = 0; |
| 3179 | dmae->len = sizeof(struct dmae_command) >> 2; |
| 3180 | if (CHIP_IS_E1(bp)) |
| 3181 | dmae->len--; |
| 3182 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2; |
| 3183 | dmae->comp_addr_hi = 0; |
| 3184 | dmae->comp_val = 1; |
| 3185 | |
| 3186 | *stats_comp = 0; |
| 3187 | bnx2x_post_dmae(bp, dmae, loader_idx); |
| 3188 | |
| 3189 | } else if (bp->func_stx) { |
| 3190 | *stats_comp = 0; |
| 3191 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | static int bnx2x_stats_comp(struct bnx2x *bp) |
| 3196 | { |
| 3197 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3198 | int cnt = 10; |
| 3199 | |
| 3200 | might_sleep(); |
| 3201 | while (*stats_comp != DMAE_COMP_VAL) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3202 | if (!cnt) { |
| 3203 | BNX2X_ERR("timeout waiting for stats finished\n"); |
| 3204 | break; |
| 3205 | } |
| 3206 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 3207 | msleep(1); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3208 | } |
| 3209 | return 1; |
| 3210 | } |
| 3211 | |
| 3212 | /* |
| 3213 | * Statistics service functions |
| 3214 | */ |
| 3215 | |
| 3216 | static void bnx2x_stats_pmf_update(struct bnx2x *bp) |
| 3217 | { |
| 3218 | struct dmae_command *dmae; |
| 3219 | u32 opcode; |
| 3220 | int loader_idx = PMF_DMAE_C(bp); |
| 3221 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3222 | |
| 3223 | /* sanity */ |
| 3224 | if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) { |
| 3225 | BNX2X_ERR("BUG!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3226 | return; |
| 3227 | } |
| 3228 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3229 | bp->executer_idx = 0; |
| 3230 | |
| 3231 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3232 | DMAE_CMD_C_ENABLE | |
| 3233 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3234 | #ifdef __BIG_ENDIAN |
| 3235 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3236 | #else |
| 3237 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3238 | #endif |
| 3239 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3240 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3241 | |
| 3242 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3243 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 3244 | dmae->src_addr_lo = bp->port.port_stx >> 2; |
| 3245 | dmae->src_addr_hi = 0; |
| 3246 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3247 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3248 | dmae->len = DMAE_LEN32_RD_MAX; |
| 3249 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3250 | dmae->comp_addr_hi = 0; |
| 3251 | dmae->comp_val = 1; |
| 3252 | |
| 3253 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3254 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 3255 | dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX; |
| 3256 | dmae->src_addr_hi = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 3257 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) + |
| 3258 | DMAE_LEN32_RD_MAX * 4); |
| 3259 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) + |
| 3260 | DMAE_LEN32_RD_MAX * 4); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3261 | dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX; |
| 3262 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3263 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3264 | dmae->comp_val = DMAE_COMP_VAL; |
| 3265 | |
| 3266 | *stats_comp = 0; |
| 3267 | bnx2x_hw_stats_post(bp); |
| 3268 | bnx2x_stats_comp(bp); |
| 3269 | } |
| 3270 | |
| 3271 | static void bnx2x_port_stats_init(struct bnx2x *bp) |
| 3272 | { |
| 3273 | struct dmae_command *dmae; |
| 3274 | int port = BP_PORT(bp); |
| 3275 | int vn = BP_E1HVN(bp); |
| 3276 | u32 opcode; |
| 3277 | int loader_idx = PMF_DMAE_C(bp); |
| 3278 | u32 mac_addr; |
| 3279 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3280 | |
| 3281 | /* sanity */ |
| 3282 | if (!bp->link_vars.link_up || !bp->port.pmf) { |
| 3283 | BNX2X_ERR("BUG!\n"); |
| 3284 | return; |
| 3285 | } |
| 3286 | |
| 3287 | bp->executer_idx = 0; |
| 3288 | |
| 3289 | /* MCP */ |
| 3290 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3291 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3292 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3293 | #ifdef __BIG_ENDIAN |
| 3294 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3295 | #else |
| 3296 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3297 | #endif |
| 3298 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3299 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3300 | |
| 3301 | if (bp->port.port_stx) { |
| 3302 | |
| 3303 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3304 | dmae->opcode = opcode; |
| 3305 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3306 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3307 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
| 3308 | dmae->dst_addr_hi = 0; |
| 3309 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 3310 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3311 | dmae->comp_addr_hi = 0; |
| 3312 | dmae->comp_val = 1; |
| 3313 | } |
| 3314 | |
| 3315 | if (bp->func_stx) { |
| 3316 | |
| 3317 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3318 | dmae->opcode = opcode; |
| 3319 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3320 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3321 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3322 | dmae->dst_addr_hi = 0; |
| 3323 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3324 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3325 | dmae->comp_addr_hi = 0; |
| 3326 | dmae->comp_val = 1; |
| 3327 | } |
| 3328 | |
| 3329 | /* MAC */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3330 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3331 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3332 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3333 | #ifdef __BIG_ENDIAN |
| 3334 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3335 | #else |
| 3336 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3337 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3338 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3339 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3340 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3341 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3342 | |
| 3343 | mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM : |
| 3344 | NIG_REG_INGRESS_BMAC0_MEM); |
| 3345 | |
| 3346 | /* BIGMAC_REGISTER_TX_STAT_GTPKT .. |
| 3347 | BIGMAC_REGISTER_TX_STAT_GTBYT */ |
| 3348 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3349 | dmae->opcode = opcode; |
| 3350 | dmae->src_addr_lo = (mac_addr + |
| 3351 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3352 | dmae->src_addr_hi = 0; |
| 3353 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3354 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3355 | dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT - |
| 3356 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3357 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3358 | dmae->comp_addr_hi = 0; |
| 3359 | dmae->comp_val = 1; |
| 3360 | |
| 3361 | /* BIGMAC_REGISTER_RX_STAT_GR64 .. |
| 3362 | BIGMAC_REGISTER_RX_STAT_GRIPJ */ |
| 3363 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3364 | dmae->opcode = opcode; |
| 3365 | dmae->src_addr_lo = (mac_addr + |
| 3366 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3367 | dmae->src_addr_hi = 0; |
| 3368 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3369 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3370 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3371 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3372 | dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ - |
| 3373 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3374 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3375 | dmae->comp_addr_hi = 0; |
| 3376 | dmae->comp_val = 1; |
| 3377 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3378 | } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3379 | |
| 3380 | mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0); |
| 3381 | |
| 3382 | /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/ |
| 3383 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3384 | dmae->opcode = opcode; |
| 3385 | dmae->src_addr_lo = (mac_addr + |
| 3386 | EMAC_REG_EMAC_RX_STAT_AC) >> 2; |
| 3387 | dmae->src_addr_hi = 0; |
| 3388 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3389 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3390 | dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT; |
| 3391 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3392 | dmae->comp_addr_hi = 0; |
| 3393 | dmae->comp_val = 1; |
| 3394 | |
| 3395 | /* EMAC_REG_EMAC_RX_STAT_AC_28 */ |
| 3396 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3397 | dmae->opcode = opcode; |
| 3398 | dmae->src_addr_lo = (mac_addr + |
| 3399 | EMAC_REG_EMAC_RX_STAT_AC_28) >> 2; |
| 3400 | dmae->src_addr_hi = 0; |
| 3401 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3402 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3403 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3404 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3405 | dmae->len = 1; |
| 3406 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3407 | dmae->comp_addr_hi = 0; |
| 3408 | dmae->comp_val = 1; |
| 3409 | |
| 3410 | /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/ |
| 3411 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3412 | dmae->opcode = opcode; |
| 3413 | dmae->src_addr_lo = (mac_addr + |
| 3414 | EMAC_REG_EMAC_TX_STAT_AC) >> 2; |
| 3415 | dmae->src_addr_hi = 0; |
| 3416 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3417 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3418 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3419 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3420 | dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT; |
| 3421 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3422 | dmae->comp_addr_hi = 0; |
| 3423 | dmae->comp_val = 1; |
| 3424 | } |
| 3425 | |
| 3426 | /* NIG */ |
| 3427 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3428 | dmae->opcode = opcode; |
| 3429 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD : |
| 3430 | NIG_REG_STAT0_BRB_DISCARD) >> 2; |
| 3431 | dmae->src_addr_hi = 0; |
| 3432 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats)); |
| 3433 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats)); |
| 3434 | dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2; |
| 3435 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3436 | dmae->comp_addr_hi = 0; |
| 3437 | dmae->comp_val = 1; |
| 3438 | |
| 3439 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3440 | dmae->opcode = opcode; |
| 3441 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 : |
| 3442 | NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2; |
| 3443 | dmae->src_addr_hi = 0; |
| 3444 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3445 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3446 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3447 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3448 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3449 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3450 | dmae->comp_addr_hi = 0; |
| 3451 | dmae->comp_val = 1; |
| 3452 | |
| 3453 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3454 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3455 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3456 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3457 | #ifdef __BIG_ENDIAN |
| 3458 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3459 | #else |
| 3460 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3461 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3462 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3463 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3464 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 : |
| 3465 | NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3466 | dmae->src_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3467 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3468 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3469 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3470 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3471 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3472 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3473 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3474 | dmae->comp_val = DMAE_COMP_VAL; |
| 3475 | |
| 3476 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3477 | } |
| 3478 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3479 | static void bnx2x_func_stats_init(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3480 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3481 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3482 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3483 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3484 | /* sanity */ |
| 3485 | if (!bp->func_stx) { |
| 3486 | BNX2X_ERR("BUG!\n"); |
| 3487 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3488 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3489 | |
| 3490 | bp->executer_idx = 0; |
| 3491 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3492 | |
| 3493 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3494 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3495 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3496 | #ifdef __BIG_ENDIAN |
| 3497 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3498 | #else |
| 3499 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3500 | #endif |
| 3501 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3502 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3503 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3504 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3505 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3506 | dmae->dst_addr_hi = 0; |
| 3507 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3508 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3509 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3510 | dmae->comp_val = DMAE_COMP_VAL; |
| 3511 | |
| 3512 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3513 | } |
| 3514 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3515 | static void bnx2x_stats_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3516 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3517 | if (bp->port.pmf) |
| 3518 | bnx2x_port_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3519 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3520 | else if (bp->func_stx) |
| 3521 | bnx2x_func_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3522 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3523 | bnx2x_hw_stats_post(bp); |
| 3524 | bnx2x_storm_stats_post(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3525 | } |
| 3526 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3527 | static void bnx2x_stats_pmf_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3528 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3529 | bnx2x_stats_comp(bp); |
| 3530 | bnx2x_stats_pmf_update(bp); |
| 3531 | bnx2x_stats_start(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3532 | } |
| 3533 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3534 | static void bnx2x_stats_restart(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3535 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3536 | bnx2x_stats_comp(bp); |
| 3537 | bnx2x_stats_start(bp); |
| 3538 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3539 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3540 | static void bnx2x_bmac_stats_update(struct bnx2x *bp) |
| 3541 | { |
| 3542 | struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats); |
| 3543 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3544 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3545 | struct { |
| 3546 | u32 lo; |
| 3547 | u32 hi; |
| 3548 | } diff; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3549 | |
| 3550 | UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets); |
| 3551 | UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors); |
| 3552 | UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts); |
| 3553 | UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong); |
| 3554 | UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments); |
| 3555 | UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3556 | UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3557 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3558 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3559 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent); |
| 3560 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone); |
| 3561 | UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets); |
| 3562 | UPDATE_STAT64(tx_stat_gt127, |
| 3563 | tx_stat_etherstatspkts65octetsto127octets); |
| 3564 | UPDATE_STAT64(tx_stat_gt255, |
| 3565 | tx_stat_etherstatspkts128octetsto255octets); |
| 3566 | UPDATE_STAT64(tx_stat_gt511, |
| 3567 | tx_stat_etherstatspkts256octetsto511octets); |
| 3568 | UPDATE_STAT64(tx_stat_gt1023, |
| 3569 | tx_stat_etherstatspkts512octetsto1023octets); |
| 3570 | UPDATE_STAT64(tx_stat_gt1518, |
| 3571 | tx_stat_etherstatspkts1024octetsto1522octets); |
| 3572 | UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047); |
| 3573 | UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095); |
| 3574 | UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216); |
| 3575 | UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383); |
| 3576 | UPDATE_STAT64(tx_stat_gterr, |
| 3577 | tx_stat_dot3statsinternalmactransmiterrors); |
| 3578 | UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3579 | |
| 3580 | estats->pause_frames_received_hi = |
| 3581 | pstats->mac_stx[1].rx_stat_bmac_xpf_hi; |
| 3582 | estats->pause_frames_received_lo = |
| 3583 | pstats->mac_stx[1].rx_stat_bmac_xpf_lo; |
| 3584 | |
| 3585 | estats->pause_frames_sent_hi = |
| 3586 | pstats->mac_stx[1].tx_stat_outxoffsent_hi; |
| 3587 | estats->pause_frames_sent_lo = |
| 3588 | pstats->mac_stx[1].tx_stat_outxoffsent_lo; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | static void bnx2x_emac_stats_update(struct bnx2x *bp) |
| 3592 | { |
| 3593 | struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats); |
| 3594 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3595 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3596 | |
| 3597 | UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets); |
| 3598 | UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets); |
| 3599 | UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors); |
| 3600 | UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors); |
| 3601 | UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors); |
| 3602 | UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors); |
| 3603 | UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts); |
| 3604 | UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong); |
| 3605 | UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments); |
| 3606 | UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers); |
| 3607 | UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived); |
| 3608 | UPDATE_EXTEND_STAT(rx_stat_xoffstateentered); |
| 3609 | UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived); |
| 3610 | UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived); |
| 3611 | UPDATE_EXTEND_STAT(tx_stat_outxonsent); |
| 3612 | UPDATE_EXTEND_STAT(tx_stat_outxoffsent); |
| 3613 | UPDATE_EXTEND_STAT(tx_stat_flowcontroldone); |
| 3614 | UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions); |
| 3615 | UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes); |
| 3616 | UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes); |
| 3617 | UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions); |
| 3618 | UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions); |
| 3619 | UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions); |
| 3620 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets); |
| 3621 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets); |
| 3622 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets); |
| 3623 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets); |
| 3624 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets); |
| 3625 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets); |
| 3626 | UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets); |
| 3627 | UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3628 | |
| 3629 | estats->pause_frames_received_hi = |
| 3630 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi; |
| 3631 | estats->pause_frames_received_lo = |
| 3632 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo; |
| 3633 | ADD_64(estats->pause_frames_received_hi, |
| 3634 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi, |
| 3635 | estats->pause_frames_received_lo, |
| 3636 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo); |
| 3637 | |
| 3638 | estats->pause_frames_sent_hi = |
| 3639 | pstats->mac_stx[1].tx_stat_outxonsent_hi; |
| 3640 | estats->pause_frames_sent_lo = |
| 3641 | pstats->mac_stx[1].tx_stat_outxonsent_lo; |
| 3642 | ADD_64(estats->pause_frames_sent_hi, |
| 3643 | pstats->mac_stx[1].tx_stat_outxoffsent_hi, |
| 3644 | estats->pause_frames_sent_lo, |
| 3645 | pstats->mac_stx[1].tx_stat_outxoffsent_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | static int bnx2x_hw_stats_update(struct bnx2x *bp) |
| 3649 | { |
| 3650 | struct nig_stats *new = bnx2x_sp(bp, nig_stats); |
| 3651 | struct nig_stats *old = &(bp->port.old_nig_stats); |
| 3652 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
| 3653 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3654 | struct { |
| 3655 | u32 lo; |
| 3656 | u32 hi; |
| 3657 | } diff; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3658 | u32 nig_timer_max; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3659 | |
| 3660 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) |
| 3661 | bnx2x_bmac_stats_update(bp); |
| 3662 | |
| 3663 | else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) |
| 3664 | bnx2x_emac_stats_update(bp); |
| 3665 | |
| 3666 | else { /* unreached */ |
| 3667 | BNX2X_ERR("stats updated by dmae but no MAC active\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3668 | return -1; |
| 3669 | } |
| 3670 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3671 | ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo, |
| 3672 | new->brb_discard - old->brb_discard); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3673 | ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo, |
| 3674 | new->brb_truncate - old->brb_truncate); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3675 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3676 | UPDATE_STAT64_NIG(egress_mac_pkt0, |
| 3677 | etherstatspkts1024octetsto1522octets); |
| 3678 | UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3679 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3680 | memcpy(old, new, sizeof(struct nig_stats)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3681 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3682 | memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]), |
| 3683 | sizeof(struct mac_stx)); |
| 3684 | estats->brb_drop_hi = pstats->brb_drop_hi; |
| 3685 | estats->brb_drop_lo = pstats->brb_drop_lo; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3686 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3687 | pstats->host_port_stats_start = ++pstats->host_port_stats_end; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3688 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3689 | nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer); |
| 3690 | if (nig_timer_max != estats->nig_timer_max) { |
| 3691 | estats->nig_timer_max = nig_timer_max; |
| 3692 | BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max); |
| 3693 | } |
| 3694 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3695 | return 0; |
| 3696 | } |
| 3697 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3698 | static int bnx2x_storm_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3699 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3700 | struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3701 | struct tstorm_per_port_stats *tport = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3702 | &stats->tstorm_common.port_statistics; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3703 | struct host_func_stats *fstats = bnx2x_sp(bp, func_stats); |
| 3704 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3705 | int i; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3706 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3707 | memset(&(fstats->total_bytes_received_hi), 0, |
| 3708 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 3709 | estats->error_bytes_received_hi = 0; |
| 3710 | estats->error_bytes_received_lo = 0; |
| 3711 | estats->etherstatsoverrsizepkts_hi = 0; |
| 3712 | estats->etherstatsoverrsizepkts_lo = 0; |
| 3713 | estats->no_buff_discard_hi = 0; |
| 3714 | estats->no_buff_discard_lo = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3715 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3716 | for_each_queue(bp, i) { |
| 3717 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 3718 | int cl_id = fp->cl_id; |
| 3719 | struct tstorm_per_client_stats *tclient = |
| 3720 | &stats->tstorm_common.client_statistics[cl_id]; |
| 3721 | struct tstorm_per_client_stats *old_tclient = &fp->old_tclient; |
| 3722 | struct ustorm_per_client_stats *uclient = |
| 3723 | &stats->ustorm_common.client_statistics[cl_id]; |
| 3724 | struct ustorm_per_client_stats *old_uclient = &fp->old_uclient; |
| 3725 | struct xstorm_per_client_stats *xclient = |
| 3726 | &stats->xstorm_common.client_statistics[cl_id]; |
| 3727 | struct xstorm_per_client_stats *old_xclient = &fp->old_xclient; |
| 3728 | struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats; |
| 3729 | u32 diff; |
| 3730 | |
| 3731 | /* are storm stats valid? */ |
| 3732 | if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) != |
| 3733 | bp->stats_counter) { |
| 3734 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm" |
| 3735 | " xstorm counter (%d) != stats_counter (%d)\n", |
| 3736 | i, xclient->stats_counter, bp->stats_counter); |
| 3737 | return -1; |
| 3738 | } |
| 3739 | if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) != |
| 3740 | bp->stats_counter) { |
| 3741 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm" |
| 3742 | " tstorm counter (%d) != stats_counter (%d)\n", |
| 3743 | i, tclient->stats_counter, bp->stats_counter); |
| 3744 | return -2; |
| 3745 | } |
| 3746 | if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) != |
| 3747 | bp->stats_counter) { |
| 3748 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm" |
| 3749 | " ustorm counter (%d) != stats_counter (%d)\n", |
| 3750 | i, uclient->stats_counter, bp->stats_counter); |
| 3751 | return -4; |
| 3752 | } |
| 3753 | |
| 3754 | qstats->total_bytes_received_hi = |
| 3755 | qstats->valid_bytes_received_hi = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3756 | le32_to_cpu(tclient->total_rcv_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3757 | qstats->total_bytes_received_lo = |
| 3758 | qstats->valid_bytes_received_lo = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3759 | le32_to_cpu(tclient->total_rcv_bytes.lo); |
| 3760 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3761 | qstats->error_bytes_received_hi = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3762 | le32_to_cpu(tclient->rcv_error_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3763 | qstats->error_bytes_received_lo = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3764 | le32_to_cpu(tclient->rcv_error_bytes.lo); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3765 | |
| 3766 | ADD_64(qstats->total_bytes_received_hi, |
| 3767 | qstats->error_bytes_received_hi, |
| 3768 | qstats->total_bytes_received_lo, |
| 3769 | qstats->error_bytes_received_lo); |
| 3770 | |
| 3771 | UPDATE_EXTEND_TSTAT(rcv_unicast_pkts, |
| 3772 | total_unicast_packets_received); |
| 3773 | UPDATE_EXTEND_TSTAT(rcv_multicast_pkts, |
| 3774 | total_multicast_packets_received); |
| 3775 | UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts, |
| 3776 | total_broadcast_packets_received); |
| 3777 | UPDATE_EXTEND_TSTAT(packets_too_big_discard, |
| 3778 | etherstatsoverrsizepkts); |
| 3779 | UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard); |
| 3780 | |
| 3781 | SUB_EXTEND_USTAT(ucast_no_buff_pkts, |
| 3782 | total_unicast_packets_received); |
| 3783 | SUB_EXTEND_USTAT(mcast_no_buff_pkts, |
| 3784 | total_multicast_packets_received); |
| 3785 | SUB_EXTEND_USTAT(bcast_no_buff_pkts, |
| 3786 | total_broadcast_packets_received); |
| 3787 | UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard); |
| 3788 | UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard); |
| 3789 | UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard); |
| 3790 | |
| 3791 | qstats->total_bytes_transmitted_hi = |
| 3792 | le32_to_cpu(xclient->total_sent_bytes.hi); |
| 3793 | qstats->total_bytes_transmitted_lo = |
| 3794 | le32_to_cpu(xclient->total_sent_bytes.lo); |
| 3795 | |
| 3796 | UPDATE_EXTEND_XSTAT(unicast_pkts_sent, |
| 3797 | total_unicast_packets_transmitted); |
| 3798 | UPDATE_EXTEND_XSTAT(multicast_pkts_sent, |
| 3799 | total_multicast_packets_transmitted); |
| 3800 | UPDATE_EXTEND_XSTAT(broadcast_pkts_sent, |
| 3801 | total_broadcast_packets_transmitted); |
| 3802 | |
| 3803 | old_tclient->checksum_discard = tclient->checksum_discard; |
| 3804 | old_tclient->ttl0_discard = tclient->ttl0_discard; |
| 3805 | |
| 3806 | ADD_64(fstats->total_bytes_received_hi, |
| 3807 | qstats->total_bytes_received_hi, |
| 3808 | fstats->total_bytes_received_lo, |
| 3809 | qstats->total_bytes_received_lo); |
| 3810 | ADD_64(fstats->total_bytes_transmitted_hi, |
| 3811 | qstats->total_bytes_transmitted_hi, |
| 3812 | fstats->total_bytes_transmitted_lo, |
| 3813 | qstats->total_bytes_transmitted_lo); |
| 3814 | ADD_64(fstats->total_unicast_packets_received_hi, |
| 3815 | qstats->total_unicast_packets_received_hi, |
| 3816 | fstats->total_unicast_packets_received_lo, |
| 3817 | qstats->total_unicast_packets_received_lo); |
| 3818 | ADD_64(fstats->total_multicast_packets_received_hi, |
| 3819 | qstats->total_multicast_packets_received_hi, |
| 3820 | fstats->total_multicast_packets_received_lo, |
| 3821 | qstats->total_multicast_packets_received_lo); |
| 3822 | ADD_64(fstats->total_broadcast_packets_received_hi, |
| 3823 | qstats->total_broadcast_packets_received_hi, |
| 3824 | fstats->total_broadcast_packets_received_lo, |
| 3825 | qstats->total_broadcast_packets_received_lo); |
| 3826 | ADD_64(fstats->total_unicast_packets_transmitted_hi, |
| 3827 | qstats->total_unicast_packets_transmitted_hi, |
| 3828 | fstats->total_unicast_packets_transmitted_lo, |
| 3829 | qstats->total_unicast_packets_transmitted_lo); |
| 3830 | ADD_64(fstats->total_multicast_packets_transmitted_hi, |
| 3831 | qstats->total_multicast_packets_transmitted_hi, |
| 3832 | fstats->total_multicast_packets_transmitted_lo, |
| 3833 | qstats->total_multicast_packets_transmitted_lo); |
| 3834 | ADD_64(fstats->total_broadcast_packets_transmitted_hi, |
| 3835 | qstats->total_broadcast_packets_transmitted_hi, |
| 3836 | fstats->total_broadcast_packets_transmitted_lo, |
| 3837 | qstats->total_broadcast_packets_transmitted_lo); |
| 3838 | ADD_64(fstats->valid_bytes_received_hi, |
| 3839 | qstats->valid_bytes_received_hi, |
| 3840 | fstats->valid_bytes_received_lo, |
| 3841 | qstats->valid_bytes_received_lo); |
| 3842 | |
| 3843 | ADD_64(estats->error_bytes_received_hi, |
| 3844 | qstats->error_bytes_received_hi, |
| 3845 | estats->error_bytes_received_lo, |
| 3846 | qstats->error_bytes_received_lo); |
| 3847 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 3848 | qstats->etherstatsoverrsizepkts_hi, |
| 3849 | estats->etherstatsoverrsizepkts_lo, |
| 3850 | qstats->etherstatsoverrsizepkts_lo); |
| 3851 | ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi, |
| 3852 | estats->no_buff_discard_lo, qstats->no_buff_discard_lo); |
| 3853 | } |
| 3854 | |
| 3855 | ADD_64(fstats->total_bytes_received_hi, |
| 3856 | estats->rx_stat_ifhcinbadoctets_hi, |
| 3857 | fstats->total_bytes_received_lo, |
| 3858 | estats->rx_stat_ifhcinbadoctets_lo); |
| 3859 | |
| 3860 | memcpy(estats, &(fstats->total_bytes_received_hi), |
| 3861 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 3862 | |
| 3863 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 3864 | estats->rx_stat_dot3statsframestoolong_hi, |
| 3865 | estats->etherstatsoverrsizepkts_lo, |
| 3866 | estats->rx_stat_dot3statsframestoolong_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3867 | ADD_64(estats->error_bytes_received_hi, |
| 3868 | estats->rx_stat_ifhcinbadoctets_hi, |
| 3869 | estats->error_bytes_received_lo, |
| 3870 | estats->rx_stat_ifhcinbadoctets_lo); |
| 3871 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3872 | if (bp->port.pmf) { |
| 3873 | estats->mac_filter_discard = |
| 3874 | le32_to_cpu(tport->mac_filter_discard); |
| 3875 | estats->xxoverflow_discard = |
| 3876 | le32_to_cpu(tport->xxoverflow_discard); |
| 3877 | estats->brb_truncate_discard = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3878 | le32_to_cpu(tport->brb_truncate_discard); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3879 | estats->mac_discard = le32_to_cpu(tport->mac_discard); |
| 3880 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3881 | |
| 3882 | fstats->host_func_stats_start = ++fstats->host_func_stats_end; |
| 3883 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3884 | bp->stats_pending = 0; |
| 3885 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3886 | return 0; |
| 3887 | } |
| 3888 | |
| 3889 | static void bnx2x_net_stats_update(struct bnx2x *bp) |
| 3890 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3891 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3892 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3893 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3894 | |
| 3895 | nstats->rx_packets = |
| 3896 | bnx2x_hilo(&estats->total_unicast_packets_received_hi) + |
| 3897 | bnx2x_hilo(&estats->total_multicast_packets_received_hi) + |
| 3898 | bnx2x_hilo(&estats->total_broadcast_packets_received_hi); |
| 3899 | |
| 3900 | nstats->tx_packets = |
| 3901 | bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) + |
| 3902 | bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) + |
| 3903 | bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi); |
| 3904 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3905 | nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3906 | |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 3907 | nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3908 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3909 | nstats->rx_dropped = estats->mac_discard; |
| 3910 | for_each_queue(bp, i) |
| 3911 | nstats->rx_dropped += |
| 3912 | le32_to_cpu(bp->fp[i].old_tclient.checksum_discard); |
| 3913 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3914 | nstats->tx_dropped = 0; |
| 3915 | |
| 3916 | nstats->multicast = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3917 | bnx2x_hilo(&estats->total_multicast_packets_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3918 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3919 | nstats->collisions = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3920 | bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3921 | |
| 3922 | nstats->rx_length_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3923 | bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) + |
| 3924 | bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi); |
| 3925 | nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) + |
| 3926 | bnx2x_hilo(&estats->brb_truncate_hi); |
| 3927 | nstats->rx_crc_errors = |
| 3928 | bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi); |
| 3929 | nstats->rx_frame_errors = |
| 3930 | bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi); |
| 3931 | nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3932 | nstats->rx_missed_errors = estats->xxoverflow_discard; |
| 3933 | |
| 3934 | nstats->rx_errors = nstats->rx_length_errors + |
| 3935 | nstats->rx_over_errors + |
| 3936 | nstats->rx_crc_errors + |
| 3937 | nstats->rx_frame_errors + |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 3938 | nstats->rx_fifo_errors + |
| 3939 | nstats->rx_missed_errors; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3940 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3941 | nstats->tx_aborted_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3942 | bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) + |
| 3943 | bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi); |
| 3944 | nstats->tx_carrier_errors = |
| 3945 | bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3946 | nstats->tx_fifo_errors = 0; |
| 3947 | nstats->tx_heartbeat_errors = 0; |
| 3948 | nstats->tx_window_errors = 0; |
| 3949 | |
| 3950 | nstats->tx_errors = nstats->tx_aborted_errors + |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3951 | nstats->tx_carrier_errors + |
| 3952 | bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi); |
| 3953 | } |
| 3954 | |
| 3955 | static void bnx2x_drv_stats_update(struct bnx2x *bp) |
| 3956 | { |
| 3957 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
| 3958 | int i; |
| 3959 | |
| 3960 | estats->driver_xoff = 0; |
| 3961 | estats->rx_err_discard_pkt = 0; |
| 3962 | estats->rx_skb_alloc_failed = 0; |
| 3963 | estats->hw_csum_err = 0; |
| 3964 | for_each_queue(bp, i) { |
| 3965 | struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats; |
| 3966 | |
| 3967 | estats->driver_xoff += qstats->driver_xoff; |
| 3968 | estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt; |
| 3969 | estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed; |
| 3970 | estats->hw_csum_err += qstats->hw_csum_err; |
| 3971 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3972 | } |
| 3973 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3974 | static void bnx2x_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3975 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3976 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3977 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3978 | if (*stats_comp != DMAE_COMP_VAL) |
| 3979 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3980 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3981 | if (bp->port.pmf) |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3982 | bnx2x_hw_stats_update(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3983 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3984 | if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) { |
| 3985 | BNX2X_ERR("storm stats were not updated for 3 times\n"); |
| 3986 | bnx2x_panic(); |
| 3987 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3988 | } |
| 3989 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3990 | bnx2x_net_stats_update(bp); |
| 3991 | bnx2x_drv_stats_update(bp); |
| 3992 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3993 | if (bp->msglevel & NETIF_MSG_TIMER) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3994 | struct tstorm_per_client_stats *old_tclient = |
| 3995 | &bp->fp->old_tclient; |
| 3996 | struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3997 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3998 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3999 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4000 | |
| 4001 | printk(KERN_DEBUG "%s:\n", bp->dev->name); |
| 4002 | printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)" |
| 4003 | " tx pkt (%lx)\n", |
| 4004 | bnx2x_tx_avail(bp->fp), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4005 | le16_to_cpu(*bp->fp->tx_cons_sb), nstats->tx_packets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4006 | printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)" |
| 4007 | " rx pkt (%lx)\n", |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4008 | (u16)(le16_to_cpu(*bp->fp->rx_cons_sb) - |
| 4009 | bp->fp->rx_comp_cons), |
| 4010 | le16_to_cpu(*bp->fp->rx_cons_sb), nstats->rx_packets); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4011 | printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u " |
| 4012 | "brb truncate %u\n", |
| 4013 | (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"), |
| 4014 | qstats->driver_xoff, |
| 4015 | estats->brb_drop_lo, estats->brb_truncate_lo); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4016 | printk(KERN_DEBUG "tstats: checksum_discard %u " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4017 | "packets_too_big_discard %lu no_buff_discard %lu " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4018 | "mac_discard %u mac_filter_discard %u " |
| 4019 | "xxovrflow_discard %u brb_truncate_discard %u " |
| 4020 | "ttl0_discard %u\n", |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 4021 | le32_to_cpu(old_tclient->checksum_discard), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4022 | bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi), |
| 4023 | bnx2x_hilo(&qstats->no_buff_discard_hi), |
| 4024 | estats->mac_discard, estats->mac_filter_discard, |
| 4025 | estats->xxoverflow_discard, estats->brb_truncate_discard, |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 4026 | le32_to_cpu(old_tclient->ttl0_discard)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4027 | |
| 4028 | for_each_queue(bp, i) { |
| 4029 | printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i, |
| 4030 | bnx2x_fp(bp, i, tx_pkt), |
| 4031 | bnx2x_fp(bp, i, rx_pkt), |
| 4032 | bnx2x_fp(bp, i, rx_calls)); |
| 4033 | } |
| 4034 | } |
| 4035 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4036 | bnx2x_hw_stats_post(bp); |
| 4037 | bnx2x_storm_stats_post(bp); |
| 4038 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4039 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4040 | static void bnx2x_port_stats_stop(struct bnx2x *bp) |
| 4041 | { |
| 4042 | struct dmae_command *dmae; |
| 4043 | u32 opcode; |
| 4044 | int loader_idx = PMF_DMAE_C(bp); |
| 4045 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4046 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4047 | bp->executer_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4048 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4049 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 4050 | DMAE_CMD_C_ENABLE | |
| 4051 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4052 | #ifdef __BIG_ENDIAN |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4053 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4054 | #else |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4055 | DMAE_CMD_ENDIANITY_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4056 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4057 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 4058 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 4059 | |
| 4060 | if (bp->port.port_stx) { |
| 4061 | |
| 4062 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 4063 | if (bp->func_stx) |
| 4064 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 4065 | else |
| 4066 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 4067 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 4068 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 4069 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4070 | dmae->dst_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4071 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 4072 | if (bp->func_stx) { |
| 4073 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 4074 | dmae->comp_addr_hi = 0; |
| 4075 | dmae->comp_val = 1; |
| 4076 | } else { |
| 4077 | dmae->comp_addr_lo = |
| 4078 | U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4079 | dmae->comp_addr_hi = |
| 4080 | U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4081 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4082 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4083 | *stats_comp = 0; |
| 4084 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4085 | } |
| 4086 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4087 | if (bp->func_stx) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4088 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4089 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 4090 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 4091 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 4092 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 4093 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 4094 | dmae->dst_addr_hi = 0; |
| 4095 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 4096 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4097 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4098 | dmae->comp_val = DMAE_COMP_VAL; |
| 4099 | |
| 4100 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4101 | } |
| 4102 | } |
| 4103 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4104 | static void bnx2x_stats_stop(struct bnx2x *bp) |
| 4105 | { |
| 4106 | int update = 0; |
| 4107 | |
| 4108 | bnx2x_stats_comp(bp); |
| 4109 | |
| 4110 | if (bp->port.pmf) |
| 4111 | update = (bnx2x_hw_stats_update(bp) == 0); |
| 4112 | |
| 4113 | update |= (bnx2x_storm_stats_update(bp) == 0); |
| 4114 | |
| 4115 | if (update) { |
| 4116 | bnx2x_net_stats_update(bp); |
| 4117 | |
| 4118 | if (bp->port.pmf) |
| 4119 | bnx2x_port_stats_stop(bp); |
| 4120 | |
| 4121 | bnx2x_hw_stats_post(bp); |
| 4122 | bnx2x_stats_comp(bp); |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | static void bnx2x_stats_do_nothing(struct bnx2x *bp) |
| 4127 | { |
| 4128 | } |
| 4129 | |
| 4130 | static const struct { |
| 4131 | void (*action)(struct bnx2x *bp); |
| 4132 | enum bnx2x_stats_state next_state; |
| 4133 | } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = { |
| 4134 | /* state event */ |
| 4135 | { |
| 4136 | /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED}, |
| 4137 | /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED}, |
| 4138 | /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}, |
| 4139 | /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED} |
| 4140 | }, |
| 4141 | { |
| 4142 | /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED}, |
| 4143 | /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED}, |
| 4144 | /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED}, |
| 4145 | /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED} |
| 4146 | } |
| 4147 | }; |
| 4148 | |
| 4149 | static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event) |
| 4150 | { |
| 4151 | enum bnx2x_stats_state state = bp->stats_state; |
| 4152 | |
| 4153 | bnx2x_stats_stm[state][event].action(bp); |
| 4154 | bp->stats_state = bnx2x_stats_stm[state][event].next_state; |
| 4155 | |
| 4156 | if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER)) |
| 4157 | DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", |
| 4158 | state, event, bp->stats_state); |
| 4159 | } |
| 4160 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4161 | static void bnx2x_timer(unsigned long data) |
| 4162 | { |
| 4163 | struct bnx2x *bp = (struct bnx2x *) data; |
| 4164 | |
| 4165 | if (!netif_running(bp->dev)) |
| 4166 | return; |
| 4167 | |
| 4168 | if (atomic_read(&bp->intr_sem) != 0) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4169 | goto timer_restart; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4170 | |
| 4171 | if (poll) { |
| 4172 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 4173 | int rc; |
| 4174 | |
| 4175 | bnx2x_tx_int(fp, 1000); |
| 4176 | rc = bnx2x_rx_int(fp, 1000); |
| 4177 | } |
| 4178 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4179 | if (!BP_NOMCP(bp)) { |
| 4180 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4181 | u32 drv_pulse; |
| 4182 | u32 mcp_pulse; |
| 4183 | |
| 4184 | ++bp->fw_drv_pulse_wr_seq; |
| 4185 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; |
| 4186 | /* TBD - add SYSTEM_TIME */ |
| 4187 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4188 | SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4189 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4190 | mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4191 | MCP_PULSE_SEQ_MASK); |
| 4192 | /* The delta between driver pulse and mcp response |
| 4193 | * should be 1 (before mcp response) or 0 (after mcp response) |
| 4194 | */ |
| 4195 | if ((drv_pulse != mcp_pulse) && |
| 4196 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { |
| 4197 | /* someone lost a heartbeat... */ |
| 4198 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", |
| 4199 | drv_pulse, mcp_pulse); |
| 4200 | } |
| 4201 | } |
| 4202 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4203 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 4204 | (bp->state == BNX2X_STATE_DISABLED)) |
| 4205 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4206 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4207 | timer_restart: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4208 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 4209 | } |
| 4210 | |
| 4211 | /* end of Statistics */ |
| 4212 | |
| 4213 | /* nic init */ |
| 4214 | |
| 4215 | /* |
| 4216 | * nic init service functions |
| 4217 | */ |
| 4218 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4219 | static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4220 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4221 | int port = BP_PORT(bp); |
| 4222 | |
| 4223 | bnx2x_init_fill(bp, BAR_USTRORM_INTMEM + |
| 4224 | USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0, |
Yitchak Gertner | 3530298 | 2008-08-13 15:53:12 -0700 | [diff] [blame] | 4225 | sizeof(struct ustorm_status_block)/4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4226 | bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM + |
| 4227 | CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0, |
Yitchak Gertner | 3530298 | 2008-08-13 15:53:12 -0700 | [diff] [blame] | 4228 | sizeof(struct cstorm_status_block)/4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4231 | static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb, |
| 4232 | dma_addr_t mapping, int sb_id) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4233 | { |
| 4234 | int port = BP_PORT(bp); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4235 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4236 | int index; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4237 | u64 section; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4238 | |
| 4239 | /* USTORM */ |
| 4240 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4241 | u_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4242 | sb->u_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4243 | |
| 4244 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4245 | USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4246 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4247 | ((USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4248 | U64_HI(section)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4249 | REG_WR8(bp, BAR_USTRORM_INTMEM + FP_USB_FUNC_OFF + |
| 4250 | USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4251 | |
| 4252 | for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++) |
| 4253 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4254 | USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4255 | |
| 4256 | /* CSTORM */ |
| 4257 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4258 | c_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4259 | sb->c_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4260 | |
| 4261 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4262 | CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4263 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4264 | ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4265 | U64_HI(section)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4266 | REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF + |
| 4267 | CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4268 | |
| 4269 | for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++) |
| 4270 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4271 | CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4272 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4273 | bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
| 4274 | } |
| 4275 | |
| 4276 | static void bnx2x_zero_def_sb(struct bnx2x *bp) |
| 4277 | { |
| 4278 | int func = BP_FUNC(bp); |
| 4279 | |
| 4280 | bnx2x_init_fill(bp, BAR_USTRORM_INTMEM + |
| 4281 | USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4282 | sizeof(struct ustorm_def_status_block)/4); |
| 4283 | bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM + |
| 4284 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4285 | sizeof(struct cstorm_def_status_block)/4); |
| 4286 | bnx2x_init_fill(bp, BAR_XSTRORM_INTMEM + |
| 4287 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4288 | sizeof(struct xstorm_def_status_block)/4); |
| 4289 | bnx2x_init_fill(bp, BAR_TSTRORM_INTMEM + |
| 4290 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4291 | sizeof(struct tstorm_def_status_block)/4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | static void bnx2x_init_def_sb(struct bnx2x *bp, |
| 4295 | struct host_def_status_block *def_sb, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4296 | dma_addr_t mapping, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4297 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4298 | int port = BP_PORT(bp); |
| 4299 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4300 | int index, val, reg_offset; |
| 4301 | u64 section; |
| 4302 | |
| 4303 | /* ATTN */ |
| 4304 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4305 | atten_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4306 | def_sb->atten_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4307 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4308 | bp->attn_state = 0; |
| 4309 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4310 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 4311 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 4312 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4313 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4314 | bp->attn_group[index].sig[0] = REG_RD(bp, |
| 4315 | reg_offset + 0x10*index); |
| 4316 | bp->attn_group[index].sig[1] = REG_RD(bp, |
| 4317 | reg_offset + 0x4 + 0x10*index); |
| 4318 | bp->attn_group[index].sig[2] = REG_RD(bp, |
| 4319 | reg_offset + 0x8 + 0x10*index); |
| 4320 | bp->attn_group[index].sig[3] = REG_RD(bp, |
| 4321 | reg_offset + 0xc + 0x10*index); |
| 4322 | } |
| 4323 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4324 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : |
| 4325 | HC_REG_ATTN_MSG0_ADDR_L); |
| 4326 | |
| 4327 | REG_WR(bp, reg_offset, U64_LO(section)); |
| 4328 | REG_WR(bp, reg_offset + 4, U64_HI(section)); |
| 4329 | |
| 4330 | reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0); |
| 4331 | |
| 4332 | val = REG_RD(bp, reg_offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4333 | val |= sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4334 | REG_WR(bp, reg_offset, val); |
| 4335 | |
| 4336 | /* USTORM */ |
| 4337 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4338 | u_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4339 | def_sb->u_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4340 | |
| 4341 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4342 | USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4343 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4344 | ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4345 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4346 | REG_WR8(bp, BAR_USTRORM_INTMEM + DEF_USB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4347 | USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4348 | |
| 4349 | for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++) |
| 4350 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4351 | USTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4352 | |
| 4353 | /* CSTORM */ |
| 4354 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4355 | c_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4356 | def_sb->c_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4357 | |
| 4358 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4359 | CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4360 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4361 | ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4362 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4363 | REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4364 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4365 | |
| 4366 | for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++) |
| 4367 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4368 | CSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4369 | |
| 4370 | /* TSTORM */ |
| 4371 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4372 | t_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4373 | def_sb->t_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4374 | |
| 4375 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4376 | TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4377 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4378 | ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4379 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4380 | REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4381 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4382 | |
| 4383 | for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++) |
| 4384 | REG_WR16(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4385 | TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4386 | |
| 4387 | /* XSTORM */ |
| 4388 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4389 | x_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4390 | def_sb->x_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4391 | |
| 4392 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4393 | XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4394 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4395 | ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4396 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4397 | REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4398 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4399 | |
| 4400 | for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++) |
| 4401 | REG_WR16(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4402 | XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4403 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4404 | bp->stats_pending = 0; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4405 | bp->set_mac_pending = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4406 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4407 | 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] | 4408 | } |
| 4409 | |
| 4410 | static void bnx2x_update_coalesce(struct bnx2x *bp) |
| 4411 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4412 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4413 | int i; |
| 4414 | |
| 4415 | for_each_queue(bp, i) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4416 | int sb_id = bp->fp[i].sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4417 | |
| 4418 | /* HC_INDEX_U_ETH_RX_CQ_CONS */ |
| 4419 | REG_WR8(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4420 | USTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4421 | U_SB_ETH_RX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4422 | bp->rx_ticks/12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4423 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4424 | USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4425 | U_SB_ETH_RX_CQ_INDEX), |
| 4426 | bp->rx_ticks ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4427 | |
| 4428 | /* HC_INDEX_C_ETH_TX_CQ_CONS */ |
| 4429 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4430 | CSTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4431 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4432 | bp->tx_ticks/12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4433 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4434 | CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4435 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4436 | bp->tx_ticks ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4437 | } |
| 4438 | } |
| 4439 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4440 | static inline void bnx2x_free_tpa_pool(struct bnx2x *bp, |
| 4441 | struct bnx2x_fastpath *fp, int last) |
| 4442 | { |
| 4443 | int i; |
| 4444 | |
| 4445 | for (i = 0; i < last; i++) { |
| 4446 | struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]); |
| 4447 | struct sk_buff *skb = rx_buf->skb; |
| 4448 | |
| 4449 | if (skb == NULL) { |
| 4450 | DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i); |
| 4451 | continue; |
| 4452 | } |
| 4453 | |
| 4454 | if (fp->tpa_state[i] == BNX2X_TPA_START) |
| 4455 | pci_unmap_single(bp->pdev, |
| 4456 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 4457 | bp->rx_buf_size, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4458 | PCI_DMA_FROMDEVICE); |
| 4459 | |
| 4460 | dev_kfree_skb(skb); |
| 4461 | rx_buf->skb = NULL; |
| 4462 | } |
| 4463 | } |
| 4464 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4465 | static void bnx2x_init_rx_rings(struct bnx2x *bp) |
| 4466 | { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4467 | int func = BP_FUNC(bp); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4468 | int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 : |
| 4469 | ETH_MAX_AGGREGATION_QUEUES_E1H; |
| 4470 | u16 ring_prod, cqe_ring_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4471 | int i, j; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4472 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 4473 | bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN; |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 4474 | DP(NETIF_MSG_IFUP, |
| 4475 | "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] | 4476 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4477 | if (bp->flags & TPA_ENABLE_FLAG) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4478 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4479 | for_each_rx_queue(bp, j) { |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4480 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4481 | |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4482 | for (i = 0; i < max_agg_queues; i++) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4483 | fp->tpa_pool[i].skb = |
| 4484 | netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 4485 | if (!fp->tpa_pool[i].skb) { |
| 4486 | BNX2X_ERR("Failed to allocate TPA " |
| 4487 | "skb pool for queue[%d] - " |
| 4488 | "disabling TPA on this " |
| 4489 | "queue!\n", j); |
| 4490 | bnx2x_free_tpa_pool(bp, fp, i); |
| 4491 | fp->disable_tpa = 1; |
| 4492 | break; |
| 4493 | } |
| 4494 | pci_unmap_addr_set((struct sw_rx_bd *) |
| 4495 | &bp->fp->tpa_pool[i], |
| 4496 | mapping, 0); |
| 4497 | fp->tpa_state[i] = BNX2X_TPA_STOP; |
| 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4502 | for_each_rx_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 | fp->rx_bd_cons = 0; |
| 4506 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4507 | fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4508 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4509 | /* "next page" elements initialization */ |
| 4510 | /* SGE ring */ |
| 4511 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 4512 | struct eth_rx_sge *sge; |
| 4513 | |
| 4514 | sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2]; |
| 4515 | sge->addr_hi = |
| 4516 | cpu_to_le32(U64_HI(fp->rx_sge_mapping + |
| 4517 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4518 | sge->addr_lo = |
| 4519 | cpu_to_le32(U64_LO(fp->rx_sge_mapping + |
| 4520 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4521 | } |
| 4522 | |
| 4523 | bnx2x_init_sge_ring_bit_mask(fp); |
| 4524 | |
| 4525 | /* RX BD ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4526 | for (i = 1; i <= NUM_RX_RINGS; i++) { |
| 4527 | struct eth_rx_bd *rx_bd; |
| 4528 | |
| 4529 | rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2]; |
| 4530 | rx_bd->addr_hi = |
| 4531 | cpu_to_le32(U64_HI(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4532 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4533 | rx_bd->addr_lo = |
| 4534 | cpu_to_le32(U64_LO(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4535 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4536 | } |
| 4537 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4538 | /* CQ ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4539 | for (i = 1; i <= NUM_RCQ_RINGS; i++) { |
| 4540 | struct eth_rx_cqe_next_page *nextpg; |
| 4541 | |
| 4542 | nextpg = (struct eth_rx_cqe_next_page *) |
| 4543 | &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1]; |
| 4544 | nextpg->addr_hi = |
| 4545 | cpu_to_le32(U64_HI(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4546 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4547 | nextpg->addr_lo = |
| 4548 | cpu_to_le32(U64_LO(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4549 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4550 | } |
| 4551 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4552 | /* Allocate SGEs and initialize the ring elements */ |
| 4553 | for (i = 0, ring_prod = 0; |
| 4554 | i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4555 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4556 | if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) { |
| 4557 | BNX2X_ERR("was only able to allocate " |
| 4558 | "%d rx sges\n", i); |
| 4559 | BNX2X_ERR("disabling TPA for queue[%d]\n", j); |
| 4560 | /* Cleanup already allocated elements */ |
| 4561 | bnx2x_free_rx_sge_range(bp, fp, ring_prod); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4562 | bnx2x_free_tpa_pool(bp, fp, max_agg_queues); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4563 | fp->disable_tpa = 1; |
| 4564 | ring_prod = 0; |
| 4565 | break; |
| 4566 | } |
| 4567 | ring_prod = NEXT_SGE_IDX(ring_prod); |
| 4568 | } |
| 4569 | fp->rx_sge_prod = ring_prod; |
| 4570 | |
| 4571 | /* Allocate BDs and initialize BD ring */ |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4572 | fp->rx_comp_cons = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4573 | cqe_ring_prod = ring_prod = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4574 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 4575 | if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) { |
| 4576 | BNX2X_ERR("was only able to allocate " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4577 | "%d rx skbs on queue[%d]\n", i, j); |
| 4578 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4579 | break; |
| 4580 | } |
| 4581 | ring_prod = NEXT_RX_IDX(ring_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4582 | cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod); |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 4583 | WARN_ON(ring_prod <= i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4584 | } |
| 4585 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4586 | fp->rx_bd_prod = ring_prod; |
| 4587 | /* must not have more available CQEs than BDs */ |
| 4588 | fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT), |
| 4589 | cqe_ring_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4590 | fp->rx_pkt = fp->rx_calls = 0; |
| 4591 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4592 | /* Warning! |
| 4593 | * this will generate an interrupt (to the TSTORM) |
| 4594 | * must only be done after chip is initialized |
| 4595 | */ |
| 4596 | bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod, |
| 4597 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4598 | if (j != 0) |
| 4599 | continue; |
| 4600 | |
| 4601 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4602 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4603 | U64_LO(fp->rx_comp_mapping)); |
| 4604 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4605 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4606 | U64_HI(fp->rx_comp_mapping)); |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | static void bnx2x_init_tx_ring(struct bnx2x *bp) |
| 4611 | { |
| 4612 | int i, j; |
| 4613 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4614 | for_each_tx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4615 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 4616 | |
| 4617 | for (i = 1; i <= NUM_TX_RINGS; i++) { |
| 4618 | struct eth_tx_bd *tx_bd = |
| 4619 | &fp->tx_desc_ring[TX_DESC_CNT * i - 1]; |
| 4620 | |
| 4621 | tx_bd->addr_hi = |
| 4622 | cpu_to_le32(U64_HI(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4623 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4624 | tx_bd->addr_lo = |
| 4625 | cpu_to_le32(U64_LO(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4626 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | fp->tx_pkt_prod = 0; |
| 4630 | fp->tx_pkt_cons = 0; |
| 4631 | fp->tx_bd_prod = 0; |
| 4632 | fp->tx_bd_cons = 0; |
| 4633 | fp->tx_cons_sb = BNX2X_TX_SB_INDEX; |
| 4634 | fp->tx_pkt = 0; |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
| 4639 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4640 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4641 | |
| 4642 | spin_lock_init(&bp->spq_lock); |
| 4643 | |
| 4644 | bp->spq_left = MAX_SPQ_PENDING; |
| 4645 | bp->spq_prod_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4646 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
| 4647 | bp->spq_prod_bd = bp->spq; |
| 4648 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; |
| 4649 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4650 | 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] | 4651 | U64_LO(bp->spq_mapping)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4652 | REG_WR(bp, |
| 4653 | XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4654 | U64_HI(bp->spq_mapping)); |
| 4655 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4656 | REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4657 | bp->spq_prod_idx); |
| 4658 | } |
| 4659 | |
| 4660 | static void bnx2x_init_context(struct bnx2x *bp) |
| 4661 | { |
| 4662 | int i; |
| 4663 | |
| 4664 | for_each_queue(bp, i) { |
| 4665 | struct eth_context *context = bnx2x_sp(bp, context[i].eth); |
| 4666 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4667 | u8 cl_id = fp->cl_id; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 4668 | u8 sb_id = fp->sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4669 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4670 | context->ustorm_st_context.common.sb_index_numbers = |
| 4671 | BNX2X_RX_SB_INDEX_NUM; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 4672 | context->ustorm_st_context.common.clientId = cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4673 | context->ustorm_st_context.common.status_block_id = sb_id; |
| 4674 | context->ustorm_st_context.common.flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4675 | (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT | |
| 4676 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS); |
| 4677 | context->ustorm_st_context.common.statistics_counter_id = |
| 4678 | cl_id; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4679 | context->ustorm_st_context.common.mc_alignment_log_size = |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 4680 | BNX2X_RX_ALIGN_SHIFT; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4681 | context->ustorm_st_context.common.bd_buff_size = |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 4682 | bp->rx_buf_size; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4683 | context->ustorm_st_context.common.bd_page_base_hi = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4684 | U64_HI(fp->rx_desc_mapping); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4685 | context->ustorm_st_context.common.bd_page_base_lo = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4686 | U64_LO(fp->rx_desc_mapping); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4687 | if (!fp->disable_tpa) { |
| 4688 | context->ustorm_st_context.common.flags |= |
| 4689 | (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA | |
| 4690 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_SGE_RING); |
| 4691 | context->ustorm_st_context.common.sge_buff_size = |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4692 | (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE, |
| 4693 | (u32)0xffff); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4694 | context->ustorm_st_context.common.sge_page_base_hi = |
| 4695 | U64_HI(fp->rx_sge_mapping); |
| 4696 | context->ustorm_st_context.common.sge_page_base_lo = |
| 4697 | U64_LO(fp->rx_sge_mapping); |
| 4698 | } |
| 4699 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4700 | context->ustorm_ag_context.cdu_usage = |
| 4701 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 4702 | CDU_REGION_NUMBER_UCM_AG, |
| 4703 | ETH_CONNECTION_TYPE); |
| 4704 | |
| 4705 | context->xstorm_st_context.tx_bd_page_base_hi = |
| 4706 | U64_HI(fp->tx_desc_mapping); |
| 4707 | context->xstorm_st_context.tx_bd_page_base_lo = |
| 4708 | U64_LO(fp->tx_desc_mapping); |
| 4709 | context->xstorm_st_context.db_data_addr_hi = |
| 4710 | U64_HI(fp->tx_prods_mapping); |
| 4711 | context->xstorm_st_context.db_data_addr_lo = |
| 4712 | U64_LO(fp->tx_prods_mapping); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 4713 | context->xstorm_st_context.statistics_data = (cl_id | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4714 | XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4715 | context->cstorm_st_context.sb_index_number = |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4716 | C_SB_ETH_TX_CQ_INDEX; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4717 | context->cstorm_st_context.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4718 | |
| 4719 | context->xstorm_ag_context.cdu_reserved = |
| 4720 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 4721 | CDU_REGION_NUMBER_XCM_AG, |
| 4722 | ETH_CONNECTION_TYPE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | static void bnx2x_init_ind_table(struct bnx2x *bp) |
| 4727 | { |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 4728 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4729 | int i; |
| 4730 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4731 | if (bp->multi_mode == ETH_RSS_MODE_DISABLED) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4732 | return; |
| 4733 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4734 | DP(NETIF_MSG_IFUP, |
| 4735 | "Initializing indirection table multi_mode %d\n", bp->multi_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4736 | for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4737 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 4738 | TSTORM_INDIRECTION_TABLE_OFFSET(func) + i, |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 4739 | bp->fp->cl_id + (i % bp->num_rx_queues)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4740 | } |
| 4741 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4742 | static void bnx2x_set_client_config(struct bnx2x *bp) |
| 4743 | { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4744 | struct tstorm_eth_client_config tstorm_client = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4745 | int port = BP_PORT(bp); |
| 4746 | int i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4747 | |
Eilon Greenstein | e7799c5 | 2009-01-14 21:30:27 -0800 | [diff] [blame] | 4748 | tstorm_client.mtu = bp->dev->mtu; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4749 | tstorm_client.config_flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4750 | (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE | |
| 4751 | TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4752 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 4753 | if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4754 | tstorm_client.config_flags |= |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4755 | TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4756 | DP(NETIF_MSG_IFUP, "vlan removal enabled\n"); |
| 4757 | } |
| 4758 | #endif |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4759 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4760 | if (bp->flags & TPA_ENABLE_FLAG) { |
| 4761 | tstorm_client.max_sges_for_packet = |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 4762 | SGE_PAGE_ALIGN(tstorm_client.mtu) >> SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4763 | tstorm_client.max_sges_for_packet = |
| 4764 | ((tstorm_client.max_sges_for_packet + |
| 4765 | PAGES_PER_SGE - 1) & (~(PAGES_PER_SGE - 1))) >> |
| 4766 | PAGES_PER_SGE_SHIFT; |
| 4767 | |
| 4768 | tstorm_client.config_flags |= |
| 4769 | TSTORM_ETH_CLIENT_CONFIG_ENABLE_SGE_RING; |
| 4770 | } |
| 4771 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4772 | for_each_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4773 | tstorm_client.statistics_counter_id = bp->fp[i].cl_id; |
| 4774 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4775 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4776 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id), |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4777 | ((u32 *)&tstorm_client)[0]); |
| 4778 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4779 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4, |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4780 | ((u32 *)&tstorm_client)[1]); |
| 4781 | } |
| 4782 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4783 | DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n", |
| 4784 | ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4785 | } |
| 4786 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4787 | static void bnx2x_set_storm_rx_mode(struct bnx2x *bp) |
| 4788 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4789 | struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4790 | int mode = bp->rx_mode; |
| 4791 | int mask = (1 << BP_L_ID(bp)); |
| 4792 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4793 | int i; |
| 4794 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 4795 | 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] | 4796 | |
| 4797 | switch (mode) { |
| 4798 | case BNX2X_RX_MODE_NONE: /* no Rx */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4799 | tstorm_mac_filter.ucast_drop_all = mask; |
| 4800 | tstorm_mac_filter.mcast_drop_all = mask; |
| 4801 | tstorm_mac_filter.bcast_drop_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4802 | break; |
| 4803 | case BNX2X_RX_MODE_NORMAL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4804 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4805 | break; |
| 4806 | case BNX2X_RX_MODE_ALLMULTI: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4807 | tstorm_mac_filter.mcast_accept_all = mask; |
| 4808 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4809 | break; |
| 4810 | case BNX2X_RX_MODE_PROMISC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4811 | tstorm_mac_filter.ucast_accept_all = mask; |
| 4812 | tstorm_mac_filter.mcast_accept_all = mask; |
| 4813 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4814 | break; |
| 4815 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4816 | BNX2X_ERR("BAD rx mode (%d)\n", mode); |
| 4817 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) { |
| 4821 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4822 | TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4823 | ((u32 *)&tstorm_mac_filter)[i]); |
| 4824 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4825 | /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4826 | ((u32 *)&tstorm_mac_filter)[i]); */ |
| 4827 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4828 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4829 | if (mode != BNX2X_RX_MODE_NONE) |
| 4830 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4831 | } |
| 4832 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4833 | static void bnx2x_init_internal_common(struct bnx2x *bp) |
| 4834 | { |
| 4835 | int i; |
| 4836 | |
Yitchak Gertner | 3cdf1db | 2008-08-25 15:24:21 -0700 | [diff] [blame] | 4837 | if (bp->flags & TPA_ENABLE_FLAG) { |
| 4838 | struct tstorm_eth_tpa_exist tpa = {0}; |
| 4839 | |
| 4840 | tpa.tpa_exist = 1; |
| 4841 | |
| 4842 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET, |
| 4843 | ((u32 *)&tpa)[0]); |
| 4844 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET + 4, |
| 4845 | ((u32 *)&tpa)[1]); |
| 4846 | } |
| 4847 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4848 | /* Zero this manually as its initialization is |
| 4849 | currently missing in the initTool */ |
| 4850 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) |
| 4851 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4852 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
| 4853 | } |
| 4854 | |
| 4855 | static void bnx2x_init_internal_port(struct bnx2x *bp) |
| 4856 | { |
| 4857 | int port = BP_PORT(bp); |
| 4858 | |
| 4859 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4860 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4861 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4862 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4863 | } |
| 4864 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 4865 | /* Calculates the sum of vn_min_rates. |
| 4866 | It's needed for further normalizing of the min_rates. |
| 4867 | Returns: |
| 4868 | sum of vn_min_rates. |
| 4869 | or |
| 4870 | 0 - if all the min_rates are 0. |
| 4871 | In the later case fainess algorithm should be deactivated. |
| 4872 | If not all min_rates are zero then those that are zeroes will be set to 1. |
| 4873 | */ |
| 4874 | static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp) |
| 4875 | { |
| 4876 | int all_zero = 1; |
| 4877 | int port = BP_PORT(bp); |
| 4878 | int vn; |
| 4879 | |
| 4880 | bp->vn_weight_sum = 0; |
| 4881 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 4882 | int func = 2*vn + port; |
| 4883 | u32 vn_cfg = |
| 4884 | SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 4885 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 4886 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
| 4887 | |
| 4888 | /* Skip hidden vns */ |
| 4889 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
| 4890 | continue; |
| 4891 | |
| 4892 | /* If min rate is zero - set it to 1 */ |
| 4893 | if (!vn_min_rate) |
| 4894 | vn_min_rate = DEF_MIN_RATE; |
| 4895 | else |
| 4896 | all_zero = 0; |
| 4897 | |
| 4898 | bp->vn_weight_sum += vn_min_rate; |
| 4899 | } |
| 4900 | |
| 4901 | /* ... only if all min rates are zeros - disable fairness */ |
| 4902 | if (all_zero) |
| 4903 | bp->vn_weight_sum = 0; |
| 4904 | } |
| 4905 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4906 | static void bnx2x_init_internal_func(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4907 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4908 | struct tstorm_eth_function_common_config tstorm_config = {0}; |
| 4909 | struct stats_indication_flags stats_flags = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4910 | int port = BP_PORT(bp); |
| 4911 | int func = BP_FUNC(bp); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4912 | int i, j; |
| 4913 | u32 offset; |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4914 | u16 max_agg_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4915 | |
| 4916 | if (is_multi(bp)) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4917 | tstorm_config.config_flags = MULTI_FLAGS(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4918 | tstorm_config.rss_result_mask = MULTI_MASK; |
| 4919 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4920 | if (IS_E1HMF(bp)) |
| 4921 | tstorm_config.config_flags |= |
| 4922 | TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4923 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4924 | tstorm_config.leading_client_id = BP_L_ID(bp); |
| 4925 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4926 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4927 | TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4928 | (*(u32 *)&tstorm_config)); |
| 4929 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 4930 | 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] | 4931 | bnx2x_set_storm_rx_mode(bp); |
| 4932 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4933 | for_each_queue(bp, i) { |
| 4934 | u8 cl_id = bp->fp[i].cl_id; |
| 4935 | |
| 4936 | /* reset xstorm per client statistics */ |
| 4937 | offset = BAR_XSTRORM_INTMEM + |
| 4938 | XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4939 | for (j = 0; |
| 4940 | j < sizeof(struct xstorm_per_client_stats) / 4; j++) |
| 4941 | REG_WR(bp, offset + j*4, 0); |
| 4942 | |
| 4943 | /* reset tstorm per client statistics */ |
| 4944 | offset = BAR_TSTRORM_INTMEM + |
| 4945 | TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4946 | for (j = 0; |
| 4947 | j < sizeof(struct tstorm_per_client_stats) / 4; j++) |
| 4948 | REG_WR(bp, offset + j*4, 0); |
| 4949 | |
| 4950 | /* reset ustorm per client statistics */ |
| 4951 | offset = BAR_USTRORM_INTMEM + |
| 4952 | USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4953 | for (j = 0; |
| 4954 | j < sizeof(struct ustorm_per_client_stats) / 4; j++) |
| 4955 | REG_WR(bp, offset + j*4, 0); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | /* Init statistics related context */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4959 | stats_flags.collect_eth = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4960 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4961 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4962 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4963 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4964 | ((u32 *)&stats_flags)[1]); |
| 4965 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4966 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4967 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4968 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4969 | ((u32 *)&stats_flags)[1]); |
| 4970 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4971 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func), |
| 4972 | ((u32 *)&stats_flags)[0]); |
| 4973 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4, |
| 4974 | ((u32 *)&stats_flags)[1]); |
| 4975 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4976 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4977 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4978 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4979 | ((u32 *)&stats_flags)[1]); |
| 4980 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4981 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 4982 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4983 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4984 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 4985 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 4986 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 4987 | |
| 4988 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 4989 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4990 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4991 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 4992 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 4993 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4994 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4995 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4996 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4997 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4998 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4999 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 5000 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 5001 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5002 | if (CHIP_IS_E1H(bp)) { |
| 5003 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET, |
| 5004 | IS_E1HMF(bp)); |
| 5005 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET, |
| 5006 | IS_E1HMF(bp)); |
| 5007 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET, |
| 5008 | IS_E1HMF(bp)); |
| 5009 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET, |
| 5010 | IS_E1HMF(bp)); |
| 5011 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5012 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func), |
| 5013 | bp->e1hov); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 5016 | /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */ |
| 5017 | max_agg_size = |
| 5018 | min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) * |
| 5019 | SGE_PAGE_SIZE * PAGES_PER_SGE), |
| 5020 | (u32)0xffff); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5021 | for_each_rx_queue(bp, i) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5022 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5023 | |
| 5024 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5025 | USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5026 | U64_LO(fp->rx_comp_mapping)); |
| 5027 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5028 | USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5029 | U64_HI(fp->rx_comp_mapping)); |
| 5030 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5031 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5032 | USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5033 | max_agg_size); |
| 5034 | } |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 5035 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5036 | /* dropless flow control */ |
| 5037 | if (CHIP_IS_E1H(bp)) { |
| 5038 | struct ustorm_eth_rx_pause_data_e1h rx_pause = {0}; |
| 5039 | |
| 5040 | rx_pause.bd_thr_low = 250; |
| 5041 | rx_pause.cqe_thr_low = 250; |
| 5042 | rx_pause.cos = 1; |
| 5043 | rx_pause.sge_thr_low = 0; |
| 5044 | rx_pause.bd_thr_high = 350; |
| 5045 | rx_pause.cqe_thr_high = 350; |
| 5046 | rx_pause.sge_thr_high = 0; |
| 5047 | |
| 5048 | for_each_rx_queue(bp, i) { |
| 5049 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5050 | |
| 5051 | if (!fp->disable_tpa) { |
| 5052 | rx_pause.sge_thr_low = 150; |
| 5053 | rx_pause.sge_thr_high = 250; |
| 5054 | } |
| 5055 | |
| 5056 | |
| 5057 | offset = BAR_USTRORM_INTMEM + |
| 5058 | USTORM_ETH_RING_PAUSE_DATA_OFFSET(port, |
| 5059 | fp->cl_id); |
| 5060 | for (j = 0; |
| 5061 | j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4; |
| 5062 | j++) |
| 5063 | REG_WR(bp, offset + j*4, |
| 5064 | ((u32 *)&rx_pause)[j]); |
| 5065 | } |
| 5066 | } |
| 5067 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 5068 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); |
| 5069 | |
| 5070 | /* Init rate shaping and fairness contexts */ |
| 5071 | if (IS_E1HMF(bp)) { |
| 5072 | int vn; |
| 5073 | |
| 5074 | /* During init there is no active link |
| 5075 | Until link is up, set link rate to 10Gbps */ |
| 5076 | bp->link_vars.line_speed = SPEED_10000; |
| 5077 | bnx2x_init_port_minmax(bp); |
| 5078 | |
| 5079 | bnx2x_calc_vn_weight_sum(bp); |
| 5080 | |
| 5081 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
| 5082 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 5083 | |
| 5084 | /* Enable rate shaping and fairness */ |
| 5085 | bp->cmng.flags.cmng_enables = |
| 5086 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
| 5087 | if (bp->vn_weight_sum) |
| 5088 | bp->cmng.flags.cmng_enables |= |
| 5089 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
| 5090 | else |
| 5091 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" |
| 5092 | " fairness will be disabled\n"); |
| 5093 | } else { |
| 5094 | /* rate shaping and fairness are disabled */ |
| 5095 | DP(NETIF_MSG_IFUP, |
| 5096 | "single function mode minmax will be disabled\n"); |
| 5097 | } |
| 5098 | |
| 5099 | |
| 5100 | /* Store it to internal memory */ |
| 5101 | if (bp->port.pmf) |
| 5102 | for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 5103 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 5104 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4, |
| 5105 | ((u32 *)(&bp->cmng))[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5106 | } |
| 5107 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5108 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
| 5109 | { |
| 5110 | switch (load_code) { |
| 5111 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 5112 | bnx2x_init_internal_common(bp); |
| 5113 | /* no break */ |
| 5114 | |
| 5115 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 5116 | bnx2x_init_internal_port(bp); |
| 5117 | /* no break */ |
| 5118 | |
| 5119 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 5120 | bnx2x_init_internal_func(bp); |
| 5121 | break; |
| 5122 | |
| 5123 | default: |
| 5124 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 5125 | break; |
| 5126 | } |
| 5127 | } |
| 5128 | |
| 5129 | static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5130 | { |
| 5131 | int i; |
| 5132 | |
| 5133 | for_each_queue(bp, i) { |
| 5134 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5135 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5136 | fp->bp = bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5137 | fp->state = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5138 | fp->index = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5139 | fp->cl_id = BP_L_ID(bp) + i; |
| 5140 | fp->sb_id = fp->cl_id; |
| 5141 | DP(NETIF_MSG_IFUP, |
| 5142 | "bnx2x_init_sb(%p,%p) index %d cl_id %d sb %d\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5143 | bp, fp->status_blk, i, fp->cl_id, fp->sb_id); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5144 | bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping, |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5145 | fp->sb_id); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5146 | bnx2x_update_fpsb_idx(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5147 | } |
| 5148 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5149 | bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping, |
| 5150 | DEF_SB_ID); |
| 5151 | bnx2x_update_dsb_idx(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5152 | bnx2x_update_coalesce(bp); |
| 5153 | bnx2x_init_rx_rings(bp); |
| 5154 | bnx2x_init_tx_ring(bp); |
| 5155 | bnx2x_init_sp_ring(bp); |
| 5156 | bnx2x_init_context(bp); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5157 | bnx2x_init_internal(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5158 | bnx2x_init_ind_table(bp); |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5159 | bnx2x_stats_init(bp); |
| 5160 | |
| 5161 | /* At this point, we are ready for interrupts */ |
| 5162 | atomic_set(&bp->intr_sem, 0); |
| 5163 | |
| 5164 | /* flush all before enabling interrupts */ |
| 5165 | mb(); |
| 5166 | mmiowb(); |
| 5167 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 5168 | bnx2x_int_enable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | /* end of nic init */ |
| 5172 | |
| 5173 | /* |
| 5174 | * gzip service functions |
| 5175 | */ |
| 5176 | |
| 5177 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
| 5178 | { |
| 5179 | bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE, |
| 5180 | &bp->gunzip_mapping); |
| 5181 | if (bp->gunzip_buf == NULL) |
| 5182 | goto gunzip_nomem1; |
| 5183 | |
| 5184 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); |
| 5185 | if (bp->strm == NULL) |
| 5186 | goto gunzip_nomem2; |
| 5187 | |
| 5188 | bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), |
| 5189 | GFP_KERNEL); |
| 5190 | if (bp->strm->workspace == NULL) |
| 5191 | goto gunzip_nomem3; |
| 5192 | |
| 5193 | return 0; |
| 5194 | |
| 5195 | gunzip_nomem3: |
| 5196 | kfree(bp->strm); |
| 5197 | bp->strm = NULL; |
| 5198 | |
| 5199 | gunzip_nomem2: |
| 5200 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5201 | bp->gunzip_mapping); |
| 5202 | bp->gunzip_buf = NULL; |
| 5203 | |
| 5204 | gunzip_nomem1: |
| 5205 | printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5206 | " un-compression\n", bp->dev->name); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5207 | return -ENOMEM; |
| 5208 | } |
| 5209 | |
| 5210 | static void bnx2x_gunzip_end(struct bnx2x *bp) |
| 5211 | { |
| 5212 | kfree(bp->strm->workspace); |
| 5213 | |
| 5214 | kfree(bp->strm); |
| 5215 | bp->strm = NULL; |
| 5216 | |
| 5217 | if (bp->gunzip_buf) { |
| 5218 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5219 | bp->gunzip_mapping); |
| 5220 | bp->gunzip_buf = NULL; |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len) |
| 5225 | { |
| 5226 | int n, rc; |
| 5227 | |
| 5228 | /* check gzip header */ |
| 5229 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) |
| 5230 | return -EINVAL; |
| 5231 | |
| 5232 | n = 10; |
| 5233 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5234 | #define FNAME 0x8 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5235 | |
| 5236 | if (zbuf[3] & FNAME) |
| 5237 | while ((zbuf[n++] != 0) && (n < len)); |
| 5238 | |
| 5239 | bp->strm->next_in = zbuf + n; |
| 5240 | bp->strm->avail_in = len - n; |
| 5241 | bp->strm->next_out = bp->gunzip_buf; |
| 5242 | bp->strm->avail_out = FW_BUF_SIZE; |
| 5243 | |
| 5244 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); |
| 5245 | if (rc != Z_OK) |
| 5246 | return rc; |
| 5247 | |
| 5248 | rc = zlib_inflate(bp->strm, Z_FINISH); |
| 5249 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) |
| 5250 | printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n", |
| 5251 | bp->dev->name, bp->strm->msg); |
| 5252 | |
| 5253 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); |
| 5254 | if (bp->gunzip_outlen & 0x3) |
| 5255 | printk(KERN_ERR PFX "%s: Firmware decompression error:" |
| 5256 | " gunzip_outlen (%d) not aligned\n", |
| 5257 | bp->dev->name, bp->gunzip_outlen); |
| 5258 | bp->gunzip_outlen >>= 2; |
| 5259 | |
| 5260 | zlib_inflateEnd(bp->strm); |
| 5261 | |
| 5262 | if (rc == Z_STREAM_END) |
| 5263 | return 0; |
| 5264 | |
| 5265 | return rc; |
| 5266 | } |
| 5267 | |
| 5268 | /* nic load/unload */ |
| 5269 | |
| 5270 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5271 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5272 | */ |
| 5273 | |
| 5274 | /* send a NIG loopback debug packet */ |
| 5275 | static void bnx2x_lb_pckt(struct bnx2x *bp) |
| 5276 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5277 | u32 wb_write[3]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5278 | |
| 5279 | /* Ethernet source and destination addresses */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5280 | wb_write[0] = 0x55555555; |
| 5281 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5282 | wb_write[2] = 0x20; /* SOP */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5283 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5284 | |
| 5285 | /* NON-IP protocol */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5286 | wb_write[0] = 0x09000000; |
| 5287 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5288 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5289 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /* some of the internal memories |
| 5293 | * are not directly readable from the driver |
| 5294 | * to test them we send debug packets |
| 5295 | */ |
| 5296 | static int bnx2x_int_mem_test(struct bnx2x *bp) |
| 5297 | { |
| 5298 | int factor; |
| 5299 | int count, i; |
| 5300 | u32 val = 0; |
| 5301 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5302 | if (CHIP_REV_IS_FPGA(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5303 | factor = 120; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5304 | else if (CHIP_REV_IS_EMUL(bp)) |
| 5305 | factor = 200; |
| 5306 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5307 | factor = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5308 | |
| 5309 | DP(NETIF_MSG_HW, "start part1\n"); |
| 5310 | |
| 5311 | /* Disable inputs of parser neighbor blocks */ |
| 5312 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5313 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5314 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5315 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5316 | |
| 5317 | /* Write 0 to parser credits for CFC search request */ |
| 5318 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5319 | |
| 5320 | /* send Ethernet packet */ |
| 5321 | bnx2x_lb_pckt(bp); |
| 5322 | |
| 5323 | /* TODO do i reset NIG statistic? */ |
| 5324 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5325 | count = 1000 * factor; |
| 5326 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5327 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5328 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5329 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5330 | if (val == 0x10) |
| 5331 | break; |
| 5332 | |
| 5333 | msleep(10); |
| 5334 | count--; |
| 5335 | } |
| 5336 | if (val != 0x10) { |
| 5337 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5338 | return -1; |
| 5339 | } |
| 5340 | |
| 5341 | /* Wait until PRS register shows 1 packet */ |
| 5342 | count = 1000 * factor; |
| 5343 | while (count) { |
| 5344 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5345 | if (val == 1) |
| 5346 | break; |
| 5347 | |
| 5348 | msleep(10); |
| 5349 | count--; |
| 5350 | } |
| 5351 | if (val != 0x1) { |
| 5352 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5353 | return -2; |
| 5354 | } |
| 5355 | |
| 5356 | /* Reset and init BRB, PRS */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5357 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5358 | msleep(50); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5359 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5360 | msleep(50); |
| 5361 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
| 5362 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
| 5363 | |
| 5364 | DP(NETIF_MSG_HW, "part2\n"); |
| 5365 | |
| 5366 | /* Disable inputs of parser neighbor blocks */ |
| 5367 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5368 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5369 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5370 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5371 | |
| 5372 | /* Write 0 to parser credits for CFC search request */ |
| 5373 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5374 | |
| 5375 | /* send 10 Ethernet packets */ |
| 5376 | for (i = 0; i < 10; i++) |
| 5377 | bnx2x_lb_pckt(bp); |
| 5378 | |
| 5379 | /* Wait until NIG register shows 10 + 1 |
| 5380 | packets of size 11*0x10 = 0xb0 */ |
| 5381 | count = 1000 * factor; |
| 5382 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5383 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5384 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5385 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5386 | if (val == 0xb0) |
| 5387 | break; |
| 5388 | |
| 5389 | msleep(10); |
| 5390 | count--; |
| 5391 | } |
| 5392 | if (val != 0xb0) { |
| 5393 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5394 | return -3; |
| 5395 | } |
| 5396 | |
| 5397 | /* Wait until PRS register shows 2 packets */ |
| 5398 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5399 | if (val != 2) |
| 5400 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5401 | |
| 5402 | /* Write 1 to parser credits for CFC search request */ |
| 5403 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); |
| 5404 | |
| 5405 | /* Wait until PRS register shows 3 packets */ |
| 5406 | msleep(10 * factor); |
| 5407 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5408 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5409 | if (val != 3) |
| 5410 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5411 | |
| 5412 | /* clear NIG EOP FIFO */ |
| 5413 | for (i = 0; i < 11; i++) |
| 5414 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); |
| 5415 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); |
| 5416 | if (val != 1) { |
| 5417 | BNX2X_ERR("clear of NIG failed\n"); |
| 5418 | return -4; |
| 5419 | } |
| 5420 | |
| 5421 | /* Reset and init BRB, PRS, NIG */ |
| 5422 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
| 5423 | msleep(50); |
| 5424 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
| 5425 | msleep(50); |
| 5426 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
| 5427 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
| 5428 | #ifndef BCM_ISCSI |
| 5429 | /* set NIC mode */ |
| 5430 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 5431 | #endif |
| 5432 | |
| 5433 | /* Enable inputs of parser neighbor blocks */ |
| 5434 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); |
| 5435 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); |
| 5436 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5437 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5438 | |
| 5439 | DP(NETIF_MSG_HW, "done\n"); |
| 5440 | |
| 5441 | return 0; /* OK */ |
| 5442 | } |
| 5443 | |
| 5444 | static void enable_blocks_attention(struct bnx2x *bp) |
| 5445 | { |
| 5446 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
| 5447 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); |
| 5448 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5449 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5450 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
| 5451 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); |
| 5452 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); |
| 5453 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); |
| 5454 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5455 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
| 5456 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5457 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
| 5458 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); |
| 5459 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5460 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
| 5461 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5462 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
| 5463 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); |
| 5464 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); |
| 5465 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5466 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
| 5467 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ |
| 5468 | if (CHIP_REV_IS_FPGA(bp)) |
| 5469 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); |
| 5470 | else |
| 5471 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5472 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
| 5473 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); |
| 5474 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5475 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
| 5476 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5477 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
| 5478 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5479 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
| 5480 | 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] | 5481 | } |
| 5482 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5483 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5484 | static void bnx2x_reset_common(struct bnx2x *bp) |
| 5485 | { |
| 5486 | /* reset_common */ |
| 5487 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5488 | 0xd3ffff7f); |
| 5489 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403); |
| 5490 | } |
| 5491 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5492 | static int bnx2x_init_common(struct bnx2x *bp) |
| 5493 | { |
| 5494 | u32 val, i; |
| 5495 | |
| 5496 | DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp)); |
| 5497 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5498 | bnx2x_reset_common(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5499 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
| 5500 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc); |
| 5501 | |
| 5502 | bnx2x_init_block(bp, MISC_COMMON_START, MISC_COMMON_END); |
| 5503 | if (CHIP_IS_E1H(bp)) |
| 5504 | REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp)); |
| 5505 | |
| 5506 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100); |
| 5507 | msleep(30); |
| 5508 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0); |
| 5509 | |
| 5510 | bnx2x_init_block(bp, PXP_COMMON_START, PXP_COMMON_END); |
| 5511 | if (CHIP_IS_E1(bp)) { |
| 5512 | /* enable HW interrupt from PXP on USDM overflow |
| 5513 | bit 16 on INT_MASK_0 */ |
| 5514 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5515 | } |
| 5516 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5517 | bnx2x_init_block(bp, PXP2_COMMON_START, PXP2_COMMON_END); |
| 5518 | bnx2x_init_pxp(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5519 | |
| 5520 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5521 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
| 5522 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); |
| 5523 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); |
| 5524 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); |
| 5525 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5526 | /* make sure this value is 0 */ |
| 5527 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5528 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5529 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ |
| 5530 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); |
| 5531 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); |
| 5532 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); |
| 5533 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5534 | #endif |
| 5535 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5536 | REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5537 | #ifdef BCM_ISCSI |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5538 | REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5); |
| 5539 | REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5); |
| 5540 | REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5541 | #endif |
| 5542 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5543 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
| 5544 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5545 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5546 | /* let the HW do it's magic ... */ |
| 5547 | msleep(100); |
| 5548 | /* finish PXP init */ |
| 5549 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); |
| 5550 | if (val != 1) { |
| 5551 | BNX2X_ERR("PXP2 CFG failed\n"); |
| 5552 | return -EBUSY; |
| 5553 | } |
| 5554 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); |
| 5555 | if (val != 1) { |
| 5556 | BNX2X_ERR("PXP2 RD_INIT failed\n"); |
| 5557 | return -EBUSY; |
| 5558 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5559 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5560 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
| 5561 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5562 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5563 | bnx2x_init_block(bp, DMAE_COMMON_START, DMAE_COMMON_END); |
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 | /* clean the DMAE memory */ |
| 5566 | bp->dmae_ready = 1; |
| 5567 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5568 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5569 | bnx2x_init_block(bp, TCM_COMMON_START, TCM_COMMON_END); |
| 5570 | bnx2x_init_block(bp, UCM_COMMON_START, UCM_COMMON_END); |
| 5571 | bnx2x_init_block(bp, CCM_COMMON_START, CCM_COMMON_END); |
| 5572 | bnx2x_init_block(bp, XCM_COMMON_START, XCM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5573 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5574 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
| 5575 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); |
| 5576 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); |
| 5577 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); |
| 5578 | |
| 5579 | bnx2x_init_block(bp, QM_COMMON_START, QM_COMMON_END); |
| 5580 | /* soft reset pulse */ |
| 5581 | REG_WR(bp, QM_REG_SOFT_RESET, 1); |
| 5582 | REG_WR(bp, QM_REG_SOFT_RESET, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5583 | |
| 5584 | #ifdef BCM_ISCSI |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5585 | bnx2x_init_block(bp, TIMERS_COMMON_START, TIMERS_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5586 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5587 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5588 | bnx2x_init_block(bp, DQ_COMMON_START, DQ_COMMON_END); |
| 5589 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT); |
| 5590 | if (!CHIP_REV_IS_SLOW(bp)) { |
| 5591 | /* enable hw interrupt from doorbell Q */ |
| 5592 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5593 | } |
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 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5596 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5597 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5598 | /* set NIC mode */ |
| 5599 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5600 | if (CHIP_IS_E1H(bp)) |
| 5601 | REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5602 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5603 | bnx2x_init_block(bp, TSDM_COMMON_START, TSDM_COMMON_END); |
| 5604 | bnx2x_init_block(bp, CSDM_COMMON_START, CSDM_COMMON_END); |
| 5605 | bnx2x_init_block(bp, USDM_COMMON_START, USDM_COMMON_END); |
| 5606 | bnx2x_init_block(bp, XSDM_COMMON_START, XSDM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5607 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5608 | if (CHIP_IS_E1H(bp)) { |
| 5609 | bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0, |
| 5610 | STORM_INTMEM_SIZE_E1H/2); |
| 5611 | bnx2x_init_fill(bp, |
| 5612 | TSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5613 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5614 | bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0, |
| 5615 | STORM_INTMEM_SIZE_E1H/2); |
| 5616 | bnx2x_init_fill(bp, |
| 5617 | CSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5618 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5619 | bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0, |
| 5620 | STORM_INTMEM_SIZE_E1H/2); |
| 5621 | bnx2x_init_fill(bp, |
| 5622 | XSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5623 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5624 | bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0, |
| 5625 | STORM_INTMEM_SIZE_E1H/2); |
| 5626 | bnx2x_init_fill(bp, |
| 5627 | USTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5628 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5629 | } else { /* E1 */ |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5630 | bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0, |
| 5631 | STORM_INTMEM_SIZE_E1); |
| 5632 | bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0, |
| 5633 | STORM_INTMEM_SIZE_E1); |
| 5634 | bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0, |
| 5635 | STORM_INTMEM_SIZE_E1); |
| 5636 | bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0, |
| 5637 | STORM_INTMEM_SIZE_E1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5638 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5639 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5640 | bnx2x_init_block(bp, TSEM_COMMON_START, TSEM_COMMON_END); |
| 5641 | bnx2x_init_block(bp, USEM_COMMON_START, USEM_COMMON_END); |
| 5642 | bnx2x_init_block(bp, CSEM_COMMON_START, CSEM_COMMON_END); |
| 5643 | bnx2x_init_block(bp, XSEM_COMMON_START, XSEM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5644 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5645 | /* sync semi rtc */ |
| 5646 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5647 | 0x80000000); |
| 5648 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 5649 | 0x80000000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5650 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5651 | bnx2x_init_block(bp, UPB_COMMON_START, UPB_COMMON_END); |
| 5652 | bnx2x_init_block(bp, XPB_COMMON_START, XPB_COMMON_END); |
| 5653 | bnx2x_init_block(bp, PBF_COMMON_START, PBF_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5654 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5655 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
| 5656 | for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) { |
| 5657 | REG_WR(bp, i, 0xc0cac01a); |
| 5658 | /* TODO: replace with something meaningful */ |
| 5659 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5660 | bnx2x_init_block(bp, SRCH_COMMON_START, SRCH_COMMON_END); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5661 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5662 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5663 | if (sizeof(union cdu_context) != 1024) |
| 5664 | /* we currently assume that a context is 1024 bytes */ |
| 5665 | printk(KERN_ALERT PFX "please adjust the size of" |
| 5666 | " cdu_context(%ld)\n", (long)sizeof(union cdu_context)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5667 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5668 | bnx2x_init_block(bp, CDU_COMMON_START, CDU_COMMON_END); |
| 5669 | val = (4 << 24) + (0 << 12) + 1024; |
| 5670 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); |
| 5671 | if (CHIP_IS_E1(bp)) { |
| 5672 | /* !!! fix pxp client crdit until excel update */ |
| 5673 | REG_WR(bp, CDU_REG_CDU_DEBUG, 0x264); |
| 5674 | REG_WR(bp, CDU_REG_CDU_DEBUG, 0); |
| 5675 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5676 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5677 | bnx2x_init_block(bp, CFC_COMMON_START, CFC_COMMON_END); |
| 5678 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5679 | /* enable context validation interrupt from CFC */ |
| 5680 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5681 | |
| 5682 | /* set the thresholds to prevent CFC/CDU race */ |
| 5683 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5684 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5685 | bnx2x_init_block(bp, HC_COMMON_START, HC_COMMON_END); |
| 5686 | bnx2x_init_block(bp, MISC_AEU_COMMON_START, MISC_AEU_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5687 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5688 | /* PXPCS COMMON comes here */ |
| 5689 | /* Reset PCIE errors for debug */ |
| 5690 | REG_WR(bp, 0x2814, 0xffffffff); |
| 5691 | REG_WR(bp, 0x3820, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5692 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5693 | /* EMAC0 COMMON comes here */ |
| 5694 | /* EMAC1 COMMON comes here */ |
| 5695 | /* DBU COMMON comes here */ |
| 5696 | /* DBG COMMON comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5697 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5698 | bnx2x_init_block(bp, NIG_COMMON_START, NIG_COMMON_END); |
| 5699 | if (CHIP_IS_E1H(bp)) { |
| 5700 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp)); |
| 5701 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp)); |
| 5702 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5703 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5704 | if (CHIP_REV_IS_SLOW(bp)) |
| 5705 | msleep(200); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5706 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5707 | /* finish CFC init */ |
| 5708 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); |
| 5709 | if (val != 1) { |
| 5710 | BNX2X_ERR("CFC LL_INIT failed\n"); |
| 5711 | return -EBUSY; |
| 5712 | } |
| 5713 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); |
| 5714 | if (val != 1) { |
| 5715 | BNX2X_ERR("CFC AC_INIT failed\n"); |
| 5716 | return -EBUSY; |
| 5717 | } |
| 5718 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); |
| 5719 | if (val != 1) { |
| 5720 | BNX2X_ERR("CFC CAM_INIT failed\n"); |
| 5721 | return -EBUSY; |
| 5722 | } |
| 5723 | REG_WR(bp, CFC_REG_DEBUG0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5724 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5725 | /* read NIG statistic |
| 5726 | to see if this is our first up since powerup */ |
| 5727 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5728 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5729 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5730 | /* do internal memory self test */ |
| 5731 | if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) { |
| 5732 | BNX2X_ERR("internal mem self test failed\n"); |
| 5733 | return -EBUSY; |
| 5734 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5735 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5736 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 5737 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
| 5738 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
| 5739 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
| 5740 | bp->port.need_hw_lock = 1; |
| 5741 | break; |
| 5742 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5743 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5744 | /* Fan failure is indicated by SPIO 5 */ |
| 5745 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, |
| 5746 | MISC_REGISTERS_SPIO_INPUT_HI_Z); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5747 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5748 | /* set to active low mode */ |
| 5749 | val = REG_RD(bp, MISC_REG_SPIO_INT); |
| 5750 | val |= ((1 << MISC_REGISTERS_SPIO_5) << |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5751 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5752 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5753 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5754 | /* enable interrupt to signal the IGU */ |
| 5755 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 5756 | val |= (1 << MISC_REGISTERS_SPIO_5); |
| 5757 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
| 5758 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5759 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5760 | default: |
| 5761 | break; |
| 5762 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5763 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5764 | /* clear PXP2 attentions */ |
| 5765 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5766 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5767 | enable_blocks_attention(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5768 | |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5769 | if (!BP_NOMCP(bp)) { |
| 5770 | bnx2x_acquire_phy_lock(bp); |
| 5771 | bnx2x_common_init_phy(bp, bp->common.shmem_base); |
| 5772 | bnx2x_release_phy_lock(bp); |
| 5773 | } else |
| 5774 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
| 5775 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5776 | return 0; |
| 5777 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5778 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5779 | static int bnx2x_init_port(struct bnx2x *bp) |
| 5780 | { |
| 5781 | int port = BP_PORT(bp); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5782 | u32 low, high; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5783 | u32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5784 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5785 | DP(BNX2X_MSG_MCP, "starting port init port %x\n", port); |
| 5786 | |
| 5787 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5788 | |
| 5789 | /* Port PXP comes here */ |
| 5790 | /* Port PXP2 comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5791 | #ifdef BCM_ISCSI |
| 5792 | /* Port0 1 |
| 5793 | * Port1 385 */ |
| 5794 | i++; |
| 5795 | wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping); |
| 5796 | wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping); |
| 5797 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5798 | REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5799 | |
| 5800 | /* Port0 2 |
| 5801 | * Port1 386 */ |
| 5802 | i++; |
| 5803 | wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping); |
| 5804 | wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping); |
| 5805 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5806 | REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5807 | |
| 5808 | /* Port0 3 |
| 5809 | * Port1 387 */ |
| 5810 | i++; |
| 5811 | wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping); |
| 5812 | wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping); |
| 5813 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5814 | REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5815 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5816 | /* Port CMs come here */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5817 | bnx2x_init_block(bp, (port ? XCM_PORT1_START : XCM_PORT0_START), |
| 5818 | (port ? XCM_PORT1_END : XCM_PORT0_END)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5819 | |
| 5820 | /* Port QM comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5821 | #ifdef BCM_ISCSI |
| 5822 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20); |
| 5823 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31); |
| 5824 | |
| 5825 | bnx2x_init_block(bp, func ? TIMERS_PORT1_START : TIMERS_PORT0_START, |
| 5826 | func ? TIMERS_PORT1_END : TIMERS_PORT0_END); |
| 5827 | #endif |
| 5828 | /* Port DQ comes here */ |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5829 | |
| 5830 | bnx2x_init_block(bp, (port ? BRB1_PORT1_START : BRB1_PORT0_START), |
| 5831 | (port ? BRB1_PORT1_END : BRB1_PORT0_END)); |
| 5832 | if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) { |
| 5833 | /* no pause for emulation and FPGA */ |
| 5834 | low = 0; |
| 5835 | high = 513; |
| 5836 | } else { |
| 5837 | if (IS_E1HMF(bp)) |
| 5838 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); |
| 5839 | else if (bp->dev->mtu > 4096) { |
| 5840 | if (bp->flags & ONE_PORT_FLAG) |
| 5841 | low = 160; |
| 5842 | else { |
| 5843 | val = bp->dev->mtu; |
| 5844 | /* (24*1024 + val*4)/256 */ |
| 5845 | low = 96 + (val/64) + ((val % 64) ? 1 : 0); |
| 5846 | } |
| 5847 | } else |
| 5848 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); |
| 5849 | high = low + 56; /* 14*1024/256 */ |
| 5850 | } |
| 5851 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
| 5852 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); |
| 5853 | |
| 5854 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5855 | /* Port PRS comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5856 | /* Port TSDM comes here */ |
| 5857 | /* Port CSDM comes here */ |
| 5858 | /* Port USDM comes here */ |
| 5859 | /* Port XSDM comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5860 | bnx2x_init_block(bp, port ? TSEM_PORT1_START : TSEM_PORT0_START, |
| 5861 | port ? TSEM_PORT1_END : TSEM_PORT0_END); |
| 5862 | bnx2x_init_block(bp, port ? USEM_PORT1_START : USEM_PORT0_START, |
| 5863 | port ? USEM_PORT1_END : USEM_PORT0_END); |
| 5864 | bnx2x_init_block(bp, port ? CSEM_PORT1_START : CSEM_PORT0_START, |
| 5865 | port ? CSEM_PORT1_END : CSEM_PORT0_END); |
| 5866 | bnx2x_init_block(bp, port ? XSEM_PORT1_START : XSEM_PORT0_START, |
| 5867 | port ? XSEM_PORT1_END : XSEM_PORT0_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5868 | /* Port UPB comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5869 | /* Port XPB comes here */ |
| 5870 | |
| 5871 | bnx2x_init_block(bp, port ? PBF_PORT1_START : PBF_PORT0_START, |
| 5872 | port ? PBF_PORT1_END : PBF_PORT0_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5873 | |
| 5874 | /* configure PBF to work without PAUSE mtu 9000 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5875 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5876 | |
| 5877 | /* update threshold */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5878 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5879 | /* update init credit */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5880 | 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] | 5881 | |
| 5882 | /* probe changes */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5883 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5884 | msleep(5); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5885 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5886 | |
| 5887 | #ifdef BCM_ISCSI |
| 5888 | /* tell the searcher where the T2 table is */ |
| 5889 | REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64); |
| 5890 | |
| 5891 | wb_write[0] = U64_LO(bp->t2_mapping); |
| 5892 | wb_write[1] = U64_HI(bp->t2_mapping); |
| 5893 | REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2); |
| 5894 | wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64); |
| 5895 | wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64); |
| 5896 | REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2); |
| 5897 | |
| 5898 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10); |
| 5899 | /* Port SRCH comes here */ |
| 5900 | #endif |
| 5901 | /* Port CDU comes here */ |
| 5902 | /* Port CFC comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5903 | |
| 5904 | if (CHIP_IS_E1(bp)) { |
| 5905 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 5906 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 5907 | } |
| 5908 | bnx2x_init_block(bp, port ? HC_PORT1_START : HC_PORT0_START, |
| 5909 | port ? HC_PORT1_END : HC_PORT0_END); |
| 5910 | |
| 5911 | bnx2x_init_block(bp, port ? MISC_AEU_PORT1_START : |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5912 | MISC_AEU_PORT0_START, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5913 | port ? MISC_AEU_PORT1_END : MISC_AEU_PORT0_END); |
| 5914 | /* init aeu_mask_attn_func_0/1: |
| 5915 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use |
| 5916 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF |
| 5917 | * bits 4-7 are used for "per vn group attention" */ |
| 5918 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, |
| 5919 | (IS_E1HMF(bp) ? 0xF7 : 0x7)); |
| 5920 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5921 | /* Port PXPCS comes here */ |
| 5922 | /* Port EMAC0 comes here */ |
| 5923 | /* Port EMAC1 comes here */ |
| 5924 | /* Port DBU comes here */ |
| 5925 | /* Port DBG comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5926 | bnx2x_init_block(bp, port ? NIG_PORT1_START : NIG_PORT0_START, |
| 5927 | port ? NIG_PORT1_END : NIG_PORT0_END); |
| 5928 | |
| 5929 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); |
| 5930 | |
| 5931 | if (CHIP_IS_E1H(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5932 | /* 0x2 disable e1hov, 0x1 enable */ |
| 5933 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
| 5934 | (IS_E1HMF(bp) ? 0x1 : 0x2)); |
| 5935 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5936 | /* support pause requests from USDM, TSDM and BRB */ |
| 5937 | REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0 + port*4, 0x7); |
| 5938 | |
| 5939 | { |
| 5940 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); |
| 5941 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); |
| 5942 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); |
| 5943 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5944 | } |
| 5945 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5946 | /* Port MCP comes here */ |
| 5947 | /* Port DMAE comes here */ |
| 5948 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5949 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 5950 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
| 5951 | { |
| 5952 | u32 swap_val, swap_override, aeu_gpio_mask, offset; |
| 5953 | |
| 5954 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3, |
| 5955 | MISC_REGISTERS_GPIO_INPUT_HI_Z, port); |
| 5956 | |
| 5957 | /* The GPIO should be swapped if the swap register is |
| 5958 | set and active */ |
| 5959 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 5960 | swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
| 5961 | |
| 5962 | /* Select function upon port-swap configuration */ |
| 5963 | if (port == 0) { |
| 5964 | offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0; |
| 5965 | aeu_gpio_mask = (swap_val && swap_override) ? |
| 5966 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 : |
| 5967 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0; |
| 5968 | } else { |
| 5969 | offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0; |
| 5970 | aeu_gpio_mask = (swap_val && swap_override) ? |
| 5971 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 : |
| 5972 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1; |
| 5973 | } |
| 5974 | val = REG_RD(bp, offset); |
| 5975 | /* add GPIO3 to group */ |
| 5976 | val |= aeu_gpio_mask; |
| 5977 | REG_WR(bp, offset, val); |
| 5978 | } |
| 5979 | break; |
| 5980 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5981 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5982 | /* add SPIO 5 to group 0 */ |
| 5983 | val = REG_RD(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 5984 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
| 5985 | REG_WR(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0, val); |
| 5986 | break; |
| 5987 | |
| 5988 | default: |
| 5989 | break; |
| 5990 | } |
| 5991 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 5992 | bnx2x__link_reset(bp); |
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 | return 0; |
| 5995 | } |
| 5996 | |
| 5997 | #define ILT_PER_FUNC (768/2) |
| 5998 | #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC) |
| 5999 | /* the phys address is shifted right 12 bits and has an added |
| 6000 | 1=valid bit added to the 53rd bit |
| 6001 | then since this is a wide register(TM) |
| 6002 | we split it into two 32 bit writes |
| 6003 | */ |
| 6004 | #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF)) |
| 6005 | #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44))) |
| 6006 | #define PXP_ONE_ILT(x) (((x) << 10) | x) |
| 6007 | #define PXP_ILT_RANGE(f, l) (((l) << 10) | f) |
| 6008 | |
| 6009 | #define CNIC_ILT_LINES 0 |
| 6010 | |
| 6011 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
| 6012 | { |
| 6013 | int reg; |
| 6014 | |
| 6015 | if (CHIP_IS_E1H(bp)) |
| 6016 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; |
| 6017 | else /* E1 */ |
| 6018 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
| 6019 | |
| 6020 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); |
| 6021 | } |
| 6022 | |
| 6023 | static int bnx2x_init_func(struct bnx2x *bp) |
| 6024 | { |
| 6025 | int port = BP_PORT(bp); |
| 6026 | int func = BP_FUNC(bp); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6027 | u32 addr, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6028 | int i; |
| 6029 | |
| 6030 | DP(BNX2X_MSG_MCP, "starting func init func %x\n", func); |
| 6031 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6032 | /* set MSI reconfigure capability */ |
| 6033 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); |
| 6034 | val = REG_RD(bp, addr); |
| 6035 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; |
| 6036 | REG_WR(bp, addr, val); |
| 6037 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6038 | i = FUNC_ILT_BASE(func); |
| 6039 | |
| 6040 | bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context)); |
| 6041 | if (CHIP_IS_E1H(bp)) { |
| 6042 | REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i); |
| 6043 | REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES); |
| 6044 | } else /* E1 */ |
| 6045 | REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4, |
| 6046 | PXP_ILT_RANGE(i, i + CNIC_ILT_LINES)); |
| 6047 | |
| 6048 | |
| 6049 | if (CHIP_IS_E1H(bp)) { |
| 6050 | for (i = 0; i < 9; i++) |
| 6051 | bnx2x_init_block(bp, |
| 6052 | cm_start[func][i], cm_end[func][i]); |
| 6053 | |
| 6054 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 6055 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov); |
| 6056 | } |
| 6057 | |
| 6058 | /* HC init per function */ |
| 6059 | if (CHIP_IS_E1H(bp)) { |
| 6060 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6061 | |
| 6062 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6063 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6064 | } |
| 6065 | bnx2x_init_block(bp, hc_limits[func][0], hc_limits[func][1]); |
| 6066 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6067 | /* Reset PCIE errors for debug */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6068 | REG_WR(bp, 0x2114, 0xffffffff); |
| 6069 | REG_WR(bp, 0x2120, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6070 | |
| 6071 | return 0; |
| 6072 | } |
| 6073 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6074 | static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code) |
| 6075 | { |
| 6076 | int i, rc = 0; |
| 6077 | |
| 6078 | DP(BNX2X_MSG_MCP, "function %d load_code %x\n", |
| 6079 | BP_FUNC(bp), load_code); |
| 6080 | |
| 6081 | bp->dmae_ready = 0; |
| 6082 | mutex_init(&bp->dmae_mutex); |
| 6083 | bnx2x_gunzip_init(bp); |
| 6084 | |
| 6085 | switch (load_code) { |
| 6086 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 6087 | rc = bnx2x_init_common(bp); |
| 6088 | if (rc) |
| 6089 | goto init_hw_err; |
| 6090 | /* no break */ |
| 6091 | |
| 6092 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 6093 | bp->dmae_ready = 1; |
| 6094 | rc = bnx2x_init_port(bp); |
| 6095 | if (rc) |
| 6096 | goto init_hw_err; |
| 6097 | /* no break */ |
| 6098 | |
| 6099 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 6100 | bp->dmae_ready = 1; |
| 6101 | rc = bnx2x_init_func(bp); |
| 6102 | if (rc) |
| 6103 | goto init_hw_err; |
| 6104 | break; |
| 6105 | |
| 6106 | default: |
| 6107 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 6108 | break; |
| 6109 | } |
| 6110 | |
| 6111 | if (!BP_NOMCP(bp)) { |
| 6112 | int func = BP_FUNC(bp); |
| 6113 | |
| 6114 | bp->fw_drv_pulse_wr_seq = |
| 6115 | (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) & |
| 6116 | DRV_PULSE_SEQ_MASK); |
| 6117 | bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param); |
| 6118 | DP(BNX2X_MSG_MCP, "drv_pulse 0x%x func_stx 0x%x\n", |
| 6119 | bp->fw_drv_pulse_wr_seq, bp->func_stx); |
| 6120 | } else |
| 6121 | bp->func_stx = 0; |
| 6122 | |
| 6123 | /* this needs to be done before gunzip end */ |
| 6124 | bnx2x_zero_def_sb(bp); |
| 6125 | for_each_queue(bp, i) |
| 6126 | bnx2x_zero_sb(bp, BP_L_ID(bp) + i); |
| 6127 | |
| 6128 | init_hw_err: |
| 6129 | bnx2x_gunzip_end(bp); |
| 6130 | |
| 6131 | return rc; |
| 6132 | } |
| 6133 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6134 | /* send the MCP a request, block until there is a reply */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6135 | static u32 bnx2x_fw_command(struct bnx2x *bp, u32 command) |
| 6136 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6137 | int func = BP_FUNC(bp); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6138 | u32 seq = ++bp->fw_seq; |
| 6139 | u32 rc = 0; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6140 | u32 cnt = 1; |
| 6141 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6142 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6143 | SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq)); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6144 | 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] | 6145 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6146 | do { |
| 6147 | /* let the FW do it's magic ... */ |
| 6148 | msleep(delay); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6149 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6150 | rc = SHMEM_RD(bp, func_mb[func].fw_mb_header); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6151 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6152 | /* Give the FW up to 2 second (200*10ms) */ |
| 6153 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200)); |
| 6154 | |
| 6155 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", |
| 6156 | cnt*delay, rc, seq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6157 | |
| 6158 | /* is this a reply to our command? */ |
| 6159 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) { |
| 6160 | rc &= FW_MSG_CODE_MASK; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6161 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6162 | } else { |
| 6163 | /* FW BUG! */ |
| 6164 | BNX2X_ERR("FW failed to respond!\n"); |
| 6165 | bnx2x_fw_dump(bp); |
| 6166 | rc = 0; |
| 6167 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6168 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6169 | return rc; |
| 6170 | } |
| 6171 | |
| 6172 | static void bnx2x_free_mem(struct bnx2x *bp) |
| 6173 | { |
| 6174 | |
| 6175 | #define BNX2X_PCI_FREE(x, y, size) \ |
| 6176 | do { \ |
| 6177 | if (x) { \ |
| 6178 | pci_free_consistent(bp->pdev, size, x, y); \ |
| 6179 | x = NULL; \ |
| 6180 | y = 0; \ |
| 6181 | } \ |
| 6182 | } while (0) |
| 6183 | |
| 6184 | #define BNX2X_FREE(x) \ |
| 6185 | do { \ |
| 6186 | if (x) { \ |
| 6187 | vfree(x); \ |
| 6188 | x = NULL; \ |
| 6189 | } \ |
| 6190 | } while (0) |
| 6191 | |
| 6192 | int i; |
| 6193 | |
| 6194 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6195 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6196 | for_each_queue(bp, i) { |
| 6197 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6198 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6199 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk), |
| 6200 | bnx2x_fp(bp, i, status_blk_mapping), |
| 6201 | sizeof(struct host_status_block) + |
| 6202 | sizeof(struct eth_tx_db_data)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6203 | } |
| 6204 | /* Rx */ |
| 6205 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6206 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6207 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6208 | BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring)); |
| 6209 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring), |
| 6210 | bnx2x_fp(bp, i, rx_desc_mapping), |
| 6211 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6212 | |
| 6213 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring), |
| 6214 | bnx2x_fp(bp, i, rx_comp_mapping), |
| 6215 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6216 | NUM_RCQ_BD); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6217 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6218 | /* SGE ring */ |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6219 | BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6220 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring), |
| 6221 | bnx2x_fp(bp, i, rx_sge_mapping), |
| 6222 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
| 6223 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6224 | /* Tx */ |
| 6225 | for_each_tx_queue(bp, i) { |
| 6226 | |
| 6227 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6228 | BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring)); |
| 6229 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring), |
| 6230 | bnx2x_fp(bp, i, tx_desc_mapping), |
| 6231 | sizeof(struct eth_tx_bd) * NUM_TX_BD); |
| 6232 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6233 | /* end of fastpath */ |
| 6234 | |
| 6235 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6236 | sizeof(struct host_def_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6237 | |
| 6238 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6239 | sizeof(struct bnx2x_slowpath)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6240 | |
| 6241 | #ifdef BCM_ISCSI |
| 6242 | BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024); |
| 6243 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024); |
| 6244 | BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024); |
| 6245 | BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024); |
| 6246 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6247 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6248 | |
| 6249 | #undef BNX2X_PCI_FREE |
| 6250 | #undef BNX2X_KFREE |
| 6251 | } |
| 6252 | |
| 6253 | static int bnx2x_alloc_mem(struct bnx2x *bp) |
| 6254 | { |
| 6255 | |
| 6256 | #define BNX2X_PCI_ALLOC(x, y, size) \ |
| 6257 | do { \ |
| 6258 | x = pci_alloc_consistent(bp->pdev, size, y); \ |
| 6259 | if (x == NULL) \ |
| 6260 | goto alloc_mem_err; \ |
| 6261 | memset(x, 0, size); \ |
| 6262 | } while (0) |
| 6263 | |
| 6264 | #define BNX2X_ALLOC(x, size) \ |
| 6265 | do { \ |
| 6266 | x = vmalloc(size); \ |
| 6267 | if (x == NULL) \ |
| 6268 | goto alloc_mem_err; \ |
| 6269 | memset(x, 0, size); \ |
| 6270 | } while (0) |
| 6271 | |
| 6272 | int i; |
| 6273 | |
| 6274 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6275 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6276 | for_each_queue(bp, i) { |
| 6277 | bnx2x_fp(bp, i, bp) = bp; |
| 6278 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6279 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6280 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk), |
| 6281 | &bnx2x_fp(bp, i, status_blk_mapping), |
| 6282 | sizeof(struct host_status_block) + |
| 6283 | sizeof(struct eth_tx_db_data)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6284 | } |
| 6285 | /* Rx */ |
| 6286 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6287 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6288 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6289 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring), |
| 6290 | sizeof(struct sw_rx_bd) * NUM_RX_BD); |
| 6291 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring), |
| 6292 | &bnx2x_fp(bp, i, rx_desc_mapping), |
| 6293 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6294 | |
| 6295 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring), |
| 6296 | &bnx2x_fp(bp, i, rx_comp_mapping), |
| 6297 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6298 | NUM_RCQ_BD); |
| 6299 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6300 | /* SGE ring */ |
| 6301 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring), |
| 6302 | sizeof(struct sw_rx_page) * NUM_RX_SGE); |
| 6303 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring), |
| 6304 | &bnx2x_fp(bp, i, rx_sge_mapping), |
| 6305 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6306 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6307 | /* Tx */ |
| 6308 | for_each_tx_queue(bp, i) { |
| 6309 | |
| 6310 | bnx2x_fp(bp, i, hw_tx_prods) = |
| 6311 | (void *)(bnx2x_fp(bp, i, status_blk) + 1); |
| 6312 | |
| 6313 | bnx2x_fp(bp, i, tx_prods_mapping) = |
| 6314 | bnx2x_fp(bp, i, status_blk_mapping) + |
| 6315 | sizeof(struct host_status_block); |
| 6316 | |
| 6317 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6318 | BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring), |
| 6319 | sizeof(struct sw_tx_bd) * NUM_TX_BD); |
| 6320 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring), |
| 6321 | &bnx2x_fp(bp, i, tx_desc_mapping), |
| 6322 | sizeof(struct eth_tx_bd) * NUM_TX_BD); |
| 6323 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6324 | /* end of fastpath */ |
| 6325 | |
| 6326 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
| 6327 | sizeof(struct host_def_status_block)); |
| 6328 | |
| 6329 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
| 6330 | sizeof(struct bnx2x_slowpath)); |
| 6331 | |
| 6332 | #ifdef BCM_ISCSI |
| 6333 | BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024); |
| 6334 | |
| 6335 | /* Initialize T1 */ |
| 6336 | for (i = 0; i < 64*1024; i += 64) { |
| 6337 | *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL; |
| 6338 | *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL; |
| 6339 | } |
| 6340 | |
| 6341 | /* allocate searcher T2 table |
| 6342 | we allocate 1/4 of alloc num for T2 |
| 6343 | (which is not entered into the ILT) */ |
| 6344 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024); |
| 6345 | |
| 6346 | /* Initialize T2 */ |
| 6347 | for (i = 0; i < 16*1024; i += 64) |
| 6348 | * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64; |
| 6349 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6350 | /* 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] | 6351 | *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping; |
| 6352 | |
| 6353 | /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */ |
| 6354 | BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024); |
| 6355 | |
| 6356 | /* QM queues (128*MAX_CONN) */ |
| 6357 | BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024); |
| 6358 | #endif |
| 6359 | |
| 6360 | /* Slow path ring */ |
| 6361 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); |
| 6362 | |
| 6363 | return 0; |
| 6364 | |
| 6365 | alloc_mem_err: |
| 6366 | bnx2x_free_mem(bp); |
| 6367 | return -ENOMEM; |
| 6368 | |
| 6369 | #undef BNX2X_PCI_ALLOC |
| 6370 | #undef BNX2X_ALLOC |
| 6371 | } |
| 6372 | |
| 6373 | static void bnx2x_free_tx_skbs(struct bnx2x *bp) |
| 6374 | { |
| 6375 | int i; |
| 6376 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6377 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6378 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6379 | |
| 6380 | u16 bd_cons = fp->tx_bd_cons; |
| 6381 | u16 sw_prod = fp->tx_pkt_prod; |
| 6382 | u16 sw_cons = fp->tx_pkt_cons; |
| 6383 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6384 | while (sw_cons != sw_prod) { |
| 6385 | bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons)); |
| 6386 | sw_cons++; |
| 6387 | } |
| 6388 | } |
| 6389 | } |
| 6390 | |
| 6391 | static void bnx2x_free_rx_skbs(struct bnx2x *bp) |
| 6392 | { |
| 6393 | int i, j; |
| 6394 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6395 | for_each_rx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6396 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 6397 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6398 | for (i = 0; i < NUM_RX_BD; i++) { |
| 6399 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i]; |
| 6400 | struct sk_buff *skb = rx_buf->skb; |
| 6401 | |
| 6402 | if (skb == NULL) |
| 6403 | continue; |
| 6404 | |
| 6405 | pci_unmap_single(bp->pdev, |
| 6406 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 6407 | bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6408 | PCI_DMA_FROMDEVICE); |
| 6409 | |
| 6410 | rx_buf->skb = NULL; |
| 6411 | dev_kfree_skb(skb); |
| 6412 | } |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6413 | if (!fp->disable_tpa) |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6414 | bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ? |
| 6415 | ETH_MAX_AGGREGATION_QUEUES_E1 : |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6416 | ETH_MAX_AGGREGATION_QUEUES_E1H); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6417 | } |
| 6418 | } |
| 6419 | |
| 6420 | static void bnx2x_free_skbs(struct bnx2x *bp) |
| 6421 | { |
| 6422 | bnx2x_free_tx_skbs(bp); |
| 6423 | bnx2x_free_rx_skbs(bp); |
| 6424 | } |
| 6425 | |
| 6426 | static void bnx2x_free_msix_irqs(struct bnx2x *bp) |
| 6427 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6428 | int i, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6429 | |
| 6430 | free_irq(bp->msix_table[0].vector, bp->dev); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6431 | DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6432 | bp->msix_table[0].vector); |
| 6433 | |
| 6434 | for_each_queue(bp, i) { |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6435 | DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq " |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6436 | "state %x\n", i, bp->msix_table[i + offset].vector, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6437 | bnx2x_fp(bp, i, state)); |
| 6438 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6439 | free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6440 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | static void bnx2x_free_irq(struct bnx2x *bp) |
| 6444 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6445 | if (bp->flags & USING_MSIX_FLAG) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6446 | bnx2x_free_msix_irqs(bp); |
| 6447 | pci_disable_msix(bp->pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6448 | bp->flags &= ~USING_MSIX_FLAG; |
| 6449 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6450 | } else if (bp->flags & USING_MSI_FLAG) { |
| 6451 | free_irq(bp->pdev->irq, bp->dev); |
| 6452 | pci_disable_msi(bp->pdev); |
| 6453 | bp->flags &= ~USING_MSI_FLAG; |
| 6454 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6455 | } else |
| 6456 | free_irq(bp->pdev->irq, bp->dev); |
| 6457 | } |
| 6458 | |
| 6459 | static int bnx2x_enable_msix(struct bnx2x *bp) |
| 6460 | { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6461 | int i, rc, offset = 1; |
| 6462 | int igu_vec = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6463 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6464 | bp->msix_table[0].entry = igu_vec; |
| 6465 | 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] | 6466 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6467 | for_each_queue(bp, i) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6468 | igu_vec = BP_L_ID(bp) + offset + i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6469 | bp->msix_table[i + offset].entry = igu_vec; |
| 6470 | DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d " |
| 6471 | "(fastpath #%u)\n", i + offset, igu_vec, i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6472 | } |
| 6473 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6474 | rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6475 | BNX2X_NUM_QUEUES(bp) + offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6476 | if (rc) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6477 | DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc); |
| 6478 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6479 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6480 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6481 | bp->flags |= USING_MSIX_FLAG; |
| 6482 | |
| 6483 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6484 | } |
| 6485 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6486 | static int bnx2x_req_msix_irqs(struct bnx2x *bp) |
| 6487 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6488 | int i, rc, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6489 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6490 | rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0, |
| 6491 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6492 | if (rc) { |
| 6493 | BNX2X_ERR("request sp irq failed\n"); |
| 6494 | return -EBUSY; |
| 6495 | } |
| 6496 | |
| 6497 | for_each_queue(bp, i) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6498 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6499 | |
| 6500 | sprintf(fp->name, "%s.fp%d", bp->dev->name, i); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6501 | rc = request_irq(bp->msix_table[i + offset].vector, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6502 | bnx2x_msix_fp_int, 0, fp->name, fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6503 | if (rc) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6504 | BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6505 | bnx2x_free_msix_irqs(bp); |
| 6506 | return -EBUSY; |
| 6507 | } |
| 6508 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6509 | fp->state = BNX2X_FP_STATE_IRQ; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6510 | } |
| 6511 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6512 | i = BNX2X_NUM_QUEUES(bp); |
| 6513 | if (is_multi(bp)) |
| 6514 | printk(KERN_INFO PFX |
| 6515 | "%s: using MSI-X IRQs: sp %d fp %d - %d\n", |
| 6516 | bp->dev->name, bp->msix_table[0].vector, |
| 6517 | bp->msix_table[offset].vector, |
| 6518 | bp->msix_table[offset + i - 1].vector); |
| 6519 | else |
| 6520 | printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp %d\n", |
| 6521 | bp->dev->name, bp->msix_table[0].vector, |
| 6522 | bp->msix_table[offset + i - 1].vector); |
| 6523 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6524 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6525 | } |
| 6526 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6527 | static int bnx2x_enable_msi(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6528 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6529 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6530 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6531 | rc = pci_enable_msi(bp->pdev); |
| 6532 | if (rc) { |
| 6533 | DP(NETIF_MSG_IFUP, "MSI is not attainable\n"); |
| 6534 | return -1; |
| 6535 | } |
| 6536 | bp->flags |= USING_MSI_FLAG; |
| 6537 | |
| 6538 | return 0; |
| 6539 | } |
| 6540 | |
| 6541 | static int bnx2x_req_irq(struct bnx2x *bp) |
| 6542 | { |
| 6543 | unsigned long flags; |
| 6544 | int rc; |
| 6545 | |
| 6546 | if (bp->flags & USING_MSI_FLAG) |
| 6547 | flags = 0; |
| 6548 | else |
| 6549 | flags = IRQF_SHARED; |
| 6550 | |
| 6551 | rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6552 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6553 | if (!rc) |
| 6554 | bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ; |
| 6555 | |
| 6556 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6557 | } |
| 6558 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6559 | static void bnx2x_napi_enable(struct bnx2x *bp) |
| 6560 | { |
| 6561 | int i; |
| 6562 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6563 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6564 | napi_enable(&bnx2x_fp(bp, i, napi)); |
| 6565 | } |
| 6566 | |
| 6567 | static void bnx2x_napi_disable(struct bnx2x *bp) |
| 6568 | { |
| 6569 | int i; |
| 6570 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6571 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6572 | napi_disable(&bnx2x_fp(bp, i, napi)); |
| 6573 | } |
| 6574 | |
| 6575 | static void bnx2x_netif_start(struct bnx2x *bp) |
| 6576 | { |
| 6577 | if (atomic_dec_and_test(&bp->intr_sem)) { |
| 6578 | if (netif_running(bp->dev)) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6579 | bnx2x_napi_enable(bp); |
| 6580 | bnx2x_int_enable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6581 | if (bp->state == BNX2X_STATE_OPEN) |
| 6582 | netif_tx_wake_all_queues(bp->dev); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6583 | } |
| 6584 | } |
| 6585 | } |
| 6586 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 6587 | static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6588 | { |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 6589 | bnx2x_int_disable_sync(bp, disable_hw); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 6590 | bnx2x_napi_disable(bp); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6591 | if (netif_running(bp->dev)) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6592 | netif_tx_disable(bp->dev); |
| 6593 | bp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6594 | } |
| 6595 | } |
| 6596 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6597 | /* |
| 6598 | * Init service functions |
| 6599 | */ |
| 6600 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6601 | static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6602 | { |
| 6603 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6604 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6605 | |
| 6606 | /* CAM allocation |
| 6607 | * unicasts 0-31:port0 32-63:port1 |
| 6608 | * multicast 64-127:port0 128-191:port1 |
| 6609 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 6610 | config->hdr.length = 2; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 6611 | config->hdr.offset = port ? 32 : 0; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 6612 | config->hdr.client_id = bp->fp->cl_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6613 | config->hdr.reserved1 = 0; |
| 6614 | |
| 6615 | /* primary MAC */ |
| 6616 | config->config_table[0].cam_entry.msb_mac_addr = |
| 6617 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 6618 | config->config_table[0].cam_entry.middle_mac_addr = |
| 6619 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 6620 | config->config_table[0].cam_entry.lsb_mac_addr = |
| 6621 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6622 | config->config_table[0].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6623 | if (set) |
| 6624 | config->config_table[0].target_table_entry.flags = 0; |
| 6625 | else |
| 6626 | CAM_INVALIDATE(config->config_table[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6627 | config->config_table[0].target_table_entry.client_id = 0; |
| 6628 | config->config_table[0].target_table_entry.vlan_id = 0; |
| 6629 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6630 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n", |
| 6631 | (set ? "setting" : "clearing"), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6632 | config->config_table[0].cam_entry.msb_mac_addr, |
| 6633 | config->config_table[0].cam_entry.middle_mac_addr, |
| 6634 | config->config_table[0].cam_entry.lsb_mac_addr); |
| 6635 | |
| 6636 | /* broadcast */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 6637 | config->config_table[1].cam_entry.msb_mac_addr = cpu_to_le16(0xffff); |
| 6638 | config->config_table[1].cam_entry.middle_mac_addr = cpu_to_le16(0xffff); |
| 6639 | config->config_table[1].cam_entry.lsb_mac_addr = cpu_to_le16(0xffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6640 | config->config_table[1].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6641 | if (set) |
| 6642 | config->config_table[1].target_table_entry.flags = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6643 | TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST; |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6644 | else |
| 6645 | CAM_INVALIDATE(config->config_table[1]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6646 | config->config_table[1].target_table_entry.client_id = 0; |
| 6647 | config->config_table[1].target_table_entry.vlan_id = 0; |
| 6648 | |
| 6649 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 6650 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 6651 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 6652 | } |
| 6653 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6654 | static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6655 | { |
| 6656 | struct mac_configuration_cmd_e1h *config = |
| 6657 | (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config); |
| 6658 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6659 | if (set && (bp->state != BNX2X_STATE_OPEN)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6660 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 6661 | return; |
| 6662 | } |
| 6663 | |
| 6664 | /* CAM allocation for E1H |
| 6665 | * unicasts: by func number |
| 6666 | * multicast: 20+FUNC*20, 20 each |
| 6667 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 6668 | config->hdr.length = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6669 | config->hdr.offset = BP_FUNC(bp); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 6670 | config->hdr.client_id = bp->fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6671 | config->hdr.reserved1 = 0; |
| 6672 | |
| 6673 | /* primary MAC */ |
| 6674 | config->config_table[0].msb_mac_addr = |
| 6675 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 6676 | config->config_table[0].middle_mac_addr = |
| 6677 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 6678 | config->config_table[0].lsb_mac_addr = |
| 6679 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
| 6680 | config->config_table[0].client_id = BP_L_ID(bp); |
| 6681 | config->config_table[0].vlan_id = 0; |
| 6682 | config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6683 | if (set) |
| 6684 | config->config_table[0].flags = BP_PORT(bp); |
| 6685 | else |
| 6686 | config->config_table[0].flags = |
| 6687 | MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6688 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6689 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n", |
| 6690 | (set ? "setting" : "clearing"), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6691 | config->config_table[0].msb_mac_addr, |
| 6692 | config->config_table[0].middle_mac_addr, |
| 6693 | config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp)); |
| 6694 | |
| 6695 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 6696 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 6697 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 6698 | } |
| 6699 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6700 | static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx, |
| 6701 | int *state_p, int poll) |
| 6702 | { |
| 6703 | /* can take a while if any port is running */ |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 6704 | int cnt = 5000; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6705 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6706 | DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n", |
| 6707 | poll ? "polling" : "waiting", state, idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6708 | |
| 6709 | might_sleep(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6710 | while (cnt--) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6711 | if (poll) { |
| 6712 | bnx2x_rx_int(bp->fp, 10); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6713 | /* if index is different from 0 |
| 6714 | * the reply for some commands will |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6715 | * be on the non default queue |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6716 | */ |
| 6717 | if (idx) |
| 6718 | bnx2x_rx_int(&bp->fp[idx], 10); |
| 6719 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6720 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6721 | mb(); /* state is changed by bnx2x_sp_event() */ |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 6722 | if (*state_p == state) { |
| 6723 | #ifdef BNX2X_STOP_ON_ERROR |
| 6724 | DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt); |
| 6725 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6726 | return 0; |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 6727 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6728 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6729 | msleep(1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6730 | } |
| 6731 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6732 | /* timeout! */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6733 | BNX2X_ERR("timeout %s for state %x on IDX [%d]\n", |
| 6734 | poll ? "polling" : "waiting", state, idx); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6735 | #ifdef BNX2X_STOP_ON_ERROR |
| 6736 | bnx2x_panic(); |
| 6737 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6738 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6739 | return -EBUSY; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | static int bnx2x_setup_leading(struct bnx2x *bp) |
| 6743 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6744 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6745 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6746 | /* reset IGU state */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6747 | 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] | 6748 | |
| 6749 | /* SETUP ramrod */ |
| 6750 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0); |
| 6751 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6752 | /* Wait for completion */ |
| 6753 | rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6754 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6755 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6756 | } |
| 6757 | |
| 6758 | static int bnx2x_setup_multi(struct bnx2x *bp, int index) |
| 6759 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6760 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
| 6761 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6762 | /* reset IGU state */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6763 | 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] | 6764 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6765 | /* SETUP ramrod */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6766 | fp->state = BNX2X_FP_STATE_OPENING; |
| 6767 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0, |
| 6768 | fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6769 | |
| 6770 | /* Wait for completion */ |
| 6771 | return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6772 | &(fp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6773 | } |
| 6774 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6775 | static int bnx2x_poll(struct napi_struct *napi, int budget); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6776 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6777 | static void bnx2x_set_int_mode(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6778 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6779 | int num_queues; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6780 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6781 | switch (int_mode) { |
| 6782 | case INT_MODE_INTx: |
| 6783 | case INT_MODE_MSI: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6784 | num_queues = 1; |
| 6785 | bp->num_rx_queues = num_queues; |
| 6786 | bp->num_tx_queues = num_queues; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6787 | DP(NETIF_MSG_IFUP, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6788 | "set number of queues to %d\n", num_queues); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6789 | break; |
| 6790 | |
| 6791 | case INT_MODE_MSIX: |
| 6792 | default: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6793 | if (bp->multi_mode == ETH_RSS_MODE_REGULAR) |
| 6794 | num_queues = min_t(u32, num_online_cpus(), |
| 6795 | BNX2X_MAX_QUEUES(bp)); |
| 6796 | else |
| 6797 | num_queues = 1; |
| 6798 | bp->num_rx_queues = num_queues; |
| 6799 | bp->num_tx_queues = num_queues; |
| 6800 | DP(NETIF_MSG_IFUP, "set number of rx queues to %d" |
| 6801 | " number of tx queues to %d\n", |
| 6802 | bp->num_rx_queues, bp->num_tx_queues); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6803 | /* if we can't use MSI-X we only need one fp, |
| 6804 | * so try to enable MSI-X with the requested number of fp's |
| 6805 | * and fallback to MSI or legacy INTx with one fp |
| 6806 | */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6807 | if (bnx2x_enable_msix(bp)) { |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6808 | /* failed to enable MSI-X */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6809 | num_queues = 1; |
| 6810 | bp->num_rx_queues = num_queues; |
| 6811 | bp->num_tx_queues = num_queues; |
| 6812 | if (bp->multi_mode) |
| 6813 | BNX2X_ERR("Multi requested but failed to " |
| 6814 | "enable MSI-X set number of " |
| 6815 | "queues to %d\n", num_queues); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6816 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6817 | break; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6818 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6819 | bp->dev->real_num_tx_queues = bp->num_tx_queues; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | static void bnx2x_set_rx_mode(struct net_device *dev); |
| 6823 | |
| 6824 | /* must be called with rtnl_lock */ |
| 6825 | static int bnx2x_nic_load(struct bnx2x *bp, int load_mode) |
| 6826 | { |
| 6827 | u32 load_code; |
| 6828 | int i, rc = 0; |
| 6829 | #ifdef BNX2X_STOP_ON_ERROR |
| 6830 | DP(NETIF_MSG_IFUP, "enter load_mode %d\n", load_mode); |
| 6831 | if (unlikely(bp->panic)) |
| 6832 | return -EPERM; |
| 6833 | #endif |
| 6834 | |
| 6835 | bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD; |
| 6836 | |
| 6837 | bnx2x_set_int_mode(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6838 | |
| 6839 | if (bnx2x_alloc_mem(bp)) |
| 6840 | return -ENOMEM; |
| 6841 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6842 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6843 | bnx2x_fp(bp, i, disable_tpa) = |
| 6844 | ((bp->flags & TPA_ENABLE_FLAG) == 0); |
| 6845 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6846 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6847 | netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi), |
| 6848 | bnx2x_poll, 128); |
| 6849 | |
| 6850 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6851 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6852 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6853 | |
| 6854 | fp->poll_no_work = 0; |
| 6855 | fp->poll_calls = 0; |
| 6856 | fp->poll_max_calls = 0; |
| 6857 | fp->poll_complete = 0; |
| 6858 | fp->poll_exit = 0; |
| 6859 | } |
| 6860 | #endif |
| 6861 | bnx2x_napi_enable(bp); |
| 6862 | |
| 6863 | if (bp->flags & USING_MSIX_FLAG) { |
| 6864 | rc = bnx2x_req_msix_irqs(bp); |
| 6865 | if (rc) { |
| 6866 | pci_disable_msix(bp->pdev); |
| 6867 | goto load_error1; |
| 6868 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6869 | } else { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6870 | if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx)) |
| 6871 | bnx2x_enable_msi(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6872 | bnx2x_ack_int(bp); |
| 6873 | rc = bnx2x_req_irq(bp); |
| 6874 | if (rc) { |
| 6875 | BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6876 | if (bp->flags & USING_MSI_FLAG) |
| 6877 | pci_disable_msi(bp->pdev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6878 | goto load_error1; |
| 6879 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6880 | if (bp->flags & USING_MSI_FLAG) { |
| 6881 | bp->dev->irq = bp->pdev->irq; |
| 6882 | printk(KERN_INFO PFX "%s: using MSI IRQ %d\n", |
| 6883 | bp->dev->name, bp->pdev->irq); |
| 6884 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6885 | } |
| 6886 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6887 | /* Send LOAD_REQUEST command to MCP |
| 6888 | Returns the type of LOAD command: |
| 6889 | if it is the first port to be initialized |
| 6890 | common blocks should be initialized, otherwise - not |
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 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6893 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ); |
| 6894 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6895 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6896 | rc = -EBUSY; |
| 6897 | goto load_error2; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6898 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6899 | if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) { |
| 6900 | rc = -EBUSY; /* other port in diagnostic mode */ |
| 6901 | goto load_error2; |
| 6902 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6903 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6904 | } else { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6905 | int port = BP_PORT(bp); |
| 6906 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6907 | DP(NETIF_MSG_IFUP, "NO MCP load counts before us %d, %d, %d\n", |
| 6908 | load_count[0], load_count[1], load_count[2]); |
| 6909 | load_count[0]++; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6910 | load_count[1 + port]++; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6911 | DP(NETIF_MSG_IFUP, "NO MCP new load counts %d, %d, %d\n", |
| 6912 | load_count[0], load_count[1], load_count[2]); |
| 6913 | if (load_count[0] == 1) |
| 6914 | load_code = FW_MSG_CODE_DRV_LOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6915 | else if (load_count[1 + port] == 1) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6916 | load_code = FW_MSG_CODE_DRV_LOAD_PORT; |
| 6917 | else |
| 6918 | load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6919 | } |
| 6920 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6921 | if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) || |
| 6922 | (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) |
| 6923 | bp->port.pmf = 1; |
| 6924 | else |
| 6925 | bp->port.pmf = 0; |
| 6926 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 6927 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6928 | /* Initialize HW */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6929 | rc = bnx2x_init_hw(bp, load_code); |
| 6930 | if (rc) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6931 | BNX2X_ERR("HW init failed, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6932 | goto load_error2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6933 | } |
| 6934 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6935 | /* Setup NIC internals and enable interrupts */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 6936 | bnx2x_nic_init(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6937 | |
| 6938 | /* Send LOAD_DONE command to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6939 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6940 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE); |
| 6941 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6942 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6943 | rc = -EBUSY; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6944 | goto load_error3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | bp->state = BNX2X_STATE_OPENING_WAIT4_PORT; |
| 6949 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6950 | rc = bnx2x_setup_leading(bp); |
| 6951 | if (rc) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6952 | BNX2X_ERR("Setup leading failed!\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6953 | goto load_error3; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6954 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6955 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6956 | if (CHIP_IS_E1H(bp)) |
| 6957 | if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) { |
| 6958 | BNX2X_ERR("!!! mf_cfg function disabled\n"); |
| 6959 | bp->state = BNX2X_STATE_DISABLED; |
| 6960 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6961 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6962 | if (bp->state == BNX2X_STATE_OPEN) |
| 6963 | for_each_nondefault_queue(bp, i) { |
| 6964 | rc = bnx2x_setup_multi(bp, i); |
| 6965 | if (rc) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6966 | goto load_error3; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6967 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6968 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6969 | if (CHIP_IS_E1(bp)) |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6970 | bnx2x_set_mac_addr_e1(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6971 | else |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6972 | bnx2x_set_mac_addr_e1h(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6973 | |
| 6974 | if (bp->port.pmf) |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 6975 | bnx2x_initial_phy_init(bp, load_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6976 | |
| 6977 | /* Start fast path */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6978 | switch (load_mode) { |
| 6979 | case LOAD_NORMAL: |
| 6980 | /* Tx queue should be only reenabled */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6981 | netif_tx_wake_all_queues(bp->dev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6982 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6983 | bnx2x_set_rx_mode(bp->dev); |
| 6984 | break; |
| 6985 | |
| 6986 | case LOAD_OPEN: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6987 | netif_tx_start_all_queues(bp->dev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6988 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6989 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6990 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6991 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6992 | case LOAD_DIAG: |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6993 | /* Initialize the receive filter. */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6994 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6995 | bp->state = BNX2X_STATE_DIAG; |
| 6996 | break; |
| 6997 | |
| 6998 | default: |
| 6999 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7000 | } |
| 7001 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7002 | if (!bp->port.pmf) |
| 7003 | bnx2x__link_status_update(bp); |
| 7004 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7005 | /* start the timer */ |
| 7006 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 7007 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7008 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7009 | return 0; |
| 7010 | |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7011 | load_error3: |
| 7012 | bnx2x_int_disable_sync(bp, 1); |
| 7013 | if (!BP_NOMCP(bp)) { |
| 7014 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP); |
| 7015 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7016 | } |
| 7017 | bp->port.pmf = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7018 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 7019 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7020 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7021 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7022 | load_error2: |
Yitchak Gertner | d101463 | 2008-08-25 15:25:45 -0700 | [diff] [blame] | 7023 | /* Release IRQs */ |
| 7024 | bnx2x_free_irq(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7025 | load_error1: |
| 7026 | bnx2x_napi_disable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7027 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 7028 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7029 | bnx2x_free_mem(bp); |
| 7030 | |
| 7031 | /* TBD we really need to reset the chip |
| 7032 | if we want to recover from this */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7033 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | static int bnx2x_stop_multi(struct bnx2x *bp, int index) |
| 7037 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7038 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7039 | int rc; |
| 7040 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7041 | /* halt the connection */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7042 | fp->state = BNX2X_FP_STATE_HALTING; |
| 7043 | 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] | 7044 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7045 | /* Wait for completion */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7046 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7047 | &(fp->state), 1); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7048 | if (rc) /* timeout */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7049 | return rc; |
| 7050 | |
| 7051 | /* delete cfc entry */ |
| 7052 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1); |
| 7053 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7054 | /* Wait for completion */ |
| 7055 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7056 | &(fp->state), 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7057 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7058 | } |
| 7059 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7060 | static int bnx2x_stop_leading(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7061 | { |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 7062 | __le16 dsb_sp_prod_idx; |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7063 | /* if the other port is handling traffic, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7064 | this can take a lot of time */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7065 | int cnt = 500; |
| 7066 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7067 | |
| 7068 | might_sleep(); |
| 7069 | |
| 7070 | /* Send HALT ramrod */ |
| 7071 | bp->fp[0].state = BNX2X_FP_STATE_HALTING; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7072 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7073 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7074 | /* Wait for completion */ |
| 7075 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0, |
| 7076 | &(bp->fp[0].state), 1); |
| 7077 | if (rc) /* timeout */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7078 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7079 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7080 | dsb_sp_prod_idx = *bp->dsb_sp_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7081 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7082 | /* Send PORT_DELETE ramrod */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7083 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1); |
| 7084 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7085 | /* Wait for completion to arrive on default status block |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7086 | we are going to reset the chip anyway |
| 7087 | so there is not much to do if this times out |
| 7088 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7089 | while (dsb_sp_prod_idx == *bp->dsb_sp_prod) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7090 | if (!cnt) { |
| 7091 | DP(NETIF_MSG_IFDOWN, "timeout waiting for port del " |
| 7092 | "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n", |
| 7093 | *bp->dsb_sp_prod, dsb_sp_prod_idx); |
| 7094 | #ifdef BNX2X_STOP_ON_ERROR |
| 7095 | bnx2x_panic(); |
| 7096 | #endif |
Eilon Greenstein | 36e552a | 2009-02-12 08:37:21 +0000 | [diff] [blame] | 7097 | rc = -EBUSY; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7098 | break; |
| 7099 | } |
| 7100 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7101 | msleep(1); |
Eilon Greenstein | 5650d9d | 2009-01-22 06:01:29 +0000 | [diff] [blame] | 7102 | rmb(); /* Refresh the dsb_sp_prod */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7103 | } |
| 7104 | bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD; |
| 7105 | bp->fp[0].state = BNX2X_FP_STATE_CLOSED; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7106 | |
| 7107 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7108 | } |
| 7109 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7110 | static void bnx2x_reset_func(struct bnx2x *bp) |
| 7111 | { |
| 7112 | int port = BP_PORT(bp); |
| 7113 | int func = BP_FUNC(bp); |
| 7114 | int base, i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7115 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7116 | /* Configure IGU */ |
| 7117 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 7118 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 7119 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7120 | /* Clear ILT */ |
| 7121 | base = FUNC_ILT_BASE(func); |
| 7122 | for (i = base; i < base + ILT_PER_FUNC; i++) |
| 7123 | bnx2x_ilt_wr(bp, i, 0); |
| 7124 | } |
| 7125 | |
| 7126 | static void bnx2x_reset_port(struct bnx2x *bp) |
| 7127 | { |
| 7128 | int port = BP_PORT(bp); |
| 7129 | u32 val; |
| 7130 | |
| 7131 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
| 7132 | |
| 7133 | /* Do not rcv packets to BRB */ |
| 7134 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); |
| 7135 | /* Do not direct rcv packets that are not for MCP to the BRB */ |
| 7136 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7137 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7138 | |
| 7139 | /* Configure AEU */ |
| 7140 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); |
| 7141 | |
| 7142 | msleep(100); |
| 7143 | /* Check for BRB port occupancy */ |
| 7144 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); |
| 7145 | if (val) |
| 7146 | DP(NETIF_MSG_IFDOWN, |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7147 | "BRB1 is not empty %d blocks are occupied\n", val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7148 | |
| 7149 | /* TODO: Close Doorbell port? */ |
| 7150 | } |
| 7151 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7152 | static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code) |
| 7153 | { |
| 7154 | DP(BNX2X_MSG_MCP, "function %d reset_code %x\n", |
| 7155 | BP_FUNC(bp), reset_code); |
| 7156 | |
| 7157 | switch (reset_code) { |
| 7158 | case FW_MSG_CODE_DRV_UNLOAD_COMMON: |
| 7159 | bnx2x_reset_port(bp); |
| 7160 | bnx2x_reset_func(bp); |
| 7161 | bnx2x_reset_common(bp); |
| 7162 | break; |
| 7163 | |
| 7164 | case FW_MSG_CODE_DRV_UNLOAD_PORT: |
| 7165 | bnx2x_reset_port(bp); |
| 7166 | bnx2x_reset_func(bp); |
| 7167 | break; |
| 7168 | |
| 7169 | case FW_MSG_CODE_DRV_UNLOAD_FUNCTION: |
| 7170 | bnx2x_reset_func(bp); |
| 7171 | break; |
| 7172 | |
| 7173 | default: |
| 7174 | BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code); |
| 7175 | break; |
| 7176 | } |
| 7177 | } |
| 7178 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7179 | /* must be called with rtnl_lock */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7180 | static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7181 | { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7182 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7183 | u32 reset_code = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7184 | int i, cnt, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7185 | |
| 7186 | bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT; |
| 7187 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7188 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 7189 | bnx2x_set_storm_rx_mode(bp); |
| 7190 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 7191 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 7192 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7193 | del_timer_sync(&bp->timer); |
| 7194 | SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb, |
| 7195 | (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 7196 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7197 | |
Eilon Greenstein | 70b9986 | 2009-01-14 06:43:48 +0000 | [diff] [blame] | 7198 | /* Release IRQs */ |
| 7199 | bnx2x_free_irq(bp); |
| 7200 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7201 | /* Wait until tx fastpath tasks complete */ |
| 7202 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7203 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 7204 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7205 | cnt = 1000; |
Eilon Greenstein | 3e5b510 | 2009-02-12 08:37:25 +0000 | [diff] [blame] | 7206 | smp_mb(); |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 7207 | while (bnx2x_has_tx_work_unload(fp)) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7208 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7209 | bnx2x_tx_int(fp, 1000); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7210 | if (!cnt) { |
| 7211 | BNX2X_ERR("timeout waiting for queue[%d]\n", |
| 7212 | i); |
| 7213 | #ifdef BNX2X_STOP_ON_ERROR |
| 7214 | bnx2x_panic(); |
| 7215 | return -EBUSY; |
| 7216 | #else |
| 7217 | break; |
| 7218 | #endif |
| 7219 | } |
| 7220 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7221 | msleep(1); |
Eilon Greenstein | 3e5b510 | 2009-02-12 08:37:25 +0000 | [diff] [blame] | 7222 | smp_mb(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7223 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7224 | } |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7225 | /* Give HW time to discard old tx messages */ |
| 7226 | msleep(1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7227 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7228 | if (CHIP_IS_E1(bp)) { |
| 7229 | struct mac_configuration_cmd *config = |
| 7230 | bnx2x_sp(bp, mcast_config); |
| 7231 | |
| 7232 | bnx2x_set_mac_addr_e1(bp, 0); |
| 7233 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7234 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7235 | CAM_INVALIDATE(config->config_table[i]); |
| 7236 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7237 | config->hdr.length = i; |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7238 | if (CHIP_REV_IS_SLOW(bp)) |
| 7239 | config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 7240 | else |
| 7241 | config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7242 | config->hdr.client_id = bp->fp->cl_id; |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7243 | config->hdr.reserved1 = 0; |
| 7244 | |
| 7245 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 7246 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 7247 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0); |
| 7248 | |
| 7249 | } else { /* E1H */ |
| 7250 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 7251 | |
| 7252 | bnx2x_set_mac_addr_e1h(bp, 0); |
| 7253 | |
| 7254 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 7255 | REG_WR(bp, MC_HASH_OFFSET(bp, i), 0); |
| 7256 | } |
| 7257 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7258 | if (unload_mode == UNLOAD_NORMAL) |
| 7259 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7260 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7261 | else if (bp->flags & NO_WOL_FLAG) { |
| 7262 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
| 7263 | if (CHIP_IS_E1H(bp)) |
| 7264 | REG_WR(bp, MISC_REG_E1HMF_MODE, 0); |
| 7265 | |
| 7266 | } else if (bp->wol) { |
| 7267 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7268 | u8 *mac_addr = bp->dev->dev_addr; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7269 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7270 | /* The mac address is written to entries 1-4 to |
| 7271 | preserve entry 0 which is used by the PMF */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7272 | u8 entry = (BP_E1HVN(bp) + 1)*8; |
| 7273 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7274 | val = (mac_addr[0] << 8) | mac_addr[1]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7275 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7276 | |
| 7277 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 7278 | (mac_addr[4] << 8) | mac_addr[5]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7279 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7280 | |
| 7281 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7282 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7283 | } else |
| 7284 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
| 7285 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7286 | /* Close multi and leading connections |
| 7287 | Completions for ramrods are collected in a synchronous way */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7288 | for_each_nondefault_queue(bp, i) |
| 7289 | if (bnx2x_stop_multi(bp, i)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7290 | goto unload_error; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7291 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7292 | rc = bnx2x_stop_leading(bp); |
| 7293 | if (rc) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7294 | BNX2X_ERR("Stop leading failed!\n"); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7295 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7296 | return -EBUSY; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7297 | #else |
| 7298 | goto unload_error; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7299 | #endif |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7300 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7301 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7302 | unload_error: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7303 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7304 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7305 | else { |
| 7306 | DP(NETIF_MSG_IFDOWN, "NO MCP load counts %d, %d, %d\n", |
| 7307 | load_count[0], load_count[1], load_count[2]); |
| 7308 | load_count[0]--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7309 | load_count[1 + port]--; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7310 | DP(NETIF_MSG_IFDOWN, "NO MCP new load counts %d, %d, %d\n", |
| 7311 | load_count[0], load_count[1], load_count[2]); |
| 7312 | if (load_count[0] == 0) |
| 7313 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7314 | else if (load_count[1 + port] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7315 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; |
| 7316 | else |
| 7317 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; |
| 7318 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7319 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7320 | if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) || |
| 7321 | (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT)) |
| 7322 | bnx2x__link_reset(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7323 | |
| 7324 | /* Reset the chip */ |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7325 | bnx2x_reset_chip(bp, reset_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7326 | |
| 7327 | /* Report UNLOAD_DONE to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7328 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7329 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
Eilon Greenstein | 9a03544 | 2008-11-03 16:45:55 -0800 | [diff] [blame] | 7330 | bp->port.pmf = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7331 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7332 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7333 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7334 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7335 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7336 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 7337 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7338 | bnx2x_free_mem(bp); |
| 7339 | |
| 7340 | bp->state = BNX2X_STATE_CLOSED; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7341 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7342 | netif_carrier_off(bp->dev); |
| 7343 | |
| 7344 | return 0; |
| 7345 | } |
| 7346 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7347 | static void bnx2x_reset_task(struct work_struct *work) |
| 7348 | { |
| 7349 | struct bnx2x *bp = container_of(work, struct bnx2x, reset_task); |
| 7350 | |
| 7351 | #ifdef BNX2X_STOP_ON_ERROR |
| 7352 | BNX2X_ERR("reset task called but STOP_ON_ERROR defined" |
| 7353 | " so reset not done to allow debug dump,\n" |
| 7354 | KERN_ERR " you will need to reboot when done\n"); |
| 7355 | return; |
| 7356 | #endif |
| 7357 | |
| 7358 | rtnl_lock(); |
| 7359 | |
| 7360 | if (!netif_running(bp->dev)) |
| 7361 | goto reset_task_exit; |
| 7362 | |
| 7363 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 7364 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 7365 | |
| 7366 | reset_task_exit: |
| 7367 | rtnl_unlock(); |
| 7368 | } |
| 7369 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7370 | /* end of nic load/unload */ |
| 7371 | |
| 7372 | /* ethtool_ops */ |
| 7373 | |
| 7374 | /* |
| 7375 | * Init service functions |
| 7376 | */ |
| 7377 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7378 | static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func) |
| 7379 | { |
| 7380 | switch (func) { |
| 7381 | case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 7382 | case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1; |
| 7383 | case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2; |
| 7384 | case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3; |
| 7385 | case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4; |
| 7386 | case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5; |
| 7387 | case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6; |
| 7388 | case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7; |
| 7389 | default: |
| 7390 | BNX2X_ERR("Unsupported function index: %d\n", func); |
| 7391 | return (u32)(-1); |
| 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func) |
| 7396 | { |
| 7397 | u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val; |
| 7398 | |
| 7399 | /* Flush all outstanding writes */ |
| 7400 | mmiowb(); |
| 7401 | |
| 7402 | /* Pretend to be function 0 */ |
| 7403 | REG_WR(bp, reg, 0); |
| 7404 | /* Flush the GRC transaction (in the chip) */ |
| 7405 | new_val = REG_RD(bp, reg); |
| 7406 | if (new_val != 0) { |
| 7407 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n", |
| 7408 | new_val); |
| 7409 | BUG(); |
| 7410 | } |
| 7411 | |
| 7412 | /* From now we are in the "like-E1" mode */ |
| 7413 | bnx2x_int_disable(bp); |
| 7414 | |
| 7415 | /* Flush all outstanding writes */ |
| 7416 | mmiowb(); |
| 7417 | |
| 7418 | /* Restore the original funtion settings */ |
| 7419 | REG_WR(bp, reg, orig_func); |
| 7420 | new_val = REG_RD(bp, reg); |
| 7421 | if (new_val != orig_func) { |
| 7422 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n", |
| 7423 | orig_func, new_val); |
| 7424 | BUG(); |
| 7425 | } |
| 7426 | } |
| 7427 | |
| 7428 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func) |
| 7429 | { |
| 7430 | if (CHIP_IS_E1H(bp)) |
| 7431 | bnx2x_undi_int_disable_e1h(bp, func); |
| 7432 | else |
| 7433 | bnx2x_int_disable(bp); |
| 7434 | } |
| 7435 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7436 | static void __devinit bnx2x_undi_unload(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7437 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7438 | u32 val; |
| 7439 | |
| 7440 | /* Check if there is any driver already loaded */ |
| 7441 | val = REG_RD(bp, MISC_REG_UNPREPARED); |
| 7442 | if (val == 0x1) { |
| 7443 | /* Check if it is the UNDI driver |
| 7444 | * UNDI driver initializes CID offset for normal bell to 0x7 |
| 7445 | */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 7446 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7447 | val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); |
| 7448 | if (val == 0x7) { |
| 7449 | u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7450 | /* save our func */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7451 | int func = BP_FUNC(bp); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7452 | u32 swap_en; |
| 7453 | u32 swap_val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7454 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7455 | /* clear the UNDI indication */ |
| 7456 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); |
| 7457 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7458 | BNX2X_DEV_INFO("UNDI is active! reset device\n"); |
| 7459 | |
| 7460 | /* try unload UNDI on port 0 */ |
| 7461 | bp->func = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7462 | bp->fw_seq = |
| 7463 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7464 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7465 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7466 | |
| 7467 | /* if UNDI is loaded on the other port */ |
| 7468 | if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) { |
| 7469 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7470 | /* send "DONE" for previous unload */ |
| 7471 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7472 | |
| 7473 | /* unload UNDI on port 1 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7474 | bp->func = 1; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7475 | bp->fw_seq = |
| 7476 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7477 | DRV_MSG_SEQ_NUMBER_MASK); |
| 7478 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7479 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7480 | bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7481 | } |
| 7482 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7483 | /* now it's safe to release the lock */ |
| 7484 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
| 7485 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7486 | bnx2x_undi_int_disable(bp, func); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7487 | |
| 7488 | /* close input traffic and wait for it */ |
| 7489 | /* Do not rcv packets to BRB */ |
| 7490 | REG_WR(bp, |
| 7491 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK : |
| 7492 | NIG_REG_LLH0_BRB1_DRV_MASK), 0x0); |
| 7493 | /* Do not direct rcv packets that are not for MCP to |
| 7494 | * the BRB */ |
| 7495 | REG_WR(bp, |
| 7496 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7497 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7498 | /* clear AEU */ |
| 7499 | REG_WR(bp, |
| 7500 | (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 7501 | MISC_REG_AEU_MASK_ATTN_FUNC_0), 0); |
| 7502 | msleep(10); |
| 7503 | |
| 7504 | /* save NIG port swap info */ |
| 7505 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 7506 | swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7507 | /* reset device */ |
| 7508 | REG_WR(bp, |
| 7509 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7510 | 0xd3ffffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7511 | REG_WR(bp, |
| 7512 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
| 7513 | 0x1403); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7514 | /* take the NIG out of reset and restore swap values */ |
| 7515 | REG_WR(bp, |
| 7516 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 7517 | MISC_REGISTERS_RESET_REG_1_RST_NIG); |
| 7518 | REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); |
| 7519 | REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en); |
| 7520 | |
| 7521 | /* send unload done to the MCP */ |
| 7522 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7523 | |
| 7524 | /* restore our func and fw_seq */ |
| 7525 | bp->func = func; |
| 7526 | bp->fw_seq = |
| 7527 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7528 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7529 | |
| 7530 | } else |
| 7531 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) |
| 7536 | { |
| 7537 | u32 val, val2, val3, val4, id; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 7538 | u16 pmc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7539 | |
| 7540 | /* Get the chip revision id and number. */ |
| 7541 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ |
| 7542 | val = REG_RD(bp, MISC_REG_CHIP_NUM); |
| 7543 | id = ((val & 0xffff) << 16); |
| 7544 | val = REG_RD(bp, MISC_REG_CHIP_REV); |
| 7545 | id |= ((val & 0xf) << 12); |
| 7546 | val = REG_RD(bp, MISC_REG_CHIP_METAL); |
| 7547 | id |= ((val & 0xff) << 4); |
Eilon Greenstein | 5a40e08 | 2009-01-14 06:44:04 +0000 | [diff] [blame] | 7548 | val = REG_RD(bp, MISC_REG_BOND_ID); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7549 | id |= (val & 0xf); |
| 7550 | bp->common.chip_id = id; |
| 7551 | bp->link_params.chip_id = bp->common.chip_id; |
| 7552 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); |
| 7553 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 7554 | val = (REG_RD(bp, 0x2874) & 0x55); |
| 7555 | if ((bp->common.chip_id & 0x1) || |
| 7556 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { |
| 7557 | bp->flags |= ONE_PORT_FLAG; |
| 7558 | BNX2X_DEV_INFO("single port device\n"); |
| 7559 | } |
| 7560 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7561 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
| 7562 | bp->common.flash_size = (NVRAM_1MB_SIZE << |
| 7563 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
| 7564 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", |
| 7565 | bp->common.flash_size, bp->common.flash_size); |
| 7566 | |
| 7567 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7568 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 7569 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 7570 | |
| 7571 | if (!bp->common.shmem_base || |
| 7572 | (bp->common.shmem_base < 0xA0000) || |
| 7573 | (bp->common.shmem_base >= 0xC0000)) { |
| 7574 | BNX2X_DEV_INFO("MCP not active\n"); |
| 7575 | bp->flags |= NO_MCP_FLAG; |
| 7576 | return; |
| 7577 | } |
| 7578 | |
| 7579 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 7580 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 7581 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 7582 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 7583 | |
| 7584 | 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] | 7585 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7586 | |
| 7587 | bp->link_params.hw_led_mode = ((bp->common.hw_config & |
| 7588 | SHARED_HW_CFG_LED_MODE_MASK) >> |
| 7589 | SHARED_HW_CFG_LED_MODE_SHIFT); |
| 7590 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 7591 | bp->link_params.feature_config_flags = 0; |
| 7592 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); |
| 7593 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) |
| 7594 | bp->link_params.feature_config_flags |= |
| 7595 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 7596 | else |
| 7597 | bp->link_params.feature_config_flags &= |
| 7598 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 7599 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7600 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
| 7601 | bp->common.bc_ver = val; |
| 7602 | BNX2X_DEV_INFO("bc_ver %X\n", val); |
| 7603 | if (val < BNX2X_BC_VER) { |
| 7604 | /* for now only warn |
| 7605 | * later we might need to enforce this */ |
| 7606 | BNX2X_ERR("This driver needs bc_ver %X but found %X," |
| 7607 | " please upgrade BC\n", BNX2X_BC_VER, val); |
| 7608 | } |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 7609 | |
| 7610 | if (BP_E1HVN(bp) == 0) { |
| 7611 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
| 7612 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
| 7613 | } else { |
| 7614 | /* no WOL capability for E1HVN != 0 */ |
| 7615 | bp->flags |= NO_WOL_FLAG; |
| 7616 | } |
| 7617 | BNX2X_DEV_INFO("%sWoL capable\n", |
| 7618 | (bp->flags & NO_WOL_FLAG) ? "Not " : ""); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7619 | |
| 7620 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); |
| 7621 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); |
| 7622 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); |
| 7623 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); |
| 7624 | |
| 7625 | printk(KERN_INFO PFX "part number %X-%X-%X-%X\n", |
| 7626 | val, val2, val3, val4); |
| 7627 | } |
| 7628 | |
| 7629 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
| 7630 | u32 switch_cfg) |
| 7631 | { |
| 7632 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7633 | u32 ext_phy_type; |
| 7634 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7635 | switch (switch_cfg) { |
| 7636 | case SWITCH_CFG_1G: |
| 7637 | BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg); |
| 7638 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7639 | ext_phy_type = |
| 7640 | SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7641 | switch (ext_phy_type) { |
| 7642 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT: |
| 7643 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 7644 | ext_phy_type); |
| 7645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7646 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7647 | SUPPORTED_10baseT_Full | |
| 7648 | SUPPORTED_100baseT_Half | |
| 7649 | SUPPORTED_100baseT_Full | |
| 7650 | SUPPORTED_1000baseT_Full | |
| 7651 | SUPPORTED_2500baseX_Full | |
| 7652 | SUPPORTED_TP | |
| 7653 | SUPPORTED_FIBRE | |
| 7654 | SUPPORTED_Autoneg | |
| 7655 | SUPPORTED_Pause | |
| 7656 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7657 | break; |
| 7658 | |
| 7659 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482: |
| 7660 | BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n", |
| 7661 | ext_phy_type); |
| 7662 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7663 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7664 | SUPPORTED_10baseT_Full | |
| 7665 | SUPPORTED_100baseT_Half | |
| 7666 | SUPPORTED_100baseT_Full | |
| 7667 | SUPPORTED_1000baseT_Full | |
| 7668 | SUPPORTED_TP | |
| 7669 | SUPPORTED_FIBRE | |
| 7670 | SUPPORTED_Autoneg | |
| 7671 | SUPPORTED_Pause | |
| 7672 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7673 | break; |
| 7674 | |
| 7675 | default: |
| 7676 | BNX2X_ERR("NVRAM config error. " |
| 7677 | "BAD SerDes ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7678 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7679 | return; |
| 7680 | } |
| 7681 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7682 | bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + |
| 7683 | port*0x10); |
| 7684 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7685 | break; |
| 7686 | |
| 7687 | case SWITCH_CFG_10G: |
| 7688 | BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg); |
| 7689 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7690 | ext_phy_type = |
| 7691 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7692 | switch (ext_phy_type) { |
| 7693 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
| 7694 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 7695 | ext_phy_type); |
| 7696 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7697 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7698 | SUPPORTED_10baseT_Full | |
| 7699 | SUPPORTED_100baseT_Half | |
| 7700 | SUPPORTED_100baseT_Full | |
| 7701 | SUPPORTED_1000baseT_Full | |
| 7702 | SUPPORTED_2500baseX_Full | |
| 7703 | SUPPORTED_10000baseT_Full | |
| 7704 | SUPPORTED_TP | |
| 7705 | SUPPORTED_FIBRE | |
| 7706 | SUPPORTED_Autoneg | |
| 7707 | SUPPORTED_Pause | |
| 7708 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7709 | break; |
| 7710 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7711 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
| 7712 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n", |
| 7713 | ext_phy_type); |
| 7714 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7715 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7716 | SUPPORTED_1000baseT_Full | |
| 7717 | SUPPORTED_FIBRE | |
| 7718 | SUPPORTED_Autoneg | |
| 7719 | SUPPORTED_Pause | |
| 7720 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7721 | break; |
| 7722 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7723 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
| 7724 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n", |
| 7725 | ext_phy_type); |
| 7726 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7727 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7728 | SUPPORTED_2500baseX_Full | |
| 7729 | SUPPORTED_1000baseT_Full | |
| 7730 | SUPPORTED_FIBRE | |
| 7731 | SUPPORTED_Autoneg | |
| 7732 | SUPPORTED_Pause | |
| 7733 | SUPPORTED_Asym_Pause); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7734 | break; |
| 7735 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 7736 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
| 7737 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n", |
| 7738 | ext_phy_type); |
| 7739 | |
| 7740 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7741 | SUPPORTED_FIBRE | |
| 7742 | SUPPORTED_Pause | |
| 7743 | SUPPORTED_Asym_Pause); |
| 7744 | break; |
| 7745 | |
| 7746 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 7747 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n", |
| 7748 | ext_phy_type); |
| 7749 | |
| 7750 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7751 | SUPPORTED_1000baseT_Full | |
| 7752 | SUPPORTED_FIBRE | |
| 7753 | SUPPORTED_Pause | |
| 7754 | SUPPORTED_Asym_Pause); |
| 7755 | break; |
| 7756 | |
| 7757 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
| 7758 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n", |
| 7759 | ext_phy_type); |
| 7760 | |
| 7761 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7762 | SUPPORTED_1000baseT_Full | |
| 7763 | SUPPORTED_Autoneg | |
| 7764 | SUPPORTED_FIBRE | |
| 7765 | SUPPORTED_Pause | |
| 7766 | SUPPORTED_Asym_Pause); |
| 7767 | break; |
| 7768 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7769 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
| 7770 | BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n", |
| 7771 | ext_phy_type); |
| 7772 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7773 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7774 | SUPPORTED_TP | |
| 7775 | SUPPORTED_Autoneg | |
| 7776 | SUPPORTED_Pause | |
| 7777 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7778 | break; |
| 7779 | |
Eilon Greenstein | 2857718 | 2009-02-12 08:37:00 +0000 | [diff] [blame] | 7780 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481: |
| 7781 | BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n", |
| 7782 | ext_phy_type); |
| 7783 | |
| 7784 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7785 | SUPPORTED_10baseT_Full | |
| 7786 | SUPPORTED_100baseT_Half | |
| 7787 | SUPPORTED_100baseT_Full | |
| 7788 | SUPPORTED_1000baseT_Full | |
| 7789 | SUPPORTED_10000baseT_Full | |
| 7790 | SUPPORTED_TP | |
| 7791 | SUPPORTED_Autoneg | |
| 7792 | SUPPORTED_Pause | |
| 7793 | SUPPORTED_Asym_Pause); |
| 7794 | break; |
| 7795 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7796 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 7797 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 7798 | bp->link_params.ext_phy_config); |
| 7799 | break; |
| 7800 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7801 | default: |
| 7802 | BNX2X_ERR("NVRAM config error. " |
| 7803 | "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7804 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7805 | return; |
| 7806 | } |
| 7807 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7808 | bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + |
| 7809 | port*0x18); |
| 7810 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7811 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7812 | break; |
| 7813 | |
| 7814 | default: |
| 7815 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7816 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7817 | return; |
| 7818 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7819 | bp->link_params.phy_addr = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7820 | |
| 7821 | /* mask what we support according to speed_cap_mask */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7822 | if (!(bp->link_params.speed_cap_mask & |
| 7823 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7824 | bp->port.supported &= ~SUPPORTED_10baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7825 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7826 | if (!(bp->link_params.speed_cap_mask & |
| 7827 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7828 | bp->port.supported &= ~SUPPORTED_10baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7829 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7830 | if (!(bp->link_params.speed_cap_mask & |
| 7831 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7832 | bp->port.supported &= ~SUPPORTED_100baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7833 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7834 | if (!(bp->link_params.speed_cap_mask & |
| 7835 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7836 | bp->port.supported &= ~SUPPORTED_100baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7837 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7838 | if (!(bp->link_params.speed_cap_mask & |
| 7839 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7840 | bp->port.supported &= ~(SUPPORTED_1000baseT_Half | |
| 7841 | SUPPORTED_1000baseT_Full); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7842 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7843 | if (!(bp->link_params.speed_cap_mask & |
| 7844 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7845 | bp->port.supported &= ~SUPPORTED_2500baseX_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7846 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7847 | if (!(bp->link_params.speed_cap_mask & |
| 7848 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7849 | bp->port.supported &= ~SUPPORTED_10000baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7850 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7851 | BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7852 | } |
| 7853 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7854 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7855 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7856 | bp->link_params.req_duplex = DUPLEX_FULL; |
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 | switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7859 | case PORT_FEATURE_LINK_SPEED_AUTO: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7860 | if (bp->port.supported & SUPPORTED_Autoneg) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7861 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7862 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7863 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7864 | u32 ext_phy_type = |
| 7865 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 7866 | |
| 7867 | if ((ext_phy_type == |
| 7868 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) || |
| 7869 | (ext_phy_type == |
| 7870 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7871 | /* force 10G, no AN */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7872 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7873 | bp->port.advertising = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7874 | (ADVERTISED_10000baseT_Full | |
| 7875 | ADVERTISED_FIBRE); |
| 7876 | break; |
| 7877 | } |
| 7878 | BNX2X_ERR("NVRAM config error. " |
| 7879 | "Invalid link_config 0x%x" |
| 7880 | " Autoneg not supported\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7881 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7882 | return; |
| 7883 | } |
| 7884 | break; |
| 7885 | |
| 7886 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7887 | if (bp->port.supported & SUPPORTED_10baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7888 | bp->link_params.req_line_speed = SPEED_10; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7889 | bp->port.advertising = (ADVERTISED_10baseT_Full | |
| 7890 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7891 | } else { |
| 7892 | BNX2X_ERR("NVRAM config error. " |
| 7893 | "Invalid link_config 0x%x" |
| 7894 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7895 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7896 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7897 | return; |
| 7898 | } |
| 7899 | break; |
| 7900 | |
| 7901 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7902 | if (bp->port.supported & SUPPORTED_10baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7903 | bp->link_params.req_line_speed = SPEED_10; |
| 7904 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7905 | bp->port.advertising = (ADVERTISED_10baseT_Half | |
| 7906 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7907 | } else { |
| 7908 | BNX2X_ERR("NVRAM config error. " |
| 7909 | "Invalid link_config 0x%x" |
| 7910 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7911 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7912 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7913 | return; |
| 7914 | } |
| 7915 | break; |
| 7916 | |
| 7917 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7918 | if (bp->port.supported & SUPPORTED_100baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7919 | bp->link_params.req_line_speed = SPEED_100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7920 | bp->port.advertising = (ADVERTISED_100baseT_Full | |
| 7921 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7922 | } else { |
| 7923 | BNX2X_ERR("NVRAM config error. " |
| 7924 | "Invalid link_config 0x%x" |
| 7925 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7926 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7927 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7928 | return; |
| 7929 | } |
| 7930 | break; |
| 7931 | |
| 7932 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7933 | if (bp->port.supported & SUPPORTED_100baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7934 | bp->link_params.req_line_speed = SPEED_100; |
| 7935 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7936 | bp->port.advertising = (ADVERTISED_100baseT_Half | |
| 7937 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7938 | } else { |
| 7939 | BNX2X_ERR("NVRAM config error. " |
| 7940 | "Invalid link_config 0x%x" |
| 7941 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7942 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7943 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7944 | return; |
| 7945 | } |
| 7946 | break; |
| 7947 | |
| 7948 | case PORT_FEATURE_LINK_SPEED_1G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7949 | if (bp->port.supported & SUPPORTED_1000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7950 | bp->link_params.req_line_speed = SPEED_1000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7951 | bp->port.advertising = (ADVERTISED_1000baseT_Full | |
| 7952 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7953 | } else { |
| 7954 | BNX2X_ERR("NVRAM config error. " |
| 7955 | "Invalid link_config 0x%x" |
| 7956 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7957 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7958 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7959 | return; |
| 7960 | } |
| 7961 | break; |
| 7962 | |
| 7963 | case PORT_FEATURE_LINK_SPEED_2_5G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7964 | if (bp->port.supported & SUPPORTED_2500baseX_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7965 | bp->link_params.req_line_speed = SPEED_2500; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7966 | bp->port.advertising = (ADVERTISED_2500baseX_Full | |
| 7967 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7968 | } else { |
| 7969 | BNX2X_ERR("NVRAM config error. " |
| 7970 | "Invalid link_config 0x%x" |
| 7971 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7972 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7973 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7974 | return; |
| 7975 | } |
| 7976 | break; |
| 7977 | |
| 7978 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
| 7979 | case PORT_FEATURE_LINK_SPEED_10G_KX4: |
| 7980 | case PORT_FEATURE_LINK_SPEED_10G_KR: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7981 | if (bp->port.supported & SUPPORTED_10000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7982 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7983 | bp->port.advertising = (ADVERTISED_10000baseT_Full | |
| 7984 | ADVERTISED_FIBRE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7985 | } else { |
| 7986 | BNX2X_ERR("NVRAM config error. " |
| 7987 | "Invalid link_config 0x%x" |
| 7988 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7989 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7990 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7991 | return; |
| 7992 | } |
| 7993 | break; |
| 7994 | |
| 7995 | default: |
| 7996 | BNX2X_ERR("NVRAM config error. " |
| 7997 | "BAD link speed link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7998 | bp->port.link_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7999 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8000 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8001 | break; |
| 8002 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8003 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8004 | bp->link_params.req_flow_ctrl = (bp->port.link_config & |
| 8005 | PORT_FEATURE_FLOW_CONTROL_MASK); |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8006 | if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) && |
Randy Dunlap | 4ab84d4 | 2008-08-07 20:33:19 -0700 | [diff] [blame] | 8007 | !(bp->port.supported & SUPPORTED_Autoneg)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8008 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8009 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8010 | 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] | 8011 | " advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8012 | bp->link_params.req_line_speed, |
| 8013 | bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8014 | bp->link_params.req_flow_ctrl, bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8015 | } |
| 8016 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8017 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8018 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8019 | int port = BP_PORT(bp); |
| 8020 | u32 val, val2; |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8021 | u32 config; |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8022 | u16 i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8023 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8024 | bp->link_params.bp = bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8025 | bp->link_params.port = port; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8026 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8027 | bp->link_params.lane_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8028 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8029 | bp->link_params.ext_phy_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8030 | SHMEM_RD(bp, |
| 8031 | dev_info.port_hw_config[port].external_phy_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8032 | bp->link_params.speed_cap_mask = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8033 | SHMEM_RD(bp, |
| 8034 | dev_info.port_hw_config[port].speed_capability_mask); |
| 8035 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8036 | bp->port.link_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8037 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
| 8038 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8039 | /* Get the 4 lanes xgxs config rx and tx */ |
| 8040 | for (i = 0; i < 2; i++) { |
| 8041 | val = SHMEM_RD(bp, |
| 8042 | dev_info.port_hw_config[port].xgxs_config_rx[i<<1]); |
| 8043 | bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff); |
| 8044 | bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff); |
| 8045 | |
| 8046 | val = SHMEM_RD(bp, |
| 8047 | dev_info.port_hw_config[port].xgxs_config_tx[i<<1]); |
| 8048 | bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff); |
| 8049 | bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff); |
| 8050 | } |
| 8051 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8052 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
| 8053 | if (config & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_ENABLED) |
| 8054 | bp->link_params.feature_config_flags |= |
| 8055 | FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED; |
| 8056 | else |
| 8057 | bp->link_params.feature_config_flags &= |
| 8058 | ~FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED; |
| 8059 | |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8060 | /* If the device is capable of WoL, set the default state according |
| 8061 | * to the HW |
| 8062 | */ |
| 8063 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
| 8064 | (config & PORT_FEATURE_WOL_ENABLED)); |
| 8065 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8066 | BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x" |
| 8067 | " speed_cap_mask 0x%08x link_config 0x%08x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8068 | bp->link_params.lane_config, |
| 8069 | bp->link_params.ext_phy_config, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8070 | bp->link_params.speed_cap_mask, bp->port.link_config); |
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 | bp->link_params.switch_cfg = (bp->port.link_config & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8073 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
| 8074 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8075 | |
| 8076 | bnx2x_link_settings_requested(bp); |
| 8077 | |
| 8078 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); |
| 8079 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); |
| 8080 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 8081 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 8082 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 8083 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 8084 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 8085 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8086 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8087 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8088 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8089 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8090 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) |
| 8091 | { |
| 8092 | int func = BP_FUNC(bp); |
| 8093 | u32 val, val2; |
| 8094 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8095 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8096 | bnx2x_get_common_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8097 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8098 | bp->e1hov = 0; |
| 8099 | bp->e1hmf = 0; |
| 8100 | if (CHIP_IS_E1H(bp)) { |
| 8101 | bp->mf_config = |
| 8102 | SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8103 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 8104 | val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].e1hov_tag) & |
| 8105 | FUNC_MF_CFG_E1HOV_TAG_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8106 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8107 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8108 | bp->e1hov = val; |
| 8109 | bp->e1hmf = 1; |
| 8110 | BNX2X_DEV_INFO("MF mode E1HOV for func %d is %d " |
| 8111 | "(0x%04x)\n", |
| 8112 | func, bp->e1hov, bp->e1hov); |
| 8113 | } else { |
| 8114 | BNX2X_DEV_INFO("Single function mode\n"); |
| 8115 | if (BP_E1HVN(bp)) { |
| 8116 | BNX2X_ERR("!!! No valid E1HOV for func %d," |
| 8117 | " aborting\n", func); |
| 8118 | rc = -EPERM; |
| 8119 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8120 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8121 | } |
| 8122 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8123 | if (!BP_NOMCP(bp)) { |
| 8124 | bnx2x_get_port_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8125 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8126 | bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) & |
| 8127 | DRV_MSG_SEQ_NUMBER_MASK); |
| 8128 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 8129 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8130 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8131 | if (IS_E1HMF(bp)) { |
| 8132 | val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper); |
| 8133 | val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower); |
| 8134 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && |
| 8135 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) { |
| 8136 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 8137 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 8138 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 8139 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 8140 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 8141 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
| 8142 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, |
| 8143 | ETH_ALEN); |
| 8144 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, |
| 8145 | ETH_ALEN); |
| 8146 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8147 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8148 | return rc; |
| 8149 | } |
| 8150 | |
| 8151 | if (BP_NOMCP(bp)) { |
| 8152 | /* only supposed to happen on emulation/FPGA */ |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 8153 | BNX2X_ERR("warning random MAC workaround active\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8154 | random_ether_addr(bp->dev->dev_addr); |
| 8155 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8156 | } |
| 8157 | |
| 8158 | return rc; |
| 8159 | } |
| 8160 | |
| 8161 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
| 8162 | { |
| 8163 | int func = BP_FUNC(bp); |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 8164 | int timer_interval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8165 | int rc; |
| 8166 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8167 | /* Disable interrupt handling until HW is initialized */ |
| 8168 | atomic_set(&bp->intr_sem, 1); |
| 8169 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8170 | mutex_init(&bp->port.phy_mutex); |
| 8171 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 8172 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8173 | INIT_WORK(&bp->reset_task, bnx2x_reset_task); |
| 8174 | |
| 8175 | rc = bnx2x_get_hwinfo(bp); |
| 8176 | |
| 8177 | /* need to reset chip if undi was active */ |
| 8178 | if (!BP_NOMCP(bp)) |
| 8179 | bnx2x_undi_unload(bp); |
| 8180 | |
| 8181 | if (CHIP_REV_IS_FPGA(bp)) |
| 8182 | printk(KERN_ERR PFX "FPGA detected\n"); |
| 8183 | |
| 8184 | if (BP_NOMCP(bp) && (func == 0)) |
| 8185 | printk(KERN_ERR PFX |
| 8186 | "MCP disabled, must load devices in order!\n"); |
| 8187 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8188 | /* Set multi queue mode */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 8189 | if ((multi_mode != ETH_RSS_MODE_DISABLED) && |
| 8190 | ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8191 | printk(KERN_ERR PFX |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 8192 | "Multi disabled since int_mode requested is not MSI-X\n"); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8193 | multi_mode = ETH_RSS_MODE_DISABLED; |
| 8194 | } |
| 8195 | bp->multi_mode = multi_mode; |
| 8196 | |
| 8197 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 8198 | /* Set TPA flags */ |
| 8199 | if (disable_tpa) { |
| 8200 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 8201 | bp->dev->features &= ~NETIF_F_LRO; |
| 8202 | } else { |
| 8203 | bp->flags |= TPA_ENABLE_FLAG; |
| 8204 | bp->dev->features |= NETIF_F_LRO; |
| 8205 | } |
| 8206 | |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 8207 | bp->mrrs = mrrs; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 8208 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8209 | bp->tx_ring_size = MAX_TX_AVAIL; |
| 8210 | bp->rx_ring_size = MAX_RX_AVAIL; |
| 8211 | |
| 8212 | bp->rx_csum = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8213 | |
| 8214 | bp->tx_ticks = 50; |
| 8215 | bp->rx_ticks = 25; |
| 8216 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 8217 | timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ); |
| 8218 | bp->current_interval = (poll ? poll : timer_interval); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8219 | |
| 8220 | init_timer(&bp->timer); |
| 8221 | bp->timer.expires = jiffies + bp->current_interval; |
| 8222 | bp->timer.data = (unsigned long) bp; |
| 8223 | bp->timer.function = bnx2x_timer; |
| 8224 | |
| 8225 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8226 | } |
| 8227 | |
| 8228 | /* |
| 8229 | * ethtool service functions |
| 8230 | */ |
| 8231 | |
| 8232 | /* All ethtool functions called with rtnl_lock */ |
| 8233 | |
| 8234 | static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8235 | { |
| 8236 | struct bnx2x *bp = netdev_priv(dev); |
| 8237 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8238 | cmd->supported = bp->port.supported; |
| 8239 | cmd->advertising = bp->port.advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8240 | |
| 8241 | if (netif_carrier_ok(dev)) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8242 | cmd->speed = bp->link_vars.line_speed; |
| 8243 | cmd->duplex = bp->link_vars.duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8244 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8245 | cmd->speed = bp->link_params.req_line_speed; |
| 8246 | cmd->duplex = bp->link_params.req_duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8247 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8248 | if (IS_E1HMF(bp)) { |
| 8249 | u16 vn_max_rate; |
| 8250 | |
| 8251 | vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 8252 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 8253 | if (vn_max_rate < cmd->speed) |
| 8254 | cmd->speed = vn_max_rate; |
| 8255 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8256 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8257 | if (bp->link_params.switch_cfg == SWITCH_CFG_10G) { |
| 8258 | u32 ext_phy_type = |
| 8259 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8260 | |
| 8261 | switch (ext_phy_type) { |
| 8262 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8263 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8264 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8265 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
| 8266 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 8267 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8268 | cmd->port = PORT_FIBRE; |
| 8269 | break; |
| 8270 | |
| 8271 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 2857718 | 2009-02-12 08:37:00 +0000 | [diff] [blame] | 8272 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8273 | cmd->port = PORT_TP; |
| 8274 | break; |
| 8275 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8276 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 8277 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 8278 | bp->link_params.ext_phy_config); |
| 8279 | break; |
| 8280 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8281 | default: |
| 8282 | DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8283 | bp->link_params.ext_phy_config); |
| 8284 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8285 | } |
| 8286 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8287 | cmd->port = PORT_TP; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8288 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8289 | cmd->phy_address = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8290 | cmd->transceiver = XCVR_INTERNAL; |
| 8291 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8292 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8293 | cmd->autoneg = AUTONEG_ENABLE; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8294 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8295 | cmd->autoneg = AUTONEG_DISABLE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8296 | |
| 8297 | cmd->maxtxpkt = 0; |
| 8298 | cmd->maxrxpkt = 0; |
| 8299 | |
| 8300 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8301 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8302 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8303 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8304 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8305 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8306 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8307 | |
| 8308 | return 0; |
| 8309 | } |
| 8310 | |
| 8311 | static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8312 | { |
| 8313 | struct bnx2x *bp = netdev_priv(dev); |
| 8314 | u32 advertising; |
| 8315 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8316 | if (IS_E1HMF(bp)) |
| 8317 | return 0; |
| 8318 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8319 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8320 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8321 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8322 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8323 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8324 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8325 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8326 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8327 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8328 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
| 8329 | DP(NETIF_MSG_LINK, "Autoneg not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8330 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8331 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8332 | |
| 8333 | /* advertise the requested speed and duplex if supported */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8334 | cmd->advertising &= bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8335 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8336 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
| 8337 | bp->link_params.req_duplex = DUPLEX_FULL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8338 | bp->port.advertising |= (ADVERTISED_Autoneg | |
| 8339 | cmd->advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8340 | |
| 8341 | } else { /* forced speed */ |
| 8342 | /* advertise the requested speed and duplex if supported */ |
| 8343 | switch (cmd->speed) { |
| 8344 | case SPEED_10: |
| 8345 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8346 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8347 | SUPPORTED_10baseT_Full)) { |
| 8348 | DP(NETIF_MSG_LINK, |
| 8349 | "10M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8350 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8351 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8352 | |
| 8353 | advertising = (ADVERTISED_10baseT_Full | |
| 8354 | ADVERTISED_TP); |
| 8355 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8356 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8357 | SUPPORTED_10baseT_Half)) { |
| 8358 | DP(NETIF_MSG_LINK, |
| 8359 | "10M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8360 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8361 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8362 | |
| 8363 | advertising = (ADVERTISED_10baseT_Half | |
| 8364 | ADVERTISED_TP); |
| 8365 | } |
| 8366 | break; |
| 8367 | |
| 8368 | case SPEED_100: |
| 8369 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8370 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8371 | SUPPORTED_100baseT_Full)) { |
| 8372 | DP(NETIF_MSG_LINK, |
| 8373 | "100M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8374 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8375 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8376 | |
| 8377 | advertising = (ADVERTISED_100baseT_Full | |
| 8378 | ADVERTISED_TP); |
| 8379 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8380 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8381 | SUPPORTED_100baseT_Half)) { |
| 8382 | DP(NETIF_MSG_LINK, |
| 8383 | "100M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8384 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8385 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8386 | |
| 8387 | advertising = (ADVERTISED_100baseT_Half | |
| 8388 | ADVERTISED_TP); |
| 8389 | } |
| 8390 | break; |
| 8391 | |
| 8392 | case SPEED_1000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8393 | if (cmd->duplex != DUPLEX_FULL) { |
| 8394 | DP(NETIF_MSG_LINK, "1G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8395 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8396 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8397 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8398 | if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8399 | DP(NETIF_MSG_LINK, "1G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8400 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8401 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8402 | |
| 8403 | advertising = (ADVERTISED_1000baseT_Full | |
| 8404 | ADVERTISED_TP); |
| 8405 | break; |
| 8406 | |
| 8407 | case SPEED_2500: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8408 | if (cmd->duplex != DUPLEX_FULL) { |
| 8409 | DP(NETIF_MSG_LINK, |
| 8410 | "2.5G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8411 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8412 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8413 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8414 | if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8415 | DP(NETIF_MSG_LINK, |
| 8416 | "2.5G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8417 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8418 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8419 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8420 | advertising = (ADVERTISED_2500baseX_Full | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8421 | ADVERTISED_TP); |
| 8422 | break; |
| 8423 | |
| 8424 | case SPEED_10000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8425 | if (cmd->duplex != DUPLEX_FULL) { |
| 8426 | DP(NETIF_MSG_LINK, "10G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8427 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8428 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8429 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8430 | if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8431 | DP(NETIF_MSG_LINK, "10G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8432 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8433 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8434 | |
| 8435 | advertising = (ADVERTISED_10000baseT_Full | |
| 8436 | ADVERTISED_FIBRE); |
| 8437 | break; |
| 8438 | |
| 8439 | default: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8440 | DP(NETIF_MSG_LINK, "Unsupported speed\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8441 | return -EINVAL; |
| 8442 | } |
| 8443 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8444 | bp->link_params.req_line_speed = cmd->speed; |
| 8445 | bp->link_params.req_duplex = cmd->duplex; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8446 | bp->port.advertising = advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8447 | } |
| 8448 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8449 | DP(NETIF_MSG_LINK, "req_line_speed %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8450 | DP_LEVEL " req_duplex %d advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8451 | bp->link_params.req_line_speed, bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8452 | bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8453 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8454 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8455 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8456 | bnx2x_link_set(bp); |
| 8457 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8458 | |
| 8459 | return 0; |
| 8460 | } |
| 8461 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8462 | #define PHY_FW_VER_LEN 10 |
| 8463 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8464 | static void bnx2x_get_drvinfo(struct net_device *dev, |
| 8465 | struct ethtool_drvinfo *info) |
| 8466 | { |
| 8467 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | f0e53a8 | 2008-08-13 15:58:30 -0700 | [diff] [blame] | 8468 | u8 phy_fw_ver[PHY_FW_VER_LEN]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8469 | |
| 8470 | strcpy(info->driver, DRV_MODULE_NAME); |
| 8471 | strcpy(info->version, DRV_MODULE_VERSION); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8472 | |
| 8473 | phy_fw_ver[0] = '\0'; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8474 | if (bp->port.pmf) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8475 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8476 | bnx2x_get_ext_phy_fw_version(&bp->link_params, |
| 8477 | (bp->state != BNX2X_STATE_CLOSED), |
| 8478 | phy_fw_ver, PHY_FW_VER_LEN); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8479 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8480 | } |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8481 | |
Eilon Greenstein | f0e53a8 | 2008-08-13 15:58:30 -0700 | [diff] [blame] | 8482 | snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s", |
| 8483 | (bp->common.bc_ver & 0xff0000) >> 16, |
| 8484 | (bp->common.bc_ver & 0xff00) >> 8, |
| 8485 | (bp->common.bc_ver & 0xff), |
| 8486 | ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8487 | strcpy(info->bus_info, pci_name(bp->pdev)); |
| 8488 | info->n_stats = BNX2X_NUM_STATS; |
| 8489 | info->testinfo_len = BNX2X_NUM_TESTS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8490 | info->eedump_len = bp->common.flash_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8491 | info->regdump_len = 0; |
| 8492 | } |
| 8493 | |
| 8494 | static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 8495 | { |
| 8496 | struct bnx2x *bp = netdev_priv(dev); |
| 8497 | |
| 8498 | if (bp->flags & NO_WOL_FLAG) { |
| 8499 | wol->supported = 0; |
| 8500 | wol->wolopts = 0; |
| 8501 | } else { |
| 8502 | wol->supported = WAKE_MAGIC; |
| 8503 | if (bp->wol) |
| 8504 | wol->wolopts = WAKE_MAGIC; |
| 8505 | else |
| 8506 | wol->wolopts = 0; |
| 8507 | } |
| 8508 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 8509 | } |
| 8510 | |
| 8511 | static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 8512 | { |
| 8513 | struct bnx2x *bp = netdev_priv(dev); |
| 8514 | |
| 8515 | if (wol->wolopts & ~WAKE_MAGIC) |
| 8516 | return -EINVAL; |
| 8517 | |
| 8518 | if (wol->wolopts & WAKE_MAGIC) { |
| 8519 | if (bp->flags & NO_WOL_FLAG) |
| 8520 | return -EINVAL; |
| 8521 | |
| 8522 | bp->wol = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8523 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8524 | bp->wol = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8525 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8526 | return 0; |
| 8527 | } |
| 8528 | |
| 8529 | static u32 bnx2x_get_msglevel(struct net_device *dev) |
| 8530 | { |
| 8531 | struct bnx2x *bp = netdev_priv(dev); |
| 8532 | |
| 8533 | return bp->msglevel; |
| 8534 | } |
| 8535 | |
| 8536 | static void bnx2x_set_msglevel(struct net_device *dev, u32 level) |
| 8537 | { |
| 8538 | struct bnx2x *bp = netdev_priv(dev); |
| 8539 | |
| 8540 | if (capable(CAP_NET_ADMIN)) |
| 8541 | bp->msglevel = level; |
| 8542 | } |
| 8543 | |
| 8544 | static int bnx2x_nway_reset(struct net_device *dev) |
| 8545 | { |
| 8546 | struct bnx2x *bp = netdev_priv(dev); |
| 8547 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8548 | if (!bp->port.pmf) |
| 8549 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8550 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8551 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8552 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8553 | bnx2x_link_set(bp); |
| 8554 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8555 | |
| 8556 | return 0; |
| 8557 | } |
| 8558 | |
| 8559 | static int bnx2x_get_eeprom_len(struct net_device *dev) |
| 8560 | { |
| 8561 | struct bnx2x *bp = netdev_priv(dev); |
| 8562 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8563 | return bp->common.flash_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8564 | } |
| 8565 | |
| 8566 | static int bnx2x_acquire_nvram_lock(struct bnx2x *bp) |
| 8567 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8568 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8569 | int count, i; |
| 8570 | u32 val = 0; |
| 8571 | |
| 8572 | /* adjust timeout for emulation/FPGA */ |
| 8573 | count = NVRAM_TIMEOUT_COUNT; |
| 8574 | if (CHIP_REV_IS_SLOW(bp)) |
| 8575 | count *= 100; |
| 8576 | |
| 8577 | /* request access to nvram interface */ |
| 8578 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 8579 | (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port)); |
| 8580 | |
| 8581 | for (i = 0; i < count*10; i++) { |
| 8582 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 8583 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) |
| 8584 | break; |
| 8585 | |
| 8586 | udelay(5); |
| 8587 | } |
| 8588 | |
| 8589 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8590 | DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8591 | return -EBUSY; |
| 8592 | } |
| 8593 | |
| 8594 | return 0; |
| 8595 | } |
| 8596 | |
| 8597 | static int bnx2x_release_nvram_lock(struct bnx2x *bp) |
| 8598 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8599 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8600 | int count, i; |
| 8601 | u32 val = 0; |
| 8602 | |
| 8603 | /* adjust timeout for emulation/FPGA */ |
| 8604 | count = NVRAM_TIMEOUT_COUNT; |
| 8605 | if (CHIP_REV_IS_SLOW(bp)) |
| 8606 | count *= 100; |
| 8607 | |
| 8608 | /* relinquish nvram interface */ |
| 8609 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 8610 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port)); |
| 8611 | |
| 8612 | for (i = 0; i < count*10; i++) { |
| 8613 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 8614 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) |
| 8615 | break; |
| 8616 | |
| 8617 | udelay(5); |
| 8618 | } |
| 8619 | |
| 8620 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8621 | DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8622 | return -EBUSY; |
| 8623 | } |
| 8624 | |
| 8625 | return 0; |
| 8626 | } |
| 8627 | |
| 8628 | static void bnx2x_enable_nvram_access(struct bnx2x *bp) |
| 8629 | { |
| 8630 | u32 val; |
| 8631 | |
| 8632 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 8633 | |
| 8634 | /* enable both bits, even on read */ |
| 8635 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 8636 | (val | MCPR_NVM_ACCESS_ENABLE_EN | |
| 8637 | MCPR_NVM_ACCESS_ENABLE_WR_EN)); |
| 8638 | } |
| 8639 | |
| 8640 | static void bnx2x_disable_nvram_access(struct bnx2x *bp) |
| 8641 | { |
| 8642 | u32 val; |
| 8643 | |
| 8644 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 8645 | |
| 8646 | /* disable both bits, even after read */ |
| 8647 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 8648 | (val & ~(MCPR_NVM_ACCESS_ENABLE_EN | |
| 8649 | MCPR_NVM_ACCESS_ENABLE_WR_EN))); |
| 8650 | } |
| 8651 | |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 8652 | static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8653 | u32 cmd_flags) |
| 8654 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8655 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8656 | u32 val; |
| 8657 | |
| 8658 | /* build the command word */ |
| 8659 | cmd_flags |= MCPR_NVM_COMMAND_DOIT; |
| 8660 | |
| 8661 | /* need to clear DONE bit separately */ |
| 8662 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 8663 | |
| 8664 | /* address of the NVRAM to read from */ |
| 8665 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 8666 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 8667 | |
| 8668 | /* issue a read command */ |
| 8669 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 8670 | |
| 8671 | /* adjust timeout for emulation/FPGA */ |
| 8672 | count = NVRAM_TIMEOUT_COUNT; |
| 8673 | if (CHIP_REV_IS_SLOW(bp)) |
| 8674 | count *= 100; |
| 8675 | |
| 8676 | /* wait for completion */ |
| 8677 | *ret_val = 0; |
| 8678 | rc = -EBUSY; |
| 8679 | for (i = 0; i < count; i++) { |
| 8680 | udelay(5); |
| 8681 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 8682 | |
| 8683 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 8684 | val = REG_RD(bp, MCP_REG_MCPR_NVM_READ); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8685 | /* we read nvram data in cpu order |
| 8686 | * but ethtool sees it as an array of bytes |
| 8687 | * converting to big-endian will do the work */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 8688 | *ret_val = cpu_to_be32(val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8689 | rc = 0; |
| 8690 | break; |
| 8691 | } |
| 8692 | } |
| 8693 | |
| 8694 | return rc; |
| 8695 | } |
| 8696 | |
| 8697 | static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf, |
| 8698 | int buf_size) |
| 8699 | { |
| 8700 | int rc; |
| 8701 | u32 cmd_flags; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 8702 | __be32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8703 | |
| 8704 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8705 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 8706 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8707 | offset, buf_size); |
| 8708 | return -EINVAL; |
| 8709 | } |
| 8710 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8711 | if (offset + buf_size > bp->common.flash_size) { |
| 8712 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8713 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8714 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8715 | return -EINVAL; |
| 8716 | } |
| 8717 | |
| 8718 | /* request access to nvram interface */ |
| 8719 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8720 | if (rc) |
| 8721 | return rc; |
| 8722 | |
| 8723 | /* enable access to nvram interface */ |
| 8724 | bnx2x_enable_nvram_access(bp); |
| 8725 | |
| 8726 | /* read the first word(s) */ |
| 8727 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 8728 | while ((buf_size > sizeof(u32)) && (rc == 0)) { |
| 8729 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 8730 | memcpy(ret_buf, &val, 4); |
| 8731 | |
| 8732 | /* advance to the next dword */ |
| 8733 | offset += sizeof(u32); |
| 8734 | ret_buf += sizeof(u32); |
| 8735 | buf_size -= sizeof(u32); |
| 8736 | cmd_flags = 0; |
| 8737 | } |
| 8738 | |
| 8739 | if (rc == 0) { |
| 8740 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8741 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 8742 | memcpy(ret_buf, &val, 4); |
| 8743 | } |
| 8744 | |
| 8745 | /* disable access to nvram interface */ |
| 8746 | bnx2x_disable_nvram_access(bp); |
| 8747 | bnx2x_release_nvram_lock(bp); |
| 8748 | |
| 8749 | return rc; |
| 8750 | } |
| 8751 | |
| 8752 | static int bnx2x_get_eeprom(struct net_device *dev, |
| 8753 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 8754 | { |
| 8755 | struct bnx2x *bp = netdev_priv(dev); |
| 8756 | int rc; |
| 8757 | |
Eilon Greenstein | 2add3ac | 2009-01-14 06:44:07 +0000 | [diff] [blame] | 8758 | if (!netif_running(dev)) |
| 8759 | return -EAGAIN; |
| 8760 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8761 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8762 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 8763 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 8764 | eeprom->len, eeprom->len); |
| 8765 | |
| 8766 | /* parameters already validated in ethtool_get_eeprom */ |
| 8767 | |
| 8768 | rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len); |
| 8769 | |
| 8770 | return rc; |
| 8771 | } |
| 8772 | |
| 8773 | static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val, |
| 8774 | u32 cmd_flags) |
| 8775 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8776 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8777 | |
| 8778 | /* build the command word */ |
| 8779 | cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR; |
| 8780 | |
| 8781 | /* need to clear DONE bit separately */ |
| 8782 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 8783 | |
| 8784 | /* write the data */ |
| 8785 | REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val); |
| 8786 | |
| 8787 | /* address of the NVRAM to write to */ |
| 8788 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 8789 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 8790 | |
| 8791 | /* issue the write command */ |
| 8792 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 8793 | |
| 8794 | /* adjust timeout for emulation/FPGA */ |
| 8795 | count = NVRAM_TIMEOUT_COUNT; |
| 8796 | if (CHIP_REV_IS_SLOW(bp)) |
| 8797 | count *= 100; |
| 8798 | |
| 8799 | /* wait for completion */ |
| 8800 | rc = -EBUSY; |
| 8801 | for (i = 0; i < count; i++) { |
| 8802 | udelay(5); |
| 8803 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 8804 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 8805 | rc = 0; |
| 8806 | break; |
| 8807 | } |
| 8808 | } |
| 8809 | |
| 8810 | return rc; |
| 8811 | } |
| 8812 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8813 | #define BYTE_OFFSET(offset) (8 * (offset & 0x03)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8814 | |
| 8815 | static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 8816 | int buf_size) |
| 8817 | { |
| 8818 | int rc; |
| 8819 | u32 cmd_flags; |
| 8820 | u32 align_offset; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 8821 | __be32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8822 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8823 | if (offset + buf_size > bp->common.flash_size) { |
| 8824 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8825 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8826 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8827 | return -EINVAL; |
| 8828 | } |
| 8829 | |
| 8830 | /* request access to nvram interface */ |
| 8831 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8832 | if (rc) |
| 8833 | return rc; |
| 8834 | |
| 8835 | /* enable access to nvram interface */ |
| 8836 | bnx2x_enable_nvram_access(bp); |
| 8837 | |
| 8838 | cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST); |
| 8839 | align_offset = (offset & ~0x03); |
| 8840 | rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags); |
| 8841 | |
| 8842 | if (rc == 0) { |
| 8843 | val &= ~(0xff << BYTE_OFFSET(offset)); |
| 8844 | val |= (*data_buf << BYTE_OFFSET(offset)); |
| 8845 | |
| 8846 | /* nvram data is returned as an array of bytes |
| 8847 | * convert it back to cpu order */ |
| 8848 | val = be32_to_cpu(val); |
| 8849 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8850 | rc = bnx2x_nvram_write_dword(bp, align_offset, val, |
| 8851 | cmd_flags); |
| 8852 | } |
| 8853 | |
| 8854 | /* disable access to nvram interface */ |
| 8855 | bnx2x_disable_nvram_access(bp); |
| 8856 | bnx2x_release_nvram_lock(bp); |
| 8857 | |
| 8858 | return rc; |
| 8859 | } |
| 8860 | |
| 8861 | static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 8862 | int buf_size) |
| 8863 | { |
| 8864 | int rc; |
| 8865 | u32 cmd_flags; |
| 8866 | u32 val; |
| 8867 | u32 written_so_far; |
| 8868 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8869 | if (buf_size == 1) /* ethtool */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8870 | return bnx2x_nvram_write1(bp, offset, data_buf, buf_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8871 | |
| 8872 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8873 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 8874 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8875 | offset, buf_size); |
| 8876 | return -EINVAL; |
| 8877 | } |
| 8878 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8879 | if (offset + buf_size > bp->common.flash_size) { |
| 8880 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8881 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8882 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8883 | return -EINVAL; |
| 8884 | } |
| 8885 | |
| 8886 | /* request access to nvram interface */ |
| 8887 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8888 | if (rc) |
| 8889 | return rc; |
| 8890 | |
| 8891 | /* enable access to nvram interface */ |
| 8892 | bnx2x_enable_nvram_access(bp); |
| 8893 | |
| 8894 | written_so_far = 0; |
| 8895 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 8896 | while ((written_so_far < buf_size) && (rc == 0)) { |
| 8897 | if (written_so_far == (buf_size - sizeof(u32))) |
| 8898 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8899 | else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) |
| 8900 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8901 | else if ((offset % NVRAM_PAGE_SIZE) == 0) |
| 8902 | cmd_flags |= MCPR_NVM_COMMAND_FIRST; |
| 8903 | |
| 8904 | memcpy(&val, data_buf, 4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8905 | |
| 8906 | rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags); |
| 8907 | |
| 8908 | /* advance to the next dword */ |
| 8909 | offset += sizeof(u32); |
| 8910 | data_buf += sizeof(u32); |
| 8911 | written_so_far += sizeof(u32); |
| 8912 | cmd_flags = 0; |
| 8913 | } |
| 8914 | |
| 8915 | /* disable access to nvram interface */ |
| 8916 | bnx2x_disable_nvram_access(bp); |
| 8917 | bnx2x_release_nvram_lock(bp); |
| 8918 | |
| 8919 | return rc; |
| 8920 | } |
| 8921 | |
| 8922 | static int bnx2x_set_eeprom(struct net_device *dev, |
| 8923 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 8924 | { |
| 8925 | struct bnx2x *bp = netdev_priv(dev); |
| 8926 | int rc; |
| 8927 | |
Eilon Greenstein | 9f4c958 | 2009-01-08 11:21:43 -0800 | [diff] [blame] | 8928 | if (!netif_running(dev)) |
| 8929 | return -EAGAIN; |
| 8930 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8931 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8932 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 8933 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 8934 | eeprom->len, eeprom->len); |
| 8935 | |
| 8936 | /* parameters already validated in ethtool_set_eeprom */ |
| 8937 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8938 | /* If the magic number is PHY (0x00504859) upgrade the PHY FW */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8939 | if (eeprom->magic == 0x00504859) |
| 8940 | if (bp->port.pmf) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8941 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8942 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8943 | rc = bnx2x_flash_download(bp, BP_PORT(bp), |
| 8944 | bp->link_params.ext_phy_config, |
| 8945 | (bp->state != BNX2X_STATE_CLOSED), |
| 8946 | eebuf, eeprom->len); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8947 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 8948 | (bp->state == BNX2X_STATE_DISABLED)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8949 | rc |= bnx2x_link_reset(&bp->link_params, |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8950 | &bp->link_vars, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8951 | rc |= bnx2x_phy_init(&bp->link_params, |
| 8952 | &bp->link_vars); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8953 | } |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8954 | bnx2x_release_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8955 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8956 | } else /* Only the PMF can access the PHY */ |
| 8957 | return -EINVAL; |
| 8958 | else |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8959 | rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8960 | |
| 8961 | return rc; |
| 8962 | } |
| 8963 | |
| 8964 | static int bnx2x_get_coalesce(struct net_device *dev, |
| 8965 | struct ethtool_coalesce *coal) |
| 8966 | { |
| 8967 | struct bnx2x *bp = netdev_priv(dev); |
| 8968 | |
| 8969 | memset(coal, 0, sizeof(struct ethtool_coalesce)); |
| 8970 | |
| 8971 | coal->rx_coalesce_usecs = bp->rx_ticks; |
| 8972 | coal->tx_coalesce_usecs = bp->tx_ticks; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8973 | |
| 8974 | return 0; |
| 8975 | } |
| 8976 | |
| 8977 | static int bnx2x_set_coalesce(struct net_device *dev, |
| 8978 | struct ethtool_coalesce *coal) |
| 8979 | { |
| 8980 | struct bnx2x *bp = netdev_priv(dev); |
| 8981 | |
| 8982 | bp->rx_ticks = (u16) coal->rx_coalesce_usecs; |
| 8983 | if (bp->rx_ticks > 3000) |
| 8984 | bp->rx_ticks = 3000; |
| 8985 | |
| 8986 | bp->tx_ticks = (u16) coal->tx_coalesce_usecs; |
| 8987 | if (bp->tx_ticks > 0x3000) |
| 8988 | bp->tx_ticks = 0x3000; |
| 8989 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8990 | if (netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8991 | bnx2x_update_coalesce(bp); |
| 8992 | |
| 8993 | return 0; |
| 8994 | } |
| 8995 | |
| 8996 | static void bnx2x_get_ringparam(struct net_device *dev, |
| 8997 | struct ethtool_ringparam *ering) |
| 8998 | { |
| 8999 | struct bnx2x *bp = netdev_priv(dev); |
| 9000 | |
| 9001 | ering->rx_max_pending = MAX_RX_AVAIL; |
| 9002 | ering->rx_mini_max_pending = 0; |
| 9003 | ering->rx_jumbo_max_pending = 0; |
| 9004 | |
| 9005 | ering->rx_pending = bp->rx_ring_size; |
| 9006 | ering->rx_mini_pending = 0; |
| 9007 | ering->rx_jumbo_pending = 0; |
| 9008 | |
| 9009 | ering->tx_max_pending = MAX_TX_AVAIL; |
| 9010 | ering->tx_pending = bp->tx_ring_size; |
| 9011 | } |
| 9012 | |
| 9013 | static int bnx2x_set_ringparam(struct net_device *dev, |
| 9014 | struct ethtool_ringparam *ering) |
| 9015 | { |
| 9016 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9017 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9018 | |
| 9019 | if ((ering->rx_pending > MAX_RX_AVAIL) || |
| 9020 | (ering->tx_pending > MAX_TX_AVAIL) || |
| 9021 | (ering->tx_pending <= MAX_SKB_FRAGS + 4)) |
| 9022 | return -EINVAL; |
| 9023 | |
| 9024 | bp->rx_ring_size = ering->rx_pending; |
| 9025 | bp->tx_ring_size = ering->tx_pending; |
| 9026 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9027 | if (netif_running(dev)) { |
| 9028 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9029 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9030 | } |
| 9031 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9032 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9033 | } |
| 9034 | |
| 9035 | static void bnx2x_get_pauseparam(struct net_device *dev, |
| 9036 | struct ethtool_pauseparam *epause) |
| 9037 | { |
| 9038 | struct bnx2x *bp = netdev_priv(dev); |
| 9039 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9040 | epause->autoneg = (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) && |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9041 | (bp->link_params.req_line_speed == SPEED_AUTO_NEG); |
| 9042 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9043 | epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) == |
| 9044 | BNX2X_FLOW_CTRL_RX); |
| 9045 | epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) == |
| 9046 | BNX2X_FLOW_CTRL_TX); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9047 | |
| 9048 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 9049 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 9050 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 9051 | } |
| 9052 | |
| 9053 | static int bnx2x_set_pauseparam(struct net_device *dev, |
| 9054 | struct ethtool_pauseparam *epause) |
| 9055 | { |
| 9056 | struct bnx2x *bp = netdev_priv(dev); |
| 9057 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9058 | if (IS_E1HMF(bp)) |
| 9059 | return 0; |
| 9060 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9061 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 9062 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 9063 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 9064 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9065 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9066 | |
| 9067 | if (epause->rx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9068 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9069 | |
| 9070 | if (epause->tx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9071 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9072 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9073 | if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) |
| 9074 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9075 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9076 | if (epause->autoneg) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9077 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 9078 | DP(NETIF_MSG_LINK, "autoneg not supported\n"); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 9079 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9080 | } |
| 9081 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9082 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9083 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9084 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9085 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9086 | DP(NETIF_MSG_LINK, |
| 9087 | "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9088 | |
| 9089 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9090 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9091 | bnx2x_link_set(bp); |
| 9092 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9093 | |
| 9094 | return 0; |
| 9095 | } |
| 9096 | |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9097 | static int bnx2x_set_flags(struct net_device *dev, u32 data) |
| 9098 | { |
| 9099 | struct bnx2x *bp = netdev_priv(dev); |
| 9100 | int changed = 0; |
| 9101 | int rc = 0; |
| 9102 | |
| 9103 | /* TPA requires Rx CSUM offloading */ |
| 9104 | if ((data & ETH_FLAG_LRO) && bp->rx_csum) { |
| 9105 | if (!(dev->features & NETIF_F_LRO)) { |
| 9106 | dev->features |= NETIF_F_LRO; |
| 9107 | bp->flags |= TPA_ENABLE_FLAG; |
| 9108 | changed = 1; |
| 9109 | } |
| 9110 | |
| 9111 | } else if (dev->features & NETIF_F_LRO) { |
| 9112 | dev->features &= ~NETIF_F_LRO; |
| 9113 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 9114 | changed = 1; |
| 9115 | } |
| 9116 | |
| 9117 | if (changed && netif_running(dev)) { |
| 9118 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9119 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
| 9120 | } |
| 9121 | |
| 9122 | return rc; |
| 9123 | } |
| 9124 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9125 | static u32 bnx2x_get_rx_csum(struct net_device *dev) |
| 9126 | { |
| 9127 | struct bnx2x *bp = netdev_priv(dev); |
| 9128 | |
| 9129 | return bp->rx_csum; |
| 9130 | } |
| 9131 | |
| 9132 | static int bnx2x_set_rx_csum(struct net_device *dev, u32 data) |
| 9133 | { |
| 9134 | struct bnx2x *bp = netdev_priv(dev); |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9135 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9136 | |
| 9137 | bp->rx_csum = data; |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9138 | |
| 9139 | /* Disable TPA, when Rx CSUM is disabled. Otherwise all |
| 9140 | TPA'ed packets will be discarded due to wrong TCP CSUM */ |
| 9141 | if (!data) { |
| 9142 | u32 flags = ethtool_op_get_flags(dev); |
| 9143 | |
| 9144 | rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO)); |
| 9145 | } |
| 9146 | |
| 9147 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9148 | } |
| 9149 | |
| 9150 | static int bnx2x_set_tso(struct net_device *dev, u32 data) |
| 9151 | { |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9152 | if (data) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9153 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9154 | dev->features |= NETIF_F_TSO6; |
| 9155 | } else { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9156 | dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9157 | dev->features &= ~NETIF_F_TSO6; |
| 9158 | } |
| 9159 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9160 | return 0; |
| 9161 | } |
| 9162 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9163 | static const struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9164 | char string[ETH_GSTRING_LEN]; |
| 9165 | } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9166 | { "register_test (offline)" }, |
| 9167 | { "memory_test (offline)" }, |
| 9168 | { "loopback_test (offline)" }, |
| 9169 | { "nvram_test (online)" }, |
| 9170 | { "interrupt_test (online)" }, |
| 9171 | { "link_test (online)" }, |
Eilon Greenstein | d3d4f49 | 2009-02-12 08:36:27 +0000 | [diff] [blame] | 9172 | { "idle check (online)" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9173 | }; |
| 9174 | |
| 9175 | static int bnx2x_self_test_count(struct net_device *dev) |
| 9176 | { |
| 9177 | return BNX2X_NUM_TESTS; |
| 9178 | } |
| 9179 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9180 | static int bnx2x_test_registers(struct bnx2x *bp) |
| 9181 | { |
| 9182 | int idx, i, rc = -ENODEV; |
| 9183 | u32 wr_val = 0; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9184 | int port = BP_PORT(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9185 | static const struct { |
| 9186 | u32 offset0; |
| 9187 | u32 offset1; |
| 9188 | u32 mask; |
| 9189 | } reg_tbl[] = { |
| 9190 | /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff }, |
| 9191 | { DORQ_REG_DB_ADDR0, 4, 0xffffffff }, |
| 9192 | { HC_REG_AGG_INT_0, 4, 0x000003ff }, |
| 9193 | { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 }, |
| 9194 | { PBF_REG_P0_INIT_CRD, 4, 0x000007ff }, |
| 9195 | { PRS_REG_CID_PORT_0, 4, 0x00ffffff }, |
| 9196 | { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff }, |
| 9197 | { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 9198 | { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff }, |
| 9199 | { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 9200 | /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff }, |
| 9201 | { QM_REG_CONNNUM_0, 4, 0x000fffff }, |
| 9202 | { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff }, |
| 9203 | { SRC_REG_KEYRSS0_0, 40, 0xffffffff }, |
| 9204 | { SRC_REG_KEYRSS0_7, 40, 0xffffffff }, |
| 9205 | { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 }, |
| 9206 | { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 }, |
| 9207 | { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff }, |
| 9208 | { NIG_REG_EGRESS_MNG0_FIFO, 20, 0xffffffff }, |
| 9209 | { NIG_REG_LLH0_T_BIT, 4, 0x00000001 }, |
| 9210 | /* 20 */ { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 }, |
| 9211 | { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 }, |
| 9212 | { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 }, |
| 9213 | { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 }, |
| 9214 | { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 }, |
| 9215 | { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff }, |
| 9216 | { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff }, |
| 9217 | { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff }, |
| 9218 | { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff }, |
| 9219 | { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 }, |
| 9220 | /* 30 */ { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff }, |
| 9221 | { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff }, |
| 9222 | { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff }, |
| 9223 | { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 }, |
| 9224 | { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 }, |
| 9225 | { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff }, |
| 9226 | { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 }, |
| 9227 | { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f }, |
| 9228 | |
| 9229 | { 0xffffffff, 0, 0x00000000 } |
| 9230 | }; |
| 9231 | |
| 9232 | if (!netif_running(bp->dev)) |
| 9233 | return rc; |
| 9234 | |
| 9235 | /* Repeat the test twice: |
| 9236 | First by writing 0x00000000, second by writing 0xffffffff */ |
| 9237 | for (idx = 0; idx < 2; idx++) { |
| 9238 | |
| 9239 | switch (idx) { |
| 9240 | case 0: |
| 9241 | wr_val = 0; |
| 9242 | break; |
| 9243 | case 1: |
| 9244 | wr_val = 0xffffffff; |
| 9245 | break; |
| 9246 | } |
| 9247 | |
| 9248 | for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) { |
| 9249 | u32 offset, mask, save_val, val; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9250 | |
| 9251 | offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1; |
| 9252 | mask = reg_tbl[i].mask; |
| 9253 | |
| 9254 | save_val = REG_RD(bp, offset); |
| 9255 | |
| 9256 | REG_WR(bp, offset, wr_val); |
| 9257 | val = REG_RD(bp, offset); |
| 9258 | |
| 9259 | /* Restore the original register's value */ |
| 9260 | REG_WR(bp, offset, save_val); |
| 9261 | |
| 9262 | /* verify that value is as expected value */ |
| 9263 | if ((val & mask) != (wr_val & mask)) |
| 9264 | goto test_reg_exit; |
| 9265 | } |
| 9266 | } |
| 9267 | |
| 9268 | rc = 0; |
| 9269 | |
| 9270 | test_reg_exit: |
| 9271 | return rc; |
| 9272 | } |
| 9273 | |
| 9274 | static int bnx2x_test_memory(struct bnx2x *bp) |
| 9275 | { |
| 9276 | int i, j, rc = -ENODEV; |
| 9277 | u32 val; |
| 9278 | static const struct { |
| 9279 | u32 offset; |
| 9280 | int size; |
| 9281 | } mem_tbl[] = { |
| 9282 | { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9283 | { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE }, |
| 9284 | { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE }, |
| 9285 | { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE }, |
| 9286 | { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9287 | { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9288 | { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9289 | |
| 9290 | { 0xffffffff, 0 } |
| 9291 | }; |
| 9292 | static const struct { |
| 9293 | char *name; |
| 9294 | u32 offset; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9295 | u32 e1_mask; |
| 9296 | u32 e1h_mask; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9297 | } prty_tbl[] = { |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9298 | { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9299 | { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 }, |
| 9300 | { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 }, |
| 9301 | { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9302 | { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9303 | { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9304 | |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9305 | { NULL, 0xffffffff, 0, 0 } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9306 | }; |
| 9307 | |
| 9308 | if (!netif_running(bp->dev)) |
| 9309 | return rc; |
| 9310 | |
| 9311 | /* Go through all the memories */ |
| 9312 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) |
| 9313 | for (j = 0; j < mem_tbl[i].size; j++) |
| 9314 | REG_RD(bp, mem_tbl[i].offset + j*4); |
| 9315 | |
| 9316 | /* Check the parity status */ |
| 9317 | for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) { |
| 9318 | val = REG_RD(bp, prty_tbl[i].offset); |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9319 | if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) || |
| 9320 | (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9321 | DP(NETIF_MSG_HW, |
| 9322 | "%s is 0x%x\n", prty_tbl[i].name, val); |
| 9323 | goto test_mem_exit; |
| 9324 | } |
| 9325 | } |
| 9326 | |
| 9327 | rc = 0; |
| 9328 | |
| 9329 | test_mem_exit: |
| 9330 | return rc; |
| 9331 | } |
| 9332 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9333 | static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up) |
| 9334 | { |
| 9335 | int cnt = 1000; |
| 9336 | |
| 9337 | if (link_up) |
| 9338 | while (bnx2x_link_test(bp) && cnt--) |
| 9339 | msleep(10); |
| 9340 | } |
| 9341 | |
| 9342 | static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up) |
| 9343 | { |
| 9344 | unsigned int pkt_size, num_pkts, i; |
| 9345 | struct sk_buff *skb; |
| 9346 | unsigned char *packet; |
| 9347 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 9348 | u16 tx_start_idx, tx_idx; |
| 9349 | u16 rx_start_idx, rx_idx; |
| 9350 | u16 pkt_prod; |
| 9351 | struct sw_tx_bd *tx_buf; |
| 9352 | struct eth_tx_bd *tx_bd; |
| 9353 | dma_addr_t mapping; |
| 9354 | union eth_rx_cqe *cqe; |
| 9355 | u8 cqe_fp_flags; |
| 9356 | struct sw_rx_bd *rx_buf; |
| 9357 | u16 len; |
| 9358 | int rc = -ENODEV; |
| 9359 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9360 | /* check the loopback mode */ |
| 9361 | switch (loopback_mode) { |
| 9362 | case BNX2X_PHY_LOOPBACK: |
| 9363 | if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10) |
| 9364 | return -EINVAL; |
| 9365 | break; |
| 9366 | case BNX2X_MAC_LOOPBACK: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9367 | bp->link_params.loopback_mode = LOOPBACK_BMAC; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9368 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9369 | break; |
| 9370 | default: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9371 | return -EINVAL; |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9372 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9373 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9374 | /* prepare the loopback packet */ |
| 9375 | pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ? |
| 9376 | bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9377 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 9378 | if (!skb) { |
| 9379 | rc = -ENOMEM; |
| 9380 | goto test_loopback_exit; |
| 9381 | } |
| 9382 | packet = skb_put(skb, pkt_size); |
| 9383 | memcpy(packet, bp->dev->dev_addr, ETH_ALEN); |
| 9384 | memset(packet + ETH_ALEN, 0, (ETH_HLEN - ETH_ALEN)); |
| 9385 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 9386 | packet[i] = (unsigned char) (i & 0xff); |
| 9387 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9388 | /* send the loopback packet */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9389 | num_pkts = 0; |
| 9390 | tx_start_idx = le16_to_cpu(*fp->tx_cons_sb); |
| 9391 | rx_start_idx = le16_to_cpu(*fp->rx_cons_sb); |
| 9392 | |
| 9393 | pkt_prod = fp->tx_pkt_prod++; |
| 9394 | tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)]; |
| 9395 | tx_buf->first_bd = fp->tx_bd_prod; |
| 9396 | tx_buf->skb = skb; |
| 9397 | |
| 9398 | tx_bd = &fp->tx_desc_ring[TX_BD(fp->tx_bd_prod)]; |
| 9399 | mapping = pci_map_single(bp->pdev, skb->data, |
| 9400 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 9401 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 9402 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 9403 | tx_bd->nbd = cpu_to_le16(1); |
| 9404 | tx_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 9405 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
| 9406 | tx_bd->bd_flags.as_bitfield = (ETH_TX_BD_FLAGS_START_BD | |
| 9407 | ETH_TX_BD_FLAGS_END_BD); |
| 9408 | tx_bd->general_data = ((UNICAST_ADDRESS << |
| 9409 | ETH_TX_BD_ETH_ADDR_TYPE_SHIFT) | 1); |
| 9410 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 9411 | wmb(); |
| 9412 | |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9413 | le16_add_cpu(&fp->hw_tx_prods->bds_prod, 1); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9414 | mb(); /* FW restriction: must not reorder writing nbd and packets */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9415 | le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 9416 | DOORBELL(bp, fp->index, 0); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9417 | |
| 9418 | mmiowb(); |
| 9419 | |
| 9420 | num_pkts++; |
| 9421 | fp->tx_bd_prod++; |
| 9422 | bp->dev->trans_start = jiffies; |
| 9423 | |
| 9424 | udelay(100); |
| 9425 | |
| 9426 | tx_idx = le16_to_cpu(*fp->tx_cons_sb); |
| 9427 | if (tx_idx != tx_start_idx + num_pkts) |
| 9428 | goto test_loopback_exit; |
| 9429 | |
| 9430 | rx_idx = le16_to_cpu(*fp->rx_cons_sb); |
| 9431 | if (rx_idx != rx_start_idx + num_pkts) |
| 9432 | goto test_loopback_exit; |
| 9433 | |
| 9434 | cqe = &fp->rx_comp_ring[RCQ_BD(fp->rx_comp_cons)]; |
| 9435 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
| 9436 | if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS)) |
| 9437 | goto test_loopback_rx_exit; |
| 9438 | |
| 9439 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 9440 | if (len != pkt_size) |
| 9441 | goto test_loopback_rx_exit; |
| 9442 | |
| 9443 | rx_buf = &fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)]; |
| 9444 | skb = rx_buf->skb; |
| 9445 | skb_reserve(skb, cqe->fast_path_cqe.placement_offset); |
| 9446 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 9447 | if (*(skb->data + i) != (unsigned char) (i & 0xff)) |
| 9448 | goto test_loopback_rx_exit; |
| 9449 | |
| 9450 | rc = 0; |
| 9451 | |
| 9452 | test_loopback_rx_exit: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9453 | |
| 9454 | fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons); |
| 9455 | fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod); |
| 9456 | fp->rx_comp_cons = NEXT_RCQ_IDX(fp->rx_comp_cons); |
| 9457 | fp->rx_comp_prod = NEXT_RCQ_IDX(fp->rx_comp_prod); |
| 9458 | |
| 9459 | /* Update producers */ |
| 9460 | bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod, |
| 9461 | fp->rx_sge_prod); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9462 | |
| 9463 | test_loopback_exit: |
| 9464 | bp->link_params.loopback_mode = LOOPBACK_NONE; |
| 9465 | |
| 9466 | return rc; |
| 9467 | } |
| 9468 | |
| 9469 | static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up) |
| 9470 | { |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9471 | int rc = 0, res; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9472 | |
| 9473 | if (!netif_running(bp->dev)) |
| 9474 | return BNX2X_LOOPBACK_FAILED; |
| 9475 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 9476 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9477 | bnx2x_acquire_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9478 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9479 | res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up); |
| 9480 | if (res) { |
| 9481 | DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res); |
| 9482 | rc |= BNX2X_PHY_LOOPBACK_FAILED; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9483 | } |
| 9484 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 9485 | res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up); |
| 9486 | if (res) { |
| 9487 | DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res); |
| 9488 | rc |= BNX2X_MAC_LOOPBACK_FAILED; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9489 | } |
| 9490 | |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9491 | bnx2x_release_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9492 | bnx2x_netif_start(bp); |
| 9493 | |
| 9494 | return rc; |
| 9495 | } |
| 9496 | |
| 9497 | #define CRC32_RESIDUAL 0xdebb20e3 |
| 9498 | |
| 9499 | static int bnx2x_test_nvram(struct bnx2x *bp) |
| 9500 | { |
| 9501 | static const struct { |
| 9502 | int offset; |
| 9503 | int size; |
| 9504 | } nvram_tbl[] = { |
| 9505 | { 0, 0x14 }, /* bootstrap */ |
| 9506 | { 0x14, 0xec }, /* dir */ |
| 9507 | { 0x100, 0x350 }, /* manuf_info */ |
| 9508 | { 0x450, 0xf0 }, /* feature_info */ |
| 9509 | { 0x640, 0x64 }, /* upgrade_key_info */ |
| 9510 | { 0x6a4, 0x64 }, |
| 9511 | { 0x708, 0x70 }, /* manuf_key_info */ |
| 9512 | { 0x778, 0x70 }, |
| 9513 | { 0, 0 } |
| 9514 | }; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9515 | __be32 buf[0x350 / 4]; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9516 | u8 *data = (u8 *)buf; |
| 9517 | int i, rc; |
| 9518 | u32 magic, csum; |
| 9519 | |
| 9520 | rc = bnx2x_nvram_read(bp, 0, data, 4); |
| 9521 | if (rc) { |
| 9522 | DP(NETIF_MSG_PROBE, "magic value read (rc -%d)\n", -rc); |
| 9523 | goto test_nvram_exit; |
| 9524 | } |
| 9525 | |
| 9526 | magic = be32_to_cpu(buf[0]); |
| 9527 | if (magic != 0x669955aa) { |
| 9528 | DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic); |
| 9529 | rc = -ENODEV; |
| 9530 | goto test_nvram_exit; |
| 9531 | } |
| 9532 | |
| 9533 | for (i = 0; nvram_tbl[i].size; i++) { |
| 9534 | |
| 9535 | rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data, |
| 9536 | nvram_tbl[i].size); |
| 9537 | if (rc) { |
| 9538 | DP(NETIF_MSG_PROBE, |
| 9539 | "nvram_tbl[%d] read data (rc -%d)\n", i, -rc); |
| 9540 | goto test_nvram_exit; |
| 9541 | } |
| 9542 | |
| 9543 | csum = ether_crc_le(nvram_tbl[i].size, data); |
| 9544 | if (csum != CRC32_RESIDUAL) { |
| 9545 | DP(NETIF_MSG_PROBE, |
| 9546 | "nvram_tbl[%d] csum value (0x%08x)\n", i, csum); |
| 9547 | rc = -ENODEV; |
| 9548 | goto test_nvram_exit; |
| 9549 | } |
| 9550 | } |
| 9551 | |
| 9552 | test_nvram_exit: |
| 9553 | return rc; |
| 9554 | } |
| 9555 | |
| 9556 | static int bnx2x_test_intr(struct bnx2x *bp) |
| 9557 | { |
| 9558 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
| 9559 | int i, rc; |
| 9560 | |
| 9561 | if (!netif_running(bp->dev)) |
| 9562 | return -ENODEV; |
| 9563 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 9564 | config->hdr.length = 0; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 9565 | if (CHIP_IS_E1(bp)) |
| 9566 | config->hdr.offset = (BP_PORT(bp) ? 32 : 0); |
| 9567 | else |
| 9568 | config->hdr.offset = BP_FUNC(bp); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 9569 | config->hdr.client_id = bp->fp->cl_id; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9570 | config->hdr.reserved1 = 0; |
| 9571 | |
| 9572 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 9573 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 9574 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 9575 | if (rc == 0) { |
| 9576 | bp->set_mac_pending++; |
| 9577 | for (i = 0; i < 10; i++) { |
| 9578 | if (!bp->set_mac_pending) |
| 9579 | break; |
| 9580 | msleep_interruptible(10); |
| 9581 | } |
| 9582 | if (i == 10) |
| 9583 | rc = -ENODEV; |
| 9584 | } |
| 9585 | |
| 9586 | return rc; |
| 9587 | } |
| 9588 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9589 | static void bnx2x_self_test(struct net_device *dev, |
| 9590 | struct ethtool_test *etest, u64 *buf) |
| 9591 | { |
| 9592 | struct bnx2x *bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9593 | |
| 9594 | memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS); |
| 9595 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9596 | if (!netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9597 | return; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9598 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 9599 | /* offline tests are not supported in MF mode */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9600 | if (IS_E1HMF(bp)) |
| 9601 | etest->flags &= ~ETH_TEST_FL_OFFLINE; |
| 9602 | |
| 9603 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
| 9604 | u8 link_up; |
| 9605 | |
| 9606 | link_up = bp->link_vars.link_up; |
| 9607 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9608 | bnx2x_nic_load(bp, LOAD_DIAG); |
| 9609 | /* wait until link state is restored */ |
| 9610 | bnx2x_wait_for_link(bp, link_up); |
| 9611 | |
| 9612 | if (bnx2x_test_registers(bp) != 0) { |
| 9613 | buf[0] = 1; |
| 9614 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9615 | } |
| 9616 | if (bnx2x_test_memory(bp) != 0) { |
| 9617 | buf[1] = 1; |
| 9618 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9619 | } |
| 9620 | buf[2] = bnx2x_test_loopback(bp, link_up); |
| 9621 | if (buf[2] != 0) |
| 9622 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9623 | |
| 9624 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9625 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 9626 | /* wait until link state is restored */ |
| 9627 | bnx2x_wait_for_link(bp, link_up); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9628 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9629 | if (bnx2x_test_nvram(bp) != 0) { |
| 9630 | buf[3] = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9631 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9632 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9633 | if (bnx2x_test_intr(bp) != 0) { |
| 9634 | buf[4] = 1; |
| 9635 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9636 | } |
| 9637 | if (bp->port.pmf) |
| 9638 | if (bnx2x_link_test(bp) != 0) { |
| 9639 | buf[5] = 1; |
| 9640 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9641 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9642 | |
| 9643 | #ifdef BNX2X_EXTRA_DEBUG |
| 9644 | bnx2x_panic_dump(bp); |
| 9645 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9646 | } |
| 9647 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9648 | static const struct { |
| 9649 | long offset; |
| 9650 | int size; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9651 | u8 string[ETH_GSTRING_LEN]; |
| 9652 | } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = { |
| 9653 | /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" }, |
| 9654 | { Q_STATS_OFFSET32(error_bytes_received_hi), |
| 9655 | 8, "[%d]: rx_error_bytes" }, |
| 9656 | { Q_STATS_OFFSET32(total_unicast_packets_received_hi), |
| 9657 | 8, "[%d]: rx_ucast_packets" }, |
| 9658 | { Q_STATS_OFFSET32(total_multicast_packets_received_hi), |
| 9659 | 8, "[%d]: rx_mcast_packets" }, |
| 9660 | { Q_STATS_OFFSET32(total_broadcast_packets_received_hi), |
| 9661 | 8, "[%d]: rx_bcast_packets" }, |
| 9662 | { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" }, |
| 9663 | { Q_STATS_OFFSET32(rx_err_discard_pkt), |
| 9664 | 4, "[%d]: rx_phy_ip_err_discards"}, |
| 9665 | { Q_STATS_OFFSET32(rx_skb_alloc_failed), |
| 9666 | 4, "[%d]: rx_skb_alloc_discard" }, |
| 9667 | { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" }, |
| 9668 | |
| 9669 | /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" }, |
| 9670 | { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 9671 | 8, "[%d]: tx_packets" } |
| 9672 | }; |
| 9673 | |
| 9674 | static const struct { |
| 9675 | long offset; |
| 9676 | int size; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9677 | u32 flags; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9678 | #define STATS_FLAGS_PORT 1 |
| 9679 | #define STATS_FLAGS_FUNC 2 |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9680 | #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9681 | u8 string[ETH_GSTRING_LEN]; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9682 | } bnx2x_stats_arr[BNX2X_NUM_STATS] = { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9683 | /* 1 */ { STATS_OFFSET32(total_bytes_received_hi), |
| 9684 | 8, STATS_FLAGS_BOTH, "rx_bytes" }, |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9685 | { STATS_OFFSET32(error_bytes_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9686 | 8, STATS_FLAGS_BOTH, "rx_error_bytes" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9687 | { STATS_OFFSET32(total_unicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9688 | 8, STATS_FLAGS_BOTH, "rx_ucast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9689 | { STATS_OFFSET32(total_multicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9690 | 8, STATS_FLAGS_BOTH, "rx_mcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9691 | { STATS_OFFSET32(total_broadcast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9692 | 8, STATS_FLAGS_BOTH, "rx_bcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9693 | { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9694 | 8, STATS_FLAGS_PORT, "rx_crc_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9695 | { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9696 | 8, STATS_FLAGS_PORT, "rx_align_errors" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9697 | { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi), |
| 9698 | 8, STATS_FLAGS_PORT, "rx_undersize_packets" }, |
| 9699 | { STATS_OFFSET32(etherstatsoverrsizepkts_hi), |
| 9700 | 8, STATS_FLAGS_PORT, "rx_oversize_packets" }, |
| 9701 | /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi), |
| 9702 | 8, STATS_FLAGS_PORT, "rx_fragments" }, |
| 9703 | { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi), |
| 9704 | 8, STATS_FLAGS_PORT, "rx_jabbers" }, |
| 9705 | { STATS_OFFSET32(no_buff_discard_hi), |
| 9706 | 8, STATS_FLAGS_BOTH, "rx_discards" }, |
| 9707 | { STATS_OFFSET32(mac_filter_discard), |
| 9708 | 4, STATS_FLAGS_PORT, "rx_filtered_packets" }, |
| 9709 | { STATS_OFFSET32(xxoverflow_discard), |
| 9710 | 4, STATS_FLAGS_PORT, "rx_fw_discards" }, |
| 9711 | { STATS_OFFSET32(brb_drop_hi), |
| 9712 | 8, STATS_FLAGS_PORT, "rx_brb_discard" }, |
| 9713 | { STATS_OFFSET32(brb_truncate_hi), |
| 9714 | 8, STATS_FLAGS_PORT, "rx_brb_truncate" }, |
| 9715 | { STATS_OFFSET32(pause_frames_received_hi), |
| 9716 | 8, STATS_FLAGS_PORT, "rx_pause_frames" }, |
| 9717 | { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi), |
| 9718 | 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" }, |
| 9719 | { STATS_OFFSET32(nig_timer_max), |
| 9720 | 4, STATS_FLAGS_PORT, "rx_constant_pause_events" }, |
| 9721 | /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt), |
| 9722 | 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"}, |
| 9723 | { STATS_OFFSET32(rx_skb_alloc_failed), |
| 9724 | 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" }, |
| 9725 | { STATS_OFFSET32(hw_csum_err), |
| 9726 | 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" }, |
| 9727 | |
| 9728 | { STATS_OFFSET32(total_bytes_transmitted_hi), |
| 9729 | 8, STATS_FLAGS_BOTH, "tx_bytes" }, |
| 9730 | { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi), |
| 9731 | 8, STATS_FLAGS_PORT, "tx_error_bytes" }, |
| 9732 | { STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 9733 | 8, STATS_FLAGS_BOTH, "tx_packets" }, |
| 9734 | { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi), |
| 9735 | 8, STATS_FLAGS_PORT, "tx_mac_errors" }, |
| 9736 | { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi), |
| 9737 | 8, STATS_FLAGS_PORT, "tx_carrier_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9738 | { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9739 | 8, STATS_FLAGS_PORT, "tx_single_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9740 | { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9741 | 8, STATS_FLAGS_PORT, "tx_multi_collisions" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9742 | /* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9743 | 8, STATS_FLAGS_PORT, "tx_deferred" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9744 | { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9745 | 8, STATS_FLAGS_PORT, "tx_excess_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9746 | { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9747 | 8, STATS_FLAGS_PORT, "tx_late_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9748 | { STATS_OFFSET32(tx_stat_etherstatscollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9749 | 8, STATS_FLAGS_PORT, "tx_total_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9750 | { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9751 | 8, STATS_FLAGS_PORT, "tx_64_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9752 | { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9753 | 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9754 | { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9755 | 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9756 | { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9757 | 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9758 | { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9759 | 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9760 | { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9761 | 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9762 | /* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9763 | 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9764 | { STATS_OFFSET32(pause_frames_sent_hi), |
| 9765 | 8, STATS_FLAGS_PORT, "tx_pause_frames" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9766 | }; |
| 9767 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9768 | #define IS_PORT_STAT(i) \ |
| 9769 | ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT) |
| 9770 | #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC) |
| 9771 | #define IS_E1HMF_MODE_STAT(bp) \ |
| 9772 | (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS)) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9773 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9774 | static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
| 9775 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9776 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9777 | int i, j, k; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9778 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9779 | switch (stringset) { |
| 9780 | case ETH_SS_STATS: |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9781 | if (is_multi(bp)) { |
| 9782 | k = 0; |
| 9783 | for_each_queue(bp, i) { |
| 9784 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) |
| 9785 | sprintf(buf + (k + j)*ETH_GSTRING_LEN, |
| 9786 | bnx2x_q_stats_arr[j].string, i); |
| 9787 | k += BNX2X_NUM_Q_STATS; |
| 9788 | } |
| 9789 | if (IS_E1HMF_MODE_STAT(bp)) |
| 9790 | break; |
| 9791 | for (j = 0; j < BNX2X_NUM_STATS; j++) |
| 9792 | strcpy(buf + (k + j)*ETH_GSTRING_LEN, |
| 9793 | bnx2x_stats_arr[j].string); |
| 9794 | } else { |
| 9795 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 9796 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 9797 | continue; |
| 9798 | strcpy(buf + j*ETH_GSTRING_LEN, |
| 9799 | bnx2x_stats_arr[i].string); |
| 9800 | j++; |
| 9801 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9802 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9803 | break; |
| 9804 | |
| 9805 | case ETH_SS_TEST: |
| 9806 | memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr)); |
| 9807 | break; |
| 9808 | } |
| 9809 | } |
| 9810 | |
| 9811 | static int bnx2x_get_stats_count(struct net_device *dev) |
| 9812 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9813 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9814 | int i, num_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9815 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9816 | if (is_multi(bp)) { |
| 9817 | num_stats = BNX2X_NUM_Q_STATS * BNX2X_NUM_QUEUES(bp); |
| 9818 | if (!IS_E1HMF_MODE_STAT(bp)) |
| 9819 | num_stats += BNX2X_NUM_STATS; |
| 9820 | } else { |
| 9821 | if (IS_E1HMF_MODE_STAT(bp)) { |
| 9822 | num_stats = 0; |
| 9823 | for (i = 0; i < BNX2X_NUM_STATS; i++) |
| 9824 | if (IS_FUNC_STAT(i)) |
| 9825 | num_stats++; |
| 9826 | } else |
| 9827 | num_stats = BNX2X_NUM_STATS; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9828 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9829 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9830 | return num_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9831 | } |
| 9832 | |
| 9833 | static void bnx2x_get_ethtool_stats(struct net_device *dev, |
| 9834 | struct ethtool_stats *stats, u64 *buf) |
| 9835 | { |
| 9836 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9837 | u32 *hw_stats, *offset; |
| 9838 | int i, j, k; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9839 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9840 | if (is_multi(bp)) { |
| 9841 | k = 0; |
| 9842 | for_each_queue(bp, i) { |
| 9843 | hw_stats = (u32 *)&bp->fp[i].eth_q_stats; |
| 9844 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) { |
| 9845 | if (bnx2x_q_stats_arr[j].size == 0) { |
| 9846 | /* skip this counter */ |
| 9847 | buf[k + j] = 0; |
| 9848 | continue; |
| 9849 | } |
| 9850 | offset = (hw_stats + |
| 9851 | bnx2x_q_stats_arr[j].offset); |
| 9852 | if (bnx2x_q_stats_arr[j].size == 4) { |
| 9853 | /* 4-byte counter */ |
| 9854 | buf[k + j] = (u64) *offset; |
| 9855 | continue; |
| 9856 | } |
| 9857 | /* 8-byte counter */ |
| 9858 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
| 9859 | } |
| 9860 | k += BNX2X_NUM_Q_STATS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9861 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9862 | if (IS_E1HMF_MODE_STAT(bp)) |
| 9863 | return; |
| 9864 | hw_stats = (u32 *)&bp->eth_stats; |
| 9865 | for (j = 0; j < BNX2X_NUM_STATS; j++) { |
| 9866 | if (bnx2x_stats_arr[j].size == 0) { |
| 9867 | /* skip this counter */ |
| 9868 | buf[k + j] = 0; |
| 9869 | continue; |
| 9870 | } |
| 9871 | offset = (hw_stats + bnx2x_stats_arr[j].offset); |
| 9872 | if (bnx2x_stats_arr[j].size == 4) { |
| 9873 | /* 4-byte counter */ |
| 9874 | buf[k + j] = (u64) *offset; |
| 9875 | continue; |
| 9876 | } |
| 9877 | /* 8-byte counter */ |
| 9878 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9879 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9880 | } else { |
| 9881 | hw_stats = (u32 *)&bp->eth_stats; |
| 9882 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 9883 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 9884 | continue; |
| 9885 | if (bnx2x_stats_arr[i].size == 0) { |
| 9886 | /* skip this counter */ |
| 9887 | buf[j] = 0; |
| 9888 | j++; |
| 9889 | continue; |
| 9890 | } |
| 9891 | offset = (hw_stats + bnx2x_stats_arr[i].offset); |
| 9892 | if (bnx2x_stats_arr[i].size == 4) { |
| 9893 | /* 4-byte counter */ |
| 9894 | buf[j] = (u64) *offset; |
| 9895 | j++; |
| 9896 | continue; |
| 9897 | } |
| 9898 | /* 8-byte counter */ |
| 9899 | buf[j] = HILO_U64(*offset, *(offset + 1)); |
| 9900 | j++; |
| 9901 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9902 | } |
| 9903 | } |
| 9904 | |
| 9905 | static int bnx2x_phys_id(struct net_device *dev, u32 data) |
| 9906 | { |
| 9907 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9908 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9909 | int i; |
| 9910 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9911 | if (!netif_running(dev)) |
| 9912 | return 0; |
| 9913 | |
| 9914 | if (!bp->port.pmf) |
| 9915 | return 0; |
| 9916 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9917 | if (data == 0) |
| 9918 | data = 2; |
| 9919 | |
| 9920 | for (i = 0; i < (data * 2); i++) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9921 | if ((i % 2) == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9922 | bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9923 | bp->link_params.hw_led_mode, |
| 9924 | bp->link_params.chip_id); |
| 9925 | else |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9926 | bnx2x_set_led(bp, port, LED_MODE_OFF, 0, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9927 | bp->link_params.hw_led_mode, |
| 9928 | bp->link_params.chip_id); |
| 9929 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9930 | msleep_interruptible(500); |
| 9931 | if (signal_pending(current)) |
| 9932 | break; |
| 9933 | } |
| 9934 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9935 | if (bp->link_vars.link_up) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9936 | bnx2x_set_led(bp, port, LED_MODE_OPER, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9937 | bp->link_vars.line_speed, |
| 9938 | bp->link_params.hw_led_mode, |
| 9939 | bp->link_params.chip_id); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9940 | |
| 9941 | return 0; |
| 9942 | } |
| 9943 | |
| 9944 | static struct ethtool_ops bnx2x_ethtool_ops = { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9945 | .get_settings = bnx2x_get_settings, |
| 9946 | .set_settings = bnx2x_set_settings, |
| 9947 | .get_drvinfo = bnx2x_get_drvinfo, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9948 | .get_wol = bnx2x_get_wol, |
| 9949 | .set_wol = bnx2x_set_wol, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9950 | .get_msglevel = bnx2x_get_msglevel, |
| 9951 | .set_msglevel = bnx2x_set_msglevel, |
| 9952 | .nway_reset = bnx2x_nway_reset, |
| 9953 | .get_link = ethtool_op_get_link, |
| 9954 | .get_eeprom_len = bnx2x_get_eeprom_len, |
| 9955 | .get_eeprom = bnx2x_get_eeprom, |
| 9956 | .set_eeprom = bnx2x_set_eeprom, |
| 9957 | .get_coalesce = bnx2x_get_coalesce, |
| 9958 | .set_coalesce = bnx2x_set_coalesce, |
| 9959 | .get_ringparam = bnx2x_get_ringparam, |
| 9960 | .set_ringparam = bnx2x_set_ringparam, |
| 9961 | .get_pauseparam = bnx2x_get_pauseparam, |
| 9962 | .set_pauseparam = bnx2x_set_pauseparam, |
| 9963 | .get_rx_csum = bnx2x_get_rx_csum, |
| 9964 | .set_rx_csum = bnx2x_set_rx_csum, |
| 9965 | .get_tx_csum = ethtool_op_get_tx_csum, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9966 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9967 | .set_flags = bnx2x_set_flags, |
| 9968 | .get_flags = ethtool_op_get_flags, |
| 9969 | .get_sg = ethtool_op_get_sg, |
| 9970 | .set_sg = ethtool_op_set_sg, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9971 | .get_tso = ethtool_op_get_tso, |
| 9972 | .set_tso = bnx2x_set_tso, |
| 9973 | .self_test_count = bnx2x_self_test_count, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9974 | .self_test = bnx2x_self_test, |
| 9975 | .get_strings = bnx2x_get_strings, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9976 | .phys_id = bnx2x_phys_id, |
| 9977 | .get_stats_count = bnx2x_get_stats_count, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9978 | .get_ethtool_stats = bnx2x_get_ethtool_stats, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9979 | }; |
| 9980 | |
| 9981 | /* end of ethtool_ops */ |
| 9982 | |
| 9983 | /**************************************************************************** |
| 9984 | * General service functions |
| 9985 | ****************************************************************************/ |
| 9986 | |
| 9987 | static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state) |
| 9988 | { |
| 9989 | u16 pmcsr; |
| 9990 | |
| 9991 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 9992 | |
| 9993 | switch (state) { |
| 9994 | case PCI_D0: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9995 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9996 | ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) | |
| 9997 | PCI_PM_CTRL_PME_STATUS)); |
| 9998 | |
| 9999 | if (pmcsr & PCI_PM_CTRL_STATE_MASK) |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10000 | /* delay required during transition out of D3hot */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10001 | msleep(20); |
| 10002 | break; |
| 10003 | |
| 10004 | case PCI_D3hot: |
| 10005 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 10006 | pmcsr |= 3; |
| 10007 | |
| 10008 | if (bp->wol) |
| 10009 | pmcsr |= PCI_PM_CTRL_PME_ENABLE; |
| 10010 | |
| 10011 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
| 10012 | pmcsr); |
| 10013 | |
| 10014 | /* No more memory access after this point until |
| 10015 | * device is brought back to D0. |
| 10016 | */ |
| 10017 | break; |
| 10018 | |
| 10019 | default: |
| 10020 | return -EINVAL; |
| 10021 | } |
| 10022 | return 0; |
| 10023 | } |
| 10024 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 10025 | static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp) |
| 10026 | { |
| 10027 | u16 rx_cons_sb; |
| 10028 | |
| 10029 | /* Tell compiler that status block fields can change */ |
| 10030 | barrier(); |
| 10031 | rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb); |
| 10032 | if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 10033 | rx_cons_sb++; |
| 10034 | return (fp->rx_comp_cons != rx_cons_sb); |
| 10035 | } |
| 10036 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10037 | /* |
| 10038 | * net_device service functions |
| 10039 | */ |
| 10040 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10041 | static int bnx2x_poll(struct napi_struct *napi, int budget) |
| 10042 | { |
| 10043 | struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath, |
| 10044 | napi); |
| 10045 | struct bnx2x *bp = fp->bp; |
| 10046 | int work_done = 0; |
| 10047 | |
| 10048 | #ifdef BNX2X_STOP_ON_ERROR |
| 10049 | if (unlikely(bp->panic)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10050 | goto poll_panic; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10051 | #endif |
| 10052 | |
| 10053 | prefetch(fp->tx_buf_ring[TX_BD(fp->tx_pkt_cons)].skb); |
| 10054 | prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb); |
| 10055 | prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256); |
| 10056 | |
| 10057 | bnx2x_update_fpsb_idx(fp); |
| 10058 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 10059 | if (bnx2x_has_tx_work(fp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10060 | bnx2x_tx_int(fp, budget); |
| 10061 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 10062 | if (bnx2x_has_rx_work(fp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10063 | work_done = bnx2x_rx_int(fp, budget); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10064 | rmb(); /* BNX2X_HAS_WORK() reads the status block */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10065 | |
| 10066 | /* must not complete if we consumed full budget */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10067 | if ((work_done < budget) && !BNX2X_HAS_WORK(fp)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10068 | |
| 10069 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10070 | poll_panic: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10071 | #endif |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 10072 | napi_complete(napi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10073 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10074 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10075 | le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10076 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10077 | le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1); |
| 10078 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10079 | return work_done; |
| 10080 | } |
| 10081 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10082 | |
| 10083 | /* we split the first BD into headers and data BDs |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10084 | * to ease the pain of our fellow microcode engineers |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10085 | * we use one mapping for both BDs |
| 10086 | * So far this has only been observed to happen |
| 10087 | * in Other Operating Systems(TM) |
| 10088 | */ |
| 10089 | static noinline u16 bnx2x_tx_split(struct bnx2x *bp, |
| 10090 | struct bnx2x_fastpath *fp, |
| 10091 | struct eth_tx_bd **tx_bd, u16 hlen, |
| 10092 | u16 bd_prod, int nbd) |
| 10093 | { |
| 10094 | struct eth_tx_bd *h_tx_bd = *tx_bd; |
| 10095 | struct eth_tx_bd *d_tx_bd; |
| 10096 | dma_addr_t mapping; |
| 10097 | int old_len = le16_to_cpu(h_tx_bd->nbytes); |
| 10098 | |
| 10099 | /* first fix first BD */ |
| 10100 | h_tx_bd->nbd = cpu_to_le16(nbd); |
| 10101 | h_tx_bd->nbytes = cpu_to_le16(hlen); |
| 10102 | |
| 10103 | DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d " |
| 10104 | "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi, |
| 10105 | h_tx_bd->addr_lo, h_tx_bd->nbd); |
| 10106 | |
| 10107 | /* now get a new data BD |
| 10108 | * (after the pbd) and fill it */ |
| 10109 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10110 | d_tx_bd = &fp->tx_desc_ring[bd_prod]; |
| 10111 | |
| 10112 | mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi), |
| 10113 | le32_to_cpu(h_tx_bd->addr_lo)) + hlen; |
| 10114 | |
| 10115 | d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10116 | d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 10117 | d_tx_bd->nbytes = cpu_to_le16(old_len - hlen); |
| 10118 | d_tx_bd->vlan = 0; |
| 10119 | /* this marks the BD as one that has no individual mapping |
| 10120 | * the FW ignores this flag in a BD not marked start |
| 10121 | */ |
| 10122 | d_tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_SW_LSO; |
| 10123 | DP(NETIF_MSG_TX_QUEUED, |
| 10124 | "TSO split data size is %d (%x:%x)\n", |
| 10125 | d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo); |
| 10126 | |
| 10127 | /* update tx_bd for marking the last BD flag */ |
| 10128 | *tx_bd = d_tx_bd; |
| 10129 | |
| 10130 | return bd_prod; |
| 10131 | } |
| 10132 | |
| 10133 | static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix) |
| 10134 | { |
| 10135 | if (fix > 0) |
| 10136 | csum = (u16) ~csum_fold(csum_sub(csum, |
| 10137 | csum_partial(t_header - fix, fix, 0))); |
| 10138 | |
| 10139 | else if (fix < 0) |
| 10140 | csum = (u16) ~csum_fold(csum_add(csum, |
| 10141 | csum_partial(t_header, -fix, 0))); |
| 10142 | |
| 10143 | return swab16(csum); |
| 10144 | } |
| 10145 | |
| 10146 | static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb) |
| 10147 | { |
| 10148 | u32 rc; |
| 10149 | |
| 10150 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 10151 | rc = XMIT_PLAIN; |
| 10152 | |
| 10153 | else { |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10154 | if (skb->protocol == htons(ETH_P_IPV6)) { |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10155 | rc = XMIT_CSUM_V6; |
| 10156 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 10157 | rc |= XMIT_CSUM_TCP; |
| 10158 | |
| 10159 | } else { |
| 10160 | rc = XMIT_CSUM_V4; |
| 10161 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 10162 | rc |= XMIT_CSUM_TCP; |
| 10163 | } |
| 10164 | } |
| 10165 | |
| 10166 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) |
| 10167 | rc |= XMIT_GSO_V4; |
| 10168 | |
| 10169 | else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 10170 | rc |= XMIT_GSO_V6; |
| 10171 | |
| 10172 | return rc; |
| 10173 | } |
| 10174 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10175 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10176 | /* check if packet requires linearization (packet is too fragmented) */ |
| 10177 | static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb, |
| 10178 | u32 xmit_type) |
| 10179 | { |
| 10180 | int to_copy = 0; |
| 10181 | int hlen = 0; |
| 10182 | int first_bd_sz = 0; |
| 10183 | |
| 10184 | /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */ |
| 10185 | if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) { |
| 10186 | |
| 10187 | if (xmit_type & XMIT_GSO) { |
| 10188 | unsigned short lso_mss = skb_shinfo(skb)->gso_size; |
| 10189 | /* Check if LSO packet needs to be copied: |
| 10190 | 3 = 1 (for headers BD) + 2 (for PBD and last BD) */ |
| 10191 | int wnd_size = MAX_FETCH_BD - 3; |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10192 | /* Number of windows to check */ |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10193 | int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size; |
| 10194 | int wnd_idx = 0; |
| 10195 | int frag_idx = 0; |
| 10196 | u32 wnd_sum = 0; |
| 10197 | |
| 10198 | /* Headers length */ |
| 10199 | hlen = (int)(skb_transport_header(skb) - skb->data) + |
| 10200 | tcp_hdrlen(skb); |
| 10201 | |
| 10202 | /* Amount of data (w/o headers) on linear part of SKB*/ |
| 10203 | first_bd_sz = skb_headlen(skb) - hlen; |
| 10204 | |
| 10205 | wnd_sum = first_bd_sz; |
| 10206 | |
| 10207 | /* Calculate the first sum - it's special */ |
| 10208 | for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++) |
| 10209 | wnd_sum += |
| 10210 | skb_shinfo(skb)->frags[frag_idx].size; |
| 10211 | |
| 10212 | /* If there was data on linear skb data - check it */ |
| 10213 | if (first_bd_sz > 0) { |
| 10214 | if (unlikely(wnd_sum < lso_mss)) { |
| 10215 | to_copy = 1; |
| 10216 | goto exit_lbl; |
| 10217 | } |
| 10218 | |
| 10219 | wnd_sum -= first_bd_sz; |
| 10220 | } |
| 10221 | |
| 10222 | /* Others are easier: run through the frag list and |
| 10223 | check all windows */ |
| 10224 | for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) { |
| 10225 | wnd_sum += |
| 10226 | skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size; |
| 10227 | |
| 10228 | if (unlikely(wnd_sum < lso_mss)) { |
| 10229 | to_copy = 1; |
| 10230 | break; |
| 10231 | } |
| 10232 | wnd_sum -= |
| 10233 | skb_shinfo(skb)->frags[wnd_idx].size; |
| 10234 | } |
| 10235 | |
| 10236 | } else { |
| 10237 | /* in non-LSO too fragmented packet should always |
| 10238 | be linearized */ |
| 10239 | to_copy = 1; |
| 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | exit_lbl: |
| 10244 | if (unlikely(to_copy)) |
| 10245 | DP(NETIF_MSG_TX_QUEUED, |
| 10246 | "Linearization IS REQUIRED for %s packet. " |
| 10247 | "num_frags %d hlen %d first_bd_sz %d\n", |
| 10248 | (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO", |
| 10249 | skb_shinfo(skb)->nr_frags, hlen, first_bd_sz); |
| 10250 | |
| 10251 | return to_copy; |
| 10252 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10253 | #endif |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10254 | |
| 10255 | /* called with netif_tx_lock |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10256 | * 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] | 10257 | * netif_wake_queue() |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10258 | */ |
| 10259 | static int bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 10260 | { |
| 10261 | struct bnx2x *bp = netdev_priv(dev); |
| 10262 | struct bnx2x_fastpath *fp; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10263 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10264 | struct sw_tx_bd *tx_buf; |
| 10265 | struct eth_tx_bd *tx_bd; |
| 10266 | struct eth_tx_parse_bd *pbd = NULL; |
| 10267 | u16 pkt_prod, bd_prod; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10268 | int nbd, fp_index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10269 | dma_addr_t mapping; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10270 | u32 xmit_type = bnx2x_xmit_type(bp, skb); |
| 10271 | int vlan_off = (bp->e1hov ? 4 : 0); |
| 10272 | int i; |
| 10273 | u8 hlen = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10274 | |
| 10275 | #ifdef BNX2X_STOP_ON_ERROR |
| 10276 | if (unlikely(bp->panic)) |
| 10277 | return NETDEV_TX_BUSY; |
| 10278 | #endif |
| 10279 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10280 | fp_index = skb_get_queue_mapping(skb); |
| 10281 | txq = netdev_get_tx_queue(dev, fp_index); |
| 10282 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10283 | fp = &bp->fp[fp_index]; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10284 | |
Yitchak Gertner | 231fd58 | 2008-08-25 15:27:06 -0700 | [diff] [blame] | 10285 | if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10286 | fp->eth_q_stats.driver_xoff++, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10287 | netif_tx_stop_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10288 | BNX2X_ERR("BUG! Tx ring full when queue awake!\n"); |
| 10289 | return NETDEV_TX_BUSY; |
| 10290 | } |
| 10291 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10292 | DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)" |
| 10293 | " gso type %x xmit_type %x\n", |
| 10294 | skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr, |
| 10295 | ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type); |
| 10296 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10297 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10298 | /* First, check if we need to linearize the skb |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10299 | (due to FW restrictions) */ |
| 10300 | if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) { |
| 10301 | /* Statistics of linearization */ |
| 10302 | bp->lin_cnt++; |
| 10303 | if (skb_linearize(skb) != 0) { |
| 10304 | DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - " |
| 10305 | "silently dropping this SKB\n"); |
| 10306 | dev_kfree_skb_any(skb); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10307 | return NETDEV_TX_OK; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10308 | } |
| 10309 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10310 | #endif |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10311 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10312 | /* |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10313 | 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] | 10314 | then for TSO or xsum we have a parsing info BD, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10315 | and only then we have the rest of the TSO BDs. |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10316 | (don't forget to mark the last one as last, |
| 10317 | and to unmap only AFTER you write to the BD ...) |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10318 | And above all, all pdb sizes are in words - NOT DWORDS! |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10319 | */ |
| 10320 | |
| 10321 | pkt_prod = fp->tx_pkt_prod++; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10322 | bd_prod = TX_BD(fp->tx_bd_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10323 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10324 | /* get a tx_buf and first BD */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10325 | tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)]; |
| 10326 | tx_bd = &fp->tx_desc_ring[bd_prod]; |
| 10327 | |
| 10328 | tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; |
| 10329 | tx_bd->general_data = (UNICAST_ADDRESS << |
| 10330 | ETH_TX_BD_ETH_ADDR_TYPE_SHIFT); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10331 | /* header nbd */ |
| 10332 | tx_bd->general_data |= (1 << ETH_TX_BD_HDR_NBDS_SHIFT); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10333 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10334 | /* remember the first BD of the packet */ |
| 10335 | tx_buf->first_bd = fp->tx_bd_prod; |
| 10336 | tx_buf->skb = skb; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10337 | |
| 10338 | DP(NETIF_MSG_TX_QUEUED, |
| 10339 | "sending pkt %u @%p next_idx %u bd %u @%p\n", |
| 10340 | pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_bd); |
| 10341 | |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10342 | #ifdef BCM_VLAN |
| 10343 | if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) && |
| 10344 | (bp->flags & HW_VLAN_TX_FLAG)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10345 | tx_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb)); |
| 10346 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10347 | vlan_off += 4; |
| 10348 | } else |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10349 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10350 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10351 | |
| 10352 | if (xmit_type) { |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10353 | /* turn on parsing and get a BD */ |
| 10354 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10355 | pbd = (void *)&fp->tx_desc_ring[bd_prod]; |
| 10356 | |
| 10357 | memset(pbd, 0, sizeof(struct eth_tx_parse_bd)); |
| 10358 | } |
| 10359 | |
| 10360 | if (xmit_type & XMIT_CSUM) { |
| 10361 | hlen = (skb_network_header(skb) - skb->data + vlan_off) / 2; |
| 10362 | |
| 10363 | /* for now NS flag is not used in Linux */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10364 | pbd->global_data = |
| 10365 | (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) << |
| 10366 | ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT)); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10367 | |
| 10368 | pbd->ip_hlen = (skb_transport_header(skb) - |
| 10369 | skb_network_header(skb)) / 2; |
| 10370 | |
| 10371 | hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2; |
| 10372 | |
| 10373 | pbd->total_hlen = cpu_to_le16(hlen); |
| 10374 | hlen = hlen*2 - vlan_off; |
| 10375 | |
| 10376 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_TCP_CSUM; |
| 10377 | |
| 10378 | if (xmit_type & XMIT_CSUM_V4) |
| 10379 | tx_bd->bd_flags.as_bitfield |= |
| 10380 | ETH_TX_BD_FLAGS_IP_CSUM; |
| 10381 | else |
| 10382 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IPV6; |
| 10383 | |
| 10384 | if (xmit_type & XMIT_CSUM_TCP) { |
| 10385 | pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check); |
| 10386 | |
| 10387 | } else { |
| 10388 | s8 fix = SKB_CS_OFF(skb); /* signed! */ |
| 10389 | |
| 10390 | pbd->global_data |= ETH_TX_PARSE_BD_CS_ANY_FLG; |
| 10391 | pbd->cs_offset = fix / 2; |
| 10392 | |
| 10393 | DP(NETIF_MSG_TX_QUEUED, |
| 10394 | "hlen %d offset %d fix %d csum before fix %x\n", |
| 10395 | le16_to_cpu(pbd->total_hlen), pbd->cs_offset, fix, |
| 10396 | SKB_CS(skb)); |
| 10397 | |
| 10398 | /* HW bug: fixup the CSUM */ |
| 10399 | pbd->tcp_pseudo_csum = |
| 10400 | bnx2x_csum_fix(skb_transport_header(skb), |
| 10401 | SKB_CS(skb), fix); |
| 10402 | |
| 10403 | DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n", |
| 10404 | pbd->tcp_pseudo_csum); |
| 10405 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10406 | } |
| 10407 | |
| 10408 | mapping = pci_map_single(bp->pdev, skb->data, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10409 | skb_headlen(skb), PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10410 | |
| 10411 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10412 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 10413 | nbd = skb_shinfo(skb)->nr_frags + ((pbd == NULL) ? 1 : 2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10414 | tx_bd->nbd = cpu_to_le16(nbd); |
| 10415 | tx_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 10416 | |
| 10417 | 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] | 10418 | " nbytes %d flags %x vlan %x\n", |
| 10419 | tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, le16_to_cpu(tx_bd->nbd), |
| 10420 | le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield, |
| 10421 | le16_to_cpu(tx_bd->vlan)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10422 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10423 | if (xmit_type & XMIT_GSO) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10424 | |
| 10425 | DP(NETIF_MSG_TX_QUEUED, |
| 10426 | "TSO packet len %d hlen %d total len %d tso size %d\n", |
| 10427 | skb->len, hlen, skb_headlen(skb), |
| 10428 | skb_shinfo(skb)->gso_size); |
| 10429 | |
| 10430 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO; |
| 10431 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10432 | if (unlikely(skb_headlen(skb) > hlen)) |
| 10433 | bd_prod = bnx2x_tx_split(bp, fp, &tx_bd, hlen, |
| 10434 | bd_prod, ++nbd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10435 | |
| 10436 | pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 10437 | pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10438 | pbd->tcp_flags = pbd_tcp_flags(skb); |
| 10439 | |
| 10440 | if (xmit_type & XMIT_GSO_V4) { |
| 10441 | pbd->ip_id = swab16(ip_hdr(skb)->id); |
| 10442 | pbd->tcp_pseudo_csum = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10443 | swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 10444 | ip_hdr(skb)->daddr, |
| 10445 | 0, IPPROTO_TCP, 0)); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10446 | |
| 10447 | } else |
| 10448 | pbd->tcp_pseudo_csum = |
| 10449 | swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 10450 | &ipv6_hdr(skb)->daddr, |
| 10451 | 0, IPPROTO_TCP, 0)); |
| 10452 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10453 | pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN; |
| 10454 | } |
| 10455 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10456 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 10457 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10458 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10459 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10460 | tx_bd = &fp->tx_desc_ring[bd_prod]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10461 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10462 | mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset, |
| 10463 | frag->size, PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10464 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10465 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10466 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 10467 | tx_bd->nbytes = cpu_to_le16(frag->size); |
| 10468 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
| 10469 | tx_bd->bd_flags.as_bitfield = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10470 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10471 | DP(NETIF_MSG_TX_QUEUED, |
| 10472 | "frag %d bd @%p addr (%x:%x) nbytes %d flags %x\n", |
| 10473 | i, tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, |
| 10474 | le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10475 | } |
| 10476 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10477 | /* now at last mark the BD as the last BD */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10478 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_END_BD; |
| 10479 | |
| 10480 | DP(NETIF_MSG_TX_QUEUED, "last bd @%p flags %x\n", |
| 10481 | tx_bd, tx_bd->bd_flags.as_bitfield); |
| 10482 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10483 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10484 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10485 | /* now send a tx doorbell, counting the next BD |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10486 | * if the packet contains or ends with it |
| 10487 | */ |
| 10488 | if (TX_BD_POFF(bd_prod) < nbd) |
| 10489 | nbd++; |
| 10490 | |
| 10491 | if (pbd) |
| 10492 | DP(NETIF_MSG_TX_QUEUED, |
| 10493 | "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u" |
| 10494 | " tcp_flags %x xsum %x seq %u hlen %u\n", |
| 10495 | pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id, |
| 10496 | pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10497 | pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10498 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10499 | 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] | 10500 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 10501 | /* |
| 10502 | * Make sure that the BD data is updated before updating the producer |
| 10503 | * since FW might read the BD right after the producer is updated. |
| 10504 | * This is only applicable for weak-ordered memory model archs such |
| 10505 | * as IA-64. The following barrier is also mandatory since FW will |
| 10506 | * assumes packets must have BDs. |
| 10507 | */ |
| 10508 | wmb(); |
| 10509 | |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10510 | le16_add_cpu(&fp->hw_tx_prods->bds_prod, nbd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10511 | mb(); /* FW restriction: must not reorder writing nbd and packets */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10512 | le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10513 | DOORBELL(bp, fp->index, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10514 | |
| 10515 | mmiowb(); |
| 10516 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10517 | fp->tx_bd_prod += nbd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10518 | dev->trans_start = jiffies; |
| 10519 | |
| 10520 | if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) { |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 10521 | /* We want bnx2x_tx_int to "see" the updated tx_bd_prod |
| 10522 | if we put Tx into XOFF state. */ |
| 10523 | smp_mb(); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10524 | netif_tx_stop_queue(txq); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10525 | fp->eth_q_stats.driver_xoff++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10526 | if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10527 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10528 | } |
| 10529 | fp->tx_pkt++; |
| 10530 | |
| 10531 | return NETDEV_TX_OK; |
| 10532 | } |
| 10533 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10534 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10535 | static int bnx2x_open(struct net_device *dev) |
| 10536 | { |
| 10537 | struct bnx2x *bp = netdev_priv(dev); |
| 10538 | |
Eilon Greenstein | 6eccabb | 2009-01-22 03:37:48 +0000 | [diff] [blame] | 10539 | netif_carrier_off(dev); |
| 10540 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10541 | bnx2x_set_power_state(bp, PCI_D0); |
| 10542 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10543 | return bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10544 | } |
| 10545 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10546 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10547 | static int bnx2x_close(struct net_device *dev) |
| 10548 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10549 | struct bnx2x *bp = netdev_priv(dev); |
| 10550 | |
| 10551 | /* Unload the driver, release IRQs */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10552 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
| 10553 | if (atomic_read(&bp->pdev->enable_cnt) == 1) |
| 10554 | if (!CHIP_REV_IS_SLOW(bp)) |
| 10555 | bnx2x_set_power_state(bp, PCI_D3hot); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10556 | |
| 10557 | return 0; |
| 10558 | } |
| 10559 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10560 | /* called with netif_tx_lock from set_multicast */ |
| 10561 | static void bnx2x_set_rx_mode(struct net_device *dev) |
| 10562 | { |
| 10563 | struct bnx2x *bp = netdev_priv(dev); |
| 10564 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; |
| 10565 | int port = BP_PORT(bp); |
| 10566 | |
| 10567 | if (bp->state != BNX2X_STATE_OPEN) { |
| 10568 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 10569 | return; |
| 10570 | } |
| 10571 | |
| 10572 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); |
| 10573 | |
| 10574 | if (dev->flags & IFF_PROMISC) |
| 10575 | rx_mode = BNX2X_RX_MODE_PROMISC; |
| 10576 | |
| 10577 | else if ((dev->flags & IFF_ALLMULTI) || |
| 10578 | ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp))) |
| 10579 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
| 10580 | |
| 10581 | else { /* some multicasts */ |
| 10582 | if (CHIP_IS_E1(bp)) { |
| 10583 | int i, old, offset; |
| 10584 | struct dev_mc_list *mclist; |
| 10585 | struct mac_configuration_cmd *config = |
| 10586 | bnx2x_sp(bp, mcast_config); |
| 10587 | |
| 10588 | for (i = 0, mclist = dev->mc_list; |
| 10589 | mclist && (i < dev->mc_count); |
| 10590 | i++, mclist = mclist->next) { |
| 10591 | |
| 10592 | config->config_table[i]. |
| 10593 | cam_entry.msb_mac_addr = |
| 10594 | swab16(*(u16 *)&mclist->dmi_addr[0]); |
| 10595 | config->config_table[i]. |
| 10596 | cam_entry.middle_mac_addr = |
| 10597 | swab16(*(u16 *)&mclist->dmi_addr[2]); |
| 10598 | config->config_table[i]. |
| 10599 | cam_entry.lsb_mac_addr = |
| 10600 | swab16(*(u16 *)&mclist->dmi_addr[4]); |
| 10601 | config->config_table[i].cam_entry.flags = |
| 10602 | cpu_to_le16(port); |
| 10603 | config->config_table[i]. |
| 10604 | target_table_entry.flags = 0; |
| 10605 | config->config_table[i]. |
| 10606 | target_table_entry.client_id = 0; |
| 10607 | config->config_table[i]. |
| 10608 | target_table_entry.vlan_id = 0; |
| 10609 | |
| 10610 | DP(NETIF_MSG_IFUP, |
| 10611 | "setting MCAST[%d] (%04x:%04x:%04x)\n", i, |
| 10612 | config->config_table[i]. |
| 10613 | cam_entry.msb_mac_addr, |
| 10614 | config->config_table[i]. |
| 10615 | cam_entry.middle_mac_addr, |
| 10616 | config->config_table[i]. |
| 10617 | cam_entry.lsb_mac_addr); |
| 10618 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10619 | old = config->hdr.length; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10620 | if (old > i) { |
| 10621 | for (; i < old; i++) { |
| 10622 | if (CAM_IS_INVALID(config-> |
| 10623 | config_table[i])) { |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 10624 | /* already invalidated */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10625 | break; |
| 10626 | } |
| 10627 | /* invalidate */ |
| 10628 | CAM_INVALIDATE(config-> |
| 10629 | config_table[i]); |
| 10630 | } |
| 10631 | } |
| 10632 | |
| 10633 | if (CHIP_REV_IS_SLOW(bp)) |
| 10634 | offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 10635 | else |
| 10636 | offset = BNX2X_MAX_MULTICAST*(1 + port); |
| 10637 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10638 | config->hdr.length = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10639 | config->hdr.offset = offset; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10640 | config->hdr.client_id = bp->fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10641 | config->hdr.reserved1 = 0; |
| 10642 | |
| 10643 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 10644 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 10645 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), |
| 10646 | 0); |
| 10647 | } else { /* E1H */ |
| 10648 | /* Accept one or more multicasts */ |
| 10649 | struct dev_mc_list *mclist; |
| 10650 | u32 mc_filter[MC_HASH_SIZE]; |
| 10651 | u32 crc, bit, regidx; |
| 10652 | int i; |
| 10653 | |
| 10654 | memset(mc_filter, 0, 4 * MC_HASH_SIZE); |
| 10655 | |
| 10656 | for (i = 0, mclist = dev->mc_list; |
| 10657 | mclist && (i < dev->mc_count); |
| 10658 | i++, mclist = mclist->next) { |
| 10659 | |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 10660 | DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", |
| 10661 | mclist->dmi_addr); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10662 | |
| 10663 | crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN); |
| 10664 | bit = (crc >> 24) & 0xff; |
| 10665 | regidx = bit >> 5; |
| 10666 | bit &= 0x1f; |
| 10667 | mc_filter[regidx] |= (1 << bit); |
| 10668 | } |
| 10669 | |
| 10670 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 10671 | REG_WR(bp, MC_HASH_OFFSET(bp, i), |
| 10672 | mc_filter[i]); |
| 10673 | } |
| 10674 | } |
| 10675 | |
| 10676 | bp->rx_mode = rx_mode; |
| 10677 | bnx2x_set_storm_rx_mode(bp); |
| 10678 | } |
| 10679 | |
| 10680 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10681 | static int bnx2x_change_mac_addr(struct net_device *dev, void *p) |
| 10682 | { |
| 10683 | struct sockaddr *addr = p; |
| 10684 | struct bnx2x *bp = netdev_priv(dev); |
| 10685 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10686 | if (!is_valid_ether_addr((u8 *)(addr->sa_data))) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10687 | return -EINVAL; |
| 10688 | |
| 10689 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10690 | if (netif_running(dev)) { |
| 10691 | if (CHIP_IS_E1(bp)) |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 10692 | bnx2x_set_mac_addr_e1(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10693 | else |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 10694 | bnx2x_set_mac_addr_e1h(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10695 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10696 | |
| 10697 | return 0; |
| 10698 | } |
| 10699 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10700 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10701 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 10702 | { |
| 10703 | struct mii_ioctl_data *data = if_mii(ifr); |
| 10704 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10705 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10706 | int err; |
| 10707 | |
| 10708 | switch (cmd) { |
| 10709 | case SIOCGMIIPHY: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10710 | data->phy_id = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10711 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 10712 | /* fallthrough */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10713 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10714 | case SIOCGMIIREG: { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10715 | u16 mii_regval; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10716 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10717 | if (!netif_running(dev)) |
| 10718 | return -EAGAIN; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10719 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10720 | mutex_lock(&bp->port.phy_mutex); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10721 | err = bnx2x_cl45_read(bp, port, 0, bp->port.phy_addr, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10722 | DEFAULT_PHY_DEV_ADDR, |
| 10723 | (data->reg_num & 0x1f), &mii_regval); |
| 10724 | data->val_out = mii_regval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10725 | mutex_unlock(&bp->port.phy_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10726 | return err; |
| 10727 | } |
| 10728 | |
| 10729 | case SIOCSMIIREG: |
| 10730 | if (!capable(CAP_NET_ADMIN)) |
| 10731 | return -EPERM; |
| 10732 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10733 | if (!netif_running(dev)) |
| 10734 | return -EAGAIN; |
| 10735 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10736 | mutex_lock(&bp->port.phy_mutex); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10737 | err = bnx2x_cl45_write(bp, port, 0, bp->port.phy_addr, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10738 | DEFAULT_PHY_DEV_ADDR, |
| 10739 | (data->reg_num & 0x1f), data->val_in); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10740 | mutex_unlock(&bp->port.phy_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10741 | return err; |
| 10742 | |
| 10743 | default: |
| 10744 | /* do nothing */ |
| 10745 | break; |
| 10746 | } |
| 10747 | |
| 10748 | return -EOPNOTSUPP; |
| 10749 | } |
| 10750 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10751 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10752 | static int bnx2x_change_mtu(struct net_device *dev, int new_mtu) |
| 10753 | { |
| 10754 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10755 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10756 | |
| 10757 | if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) || |
| 10758 | ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) |
| 10759 | return -EINVAL; |
| 10760 | |
| 10761 | /* This does not race with packet allocation |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 10762 | * because the actual alloc size is |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10763 | * only updated as part of load |
| 10764 | */ |
| 10765 | dev->mtu = new_mtu; |
| 10766 | |
| 10767 | if (netif_running(dev)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10768 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 10769 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10770 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10771 | |
| 10772 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10773 | } |
| 10774 | |
| 10775 | static void bnx2x_tx_timeout(struct net_device *dev) |
| 10776 | { |
| 10777 | struct bnx2x *bp = netdev_priv(dev); |
| 10778 | |
| 10779 | #ifdef BNX2X_STOP_ON_ERROR |
| 10780 | if (!bp->panic) |
| 10781 | bnx2x_panic(); |
| 10782 | #endif |
| 10783 | /* This allows the netif to be shutdown gracefully before resetting */ |
| 10784 | schedule_work(&bp->reset_task); |
| 10785 | } |
| 10786 | |
| 10787 | #ifdef BCM_VLAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10788 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10789 | static void bnx2x_vlan_rx_register(struct net_device *dev, |
| 10790 | struct vlan_group *vlgrp) |
| 10791 | { |
| 10792 | struct bnx2x *bp = netdev_priv(dev); |
| 10793 | |
| 10794 | bp->vlgrp = vlgrp; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10795 | |
| 10796 | /* Set flags according to the required capabilities */ |
| 10797 | bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
| 10798 | |
| 10799 | if (dev->features & NETIF_F_HW_VLAN_TX) |
| 10800 | bp->flags |= HW_VLAN_TX_FLAG; |
| 10801 | |
| 10802 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 10803 | bp->flags |= HW_VLAN_RX_FLAG; |
| 10804 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10805 | if (netif_running(dev)) |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 10806 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10807 | } |
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 | #endif |
| 10810 | |
| 10811 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 10812 | static void poll_bnx2x(struct net_device *dev) |
| 10813 | { |
| 10814 | struct bnx2x *bp = netdev_priv(dev); |
| 10815 | |
| 10816 | disable_irq(bp->pdev->irq); |
| 10817 | bnx2x_interrupt(bp->pdev->irq, dev); |
| 10818 | enable_irq(bp->pdev->irq); |
| 10819 | } |
| 10820 | #endif |
| 10821 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 10822 | static const struct net_device_ops bnx2x_netdev_ops = { |
| 10823 | .ndo_open = bnx2x_open, |
| 10824 | .ndo_stop = bnx2x_close, |
| 10825 | .ndo_start_xmit = bnx2x_start_xmit, |
| 10826 | .ndo_set_multicast_list = bnx2x_set_rx_mode, |
| 10827 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
| 10828 | .ndo_validate_addr = eth_validate_addr, |
| 10829 | .ndo_do_ioctl = bnx2x_ioctl, |
| 10830 | .ndo_change_mtu = bnx2x_change_mtu, |
| 10831 | .ndo_tx_timeout = bnx2x_tx_timeout, |
| 10832 | #ifdef BCM_VLAN |
| 10833 | .ndo_vlan_rx_register = bnx2x_vlan_rx_register, |
| 10834 | #endif |
| 10835 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 10836 | .ndo_poll_controller = poll_bnx2x, |
| 10837 | #endif |
| 10838 | }; |
| 10839 | |
| 10840 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10841 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
| 10842 | struct net_device *dev) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10843 | { |
| 10844 | struct bnx2x *bp; |
| 10845 | int rc; |
| 10846 | |
| 10847 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 10848 | bp = netdev_priv(dev); |
| 10849 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10850 | bp->dev = dev; |
| 10851 | bp->pdev = pdev; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10852 | bp->flags = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10853 | bp->func = PCI_FUNC(pdev->devfn); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10854 | |
| 10855 | rc = pci_enable_device(pdev); |
| 10856 | if (rc) { |
| 10857 | printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n"); |
| 10858 | goto err_out; |
| 10859 | } |
| 10860 | |
| 10861 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 10862 | printk(KERN_ERR PFX "Cannot find PCI device base address," |
| 10863 | " aborting\n"); |
| 10864 | rc = -ENODEV; |
| 10865 | goto err_out_disable; |
| 10866 | } |
| 10867 | |
| 10868 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
| 10869 | printk(KERN_ERR PFX "Cannot find second PCI device" |
| 10870 | " base address, aborting\n"); |
| 10871 | rc = -ENODEV; |
| 10872 | goto err_out_disable; |
| 10873 | } |
| 10874 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10875 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 10876 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 10877 | if (rc) { |
| 10878 | printk(KERN_ERR PFX "Cannot obtain PCI resources," |
| 10879 | " aborting\n"); |
| 10880 | goto err_out_disable; |
| 10881 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10882 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10883 | pci_set_master(pdev); |
| 10884 | pci_save_state(pdev); |
| 10885 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10886 | |
| 10887 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 10888 | if (bp->pm_cap == 0) { |
| 10889 | printk(KERN_ERR PFX "Cannot find power management" |
| 10890 | " capability, aborting\n"); |
| 10891 | rc = -EIO; |
| 10892 | goto err_out_release; |
| 10893 | } |
| 10894 | |
| 10895 | bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 10896 | if (bp->pcie_cap == 0) { |
| 10897 | printk(KERN_ERR PFX "Cannot find PCI Express capability," |
| 10898 | " aborting\n"); |
| 10899 | rc = -EIO; |
| 10900 | goto err_out_release; |
| 10901 | } |
| 10902 | |
| 10903 | if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) { |
| 10904 | bp->flags |= USING_DAC_FLAG; |
| 10905 | if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) { |
| 10906 | printk(KERN_ERR PFX "pci_set_consistent_dma_mask" |
| 10907 | " failed, aborting\n"); |
| 10908 | rc = -EIO; |
| 10909 | goto err_out_release; |
| 10910 | } |
| 10911 | |
| 10912 | } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) { |
| 10913 | printk(KERN_ERR PFX "System does not support DMA," |
| 10914 | " aborting\n"); |
| 10915 | rc = -EIO; |
| 10916 | goto err_out_release; |
| 10917 | } |
| 10918 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10919 | dev->mem_start = pci_resource_start(pdev, 0); |
| 10920 | dev->base_addr = dev->mem_start; |
| 10921 | dev->mem_end = pci_resource_end(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10922 | |
| 10923 | dev->irq = pdev->irq; |
| 10924 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 10925 | bp->regview = pci_ioremap_bar(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10926 | if (!bp->regview) { |
| 10927 | printk(KERN_ERR PFX "Cannot map register space, aborting\n"); |
| 10928 | rc = -ENOMEM; |
| 10929 | goto err_out_release; |
| 10930 | } |
| 10931 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10932 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), |
| 10933 | min_t(u64, BNX2X_DB_SIZE, |
| 10934 | pci_resource_len(pdev, 2))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10935 | if (!bp->doorbells) { |
| 10936 | printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n"); |
| 10937 | rc = -ENOMEM; |
| 10938 | goto err_out_unmap; |
| 10939 | } |
| 10940 | |
| 10941 | bnx2x_set_power_state(bp, PCI_D0); |
| 10942 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10943 | /* clean indirect addresses */ |
| 10944 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 10945 | PCICFG_VENDOR_ID_OFFSET); |
| 10946 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0); |
| 10947 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0); |
| 10948 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0); |
| 10949 | 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] | 10950 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10951 | dev->watchdog_timeo = TX_TIMEOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10952 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 10953 | dev->netdev_ops = &bnx2x_netdev_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10954 | dev->ethtool_ops = &bnx2x_ethtool_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10955 | dev->features |= NETIF_F_SG; |
| 10956 | dev->features |= NETIF_F_HW_CSUM; |
| 10957 | if (bp->flags & USING_DAC_FLAG) |
| 10958 | dev->features |= NETIF_F_HIGHDMA; |
| 10959 | #ifdef BCM_VLAN |
| 10960 | dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX); |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10961 | bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10962 | #endif |
| 10963 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10964 | dev->features |= NETIF_F_TSO6; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10965 | |
| 10966 | return 0; |
| 10967 | |
| 10968 | err_out_unmap: |
| 10969 | if (bp->regview) { |
| 10970 | iounmap(bp->regview); |
| 10971 | bp->regview = NULL; |
| 10972 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10973 | if (bp->doorbells) { |
| 10974 | iounmap(bp->doorbells); |
| 10975 | bp->doorbells = NULL; |
| 10976 | } |
| 10977 | |
| 10978 | err_out_release: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10979 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10980 | pci_release_regions(pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10981 | |
| 10982 | err_out_disable: |
| 10983 | pci_disable_device(pdev); |
| 10984 | pci_set_drvdata(pdev, NULL); |
| 10985 | |
| 10986 | err_out: |
| 10987 | return rc; |
| 10988 | } |
| 10989 | |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 10990 | static int __devinit bnx2x_get_pcie_width(struct bnx2x *bp) |
| 10991 | { |
| 10992 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 10993 | |
| 10994 | val = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
| 10995 | return val; |
| 10996 | } |
| 10997 | |
| 10998 | /* return value of 1=2.5GHz 2=5GHz */ |
| 10999 | static int __devinit bnx2x_get_pcie_speed(struct bnx2x *bp) |
| 11000 | { |
| 11001 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 11002 | |
| 11003 | val = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; |
| 11004 | return val; |
| 11005 | } |
| 11006 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11007 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
| 11008 | const struct pci_device_id *ent) |
| 11009 | { |
| 11010 | static int version_printed; |
| 11011 | struct net_device *dev = NULL; |
| 11012 | struct bnx2x *bp; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11013 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11014 | |
| 11015 | if (version_printed++ == 0) |
| 11016 | printk(KERN_INFO "%s", version); |
| 11017 | |
| 11018 | /* dev zeroed in init_etherdev */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 11019 | dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11020 | if (!dev) { |
| 11021 | printk(KERN_ERR PFX "Cannot allocate net device\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11022 | return -ENOMEM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11023 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11024 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11025 | bp = netdev_priv(dev); |
| 11026 | bp->msglevel = debug; |
| 11027 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11028 | rc = bnx2x_init_dev(pdev, dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11029 | if (rc < 0) { |
| 11030 | free_netdev(dev); |
| 11031 | return rc; |
| 11032 | } |
| 11033 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11034 | pci_set_drvdata(pdev, dev); |
| 11035 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11036 | rc = bnx2x_init_bp(bp); |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 11037 | if (rc) |
| 11038 | goto init_one_exit; |
| 11039 | |
| 11040 | rc = register_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11041 | if (rc) { |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 11042 | dev_err(&pdev->dev, "Cannot register net device\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11043 | goto init_one_exit; |
| 11044 | } |
| 11045 | |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11046 | 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] | 11047 | " IRQ %d, ", dev->name, board_info[ent->driver_data].name, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11048 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11049 | bnx2x_get_pcie_width(bp), |
| 11050 | (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz", |
| 11051 | dev->base_addr, bp->pdev->irq); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 11052 | printk(KERN_CONT "node addr %pM\n", dev->dev_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11053 | return 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11054 | |
| 11055 | init_one_exit: |
| 11056 | if (bp->regview) |
| 11057 | iounmap(bp->regview); |
| 11058 | |
| 11059 | if (bp->doorbells) |
| 11060 | iounmap(bp->doorbells); |
| 11061 | |
| 11062 | free_netdev(dev); |
| 11063 | |
| 11064 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 11065 | pci_release_regions(pdev); |
| 11066 | |
| 11067 | pci_disable_device(pdev); |
| 11068 | pci_set_drvdata(pdev, NULL); |
| 11069 | |
| 11070 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11071 | } |
| 11072 | |
| 11073 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) |
| 11074 | { |
| 11075 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11076 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11077 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11078 | if (!dev) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11079 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 11080 | return; |
| 11081 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11082 | bp = netdev_priv(dev); |
| 11083 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11084 | unregister_netdev(dev); |
| 11085 | |
| 11086 | if (bp->regview) |
| 11087 | iounmap(bp->regview); |
| 11088 | |
| 11089 | if (bp->doorbells) |
| 11090 | iounmap(bp->doorbells); |
| 11091 | |
| 11092 | free_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11093 | |
| 11094 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 11095 | pci_release_regions(pdev); |
| 11096 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11097 | pci_disable_device(pdev); |
| 11098 | pci_set_drvdata(pdev, NULL); |
| 11099 | } |
| 11100 | |
| 11101 | static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11102 | { |
| 11103 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11104 | struct bnx2x *bp; |
| 11105 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11106 | if (!dev) { |
| 11107 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 11108 | return -ENODEV; |
| 11109 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11110 | bp = netdev_priv(dev); |
| 11111 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11112 | rtnl_lock(); |
| 11113 | |
| 11114 | pci_save_state(pdev); |
| 11115 | |
| 11116 | if (!netif_running(dev)) { |
| 11117 | rtnl_unlock(); |
| 11118 | return 0; |
| 11119 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11120 | |
| 11121 | netif_device_detach(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11122 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 11123 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11124 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11125 | bnx2x_set_power_state(bp, pci_choose_state(pdev, state)); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11126 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11127 | rtnl_unlock(); |
| 11128 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11129 | return 0; |
| 11130 | } |
| 11131 | |
| 11132 | static int bnx2x_resume(struct pci_dev *pdev) |
| 11133 | { |
| 11134 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11135 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11136 | int rc; |
| 11137 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11138 | if (!dev) { |
| 11139 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 11140 | return -ENODEV; |
| 11141 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11142 | bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11143 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11144 | rtnl_lock(); |
| 11145 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11146 | pci_restore_state(pdev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11147 | |
| 11148 | if (!netif_running(dev)) { |
| 11149 | rtnl_unlock(); |
| 11150 | return 0; |
| 11151 | } |
| 11152 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11153 | bnx2x_set_power_state(bp, PCI_D0); |
| 11154 | netif_device_attach(dev); |
| 11155 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 11156 | rc = bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11157 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11158 | rtnl_unlock(); |
| 11159 | |
| 11160 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11161 | } |
| 11162 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11163 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
| 11164 | { |
| 11165 | int i; |
| 11166 | |
| 11167 | bp->state = BNX2X_STATE_ERROR; |
| 11168 | |
| 11169 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 11170 | |
| 11171 | bnx2x_netif_stop(bp, 0); |
| 11172 | |
| 11173 | del_timer_sync(&bp->timer); |
| 11174 | bp->stats_state = STATS_STATE_DISABLED; |
| 11175 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 11176 | |
| 11177 | /* Release IRQs */ |
| 11178 | bnx2x_free_irq(bp); |
| 11179 | |
| 11180 | if (CHIP_IS_E1(bp)) { |
| 11181 | struct mac_configuration_cmd *config = |
| 11182 | bnx2x_sp(bp, mcast_config); |
| 11183 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 11184 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11185 | CAM_INVALIDATE(config->config_table[i]); |
| 11186 | } |
| 11187 | |
| 11188 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 11189 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 11190 | for_each_rx_queue(bp, i) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11191 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 11192 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 11193 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11194 | bnx2x_free_mem(bp); |
| 11195 | |
| 11196 | bp->state = BNX2X_STATE_CLOSED; |
| 11197 | |
| 11198 | netif_carrier_off(bp->dev); |
| 11199 | |
| 11200 | return 0; |
| 11201 | } |
| 11202 | |
| 11203 | static void bnx2x_eeh_recover(struct bnx2x *bp) |
| 11204 | { |
| 11205 | u32 val; |
| 11206 | |
| 11207 | mutex_init(&bp->port.phy_mutex); |
| 11208 | |
| 11209 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 11210 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 11211 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 11212 | |
| 11213 | if (!bp->common.shmem_base || |
| 11214 | (bp->common.shmem_base < 0xA0000) || |
| 11215 | (bp->common.shmem_base >= 0xC0000)) { |
| 11216 | BNX2X_DEV_INFO("MCP not active\n"); |
| 11217 | bp->flags |= NO_MCP_FLAG; |
| 11218 | return; |
| 11219 | } |
| 11220 | |
| 11221 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 11222 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 11223 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 11224 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 11225 | |
| 11226 | if (!BP_NOMCP(bp)) { |
| 11227 | bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header) |
| 11228 | & DRV_MSG_SEQ_NUMBER_MASK); |
| 11229 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 11230 | } |
| 11231 | } |
| 11232 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11233 | /** |
| 11234 | * bnx2x_io_error_detected - called when PCI error is detected |
| 11235 | * @pdev: Pointer to PCI device |
| 11236 | * @state: The current pci connection state |
| 11237 | * |
| 11238 | * This function is called after a PCI bus error affecting |
| 11239 | * this device has been detected. |
| 11240 | */ |
| 11241 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, |
| 11242 | pci_channel_state_t state) |
| 11243 | { |
| 11244 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11245 | struct bnx2x *bp = netdev_priv(dev); |
| 11246 | |
| 11247 | rtnl_lock(); |
| 11248 | |
| 11249 | netif_device_detach(dev); |
| 11250 | |
| 11251 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11252 | bnx2x_eeh_nic_unload(bp); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11253 | |
| 11254 | pci_disable_device(pdev); |
| 11255 | |
| 11256 | rtnl_unlock(); |
| 11257 | |
| 11258 | /* Request a slot reset */ |
| 11259 | return PCI_ERS_RESULT_NEED_RESET; |
| 11260 | } |
| 11261 | |
| 11262 | /** |
| 11263 | * bnx2x_io_slot_reset - called after the PCI bus has been reset |
| 11264 | * @pdev: Pointer to PCI device |
| 11265 | * |
| 11266 | * Restart the card from scratch, as if from a cold-boot. |
| 11267 | */ |
| 11268 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) |
| 11269 | { |
| 11270 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11271 | struct bnx2x *bp = netdev_priv(dev); |
| 11272 | |
| 11273 | rtnl_lock(); |
| 11274 | |
| 11275 | if (pci_enable_device(pdev)) { |
| 11276 | dev_err(&pdev->dev, |
| 11277 | "Cannot re-enable PCI device after reset\n"); |
| 11278 | rtnl_unlock(); |
| 11279 | return PCI_ERS_RESULT_DISCONNECT; |
| 11280 | } |
| 11281 | |
| 11282 | pci_set_master(pdev); |
| 11283 | pci_restore_state(pdev); |
| 11284 | |
| 11285 | if (netif_running(dev)) |
| 11286 | bnx2x_set_power_state(bp, PCI_D0); |
| 11287 | |
| 11288 | rtnl_unlock(); |
| 11289 | |
| 11290 | return PCI_ERS_RESULT_RECOVERED; |
| 11291 | } |
| 11292 | |
| 11293 | /** |
| 11294 | * bnx2x_io_resume - called when traffic can start flowing again |
| 11295 | * @pdev: Pointer to PCI device |
| 11296 | * |
| 11297 | * This callback is called when the error recovery driver tells us that |
| 11298 | * its OK to resume normal operation. |
| 11299 | */ |
| 11300 | static void bnx2x_io_resume(struct pci_dev *pdev) |
| 11301 | { |
| 11302 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11303 | struct bnx2x *bp = netdev_priv(dev); |
| 11304 | |
| 11305 | rtnl_lock(); |
| 11306 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11307 | bnx2x_eeh_recover(bp); |
| 11308 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11309 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11310 | bnx2x_nic_load(bp, LOAD_NORMAL); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11311 | |
| 11312 | netif_device_attach(dev); |
| 11313 | |
| 11314 | rtnl_unlock(); |
| 11315 | } |
| 11316 | |
| 11317 | static struct pci_error_handlers bnx2x_err_handler = { |
| 11318 | .error_detected = bnx2x_io_error_detected, |
| 11319 | .slot_reset = bnx2x_io_slot_reset, |
| 11320 | .resume = bnx2x_io_resume, |
| 11321 | }; |
| 11322 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11323 | static struct pci_driver bnx2x_pci_driver = { |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11324 | .name = DRV_MODULE_NAME, |
| 11325 | .id_table = bnx2x_pci_tbl, |
| 11326 | .probe = bnx2x_init_one, |
| 11327 | .remove = __devexit_p(bnx2x_remove_one), |
| 11328 | .suspend = bnx2x_suspend, |
| 11329 | .resume = bnx2x_resume, |
| 11330 | .err_handler = &bnx2x_err_handler, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11331 | }; |
| 11332 | |
| 11333 | static int __init bnx2x_init(void) |
| 11334 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 11335 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
| 11336 | if (bnx2x_wq == NULL) { |
| 11337 | printk(KERN_ERR PFX "Cannot create workqueue\n"); |
| 11338 | return -ENOMEM; |
| 11339 | } |
| 11340 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11341 | return pci_register_driver(&bnx2x_pci_driver); |
| 11342 | } |
| 11343 | |
| 11344 | static void __exit bnx2x_cleanup(void) |
| 11345 | { |
| 11346 | pci_unregister_driver(&bnx2x_pci_driver); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 11347 | |
| 11348 | destroy_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11349 | } |
| 11350 | |
| 11351 | module_init(bnx2x_init); |
| 11352 | module_exit(bnx2x_cleanup); |
| 11353 | |