blob: 2e95799a0db24378f86f5b6651b0de62f1856e44 [file] [log] [blame]
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001/* bnx2x_main.c: Broadcom Everest network driver.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002 *
Eilon Greensteind05c26c2009-01-17 23:26:13 -08003 * Copyright (c) 2007-2009 Broadcom Corporation
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004 *
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 Greenstein24e3fce2008-06-12 14:30:28 -07009 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath rework by Vladislav Zolotarov
Eliezer Tamirc14423f2008-02-28 11:49:42 -080014 * Statistics and Link management by Yitchak Gertner
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020015 *
16 */
17
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020018#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 Greenstein0c6671b2009-01-14 21:26:51 -080041#include <linux/if_vlan.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020042#include <net/ip.h>
43#include <net/tcp.h>
44#include <net/checksum.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070045#include <net/ip6_checksum.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020046#include <linux/workqueue.h>
47#include <linux/crc32.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070048#include <linux/crc32c.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020049#include <linux/prefetch.h>
50#include <linux/zlib.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020051#include <linux/io.h>
52
53#include "bnx2x_reg.h"
54#include "bnx2x_fw_defs.h"
55#include "bnx2x_hsi.h"
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070056#include "bnx2x_link.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020057#include "bnx2x.h"
58#include "bnx2x_init.h"
59
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -080060#define DRV_MODULE_VERSION "1.45.26"
61#define DRV_MODULE_RELDATE "2009/01/26"
Eilon Greenstein34f80b02008-06-23 20:33:01 -070062#define BNX2X_BC_VER 0x040200
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020063
Eilon Greenstein34f80b02008-06-23 20:33:01 -070064/* Time in jiffies before concluding the transmitter is hung */
65#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020066
Andrew Morton53a10562008-02-09 23:16:41 -080067static char version[] __devinitdata =
Eilon Greenstein34f80b02008-06-23 20:33:01 -070068 "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020069 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
70
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070071MODULE_AUTHOR("Eliezer Tamir");
Eilon Greensteine47d7e62009-01-14 06:44:28 +000072MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020073MODULE_LICENSE("GPL");
74MODULE_VERSION(DRV_MODULE_VERSION);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020075
Eilon Greenstein555f6c72009-02-12 08:36:11 +000076static int multi_mode = 1;
77module_param(multi_mode, int, 0);
78
Eilon Greenstein19680c42008-08-13 15:47:33 -070079static int disable_tpa;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020080static int poll;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020081static int debug;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070082static int load_count[3]; /* 0-common, 1-port0, 2-port1 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020083
Eilon Greenstein19680c42008-08-13 15:47:33 -070084module_param(disable_tpa, int, 0);
Eilon Greenstein8badd272009-02-12 08:36:15 +000085
86static int int_mode;
87module_param(int_mode, int, 0);
88MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)");
89
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020090module_param(poll, int, 0);
Eilon Greenstein8d5726c2009-02-12 08:37:19 +000091
92static int mrrs = -1;
93module_param(mrrs, int, 0);
94MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
95
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020096module_param(debug, int, 0);
Eilon Greenstein19680c42008-08-13 15:47:33 -070097MODULE_PARM_DESC(disable_tpa, "disable the TPA (LRO) feature");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020098MODULE_PARM_DESC(poll, "use polling (for debug)");
Eliezer Tamirc14423f2008-02-28 11:49:42 -080099MODULE_PARM_DESC(debug, "default debug msglevel");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200100
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800101static struct workqueue_struct *bnx2x_wq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200102
103enum bnx2x_board_type {
104 BCM57710 = 0,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700105 BCM57711 = 1,
106 BCM57711E = 2,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200107};
108
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700109/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800110static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200111 char *name;
112} board_info[] __devinitdata = {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700113 { "Broadcom NetXtreme II BCM57710 XGb" },
114 { "Broadcom NetXtreme II BCM57711 XGb" },
115 { "Broadcom NetXtreme II BCM57711E XGb" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200116};
117
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700118
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200119static const struct pci_device_id bnx2x_pci_tbl[] = {
120 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710,
121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57710 },
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700122 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711,
123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711 },
124 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E,
125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711E },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200126 { 0 }
127};
128
129MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
130
131/****************************************************************************
132* General service functions
133****************************************************************************/
134
135/* used only at init
136 * locking is done by mcp
137 */
138static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
139{
140 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
141 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
142 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
143 PCICFG_VENDOR_ID_OFFSET);
144}
145
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200146static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
147{
148 u32 val;
149
150 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
151 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
152 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
153 PCICFG_VENDOR_ID_OFFSET);
154
155 return val;
156}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200157
158static const u32 dmae_reg_go_c[] = {
159 DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
160 DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
161 DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
162 DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
163};
164
165/* copy command into DMAE command memory and set DMAE command go */
166static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
167 int idx)
168{
169 u32 cmd_offset;
170 int i;
171
172 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
173 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
174 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
175
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700176 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
177 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200178 }
179 REG_WR(bp, dmae_reg_go_c[idx], 1);
180}
181
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700182void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
183 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200184{
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700185 struct dmae_command *dmae = &bp->init_dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200186 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700187 int cnt = 200;
188
189 if (!bp->dmae_ready) {
190 u32 *data = bnx2x_sp(bp, wb_data[0]);
191
192 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
193 " using indirect\n", dst_addr, len32);
194 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
195 return;
196 }
197
198 mutex_lock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200199
200 memset(dmae, 0, sizeof(struct dmae_command));
201
202 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
203 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
204 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
205#ifdef __BIG_ENDIAN
206 DMAE_CMD_ENDIANITY_B_DW_SWAP |
207#else
208 DMAE_CMD_ENDIANITY_DW_SWAP |
209#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700210 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
211 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200212 dmae->src_addr_lo = U64_LO(dma_addr);
213 dmae->src_addr_hi = U64_HI(dma_addr);
214 dmae->dst_addr_lo = dst_addr >> 2;
215 dmae->dst_addr_hi = 0;
216 dmae->len = len32;
217 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
218 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700219 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200220
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700221 DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200222 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
223 "dst_addr [%x:%08x (%08x)]\n"
224 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
225 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
226 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr,
227 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700228 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200229 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
230 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200231
232 *wb_comp = 0;
233
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700234 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200235
236 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700237
238 while (*wb_comp != DMAE_COMP_VAL) {
239 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
240
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700241 if (!cnt) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200242 BNX2X_ERR("dmae timeout!\n");
243 break;
244 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700245 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700246 /* adjust delay for emulation/FPGA */
247 if (CHIP_REV_IS_SLOW(bp))
248 msleep(100);
249 else
250 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200251 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700252
253 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200254}
255
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700256void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200257{
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700258 struct dmae_command *dmae = &bp->init_dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200259 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700260 int cnt = 200;
261
262 if (!bp->dmae_ready) {
263 u32 *data = bnx2x_sp(bp, wb_data[0]);
264 int i;
265
266 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
267 " using indirect\n", src_addr, len32);
268 for (i = 0; i < len32; i++)
269 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
270 return;
271 }
272
273 mutex_lock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200274
275 memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
276 memset(dmae, 0, sizeof(struct dmae_command));
277
278 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
279 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
280 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
281#ifdef __BIG_ENDIAN
282 DMAE_CMD_ENDIANITY_B_DW_SWAP |
283#else
284 DMAE_CMD_ENDIANITY_DW_SWAP |
285#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700286 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
287 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200288 dmae->src_addr_lo = src_addr >> 2;
289 dmae->src_addr_hi = 0;
290 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
291 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
292 dmae->len = len32;
293 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
294 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700295 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200296
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700297 DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200298 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
299 "dst_addr [%x:%08x (%08x)]\n"
300 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
301 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
302 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr,
303 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200304
305 *wb_comp = 0;
306
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700307 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200308
309 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700310
311 while (*wb_comp != DMAE_COMP_VAL) {
312
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700313 if (!cnt) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200314 BNX2X_ERR("dmae timeout!\n");
315 break;
316 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700317 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700318 /* adjust delay for emulation/FPGA */
319 if (CHIP_REV_IS_SLOW(bp))
320 msleep(100);
321 else
322 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200323 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700324 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200325 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
326 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700327
328 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200329}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200330
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700331/* used only for slowpath so not inlined */
332static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
333{
334 u32 wb_write[2];
335
336 wb_write[0] = val_hi;
337 wb_write[1] = val_lo;
338 REG_WR_DMAE(bp, reg, wb_write, 2);
339}
340
341#ifdef USE_WB_RD
342static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
343{
344 u32 wb_data[2];
345
346 REG_RD_DMAE(bp, reg, wb_data, 2);
347
348 return HILO_U64(wb_data[0], wb_data[1]);
349}
350#endif
351
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200352static int bnx2x_mc_assert(struct bnx2x *bp)
353{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200354 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700355 int i, rc = 0;
356 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200357
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700358 /* XSTORM */
359 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
360 XSTORM_ASSERT_LIST_INDEX_OFFSET);
361 if (last_idx)
362 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200363
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700364 /* print the asserts */
365 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200366
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700367 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
368 XSTORM_ASSERT_LIST_OFFSET(i));
369 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
370 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
371 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
372 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
373 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
374 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200375
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700376 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
377 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
378 " 0x%08x 0x%08x 0x%08x\n",
379 i, row3, row2, row1, row0);
380 rc++;
381 } else {
382 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200383 }
384 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700385
386 /* TSTORM */
387 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
388 TSTORM_ASSERT_LIST_INDEX_OFFSET);
389 if (last_idx)
390 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
391
392 /* print the asserts */
393 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
394
395 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
396 TSTORM_ASSERT_LIST_OFFSET(i));
397 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
398 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
399 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
400 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
401 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
402 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
403
404 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
405 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
406 " 0x%08x 0x%08x 0x%08x\n",
407 i, row3, row2, row1, row0);
408 rc++;
409 } else {
410 break;
411 }
412 }
413
414 /* CSTORM */
415 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
416 CSTORM_ASSERT_LIST_INDEX_OFFSET);
417 if (last_idx)
418 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
419
420 /* print the asserts */
421 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
422
423 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
424 CSTORM_ASSERT_LIST_OFFSET(i));
425 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
426 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
427 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
428 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
429 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
430 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
431
432 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
433 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
434 " 0x%08x 0x%08x 0x%08x\n",
435 i, row3, row2, row1, row0);
436 rc++;
437 } else {
438 break;
439 }
440 }
441
442 /* USTORM */
443 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
444 USTORM_ASSERT_LIST_INDEX_OFFSET);
445 if (last_idx)
446 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
447
448 /* print the asserts */
449 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
450
451 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
452 USTORM_ASSERT_LIST_OFFSET(i));
453 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
454 USTORM_ASSERT_LIST_OFFSET(i) + 4);
455 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
456 USTORM_ASSERT_LIST_OFFSET(i) + 8);
457 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
458 USTORM_ASSERT_LIST_OFFSET(i) + 12);
459
460 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
461 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
462 " 0x%08x 0x%08x 0x%08x\n",
463 i, row3, row2, row1, row0);
464 rc++;
465 } else {
466 break;
467 }
468 }
469
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200470 return rc;
471}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800472
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200473static void bnx2x_fw_dump(struct bnx2x *bp)
474{
475 u32 mark, offset;
476 u32 data[9];
477 int word;
478
479 mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800480 mark = ((mark + 0x3) & ~0x3);
481 printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n" KERN_ERR, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200482
483 for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) {
484 for (word = 0; word < 8; word++)
485 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
486 offset + 4*word));
487 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800488 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200489 }
490 for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) {
491 for (word = 0; word < 8; word++)
492 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
493 offset + 4*word));
494 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800495 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200496 }
497 printk("\n" KERN_ERR PFX "end of fw dump\n");
498}
499
500static void bnx2x_panic_dump(struct bnx2x *bp)
501{
502 int i;
503 u16 j, start, end;
504
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700505 bp->stats_state = STATS_STATE_DISABLED;
506 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
507
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200508 BNX2X_ERR("begin crash dump -----------------\n");
509
510 for_each_queue(bp, i) {
511 struct bnx2x_fastpath *fp = &bp->fp[i];
512 struct eth_tx_db_data *hw_prods = fp->hw_tx_prods;
513
514 BNX2X_ERR("queue[%d]: tx_pkt_prod(%x) tx_pkt_cons(%x)"
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700515 " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200516 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700517 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700518 BNX2X_ERR(" rx_bd_prod(%x) rx_bd_cons(%x)"
519 " *rx_bd_cons_sb(%x) rx_comp_prod(%x)"
520 " rx_comp_cons(%x) *rx_cons_sb(%x)\n",
521 fp->rx_bd_prod, fp->rx_bd_cons,
522 le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
523 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
524 BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)"
525 " fp_c_idx(%x) *sb_c_idx(%x) fp_u_idx(%x)"
526 " *sb_u_idx(%x) bd data(%x,%x)\n",
527 fp->rx_sge_prod, fp->last_max_sge, fp->fp_c_idx,
528 fp->status_blk->c_status_block.status_block_index,
529 fp->fp_u_idx,
530 fp->status_blk->u_status_block.status_block_index,
531 hw_prods->packets_prod, hw_prods->bds_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200532
533 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
534 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
535 for (j = start; j < end; j++) {
536 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
537
538 BNX2X_ERR("packet[%x]=[%p,%x]\n", j,
539 sw_bd->skb, sw_bd->first_bd);
540 }
541
542 start = TX_BD(fp->tx_bd_cons - 10);
543 end = TX_BD(fp->tx_bd_cons + 254);
544 for (j = start; j < end; j++) {
545 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
546
547 BNX2X_ERR("tx_bd[%x]=[%x:%x:%x:%x]\n",
548 j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
549 }
550
551 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
552 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
553 for (j = start; j < end; j++) {
554 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
555 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
556
557 BNX2X_ERR("rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700558 j, rx_bd[1], rx_bd[0], sw_bd->skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200559 }
560
Eilon Greenstein3196a882008-08-13 15:58:49 -0700561 start = RX_SGE(fp->rx_sge_prod);
562 end = RX_SGE(fp->last_max_sge);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700563 for (j = start; j < end; j++) {
564 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
565 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
566
567 BNX2X_ERR("rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
568 j, rx_sge[1], rx_sge[0], sw_page->page);
569 }
570
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200571 start = RCQ_BD(fp->rx_comp_cons - 10);
572 end = RCQ_BD(fp->rx_comp_cons + 503);
573 for (j = start; j < end; j++) {
574 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
575
576 BNX2X_ERR("cqe[%x]=[%x:%x:%x:%x]\n",
577 j, cqe[0], cqe[1], cqe[2], cqe[3]);
578 }
579 }
580
Eliezer Tamir49d66772008-02-28 11:53:13 -0800581 BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)"
582 " def_t_idx(%u) def_att_idx(%u) attn_state(%u)"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200583 " spq_prod_idx(%u)\n",
Eliezer Tamir49d66772008-02-28 11:53:13 -0800584 bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200585 bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
586
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700587 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200588 bnx2x_mc_assert(bp);
589 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200590}
591
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800592static void bnx2x_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200593{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700594 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200595 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
596 u32 val = REG_RD(bp, addr);
597 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000598 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200599
600 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000601 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
602 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200603 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
604 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eilon Greenstein8badd272009-02-12 08:36:15 +0000605 } else if (msi) {
606 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
607 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
608 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
609 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200610 } else {
611 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800612 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200613 HC_CONFIG_0_REG_INT_LINE_EN_0 |
614 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800615
Eilon Greenstein8badd272009-02-12 08:36:15 +0000616 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
617 val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800618
619 REG_WR(bp, addr, val);
620
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200621 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
622 }
623
Eilon Greenstein8badd272009-02-12 08:36:15 +0000624 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
625 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200626
627 REG_WR(bp, addr, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700628
629 if (CHIP_IS_E1H(bp)) {
630 /* init leading/trailing edge */
631 if (IS_E1HMF(bp)) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000632 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700633 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +0000634 /* enable nig and gpio3 attention */
635 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700636 } else
637 val = 0xffff;
638
639 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
640 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
641 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200642}
643
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800644static void bnx2x_int_disable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200645{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700646 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200647 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
648 u32 val = REG_RD(bp, addr);
649
650 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
651 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
652 HC_CONFIG_0_REG_INT_LINE_EN_0 |
653 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
654
655 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
656 val, port, addr);
657
Eilon Greenstein8badd272009-02-12 08:36:15 +0000658 /* flush all outstanding writes */
659 mmiowb();
660
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200661 REG_WR(bp, addr, val);
662 if (REG_RD(bp, addr) != val)
663 BNX2X_ERR("BUG! proper val not read from IGU!\n");
664}
665
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700666static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200667{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200668 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000669 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200670
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700671 /* disable interrupt handling */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200672 atomic_inc(&bp->intr_sem);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700673 if (disable_hw)
674 /* prevent the HW from sending interrupts */
675 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200676
677 /* make sure all ISRs are done */
678 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000679 synchronize_irq(bp->msix_table[0].vector);
680 offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200681 for_each_queue(bp, i)
Eilon Greenstein8badd272009-02-12 08:36:15 +0000682 synchronize_irq(bp->msix_table[i + offset].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200683 } else
684 synchronize_irq(bp->pdev->irq);
685
686 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800687 cancel_delayed_work(&bp->sp_task);
688 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200689}
690
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700691/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200692
693/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700694 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200695 */
696
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700697static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200698 u8 storm, u16 index, u8 op, u8 update)
699{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700700 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
701 COMMAND_REG_INT_ACK);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200702 struct igu_ack_register igu_ack;
703
704 igu_ack.status_block_index = index;
705 igu_ack.sb_id_and_flags =
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700706 ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200707 (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
708 (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
709 (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
710
Eilon Greenstein5c862842008-08-13 15:51:48 -0700711 DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
712 (*(u32 *)&igu_ack), hc_addr);
713 REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200714}
715
716static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
717{
718 struct host_status_block *fpsb = fp->status_blk;
719 u16 rc = 0;
720
721 barrier(); /* status block is written to by the chip */
722 if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
723 fp->fp_c_idx = fpsb->c_status_block.status_block_index;
724 rc |= 1;
725 }
726 if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
727 fp->fp_u_idx = fpsb->u_status_block.status_block_index;
728 rc |= 2;
729 }
730 return rc;
731}
732
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200733static u16 bnx2x_ack_int(struct bnx2x *bp)
734{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700735 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
736 COMMAND_REG_SIMD_MASK);
737 u32 result = REG_RD(bp, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200738
Eilon Greenstein5c862842008-08-13 15:51:48 -0700739 DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
740 result, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200741
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200742 return result;
743}
744
745
746/*
747 * fast path service functions
748 */
749
Eilon Greenstein237907c2009-01-14 06:42:44 +0000750static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
751{
752 u16 tx_cons_sb;
753
754 /* Tell compiler that status block fields can change */
755 barrier();
756 tx_cons_sb = le16_to_cpu(*fp->tx_cons_sb);
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -0800757 return (fp->tx_pkt_cons != tx_cons_sb);
758}
759
760static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
761{
762 /* Tell compiler that consumer and producer can change */
763 barrier();
764 return (fp->tx_pkt_prod != fp->tx_pkt_cons);
765
Eilon Greenstein237907c2009-01-14 06:42:44 +0000766}
767
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200768/* free skb in the packet ring at pos idx
769 * return idx of last bd freed
770 */
771static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
772 u16 idx)
773{
774 struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
775 struct eth_tx_bd *tx_bd;
776 struct sk_buff *skb = tx_buf->skb;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700777 u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200778 int nbd;
779
780 DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
781 idx, tx_buf, skb);
782
783 /* unmap first bd */
784 DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
785 tx_bd = &fp->tx_desc_ring[bd_idx];
786 pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_bd),
787 BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
788
789 nbd = le16_to_cpu(tx_bd->nbd) - 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700790 new_cons = nbd + tx_buf->first_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200791#ifdef BNX2X_STOP_ON_ERROR
792 if (nbd > (MAX_SKB_FRAGS + 2)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700793 BNX2X_ERR("BAD nbd!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200794 bnx2x_panic();
795 }
796#endif
797
798 /* Skip a parse bd and the TSO split header bd
799 since they have no mapping */
800 if (nbd)
801 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
802
803 if (tx_bd->bd_flags.as_bitfield & (ETH_TX_BD_FLAGS_IP_CSUM |
804 ETH_TX_BD_FLAGS_TCP_CSUM |
805 ETH_TX_BD_FLAGS_SW_LSO)) {
806 if (--nbd)
807 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
808 tx_bd = &fp->tx_desc_ring[bd_idx];
809 /* is this a TSO split header bd? */
810 if (tx_bd->bd_flags.as_bitfield & ETH_TX_BD_FLAGS_SW_LSO) {
811 if (--nbd)
812 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
813 }
814 }
815
816 /* now free frags */
817 while (nbd > 0) {
818
819 DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
820 tx_bd = &fp->tx_desc_ring[bd_idx];
821 pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_bd),
822 BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
823 if (--nbd)
824 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
825 }
826
827 /* release skb */
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700828 WARN_ON(!skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200829 dev_kfree_skb(skb);
830 tx_buf->first_bd = 0;
831 tx_buf->skb = NULL;
832
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700833 return new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200834}
835
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700836static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200837{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700838 s16 used;
839 u16 prod;
840 u16 cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200841
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700842 barrier(); /* Tell compiler that prod and cons can change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200843 prod = fp->tx_bd_prod;
844 cons = fp->tx_bd_cons;
845
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700846 /* NUM_TX_RINGS = number of "next-page" entries
847 It will be used as a threshold */
848 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200849
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700850#ifdef BNX2X_STOP_ON_ERROR
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700851 WARN_ON(used < 0);
852 WARN_ON(used > fp->bp->tx_ring_size);
853 WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700854#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200855
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700856 return (s16)(fp->bp->tx_ring_size) - used;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200857}
858
859static void bnx2x_tx_int(struct bnx2x_fastpath *fp, int work)
860{
861 struct bnx2x *bp = fp->bp;
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000862 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200863 u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
864 int done = 0;
865
866#ifdef BNX2X_STOP_ON_ERROR
867 if (unlikely(bp->panic))
868 return;
869#endif
870
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000871 txq = netdev_get_tx_queue(bp->dev, fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200872 hw_cons = le16_to_cpu(*fp->tx_cons_sb);
873 sw_cons = fp->tx_pkt_cons;
874
875 while (sw_cons != hw_cons) {
876 u16 pkt_cons;
877
878 pkt_cons = TX_BD(sw_cons);
879
880 /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
881
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700882 DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200883 hw_cons, sw_cons, pkt_cons);
884
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700885/* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200886 rmb();
887 prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
888 }
889*/
890 bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
891 sw_cons++;
892 done++;
893
894 if (done == work)
895 break;
896 }
897
898 fp->tx_pkt_cons = sw_cons;
899 fp->tx_bd_cons = bd_cons;
900
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000901 /* Need to make the tx_bd_cons update visible to start_xmit()
902 * before checking for netif_tx_queue_stopped(). Without the
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200903 * memory barrier, there is a small possibility that start_xmit()
904 * will miss it and cause the queue to be stopped forever.
905 */
906 smp_mb();
907
908 /* TBD need a thresh? */
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000909 if (unlikely(netif_tx_queue_stopped(txq))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200910
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000911 __netif_tx_lock(txq, smp_processor_id());
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200912
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000913 if ((netif_tx_queue_stopped(txq)) &&
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -0700914 (bp->state == BNX2X_STATE_OPEN) &&
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200915 (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000916 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200917
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000918 __netif_tx_unlock(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200919 }
920}
921
Eilon Greenstein3196a882008-08-13 15:58:49 -0700922
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200923static void bnx2x_sp_event(struct bnx2x_fastpath *fp,
924 union eth_rx_cqe *rr_cqe)
925{
926 struct bnx2x *bp = fp->bp;
927 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
928 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
929
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700930 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200931 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700932 FP_IDX(fp), cid, command, bp->state,
933 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200934
935 bp->spq_left++;
936
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700937 if (FP_IDX(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200938 switch (command | fp->state) {
939 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
940 BNX2X_FP_STATE_OPENING):
941 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
942 cid);
943 fp->state = BNX2X_FP_STATE_OPEN;
944 break;
945
946 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
947 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
948 cid);
949 fp->state = BNX2X_FP_STATE_HALTED;
950 break;
951
952 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700953 BNX2X_ERR("unexpected MC reply (%d) "
954 "fp->state is %x\n", command, fp->state);
955 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200956 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700957 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200958 return;
959 }
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800960
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200961 switch (command | bp->state) {
962 case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
963 DP(NETIF_MSG_IFUP, "got setup ramrod\n");
964 bp->state = BNX2X_STATE_OPEN;
965 break;
966
967 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
968 DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
969 bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
970 fp->state = BNX2X_FP_STATE_HALTED;
971 break;
972
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200973 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700974 DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800975 bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200976 break;
977
Eilon Greenstein3196a882008-08-13 15:58:49 -0700978
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200979 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700980 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200981 DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700982 bp->set_mac_pending = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200983 break;
984
Eliezer Tamir49d66772008-02-28 11:53:13 -0800985 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700986 DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
Eliezer Tamir49d66772008-02-28 11:53:13 -0800987 break;
988
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200989 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700990 BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200991 command, bp->state);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700992 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200993 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700994 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200995}
996
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700997static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
998 struct bnx2x_fastpath *fp, u16 index)
999{
1000 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1001 struct page *page = sw_buf->page;
1002 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1003
1004 /* Skip "next page" elements */
1005 if (!page)
1006 return;
1007
1008 pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001009 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001010 __free_pages(page, PAGES_PER_SGE_SHIFT);
1011
1012 sw_buf->page = NULL;
1013 sge->addr_hi = 0;
1014 sge->addr_lo = 0;
1015}
1016
1017static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
1018 struct bnx2x_fastpath *fp, int last)
1019{
1020 int i;
1021
1022 for (i = 0; i < last; i++)
1023 bnx2x_free_rx_sge(bp, fp, i);
1024}
1025
1026static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
1027 struct bnx2x_fastpath *fp, u16 index)
1028{
1029 struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
1030 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1031 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1032 dma_addr_t mapping;
1033
1034 if (unlikely(page == NULL))
1035 return -ENOMEM;
1036
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001037 mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001038 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001039 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001040 __free_pages(page, PAGES_PER_SGE_SHIFT);
1041 return -ENOMEM;
1042 }
1043
1044 sw_buf->page = page;
1045 pci_unmap_addr_set(sw_buf, mapping, mapping);
1046
1047 sge->addr_hi = cpu_to_le32(U64_HI(mapping));
1048 sge->addr_lo = cpu_to_le32(U64_LO(mapping));
1049
1050 return 0;
1051}
1052
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001053static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
1054 struct bnx2x_fastpath *fp, u16 index)
1055{
1056 struct sk_buff *skb;
1057 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
1058 struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
1059 dma_addr_t mapping;
1060
1061 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1062 if (unlikely(skb == NULL))
1063 return -ENOMEM;
1064
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001065 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001066 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001067 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001068 dev_kfree_skb(skb);
1069 return -ENOMEM;
1070 }
1071
1072 rx_buf->skb = skb;
1073 pci_unmap_addr_set(rx_buf, mapping, mapping);
1074
1075 rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1076 rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1077
1078 return 0;
1079}
1080
1081/* note that we are not allocating a new skb,
1082 * we are just moving one from cons to prod
1083 * we are not creating a new mapping,
1084 * so there is no need to check for dma_mapping_error().
1085 */
1086static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
1087 struct sk_buff *skb, u16 cons, u16 prod)
1088{
1089 struct bnx2x *bp = fp->bp;
1090 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1091 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1092 struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
1093 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1094
1095 pci_dma_sync_single_for_device(bp->pdev,
1096 pci_unmap_addr(cons_rx_buf, mapping),
Eilon Greenstein87942b42009-02-12 08:36:49 +00001097 RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001098
1099 prod_rx_buf->skb = cons_rx_buf->skb;
1100 pci_unmap_addr_set(prod_rx_buf, mapping,
1101 pci_unmap_addr(cons_rx_buf, mapping));
1102 *prod_bd = *cons_bd;
1103}
1104
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001105static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
1106 u16 idx)
1107{
1108 u16 last_max = fp->last_max_sge;
1109
1110 if (SUB_S16(idx, last_max) > 0)
1111 fp->last_max_sge = idx;
1112}
1113
1114static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
1115{
1116 int i, j;
1117
1118 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
1119 int idx = RX_SGE_CNT * i - 1;
1120
1121 for (j = 0; j < 2; j++) {
1122 SGE_MASK_CLEAR_BIT(fp, idx);
1123 idx--;
1124 }
1125 }
1126}
1127
1128static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
1129 struct eth_fast_path_rx_cqe *fp_cqe)
1130{
1131 struct bnx2x *bp = fp->bp;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001132 u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001133 le16_to_cpu(fp_cqe->len_on_bd)) >>
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001134 SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001135 u16 last_max, last_elem, first_elem;
1136 u16 delta = 0;
1137 u16 i;
1138
1139 if (!sge_len)
1140 return;
1141
1142 /* First mark all used pages */
1143 for (i = 0; i < sge_len; i++)
1144 SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i])));
1145
1146 DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
1147 sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1148
1149 /* Here we assume that the last SGE index is the biggest */
1150 prefetch((void *)(fp->sge_mask));
1151 bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1152
1153 last_max = RX_SGE(fp->last_max_sge);
1154 last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
1155 first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
1156
1157 /* If ring is not full */
1158 if (last_elem + 1 != first_elem)
1159 last_elem++;
1160
1161 /* Now update the prod */
1162 for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
1163 if (likely(fp->sge_mask[i]))
1164 break;
1165
1166 fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
1167 delta += RX_SGE_MASK_ELEM_SZ;
1168 }
1169
1170 if (delta > 0) {
1171 fp->rx_sge_prod += delta;
1172 /* clear page-end entries */
1173 bnx2x_clear_sge_mask_next_elems(fp);
1174 }
1175
1176 DP(NETIF_MSG_RX_STATUS,
1177 "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
1178 fp->last_max_sge, fp->rx_sge_prod);
1179}
1180
1181static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
1182{
1183 /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
1184 memset(fp->sge_mask, 0xff,
1185 (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
1186
Eilon Greenstein33471622008-08-13 15:59:08 -07001187 /* Clear the two last indices in the page to 1:
1188 these are the indices that correspond to the "next" element,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001189 hence will never be indicated and should be removed from
1190 the calculations. */
1191 bnx2x_clear_sge_mask_next_elems(fp);
1192}
1193
1194static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
1195 struct sk_buff *skb, u16 cons, u16 prod)
1196{
1197 struct bnx2x *bp = fp->bp;
1198 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1199 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1200 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1201 dma_addr_t mapping;
1202
1203 /* move empty skb from pool to prod and map it */
1204 prod_rx_buf->skb = fp->tpa_pool[queue].skb;
1205 mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001206 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001207 pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
1208
1209 /* move partial skb from cons to pool (don't unmap yet) */
1210 fp->tpa_pool[queue] = *cons_rx_buf;
1211
1212 /* mark bin state as start - print error if current state != stop */
1213 if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
1214 BNX2X_ERR("start of bin not in stop [%d]\n", queue);
1215
1216 fp->tpa_state[queue] = BNX2X_TPA_START;
1217
1218 /* point prod_bd to new skb */
1219 prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1220 prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1221
1222#ifdef BNX2X_STOP_ON_ERROR
1223 fp->tpa_queue_used |= (1 << queue);
1224#ifdef __powerpc64__
1225 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
1226#else
1227 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
1228#endif
1229 fp->tpa_queue_used);
1230#endif
1231}
1232
1233static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1234 struct sk_buff *skb,
1235 struct eth_fast_path_rx_cqe *fp_cqe,
1236 u16 cqe_idx)
1237{
1238 struct sw_rx_page *rx_pg, old_rx_pg;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001239 u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
1240 u32 i, frag_len, frag_size, pages;
1241 int err;
1242 int j;
1243
1244 frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001245 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001246
1247 /* This is needed in order to enable forwarding support */
1248 if (frag_size)
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001249 skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001250 max(frag_size, (u32)len_on_bd));
1251
1252#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001253 if (pages >
1254 min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001255 BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
1256 pages, cqe_idx);
1257 BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
1258 fp_cqe->pkt_len, len_on_bd);
1259 bnx2x_panic();
1260 return -EINVAL;
1261 }
1262#endif
1263
1264 /* Run through the SGL and compose the fragmented skb */
1265 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
1266 u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j]));
1267
1268 /* FW gives the indices of the SGE as if the ring is an array
1269 (meaning that "next" element will consume 2 indices) */
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001270 frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001271 rx_pg = &fp->rx_page_ring[sge_idx];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001272 old_rx_pg = *rx_pg;
1273
1274 /* If we fail to allocate a substitute page, we simply stop
1275 where we are and drop the whole packet */
1276 err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
1277 if (unlikely(err)) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00001278 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001279 return err;
1280 }
1281
1282 /* Unmap the page as we r going to pass it to the stack */
1283 pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001284 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001285
1286 /* Add one frag and update the appropriate fields in the skb */
1287 skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
1288
1289 skb->data_len += frag_len;
1290 skb->truesize += frag_len;
1291 skb->len += frag_len;
1292
1293 frag_size -= frag_len;
1294 }
1295
1296 return 0;
1297}
1298
1299static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1300 u16 queue, int pad, int len, union eth_rx_cqe *cqe,
1301 u16 cqe_idx)
1302{
1303 struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
1304 struct sk_buff *skb = rx_buf->skb;
1305 /* alloc new skb */
1306 struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1307
1308 /* Unmap skb in the pool anyway, as we are going to change
1309 pool entry status to BNX2X_TPA_STOP even if new skb allocation
1310 fails. */
1311 pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001312 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001313
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001314 if (likely(new_skb)) {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001315 /* fix ip xsum and give it to the stack */
1316 /* (no need to map the new skb) */
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001317#ifdef BCM_VLAN
1318 int is_vlan_cqe =
1319 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1320 PARSING_FLAGS_VLAN);
1321 int is_not_hwaccel_vlan_cqe =
1322 (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG)));
1323#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001324
1325 prefetch(skb);
1326 prefetch(((char *)(skb)) + 128);
1327
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001328#ifdef BNX2X_STOP_ON_ERROR
1329 if (pad + len > bp->rx_buf_size) {
1330 BNX2X_ERR("skb_put is about to fail... "
1331 "pad %d len %d rx_buf_size %d\n",
1332 pad, len, bp->rx_buf_size);
1333 bnx2x_panic();
1334 return;
1335 }
1336#endif
1337
1338 skb_reserve(skb, pad);
1339 skb_put(skb, len);
1340
1341 skb->protocol = eth_type_trans(skb, bp->dev);
1342 skb->ip_summed = CHECKSUM_UNNECESSARY;
1343
1344 {
1345 struct iphdr *iph;
1346
1347 iph = (struct iphdr *)skb->data;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001348#ifdef BCM_VLAN
1349 /* If there is no Rx VLAN offloading -
1350 take VLAN tag into an account */
1351 if (unlikely(is_not_hwaccel_vlan_cqe))
1352 iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN);
1353#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001354 iph->check = 0;
1355 iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
1356 }
1357
1358 if (!bnx2x_fill_frag_skb(bp, fp, skb,
1359 &cqe->fast_path_cqe, cqe_idx)) {
1360#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001361 if ((bp->vlgrp != NULL) && is_vlan_cqe &&
1362 (!is_not_hwaccel_vlan_cqe))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001363 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1364 le16_to_cpu(cqe->fast_path_cqe.
1365 vlan_tag));
1366 else
1367#endif
1368 netif_receive_skb(skb);
1369 } else {
1370 DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
1371 " - dropping packet!\n");
1372 dev_kfree_skb(skb);
1373 }
1374
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001375
1376 /* put new skb in bin */
1377 fp->tpa_pool[queue].skb = new_skb;
1378
1379 } else {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001380 /* else drop the packet and keep the buffer in the bin */
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001381 DP(NETIF_MSG_RX_STATUS,
1382 "Failed to allocate new skb - dropping packet!\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001383 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001384 }
1385
1386 fp->tpa_state[queue] = BNX2X_TPA_STOP;
1387}
1388
1389static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
1390 struct bnx2x_fastpath *fp,
1391 u16 bd_prod, u16 rx_comp_prod,
1392 u16 rx_sge_prod)
1393{
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001394 struct ustorm_eth_rx_producers rx_prods = {0};
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001395 int i;
1396
1397 /* Update producers */
1398 rx_prods.bd_prod = bd_prod;
1399 rx_prods.cqe_prod = rx_comp_prod;
1400 rx_prods.sge_prod = rx_sge_prod;
1401
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001402 /*
1403 * Make sure that the BD and SGE data is updated before updating the
1404 * producers since FW might read the BD/SGE right after the producer
1405 * is updated.
1406 * This is only applicable for weak-ordered memory model archs such
1407 * as IA-64. The following barrier is also mandatory since FW will
1408 * assumes BDs must have buffers.
1409 */
1410 wmb();
1411
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001412 for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
1413 REG_WR(bp, BAR_USTRORM_INTMEM +
1414 USTORM_RX_PRODS_OFFSET(BP_PORT(bp), FP_CL_ID(fp)) + i*4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001415 ((u32 *)&rx_prods)[i]);
1416
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001417 mmiowb(); /* keep prod updates ordered */
1418
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001419 DP(NETIF_MSG_RX_STATUS,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001420 "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
1421 fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001422}
1423
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001424static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
1425{
1426 struct bnx2x *bp = fp->bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001427 u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001428 u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
1429 int rx_pkt = 0;
1430
1431#ifdef BNX2X_STOP_ON_ERROR
1432 if (unlikely(bp->panic))
1433 return 0;
1434#endif
1435
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001436 /* CQ "next element" is of the size of the regular element,
1437 that's why it's ok here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001438 hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
1439 if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
1440 hw_comp_cons++;
1441
1442 bd_cons = fp->rx_bd_cons;
1443 bd_prod = fp->rx_bd_prod;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001444 bd_prod_fw = bd_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001445 sw_comp_cons = fp->rx_comp_cons;
1446 sw_comp_prod = fp->rx_comp_prod;
1447
1448 /* Memory barrier necessary as speculative reads of the rx
1449 * buffer can be ahead of the index in the status block
1450 */
1451 rmb();
1452
1453 DP(NETIF_MSG_RX_STATUS,
1454 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001455 FP_IDX(fp), hw_comp_cons, sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001456
1457 while (sw_comp_cons != hw_comp_cons) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001458 struct sw_rx_bd *rx_buf = NULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001459 struct sk_buff *skb;
1460 union eth_rx_cqe *cqe;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001461 u8 cqe_fp_flags;
1462 u16 len, pad;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001463
1464 comp_ring_cons = RCQ_BD(sw_comp_cons);
1465 bd_prod = RX_BD(bd_prod);
1466 bd_cons = RX_BD(bd_cons);
1467
1468 cqe = &fp->rx_comp_ring[comp_ring_cons];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001469 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001470
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001471 DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001472 " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
1473 cqe_fp_flags, cqe->fast_path_cqe.status_flags,
Eilon Greenstein68d59482009-01-14 21:27:36 -08001474 le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001475 le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
1476 le16_to_cpu(cqe->fast_path_cqe.pkt_len));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001477
1478 /* is this a slowpath msg? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001479 if (unlikely(CQE_TYPE(cqe_fp_flags))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001480 bnx2x_sp_event(fp, cqe);
1481 goto next_cqe;
1482
1483 /* this is an rx packet */
1484 } else {
1485 rx_buf = &fp->rx_buf_ring[bd_cons];
1486 skb = rx_buf->skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001487 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
1488 pad = cqe->fast_path_cqe.placement_offset;
1489
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001490 /* If CQE is marked both TPA_START and TPA_END
1491 it is a non-TPA CQE */
1492 if ((!fp->disable_tpa) &&
1493 (TPA_TYPE(cqe_fp_flags) !=
1494 (TPA_TYPE_START | TPA_TYPE_END))) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07001495 u16 queue = cqe->fast_path_cqe.queue_index;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001496
1497 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
1498 DP(NETIF_MSG_RX_STATUS,
1499 "calling tpa_start on queue %d\n",
1500 queue);
1501
1502 bnx2x_tpa_start(fp, queue, skb,
1503 bd_cons, bd_prod);
1504 goto next_rx;
1505 }
1506
1507 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) {
1508 DP(NETIF_MSG_RX_STATUS,
1509 "calling tpa_stop on queue %d\n",
1510 queue);
1511
1512 if (!BNX2X_RX_SUM_FIX(cqe))
1513 BNX2X_ERR("STOP on none TCP "
1514 "data\n");
1515
1516 /* This is a size of the linear data
1517 on this skb */
1518 len = le16_to_cpu(cqe->fast_path_cqe.
1519 len_on_bd);
1520 bnx2x_tpa_stop(bp, fp, queue, pad,
1521 len, cqe, comp_ring_cons);
1522#ifdef BNX2X_STOP_ON_ERROR
1523 if (bp->panic)
1524 return -EINVAL;
1525#endif
1526
1527 bnx2x_update_sge_prod(fp,
1528 &cqe->fast_path_cqe);
1529 goto next_cqe;
1530 }
1531 }
1532
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001533 pci_dma_sync_single_for_device(bp->pdev,
1534 pci_unmap_addr(rx_buf, mapping),
1535 pad + RX_COPY_THRESH,
1536 PCI_DMA_FROMDEVICE);
1537 prefetch(skb);
1538 prefetch(((char *)(skb)) + 128);
1539
1540 /* is this an error packet? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001541 if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001542 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001543 "ERROR flags %x rx packet %u\n",
1544 cqe_fp_flags, sw_comp_cons);
Eilon Greensteinde832a52009-02-12 08:36:33 +00001545 fp->eth_q_stats.rx_err_discard_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001546 goto reuse_rx;
1547 }
1548
1549 /* Since we don't have a jumbo ring
1550 * copy small packets if mtu > 1500
1551 */
1552 if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
1553 (len <= RX_COPY_THRESH)) {
1554 struct sk_buff *new_skb;
1555
1556 new_skb = netdev_alloc_skb(bp->dev,
1557 len + pad);
1558 if (new_skb == NULL) {
1559 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001560 "ERROR packet dropped "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001561 "because of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001562 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001563 goto reuse_rx;
1564 }
1565
1566 /* aligned copy */
1567 skb_copy_from_linear_data_offset(skb, pad,
1568 new_skb->data + pad, len);
1569 skb_reserve(new_skb, pad);
1570 skb_put(new_skb, len);
1571
1572 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1573
1574 skb = new_skb;
1575
1576 } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) {
1577 pci_unmap_single(bp->pdev,
1578 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001579 bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001580 PCI_DMA_FROMDEVICE);
1581 skb_reserve(skb, pad);
1582 skb_put(skb, len);
1583
1584 } else {
1585 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001586 "ERROR packet dropped because "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001587 "of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001588 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001589reuse_rx:
1590 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1591 goto next_rx;
1592 }
1593
1594 skb->protocol = eth_type_trans(skb, bp->dev);
1595
1596 skb->ip_summed = CHECKSUM_NONE;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001597 if (bp->rx_csum) {
Eilon Greenstein1adcd8b2008-08-13 15:48:29 -07001598 if (likely(BNX2X_RX_CSUM_OK(cqe)))
1599 skb->ip_summed = CHECKSUM_UNNECESSARY;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001600 else
Eilon Greensteinde832a52009-02-12 08:36:33 +00001601 fp->eth_q_stats.hw_csum_err++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001602 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001603 }
1604
Eilon Greenstein748e5432009-02-12 08:36:37 +00001605 skb_record_rx_queue(skb, fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001606#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001607 if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001608 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1609 PARSING_FLAGS_VLAN))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001610 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1611 le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
1612 else
1613#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001614 netif_receive_skb(skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001615
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001616
1617next_rx:
1618 rx_buf->skb = NULL;
1619
1620 bd_cons = NEXT_RX_IDX(bd_cons);
1621 bd_prod = NEXT_RX_IDX(bd_prod);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001622 bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
1623 rx_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001624next_cqe:
1625 sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
1626 sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001627
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001628 if (rx_pkt == budget)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001629 break;
1630 } /* while */
1631
1632 fp->rx_bd_cons = bd_cons;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001633 fp->rx_bd_prod = bd_prod_fw;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001634 fp->rx_comp_cons = sw_comp_cons;
1635 fp->rx_comp_prod = sw_comp_prod;
1636
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001637 /* Update producers */
1638 bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
1639 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001640
1641 fp->rx_pkt += rx_pkt;
1642 fp->rx_calls++;
1643
1644 return rx_pkt;
1645}
1646
1647static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
1648{
1649 struct bnx2x_fastpath *fp = fp_cookie;
1650 struct bnx2x *bp = fp->bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001651 int index = FP_IDX(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001652
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07001653 /* Return here if interrupt is disabled */
1654 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1655 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1656 return IRQ_HANDLED;
1657 }
1658
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001659 DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n",
1660 index, FP_SB_ID(fp));
1661 bnx2x_ack_sb(bp, FP_SB_ID(fp), USTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001662
1663#ifdef BNX2X_STOP_ON_ERROR
1664 if (unlikely(bp->panic))
1665 return IRQ_HANDLED;
1666#endif
1667
1668 prefetch(fp->rx_cons_sb);
1669 prefetch(fp->tx_cons_sb);
1670 prefetch(&fp->status_blk->c_status_block.status_block_index);
1671 prefetch(&fp->status_blk->u_status_block.status_block_index);
1672
Ben Hutchings288379f2009-01-19 16:43:59 -08001673 napi_schedule(&bnx2x_fp(bp, index, napi));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001674
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001675 return IRQ_HANDLED;
1676}
1677
1678static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1679{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001680 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001681 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001682 u16 mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001683
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001684 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001685 if (unlikely(status == 0)) {
1686 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1687 return IRQ_NONE;
1688 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001689 DP(NETIF_MSG_INTR, "got an interrupt status %u\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001690
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001691 /* Return here if interrupt is disabled */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001692 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1693 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1694 return IRQ_HANDLED;
1695 }
1696
Eilon Greenstein3196a882008-08-13 15:58:49 -07001697#ifdef BNX2X_STOP_ON_ERROR
1698 if (unlikely(bp->panic))
1699 return IRQ_HANDLED;
1700#endif
1701
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001702 mask = 0x2 << bp->fp[0].sb_id;
1703 if (status & mask) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001704 struct bnx2x_fastpath *fp = &bp->fp[0];
1705
1706 prefetch(fp->rx_cons_sb);
1707 prefetch(fp->tx_cons_sb);
1708 prefetch(&fp->status_blk->c_status_block.status_block_index);
1709 prefetch(&fp->status_blk->u_status_block.status_block_index);
1710
Ben Hutchings288379f2009-01-19 16:43:59 -08001711 napi_schedule(&bnx2x_fp(bp, 0, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001712
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001713 status &= ~mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001714 }
1715
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001716
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001717 if (unlikely(status & 0x1)) {
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001718 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001719
1720 status &= ~0x1;
1721 if (!status)
1722 return IRQ_HANDLED;
1723 }
1724
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001725 if (status)
1726 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n",
1727 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001728
1729 return IRQ_HANDLED;
1730}
1731
1732/* end of fast path */
1733
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001734static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001735
1736/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001737
1738/*
1739 * General service functions
1740 */
1741
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001742static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001743{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001744 u32 lock_status;
1745 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001746 int func = BP_FUNC(bp);
1747 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001748 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001749
1750 /* Validating that the resource is within range */
1751 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1752 DP(NETIF_MSG_HW,
1753 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1754 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1755 return -EINVAL;
1756 }
1757
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001758 if (func <= 5) {
1759 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1760 } else {
1761 hw_lock_control_reg =
1762 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1763 }
1764
Eliezer Tamirf1410642008-02-28 11:51:50 -08001765 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001766 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001767 if (lock_status & resource_bit) {
1768 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1769 lock_status, resource_bit);
1770 return -EEXIST;
1771 }
1772
Eilon Greenstein46230472008-08-25 15:23:30 -07001773 /* Try for 5 second every 5ms */
1774 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001775 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001776 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1777 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001778 if (lock_status & resource_bit)
1779 return 0;
1780
1781 msleep(5);
1782 }
1783 DP(NETIF_MSG_HW, "Timeout\n");
1784 return -EAGAIN;
1785}
1786
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001787static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001788{
1789 u32 lock_status;
1790 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001791 int func = BP_FUNC(bp);
1792 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001793
1794 /* Validating that the resource is within range */
1795 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1796 DP(NETIF_MSG_HW,
1797 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1798 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1799 return -EINVAL;
1800 }
1801
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001802 if (func <= 5) {
1803 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1804 } else {
1805 hw_lock_control_reg =
1806 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1807 }
1808
Eliezer Tamirf1410642008-02-28 11:51:50 -08001809 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001810 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001811 if (!(lock_status & resource_bit)) {
1812 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1813 lock_status, resource_bit);
1814 return -EFAULT;
1815 }
1816
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001817 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001818 return 0;
1819}
1820
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001821/* HW Lock for shared dual port PHYs */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001822static void bnx2x_acquire_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001823{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001824 mutex_lock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001825
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001826 if (bp->port.need_hw_lock)
1827 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001828}
1829
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001830static void bnx2x_release_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001831{
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001832 if (bp->port.need_hw_lock)
1833 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001834
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001835 mutex_unlock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001836}
1837
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001838int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1839{
1840 /* The GPIO should be swapped if swap register is set and active */
1841 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1842 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1843 int gpio_shift = gpio_num +
1844 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1845 u32 gpio_mask = (1 << gpio_shift);
1846 u32 gpio_reg;
1847 int value;
1848
1849 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1850 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1851 return -EINVAL;
1852 }
1853
1854 /* read GPIO value */
1855 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1856
1857 /* get the requested pin value */
1858 if ((gpio_reg & gpio_mask) == gpio_mask)
1859 value = 1;
1860 else
1861 value = 0;
1862
1863 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1864
1865 return value;
1866}
1867
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001868int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001869{
1870 /* The GPIO should be swapped if swap register is set and active */
1871 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001872 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001873 int gpio_shift = gpio_num +
1874 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1875 u32 gpio_mask = (1 << gpio_shift);
1876 u32 gpio_reg;
1877
1878 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1879 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1880 return -EINVAL;
1881 }
1882
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001883 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001884 /* read GPIO and mask except the float bits */
1885 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1886
1887 switch (mode) {
1888 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1889 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1890 gpio_num, gpio_shift);
1891 /* clear FLOAT and set CLR */
1892 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1893 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1894 break;
1895
1896 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1897 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1898 gpio_num, gpio_shift);
1899 /* clear FLOAT and set SET */
1900 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1901 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1902 break;
1903
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001904 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001905 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1906 gpio_num, gpio_shift);
1907 /* set FLOAT */
1908 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1909 break;
1910
1911 default:
1912 break;
1913 }
1914
1915 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001916 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001917
1918 return 0;
1919}
1920
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001921int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1922{
1923 /* The GPIO should be swapped if swap register is set and active */
1924 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1925 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1926 int gpio_shift = gpio_num +
1927 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1928 u32 gpio_mask = (1 << gpio_shift);
1929 u32 gpio_reg;
1930
1931 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1932 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1933 return -EINVAL;
1934 }
1935
1936 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1937 /* read GPIO int */
1938 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1939
1940 switch (mode) {
1941 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1942 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
1943 "output low\n", gpio_num, gpio_shift);
1944 /* clear SET and set CLR */
1945 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1946 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1947 break;
1948
1949 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1950 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
1951 "output high\n", gpio_num, gpio_shift);
1952 /* clear CLR and set SET */
1953 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1954 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1955 break;
1956
1957 default:
1958 break;
1959 }
1960
1961 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1962 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1963
1964 return 0;
1965}
1966
Eliezer Tamirf1410642008-02-28 11:51:50 -08001967static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
1968{
1969 u32 spio_mask = (1 << spio_num);
1970 u32 spio_reg;
1971
1972 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
1973 (spio_num > MISC_REGISTERS_SPIO_7)) {
1974 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
1975 return -EINVAL;
1976 }
1977
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001978 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001979 /* read SPIO and mask except the float bits */
1980 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
1981
1982 switch (mode) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07001983 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001984 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
1985 /* clear FLOAT and set CLR */
1986 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
1987 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
1988 break;
1989
Eilon Greenstein6378c022008-08-13 15:59:25 -07001990 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001991 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
1992 /* clear FLOAT and set SET */
1993 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
1994 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
1995 break;
1996
1997 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
1998 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
1999 /* set FLOAT */
2000 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2001 break;
2002
2003 default:
2004 break;
2005 }
2006
2007 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002008 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002009
2010 return 0;
2011}
2012
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002013static void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002014{
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002015 switch (bp->link_vars.ieee_fc &
2016 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002017 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002018 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002019 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002020 break;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002021 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002022 bp->port.advertising |= (ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002023 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002024 break;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002025 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002026 bp->port.advertising |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002027 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002028 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002029 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002030 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002031 break;
2032 }
2033}
2034
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002035static void bnx2x_link_report(struct bnx2x *bp)
2036{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002037 if (bp->link_vars.link_up) {
2038 if (bp->state == BNX2X_STATE_OPEN)
2039 netif_carrier_on(bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002040 printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
2041
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002042 printk("%d Mbps ", bp->link_vars.line_speed);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002043
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002044 if (bp->link_vars.duplex == DUPLEX_FULL)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002045 printk("full duplex");
2046 else
2047 printk("half duplex");
2048
David S. Millerc0700f92008-12-16 23:53:20 -08002049 if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) {
2050 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002051 printk(", receive ");
David S. Millerc0700f92008-12-16 23:53:20 -08002052 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002053 printk("& transmit ");
2054 } else {
2055 printk(", transmit ");
2056 }
2057 printk("flow control ON");
2058 }
2059 printk("\n");
2060
2061 } else { /* link_down */
2062 netif_carrier_off(bp->dev);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002063 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002064 }
2065}
2066
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002067static u8 bnx2x_initial_phy_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002068{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002069 if (!BP_NOMCP(bp)) {
2070 u8 rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002071
Eilon Greenstein19680c42008-08-13 15:47:33 -07002072 /* Initialize link parameters structure variables */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002073 /* It is recommended to turn off RX FC for jumbo frames
2074 for better performance */
2075 if (IS_E1HMF(bp))
David S. Millerc0700f92008-12-16 23:53:20 -08002076 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002077 else if (bp->dev->mtu > 5000)
David S. Millerc0700f92008-12-16 23:53:20 -08002078 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002079 else
David S. Millerc0700f92008-12-16 23:53:20 -08002080 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002081
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002082 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002083 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002084 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002085
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002086 bnx2x_calc_fc_adv(bp);
2087
Eilon Greenstein19680c42008-08-13 15:47:33 -07002088 if (bp->link_vars.link_up)
2089 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002090
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002091
Eilon Greenstein19680c42008-08-13 15:47:33 -07002092 return rc;
2093 }
2094 BNX2X_ERR("Bootcode is missing -not initializing link\n");
2095 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002096}
2097
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002098static void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002099{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002100 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002101 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002102 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002103 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002104
Eilon Greenstein19680c42008-08-13 15:47:33 -07002105 bnx2x_calc_fc_adv(bp);
2106 } else
2107 BNX2X_ERR("Bootcode is missing -not setting link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002108}
2109
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002110static void bnx2x__link_reset(struct bnx2x *bp)
2111{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002112 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002113 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002114 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002115 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002116 } else
2117 BNX2X_ERR("Bootcode is missing -not resetting link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002118}
2119
2120static u8 bnx2x_link_test(struct bnx2x *bp)
2121{
2122 u8 rc;
2123
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002124 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002125 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002126 bnx2x_release_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002127
2128 return rc;
2129}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002130
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002131static void bnx2x_init_port_minmax(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002132{
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002133 u32 r_param = bp->link_vars.line_speed / 8;
2134 u32 fair_periodic_timeout_usec;
2135 u32 t_fair;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002136
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002137 memset(&(bp->cmng.rs_vars), 0,
2138 sizeof(struct rate_shaping_vars_per_port));
2139 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002140
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002141 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2142 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002143
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002144 /* this is the threshold below which no timer arming will occur
2145 1.25 coefficient is for the threshold to be a little bigger
2146 than the real time, to compensate for timer in-accuracy */
2147 bp->cmng.rs_vars.rs_threshold =
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002148 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2149
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002150 /* resolution of fairness timer */
2151 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2152 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2153 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002154
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002155 /* this is the threshold below which we won't arm the timer anymore */
2156 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002157
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002158 /* we multiply by 1e3/8 to get bytes/msec.
2159 We don't want the credits to pass a credit
2160 of the t_fair*FAIR_MEM (algorithm resolution) */
2161 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2162 /* since each tick is 4 usec */
2163 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002164}
2165
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002166static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002167{
2168 struct rate_shaping_vars_per_vn m_rs_vn;
2169 struct fairness_vars_per_vn m_fair_vn;
2170 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
2171 u16 vn_min_rate, vn_max_rate;
2172 int i;
2173
2174 /* If function is hidden - set min and max to zeroes */
2175 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2176 vn_min_rate = 0;
2177 vn_max_rate = 0;
2178
2179 } else {
2180 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2181 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002182 /* If fairness is enabled (not all min rates are zeroes) and
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002183 if current min rate is zero - set it to 1.
Eilon Greenstein33471622008-08-13 15:59:08 -07002184 This is a requirement of the algorithm. */
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002185 if (bp->vn_weight_sum && (vn_min_rate == 0))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002186 vn_min_rate = DEF_MIN_RATE;
2187 vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
2188 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
2189 }
2190
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002191 DP(NETIF_MSG_IFUP,
2192 "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n",
2193 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002194
2195 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2196 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2197
2198 /* global vn counter - maximal Mbps for this vn */
2199 m_rs_vn.vn_counter.rate = vn_max_rate;
2200
2201 /* quota - number of bytes transmitted in this period */
2202 m_rs_vn.vn_counter.quota =
2203 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2204
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002205 if (bp->vn_weight_sum) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002206 /* credit for each period of the fairness algorithm:
2207 number of bytes in T_FAIR (the vn share the port rate).
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002208 vn_weight_sum should not be larger than 10000, thus
2209 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2210 than zero */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002211 m_fair_vn.vn_credit_delta =
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002212 max((u32)(vn_min_rate * (T_FAIR_COEF /
2213 (8 * bp->vn_weight_sum))),
2214 (u32)(bp->cmng.fair_vars.fair_threshold * 2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002215 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n",
2216 m_fair_vn.vn_credit_delta);
2217 }
2218
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002219 /* Store it to internal memory */
2220 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2221 REG_WR(bp, BAR_XSTRORM_INTMEM +
2222 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2223 ((u32 *)(&m_rs_vn))[i]);
2224
2225 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2226 REG_WR(bp, BAR_XSTRORM_INTMEM +
2227 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2228 ((u32 *)(&m_fair_vn))[i]);
2229}
2230
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002231
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002232/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002233static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002234{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002235 /* Make sure that we are synced with the current statistics */
2236 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2237
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002238 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002239
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002240 if (bp->link_vars.link_up) {
2241
Eilon Greenstein1c063282009-02-12 08:36:43 +00002242 /* dropless flow control */
2243 if (CHIP_IS_E1H(bp)) {
2244 int port = BP_PORT(bp);
2245 u32 pause_enabled = 0;
2246
2247 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2248 pause_enabled = 1;
2249
2250 REG_WR(bp, BAR_USTRORM_INTMEM +
2251 USTORM_PAUSE_ENABLED_OFFSET(port),
2252 pause_enabled);
2253 }
2254
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002255 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
2256 struct host_port_stats *pstats;
2257
2258 pstats = bnx2x_sp(bp, port_stats);
2259 /* reset old bmac stats */
2260 memset(&(pstats->mac_stx[0]), 0,
2261 sizeof(struct mac_stx));
2262 }
2263 if ((bp->state == BNX2X_STATE_OPEN) ||
2264 (bp->state == BNX2X_STATE_DISABLED))
2265 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2266 }
2267
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002268 /* indicate link status */
2269 bnx2x_link_report(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002270
2271 if (IS_E1HMF(bp)) {
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002272 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002273 int func;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002274 int vn;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002275
2276 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2277 if (vn == BP_E1HVN(bp))
2278 continue;
2279
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002280 func = ((vn << 1) | port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002281
2282 /* Set the attention towards other drivers
2283 on the same port */
2284 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2285 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2286 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002287
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002288 if (bp->link_vars.link_up) {
2289 int i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002290
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002291 /* Init rate shaping and fairness contexts */
2292 bnx2x_init_port_minmax(bp);
2293
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002294 for (vn = VN_0; vn < E1HVN_MAX; vn++)
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002295 bnx2x_init_vn_minmax(bp, 2*vn + port);
2296
2297 /* Store it to internal memory */
2298 for (i = 0;
2299 i < sizeof(struct cmng_struct_per_port) / 4; i++)
2300 REG_WR(bp, BAR_XSTRORM_INTMEM +
2301 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
2302 ((u32 *)(&bp->cmng))[i]);
2303 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002304 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002305}
2306
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002307static void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002308{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002309 if (bp->state != BNX2X_STATE_OPEN)
2310 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002311
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002312 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2313
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002314 if (bp->link_vars.link_up)
2315 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2316 else
2317 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2318
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002319 /* indicate link status */
2320 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002321}
2322
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002323static void bnx2x_pmf_update(struct bnx2x *bp)
2324{
2325 int port = BP_PORT(bp);
2326 u32 val;
2327
2328 bp->port.pmf = 1;
2329 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2330
2331 /* enable nig attention */
2332 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2333 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2334 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002335
2336 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002337}
2338
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002339/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002340
2341/* slow path */
2342
2343/*
2344 * General service functions
2345 */
2346
2347/* the slow path queue is odd since completions arrive on the fastpath ring */
2348static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
2349 u32 data_hi, u32 data_lo, int common)
2350{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002351 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002352
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002353 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
2354 "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002355 (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) +
2356 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
2357 HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
2358
2359#ifdef BNX2X_STOP_ON_ERROR
2360 if (unlikely(bp->panic))
2361 return -EIO;
2362#endif
2363
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002364 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002365
2366 if (!bp->spq_left) {
2367 BNX2X_ERR("BUG! SPQ ring full!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002368 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002369 bnx2x_panic();
2370 return -EBUSY;
2371 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08002372
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002373 /* CID needs port number to be encoded int it */
2374 bp->spq_prod_bd->hdr.conn_and_cmd_data =
2375 cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) |
2376 HW_CID(bp, cid)));
2377 bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
2378 if (common)
2379 bp->spq_prod_bd->hdr.type |=
2380 cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
2381
2382 bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi);
2383 bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo);
2384
2385 bp->spq_left--;
2386
2387 if (bp->spq_prod_bd == bp->spq_last_bd) {
2388 bp->spq_prod_bd = bp->spq;
2389 bp->spq_prod_idx = 0;
2390 DP(NETIF_MSG_TIMER, "end of spq\n");
2391
2392 } else {
2393 bp->spq_prod_bd++;
2394 bp->spq_prod_idx++;
2395 }
2396
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002397 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002398 bp->spq_prod_idx);
2399
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002400 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002401 return 0;
2402}
2403
2404/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002405static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002406{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002407 u32 i, j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002408 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002409
2410 might_sleep();
2411 i = 100;
2412 for (j = 0; j < i*10; j++) {
2413 val = (1UL << 31);
2414 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2415 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
2416 if (val & (1L << 31))
2417 break;
2418
2419 msleep(5);
2420 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002421 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07002422 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002423 rc = -EBUSY;
2424 }
2425
2426 return rc;
2427}
2428
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002429/* release split MCP access lock register */
2430static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002431{
2432 u32 val = 0;
2433
2434 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2435}
2436
2437static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
2438{
2439 struct host_def_status_block *def_sb = bp->def_status_blk;
2440 u16 rc = 0;
2441
2442 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002443 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
2444 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
2445 rc |= 1;
2446 }
2447 if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
2448 bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
2449 rc |= 2;
2450 }
2451 if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
2452 bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
2453 rc |= 4;
2454 }
2455 if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
2456 bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
2457 rc |= 8;
2458 }
2459 if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
2460 bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
2461 rc |= 16;
2462 }
2463 return rc;
2464}
2465
2466/*
2467 * slow path service functions
2468 */
2469
2470static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
2471{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002472 int port = BP_PORT(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002473 u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
2474 COMMAND_REG_ATTN_BITS_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002475 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2476 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002477 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
2478 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002479 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00002480 u32 nig_mask = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002481
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002482 if (bp->attn_state & asserted)
2483 BNX2X_ERR("IGU ERROR\n");
2484
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002485 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2486 aeu_mask = REG_RD(bp, aeu_addr);
2487
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002488 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002489 aeu_mask, asserted);
2490 aeu_mask &= ~(asserted & 0xff);
2491 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002492
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002493 REG_WR(bp, aeu_addr, aeu_mask);
2494 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002495
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002496 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002497 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002498 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002499
2500 if (asserted & ATTN_HARD_WIRED_MASK) {
2501 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002502
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002503 bnx2x_acquire_phy_lock(bp);
2504
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002505 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00002506 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002507 REG_WR(bp, nig_int_mask_addr, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002508
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002509 bnx2x_link_attn(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002510
2511 /* handle unicore attn? */
2512 }
2513 if (asserted & ATTN_SW_TIMER_4_FUNC)
2514 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
2515
2516 if (asserted & GPIO_2_FUNC)
2517 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
2518
2519 if (asserted & GPIO_3_FUNC)
2520 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
2521
2522 if (asserted & GPIO_4_FUNC)
2523 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
2524
2525 if (port == 0) {
2526 if (asserted & ATTN_GENERAL_ATTN_1) {
2527 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
2528 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
2529 }
2530 if (asserted & ATTN_GENERAL_ATTN_2) {
2531 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
2532 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
2533 }
2534 if (asserted & ATTN_GENERAL_ATTN_3) {
2535 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
2536 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
2537 }
2538 } else {
2539 if (asserted & ATTN_GENERAL_ATTN_4) {
2540 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
2541 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
2542 }
2543 if (asserted & ATTN_GENERAL_ATTN_5) {
2544 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
2545 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
2546 }
2547 if (asserted & ATTN_GENERAL_ATTN_6) {
2548 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
2549 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
2550 }
2551 }
2552
2553 } /* if hardwired */
2554
Eilon Greenstein5c862842008-08-13 15:51:48 -07002555 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2556 asserted, hc_addr);
2557 REG_WR(bp, hc_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002558
2559 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002560 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00002561 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002562 bnx2x_release_phy_lock(bp);
2563 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002564}
2565
2566static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
2567{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002568 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002569 int reg_offset;
2570 u32 val;
2571
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002572 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
2573 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002574
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002575 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002576
2577 val = REG_RD(bp, reg_offset);
2578 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
2579 REG_WR(bp, reg_offset, val);
2580
2581 BNX2X_ERR("SPIO5 hw attention\n");
2582
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00002583 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
2584 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002585 /* Fan failure attention */
2586
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002587 /* The PHY reset is controlled by GPIO 1 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002588 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002589 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
2590 /* Low power mode is controlled by GPIO 2 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002591 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002592 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002593 /* mark the failure */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002594 bp->link_params.ext_phy_config &=
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002595 ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002596 bp->link_params.ext_phy_config |=
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002597 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
2598 SHMEM_WR(bp,
2599 dev_info.port_hw_config[port].
2600 external_phy_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002601 bp->link_params.ext_phy_config);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002602 /* log the failure */
2603 printk(KERN_ERR PFX "Fan Failure on Network"
2604 " Controller %s has caused the driver to"
2605 " shutdown the card to prevent permanent"
2606 " damage. Please contact Dell Support for"
2607 " assistance\n", bp->dev->name);
2608 break;
2609
2610 default:
2611 break;
2612 }
2613 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002614
Eilon Greenstein589abe32009-02-12 08:36:55 +00002615 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
2616 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
2617 bnx2x_acquire_phy_lock(bp);
2618 bnx2x_handle_module_detect_int(&bp->link_params);
2619 bnx2x_release_phy_lock(bp);
2620 }
2621
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002622 if (attn & HW_INTERRUT_ASSERT_SET_0) {
2623
2624 val = REG_RD(bp, reg_offset);
2625 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
2626 REG_WR(bp, reg_offset, val);
2627
2628 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
2629 (attn & HW_INTERRUT_ASSERT_SET_0));
2630 bnx2x_panic();
2631 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002632}
2633
2634static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
2635{
2636 u32 val;
2637
2638 if (attn & BNX2X_DOORQ_ASSERT) {
2639
2640 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
2641 BNX2X_ERR("DB hw attention 0x%x\n", val);
2642 /* DORQ discard attention */
2643 if (val & 0x2)
2644 BNX2X_ERR("FATAL error from DORQ\n");
2645 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002646
2647 if (attn & HW_INTERRUT_ASSERT_SET_1) {
2648
2649 int port = BP_PORT(bp);
2650 int reg_offset;
2651
2652 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
2653 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
2654
2655 val = REG_RD(bp, reg_offset);
2656 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
2657 REG_WR(bp, reg_offset, val);
2658
2659 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
2660 (attn & HW_INTERRUT_ASSERT_SET_1));
2661 bnx2x_panic();
2662 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002663}
2664
2665static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
2666{
2667 u32 val;
2668
2669 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
2670
2671 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
2672 BNX2X_ERR("CFC hw attention 0x%x\n", val);
2673 /* CFC error attention */
2674 if (val & 0x2)
2675 BNX2X_ERR("FATAL error from CFC\n");
2676 }
2677
2678 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
2679
2680 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
2681 BNX2X_ERR("PXP hw attention 0x%x\n", val);
2682 /* RQ_USDMDP_FIFO_OVERFLOW */
2683 if (val & 0x18000)
2684 BNX2X_ERR("FATAL error from PXP\n");
2685 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002686
2687 if (attn & HW_INTERRUT_ASSERT_SET_2) {
2688
2689 int port = BP_PORT(bp);
2690 int reg_offset;
2691
2692 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
2693 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
2694
2695 val = REG_RD(bp, reg_offset);
2696 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
2697 REG_WR(bp, reg_offset, val);
2698
2699 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
2700 (attn & HW_INTERRUT_ASSERT_SET_2));
2701 bnx2x_panic();
2702 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002703}
2704
2705static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
2706{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002707 u32 val;
2708
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002709 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
2710
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002711 if (attn & BNX2X_PMF_LINK_ASSERT) {
2712 int func = BP_FUNC(bp);
2713
2714 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
2715 bnx2x__link_status_update(bp);
2716 if (SHMEM_RD(bp, func_mb[func].drv_status) &
2717 DRV_STATUS_PMF)
2718 bnx2x_pmf_update(bp);
2719
2720 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002721
2722 BNX2X_ERR("MC assert!\n");
2723 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
2724 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
2725 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
2726 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
2727 bnx2x_panic();
2728
2729 } else if (attn & BNX2X_MCP_ASSERT) {
2730
2731 BNX2X_ERR("MCP assert!\n");
2732 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002733 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002734
2735 } else
2736 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
2737 }
2738
2739 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002740 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
2741 if (attn & BNX2X_GRC_TIMEOUT) {
2742 val = CHIP_IS_E1H(bp) ?
2743 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
2744 BNX2X_ERR("GRC time-out 0x%08x\n", val);
2745 }
2746 if (attn & BNX2X_GRC_RSV) {
2747 val = CHIP_IS_E1H(bp) ?
2748 REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
2749 BNX2X_ERR("GRC reserved 0x%08x\n", val);
2750 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002751 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002752 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002753}
2754
2755static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
2756{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002757 struct attn_route attn;
2758 struct attn_route group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002759 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002760 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002761 u32 reg_addr;
2762 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002763 u32 aeu_mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002764
2765 /* need to take HW lock because MCP or other port might also
2766 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002767 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002768
2769 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
2770 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
2771 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
2772 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002773 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
2774 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002775
2776 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
2777 if (deasserted & (1 << index)) {
2778 group_mask = bp->attn_group[index];
2779
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002780 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
2781 index, group_mask.sig[0], group_mask.sig[1],
2782 group_mask.sig[2], group_mask.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002783
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002784 bnx2x_attn_int_deasserted3(bp,
2785 attn.sig[3] & group_mask.sig[3]);
2786 bnx2x_attn_int_deasserted1(bp,
2787 attn.sig[1] & group_mask.sig[1]);
2788 bnx2x_attn_int_deasserted2(bp,
2789 attn.sig[2] & group_mask.sig[2]);
2790 bnx2x_attn_int_deasserted0(bp,
2791 attn.sig[0] & group_mask.sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002792
2793 if ((attn.sig[0] & group_mask.sig[0] &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002794 HW_PRTY_ASSERT_SET_0) ||
2795 (attn.sig[1] & group_mask.sig[1] &
2796 HW_PRTY_ASSERT_SET_1) ||
2797 (attn.sig[2] & group_mask.sig[2] &
2798 HW_PRTY_ASSERT_SET_2))
Eilon Greenstein6378c022008-08-13 15:59:25 -07002799 BNX2X_ERR("FATAL HW block parity attention\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002800 }
2801 }
2802
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002803 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002804
Eilon Greenstein5c862842008-08-13 15:51:48 -07002805 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002806
2807 val = ~deasserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002808 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2809 val, reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002810 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002811
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002812 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002813 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002814
2815 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2816 MISC_REG_AEU_MASK_ATTN_FUNC_0;
2817
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002818 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2819 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002820
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002821 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
2822 aeu_mask, deasserted);
2823 aeu_mask |= (deasserted & 0xff);
2824 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
2825
2826 REG_WR(bp, reg_addr, aeu_mask);
2827 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002828
2829 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
2830 bp->attn_state &= ~deasserted;
2831 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
2832}
2833
2834static void bnx2x_attn_int(struct bnx2x *bp)
2835{
2836 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08002837 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
2838 attn_bits);
2839 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
2840 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002841 u32 attn_state = bp->attn_state;
2842
2843 /* look for changed bits */
2844 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
2845 u32 deasserted = ~attn_bits & attn_ack & attn_state;
2846
2847 DP(NETIF_MSG_HW,
2848 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
2849 attn_bits, attn_ack, asserted, deasserted);
2850
2851 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002852 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002853
2854 /* handle bits that were raised */
2855 if (asserted)
2856 bnx2x_attn_int_asserted(bp, asserted);
2857
2858 if (deasserted)
2859 bnx2x_attn_int_deasserted(bp, deasserted);
2860}
2861
2862static void bnx2x_sp_task(struct work_struct *work)
2863{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002864 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002865 u16 status;
2866
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002867
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002868 /* Return here if interrupt is disabled */
2869 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002870 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002871 return;
2872 }
2873
2874 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002875/* if (status == 0) */
2876/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002877
Eilon Greenstein3196a882008-08-13 15:58:49 -07002878 DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002879
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002880 /* HW attentions */
2881 if (status & 0x1)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002882 bnx2x_attn_int(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002883
Eilon Greenstein68d59482009-01-14 21:27:36 -08002884 bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002885 IGU_INT_NOP, 1);
2886 bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
2887 IGU_INT_NOP, 1);
2888 bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
2889 IGU_INT_NOP, 1);
2890 bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
2891 IGU_INT_NOP, 1);
2892 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
2893 IGU_INT_ENABLE, 1);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002894
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002895}
2896
2897static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
2898{
2899 struct net_device *dev = dev_instance;
2900 struct bnx2x *bp = netdev_priv(dev);
2901
2902 /* Return here if interrupt is disabled */
2903 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002904 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002905 return IRQ_HANDLED;
2906 }
2907
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08002908 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002909
2910#ifdef BNX2X_STOP_ON_ERROR
2911 if (unlikely(bp->panic))
2912 return IRQ_HANDLED;
2913#endif
2914
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002915 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002916
2917 return IRQ_HANDLED;
2918}
2919
2920/* end of slow path */
2921
2922/* Statistics */
2923
2924/****************************************************************************
2925* Macros
2926****************************************************************************/
2927
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002928/* sum[hi:lo] += add[hi:lo] */
2929#define ADD_64(s_hi, a_hi, s_lo, a_lo) \
2930 do { \
2931 s_lo += a_lo; \
Eilon Greensteinf5ba6772009-01-14 21:29:18 -08002932 s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002933 } while (0)
2934
2935/* difference = minuend - subtrahend */
2936#define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
2937 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002938 if (m_lo < s_lo) { \
2939 /* underflow */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002940 d_hi = m_hi - s_hi; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002941 if (d_hi > 0) { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002942 /* we can 'loan' 1 */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002943 d_hi--; \
2944 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002945 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002946 /* m_hi <= s_hi */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002947 d_hi = 0; \
2948 d_lo = 0; \
2949 } \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002950 } else { \
2951 /* m_lo >= s_lo */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002952 if (m_hi < s_hi) { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002953 d_hi = 0; \
2954 d_lo = 0; \
2955 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002956 /* m_hi >= s_hi */ \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002957 d_hi = m_hi - s_hi; \
2958 d_lo = m_lo - s_lo; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002959 } \
2960 } \
2961 } while (0)
2962
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002963#define UPDATE_STAT64(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002964 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002965 DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
2966 diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
2967 pstats->mac_stx[0].t##_hi = new->s##_hi; \
2968 pstats->mac_stx[0].t##_lo = new->s##_lo; \
2969 ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
2970 pstats->mac_stx[1].t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002971 } while (0)
2972
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002973#define UPDATE_STAT64_NIG(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002974 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002975 DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
2976 diff.lo, new->s##_lo, old->s##_lo); \
2977 ADD_64(estats->t##_hi, diff.hi, \
2978 estats->t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002979 } while (0)
2980
2981/* sum[hi:lo] += add */
2982#define ADD_EXTEND_64(s_hi, s_lo, a) \
2983 do { \
2984 s_lo += a; \
2985 s_hi += (s_lo < a) ? 1 : 0; \
2986 } while (0)
2987
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002988#define UPDATE_EXTEND_STAT(s) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002989 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002990 ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
2991 pstats->mac_stx[1].s##_lo, \
2992 new->s); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002993 } while (0)
2994
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002995#define UPDATE_EXTEND_TSTAT(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002996 do { \
2997 diff = le32_to_cpu(tclient->s) - old_tclient->s; \
2998 old_tclient->s = le32_to_cpu(tclient->s); \
Eilon Greensteinde832a52009-02-12 08:36:33 +00002999 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3000 } while (0)
3001
3002#define UPDATE_EXTEND_USTAT(s, t) \
3003 do { \
3004 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3005 old_uclient->s = uclient->s; \
3006 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003007 } while (0)
3008
3009#define UPDATE_EXTEND_XSTAT(s, t) \
3010 do { \
3011 diff = le32_to_cpu(xclient->s) - old_xclient->s; \
3012 old_xclient->s = le32_to_cpu(xclient->s); \
Eilon Greensteinde832a52009-02-12 08:36:33 +00003013 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3014 } while (0)
3015
3016/* minuend -= subtrahend */
3017#define SUB_64(m_hi, s_hi, m_lo, s_lo) \
3018 do { \
3019 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
3020 } while (0)
3021
3022/* minuend[hi:lo] -= subtrahend */
3023#define SUB_EXTEND_64(m_hi, m_lo, s) \
3024 do { \
3025 SUB_64(m_hi, 0, m_lo, s); \
3026 } while (0)
3027
3028#define SUB_EXTEND_USTAT(s, t) \
3029 do { \
3030 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3031 SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003032 } while (0)
3033
3034/*
3035 * General service functions
3036 */
3037
3038static inline long bnx2x_hilo(u32 *hiref)
3039{
3040 u32 lo = *(hiref + 1);
3041#if (BITS_PER_LONG == 64)
3042 u32 hi = *hiref;
3043
3044 return HILO_U64(hi, lo);
3045#else
3046 return lo;
3047#endif
3048}
3049
3050/*
3051 * Init service functions
3052 */
3053
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003054static void bnx2x_storm_stats_post(struct bnx2x *bp)
3055{
3056 if (!bp->stats_pending) {
3057 struct eth_query_ramrod_data ramrod_data = {0};
Eilon Greensteinde832a52009-02-12 08:36:33 +00003058 int i, rc;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003059
3060 ramrod_data.drv_counter = bp->stats_counter++;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08003061 ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003062 for_each_queue(bp, i)
3063 ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003064
3065 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
3066 ((u32 *)&ramrod_data)[1],
3067 ((u32 *)&ramrod_data)[0], 0);
3068 if (rc == 0) {
3069 /* stats ramrod has it's own slot on the spq */
3070 bp->spq_left++;
3071 bp->stats_pending = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003072 }
3073 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003074}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003075
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003076static void bnx2x_stats_init(struct bnx2x *bp)
3077{
3078 int port = BP_PORT(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003079 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003080
Eilon Greensteinde832a52009-02-12 08:36:33 +00003081 bp->stats_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003082 bp->executer_idx = 0;
3083 bp->stats_counter = 0;
3084
3085 /* port stats */
3086 if (!BP_NOMCP(bp))
3087 bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
3088 else
3089 bp->port.port_stx = 0;
3090 DP(BNX2X_MSG_STATS, "port_stx 0x%x\n", bp->port.port_stx);
3091
3092 memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
3093 bp->port.old_nig_stats.brb_discard =
3094 REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003095 bp->port.old_nig_stats.brb_truncate =
3096 REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003097 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
3098 &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
3099 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
3100 &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
3101
3102 /* function stats */
Eilon Greensteinde832a52009-02-12 08:36:33 +00003103 for_each_queue(bp, i) {
3104 struct bnx2x_fastpath *fp = &bp->fp[i];
3105
3106 memset(&fp->old_tclient, 0,
3107 sizeof(struct tstorm_per_client_stats));
3108 memset(&fp->old_uclient, 0,
3109 sizeof(struct ustorm_per_client_stats));
3110 memset(&fp->old_xclient, 0,
3111 sizeof(struct xstorm_per_client_stats));
3112 memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
3113 }
3114
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003115 memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003116 memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
3117
3118 bp->stats_state = STATS_STATE_DISABLED;
3119 if (IS_E1HMF(bp) && bp->port.pmf && bp->port.port_stx)
3120 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
3121}
3122
3123static void bnx2x_hw_stats_post(struct bnx2x *bp)
3124{
3125 struct dmae_command *dmae = &bp->stats_dmae;
3126 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3127
3128 *stats_comp = DMAE_COMP_VAL;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003129 if (CHIP_REV_IS_SLOW(bp))
3130 return;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003131
3132 /* loader */
3133 if (bp->executer_idx) {
3134 int loader_idx = PMF_DMAE_C(bp);
3135
3136 memset(dmae, 0, sizeof(struct dmae_command));
3137
3138 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3139 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3140 DMAE_CMD_DST_RESET |
3141#ifdef __BIG_ENDIAN
3142 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3143#else
3144 DMAE_CMD_ENDIANITY_DW_SWAP |
3145#endif
3146 (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
3147 DMAE_CMD_PORT_0) |
3148 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3149 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
3150 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
3151 dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
3152 sizeof(struct dmae_command) *
3153 (loader_idx + 1)) >> 2;
3154 dmae->dst_addr_hi = 0;
3155 dmae->len = sizeof(struct dmae_command) >> 2;
3156 if (CHIP_IS_E1(bp))
3157 dmae->len--;
3158 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
3159 dmae->comp_addr_hi = 0;
3160 dmae->comp_val = 1;
3161
3162 *stats_comp = 0;
3163 bnx2x_post_dmae(bp, dmae, loader_idx);
3164
3165 } else if (bp->func_stx) {
3166 *stats_comp = 0;
3167 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
3168 }
3169}
3170
3171static int bnx2x_stats_comp(struct bnx2x *bp)
3172{
3173 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3174 int cnt = 10;
3175
3176 might_sleep();
3177 while (*stats_comp != DMAE_COMP_VAL) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003178 if (!cnt) {
3179 BNX2X_ERR("timeout waiting for stats finished\n");
3180 break;
3181 }
3182 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -07003183 msleep(1);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003184 }
3185 return 1;
3186}
3187
3188/*
3189 * Statistics service functions
3190 */
3191
3192static void bnx2x_stats_pmf_update(struct bnx2x *bp)
3193{
3194 struct dmae_command *dmae;
3195 u32 opcode;
3196 int loader_idx = PMF_DMAE_C(bp);
3197 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3198
3199 /* sanity */
3200 if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
3201 BNX2X_ERR("BUG!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003202 return;
3203 }
3204
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003205 bp->executer_idx = 0;
3206
3207 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3208 DMAE_CMD_C_ENABLE |
3209 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3210#ifdef __BIG_ENDIAN
3211 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3212#else
3213 DMAE_CMD_ENDIANITY_DW_SWAP |
3214#endif
3215 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3216 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3217
3218 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3219 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
3220 dmae->src_addr_lo = bp->port.port_stx >> 2;
3221 dmae->src_addr_hi = 0;
3222 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3223 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3224 dmae->len = DMAE_LEN32_RD_MAX;
3225 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3226 dmae->comp_addr_hi = 0;
3227 dmae->comp_val = 1;
3228
3229 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3230 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
3231 dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
3232 dmae->src_addr_hi = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07003233 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
3234 DMAE_LEN32_RD_MAX * 4);
3235 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
3236 DMAE_LEN32_RD_MAX * 4);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003237 dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
3238 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3239 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3240 dmae->comp_val = DMAE_COMP_VAL;
3241
3242 *stats_comp = 0;
3243 bnx2x_hw_stats_post(bp);
3244 bnx2x_stats_comp(bp);
3245}
3246
3247static void bnx2x_port_stats_init(struct bnx2x *bp)
3248{
3249 struct dmae_command *dmae;
3250 int port = BP_PORT(bp);
3251 int vn = BP_E1HVN(bp);
3252 u32 opcode;
3253 int loader_idx = PMF_DMAE_C(bp);
3254 u32 mac_addr;
3255 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3256
3257 /* sanity */
3258 if (!bp->link_vars.link_up || !bp->port.pmf) {
3259 BNX2X_ERR("BUG!\n");
3260 return;
3261 }
3262
3263 bp->executer_idx = 0;
3264
3265 /* MCP */
3266 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3267 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3268 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3269#ifdef __BIG_ENDIAN
3270 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3271#else
3272 DMAE_CMD_ENDIANITY_DW_SWAP |
3273#endif
3274 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3275 (vn << DMAE_CMD_E1HVN_SHIFT));
3276
3277 if (bp->port.port_stx) {
3278
3279 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3280 dmae->opcode = opcode;
3281 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3282 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3283 dmae->dst_addr_lo = bp->port.port_stx >> 2;
3284 dmae->dst_addr_hi = 0;
3285 dmae->len = sizeof(struct host_port_stats) >> 2;
3286 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3287 dmae->comp_addr_hi = 0;
3288 dmae->comp_val = 1;
3289 }
3290
3291 if (bp->func_stx) {
3292
3293 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3294 dmae->opcode = opcode;
3295 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3296 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3297 dmae->dst_addr_lo = bp->func_stx >> 2;
3298 dmae->dst_addr_hi = 0;
3299 dmae->len = sizeof(struct host_func_stats) >> 2;
3300 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3301 dmae->comp_addr_hi = 0;
3302 dmae->comp_val = 1;
3303 }
3304
3305 /* MAC */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003306 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3307 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3308 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3309#ifdef __BIG_ENDIAN
3310 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3311#else
3312 DMAE_CMD_ENDIANITY_DW_SWAP |
3313#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003314 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3315 (vn << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003316
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003317 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003318
3319 mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
3320 NIG_REG_INGRESS_BMAC0_MEM);
3321
3322 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
3323 BIGMAC_REGISTER_TX_STAT_GTBYT */
3324 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3325 dmae->opcode = opcode;
3326 dmae->src_addr_lo = (mac_addr +
3327 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3328 dmae->src_addr_hi = 0;
3329 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3330 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3331 dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
3332 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3333 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3334 dmae->comp_addr_hi = 0;
3335 dmae->comp_val = 1;
3336
3337 /* BIGMAC_REGISTER_RX_STAT_GR64 ..
3338 BIGMAC_REGISTER_RX_STAT_GRIPJ */
3339 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3340 dmae->opcode = opcode;
3341 dmae->src_addr_lo = (mac_addr +
3342 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3343 dmae->src_addr_hi = 0;
3344 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003345 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003346 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003347 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003348 dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
3349 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3350 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3351 dmae->comp_addr_hi = 0;
3352 dmae->comp_val = 1;
3353
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003354 } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003355
3356 mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
3357
3358 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
3359 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3360 dmae->opcode = opcode;
3361 dmae->src_addr_lo = (mac_addr +
3362 EMAC_REG_EMAC_RX_STAT_AC) >> 2;
3363 dmae->src_addr_hi = 0;
3364 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3365 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3366 dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
3367 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3368 dmae->comp_addr_hi = 0;
3369 dmae->comp_val = 1;
3370
3371 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
3372 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3373 dmae->opcode = opcode;
3374 dmae->src_addr_lo = (mac_addr +
3375 EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
3376 dmae->src_addr_hi = 0;
3377 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003378 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003379 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003380 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003381 dmae->len = 1;
3382 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3383 dmae->comp_addr_hi = 0;
3384 dmae->comp_val = 1;
3385
3386 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
3387 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3388 dmae->opcode = opcode;
3389 dmae->src_addr_lo = (mac_addr +
3390 EMAC_REG_EMAC_TX_STAT_AC) >> 2;
3391 dmae->src_addr_hi = 0;
3392 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003393 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003394 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003395 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003396 dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
3397 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3398 dmae->comp_addr_hi = 0;
3399 dmae->comp_val = 1;
3400 }
3401
3402 /* NIG */
3403 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003404 dmae->opcode = opcode;
3405 dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
3406 NIG_REG_STAT0_BRB_DISCARD) >> 2;
3407 dmae->src_addr_hi = 0;
3408 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
3409 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
3410 dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
3411 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3412 dmae->comp_addr_hi = 0;
3413 dmae->comp_val = 1;
3414
3415 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3416 dmae->opcode = opcode;
3417 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
3418 NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
3419 dmae->src_addr_hi = 0;
3420 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3421 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3422 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3423 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3424 dmae->len = (2*sizeof(u32)) >> 2;
3425 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3426 dmae->comp_addr_hi = 0;
3427 dmae->comp_val = 1;
3428
3429 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003430 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3431 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3432 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3433#ifdef __BIG_ENDIAN
3434 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3435#else
3436 DMAE_CMD_ENDIANITY_DW_SWAP |
3437#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003438 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3439 (vn << DMAE_CMD_E1HVN_SHIFT));
3440 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
3441 NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003442 dmae->src_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003443 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3444 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3445 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3446 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3447 dmae->len = (2*sizeof(u32)) >> 2;
3448 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3449 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3450 dmae->comp_val = DMAE_COMP_VAL;
3451
3452 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003453}
3454
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003455static void bnx2x_func_stats_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003456{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003457 struct dmae_command *dmae = &bp->stats_dmae;
3458 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003459
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003460 /* sanity */
3461 if (!bp->func_stx) {
3462 BNX2X_ERR("BUG!\n");
3463 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003464 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003465
3466 bp->executer_idx = 0;
3467 memset(dmae, 0, sizeof(struct dmae_command));
3468
3469 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3470 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3471 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3472#ifdef __BIG_ENDIAN
3473 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3474#else
3475 DMAE_CMD_ENDIANITY_DW_SWAP |
3476#endif
3477 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3478 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3479 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3480 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3481 dmae->dst_addr_lo = bp->func_stx >> 2;
3482 dmae->dst_addr_hi = 0;
3483 dmae->len = sizeof(struct host_func_stats) >> 2;
3484 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3485 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3486 dmae->comp_val = DMAE_COMP_VAL;
3487
3488 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003489}
3490
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003491static void bnx2x_stats_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003492{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003493 if (bp->port.pmf)
3494 bnx2x_port_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003495
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003496 else if (bp->func_stx)
3497 bnx2x_func_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003498
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003499 bnx2x_hw_stats_post(bp);
3500 bnx2x_storm_stats_post(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003501}
3502
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003503static void bnx2x_stats_pmf_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003504{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003505 bnx2x_stats_comp(bp);
3506 bnx2x_stats_pmf_update(bp);
3507 bnx2x_stats_start(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003508}
3509
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003510static void bnx2x_stats_restart(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003511{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003512 bnx2x_stats_comp(bp);
3513 bnx2x_stats_start(bp);
3514}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003515
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003516static void bnx2x_bmac_stats_update(struct bnx2x *bp)
3517{
3518 struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
3519 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003520 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003521 struct regpair diff;
3522
3523 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
3524 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
3525 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
3526 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
3527 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
3528 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003529 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003530 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003531 UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003532 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
3533 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
3534 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
3535 UPDATE_STAT64(tx_stat_gt127,
3536 tx_stat_etherstatspkts65octetsto127octets);
3537 UPDATE_STAT64(tx_stat_gt255,
3538 tx_stat_etherstatspkts128octetsto255octets);
3539 UPDATE_STAT64(tx_stat_gt511,
3540 tx_stat_etherstatspkts256octetsto511octets);
3541 UPDATE_STAT64(tx_stat_gt1023,
3542 tx_stat_etherstatspkts512octetsto1023octets);
3543 UPDATE_STAT64(tx_stat_gt1518,
3544 tx_stat_etherstatspkts1024octetsto1522octets);
3545 UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
3546 UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
3547 UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
3548 UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
3549 UPDATE_STAT64(tx_stat_gterr,
3550 tx_stat_dot3statsinternalmactransmiterrors);
3551 UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003552
3553 estats->pause_frames_received_hi =
3554 pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
3555 estats->pause_frames_received_lo =
3556 pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
3557
3558 estats->pause_frames_sent_hi =
3559 pstats->mac_stx[1].tx_stat_outxoffsent_hi;
3560 estats->pause_frames_sent_lo =
3561 pstats->mac_stx[1].tx_stat_outxoffsent_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003562}
3563
3564static void bnx2x_emac_stats_update(struct bnx2x *bp)
3565{
3566 struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
3567 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003568 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003569
3570 UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
3571 UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
3572 UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
3573 UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
3574 UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
3575 UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
3576 UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
3577 UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
3578 UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
3579 UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
3580 UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
3581 UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
3582 UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
3583 UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
3584 UPDATE_EXTEND_STAT(tx_stat_outxonsent);
3585 UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
3586 UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
3587 UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
3588 UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
3589 UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
3590 UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
3591 UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
3592 UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
3593 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
3594 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
3595 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
3596 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
3597 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
3598 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
3599 UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
3600 UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003601
3602 estats->pause_frames_received_hi =
3603 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
3604 estats->pause_frames_received_lo =
3605 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
3606 ADD_64(estats->pause_frames_received_hi,
3607 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
3608 estats->pause_frames_received_lo,
3609 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
3610
3611 estats->pause_frames_sent_hi =
3612 pstats->mac_stx[1].tx_stat_outxonsent_hi;
3613 estats->pause_frames_sent_lo =
3614 pstats->mac_stx[1].tx_stat_outxonsent_lo;
3615 ADD_64(estats->pause_frames_sent_hi,
3616 pstats->mac_stx[1].tx_stat_outxoffsent_hi,
3617 estats->pause_frames_sent_lo,
3618 pstats->mac_stx[1].tx_stat_outxoffsent_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003619}
3620
3621static int bnx2x_hw_stats_update(struct bnx2x *bp)
3622{
3623 struct nig_stats *new = bnx2x_sp(bp, nig_stats);
3624 struct nig_stats *old = &(bp->port.old_nig_stats);
3625 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
3626 struct bnx2x_eth_stats *estats = &bp->eth_stats;
3627 struct regpair diff;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003628 u32 nig_timer_max;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003629
3630 if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
3631 bnx2x_bmac_stats_update(bp);
3632
3633 else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
3634 bnx2x_emac_stats_update(bp);
3635
3636 else { /* unreached */
3637 BNX2X_ERR("stats updated by dmae but no MAC active\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003638 return -1;
3639 }
3640
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003641 ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
3642 new->brb_discard - old->brb_discard);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003643 ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
3644 new->brb_truncate - old->brb_truncate);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003645
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003646 UPDATE_STAT64_NIG(egress_mac_pkt0,
3647 etherstatspkts1024octetsto1522octets);
3648 UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003649
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003650 memcpy(old, new, sizeof(struct nig_stats));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003651
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003652 memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
3653 sizeof(struct mac_stx));
3654 estats->brb_drop_hi = pstats->brb_drop_hi;
3655 estats->brb_drop_lo = pstats->brb_drop_lo;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003656
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003657 pstats->host_port_stats_start = ++pstats->host_port_stats_end;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003658
Eilon Greensteinde832a52009-02-12 08:36:33 +00003659 nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
3660 if (nig_timer_max != estats->nig_timer_max) {
3661 estats->nig_timer_max = nig_timer_max;
3662 BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max);
3663 }
3664
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003665 return 0;
3666}
3667
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003668static int bnx2x_storm_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003669{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003670 struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003671 struct tstorm_per_port_stats *tport =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003672 &stats->tstorm_common.port_statistics;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003673 struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
3674 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003675 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003676
Eilon Greensteinde832a52009-02-12 08:36:33 +00003677 memset(&(fstats->total_bytes_received_hi), 0,
3678 sizeof(struct host_func_stats) - 2*sizeof(u32));
3679 estats->error_bytes_received_hi = 0;
3680 estats->error_bytes_received_lo = 0;
3681 estats->etherstatsoverrsizepkts_hi = 0;
3682 estats->etherstatsoverrsizepkts_lo = 0;
3683 estats->no_buff_discard_hi = 0;
3684 estats->no_buff_discard_lo = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003685
Eilon Greensteinde832a52009-02-12 08:36:33 +00003686 for_each_queue(bp, i) {
3687 struct bnx2x_fastpath *fp = &bp->fp[i];
3688 int cl_id = fp->cl_id;
3689 struct tstorm_per_client_stats *tclient =
3690 &stats->tstorm_common.client_statistics[cl_id];
3691 struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
3692 struct ustorm_per_client_stats *uclient =
3693 &stats->ustorm_common.client_statistics[cl_id];
3694 struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
3695 struct xstorm_per_client_stats *xclient =
3696 &stats->xstorm_common.client_statistics[cl_id];
3697 struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
3698 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
3699 u32 diff;
3700
3701 /* are storm stats valid? */
3702 if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
3703 bp->stats_counter) {
3704 DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
3705 " xstorm counter (%d) != stats_counter (%d)\n",
3706 i, xclient->stats_counter, bp->stats_counter);
3707 return -1;
3708 }
3709 if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
3710 bp->stats_counter) {
3711 DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
3712 " tstorm counter (%d) != stats_counter (%d)\n",
3713 i, tclient->stats_counter, bp->stats_counter);
3714 return -2;
3715 }
3716 if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
3717 bp->stats_counter) {
3718 DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
3719 " ustorm counter (%d) != stats_counter (%d)\n",
3720 i, uclient->stats_counter, bp->stats_counter);
3721 return -4;
3722 }
3723
3724 qstats->total_bytes_received_hi =
3725 qstats->valid_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003726 le32_to_cpu(tclient->total_rcv_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003727 qstats->total_bytes_received_lo =
3728 qstats->valid_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003729 le32_to_cpu(tclient->total_rcv_bytes.lo);
3730
Eilon Greensteinde832a52009-02-12 08:36:33 +00003731 qstats->error_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003732 le32_to_cpu(tclient->rcv_error_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003733 qstats->error_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003734 le32_to_cpu(tclient->rcv_error_bytes.lo);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003735
3736 ADD_64(qstats->total_bytes_received_hi,
3737 qstats->error_bytes_received_hi,
3738 qstats->total_bytes_received_lo,
3739 qstats->error_bytes_received_lo);
3740
3741 UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
3742 total_unicast_packets_received);
3743 UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
3744 total_multicast_packets_received);
3745 UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
3746 total_broadcast_packets_received);
3747 UPDATE_EXTEND_TSTAT(packets_too_big_discard,
3748 etherstatsoverrsizepkts);
3749 UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
3750
3751 SUB_EXTEND_USTAT(ucast_no_buff_pkts,
3752 total_unicast_packets_received);
3753 SUB_EXTEND_USTAT(mcast_no_buff_pkts,
3754 total_multicast_packets_received);
3755 SUB_EXTEND_USTAT(bcast_no_buff_pkts,
3756 total_broadcast_packets_received);
3757 UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
3758 UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
3759 UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
3760
3761 qstats->total_bytes_transmitted_hi =
3762 le32_to_cpu(xclient->total_sent_bytes.hi);
3763 qstats->total_bytes_transmitted_lo =
3764 le32_to_cpu(xclient->total_sent_bytes.lo);
3765
3766 UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
3767 total_unicast_packets_transmitted);
3768 UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
3769 total_multicast_packets_transmitted);
3770 UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
3771 total_broadcast_packets_transmitted);
3772
3773 old_tclient->checksum_discard = tclient->checksum_discard;
3774 old_tclient->ttl0_discard = tclient->ttl0_discard;
3775
3776 ADD_64(fstats->total_bytes_received_hi,
3777 qstats->total_bytes_received_hi,
3778 fstats->total_bytes_received_lo,
3779 qstats->total_bytes_received_lo);
3780 ADD_64(fstats->total_bytes_transmitted_hi,
3781 qstats->total_bytes_transmitted_hi,
3782 fstats->total_bytes_transmitted_lo,
3783 qstats->total_bytes_transmitted_lo);
3784 ADD_64(fstats->total_unicast_packets_received_hi,
3785 qstats->total_unicast_packets_received_hi,
3786 fstats->total_unicast_packets_received_lo,
3787 qstats->total_unicast_packets_received_lo);
3788 ADD_64(fstats->total_multicast_packets_received_hi,
3789 qstats->total_multicast_packets_received_hi,
3790 fstats->total_multicast_packets_received_lo,
3791 qstats->total_multicast_packets_received_lo);
3792 ADD_64(fstats->total_broadcast_packets_received_hi,
3793 qstats->total_broadcast_packets_received_hi,
3794 fstats->total_broadcast_packets_received_lo,
3795 qstats->total_broadcast_packets_received_lo);
3796 ADD_64(fstats->total_unicast_packets_transmitted_hi,
3797 qstats->total_unicast_packets_transmitted_hi,
3798 fstats->total_unicast_packets_transmitted_lo,
3799 qstats->total_unicast_packets_transmitted_lo);
3800 ADD_64(fstats->total_multicast_packets_transmitted_hi,
3801 qstats->total_multicast_packets_transmitted_hi,
3802 fstats->total_multicast_packets_transmitted_lo,
3803 qstats->total_multicast_packets_transmitted_lo);
3804 ADD_64(fstats->total_broadcast_packets_transmitted_hi,
3805 qstats->total_broadcast_packets_transmitted_hi,
3806 fstats->total_broadcast_packets_transmitted_lo,
3807 qstats->total_broadcast_packets_transmitted_lo);
3808 ADD_64(fstats->valid_bytes_received_hi,
3809 qstats->valid_bytes_received_hi,
3810 fstats->valid_bytes_received_lo,
3811 qstats->valid_bytes_received_lo);
3812
3813 ADD_64(estats->error_bytes_received_hi,
3814 qstats->error_bytes_received_hi,
3815 estats->error_bytes_received_lo,
3816 qstats->error_bytes_received_lo);
3817 ADD_64(estats->etherstatsoverrsizepkts_hi,
3818 qstats->etherstatsoverrsizepkts_hi,
3819 estats->etherstatsoverrsizepkts_lo,
3820 qstats->etherstatsoverrsizepkts_lo);
3821 ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
3822 estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
3823 }
3824
3825 ADD_64(fstats->total_bytes_received_hi,
3826 estats->rx_stat_ifhcinbadoctets_hi,
3827 fstats->total_bytes_received_lo,
3828 estats->rx_stat_ifhcinbadoctets_lo);
3829
3830 memcpy(estats, &(fstats->total_bytes_received_hi),
3831 sizeof(struct host_func_stats) - 2*sizeof(u32));
3832
3833 ADD_64(estats->etherstatsoverrsizepkts_hi,
3834 estats->rx_stat_dot3statsframestoolong_hi,
3835 estats->etherstatsoverrsizepkts_lo,
3836 estats->rx_stat_dot3statsframestoolong_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003837 ADD_64(estats->error_bytes_received_hi,
3838 estats->rx_stat_ifhcinbadoctets_hi,
3839 estats->error_bytes_received_lo,
3840 estats->rx_stat_ifhcinbadoctets_lo);
3841
Eilon Greensteinde832a52009-02-12 08:36:33 +00003842 if (bp->port.pmf) {
3843 estats->mac_filter_discard =
3844 le32_to_cpu(tport->mac_filter_discard);
3845 estats->xxoverflow_discard =
3846 le32_to_cpu(tport->xxoverflow_discard);
3847 estats->brb_truncate_discard =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003848 le32_to_cpu(tport->brb_truncate_discard);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003849 estats->mac_discard = le32_to_cpu(tport->mac_discard);
3850 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003851
3852 fstats->host_func_stats_start = ++fstats->host_func_stats_end;
3853
Eilon Greensteinde832a52009-02-12 08:36:33 +00003854 bp->stats_pending = 0;
3855
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003856 return 0;
3857}
3858
3859static void bnx2x_net_stats_update(struct bnx2x *bp)
3860{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003861 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003862 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003863 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003864
3865 nstats->rx_packets =
3866 bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
3867 bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
3868 bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
3869
3870 nstats->tx_packets =
3871 bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
3872 bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
3873 bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
3874
Eilon Greensteinde832a52009-02-12 08:36:33 +00003875 nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003876
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003877 nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003878
Eilon Greensteinde832a52009-02-12 08:36:33 +00003879 nstats->rx_dropped = estats->mac_discard;
3880 for_each_queue(bp, i)
3881 nstats->rx_dropped +=
3882 le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
3883
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003884 nstats->tx_dropped = 0;
3885
3886 nstats->multicast =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003887 bnx2x_hilo(&estats->total_multicast_packets_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003888
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003889 nstats->collisions =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003890 bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003891
3892 nstats->rx_length_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003893 bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
3894 bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
3895 nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
3896 bnx2x_hilo(&estats->brb_truncate_hi);
3897 nstats->rx_crc_errors =
3898 bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
3899 nstats->rx_frame_errors =
3900 bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
3901 nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003902 nstats->rx_missed_errors = estats->xxoverflow_discard;
3903
3904 nstats->rx_errors = nstats->rx_length_errors +
3905 nstats->rx_over_errors +
3906 nstats->rx_crc_errors +
3907 nstats->rx_frame_errors +
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003908 nstats->rx_fifo_errors +
3909 nstats->rx_missed_errors;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003910
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003911 nstats->tx_aborted_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003912 bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
3913 bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
3914 nstats->tx_carrier_errors =
3915 bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003916 nstats->tx_fifo_errors = 0;
3917 nstats->tx_heartbeat_errors = 0;
3918 nstats->tx_window_errors = 0;
3919
3920 nstats->tx_errors = nstats->tx_aborted_errors +
Eilon Greensteinde832a52009-02-12 08:36:33 +00003921 nstats->tx_carrier_errors +
3922 bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
3923}
3924
3925static void bnx2x_drv_stats_update(struct bnx2x *bp)
3926{
3927 struct bnx2x_eth_stats *estats = &bp->eth_stats;
3928 int i;
3929
3930 estats->driver_xoff = 0;
3931 estats->rx_err_discard_pkt = 0;
3932 estats->rx_skb_alloc_failed = 0;
3933 estats->hw_csum_err = 0;
3934 for_each_queue(bp, i) {
3935 struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
3936
3937 estats->driver_xoff += qstats->driver_xoff;
3938 estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
3939 estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
3940 estats->hw_csum_err += qstats->hw_csum_err;
3941 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003942}
3943
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003944static void bnx2x_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003945{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003946 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003947
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003948 if (*stats_comp != DMAE_COMP_VAL)
3949 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003950
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003951 if (bp->port.pmf)
Eilon Greensteinde832a52009-02-12 08:36:33 +00003952 bnx2x_hw_stats_update(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003953
Eilon Greensteinde832a52009-02-12 08:36:33 +00003954 if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
3955 BNX2X_ERR("storm stats were not updated for 3 times\n");
3956 bnx2x_panic();
3957 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003958 }
3959
Eilon Greensteinde832a52009-02-12 08:36:33 +00003960 bnx2x_net_stats_update(bp);
3961 bnx2x_drv_stats_update(bp);
3962
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003963 if (bp->msglevel & NETIF_MSG_TIMER) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00003964 struct tstorm_per_client_stats *old_tclient =
3965 &bp->fp->old_tclient;
3966 struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003967 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003968 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003969 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003970
3971 printk(KERN_DEBUG "%s:\n", bp->dev->name);
3972 printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)"
3973 " tx pkt (%lx)\n",
3974 bnx2x_tx_avail(bp->fp),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07003975 le16_to_cpu(*bp->fp->tx_cons_sb), nstats->tx_packets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003976 printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)"
3977 " rx pkt (%lx)\n",
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07003978 (u16)(le16_to_cpu(*bp->fp->rx_cons_sb) -
3979 bp->fp->rx_comp_cons),
3980 le16_to_cpu(*bp->fp->rx_cons_sb), nstats->rx_packets);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003981 printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u "
3982 "brb truncate %u\n",
3983 (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"),
3984 qstats->driver_xoff,
3985 estats->brb_drop_lo, estats->brb_truncate_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003986 printk(KERN_DEBUG "tstats: checksum_discard %u "
Eilon Greensteinde832a52009-02-12 08:36:33 +00003987 "packets_too_big_discard %lu no_buff_discard %lu "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003988 "mac_discard %u mac_filter_discard %u "
3989 "xxovrflow_discard %u brb_truncate_discard %u "
3990 "ttl0_discard %u\n",
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003991 old_tclient->checksum_discard,
Eilon Greensteinde832a52009-02-12 08:36:33 +00003992 bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi),
3993 bnx2x_hilo(&qstats->no_buff_discard_hi),
3994 estats->mac_discard, estats->mac_filter_discard,
3995 estats->xxoverflow_discard, estats->brb_truncate_discard,
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003996 old_tclient->ttl0_discard);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003997
3998 for_each_queue(bp, i) {
3999 printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i,
4000 bnx2x_fp(bp, i, tx_pkt),
4001 bnx2x_fp(bp, i, rx_pkt),
4002 bnx2x_fp(bp, i, rx_calls));
4003 }
4004 }
4005
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004006 bnx2x_hw_stats_post(bp);
4007 bnx2x_storm_stats_post(bp);
4008}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004009
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004010static void bnx2x_port_stats_stop(struct bnx2x *bp)
4011{
4012 struct dmae_command *dmae;
4013 u32 opcode;
4014 int loader_idx = PMF_DMAE_C(bp);
4015 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004016
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004017 bp->executer_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004018
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004019 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
4020 DMAE_CMD_C_ENABLE |
4021 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004022#ifdef __BIG_ENDIAN
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004023 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004024#else
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004025 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004026#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004027 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
4028 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
4029
4030 if (bp->port.port_stx) {
4031
4032 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4033 if (bp->func_stx)
4034 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
4035 else
4036 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4037 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
4038 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
4039 dmae->dst_addr_lo = bp->port.port_stx >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004040 dmae->dst_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004041 dmae->len = sizeof(struct host_port_stats) >> 2;
4042 if (bp->func_stx) {
4043 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
4044 dmae->comp_addr_hi = 0;
4045 dmae->comp_val = 1;
4046 } else {
4047 dmae->comp_addr_lo =
4048 U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4049 dmae->comp_addr_hi =
4050 U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4051 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004052
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004053 *stats_comp = 0;
4054 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004055 }
4056
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004057 if (bp->func_stx) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004058
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004059 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4060 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4061 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
4062 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
4063 dmae->dst_addr_lo = bp->func_stx >> 2;
4064 dmae->dst_addr_hi = 0;
4065 dmae->len = sizeof(struct host_func_stats) >> 2;
4066 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4067 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4068 dmae->comp_val = DMAE_COMP_VAL;
4069
4070 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004071 }
4072}
4073
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004074static void bnx2x_stats_stop(struct bnx2x *bp)
4075{
4076 int update = 0;
4077
4078 bnx2x_stats_comp(bp);
4079
4080 if (bp->port.pmf)
4081 update = (bnx2x_hw_stats_update(bp) == 0);
4082
4083 update |= (bnx2x_storm_stats_update(bp) == 0);
4084
4085 if (update) {
4086 bnx2x_net_stats_update(bp);
4087
4088 if (bp->port.pmf)
4089 bnx2x_port_stats_stop(bp);
4090
4091 bnx2x_hw_stats_post(bp);
4092 bnx2x_stats_comp(bp);
4093 }
4094}
4095
4096static void bnx2x_stats_do_nothing(struct bnx2x *bp)
4097{
4098}
4099
4100static const struct {
4101 void (*action)(struct bnx2x *bp);
4102 enum bnx2x_stats_state next_state;
4103} bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
4104/* state event */
4105{
4106/* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
4107/* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
4108/* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
4109/* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
4110},
4111{
4112/* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
4113/* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
4114/* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
4115/* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
4116}
4117};
4118
4119static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
4120{
4121 enum bnx2x_stats_state state = bp->stats_state;
4122
4123 bnx2x_stats_stm[state][event].action(bp);
4124 bp->stats_state = bnx2x_stats_stm[state][event].next_state;
4125
4126 if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER))
4127 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
4128 state, event, bp->stats_state);
4129}
4130
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004131static void bnx2x_timer(unsigned long data)
4132{
4133 struct bnx2x *bp = (struct bnx2x *) data;
4134
4135 if (!netif_running(bp->dev))
4136 return;
4137
4138 if (atomic_read(&bp->intr_sem) != 0)
Eliezer Tamirf1410642008-02-28 11:51:50 -08004139 goto timer_restart;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004140
4141 if (poll) {
4142 struct bnx2x_fastpath *fp = &bp->fp[0];
4143 int rc;
4144
4145 bnx2x_tx_int(fp, 1000);
4146 rc = bnx2x_rx_int(fp, 1000);
4147 }
4148
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004149 if (!BP_NOMCP(bp)) {
4150 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004151 u32 drv_pulse;
4152 u32 mcp_pulse;
4153
4154 ++bp->fw_drv_pulse_wr_seq;
4155 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4156 /* TBD - add SYSTEM_TIME */
4157 drv_pulse = bp->fw_drv_pulse_wr_seq;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004158 SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004159
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004160 mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004161 MCP_PULSE_SEQ_MASK);
4162 /* The delta between driver pulse and mcp response
4163 * should be 1 (before mcp response) or 0 (after mcp response)
4164 */
4165 if ((drv_pulse != mcp_pulse) &&
4166 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4167 /* someone lost a heartbeat... */
4168 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4169 drv_pulse, mcp_pulse);
4170 }
4171 }
4172
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004173 if ((bp->state == BNX2X_STATE_OPEN) ||
4174 (bp->state == BNX2X_STATE_DISABLED))
4175 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004176
Eliezer Tamirf1410642008-02-28 11:51:50 -08004177timer_restart:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004178 mod_timer(&bp->timer, jiffies + bp->current_interval);
4179}
4180
4181/* end of Statistics */
4182
4183/* nic init */
4184
4185/*
4186 * nic init service functions
4187 */
4188
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004189static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004190{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004191 int port = BP_PORT(bp);
4192
4193 bnx2x_init_fill(bp, BAR_USTRORM_INTMEM +
4194 USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
Yitchak Gertner35302982008-08-13 15:53:12 -07004195 sizeof(struct ustorm_status_block)/4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004196 bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM +
4197 CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
Yitchak Gertner35302982008-08-13 15:53:12 -07004198 sizeof(struct cstorm_status_block)/4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004199}
4200
Eilon Greenstein5c862842008-08-13 15:51:48 -07004201static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
4202 dma_addr_t mapping, int sb_id)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004203{
4204 int port = BP_PORT(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004205 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004206 int index;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004207 u64 section;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004208
4209 /* USTORM */
4210 section = ((u64)mapping) + offsetof(struct host_status_block,
4211 u_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004212 sb->u_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004213
4214 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004215 USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004216 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004217 ((USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004218 U64_HI(section));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004219 REG_WR8(bp, BAR_USTRORM_INTMEM + FP_USB_FUNC_OFF +
4220 USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004221
4222 for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
4223 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004224 USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004225
4226 /* CSTORM */
4227 section = ((u64)mapping) + offsetof(struct host_status_block,
4228 c_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004229 sb->c_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004230
4231 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004232 CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004233 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004234 ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004235 U64_HI(section));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004236 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
4237 CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004238
4239 for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
4240 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004241 CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004242
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004243 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
4244}
4245
4246static void bnx2x_zero_def_sb(struct bnx2x *bp)
4247{
4248 int func = BP_FUNC(bp);
4249
4250 bnx2x_init_fill(bp, BAR_USTRORM_INTMEM +
4251 USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4252 sizeof(struct ustorm_def_status_block)/4);
4253 bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM +
4254 CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4255 sizeof(struct cstorm_def_status_block)/4);
4256 bnx2x_init_fill(bp, BAR_XSTRORM_INTMEM +
4257 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4258 sizeof(struct xstorm_def_status_block)/4);
4259 bnx2x_init_fill(bp, BAR_TSTRORM_INTMEM +
4260 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4261 sizeof(struct tstorm_def_status_block)/4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004262}
4263
4264static void bnx2x_init_def_sb(struct bnx2x *bp,
4265 struct host_def_status_block *def_sb,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004266 dma_addr_t mapping, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004267{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004268 int port = BP_PORT(bp);
4269 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004270 int index, val, reg_offset;
4271 u64 section;
4272
4273 /* ATTN */
4274 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4275 atten_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004276 def_sb->atten_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004277
Eliezer Tamir49d66772008-02-28 11:53:13 -08004278 bp->attn_state = 0;
4279
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004280 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4281 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4282
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004283 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004284 bp->attn_group[index].sig[0] = REG_RD(bp,
4285 reg_offset + 0x10*index);
4286 bp->attn_group[index].sig[1] = REG_RD(bp,
4287 reg_offset + 0x4 + 0x10*index);
4288 bp->attn_group[index].sig[2] = REG_RD(bp,
4289 reg_offset + 0x8 + 0x10*index);
4290 bp->attn_group[index].sig[3] = REG_RD(bp,
4291 reg_offset + 0xc + 0x10*index);
4292 }
4293
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004294 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4295 HC_REG_ATTN_MSG0_ADDR_L);
4296
4297 REG_WR(bp, reg_offset, U64_LO(section));
4298 REG_WR(bp, reg_offset + 4, U64_HI(section));
4299
4300 reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
4301
4302 val = REG_RD(bp, reg_offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004303 val |= sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004304 REG_WR(bp, reg_offset, val);
4305
4306 /* USTORM */
4307 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4308 u_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004309 def_sb->u_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004310
4311 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004312 USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004313 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004314 ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004315 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004316 REG_WR8(bp, BAR_USTRORM_INTMEM + DEF_USB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004317 USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004318
4319 for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
4320 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004321 USTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004322
4323 /* CSTORM */
4324 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4325 c_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004326 def_sb->c_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004327
4328 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004329 CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004330 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004331 ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004332 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004333 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004334 CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004335
4336 for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
4337 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004338 CSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004339
4340 /* TSTORM */
4341 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4342 t_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004343 def_sb->t_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004344
4345 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004346 TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004347 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004348 ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004349 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004350 REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004351 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004352
4353 for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
4354 REG_WR16(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004355 TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004356
4357 /* XSTORM */
4358 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4359 x_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004360 def_sb->x_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004361
4362 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004363 XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004364 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004365 ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004366 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004367 REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004368 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004369
4370 for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
4371 REG_WR16(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004372 XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004373
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004374 bp->stats_pending = 0;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004375 bp->set_mac_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004376
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004377 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004378}
4379
4380static void bnx2x_update_coalesce(struct bnx2x *bp)
4381{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004382 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004383 int i;
4384
4385 for_each_queue(bp, i) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004386 int sb_id = bp->fp[i].sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004387
4388 /* HC_INDEX_U_ETH_RX_CQ_CONS */
4389 REG_WR8(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004390 USTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004391 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004392 bp->rx_ticks/12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004393 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004394 USTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004395 U_SB_ETH_RX_CQ_INDEX),
4396 bp->rx_ticks ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004397
4398 /* HC_INDEX_C_ETH_TX_CQ_CONS */
4399 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004400 CSTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004401 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004402 bp->tx_ticks/12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004403 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004404 CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004405 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004406 bp->tx_ticks ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004407 }
4408}
4409
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004410static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
4411 struct bnx2x_fastpath *fp, int last)
4412{
4413 int i;
4414
4415 for (i = 0; i < last; i++) {
4416 struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
4417 struct sk_buff *skb = rx_buf->skb;
4418
4419 if (skb == NULL) {
4420 DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
4421 continue;
4422 }
4423
4424 if (fp->tpa_state[i] == BNX2X_TPA_START)
4425 pci_unmap_single(bp->pdev,
4426 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07004427 bp->rx_buf_size,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004428 PCI_DMA_FROMDEVICE);
4429
4430 dev_kfree_skb(skb);
4431 rx_buf->skb = NULL;
4432 }
4433}
4434
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004435static void bnx2x_init_rx_rings(struct bnx2x *bp)
4436{
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004437 int func = BP_FUNC(bp);
Eilon Greenstein32626232008-08-13 15:51:07 -07004438 int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
4439 ETH_MAX_AGGREGATION_QUEUES_E1H;
4440 u16 ring_prod, cqe_ring_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004441 int i, j;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004442
Eilon Greenstein87942b42009-02-12 08:36:49 +00004443 bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN;
Eilon Greenstein0f008462009-02-12 08:36:18 +00004444 DP(NETIF_MSG_IFUP,
4445 "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004446
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004447 if (bp->flags & TPA_ENABLE_FLAG) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004448
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004449 for_each_rx_queue(bp, j) {
Eilon Greenstein32626232008-08-13 15:51:07 -07004450 struct bnx2x_fastpath *fp = &bp->fp[j];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004451
Eilon Greenstein32626232008-08-13 15:51:07 -07004452 for (i = 0; i < max_agg_queues; i++) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004453 fp->tpa_pool[i].skb =
4454 netdev_alloc_skb(bp->dev, bp->rx_buf_size);
4455 if (!fp->tpa_pool[i].skb) {
4456 BNX2X_ERR("Failed to allocate TPA "
4457 "skb pool for queue[%d] - "
4458 "disabling TPA on this "
4459 "queue!\n", j);
4460 bnx2x_free_tpa_pool(bp, fp, i);
4461 fp->disable_tpa = 1;
4462 break;
4463 }
4464 pci_unmap_addr_set((struct sw_rx_bd *)
4465 &bp->fp->tpa_pool[i],
4466 mapping, 0);
4467 fp->tpa_state[i] = BNX2X_TPA_STOP;
4468 }
4469 }
4470 }
4471
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004472 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004473 struct bnx2x_fastpath *fp = &bp->fp[j];
4474
4475 fp->rx_bd_cons = 0;
4476 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004477 fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004478
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004479 /* "next page" elements initialization */
4480 /* SGE ring */
4481 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
4482 struct eth_rx_sge *sge;
4483
4484 sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
4485 sge->addr_hi =
4486 cpu_to_le32(U64_HI(fp->rx_sge_mapping +
4487 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
4488 sge->addr_lo =
4489 cpu_to_le32(U64_LO(fp->rx_sge_mapping +
4490 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
4491 }
4492
4493 bnx2x_init_sge_ring_bit_mask(fp);
4494
4495 /* RX BD ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004496 for (i = 1; i <= NUM_RX_RINGS; i++) {
4497 struct eth_rx_bd *rx_bd;
4498
4499 rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
4500 rx_bd->addr_hi =
4501 cpu_to_le32(U64_HI(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004502 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004503 rx_bd->addr_lo =
4504 cpu_to_le32(U64_LO(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004505 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004506 }
4507
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004508 /* CQ ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004509 for (i = 1; i <= NUM_RCQ_RINGS; i++) {
4510 struct eth_rx_cqe_next_page *nextpg;
4511
4512 nextpg = (struct eth_rx_cqe_next_page *)
4513 &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
4514 nextpg->addr_hi =
4515 cpu_to_le32(U64_HI(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004516 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004517 nextpg->addr_lo =
4518 cpu_to_le32(U64_LO(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004519 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004520 }
4521
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004522 /* Allocate SGEs and initialize the ring elements */
4523 for (i = 0, ring_prod = 0;
4524 i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004525
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004526 if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
4527 BNX2X_ERR("was only able to allocate "
4528 "%d rx sges\n", i);
4529 BNX2X_ERR("disabling TPA for queue[%d]\n", j);
4530 /* Cleanup already allocated elements */
4531 bnx2x_free_rx_sge_range(bp, fp, ring_prod);
Eilon Greenstein32626232008-08-13 15:51:07 -07004532 bnx2x_free_tpa_pool(bp, fp, max_agg_queues);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004533 fp->disable_tpa = 1;
4534 ring_prod = 0;
4535 break;
4536 }
4537 ring_prod = NEXT_SGE_IDX(ring_prod);
4538 }
4539 fp->rx_sge_prod = ring_prod;
4540
4541 /* Allocate BDs and initialize BD ring */
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004542 fp->rx_comp_cons = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004543 cqe_ring_prod = ring_prod = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004544 for (i = 0; i < bp->rx_ring_size; i++) {
4545 if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) {
4546 BNX2X_ERR("was only able to allocate "
Eilon Greensteinde832a52009-02-12 08:36:33 +00004547 "%d rx skbs on queue[%d]\n", i, j);
4548 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004549 break;
4550 }
4551 ring_prod = NEXT_RX_IDX(ring_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004552 cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
Ilpo Järvinen53e5e962008-07-25 21:40:45 -07004553 WARN_ON(ring_prod <= i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004554 }
4555
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004556 fp->rx_bd_prod = ring_prod;
4557 /* must not have more available CQEs than BDs */
4558 fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT),
4559 cqe_ring_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004560 fp->rx_pkt = fp->rx_calls = 0;
4561
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004562 /* Warning!
4563 * this will generate an interrupt (to the TSTORM)
4564 * must only be done after chip is initialized
4565 */
4566 bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod,
4567 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004568 if (j != 0)
4569 continue;
4570
4571 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004572 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004573 U64_LO(fp->rx_comp_mapping));
4574 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004575 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004576 U64_HI(fp->rx_comp_mapping));
4577 }
4578}
4579
4580static void bnx2x_init_tx_ring(struct bnx2x *bp)
4581{
4582 int i, j;
4583
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004584 for_each_tx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004585 struct bnx2x_fastpath *fp = &bp->fp[j];
4586
4587 for (i = 1; i <= NUM_TX_RINGS; i++) {
4588 struct eth_tx_bd *tx_bd =
4589 &fp->tx_desc_ring[TX_DESC_CNT * i - 1];
4590
4591 tx_bd->addr_hi =
4592 cpu_to_le32(U64_HI(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004593 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004594 tx_bd->addr_lo =
4595 cpu_to_le32(U64_LO(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004596 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004597 }
4598
4599 fp->tx_pkt_prod = 0;
4600 fp->tx_pkt_cons = 0;
4601 fp->tx_bd_prod = 0;
4602 fp->tx_bd_cons = 0;
4603 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
4604 fp->tx_pkt = 0;
4605 }
4606}
4607
4608static void bnx2x_init_sp_ring(struct bnx2x *bp)
4609{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004610 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004611
4612 spin_lock_init(&bp->spq_lock);
4613
4614 bp->spq_left = MAX_SPQ_PENDING;
4615 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004616 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4617 bp->spq_prod_bd = bp->spq;
4618 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4619
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004620 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004621 U64_LO(bp->spq_mapping));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004622 REG_WR(bp,
4623 XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004624 U64_HI(bp->spq_mapping));
4625
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004626 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004627 bp->spq_prod_idx);
4628}
4629
4630static void bnx2x_init_context(struct bnx2x *bp)
4631{
4632 int i;
4633
4634 for_each_queue(bp, i) {
4635 struct eth_context *context = bnx2x_sp(bp, context[i].eth);
4636 struct bnx2x_fastpath *fp = &bp->fp[i];
Eilon Greensteinde832a52009-02-12 08:36:33 +00004637 u8 cl_id = fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004638 u8 sb_id = FP_SB_ID(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004639
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004640 context->ustorm_st_context.common.sb_index_numbers =
4641 BNX2X_RX_SB_INDEX_NUM;
4642 context->ustorm_st_context.common.clientId = FP_CL_ID(fp);
4643 context->ustorm_st_context.common.status_block_id = sb_id;
4644 context->ustorm_st_context.common.flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004645 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
4646 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
4647 context->ustorm_st_context.common.statistics_counter_id =
4648 cl_id;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004649 context->ustorm_st_context.common.mc_alignment_log_size =
Eilon Greenstein0f008462009-02-12 08:36:18 +00004650 BNX2X_RX_ALIGN_SHIFT;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004651 context->ustorm_st_context.common.bd_buff_size =
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07004652 bp->rx_buf_size;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004653 context->ustorm_st_context.common.bd_page_base_hi =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004654 U64_HI(fp->rx_desc_mapping);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004655 context->ustorm_st_context.common.bd_page_base_lo =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004656 U64_LO(fp->rx_desc_mapping);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004657 if (!fp->disable_tpa) {
4658 context->ustorm_st_context.common.flags |=
4659 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA |
4660 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_SGE_RING);
4661 context->ustorm_st_context.common.sge_buff_size =
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004662 (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE,
4663 (u32)0xffff);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004664 context->ustorm_st_context.common.sge_page_base_hi =
4665 U64_HI(fp->rx_sge_mapping);
4666 context->ustorm_st_context.common.sge_page_base_lo =
4667 U64_LO(fp->rx_sge_mapping);
4668 }
4669
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004670 context->ustorm_ag_context.cdu_usage =
4671 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4672 CDU_REGION_NUMBER_UCM_AG,
4673 ETH_CONNECTION_TYPE);
4674
4675 context->xstorm_st_context.tx_bd_page_base_hi =
4676 U64_HI(fp->tx_desc_mapping);
4677 context->xstorm_st_context.tx_bd_page_base_lo =
4678 U64_LO(fp->tx_desc_mapping);
4679 context->xstorm_st_context.db_data_addr_hi =
4680 U64_HI(fp->tx_prods_mapping);
4681 context->xstorm_st_context.db_data_addr_lo =
4682 U64_LO(fp->tx_prods_mapping);
4683 context->xstorm_st_context.statistics_data = (fp->cl_id |
4684 XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004685 context->cstorm_st_context.sb_index_number =
Eilon Greenstein5c862842008-08-13 15:51:48 -07004686 C_SB_ETH_TX_CQ_INDEX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004687 context->cstorm_st_context.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004688
4689 context->xstorm_ag_context.cdu_reserved =
4690 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4691 CDU_REGION_NUMBER_XCM_AG,
4692 ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004693 }
4694}
4695
4696static void bnx2x_init_ind_table(struct bnx2x *bp)
4697{
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004698 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004699 int i;
4700
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004701 if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004702 return;
4703
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004704 DP(NETIF_MSG_IFUP,
4705 "Initializing indirection table multi_mode %d\n", bp->multi_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004706 for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004707 REG_WR8(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004708 TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004709 BP_CL_ID(bp) + (i % bp->num_rx_queues));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004710}
4711
Eliezer Tamir49d66772008-02-28 11:53:13 -08004712static void bnx2x_set_client_config(struct bnx2x *bp)
4713{
Eliezer Tamir49d66772008-02-28 11:53:13 -08004714 struct tstorm_eth_client_config tstorm_client = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004715 int port = BP_PORT(bp);
4716 int i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004717
Eilon Greensteine7799c52009-01-14 21:30:27 -08004718 tstorm_client.mtu = bp->dev->mtu;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004719 tstorm_client.config_flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004720 (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
4721 TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004722#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08004723 if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
Eliezer Tamir49d66772008-02-28 11:53:13 -08004724 tstorm_client.config_flags |=
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004725 TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004726 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
4727 }
4728#endif
Eliezer Tamir49d66772008-02-28 11:53:13 -08004729
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004730 if (bp->flags & TPA_ENABLE_FLAG) {
4731 tstorm_client.max_sges_for_packet =
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08004732 SGE_PAGE_ALIGN(tstorm_client.mtu) >> SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004733 tstorm_client.max_sges_for_packet =
4734 ((tstorm_client.max_sges_for_packet +
4735 PAGES_PER_SGE - 1) & (~(PAGES_PER_SGE - 1))) >>
4736 PAGES_PER_SGE_SHIFT;
4737
4738 tstorm_client.config_flags |=
4739 TSTORM_ETH_CLIENT_CONFIG_ENABLE_SGE_RING;
4740 }
4741
Eliezer Tamir49d66772008-02-28 11:53:13 -08004742 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00004743 tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
4744
Eliezer Tamir49d66772008-02-28 11:53:13 -08004745 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004746 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
Eliezer Tamir49d66772008-02-28 11:53:13 -08004747 ((u32 *)&tstorm_client)[0]);
4748 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004749 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
Eliezer Tamir49d66772008-02-28 11:53:13 -08004750 ((u32 *)&tstorm_client)[1]);
4751 }
4752
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004753 DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
4754 ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004755}
4756
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004757static void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4758{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004759 struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004760 int mode = bp->rx_mode;
4761 int mask = (1 << BP_L_ID(bp));
4762 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004763 int i;
4764
Eilon Greenstein3196a882008-08-13 15:58:49 -07004765 DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004766
4767 switch (mode) {
4768 case BNX2X_RX_MODE_NONE: /* no Rx */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004769 tstorm_mac_filter.ucast_drop_all = mask;
4770 tstorm_mac_filter.mcast_drop_all = mask;
4771 tstorm_mac_filter.bcast_drop_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004772 break;
4773 case BNX2X_RX_MODE_NORMAL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004774 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004775 break;
4776 case BNX2X_RX_MODE_ALLMULTI:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004777 tstorm_mac_filter.mcast_accept_all = mask;
4778 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004779 break;
4780 case BNX2X_RX_MODE_PROMISC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004781 tstorm_mac_filter.ucast_accept_all = mask;
4782 tstorm_mac_filter.mcast_accept_all = mask;
4783 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004784 break;
4785 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004786 BNX2X_ERR("BAD rx mode (%d)\n", mode);
4787 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004788 }
4789
4790 for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
4791 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004792 TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004793 ((u32 *)&tstorm_mac_filter)[i]);
4794
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004795/* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004796 ((u32 *)&tstorm_mac_filter)[i]); */
4797 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004798
Eliezer Tamir49d66772008-02-28 11:53:13 -08004799 if (mode != BNX2X_RX_MODE_NONE)
4800 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004801}
4802
Eilon Greenstein471de712008-08-13 15:49:35 -07004803static void bnx2x_init_internal_common(struct bnx2x *bp)
4804{
4805 int i;
4806
Yitchak Gertner3cdf1db2008-08-25 15:24:21 -07004807 if (bp->flags & TPA_ENABLE_FLAG) {
4808 struct tstorm_eth_tpa_exist tpa = {0};
4809
4810 tpa.tpa_exist = 1;
4811
4812 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET,
4813 ((u32 *)&tpa)[0]);
4814 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET + 4,
4815 ((u32 *)&tpa)[1]);
4816 }
4817
Eilon Greenstein471de712008-08-13 15:49:35 -07004818 /* Zero this manually as its initialization is
4819 currently missing in the initTool */
4820 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4821 REG_WR(bp, BAR_USTRORM_INTMEM +
4822 USTORM_AGG_DATA_OFFSET + i * 4, 0);
4823}
4824
4825static void bnx2x_init_internal_port(struct bnx2x *bp)
4826{
4827 int port = BP_PORT(bp);
4828
4829 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4830 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4831 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4832 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4833}
4834
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004835/* Calculates the sum of vn_min_rates.
4836 It's needed for further normalizing of the min_rates.
4837 Returns:
4838 sum of vn_min_rates.
4839 or
4840 0 - if all the min_rates are 0.
4841 In the later case fainess algorithm should be deactivated.
4842 If not all min_rates are zero then those that are zeroes will be set to 1.
4843 */
4844static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
4845{
4846 int all_zero = 1;
4847 int port = BP_PORT(bp);
4848 int vn;
4849
4850 bp->vn_weight_sum = 0;
4851 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
4852 int func = 2*vn + port;
4853 u32 vn_cfg =
4854 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
4855 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
4856 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
4857
4858 /* Skip hidden vns */
4859 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
4860 continue;
4861
4862 /* If min rate is zero - set it to 1 */
4863 if (!vn_min_rate)
4864 vn_min_rate = DEF_MIN_RATE;
4865 else
4866 all_zero = 0;
4867
4868 bp->vn_weight_sum += vn_min_rate;
4869 }
4870
4871 /* ... only if all min rates are zeros - disable fairness */
4872 if (all_zero)
4873 bp->vn_weight_sum = 0;
4874}
4875
Eilon Greenstein471de712008-08-13 15:49:35 -07004876static void bnx2x_init_internal_func(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004877{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004878 struct tstorm_eth_function_common_config tstorm_config = {0};
4879 struct stats_indication_flags stats_flags = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004880 int port = BP_PORT(bp);
4881 int func = BP_FUNC(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004882 int i, j;
4883 u32 offset;
Eilon Greenstein471de712008-08-13 15:49:35 -07004884 u16 max_agg_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004885
4886 if (is_multi(bp)) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004887 tstorm_config.config_flags = MULTI_FLAGS(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004888 tstorm_config.rss_result_mask = MULTI_MASK;
4889 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004890 if (IS_E1HMF(bp))
4891 tstorm_config.config_flags |=
4892 TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004893
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004894 tstorm_config.leading_client_id = BP_L_ID(bp);
4895
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004896 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004897 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004898 (*(u32 *)&tstorm_config));
4899
Eliezer Tamirc14423f2008-02-28 11:49:42 -08004900 bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004901 bnx2x_set_storm_rx_mode(bp);
4902
Eilon Greensteinde832a52009-02-12 08:36:33 +00004903 for_each_queue(bp, i) {
4904 u8 cl_id = bp->fp[i].cl_id;
4905
4906 /* reset xstorm per client statistics */
4907 offset = BAR_XSTRORM_INTMEM +
4908 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4909 for (j = 0;
4910 j < sizeof(struct xstorm_per_client_stats) / 4; j++)
4911 REG_WR(bp, offset + j*4, 0);
4912
4913 /* reset tstorm per client statistics */
4914 offset = BAR_TSTRORM_INTMEM +
4915 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4916 for (j = 0;
4917 j < sizeof(struct tstorm_per_client_stats) / 4; j++)
4918 REG_WR(bp, offset + j*4, 0);
4919
4920 /* reset ustorm per client statistics */
4921 offset = BAR_USTRORM_INTMEM +
4922 USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4923 for (j = 0;
4924 j < sizeof(struct ustorm_per_client_stats) / 4; j++)
4925 REG_WR(bp, offset + j*4, 0);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004926 }
4927
4928 /* Init statistics related context */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004929 stats_flags.collect_eth = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004930
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004931 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004932 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004933 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004934 ((u32 *)&stats_flags)[1]);
4935
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004936 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004937 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004938 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004939 ((u32 *)&stats_flags)[1]);
4940
Eilon Greensteinde832a52009-02-12 08:36:33 +00004941 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
4942 ((u32 *)&stats_flags)[0]);
4943 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
4944 ((u32 *)&stats_flags)[1]);
4945
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004946 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004947 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004948 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004949 ((u32 *)&stats_flags)[1]);
4950
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004951 REG_WR(bp, BAR_XSTRORM_INTMEM +
4952 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4953 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4954 REG_WR(bp, BAR_XSTRORM_INTMEM +
4955 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4956 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
4957
4958 REG_WR(bp, BAR_TSTRORM_INTMEM +
4959 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4960 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4961 REG_WR(bp, BAR_TSTRORM_INTMEM +
4962 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4963 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004964
Eilon Greensteinde832a52009-02-12 08:36:33 +00004965 REG_WR(bp, BAR_USTRORM_INTMEM +
4966 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4967 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4968 REG_WR(bp, BAR_USTRORM_INTMEM +
4969 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4970 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
4971
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004972 if (CHIP_IS_E1H(bp)) {
4973 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
4974 IS_E1HMF(bp));
4975 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
4976 IS_E1HMF(bp));
4977 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
4978 IS_E1HMF(bp));
4979 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
4980 IS_E1HMF(bp));
4981
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004982 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
4983 bp->e1hov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004984 }
4985
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08004986 /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
4987 max_agg_size =
4988 min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
4989 SGE_PAGE_SIZE * PAGES_PER_SGE),
4990 (u32)0xffff);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004991 for_each_rx_queue(bp, i) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004992 struct bnx2x_fastpath *fp = &bp->fp[i];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004993
4994 REG_WR(bp, BAR_USTRORM_INTMEM +
4995 USTORM_CQE_PAGE_BASE_OFFSET(port, FP_CL_ID(fp)),
4996 U64_LO(fp->rx_comp_mapping));
4997 REG_WR(bp, BAR_USTRORM_INTMEM +
4998 USTORM_CQE_PAGE_BASE_OFFSET(port, FP_CL_ID(fp)) + 4,
4999 U64_HI(fp->rx_comp_mapping));
5000
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005001 REG_WR16(bp, BAR_USTRORM_INTMEM +
5002 USTORM_MAX_AGG_SIZE_OFFSET(port, FP_CL_ID(fp)),
5003 max_agg_size);
5004 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005005
Eilon Greenstein1c063282009-02-12 08:36:43 +00005006 /* dropless flow control */
5007 if (CHIP_IS_E1H(bp)) {
5008 struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
5009
5010 rx_pause.bd_thr_low = 250;
5011 rx_pause.cqe_thr_low = 250;
5012 rx_pause.cos = 1;
5013 rx_pause.sge_thr_low = 0;
5014 rx_pause.bd_thr_high = 350;
5015 rx_pause.cqe_thr_high = 350;
5016 rx_pause.sge_thr_high = 0;
5017
5018 for_each_rx_queue(bp, i) {
5019 struct bnx2x_fastpath *fp = &bp->fp[i];
5020
5021 if (!fp->disable_tpa) {
5022 rx_pause.sge_thr_low = 150;
5023 rx_pause.sge_thr_high = 250;
5024 }
5025
5026
5027 offset = BAR_USTRORM_INTMEM +
5028 USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
5029 fp->cl_id);
5030 for (j = 0;
5031 j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
5032 j++)
5033 REG_WR(bp, offset + j*4,
5034 ((u32 *)&rx_pause)[j]);
5035 }
5036 }
5037
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005038 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
5039
5040 /* Init rate shaping and fairness contexts */
5041 if (IS_E1HMF(bp)) {
5042 int vn;
5043
5044 /* During init there is no active link
5045 Until link is up, set link rate to 10Gbps */
5046 bp->link_vars.line_speed = SPEED_10000;
5047 bnx2x_init_port_minmax(bp);
5048
5049 bnx2x_calc_vn_weight_sum(bp);
5050
5051 for (vn = VN_0; vn < E1HVN_MAX; vn++)
5052 bnx2x_init_vn_minmax(bp, 2*vn + port);
5053
5054 /* Enable rate shaping and fairness */
5055 bp->cmng.flags.cmng_enables =
5056 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
5057 if (bp->vn_weight_sum)
5058 bp->cmng.flags.cmng_enables |=
5059 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
5060 else
5061 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
5062 " fairness will be disabled\n");
5063 } else {
5064 /* rate shaping and fairness are disabled */
5065 DP(NETIF_MSG_IFUP,
5066 "single function mode minmax will be disabled\n");
5067 }
5068
5069
5070 /* Store it to internal memory */
5071 if (bp->port.pmf)
5072 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
5073 REG_WR(bp, BAR_XSTRORM_INTMEM +
5074 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
5075 ((u32 *)(&bp->cmng))[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005076}
5077
Eilon Greenstein471de712008-08-13 15:49:35 -07005078static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5079{
5080 switch (load_code) {
5081 case FW_MSG_CODE_DRV_LOAD_COMMON:
5082 bnx2x_init_internal_common(bp);
5083 /* no break */
5084
5085 case FW_MSG_CODE_DRV_LOAD_PORT:
5086 bnx2x_init_internal_port(bp);
5087 /* no break */
5088
5089 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5090 bnx2x_init_internal_func(bp);
5091 break;
5092
5093 default:
5094 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5095 break;
5096 }
5097}
5098
5099static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005100{
5101 int i;
5102
5103 for_each_queue(bp, i) {
5104 struct bnx2x_fastpath *fp = &bp->fp[i];
5105
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005106 fp->bp = bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005107 fp->state = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005108 fp->index = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005109 fp->cl_id = BP_L_ID(bp) + i;
5110 fp->sb_id = fp->cl_id;
5111 DP(NETIF_MSG_IFUP,
5112 "bnx2x_init_sb(%p,%p) index %d cl_id %d sb %d\n",
5113 bp, fp->status_blk, i, FP_CL_ID(fp), FP_SB_ID(fp));
Eilon Greenstein5c862842008-08-13 15:51:48 -07005114 bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
5115 FP_SB_ID(fp));
5116 bnx2x_update_fpsb_idx(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005117 }
5118
Eilon Greenstein5c862842008-08-13 15:51:48 -07005119 bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
5120 DEF_SB_ID);
5121 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005122 bnx2x_update_coalesce(bp);
5123 bnx2x_init_rx_rings(bp);
5124 bnx2x_init_tx_ring(bp);
5125 bnx2x_init_sp_ring(bp);
5126 bnx2x_init_context(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07005127 bnx2x_init_internal(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005128 bnx2x_init_ind_table(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005129 bnx2x_stats_init(bp);
5130
5131 /* At this point, we are ready for interrupts */
5132 atomic_set(&bp->intr_sem, 0);
5133
5134 /* flush all before enabling interrupts */
5135 mb();
5136 mmiowb();
5137
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08005138 bnx2x_int_enable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005139}
5140
5141/* end of nic init */
5142
5143/*
5144 * gzip service functions
5145 */
5146
5147static int bnx2x_gunzip_init(struct bnx2x *bp)
5148{
5149 bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE,
5150 &bp->gunzip_mapping);
5151 if (bp->gunzip_buf == NULL)
5152 goto gunzip_nomem1;
5153
5154 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5155 if (bp->strm == NULL)
5156 goto gunzip_nomem2;
5157
5158 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5159 GFP_KERNEL);
5160 if (bp->strm->workspace == NULL)
5161 goto gunzip_nomem3;
5162
5163 return 0;
5164
5165gunzip_nomem3:
5166 kfree(bp->strm);
5167 bp->strm = NULL;
5168
5169gunzip_nomem2:
5170 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5171 bp->gunzip_mapping);
5172 bp->gunzip_buf = NULL;
5173
5174gunzip_nomem1:
5175 printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005176 " un-compression\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005177 return -ENOMEM;
5178}
5179
5180static void bnx2x_gunzip_end(struct bnx2x *bp)
5181{
5182 kfree(bp->strm->workspace);
5183
5184 kfree(bp->strm);
5185 bp->strm = NULL;
5186
5187 if (bp->gunzip_buf) {
5188 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5189 bp->gunzip_mapping);
5190 bp->gunzip_buf = NULL;
5191 }
5192}
5193
5194static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len)
5195{
5196 int n, rc;
5197
5198 /* check gzip header */
5199 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
5200 return -EINVAL;
5201
5202 n = 10;
5203
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005204#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005205
5206 if (zbuf[3] & FNAME)
5207 while ((zbuf[n++] != 0) && (n < len));
5208
5209 bp->strm->next_in = zbuf + n;
5210 bp->strm->avail_in = len - n;
5211 bp->strm->next_out = bp->gunzip_buf;
5212 bp->strm->avail_out = FW_BUF_SIZE;
5213
5214 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5215 if (rc != Z_OK)
5216 return rc;
5217
5218 rc = zlib_inflate(bp->strm, Z_FINISH);
5219 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5220 printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
5221 bp->dev->name, bp->strm->msg);
5222
5223 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5224 if (bp->gunzip_outlen & 0x3)
5225 printk(KERN_ERR PFX "%s: Firmware decompression error:"
5226 " gunzip_outlen (%d) not aligned\n",
5227 bp->dev->name, bp->gunzip_outlen);
5228 bp->gunzip_outlen >>= 2;
5229
5230 zlib_inflateEnd(bp->strm);
5231
5232 if (rc == Z_STREAM_END)
5233 return 0;
5234
5235 return rc;
5236}
5237
5238/* nic load/unload */
5239
5240/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005241 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005242 */
5243
5244/* send a NIG loopback debug packet */
5245static void bnx2x_lb_pckt(struct bnx2x *bp)
5246{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005247 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005248
5249 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005250 wb_write[0] = 0x55555555;
5251 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005252 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005253 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005254
5255 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005256 wb_write[0] = 0x09000000;
5257 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005258 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005259 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005260}
5261
5262/* some of the internal memories
5263 * are not directly readable from the driver
5264 * to test them we send debug packets
5265 */
5266static int bnx2x_int_mem_test(struct bnx2x *bp)
5267{
5268 int factor;
5269 int count, i;
5270 u32 val = 0;
5271
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005272 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005273 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005274 else if (CHIP_REV_IS_EMUL(bp))
5275 factor = 200;
5276 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005277 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005278
5279 DP(NETIF_MSG_HW, "start part1\n");
5280
5281 /* Disable inputs of parser neighbor blocks */
5282 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5283 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5284 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005285 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005286
5287 /* Write 0 to parser credits for CFC search request */
5288 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5289
5290 /* send Ethernet packet */
5291 bnx2x_lb_pckt(bp);
5292
5293 /* TODO do i reset NIG statistic? */
5294 /* Wait until NIG register shows 1 packet of size 0x10 */
5295 count = 1000 * factor;
5296 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005297
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005298 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5299 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005300 if (val == 0x10)
5301 break;
5302
5303 msleep(10);
5304 count--;
5305 }
5306 if (val != 0x10) {
5307 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5308 return -1;
5309 }
5310
5311 /* Wait until PRS register shows 1 packet */
5312 count = 1000 * factor;
5313 while (count) {
5314 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005315 if (val == 1)
5316 break;
5317
5318 msleep(10);
5319 count--;
5320 }
5321 if (val != 0x1) {
5322 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5323 return -2;
5324 }
5325
5326 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005327 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005328 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005329 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005330 msleep(50);
5331 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
5332 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
5333
5334 DP(NETIF_MSG_HW, "part2\n");
5335
5336 /* Disable inputs of parser neighbor blocks */
5337 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5338 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5339 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005340 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005341
5342 /* Write 0 to parser credits for CFC search request */
5343 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5344
5345 /* send 10 Ethernet packets */
5346 for (i = 0; i < 10; i++)
5347 bnx2x_lb_pckt(bp);
5348
5349 /* Wait until NIG register shows 10 + 1
5350 packets of size 11*0x10 = 0xb0 */
5351 count = 1000 * factor;
5352 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005353
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005354 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5355 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005356 if (val == 0xb0)
5357 break;
5358
5359 msleep(10);
5360 count--;
5361 }
5362 if (val != 0xb0) {
5363 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5364 return -3;
5365 }
5366
5367 /* Wait until PRS register shows 2 packets */
5368 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5369 if (val != 2)
5370 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5371
5372 /* Write 1 to parser credits for CFC search request */
5373 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5374
5375 /* Wait until PRS register shows 3 packets */
5376 msleep(10 * factor);
5377 /* Wait until NIG register shows 1 packet of size 0x10 */
5378 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5379 if (val != 3)
5380 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5381
5382 /* clear NIG EOP FIFO */
5383 for (i = 0; i < 11; i++)
5384 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5385 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5386 if (val != 1) {
5387 BNX2X_ERR("clear of NIG failed\n");
5388 return -4;
5389 }
5390
5391 /* Reset and init BRB, PRS, NIG */
5392 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5393 msleep(50);
5394 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5395 msleep(50);
5396 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
5397 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
5398#ifndef BCM_ISCSI
5399 /* set NIC mode */
5400 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5401#endif
5402
5403 /* Enable inputs of parser neighbor blocks */
5404 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5405 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5406 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005407 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005408
5409 DP(NETIF_MSG_HW, "done\n");
5410
5411 return 0; /* OK */
5412}
5413
5414static void enable_blocks_attention(struct bnx2x *bp)
5415{
5416 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5417 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5418 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5419 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5420 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5421 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5422 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5423 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5424 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005425/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5426/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005427 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5428 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5429 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005430/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5431/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005432 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5433 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5434 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5435 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005436/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5437/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5438 if (CHIP_REV_IS_FPGA(bp))
5439 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5440 else
5441 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005442 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5443 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5444 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005445/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5446/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005447 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5448 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005449/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5450 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005451}
5452
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005453
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005454static void bnx2x_reset_common(struct bnx2x *bp)
5455{
5456 /* reset_common */
5457 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5458 0xd3ffff7f);
5459 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
5460}
5461
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005462static int bnx2x_init_common(struct bnx2x *bp)
5463{
5464 u32 val, i;
5465
5466 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
5467
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005468 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005469 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5470 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
5471
5472 bnx2x_init_block(bp, MISC_COMMON_START, MISC_COMMON_END);
5473 if (CHIP_IS_E1H(bp))
5474 REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
5475
5476 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
5477 msleep(30);
5478 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
5479
5480 bnx2x_init_block(bp, PXP_COMMON_START, PXP_COMMON_END);
5481 if (CHIP_IS_E1(bp)) {
5482 /* enable HW interrupt from PXP on USDM overflow
5483 bit 16 on INT_MASK_0 */
5484 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005485 }
5486
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005487 bnx2x_init_block(bp, PXP2_COMMON_START, PXP2_COMMON_END);
5488 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005489
5490#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005491 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5492 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5493 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5494 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5495 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005496 /* make sure this value is 0 */
5497 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005498
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005499/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5500 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5501 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5502 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5503 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005504#endif
5505
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005506 REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005507#ifdef BCM_ISCSI
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005508 REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
5509 REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
5510 REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005511#endif
5512
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005513 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5514 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005515
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005516 /* let the HW do it's magic ... */
5517 msleep(100);
5518 /* finish PXP init */
5519 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5520 if (val != 1) {
5521 BNX2X_ERR("PXP2 CFG failed\n");
5522 return -EBUSY;
5523 }
5524 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5525 if (val != 1) {
5526 BNX2X_ERR("PXP2 RD_INIT failed\n");
5527 return -EBUSY;
5528 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005529
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005530 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5531 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005532
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005533 bnx2x_init_block(bp, DMAE_COMMON_START, DMAE_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005534
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005535 /* clean the DMAE memory */
5536 bp->dmae_ready = 1;
5537 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005538
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005539 bnx2x_init_block(bp, TCM_COMMON_START, TCM_COMMON_END);
5540 bnx2x_init_block(bp, UCM_COMMON_START, UCM_COMMON_END);
5541 bnx2x_init_block(bp, CCM_COMMON_START, CCM_COMMON_END);
5542 bnx2x_init_block(bp, XCM_COMMON_START, XCM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005543
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005544 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5545 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5546 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5547 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5548
5549 bnx2x_init_block(bp, QM_COMMON_START, QM_COMMON_END);
5550 /* soft reset pulse */
5551 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5552 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005553
5554#ifdef BCM_ISCSI
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005555 bnx2x_init_block(bp, TIMERS_COMMON_START, TIMERS_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005556#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005557
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005558 bnx2x_init_block(bp, DQ_COMMON_START, DQ_COMMON_END);
5559 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
5560 if (!CHIP_REV_IS_SLOW(bp)) {
5561 /* enable hw interrupt from doorbell Q */
5562 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5563 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005564
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005565 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005566 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005567 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005568 /* set NIC mode */
5569 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005570 if (CHIP_IS_E1H(bp))
5571 REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005572
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005573 bnx2x_init_block(bp, TSDM_COMMON_START, TSDM_COMMON_END);
5574 bnx2x_init_block(bp, CSDM_COMMON_START, CSDM_COMMON_END);
5575 bnx2x_init_block(bp, USDM_COMMON_START, USDM_COMMON_END);
5576 bnx2x_init_block(bp, XSDM_COMMON_START, XSDM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005577
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005578 if (CHIP_IS_E1H(bp)) {
5579 bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0,
5580 STORM_INTMEM_SIZE_E1H/2);
5581 bnx2x_init_fill(bp,
5582 TSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5583 0, STORM_INTMEM_SIZE_E1H/2);
5584 bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0,
5585 STORM_INTMEM_SIZE_E1H/2);
5586 bnx2x_init_fill(bp,
5587 CSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5588 0, STORM_INTMEM_SIZE_E1H/2);
5589 bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0,
5590 STORM_INTMEM_SIZE_E1H/2);
5591 bnx2x_init_fill(bp,
5592 XSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5593 0, STORM_INTMEM_SIZE_E1H/2);
5594 bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0,
5595 STORM_INTMEM_SIZE_E1H/2);
5596 bnx2x_init_fill(bp,
5597 USTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5598 0, STORM_INTMEM_SIZE_E1H/2);
5599 } else { /* E1 */
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005600 bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0,
5601 STORM_INTMEM_SIZE_E1);
5602 bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0,
5603 STORM_INTMEM_SIZE_E1);
5604 bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0,
5605 STORM_INTMEM_SIZE_E1);
5606 bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0,
5607 STORM_INTMEM_SIZE_E1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005608 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005609
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005610 bnx2x_init_block(bp, TSEM_COMMON_START, TSEM_COMMON_END);
5611 bnx2x_init_block(bp, USEM_COMMON_START, USEM_COMMON_END);
5612 bnx2x_init_block(bp, CSEM_COMMON_START, CSEM_COMMON_END);
5613 bnx2x_init_block(bp, XSEM_COMMON_START, XSEM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005614
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005615 /* sync semi rtc */
5616 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5617 0x80000000);
5618 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5619 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005620
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005621 bnx2x_init_block(bp, UPB_COMMON_START, UPB_COMMON_END);
5622 bnx2x_init_block(bp, XPB_COMMON_START, XPB_COMMON_END);
5623 bnx2x_init_block(bp, PBF_COMMON_START, PBF_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005624
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005625 REG_WR(bp, SRC_REG_SOFT_RST, 1);
5626 for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) {
5627 REG_WR(bp, i, 0xc0cac01a);
5628 /* TODO: replace with something meaningful */
5629 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005630 bnx2x_init_block(bp, SRCH_COMMON_START, SRCH_COMMON_END);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005631 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005632
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005633 if (sizeof(union cdu_context) != 1024)
5634 /* we currently assume that a context is 1024 bytes */
5635 printk(KERN_ALERT PFX "please adjust the size of"
5636 " cdu_context(%ld)\n", (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005637
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005638 bnx2x_init_block(bp, CDU_COMMON_START, CDU_COMMON_END);
5639 val = (4 << 24) + (0 << 12) + 1024;
5640 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
5641 if (CHIP_IS_E1(bp)) {
5642 /* !!! fix pxp client crdit until excel update */
5643 REG_WR(bp, CDU_REG_CDU_DEBUG, 0x264);
5644 REG_WR(bp, CDU_REG_CDU_DEBUG, 0);
5645 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005646
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005647 bnx2x_init_block(bp, CFC_COMMON_START, CFC_COMMON_END);
5648 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005649 /* enable context validation interrupt from CFC */
5650 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5651
5652 /* set the thresholds to prevent CFC/CDU race */
5653 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005654
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005655 bnx2x_init_block(bp, HC_COMMON_START, HC_COMMON_END);
5656 bnx2x_init_block(bp, MISC_AEU_COMMON_START, MISC_AEU_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005657
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005658 /* PXPCS COMMON comes here */
5659 /* Reset PCIE errors for debug */
5660 REG_WR(bp, 0x2814, 0xffffffff);
5661 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005662
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005663 /* EMAC0 COMMON comes here */
5664 /* EMAC1 COMMON comes here */
5665 /* DBU COMMON comes here */
5666 /* DBG COMMON comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005667
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005668 bnx2x_init_block(bp, NIG_COMMON_START, NIG_COMMON_END);
5669 if (CHIP_IS_E1H(bp)) {
5670 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
5671 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
5672 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005673
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005674 if (CHIP_REV_IS_SLOW(bp))
5675 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005676
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005677 /* finish CFC init */
5678 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5679 if (val != 1) {
5680 BNX2X_ERR("CFC LL_INIT failed\n");
5681 return -EBUSY;
5682 }
5683 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5684 if (val != 1) {
5685 BNX2X_ERR("CFC AC_INIT failed\n");
5686 return -EBUSY;
5687 }
5688 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5689 if (val != 1) {
5690 BNX2X_ERR("CFC CAM_INIT failed\n");
5691 return -EBUSY;
5692 }
5693 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005694
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005695 /* read NIG statistic
5696 to see if this is our first up since powerup */
5697 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5698 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005699
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005700 /* do internal memory self test */
5701 if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
5702 BNX2X_ERR("internal mem self test failed\n");
5703 return -EBUSY;
5704 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005705
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005706 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein46c6a672009-02-12 08:36:58 +00005707 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
5708 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
5709 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5710 bp->port.need_hw_lock = 1;
5711 break;
5712
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005713 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005714 /* Fan failure is indicated by SPIO 5 */
5715 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5716 MISC_REGISTERS_SPIO_INPUT_HI_Z);
Eliezer Tamirf1410642008-02-28 11:51:50 -08005717
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005718 /* set to active low mode */
5719 val = REG_RD(bp, MISC_REG_SPIO_INT);
5720 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
Eliezer Tamirf1410642008-02-28 11:51:50 -08005721 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005722 REG_WR(bp, MISC_REG_SPIO_INT, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08005723
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005724 /* enable interrupt to signal the IGU */
5725 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5726 val |= (1 << MISC_REGISTERS_SPIO_5);
5727 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5728 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08005729
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005730 default:
5731 break;
5732 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08005733
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005734 /* clear PXP2 attentions */
5735 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005736
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005737 enable_blocks_attention(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005738
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005739 if (!BP_NOMCP(bp)) {
5740 bnx2x_acquire_phy_lock(bp);
5741 bnx2x_common_init_phy(bp, bp->common.shmem_base);
5742 bnx2x_release_phy_lock(bp);
5743 } else
5744 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5745
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005746 return 0;
5747}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005748
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005749static int bnx2x_init_port(struct bnx2x *bp)
5750{
5751 int port = BP_PORT(bp);
Eilon Greenstein1c063282009-02-12 08:36:43 +00005752 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005753 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005754
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005755 DP(BNX2X_MSG_MCP, "starting port init port %x\n", port);
5756
5757 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005758
5759 /* Port PXP comes here */
5760 /* Port PXP2 comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005761#ifdef BCM_ISCSI
5762 /* Port0 1
5763 * Port1 385 */
5764 i++;
5765 wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping);
5766 wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping);
5767 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5768 REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
5769
5770 /* Port0 2
5771 * Port1 386 */
5772 i++;
5773 wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping);
5774 wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping);
5775 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5776 REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
5777
5778 /* Port0 3
5779 * Port1 387 */
5780 i++;
5781 wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping);
5782 wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping);
5783 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5784 REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
5785#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005786 /* Port CMs come here */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005787 bnx2x_init_block(bp, (port ? XCM_PORT1_START : XCM_PORT0_START),
5788 (port ? XCM_PORT1_END : XCM_PORT0_END));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005789
5790 /* Port QM comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005791#ifdef BCM_ISCSI
5792 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20);
5793 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31);
5794
5795 bnx2x_init_block(bp, func ? TIMERS_PORT1_START : TIMERS_PORT0_START,
5796 func ? TIMERS_PORT1_END : TIMERS_PORT0_END);
5797#endif
5798 /* Port DQ comes here */
Eilon Greenstein1c063282009-02-12 08:36:43 +00005799
5800 bnx2x_init_block(bp, (port ? BRB1_PORT1_START : BRB1_PORT0_START),
5801 (port ? BRB1_PORT1_END : BRB1_PORT0_END));
5802 if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
5803 /* no pause for emulation and FPGA */
5804 low = 0;
5805 high = 513;
5806 } else {
5807 if (IS_E1HMF(bp))
5808 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
5809 else if (bp->dev->mtu > 4096) {
5810 if (bp->flags & ONE_PORT_FLAG)
5811 low = 160;
5812 else {
5813 val = bp->dev->mtu;
5814 /* (24*1024 + val*4)/256 */
5815 low = 96 + (val/64) + ((val % 64) ? 1 : 0);
5816 }
5817 } else
5818 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
5819 high = low + 56; /* 14*1024/256 */
5820 }
5821 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
5822 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
5823
5824
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005825 /* Port PRS comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005826 /* Port TSDM comes here */
5827 /* Port CSDM comes here */
5828 /* Port USDM comes here */
5829 /* Port XSDM comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005830 bnx2x_init_block(bp, port ? TSEM_PORT1_START : TSEM_PORT0_START,
5831 port ? TSEM_PORT1_END : TSEM_PORT0_END);
5832 bnx2x_init_block(bp, port ? USEM_PORT1_START : USEM_PORT0_START,
5833 port ? USEM_PORT1_END : USEM_PORT0_END);
5834 bnx2x_init_block(bp, port ? CSEM_PORT1_START : CSEM_PORT0_START,
5835 port ? CSEM_PORT1_END : CSEM_PORT0_END);
5836 bnx2x_init_block(bp, port ? XSEM_PORT1_START : XSEM_PORT0_START,
5837 port ? XSEM_PORT1_END : XSEM_PORT0_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005838 /* Port UPB comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005839 /* Port XPB comes here */
5840
5841 bnx2x_init_block(bp, port ? PBF_PORT1_START : PBF_PORT0_START,
5842 port ? PBF_PORT1_END : PBF_PORT0_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005843
5844 /* configure PBF to work without PAUSE mtu 9000 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005845 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005846
5847 /* update threshold */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005848 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005849 /* update init credit */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005850 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005851
5852 /* probe changes */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005853 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005854 msleep(5);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005855 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005856
5857#ifdef BCM_ISCSI
5858 /* tell the searcher where the T2 table is */
5859 REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64);
5860
5861 wb_write[0] = U64_LO(bp->t2_mapping);
5862 wb_write[1] = U64_HI(bp->t2_mapping);
5863 REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2);
5864 wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64);
5865 wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64);
5866 REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2);
5867
5868 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10);
5869 /* Port SRCH comes here */
5870#endif
5871 /* Port CDU comes here */
5872 /* Port CFC comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005873
5874 if (CHIP_IS_E1(bp)) {
5875 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
5876 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
5877 }
5878 bnx2x_init_block(bp, port ? HC_PORT1_START : HC_PORT0_START,
5879 port ? HC_PORT1_END : HC_PORT0_END);
5880
5881 bnx2x_init_block(bp, port ? MISC_AEU_PORT1_START :
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005882 MISC_AEU_PORT0_START,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005883 port ? MISC_AEU_PORT1_END : MISC_AEU_PORT0_END);
5884 /* init aeu_mask_attn_func_0/1:
5885 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
5886 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
5887 * bits 4-7 are used for "per vn group attention" */
5888 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
5889 (IS_E1HMF(bp) ? 0xF7 : 0x7));
5890
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005891 /* Port PXPCS comes here */
5892 /* Port EMAC0 comes here */
5893 /* Port EMAC1 comes here */
5894 /* Port DBU comes here */
5895 /* Port DBG comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005896 bnx2x_init_block(bp, port ? NIG_PORT1_START : NIG_PORT0_START,
5897 port ? NIG_PORT1_END : NIG_PORT0_END);
5898
5899 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
5900
5901 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005902 /* 0x2 disable e1hov, 0x1 enable */
5903 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
5904 (IS_E1HMF(bp) ? 0x1 : 0x2));
5905
Eilon Greenstein1c063282009-02-12 08:36:43 +00005906 /* support pause requests from USDM, TSDM and BRB */
5907 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0 + port*4, 0x7);
5908
5909 {
5910 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
5911 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
5912 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
5913 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005914 }
5915
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005916 /* Port MCP comes here */
5917 /* Port DMAE comes here */
5918
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005919 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00005920 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5921 {
5922 u32 swap_val, swap_override, aeu_gpio_mask, offset;
5923
5924 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
5925 MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
5926
5927 /* The GPIO should be swapped if the swap register is
5928 set and active */
5929 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5930 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5931
5932 /* Select function upon port-swap configuration */
5933 if (port == 0) {
5934 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5935 aeu_gpio_mask = (swap_val && swap_override) ?
5936 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
5937 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
5938 } else {
5939 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
5940 aeu_gpio_mask = (swap_val && swap_override) ?
5941 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
5942 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
5943 }
5944 val = REG_RD(bp, offset);
5945 /* add GPIO3 to group */
5946 val |= aeu_gpio_mask;
5947 REG_WR(bp, offset, val);
5948 }
5949 break;
5950
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005951 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eliezer Tamirf1410642008-02-28 11:51:50 -08005952 /* add SPIO 5 to group 0 */
5953 val = REG_RD(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5954 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
5955 REG_WR(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0, val);
5956 break;
5957
5958 default:
5959 break;
5960 }
5961
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07005962 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005963
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005964 return 0;
5965}
5966
5967#define ILT_PER_FUNC (768/2)
5968#define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
5969/* the phys address is shifted right 12 bits and has an added
5970 1=valid bit added to the 53rd bit
5971 then since this is a wide register(TM)
5972 we split it into two 32 bit writes
5973 */
5974#define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
5975#define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
5976#define PXP_ONE_ILT(x) (((x) << 10) | x)
5977#define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
5978
5979#define CNIC_ILT_LINES 0
5980
5981static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
5982{
5983 int reg;
5984
5985 if (CHIP_IS_E1H(bp))
5986 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
5987 else /* E1 */
5988 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
5989
5990 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
5991}
5992
5993static int bnx2x_init_func(struct bnx2x *bp)
5994{
5995 int port = BP_PORT(bp);
5996 int func = BP_FUNC(bp);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005997 u32 addr, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005998 int i;
5999
6000 DP(BNX2X_MSG_MCP, "starting func init func %x\n", func);
6001
Eilon Greenstein8badd272009-02-12 08:36:15 +00006002 /* set MSI reconfigure capability */
6003 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6004 val = REG_RD(bp, addr);
6005 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6006 REG_WR(bp, addr, val);
6007
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006008 i = FUNC_ILT_BASE(func);
6009
6010 bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
6011 if (CHIP_IS_E1H(bp)) {
6012 REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
6013 REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
6014 } else /* E1 */
6015 REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
6016 PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
6017
6018
6019 if (CHIP_IS_E1H(bp)) {
6020 for (i = 0; i < 9; i++)
6021 bnx2x_init_block(bp,
6022 cm_start[func][i], cm_end[func][i]);
6023
6024 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6025 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
6026 }
6027
6028 /* HC init per function */
6029 if (CHIP_IS_E1H(bp)) {
6030 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6031
6032 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6033 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6034 }
6035 bnx2x_init_block(bp, hc_limits[func][0], hc_limits[func][1]);
6036
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006037 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006038 REG_WR(bp, 0x2114, 0xffffffff);
6039 REG_WR(bp, 0x2120, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006040
6041 return 0;
6042}
6043
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006044static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
6045{
6046 int i, rc = 0;
6047
6048 DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
6049 BP_FUNC(bp), load_code);
6050
6051 bp->dmae_ready = 0;
6052 mutex_init(&bp->dmae_mutex);
6053 bnx2x_gunzip_init(bp);
6054
6055 switch (load_code) {
6056 case FW_MSG_CODE_DRV_LOAD_COMMON:
6057 rc = bnx2x_init_common(bp);
6058 if (rc)
6059 goto init_hw_err;
6060 /* no break */
6061
6062 case FW_MSG_CODE_DRV_LOAD_PORT:
6063 bp->dmae_ready = 1;
6064 rc = bnx2x_init_port(bp);
6065 if (rc)
6066 goto init_hw_err;
6067 /* no break */
6068
6069 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
6070 bp->dmae_ready = 1;
6071 rc = bnx2x_init_func(bp);
6072 if (rc)
6073 goto init_hw_err;
6074 break;
6075
6076 default:
6077 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6078 break;
6079 }
6080
6081 if (!BP_NOMCP(bp)) {
6082 int func = BP_FUNC(bp);
6083
6084 bp->fw_drv_pulse_wr_seq =
6085 (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
6086 DRV_PULSE_SEQ_MASK);
6087 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
6088 DP(BNX2X_MSG_MCP, "drv_pulse 0x%x func_stx 0x%x\n",
6089 bp->fw_drv_pulse_wr_seq, bp->func_stx);
6090 } else
6091 bp->func_stx = 0;
6092
6093 /* this needs to be done before gunzip end */
6094 bnx2x_zero_def_sb(bp);
6095 for_each_queue(bp, i)
6096 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
6097
6098init_hw_err:
6099 bnx2x_gunzip_end(bp);
6100
6101 return rc;
6102}
6103
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006104/* send the MCP a request, block until there is a reply */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006105static u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
6106{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006107 int func = BP_FUNC(bp);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006108 u32 seq = ++bp->fw_seq;
6109 u32 rc = 0;
Eilon Greenstein19680c42008-08-13 15:47:33 -07006110 u32 cnt = 1;
6111 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006112
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006113 SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
Eliezer Tamirf1410642008-02-28 11:51:50 -08006114 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006115
Eilon Greenstein19680c42008-08-13 15:47:33 -07006116 do {
6117 /* let the FW do it's magic ... */
6118 msleep(delay);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006119
Eilon Greenstein19680c42008-08-13 15:47:33 -07006120 rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006121
Eilon Greenstein19680c42008-08-13 15:47:33 -07006122 /* Give the FW up to 2 second (200*10ms) */
6123 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200));
6124
6125 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
6126 cnt*delay, rc, seq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006127
6128 /* is this a reply to our command? */
6129 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
6130 rc &= FW_MSG_CODE_MASK;
Eliezer Tamirf1410642008-02-28 11:51:50 -08006131
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006132 } else {
6133 /* FW BUG! */
6134 BNX2X_ERR("FW failed to respond!\n");
6135 bnx2x_fw_dump(bp);
6136 rc = 0;
6137 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08006138
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006139 return rc;
6140}
6141
6142static void bnx2x_free_mem(struct bnx2x *bp)
6143{
6144
6145#define BNX2X_PCI_FREE(x, y, size) \
6146 do { \
6147 if (x) { \
6148 pci_free_consistent(bp->pdev, size, x, y); \
6149 x = NULL; \
6150 y = 0; \
6151 } \
6152 } while (0)
6153
6154#define BNX2X_FREE(x) \
6155 do { \
6156 if (x) { \
6157 vfree(x); \
6158 x = NULL; \
6159 } \
6160 } while (0)
6161
6162 int i;
6163
6164 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006165 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006166 for_each_queue(bp, i) {
6167
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006168 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006169 BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
6170 bnx2x_fp(bp, i, status_blk_mapping),
6171 sizeof(struct host_status_block) +
6172 sizeof(struct eth_tx_db_data));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006173 }
6174 /* Rx */
6175 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006176
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006177 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006178 BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
6179 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
6180 bnx2x_fp(bp, i, rx_desc_mapping),
6181 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6182
6183 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
6184 bnx2x_fp(bp, i, rx_comp_mapping),
6185 sizeof(struct eth_fast_path_rx_cqe) *
6186 NUM_RCQ_BD);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006187
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006188 /* SGE ring */
Eilon Greenstein32626232008-08-13 15:51:07 -07006189 BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006190 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
6191 bnx2x_fp(bp, i, rx_sge_mapping),
6192 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
6193 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006194 /* Tx */
6195 for_each_tx_queue(bp, i) {
6196
6197 /* fastpath tx rings: tx_buf tx_desc */
6198 BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
6199 BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
6200 bnx2x_fp(bp, i, tx_desc_mapping),
6201 sizeof(struct eth_tx_bd) * NUM_TX_BD);
6202 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006203 /* end of fastpath */
6204
6205 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006206 sizeof(struct host_def_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006207
6208 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006209 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006210
6211#ifdef BCM_ISCSI
6212 BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
6213 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
6214 BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
6215 BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
6216#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006217 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006218
6219#undef BNX2X_PCI_FREE
6220#undef BNX2X_KFREE
6221}
6222
6223static int bnx2x_alloc_mem(struct bnx2x *bp)
6224{
6225
6226#define BNX2X_PCI_ALLOC(x, y, size) \
6227 do { \
6228 x = pci_alloc_consistent(bp->pdev, size, y); \
6229 if (x == NULL) \
6230 goto alloc_mem_err; \
6231 memset(x, 0, size); \
6232 } while (0)
6233
6234#define BNX2X_ALLOC(x, size) \
6235 do { \
6236 x = vmalloc(size); \
6237 if (x == NULL) \
6238 goto alloc_mem_err; \
6239 memset(x, 0, size); \
6240 } while (0)
6241
6242 int i;
6243
6244 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006245 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006246 for_each_queue(bp, i) {
6247 bnx2x_fp(bp, i, bp) = bp;
6248
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006249 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006250 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
6251 &bnx2x_fp(bp, i, status_blk_mapping),
6252 sizeof(struct host_status_block) +
6253 sizeof(struct eth_tx_db_data));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006254 }
6255 /* Rx */
6256 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006257
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006258 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006259 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
6260 sizeof(struct sw_rx_bd) * NUM_RX_BD);
6261 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
6262 &bnx2x_fp(bp, i, rx_desc_mapping),
6263 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6264
6265 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
6266 &bnx2x_fp(bp, i, rx_comp_mapping),
6267 sizeof(struct eth_fast_path_rx_cqe) *
6268 NUM_RCQ_BD);
6269
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006270 /* SGE ring */
6271 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
6272 sizeof(struct sw_rx_page) * NUM_RX_SGE);
6273 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
6274 &bnx2x_fp(bp, i, rx_sge_mapping),
6275 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006276 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006277 /* Tx */
6278 for_each_tx_queue(bp, i) {
6279
6280 bnx2x_fp(bp, i, hw_tx_prods) =
6281 (void *)(bnx2x_fp(bp, i, status_blk) + 1);
6282
6283 bnx2x_fp(bp, i, tx_prods_mapping) =
6284 bnx2x_fp(bp, i, status_blk_mapping) +
6285 sizeof(struct host_status_block);
6286
6287 /* fastpath tx rings: tx_buf tx_desc */
6288 BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
6289 sizeof(struct sw_tx_bd) * NUM_TX_BD);
6290 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
6291 &bnx2x_fp(bp, i, tx_desc_mapping),
6292 sizeof(struct eth_tx_bd) * NUM_TX_BD);
6293 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006294 /* end of fastpath */
6295
6296 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6297 sizeof(struct host_def_status_block));
6298
6299 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6300 sizeof(struct bnx2x_slowpath));
6301
6302#ifdef BCM_ISCSI
6303 BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
6304
6305 /* Initialize T1 */
6306 for (i = 0; i < 64*1024; i += 64) {
6307 *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL;
6308 *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL;
6309 }
6310
6311 /* allocate searcher T2 table
6312 we allocate 1/4 of alloc num for T2
6313 (which is not entered into the ILT) */
6314 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
6315
6316 /* Initialize T2 */
6317 for (i = 0; i < 16*1024; i += 64)
6318 * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
6319
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006320 /* now fixup the last line in the block to point to the next block */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006321 *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping;
6322
6323 /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */
6324 BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
6325
6326 /* QM queues (128*MAX_CONN) */
6327 BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
6328#endif
6329
6330 /* Slow path ring */
6331 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6332
6333 return 0;
6334
6335alloc_mem_err:
6336 bnx2x_free_mem(bp);
6337 return -ENOMEM;
6338
6339#undef BNX2X_PCI_ALLOC
6340#undef BNX2X_ALLOC
6341}
6342
6343static void bnx2x_free_tx_skbs(struct bnx2x *bp)
6344{
6345 int i;
6346
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006347 for_each_tx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006348 struct bnx2x_fastpath *fp = &bp->fp[i];
6349
6350 u16 bd_cons = fp->tx_bd_cons;
6351 u16 sw_prod = fp->tx_pkt_prod;
6352 u16 sw_cons = fp->tx_pkt_cons;
6353
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006354 while (sw_cons != sw_prod) {
6355 bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
6356 sw_cons++;
6357 }
6358 }
6359}
6360
6361static void bnx2x_free_rx_skbs(struct bnx2x *bp)
6362{
6363 int i, j;
6364
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006365 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006366 struct bnx2x_fastpath *fp = &bp->fp[j];
6367
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006368 for (i = 0; i < NUM_RX_BD; i++) {
6369 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
6370 struct sk_buff *skb = rx_buf->skb;
6371
6372 if (skb == NULL)
6373 continue;
6374
6375 pci_unmap_single(bp->pdev,
6376 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07006377 bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006378 PCI_DMA_FROMDEVICE);
6379
6380 rx_buf->skb = NULL;
6381 dev_kfree_skb(skb);
6382 }
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006383 if (!fp->disable_tpa)
Eilon Greenstein32626232008-08-13 15:51:07 -07006384 bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
6385 ETH_MAX_AGGREGATION_QUEUES_E1 :
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006386 ETH_MAX_AGGREGATION_QUEUES_E1H);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006387 }
6388}
6389
6390static void bnx2x_free_skbs(struct bnx2x *bp)
6391{
6392 bnx2x_free_tx_skbs(bp);
6393 bnx2x_free_rx_skbs(bp);
6394}
6395
6396static void bnx2x_free_msix_irqs(struct bnx2x *bp)
6397{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006398 int i, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006399
6400 free_irq(bp->msix_table[0].vector, bp->dev);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006401 DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006402 bp->msix_table[0].vector);
6403
6404 for_each_queue(bp, i) {
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006405 DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006406 "state %x\n", i, bp->msix_table[i + offset].vector,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006407 bnx2x_fp(bp, i, state));
6408
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006409 free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006410 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006411}
6412
6413static void bnx2x_free_irq(struct bnx2x *bp)
6414{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006415 if (bp->flags & USING_MSIX_FLAG) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006416 bnx2x_free_msix_irqs(bp);
6417 pci_disable_msix(bp->pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006418 bp->flags &= ~USING_MSIX_FLAG;
6419
Eilon Greenstein8badd272009-02-12 08:36:15 +00006420 } else if (bp->flags & USING_MSI_FLAG) {
6421 free_irq(bp->pdev->irq, bp->dev);
6422 pci_disable_msi(bp->pdev);
6423 bp->flags &= ~USING_MSI_FLAG;
6424
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006425 } else
6426 free_irq(bp->pdev->irq, bp->dev);
6427}
6428
6429static int bnx2x_enable_msix(struct bnx2x *bp)
6430{
Eilon Greenstein8badd272009-02-12 08:36:15 +00006431 int i, rc, offset = 1;
6432 int igu_vec = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006433
Eilon Greenstein8badd272009-02-12 08:36:15 +00006434 bp->msix_table[0].entry = igu_vec;
6435 DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006436
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006437 for_each_queue(bp, i) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006438 igu_vec = BP_L_ID(bp) + offset + i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006439 bp->msix_table[i + offset].entry = igu_vec;
6440 DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
6441 "(fastpath #%u)\n", i + offset, igu_vec, i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006442 }
6443
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006444 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0],
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006445 BNX2X_NUM_QUEUES(bp) + offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006446 if (rc) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006447 DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
6448 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006449 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006450
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006451 bp->flags |= USING_MSIX_FLAG;
6452
6453 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006454}
6455
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006456static int bnx2x_req_msix_irqs(struct bnx2x *bp)
6457{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006458 int i, rc, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006459
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006460 rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
6461 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006462 if (rc) {
6463 BNX2X_ERR("request sp irq failed\n");
6464 return -EBUSY;
6465 }
6466
6467 for_each_queue(bp, i) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006468 struct bnx2x_fastpath *fp = &bp->fp[i];
6469
6470 sprintf(fp->name, "%s.fp%d", bp->dev->name, i);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006471 rc = request_irq(bp->msix_table[i + offset].vector,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006472 bnx2x_msix_fp_int, 0, fp->name, fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006473 if (rc) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006474 BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006475 bnx2x_free_msix_irqs(bp);
6476 return -EBUSY;
6477 }
6478
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006479 fp->state = BNX2X_FP_STATE_IRQ;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006480 }
6481
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006482 i = BNX2X_NUM_QUEUES(bp);
6483 if (is_multi(bp))
6484 printk(KERN_INFO PFX
6485 "%s: using MSI-X IRQs: sp %d fp %d - %d\n",
6486 bp->dev->name, bp->msix_table[0].vector,
6487 bp->msix_table[offset].vector,
6488 bp->msix_table[offset + i - 1].vector);
6489 else
6490 printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp %d\n",
6491 bp->dev->name, bp->msix_table[0].vector,
6492 bp->msix_table[offset + i - 1].vector);
6493
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006494 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006495}
6496
Eilon Greenstein8badd272009-02-12 08:36:15 +00006497static int bnx2x_enable_msi(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006498{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006499 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006500
Eilon Greenstein8badd272009-02-12 08:36:15 +00006501 rc = pci_enable_msi(bp->pdev);
6502 if (rc) {
6503 DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
6504 return -1;
6505 }
6506 bp->flags |= USING_MSI_FLAG;
6507
6508 return 0;
6509}
6510
6511static int bnx2x_req_irq(struct bnx2x *bp)
6512{
6513 unsigned long flags;
6514 int rc;
6515
6516 if (bp->flags & USING_MSI_FLAG)
6517 flags = 0;
6518 else
6519 flags = IRQF_SHARED;
6520
6521 rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006522 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006523 if (!rc)
6524 bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
6525
6526 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006527}
6528
Yitchak Gertner65abd742008-08-25 15:26:24 -07006529static void bnx2x_napi_enable(struct bnx2x *bp)
6530{
6531 int i;
6532
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006533 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006534 napi_enable(&bnx2x_fp(bp, i, napi));
6535}
6536
6537static void bnx2x_napi_disable(struct bnx2x *bp)
6538{
6539 int i;
6540
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006541 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006542 napi_disable(&bnx2x_fp(bp, i, napi));
6543}
6544
6545static void bnx2x_netif_start(struct bnx2x *bp)
6546{
6547 if (atomic_dec_and_test(&bp->intr_sem)) {
6548 if (netif_running(bp->dev)) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07006549 bnx2x_napi_enable(bp);
6550 bnx2x_int_enable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006551 if (bp->state == BNX2X_STATE_OPEN)
6552 netif_tx_wake_all_queues(bp->dev);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006553 }
6554 }
6555}
6556
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07006557static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006558{
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07006559 bnx2x_int_disable_sync(bp, disable_hw);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00006560 bnx2x_napi_disable(bp);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006561 if (netif_running(bp->dev)) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07006562 netif_tx_disable(bp->dev);
6563 bp->dev->trans_start = jiffies; /* prevent tx timeout */
6564 }
6565}
6566
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006567/*
6568 * Init service functions
6569 */
6570
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006571static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006572{
6573 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006574 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006575
6576 /* CAM allocation
6577 * unicasts 0-31:port0 32-63:port1
6578 * multicast 64-127:port0 128-191:port1
6579 */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006580 config->hdr.length = 2;
Eilon Greensteinaf246402009-01-14 06:43:59 +00006581 config->hdr.offset = port ? 32 : 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006582 config->hdr.client_id = BP_CL_ID(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006583 config->hdr.reserved1 = 0;
6584
6585 /* primary MAC */
6586 config->config_table[0].cam_entry.msb_mac_addr =
6587 swab16(*(u16 *)&bp->dev->dev_addr[0]);
6588 config->config_table[0].cam_entry.middle_mac_addr =
6589 swab16(*(u16 *)&bp->dev->dev_addr[2]);
6590 config->config_table[0].cam_entry.lsb_mac_addr =
6591 swab16(*(u16 *)&bp->dev->dev_addr[4]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006592 config->config_table[0].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006593 if (set)
6594 config->config_table[0].target_table_entry.flags = 0;
6595 else
6596 CAM_INVALIDATE(config->config_table[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006597 config->config_table[0].target_table_entry.client_id = 0;
6598 config->config_table[0].target_table_entry.vlan_id = 0;
6599
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006600 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
6601 (set ? "setting" : "clearing"),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006602 config->config_table[0].cam_entry.msb_mac_addr,
6603 config->config_table[0].cam_entry.middle_mac_addr,
6604 config->config_table[0].cam_entry.lsb_mac_addr);
6605
6606 /* broadcast */
6607 config->config_table[1].cam_entry.msb_mac_addr = 0xffff;
6608 config->config_table[1].cam_entry.middle_mac_addr = 0xffff;
6609 config->config_table[1].cam_entry.lsb_mac_addr = 0xffff;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006610 config->config_table[1].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006611 if (set)
6612 config->config_table[1].target_table_entry.flags =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006613 TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006614 else
6615 CAM_INVALIDATE(config->config_table[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006616 config->config_table[1].target_table_entry.client_id = 0;
6617 config->config_table[1].target_table_entry.vlan_id = 0;
6618
6619 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6620 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6621 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6622}
6623
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006624static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006625{
6626 struct mac_configuration_cmd_e1h *config =
6627 (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
6628
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006629 if (set && (bp->state != BNX2X_STATE_OPEN)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006630 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
6631 return;
6632 }
6633
6634 /* CAM allocation for E1H
6635 * unicasts: by func number
6636 * multicast: 20+FUNC*20, 20 each
6637 */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006638 config->hdr.length = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006639 config->hdr.offset = BP_FUNC(bp);
6640 config->hdr.client_id = BP_CL_ID(bp);
6641 config->hdr.reserved1 = 0;
6642
6643 /* primary MAC */
6644 config->config_table[0].msb_mac_addr =
6645 swab16(*(u16 *)&bp->dev->dev_addr[0]);
6646 config->config_table[0].middle_mac_addr =
6647 swab16(*(u16 *)&bp->dev->dev_addr[2]);
6648 config->config_table[0].lsb_mac_addr =
6649 swab16(*(u16 *)&bp->dev->dev_addr[4]);
6650 config->config_table[0].client_id = BP_L_ID(bp);
6651 config->config_table[0].vlan_id = 0;
6652 config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006653 if (set)
6654 config->config_table[0].flags = BP_PORT(bp);
6655 else
6656 config->config_table[0].flags =
6657 MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006658
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006659 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n",
6660 (set ? "setting" : "clearing"),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006661 config->config_table[0].msb_mac_addr,
6662 config->config_table[0].middle_mac_addr,
6663 config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp));
6664
6665 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6666 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6667 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6668}
6669
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006670static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6671 int *state_p, int poll)
6672{
6673 /* can take a while if any port is running */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006674 int cnt = 5000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006675
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006676 DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
6677 poll ? "polling" : "waiting", state, idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006678
6679 might_sleep();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006680 while (cnt--) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006681 if (poll) {
6682 bnx2x_rx_int(bp->fp, 10);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006683 /* if index is different from 0
6684 * the reply for some commands will
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006685 * be on the non default queue
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006686 */
6687 if (idx)
6688 bnx2x_rx_int(&bp->fp[idx], 10);
6689 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006690
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006691 mb(); /* state is changed by bnx2x_sp_event() */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006692 if (*state_p == state) {
6693#ifdef BNX2X_STOP_ON_ERROR
6694 DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
6695#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006696 return 0;
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006697 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006698
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006699 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006700 }
6701
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006702 /* timeout! */
Eliezer Tamir49d66772008-02-28 11:53:13 -08006703 BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
6704 poll ? "polling" : "waiting", state, idx);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006705#ifdef BNX2X_STOP_ON_ERROR
6706 bnx2x_panic();
6707#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006708
Eliezer Tamir49d66772008-02-28 11:53:13 -08006709 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006710}
6711
6712static int bnx2x_setup_leading(struct bnx2x *bp)
6713{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006714 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006715
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006716 /* reset IGU state */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006717 bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006718
6719 /* SETUP ramrod */
6720 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
6721
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006722 /* Wait for completion */
6723 rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006724
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006725 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006726}
6727
6728static int bnx2x_setup_multi(struct bnx2x *bp, int index)
6729{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006730 struct bnx2x_fastpath *fp = &bp->fp[index];
6731
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006732 /* reset IGU state */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006733 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006734
Eliezer Tamir228241e2008-02-28 11:56:57 -08006735 /* SETUP ramrod */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006736 fp->state = BNX2X_FP_STATE_OPENING;
6737 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
6738 fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006739
6740 /* Wait for completion */
6741 return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006742 &(fp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006743}
6744
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006745static int bnx2x_poll(struct napi_struct *napi, int budget);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006746
Eilon Greenstein8badd272009-02-12 08:36:15 +00006747static void bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006748{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006749 int num_queues;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006750
Eilon Greenstein8badd272009-02-12 08:36:15 +00006751 switch (int_mode) {
6752 case INT_MODE_INTx:
6753 case INT_MODE_MSI:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006754 num_queues = 1;
6755 bp->num_rx_queues = num_queues;
6756 bp->num_tx_queues = num_queues;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006757 DP(NETIF_MSG_IFUP,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006758 "set number of queues to %d\n", num_queues);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006759 break;
6760
6761 case INT_MODE_MSIX:
6762 default:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006763 if (bp->multi_mode == ETH_RSS_MODE_REGULAR)
6764 num_queues = min_t(u32, num_online_cpus(),
6765 BNX2X_MAX_QUEUES(bp));
6766 else
6767 num_queues = 1;
6768 bp->num_rx_queues = num_queues;
6769 bp->num_tx_queues = num_queues;
6770 DP(NETIF_MSG_IFUP, "set number of rx queues to %d"
6771 " number of tx queues to %d\n",
6772 bp->num_rx_queues, bp->num_tx_queues);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006773 /* if we can't use MSI-X we only need one fp,
6774 * so try to enable MSI-X with the requested number of fp's
6775 * and fallback to MSI or legacy INTx with one fp
6776 */
Eilon Greenstein8badd272009-02-12 08:36:15 +00006777 if (bnx2x_enable_msix(bp)) {
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006778 /* failed to enable MSI-X */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006779 num_queues = 1;
6780 bp->num_rx_queues = num_queues;
6781 bp->num_tx_queues = num_queues;
6782 if (bp->multi_mode)
6783 BNX2X_ERR("Multi requested but failed to "
6784 "enable MSI-X set number of "
6785 "queues to %d\n", num_queues);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006786 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006787 break;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006788 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006789 bp->dev->real_num_tx_queues = bp->num_tx_queues;
Eilon Greenstein8badd272009-02-12 08:36:15 +00006790}
6791
6792static void bnx2x_set_rx_mode(struct net_device *dev);
6793
6794/* must be called with rtnl_lock */
6795static int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
6796{
6797 u32 load_code;
6798 int i, rc = 0;
6799#ifdef BNX2X_STOP_ON_ERROR
6800 DP(NETIF_MSG_IFUP, "enter load_mode %d\n", load_mode);
6801 if (unlikely(bp->panic))
6802 return -EPERM;
6803#endif
6804
6805 bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
6806
6807 bnx2x_set_int_mode(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006808
6809 if (bnx2x_alloc_mem(bp))
6810 return -ENOMEM;
6811
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006812 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006813 bnx2x_fp(bp, i, disable_tpa) =
6814 ((bp->flags & TPA_ENABLE_FLAG) == 0);
6815
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006816 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006817 netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
6818 bnx2x_poll, 128);
6819
6820#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006821 for_each_rx_queue(bp, i) {
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006822 struct bnx2x_fastpath *fp = &bp->fp[i];
6823
6824 fp->poll_no_work = 0;
6825 fp->poll_calls = 0;
6826 fp->poll_max_calls = 0;
6827 fp->poll_complete = 0;
6828 fp->poll_exit = 0;
6829 }
6830#endif
6831 bnx2x_napi_enable(bp);
6832
6833 if (bp->flags & USING_MSIX_FLAG) {
6834 rc = bnx2x_req_msix_irqs(bp);
6835 if (rc) {
6836 pci_disable_msix(bp->pdev);
6837 goto load_error1;
6838 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006839 } else {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006840 if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
6841 bnx2x_enable_msi(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006842 bnx2x_ack_int(bp);
6843 rc = bnx2x_req_irq(bp);
6844 if (rc) {
6845 BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006846 if (bp->flags & USING_MSI_FLAG)
6847 pci_disable_msi(bp->pdev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006848 goto load_error1;
6849 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006850 if (bp->flags & USING_MSI_FLAG) {
6851 bp->dev->irq = bp->pdev->irq;
6852 printk(KERN_INFO PFX "%s: using MSI IRQ %d\n",
6853 bp->dev->name, bp->pdev->irq);
6854 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006855 }
6856
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006857 /* Send LOAD_REQUEST command to MCP
6858 Returns the type of LOAD command:
6859 if it is the first port to be initialized
6860 common blocks should be initialized, otherwise - not
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006861 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006862 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08006863 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ);
6864 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006865 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006866 rc = -EBUSY;
6867 goto load_error2;
Eliezer Tamir228241e2008-02-28 11:56:57 -08006868 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006869 if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6870 rc = -EBUSY; /* other port in diagnostic mode */
6871 goto load_error2;
6872 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006873
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006874 } else {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006875 int port = BP_PORT(bp);
6876
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006877 DP(NETIF_MSG_IFUP, "NO MCP load counts before us %d, %d, %d\n",
6878 load_count[0], load_count[1], load_count[2]);
6879 load_count[0]++;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006880 load_count[1 + port]++;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006881 DP(NETIF_MSG_IFUP, "NO MCP new load counts %d, %d, %d\n",
6882 load_count[0], load_count[1], load_count[2]);
6883 if (load_count[0] == 1)
6884 load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006885 else if (load_count[1 + port] == 1)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006886 load_code = FW_MSG_CODE_DRV_LOAD_PORT;
6887 else
6888 load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006889 }
6890
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006891 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6892 (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
6893 bp->port.pmf = 1;
6894 else
6895 bp->port.pmf = 0;
6896 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
6897
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006898 /* Initialize HW */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006899 rc = bnx2x_init_hw(bp, load_code);
6900 if (rc) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006901 BNX2X_ERR("HW init failed, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006902 goto load_error2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006903 }
6904
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006905 /* Setup NIC internals and enable interrupts */
Eilon Greenstein471de712008-08-13 15:49:35 -07006906 bnx2x_nic_init(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006907
6908 /* Send LOAD_DONE command to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006909 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08006910 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE);
6911 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006912 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006913 rc = -EBUSY;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006914 goto load_error3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006915 }
6916 }
6917
6918 bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
6919
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006920 rc = bnx2x_setup_leading(bp);
6921 if (rc) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006922 BNX2X_ERR("Setup leading failed!\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006923 goto load_error3;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006924 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006925
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006926 if (CHIP_IS_E1H(bp))
6927 if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
6928 BNX2X_ERR("!!! mf_cfg function disabled\n");
6929 bp->state = BNX2X_STATE_DISABLED;
6930 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006931
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006932 if (bp->state == BNX2X_STATE_OPEN)
6933 for_each_nondefault_queue(bp, i) {
6934 rc = bnx2x_setup_multi(bp, i);
6935 if (rc)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006936 goto load_error3;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006937 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006938
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006939 if (CHIP_IS_E1(bp))
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006940 bnx2x_set_mac_addr_e1(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006941 else
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006942 bnx2x_set_mac_addr_e1h(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006943
6944 if (bp->port.pmf)
6945 bnx2x_initial_phy_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006946
6947 /* Start fast path */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006948 switch (load_mode) {
6949 case LOAD_NORMAL:
6950 /* Tx queue should be only reenabled */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006951 netif_tx_wake_all_queues(bp->dev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006952 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006953 bnx2x_set_rx_mode(bp->dev);
6954 break;
6955
6956 case LOAD_OPEN:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006957 netif_tx_start_all_queues(bp->dev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006958 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006959 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006960 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006961
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006962 case LOAD_DIAG:
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006963 /* Initialize the receive filter. */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006964 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006965 bp->state = BNX2X_STATE_DIAG;
6966 break;
6967
6968 default:
6969 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006970 }
6971
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006972 if (!bp->port.pmf)
6973 bnx2x__link_status_update(bp);
6974
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006975 /* start the timer */
6976 mod_timer(&bp->timer, jiffies + bp->current_interval);
6977
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006978
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006979 return 0;
6980
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006981load_error3:
6982 bnx2x_int_disable_sync(bp, 1);
6983 if (!BP_NOMCP(bp)) {
6984 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP);
6985 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
6986 }
6987 bp->port.pmf = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006988 /* Free SKBs, SGEs, TPA pool and driver internals */
6989 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006990 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07006991 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006992load_error2:
Yitchak Gertnerd1014632008-08-25 15:25:45 -07006993 /* Release IRQs */
6994 bnx2x_free_irq(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006995load_error1:
6996 bnx2x_napi_disable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006997 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00006998 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006999 bnx2x_free_mem(bp);
7000
7001 /* TBD we really need to reset the chip
7002 if we want to recover from this */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007003 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007004}
7005
7006static int bnx2x_stop_multi(struct bnx2x *bp, int index)
7007{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007008 struct bnx2x_fastpath *fp = &bp->fp[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007009 int rc;
7010
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007011 /* halt the connection */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007012 fp->state = BNX2X_FP_STATE_HALTING;
7013 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007014
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007015 /* Wait for completion */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007016 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007017 &(fp->state), 1);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007018 if (rc) /* timeout */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007019 return rc;
7020
7021 /* delete cfc entry */
7022 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
7023
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007024 /* Wait for completion */
7025 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007026 &(fp->state), 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007027 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007028}
7029
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007030static int bnx2x_stop_leading(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007031{
Eliezer Tamir49d66772008-02-28 11:53:13 -08007032 u16 dsb_sp_prod_idx;
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007033 /* if the other port is handling traffic,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007034 this can take a lot of time */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007035 int cnt = 500;
7036 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007037
7038 might_sleep();
7039
7040 /* Send HALT ramrod */
7041 bp->fp[0].state = BNX2X_FP_STATE_HALTING;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007042 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, BP_CL_ID(bp), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007043
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007044 /* Wait for completion */
7045 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
7046 &(bp->fp[0].state), 1);
7047 if (rc) /* timeout */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007048 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007049
Eliezer Tamir49d66772008-02-28 11:53:13 -08007050 dsb_sp_prod_idx = *bp->dsb_sp_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007051
Eliezer Tamir228241e2008-02-28 11:56:57 -08007052 /* Send PORT_DELETE ramrod */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007053 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
7054
Eliezer Tamir49d66772008-02-28 11:53:13 -08007055 /* Wait for completion to arrive on default status block
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007056 we are going to reset the chip anyway
7057 so there is not much to do if this times out
7058 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007059 while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007060 if (!cnt) {
7061 DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
7062 "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
7063 *bp->dsb_sp_prod, dsb_sp_prod_idx);
7064#ifdef BNX2X_STOP_ON_ERROR
7065 bnx2x_panic();
7066#endif
Eilon Greenstein36e552a2009-02-12 08:37:21 +00007067 rc = -EBUSY;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007068 break;
7069 }
7070 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007071 msleep(1);
Eilon Greenstein5650d9d2009-01-22 06:01:29 +00007072 rmb(); /* Refresh the dsb_sp_prod */
Eliezer Tamir49d66772008-02-28 11:53:13 -08007073 }
7074 bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
7075 bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007076
7077 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007078}
7079
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007080static void bnx2x_reset_func(struct bnx2x *bp)
7081{
7082 int port = BP_PORT(bp);
7083 int func = BP_FUNC(bp);
7084 int base, i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08007085
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007086 /* Configure IGU */
7087 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7088 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7089
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007090 /* Clear ILT */
7091 base = FUNC_ILT_BASE(func);
7092 for (i = base; i < base + ILT_PER_FUNC; i++)
7093 bnx2x_ilt_wr(bp, i, 0);
7094}
7095
7096static void bnx2x_reset_port(struct bnx2x *bp)
7097{
7098 int port = BP_PORT(bp);
7099 u32 val;
7100
7101 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7102
7103 /* Do not rcv packets to BRB */
7104 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7105 /* Do not direct rcv packets that are not for MCP to the BRB */
7106 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7107 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7108
7109 /* Configure AEU */
7110 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7111
7112 msleep(100);
7113 /* Check for BRB port occupancy */
7114 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7115 if (val)
7116 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07007117 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007118
7119 /* TODO: Close Doorbell port? */
7120}
7121
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007122static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
7123{
7124 DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
7125 BP_FUNC(bp), reset_code);
7126
7127 switch (reset_code) {
7128 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
7129 bnx2x_reset_port(bp);
7130 bnx2x_reset_func(bp);
7131 bnx2x_reset_common(bp);
7132 break;
7133
7134 case FW_MSG_CODE_DRV_UNLOAD_PORT:
7135 bnx2x_reset_port(bp);
7136 bnx2x_reset_func(bp);
7137 break;
7138
7139 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
7140 bnx2x_reset_func(bp);
7141 break;
7142
7143 default:
7144 BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
7145 break;
7146 }
7147}
7148
Eilon Greenstein33471622008-08-13 15:59:08 -07007149/* must be called with rtnl_lock */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007150static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007151{
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007152 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007153 u32 reset_code = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007154 int i, cnt, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007155
7156 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
7157
Eliezer Tamir228241e2008-02-28 11:56:57 -08007158 bp->rx_mode = BNX2X_RX_MODE_NONE;
7159 bnx2x_set_storm_rx_mode(bp);
7160
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07007161 bnx2x_netif_stop(bp, 1);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00007162
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007163 del_timer_sync(&bp->timer);
7164 SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb,
7165 (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07007166 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007167
Eilon Greenstein70b99862009-01-14 06:43:48 +00007168 /* Release IRQs */
7169 bnx2x_free_irq(bp);
7170
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007171 /* Wait until tx fastpath tasks complete */
7172 for_each_tx_queue(bp, i) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08007173 struct bnx2x_fastpath *fp = &bp->fp[i];
7174
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007175 cnt = 1000;
Eilon Greenstein3e5b5102009-02-12 08:37:25 +00007176 smp_mb();
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -08007177 while (bnx2x_has_tx_work_unload(fp)) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007178
Yitchak Gertner65abd742008-08-25 15:26:24 -07007179 bnx2x_tx_int(fp, 1000);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007180 if (!cnt) {
7181 BNX2X_ERR("timeout waiting for queue[%d]\n",
7182 i);
7183#ifdef BNX2X_STOP_ON_ERROR
7184 bnx2x_panic();
7185 return -EBUSY;
7186#else
7187 break;
7188#endif
7189 }
7190 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007191 msleep(1);
Eilon Greenstein3e5b5102009-02-12 08:37:25 +00007192 smp_mb();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007193 }
Eliezer Tamir228241e2008-02-28 11:56:57 -08007194 }
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007195 /* Give HW time to discard old tx messages */
7196 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007197
Yitchak Gertner65abd742008-08-25 15:26:24 -07007198 if (CHIP_IS_E1(bp)) {
7199 struct mac_configuration_cmd *config =
7200 bnx2x_sp(bp, mcast_config);
7201
7202 bnx2x_set_mac_addr_e1(bp, 0);
7203
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007204 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007205 CAM_INVALIDATE(config->config_table[i]);
7206
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007207 config->hdr.length = i;
Yitchak Gertner65abd742008-08-25 15:26:24 -07007208 if (CHIP_REV_IS_SLOW(bp))
7209 config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
7210 else
7211 config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
7212 config->hdr.client_id = BP_CL_ID(bp);
7213 config->hdr.reserved1 = 0;
7214
7215 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
7216 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
7217 U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
7218
7219 } else { /* E1H */
7220 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7221
7222 bnx2x_set_mac_addr_e1h(bp, 0);
7223
7224 for (i = 0; i < MC_HASH_SIZE; i++)
7225 REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
7226 }
7227
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007228 if (unload_mode == UNLOAD_NORMAL)
7229 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007230
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007231 else if (bp->flags & NO_WOL_FLAG) {
7232 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7233 if (CHIP_IS_E1H(bp))
7234 REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
7235
7236 } else if (bp->wol) {
7237 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007238 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007239 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007240 /* The mac address is written to entries 1-4 to
7241 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007242 u8 entry = (BP_E1HVN(bp) + 1)*8;
7243
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007244 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007245 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007246
7247 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7248 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007249 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007250
7251 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007252
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007253 } else
7254 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7255
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007256 /* Close multi and leading connections
7257 Completions for ramrods are collected in a synchronous way */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007258 for_each_nondefault_queue(bp, i)
7259 if (bnx2x_stop_multi(bp, i))
Eliezer Tamir228241e2008-02-28 11:56:57 -08007260 goto unload_error;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007261
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007262 rc = bnx2x_stop_leading(bp);
7263 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007264 BNX2X_ERR("Stop leading failed!\n");
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007265#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007266 return -EBUSY;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007267#else
7268 goto unload_error;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007269#endif
Eliezer Tamir228241e2008-02-28 11:56:57 -08007270 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007271
Eliezer Tamir228241e2008-02-28 11:56:57 -08007272unload_error:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007273 if (!BP_NOMCP(bp))
Eliezer Tamir228241e2008-02-28 11:56:57 -08007274 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007275 else {
7276 DP(NETIF_MSG_IFDOWN, "NO MCP load counts %d, %d, %d\n",
7277 load_count[0], load_count[1], load_count[2]);
7278 load_count[0]--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007279 load_count[1 + port]--;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007280 DP(NETIF_MSG_IFDOWN, "NO MCP new load counts %d, %d, %d\n",
7281 load_count[0], load_count[1], load_count[2]);
7282 if (load_count[0] == 0)
7283 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007284 else if (load_count[1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007285 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7286 else
7287 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7288 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007289
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007290 if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
7291 (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
7292 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007293
7294 /* Reset the chip */
Eliezer Tamir228241e2008-02-28 11:56:57 -08007295 bnx2x_reset_chip(bp, reset_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007296
7297 /* Report UNLOAD_DONE to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007298 if (!BP_NOMCP(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007299 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
Eilon Greenstein9a035442008-11-03 16:45:55 -08007300 bp->port.pmf = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007301
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007302 /* Free SKBs, SGEs, TPA pool and driver internals */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007303 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007304 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07007305 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007306 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00007307 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007308 bnx2x_free_mem(bp);
7309
7310 bp->state = BNX2X_STATE_CLOSED;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007311
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007312 netif_carrier_off(bp->dev);
7313
7314 return 0;
7315}
7316
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007317static void bnx2x_reset_task(struct work_struct *work)
7318{
7319 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task);
7320
7321#ifdef BNX2X_STOP_ON_ERROR
7322 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7323 " so reset not done to allow debug dump,\n"
7324 KERN_ERR " you will need to reboot when done\n");
7325 return;
7326#endif
7327
7328 rtnl_lock();
7329
7330 if (!netif_running(bp->dev))
7331 goto reset_task_exit;
7332
7333 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7334 bnx2x_nic_load(bp, LOAD_NORMAL);
7335
7336reset_task_exit:
7337 rtnl_unlock();
7338}
7339
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007340/* end of nic load/unload */
7341
7342/* ethtool_ops */
7343
7344/*
7345 * Init service functions
7346 */
7347
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007348static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
7349{
7350 switch (func) {
7351 case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
7352 case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
7353 case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
7354 case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
7355 case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
7356 case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
7357 case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
7358 case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
7359 default:
7360 BNX2X_ERR("Unsupported function index: %d\n", func);
7361 return (u32)(-1);
7362 }
7363}
7364
7365static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
7366{
7367 u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
7368
7369 /* Flush all outstanding writes */
7370 mmiowb();
7371
7372 /* Pretend to be function 0 */
7373 REG_WR(bp, reg, 0);
7374 /* Flush the GRC transaction (in the chip) */
7375 new_val = REG_RD(bp, reg);
7376 if (new_val != 0) {
7377 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
7378 new_val);
7379 BUG();
7380 }
7381
7382 /* From now we are in the "like-E1" mode */
7383 bnx2x_int_disable(bp);
7384
7385 /* Flush all outstanding writes */
7386 mmiowb();
7387
7388 /* Restore the original funtion settings */
7389 REG_WR(bp, reg, orig_func);
7390 new_val = REG_RD(bp, reg);
7391 if (new_val != orig_func) {
7392 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
7393 orig_func, new_val);
7394 BUG();
7395 }
7396}
7397
7398static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
7399{
7400 if (CHIP_IS_E1H(bp))
7401 bnx2x_undi_int_disable_e1h(bp, func);
7402 else
7403 bnx2x_int_disable(bp);
7404}
7405
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007406static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007407{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007408 u32 val;
7409
7410 /* Check if there is any driver already loaded */
7411 val = REG_RD(bp, MISC_REG_UNPREPARED);
7412 if (val == 0x1) {
7413 /* Check if it is the UNDI driver
7414 * UNDI driver initializes CID offset for normal bell to 0x7
7415 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07007416 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007417 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
7418 if (val == 0x7) {
7419 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007420 /* save our func */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007421 int func = BP_FUNC(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007422 u32 swap_en;
7423 u32 swap_val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007424
Eilon Greensteinb4661732009-01-14 06:43:56 +00007425 /* clear the UNDI indication */
7426 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
7427
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007428 BNX2X_DEV_INFO("UNDI is active! reset device\n");
7429
7430 /* try unload UNDI on port 0 */
7431 bp->func = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007432 bp->fw_seq =
7433 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7434 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007435 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007436
7437 /* if UNDI is loaded on the other port */
7438 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
7439
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007440 /* send "DONE" for previous unload */
7441 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7442
7443 /* unload UNDI on port 1 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007444 bp->func = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007445 bp->fw_seq =
7446 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7447 DRV_MSG_SEQ_NUMBER_MASK);
7448 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007449
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007450 bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007451 }
7452
Eilon Greensteinb4661732009-01-14 06:43:56 +00007453 /* now it's safe to release the lock */
7454 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
7455
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007456 bnx2x_undi_int_disable(bp, func);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007457
7458 /* close input traffic and wait for it */
7459 /* Do not rcv packets to BRB */
7460 REG_WR(bp,
7461 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
7462 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
7463 /* Do not direct rcv packets that are not for MCP to
7464 * the BRB */
7465 REG_WR(bp,
7466 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
7467 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7468 /* clear AEU */
7469 REG_WR(bp,
7470 (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7471 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
7472 msleep(10);
7473
7474 /* save NIG port swap info */
7475 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7476 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007477 /* reset device */
7478 REG_WR(bp,
7479 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007480 0xd3ffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007481 REG_WR(bp,
7482 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7483 0x1403);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007484 /* take the NIG out of reset and restore swap values */
7485 REG_WR(bp,
7486 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7487 MISC_REGISTERS_RESET_REG_1_RST_NIG);
7488 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
7489 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
7490
7491 /* send unload done to the MCP */
7492 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7493
7494 /* restore our func and fw_seq */
7495 bp->func = func;
7496 bp->fw_seq =
7497 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7498 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00007499
7500 } else
7501 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007502 }
7503}
7504
7505static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
7506{
7507 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007508 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007509
7510 /* Get the chip revision id and number. */
7511 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
7512 val = REG_RD(bp, MISC_REG_CHIP_NUM);
7513 id = ((val & 0xffff) << 16);
7514 val = REG_RD(bp, MISC_REG_CHIP_REV);
7515 id |= ((val & 0xf) << 12);
7516 val = REG_RD(bp, MISC_REG_CHIP_METAL);
7517 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00007518 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007519 id |= (val & 0xf);
7520 bp->common.chip_id = id;
7521 bp->link_params.chip_id = bp->common.chip_id;
7522 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
7523
Eilon Greenstein1c063282009-02-12 08:36:43 +00007524 val = (REG_RD(bp, 0x2874) & 0x55);
7525 if ((bp->common.chip_id & 0x1) ||
7526 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
7527 bp->flags |= ONE_PORT_FLAG;
7528 BNX2X_DEV_INFO("single port device\n");
7529 }
7530
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007531 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
7532 bp->common.flash_size = (NVRAM_1MB_SIZE <<
7533 (val & MCPR_NVM_CFG4_FLASH_SIZE));
7534 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
7535 bp->common.flash_size, bp->common.flash_size);
7536
7537 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7538 bp->link_params.shmem_base = bp->common.shmem_base;
7539 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
7540
7541 if (!bp->common.shmem_base ||
7542 (bp->common.shmem_base < 0xA0000) ||
7543 (bp->common.shmem_base >= 0xC0000)) {
7544 BNX2X_DEV_INFO("MCP not active\n");
7545 bp->flags |= NO_MCP_FLAG;
7546 return;
7547 }
7548
7549 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7550 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
7551 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
7552 BNX2X_ERR("BAD MCP validity signature\n");
7553
7554 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00007555 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007556
7557 bp->link_params.hw_led_mode = ((bp->common.hw_config &
7558 SHARED_HW_CFG_LED_MODE_MASK) >>
7559 SHARED_HW_CFG_LED_MODE_SHIFT);
7560
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007561 bp->link_params.feature_config_flags = 0;
7562 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
7563 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
7564 bp->link_params.feature_config_flags |=
7565 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7566 else
7567 bp->link_params.feature_config_flags &=
7568 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7569
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007570 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
7571 bp->common.bc_ver = val;
7572 BNX2X_DEV_INFO("bc_ver %X\n", val);
7573 if (val < BNX2X_BC_VER) {
7574 /* for now only warn
7575 * later we might need to enforce this */
7576 BNX2X_ERR("This driver needs bc_ver %X but found %X,"
7577 " please upgrade BC\n", BNX2X_BC_VER, val);
7578 }
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007579
7580 if (BP_E1HVN(bp) == 0) {
7581 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
7582 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
7583 } else {
7584 /* no WOL capability for E1HVN != 0 */
7585 bp->flags |= NO_WOL_FLAG;
7586 }
7587 BNX2X_DEV_INFO("%sWoL capable\n",
7588 (bp->flags & NO_WOL_FLAG) ? "Not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007589
7590 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
7591 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
7592 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
7593 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
7594
7595 printk(KERN_INFO PFX "part number %X-%X-%X-%X\n",
7596 val, val2, val3, val4);
7597}
7598
7599static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
7600 u32 switch_cfg)
7601{
7602 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007603 u32 ext_phy_type;
7604
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007605 switch (switch_cfg) {
7606 case SWITCH_CFG_1G:
7607 BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
7608
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007609 ext_phy_type =
7610 SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007611 switch (ext_phy_type) {
7612 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
7613 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7614 ext_phy_type);
7615
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007616 bp->port.supported |= (SUPPORTED_10baseT_Half |
7617 SUPPORTED_10baseT_Full |
7618 SUPPORTED_100baseT_Half |
7619 SUPPORTED_100baseT_Full |
7620 SUPPORTED_1000baseT_Full |
7621 SUPPORTED_2500baseX_Full |
7622 SUPPORTED_TP |
7623 SUPPORTED_FIBRE |
7624 SUPPORTED_Autoneg |
7625 SUPPORTED_Pause |
7626 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007627 break;
7628
7629 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
7630 BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
7631 ext_phy_type);
7632
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007633 bp->port.supported |= (SUPPORTED_10baseT_Half |
7634 SUPPORTED_10baseT_Full |
7635 SUPPORTED_100baseT_Half |
7636 SUPPORTED_100baseT_Full |
7637 SUPPORTED_1000baseT_Full |
7638 SUPPORTED_TP |
7639 SUPPORTED_FIBRE |
7640 SUPPORTED_Autoneg |
7641 SUPPORTED_Pause |
7642 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007643 break;
7644
7645 default:
7646 BNX2X_ERR("NVRAM config error. "
7647 "BAD SerDes ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007648 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007649 return;
7650 }
7651
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007652 bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
7653 port*0x10);
7654 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007655 break;
7656
7657 case SWITCH_CFG_10G:
7658 BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
7659
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007660 ext_phy_type =
7661 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007662 switch (ext_phy_type) {
7663 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7664 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7665 ext_phy_type);
7666
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007667 bp->port.supported |= (SUPPORTED_10baseT_Half |
7668 SUPPORTED_10baseT_Full |
7669 SUPPORTED_100baseT_Half |
7670 SUPPORTED_100baseT_Full |
7671 SUPPORTED_1000baseT_Full |
7672 SUPPORTED_2500baseX_Full |
7673 SUPPORTED_10000baseT_Full |
7674 SUPPORTED_TP |
7675 SUPPORTED_FIBRE |
7676 SUPPORTED_Autoneg |
7677 SUPPORTED_Pause |
7678 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007679 break;
7680
Eliezer Tamirf1410642008-02-28 11:51:50 -08007681 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
7682 BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
7683 ext_phy_type);
7684
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007685 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7686 SUPPORTED_1000baseT_Full |
7687 SUPPORTED_FIBRE |
7688 SUPPORTED_Autoneg |
7689 SUPPORTED_Pause |
7690 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007691 break;
7692
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007693 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
7694 BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
7695 ext_phy_type);
7696
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007697 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7698 SUPPORTED_2500baseX_Full |
7699 SUPPORTED_1000baseT_Full |
7700 SUPPORTED_FIBRE |
7701 SUPPORTED_Autoneg |
7702 SUPPORTED_Pause |
7703 SUPPORTED_Asym_Pause);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007704 break;
7705
Eilon Greenstein589abe32009-02-12 08:36:55 +00007706 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7707 BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
7708 ext_phy_type);
7709
7710 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7711 SUPPORTED_FIBRE |
7712 SUPPORTED_Pause |
7713 SUPPORTED_Asym_Pause);
7714 break;
7715
7716 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7717 BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
7718 ext_phy_type);
7719
7720 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7721 SUPPORTED_1000baseT_Full |
7722 SUPPORTED_FIBRE |
7723 SUPPORTED_Pause |
7724 SUPPORTED_Asym_Pause);
7725 break;
7726
7727 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7728 BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
7729 ext_phy_type);
7730
7731 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7732 SUPPORTED_1000baseT_Full |
7733 SUPPORTED_Autoneg |
7734 SUPPORTED_FIBRE |
7735 SUPPORTED_Pause |
7736 SUPPORTED_Asym_Pause);
7737 break;
7738
Eliezer Tamirf1410642008-02-28 11:51:50 -08007739 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7740 BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
7741 ext_phy_type);
7742
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007743 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7744 SUPPORTED_TP |
7745 SUPPORTED_Autoneg |
7746 SUPPORTED_Pause |
7747 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007748 break;
7749
Eilon Greenstein28577182009-02-12 08:37:00 +00007750 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7751 BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
7752 ext_phy_type);
7753
7754 bp->port.supported |= (SUPPORTED_10baseT_Half |
7755 SUPPORTED_10baseT_Full |
7756 SUPPORTED_100baseT_Half |
7757 SUPPORTED_100baseT_Full |
7758 SUPPORTED_1000baseT_Full |
7759 SUPPORTED_10000baseT_Full |
7760 SUPPORTED_TP |
7761 SUPPORTED_Autoneg |
7762 SUPPORTED_Pause |
7763 SUPPORTED_Asym_Pause);
7764 break;
7765
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007766 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7767 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
7768 bp->link_params.ext_phy_config);
7769 break;
7770
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007771 default:
7772 BNX2X_ERR("NVRAM config error. "
7773 "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007774 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007775 return;
7776 }
7777
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007778 bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
7779 port*0x18);
7780 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007781
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007782 break;
7783
7784 default:
7785 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007786 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007787 return;
7788 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007789 bp->link_params.phy_addr = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007790
7791 /* mask what we support according to speed_cap_mask */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007792 if (!(bp->link_params.speed_cap_mask &
7793 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007794 bp->port.supported &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007795
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007796 if (!(bp->link_params.speed_cap_mask &
7797 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007798 bp->port.supported &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007799
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007800 if (!(bp->link_params.speed_cap_mask &
7801 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007802 bp->port.supported &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007803
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007804 if (!(bp->link_params.speed_cap_mask &
7805 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007806 bp->port.supported &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007807
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007808 if (!(bp->link_params.speed_cap_mask &
7809 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007810 bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
7811 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007812
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007813 if (!(bp->link_params.speed_cap_mask &
7814 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007815 bp->port.supported &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007816
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007817 if (!(bp->link_params.speed_cap_mask &
7818 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007819 bp->port.supported &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007820
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007821 BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007822}
7823
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007824static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007825{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007826 bp->link_params.req_duplex = DUPLEX_FULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007827
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007828 switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007829 case PORT_FEATURE_LINK_SPEED_AUTO:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007830 if (bp->port.supported & SUPPORTED_Autoneg) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007831 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007832 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007833 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007834 u32 ext_phy_type =
7835 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
7836
7837 if ((ext_phy_type ==
7838 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
7839 (ext_phy_type ==
7840 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007841 /* force 10G, no AN */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007842 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007843 bp->port.advertising =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007844 (ADVERTISED_10000baseT_Full |
7845 ADVERTISED_FIBRE);
7846 break;
7847 }
7848 BNX2X_ERR("NVRAM config error. "
7849 "Invalid link_config 0x%x"
7850 " Autoneg not supported\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007851 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007852 return;
7853 }
7854 break;
7855
7856 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007857 if (bp->port.supported & SUPPORTED_10baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007858 bp->link_params.req_line_speed = SPEED_10;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007859 bp->port.advertising = (ADVERTISED_10baseT_Full |
7860 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007861 } else {
7862 BNX2X_ERR("NVRAM config error. "
7863 "Invalid link_config 0x%x"
7864 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007865 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007866 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007867 return;
7868 }
7869 break;
7870
7871 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007872 if (bp->port.supported & SUPPORTED_10baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007873 bp->link_params.req_line_speed = SPEED_10;
7874 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007875 bp->port.advertising = (ADVERTISED_10baseT_Half |
7876 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007877 } else {
7878 BNX2X_ERR("NVRAM config error. "
7879 "Invalid link_config 0x%x"
7880 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007881 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007882 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007883 return;
7884 }
7885 break;
7886
7887 case PORT_FEATURE_LINK_SPEED_100M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007888 if (bp->port.supported & SUPPORTED_100baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007889 bp->link_params.req_line_speed = SPEED_100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007890 bp->port.advertising = (ADVERTISED_100baseT_Full |
7891 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007892 } else {
7893 BNX2X_ERR("NVRAM config error. "
7894 "Invalid link_config 0x%x"
7895 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007896 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007897 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007898 return;
7899 }
7900 break;
7901
7902 case PORT_FEATURE_LINK_SPEED_100M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007903 if (bp->port.supported & SUPPORTED_100baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007904 bp->link_params.req_line_speed = SPEED_100;
7905 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007906 bp->port.advertising = (ADVERTISED_100baseT_Half |
7907 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007908 } else {
7909 BNX2X_ERR("NVRAM config error. "
7910 "Invalid link_config 0x%x"
7911 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007912 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007913 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007914 return;
7915 }
7916 break;
7917
7918 case PORT_FEATURE_LINK_SPEED_1G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007919 if (bp->port.supported & SUPPORTED_1000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007920 bp->link_params.req_line_speed = SPEED_1000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007921 bp->port.advertising = (ADVERTISED_1000baseT_Full |
7922 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007923 } else {
7924 BNX2X_ERR("NVRAM config error. "
7925 "Invalid link_config 0x%x"
7926 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007927 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007928 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007929 return;
7930 }
7931 break;
7932
7933 case PORT_FEATURE_LINK_SPEED_2_5G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007934 if (bp->port.supported & SUPPORTED_2500baseX_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007935 bp->link_params.req_line_speed = SPEED_2500;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007936 bp->port.advertising = (ADVERTISED_2500baseX_Full |
7937 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007938 } else {
7939 BNX2X_ERR("NVRAM config error. "
7940 "Invalid link_config 0x%x"
7941 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007942 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007943 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007944 return;
7945 }
7946 break;
7947
7948 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7949 case PORT_FEATURE_LINK_SPEED_10G_KX4:
7950 case PORT_FEATURE_LINK_SPEED_10G_KR:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007951 if (bp->port.supported & SUPPORTED_10000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007952 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007953 bp->port.advertising = (ADVERTISED_10000baseT_Full |
7954 ADVERTISED_FIBRE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007955 } else {
7956 BNX2X_ERR("NVRAM config error. "
7957 "Invalid link_config 0x%x"
7958 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007959 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007960 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007961 return;
7962 }
7963 break;
7964
7965 default:
7966 BNX2X_ERR("NVRAM config error. "
7967 "BAD link speed link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007968 bp->port.link_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007969 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007970 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007971 break;
7972 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007973
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007974 bp->link_params.req_flow_ctrl = (bp->port.link_config &
7975 PORT_FEATURE_FLOW_CONTROL_MASK);
David S. Millerc0700f92008-12-16 23:53:20 -08007976 if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Randy Dunlap4ab84d42008-08-07 20:33:19 -07007977 !(bp->port.supported & SUPPORTED_Autoneg))
David S. Millerc0700f92008-12-16 23:53:20 -08007978 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007979
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007980 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
Eliezer Tamirf1410642008-02-28 11:51:50 -08007981 " advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007982 bp->link_params.req_line_speed,
7983 bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007984 bp->link_params.req_flow_ctrl, bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007985}
7986
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007987static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007988{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007989 int port = BP_PORT(bp);
7990 u32 val, val2;
Eilon Greenstein589abe32009-02-12 08:36:55 +00007991 u32 config;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007992 u16 i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007993
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007994 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007995 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007996
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007997 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007998 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007999 bp->link_params.ext_phy_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008000 SHMEM_RD(bp,
8001 dev_info.port_hw_config[port].external_phy_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008002 bp->link_params.speed_cap_mask =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008003 SHMEM_RD(bp,
8004 dev_info.port_hw_config[port].speed_capability_mask);
8005
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008006 bp->port.link_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008007 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8008
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008009 /* Get the 4 lanes xgxs config rx and tx */
8010 for (i = 0; i < 2; i++) {
8011 val = SHMEM_RD(bp,
8012 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
8013 bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
8014 bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
8015
8016 val = SHMEM_RD(bp,
8017 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
8018 bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
8019 bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
8020 }
8021
Eilon Greenstein589abe32009-02-12 08:36:55 +00008022 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
8023 if (config & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_ENABLED)
8024 bp->link_params.feature_config_flags |=
8025 FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
8026 else
8027 bp->link_params.feature_config_flags &=
8028 ~FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
8029
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008030 BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
8031 " speed_cap_mask 0x%08x link_config 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008032 bp->link_params.lane_config,
8033 bp->link_params.ext_phy_config,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008034 bp->link_params.speed_cap_mask, bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008035
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008036 bp->link_params.switch_cfg = (bp->port.link_config &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008037 PORT_FEATURE_CONNECTED_SWITCH_MASK);
8038 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008039
8040 bnx2x_link_settings_requested(bp);
8041
8042 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8043 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8044 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
8045 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8046 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8047 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8048 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8049 bp->dev->dev_addr[5] = (u8)(val & 0xff);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008050 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8051 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008052}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008053
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008054static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8055{
8056 int func = BP_FUNC(bp);
8057 u32 val, val2;
8058 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008059
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008060 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008061
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008062 bp->e1hov = 0;
8063 bp->e1hmf = 0;
8064 if (CHIP_IS_E1H(bp)) {
8065 bp->mf_config =
8066 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008067
Eilon Greenstein3196a882008-08-13 15:58:49 -07008068 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].e1hov_tag) &
8069 FUNC_MF_CFG_E1HOV_TAG_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008070 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008071
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008072 bp->e1hov = val;
8073 bp->e1hmf = 1;
8074 BNX2X_DEV_INFO("MF mode E1HOV for func %d is %d "
8075 "(0x%04x)\n",
8076 func, bp->e1hov, bp->e1hov);
8077 } else {
8078 BNX2X_DEV_INFO("Single function mode\n");
8079 if (BP_E1HVN(bp)) {
8080 BNX2X_ERR("!!! No valid E1HOV for func %d,"
8081 " aborting\n", func);
8082 rc = -EPERM;
8083 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008084 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008085 }
8086
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008087 if (!BP_NOMCP(bp)) {
8088 bnx2x_get_port_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008089
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008090 bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
8091 DRV_MSG_SEQ_NUMBER_MASK);
8092 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
8093 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008094
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008095 if (IS_E1HMF(bp)) {
8096 val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
8097 val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
8098 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8099 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
8100 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
8101 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8102 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8103 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8104 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8105 bp->dev->dev_addr[5] = (u8)(val & 0xff);
8106 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
8107 ETH_ALEN);
8108 memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
8109 ETH_ALEN);
8110 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008111
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008112 return rc;
8113 }
8114
8115 if (BP_NOMCP(bp)) {
8116 /* only supposed to happen on emulation/FPGA */
Eilon Greenstein33471622008-08-13 15:59:08 -07008117 BNX2X_ERR("warning random MAC workaround active\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008118 random_ether_addr(bp->dev->dev_addr);
8119 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8120 }
8121
8122 return rc;
8123}
8124
8125static int __devinit bnx2x_init_bp(struct bnx2x *bp)
8126{
8127 int func = BP_FUNC(bp);
Eilon Greenstein87942b42009-02-12 08:36:49 +00008128 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008129 int rc;
8130
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008131 /* Disable interrupt handling until HW is initialized */
8132 atomic_set(&bp->intr_sem, 1);
8133
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008134 mutex_init(&bp->port.phy_mutex);
8135
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08008136 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008137 INIT_WORK(&bp->reset_task, bnx2x_reset_task);
8138
8139 rc = bnx2x_get_hwinfo(bp);
8140
8141 /* need to reset chip if undi was active */
8142 if (!BP_NOMCP(bp))
8143 bnx2x_undi_unload(bp);
8144
8145 if (CHIP_REV_IS_FPGA(bp))
8146 printk(KERN_ERR PFX "FPGA detected\n");
8147
8148 if (BP_NOMCP(bp) && (func == 0))
8149 printk(KERN_ERR PFX
8150 "MCP disabled, must load devices in order!\n");
8151
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008152 /* Set multi queue mode */
Eilon Greenstein8badd272009-02-12 08:36:15 +00008153 if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
8154 ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008155 printk(KERN_ERR PFX
Eilon Greenstein8badd272009-02-12 08:36:15 +00008156 "Multi disabled since int_mode requested is not MSI-X\n");
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008157 multi_mode = ETH_RSS_MODE_DISABLED;
8158 }
8159 bp->multi_mode = multi_mode;
8160
8161
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008162 /* Set TPA flags */
8163 if (disable_tpa) {
8164 bp->flags &= ~TPA_ENABLE_FLAG;
8165 bp->dev->features &= ~NETIF_F_LRO;
8166 } else {
8167 bp->flags |= TPA_ENABLE_FLAG;
8168 bp->dev->features |= NETIF_F_LRO;
8169 }
8170
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00008171 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008172
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008173 bp->tx_ring_size = MAX_TX_AVAIL;
8174 bp->rx_ring_size = MAX_RX_AVAIL;
8175
8176 bp->rx_csum = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008177
8178 bp->tx_ticks = 50;
8179 bp->rx_ticks = 25;
8180
Eilon Greenstein87942b42009-02-12 08:36:49 +00008181 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
8182 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008183
8184 init_timer(&bp->timer);
8185 bp->timer.expires = jiffies + bp->current_interval;
8186 bp->timer.data = (unsigned long) bp;
8187 bp->timer.function = bnx2x_timer;
8188
8189 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008190}
8191
8192/*
8193 * ethtool service functions
8194 */
8195
8196/* All ethtool functions called with rtnl_lock */
8197
8198static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8199{
8200 struct bnx2x *bp = netdev_priv(dev);
8201
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008202 cmd->supported = bp->port.supported;
8203 cmd->advertising = bp->port.advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008204
8205 if (netif_carrier_ok(dev)) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008206 cmd->speed = bp->link_vars.line_speed;
8207 cmd->duplex = bp->link_vars.duplex;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008208 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008209 cmd->speed = bp->link_params.req_line_speed;
8210 cmd->duplex = bp->link_params.req_duplex;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008211 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008212 if (IS_E1HMF(bp)) {
8213 u16 vn_max_rate;
8214
8215 vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
8216 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
8217 if (vn_max_rate < cmd->speed)
8218 cmd->speed = vn_max_rate;
8219 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008220
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008221 if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
8222 u32 ext_phy_type =
8223 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamirf1410642008-02-28 11:51:50 -08008224
8225 switch (ext_phy_type) {
8226 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008227 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008228 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greenstein589abe32009-02-12 08:36:55 +00008229 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
8230 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
8231 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008232 cmd->port = PORT_FIBRE;
8233 break;
8234
8235 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein28577182009-02-12 08:37:00 +00008236 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008237 cmd->port = PORT_TP;
8238 break;
8239
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008240 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8241 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
8242 bp->link_params.ext_phy_config);
8243 break;
8244
Eliezer Tamirf1410642008-02-28 11:51:50 -08008245 default:
8246 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008247 bp->link_params.ext_phy_config);
8248 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008249 }
8250 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008251 cmd->port = PORT_TP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008252
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008253 cmd->phy_address = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008254 cmd->transceiver = XCVR_INTERNAL;
8255
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008256 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008257 cmd->autoneg = AUTONEG_ENABLE;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008258 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008259 cmd->autoneg = AUTONEG_DISABLE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008260
8261 cmd->maxtxpkt = 0;
8262 cmd->maxrxpkt = 0;
8263
8264 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
8265 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
8266 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
8267 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
8268 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
8269 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
8270 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
8271
8272 return 0;
8273}
8274
8275static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8276{
8277 struct bnx2x *bp = netdev_priv(dev);
8278 u32 advertising;
8279
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008280 if (IS_E1HMF(bp))
8281 return 0;
8282
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008283 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
8284 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
8285 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
8286 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
8287 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
8288 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
8289 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
8290
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008291 if (cmd->autoneg == AUTONEG_ENABLE) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008292 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
8293 DP(NETIF_MSG_LINK, "Autoneg not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008294 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008295 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008296
8297 /* advertise the requested speed and duplex if supported */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008298 cmd->advertising &= bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008299
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008300 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
8301 bp->link_params.req_duplex = DUPLEX_FULL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008302 bp->port.advertising |= (ADVERTISED_Autoneg |
8303 cmd->advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008304
8305 } else { /* forced speed */
8306 /* advertise the requested speed and duplex if supported */
8307 switch (cmd->speed) {
8308 case SPEED_10:
8309 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008310 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008311 SUPPORTED_10baseT_Full)) {
8312 DP(NETIF_MSG_LINK,
8313 "10M full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008314 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008315 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008316
8317 advertising = (ADVERTISED_10baseT_Full |
8318 ADVERTISED_TP);
8319 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008320 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008321 SUPPORTED_10baseT_Half)) {
8322 DP(NETIF_MSG_LINK,
8323 "10M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008324 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008325 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008326
8327 advertising = (ADVERTISED_10baseT_Half |
8328 ADVERTISED_TP);
8329 }
8330 break;
8331
8332 case SPEED_100:
8333 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008334 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008335 SUPPORTED_100baseT_Full)) {
8336 DP(NETIF_MSG_LINK,
8337 "100M full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008338 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008339 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008340
8341 advertising = (ADVERTISED_100baseT_Full |
8342 ADVERTISED_TP);
8343 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008344 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008345 SUPPORTED_100baseT_Half)) {
8346 DP(NETIF_MSG_LINK,
8347 "100M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008348 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008349 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008350
8351 advertising = (ADVERTISED_100baseT_Half |
8352 ADVERTISED_TP);
8353 }
8354 break;
8355
8356 case SPEED_1000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008357 if (cmd->duplex != DUPLEX_FULL) {
8358 DP(NETIF_MSG_LINK, "1G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008359 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008360 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008361
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008362 if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008363 DP(NETIF_MSG_LINK, "1G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008364 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008365 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008366
8367 advertising = (ADVERTISED_1000baseT_Full |
8368 ADVERTISED_TP);
8369 break;
8370
8371 case SPEED_2500:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008372 if (cmd->duplex != DUPLEX_FULL) {
8373 DP(NETIF_MSG_LINK,
8374 "2.5G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008375 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008376 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008377
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008378 if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008379 DP(NETIF_MSG_LINK,
8380 "2.5G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008381 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008382 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008383
Eliezer Tamirf1410642008-02-28 11:51:50 -08008384 advertising = (ADVERTISED_2500baseX_Full |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008385 ADVERTISED_TP);
8386 break;
8387
8388 case SPEED_10000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008389 if (cmd->duplex != DUPLEX_FULL) {
8390 DP(NETIF_MSG_LINK, "10G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008391 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008392 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008393
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008394 if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008395 DP(NETIF_MSG_LINK, "10G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008396 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008397 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008398
8399 advertising = (ADVERTISED_10000baseT_Full |
8400 ADVERTISED_FIBRE);
8401 break;
8402
8403 default:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008404 DP(NETIF_MSG_LINK, "Unsupported speed\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008405 return -EINVAL;
8406 }
8407
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008408 bp->link_params.req_line_speed = cmd->speed;
8409 bp->link_params.req_duplex = cmd->duplex;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008410 bp->port.advertising = advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008411 }
8412
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008413 DP(NETIF_MSG_LINK, "req_line_speed %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008414 DP_LEVEL " req_duplex %d advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008415 bp->link_params.req_line_speed, bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008416 bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008417
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008418 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008419 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008420 bnx2x_link_set(bp);
8421 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008422
8423 return 0;
8424}
8425
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008426#define PHY_FW_VER_LEN 10
8427
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008428static void bnx2x_get_drvinfo(struct net_device *dev,
8429 struct ethtool_drvinfo *info)
8430{
8431 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinf0e53a82008-08-13 15:58:30 -07008432 u8 phy_fw_ver[PHY_FW_VER_LEN];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008433
8434 strcpy(info->driver, DRV_MODULE_NAME);
8435 strcpy(info->version, DRV_MODULE_VERSION);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008436
8437 phy_fw_ver[0] = '\0';
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008438 if (bp->port.pmf) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008439 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008440 bnx2x_get_ext_phy_fw_version(&bp->link_params,
8441 (bp->state != BNX2X_STATE_CLOSED),
8442 phy_fw_ver, PHY_FW_VER_LEN);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008443 bnx2x_release_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008444 }
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008445
Eilon Greensteinf0e53a82008-08-13 15:58:30 -07008446 snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s",
8447 (bp->common.bc_ver & 0xff0000) >> 16,
8448 (bp->common.bc_ver & 0xff00) >> 8,
8449 (bp->common.bc_ver & 0xff),
8450 ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008451 strcpy(info->bus_info, pci_name(bp->pdev));
8452 info->n_stats = BNX2X_NUM_STATS;
8453 info->testinfo_len = BNX2X_NUM_TESTS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008454 info->eedump_len = bp->common.flash_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008455 info->regdump_len = 0;
8456}
8457
8458static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8459{
8460 struct bnx2x *bp = netdev_priv(dev);
8461
8462 if (bp->flags & NO_WOL_FLAG) {
8463 wol->supported = 0;
8464 wol->wolopts = 0;
8465 } else {
8466 wol->supported = WAKE_MAGIC;
8467 if (bp->wol)
8468 wol->wolopts = WAKE_MAGIC;
8469 else
8470 wol->wolopts = 0;
8471 }
8472 memset(&wol->sopass, 0, sizeof(wol->sopass));
8473}
8474
8475static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8476{
8477 struct bnx2x *bp = netdev_priv(dev);
8478
8479 if (wol->wolopts & ~WAKE_MAGIC)
8480 return -EINVAL;
8481
8482 if (wol->wolopts & WAKE_MAGIC) {
8483 if (bp->flags & NO_WOL_FLAG)
8484 return -EINVAL;
8485
8486 bp->wol = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008487 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008488 bp->wol = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008489
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008490 return 0;
8491}
8492
8493static u32 bnx2x_get_msglevel(struct net_device *dev)
8494{
8495 struct bnx2x *bp = netdev_priv(dev);
8496
8497 return bp->msglevel;
8498}
8499
8500static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
8501{
8502 struct bnx2x *bp = netdev_priv(dev);
8503
8504 if (capable(CAP_NET_ADMIN))
8505 bp->msglevel = level;
8506}
8507
8508static int bnx2x_nway_reset(struct net_device *dev)
8509{
8510 struct bnx2x *bp = netdev_priv(dev);
8511
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008512 if (!bp->port.pmf)
8513 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008514
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008515 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008516 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008517 bnx2x_link_set(bp);
8518 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008519
8520 return 0;
8521}
8522
8523static int bnx2x_get_eeprom_len(struct net_device *dev)
8524{
8525 struct bnx2x *bp = netdev_priv(dev);
8526
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008527 return bp->common.flash_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008528}
8529
8530static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
8531{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008532 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008533 int count, i;
8534 u32 val = 0;
8535
8536 /* adjust timeout for emulation/FPGA */
8537 count = NVRAM_TIMEOUT_COUNT;
8538 if (CHIP_REV_IS_SLOW(bp))
8539 count *= 100;
8540
8541 /* request access to nvram interface */
8542 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
8543 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
8544
8545 for (i = 0; i < count*10; i++) {
8546 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
8547 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
8548 break;
8549
8550 udelay(5);
8551 }
8552
8553 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008554 DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008555 return -EBUSY;
8556 }
8557
8558 return 0;
8559}
8560
8561static int bnx2x_release_nvram_lock(struct bnx2x *bp)
8562{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008563 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008564 int count, i;
8565 u32 val = 0;
8566
8567 /* adjust timeout for emulation/FPGA */
8568 count = NVRAM_TIMEOUT_COUNT;
8569 if (CHIP_REV_IS_SLOW(bp))
8570 count *= 100;
8571
8572 /* relinquish nvram interface */
8573 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
8574 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
8575
8576 for (i = 0; i < count*10; i++) {
8577 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
8578 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
8579 break;
8580
8581 udelay(5);
8582 }
8583
8584 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008585 DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008586 return -EBUSY;
8587 }
8588
8589 return 0;
8590}
8591
8592static void bnx2x_enable_nvram_access(struct bnx2x *bp)
8593{
8594 u32 val;
8595
8596 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
8597
8598 /* enable both bits, even on read */
8599 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
8600 (val | MCPR_NVM_ACCESS_ENABLE_EN |
8601 MCPR_NVM_ACCESS_ENABLE_WR_EN));
8602}
8603
8604static void bnx2x_disable_nvram_access(struct bnx2x *bp)
8605{
8606 u32 val;
8607
8608 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
8609
8610 /* disable both bits, even after read */
8611 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
8612 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
8613 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
8614}
8615
8616static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, u32 *ret_val,
8617 u32 cmd_flags)
8618{
Eliezer Tamirf1410642008-02-28 11:51:50 -08008619 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008620 u32 val;
8621
8622 /* build the command word */
8623 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
8624
8625 /* need to clear DONE bit separately */
8626 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
8627
8628 /* address of the NVRAM to read from */
8629 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
8630 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
8631
8632 /* issue a read command */
8633 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
8634
8635 /* adjust timeout for emulation/FPGA */
8636 count = NVRAM_TIMEOUT_COUNT;
8637 if (CHIP_REV_IS_SLOW(bp))
8638 count *= 100;
8639
8640 /* wait for completion */
8641 *ret_val = 0;
8642 rc = -EBUSY;
8643 for (i = 0; i < count; i++) {
8644 udelay(5);
8645 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
8646
8647 if (val & MCPR_NVM_COMMAND_DONE) {
8648 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008649 /* we read nvram data in cpu order
8650 * but ethtool sees it as an array of bytes
8651 * converting to big-endian will do the work */
8652 val = cpu_to_be32(val);
8653 *ret_val = val;
8654 rc = 0;
8655 break;
8656 }
8657 }
8658
8659 return rc;
8660}
8661
8662static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
8663 int buf_size)
8664{
8665 int rc;
8666 u32 cmd_flags;
8667 u32 val;
8668
8669 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008670 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08008671 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008672 offset, buf_size);
8673 return -EINVAL;
8674 }
8675
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008676 if (offset + buf_size > bp->common.flash_size) {
8677 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008678 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008679 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008680 return -EINVAL;
8681 }
8682
8683 /* request access to nvram interface */
8684 rc = bnx2x_acquire_nvram_lock(bp);
8685 if (rc)
8686 return rc;
8687
8688 /* enable access to nvram interface */
8689 bnx2x_enable_nvram_access(bp);
8690
8691 /* read the first word(s) */
8692 cmd_flags = MCPR_NVM_COMMAND_FIRST;
8693 while ((buf_size > sizeof(u32)) && (rc == 0)) {
8694 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
8695 memcpy(ret_buf, &val, 4);
8696
8697 /* advance to the next dword */
8698 offset += sizeof(u32);
8699 ret_buf += sizeof(u32);
8700 buf_size -= sizeof(u32);
8701 cmd_flags = 0;
8702 }
8703
8704 if (rc == 0) {
8705 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8706 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
8707 memcpy(ret_buf, &val, 4);
8708 }
8709
8710 /* disable access to nvram interface */
8711 bnx2x_disable_nvram_access(bp);
8712 bnx2x_release_nvram_lock(bp);
8713
8714 return rc;
8715}
8716
8717static int bnx2x_get_eeprom(struct net_device *dev,
8718 struct ethtool_eeprom *eeprom, u8 *eebuf)
8719{
8720 struct bnx2x *bp = netdev_priv(dev);
8721 int rc;
8722
Eilon Greenstein2add3ac2009-01-14 06:44:07 +00008723 if (!netif_running(dev))
8724 return -EAGAIN;
8725
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008726 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008727 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
8728 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
8729 eeprom->len, eeprom->len);
8730
8731 /* parameters already validated in ethtool_get_eeprom */
8732
8733 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
8734
8735 return rc;
8736}
8737
8738static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
8739 u32 cmd_flags)
8740{
Eliezer Tamirf1410642008-02-28 11:51:50 -08008741 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008742
8743 /* build the command word */
8744 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
8745
8746 /* need to clear DONE bit separately */
8747 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
8748
8749 /* write the data */
8750 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
8751
8752 /* address of the NVRAM to write to */
8753 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
8754 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
8755
8756 /* issue the write command */
8757 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
8758
8759 /* adjust timeout for emulation/FPGA */
8760 count = NVRAM_TIMEOUT_COUNT;
8761 if (CHIP_REV_IS_SLOW(bp))
8762 count *= 100;
8763
8764 /* wait for completion */
8765 rc = -EBUSY;
8766 for (i = 0; i < count; i++) {
8767 udelay(5);
8768 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
8769 if (val & MCPR_NVM_COMMAND_DONE) {
8770 rc = 0;
8771 break;
8772 }
8773 }
8774
8775 return rc;
8776}
8777
Eliezer Tamirf1410642008-02-28 11:51:50 -08008778#define BYTE_OFFSET(offset) (8 * (offset & 0x03))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008779
8780static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
8781 int buf_size)
8782{
8783 int rc;
8784 u32 cmd_flags;
8785 u32 align_offset;
8786 u32 val;
8787
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008788 if (offset + buf_size > bp->common.flash_size) {
8789 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008790 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008791 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008792 return -EINVAL;
8793 }
8794
8795 /* request access to nvram interface */
8796 rc = bnx2x_acquire_nvram_lock(bp);
8797 if (rc)
8798 return rc;
8799
8800 /* enable access to nvram interface */
8801 bnx2x_enable_nvram_access(bp);
8802
8803 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
8804 align_offset = (offset & ~0x03);
8805 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
8806
8807 if (rc == 0) {
8808 val &= ~(0xff << BYTE_OFFSET(offset));
8809 val |= (*data_buf << BYTE_OFFSET(offset));
8810
8811 /* nvram data is returned as an array of bytes
8812 * convert it back to cpu order */
8813 val = be32_to_cpu(val);
8814
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008815 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
8816 cmd_flags);
8817 }
8818
8819 /* disable access to nvram interface */
8820 bnx2x_disable_nvram_access(bp);
8821 bnx2x_release_nvram_lock(bp);
8822
8823 return rc;
8824}
8825
8826static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
8827 int buf_size)
8828{
8829 int rc;
8830 u32 cmd_flags;
8831 u32 val;
8832 u32 written_so_far;
8833
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008834 if (buf_size == 1) /* ethtool */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008835 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008836
8837 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008838 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08008839 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008840 offset, buf_size);
8841 return -EINVAL;
8842 }
8843
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008844 if (offset + buf_size > bp->common.flash_size) {
8845 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008846 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008847 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008848 return -EINVAL;
8849 }
8850
8851 /* request access to nvram interface */
8852 rc = bnx2x_acquire_nvram_lock(bp);
8853 if (rc)
8854 return rc;
8855
8856 /* enable access to nvram interface */
8857 bnx2x_enable_nvram_access(bp);
8858
8859 written_so_far = 0;
8860 cmd_flags = MCPR_NVM_COMMAND_FIRST;
8861 while ((written_so_far < buf_size) && (rc == 0)) {
8862 if (written_so_far == (buf_size - sizeof(u32)))
8863 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8864 else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
8865 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8866 else if ((offset % NVRAM_PAGE_SIZE) == 0)
8867 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
8868
8869 memcpy(&val, data_buf, 4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008870
8871 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
8872
8873 /* advance to the next dword */
8874 offset += sizeof(u32);
8875 data_buf += sizeof(u32);
8876 written_so_far += sizeof(u32);
8877 cmd_flags = 0;
8878 }
8879
8880 /* disable access to nvram interface */
8881 bnx2x_disable_nvram_access(bp);
8882 bnx2x_release_nvram_lock(bp);
8883
8884 return rc;
8885}
8886
8887static int bnx2x_set_eeprom(struct net_device *dev,
8888 struct ethtool_eeprom *eeprom, u8 *eebuf)
8889{
8890 struct bnx2x *bp = netdev_priv(dev);
8891 int rc;
8892
Eilon Greenstein9f4c9582009-01-08 11:21:43 -08008893 if (!netif_running(dev))
8894 return -EAGAIN;
8895
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008896 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008897 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
8898 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
8899 eeprom->len, eeprom->len);
8900
8901 /* parameters already validated in ethtool_set_eeprom */
8902
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008903 /* If the magic number is PHY (0x00504859) upgrade the PHY FW */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008904 if (eeprom->magic == 0x00504859)
8905 if (bp->port.pmf) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008906
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008907 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008908 rc = bnx2x_flash_download(bp, BP_PORT(bp),
8909 bp->link_params.ext_phy_config,
8910 (bp->state != BNX2X_STATE_CLOSED),
8911 eebuf, eeprom->len);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008912 if ((bp->state == BNX2X_STATE_OPEN) ||
8913 (bp->state == BNX2X_STATE_DISABLED)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008914 rc |= bnx2x_link_reset(&bp->link_params,
Eilon Greenstein589abe32009-02-12 08:36:55 +00008915 &bp->link_vars, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008916 rc |= bnx2x_phy_init(&bp->link_params,
8917 &bp->link_vars);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008918 }
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008919 bnx2x_release_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008920
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008921 } else /* Only the PMF can access the PHY */
8922 return -EINVAL;
8923 else
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008924 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008925
8926 return rc;
8927}
8928
8929static int bnx2x_get_coalesce(struct net_device *dev,
8930 struct ethtool_coalesce *coal)
8931{
8932 struct bnx2x *bp = netdev_priv(dev);
8933
8934 memset(coal, 0, sizeof(struct ethtool_coalesce));
8935
8936 coal->rx_coalesce_usecs = bp->rx_ticks;
8937 coal->tx_coalesce_usecs = bp->tx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008938
8939 return 0;
8940}
8941
8942static int bnx2x_set_coalesce(struct net_device *dev,
8943 struct ethtool_coalesce *coal)
8944{
8945 struct bnx2x *bp = netdev_priv(dev);
8946
8947 bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
8948 if (bp->rx_ticks > 3000)
8949 bp->rx_ticks = 3000;
8950
8951 bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
8952 if (bp->tx_ticks > 0x3000)
8953 bp->tx_ticks = 0x3000;
8954
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008955 if (netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008956 bnx2x_update_coalesce(bp);
8957
8958 return 0;
8959}
8960
8961static void bnx2x_get_ringparam(struct net_device *dev,
8962 struct ethtool_ringparam *ering)
8963{
8964 struct bnx2x *bp = netdev_priv(dev);
8965
8966 ering->rx_max_pending = MAX_RX_AVAIL;
8967 ering->rx_mini_max_pending = 0;
8968 ering->rx_jumbo_max_pending = 0;
8969
8970 ering->rx_pending = bp->rx_ring_size;
8971 ering->rx_mini_pending = 0;
8972 ering->rx_jumbo_pending = 0;
8973
8974 ering->tx_max_pending = MAX_TX_AVAIL;
8975 ering->tx_pending = bp->tx_ring_size;
8976}
8977
8978static int bnx2x_set_ringparam(struct net_device *dev,
8979 struct ethtool_ringparam *ering)
8980{
8981 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008982 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008983
8984 if ((ering->rx_pending > MAX_RX_AVAIL) ||
8985 (ering->tx_pending > MAX_TX_AVAIL) ||
8986 (ering->tx_pending <= MAX_SKB_FRAGS + 4))
8987 return -EINVAL;
8988
8989 bp->rx_ring_size = ering->rx_pending;
8990 bp->tx_ring_size = ering->tx_pending;
8991
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008992 if (netif_running(dev)) {
8993 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8994 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008995 }
8996
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008997 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008998}
8999
9000static void bnx2x_get_pauseparam(struct net_device *dev,
9001 struct ethtool_pauseparam *epause)
9002{
9003 struct bnx2x *bp = netdev_priv(dev);
9004
David S. Millerc0700f92008-12-16 23:53:20 -08009005 epause->autoneg = (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009006 (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
9007
David S. Millerc0700f92008-12-16 23:53:20 -08009008 epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
9009 BNX2X_FLOW_CTRL_RX);
9010 epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
9011 BNX2X_FLOW_CTRL_TX);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009012
9013 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9014 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9015 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9016}
9017
9018static int bnx2x_set_pauseparam(struct net_device *dev,
9019 struct ethtool_pauseparam *epause)
9020{
9021 struct bnx2x *bp = netdev_priv(dev);
9022
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009023 if (IS_E1HMF(bp))
9024 return 0;
9025
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009026 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9027 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9028 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9029
David S. Millerc0700f92008-12-16 23:53:20 -08009030 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009031
9032 if (epause->rx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -08009033 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009034
9035 if (epause->tx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -08009036 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009037
David S. Millerc0700f92008-12-16 23:53:20 -08009038 if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
9039 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009040
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009041 if (epause->autoneg) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009042 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07009043 DP(NETIF_MSG_LINK, "autoneg not supported\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -08009044 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009045 }
9046
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009047 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
David S. Millerc0700f92008-12-16 23:53:20 -08009048 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009049 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009050
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009051 DP(NETIF_MSG_LINK,
9052 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009053
9054 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009055 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009056 bnx2x_link_set(bp);
9057 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009058
9059 return 0;
9060}
9061
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009062static int bnx2x_set_flags(struct net_device *dev, u32 data)
9063{
9064 struct bnx2x *bp = netdev_priv(dev);
9065 int changed = 0;
9066 int rc = 0;
9067
9068 /* TPA requires Rx CSUM offloading */
9069 if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
9070 if (!(dev->features & NETIF_F_LRO)) {
9071 dev->features |= NETIF_F_LRO;
9072 bp->flags |= TPA_ENABLE_FLAG;
9073 changed = 1;
9074 }
9075
9076 } else if (dev->features & NETIF_F_LRO) {
9077 dev->features &= ~NETIF_F_LRO;
9078 bp->flags &= ~TPA_ENABLE_FLAG;
9079 changed = 1;
9080 }
9081
9082 if (changed && netif_running(dev)) {
9083 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9084 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
9085 }
9086
9087 return rc;
9088}
9089
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009090static u32 bnx2x_get_rx_csum(struct net_device *dev)
9091{
9092 struct bnx2x *bp = netdev_priv(dev);
9093
9094 return bp->rx_csum;
9095}
9096
9097static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
9098{
9099 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009100 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009101
9102 bp->rx_csum = data;
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009103
9104 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
9105 TPA'ed packets will be discarded due to wrong TCP CSUM */
9106 if (!data) {
9107 u32 flags = ethtool_op_get_flags(dev);
9108
9109 rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
9110 }
9111
9112 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009113}
9114
9115static int bnx2x_set_tso(struct net_device *dev, u32 data)
9116{
Eilon Greenstein755735e2008-06-23 20:35:13 -07009117 if (data) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009118 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -07009119 dev->features |= NETIF_F_TSO6;
9120 } else {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009121 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -07009122 dev->features &= ~NETIF_F_TSO6;
9123 }
9124
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009125 return 0;
9126}
9127
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009128static const struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009129 char string[ETH_GSTRING_LEN];
9130} bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009131 { "register_test (offline)" },
9132 { "memory_test (offline)" },
9133 { "loopback_test (offline)" },
9134 { "nvram_test (online)" },
9135 { "interrupt_test (online)" },
9136 { "link_test (online)" },
Eilon Greensteind3d4f492009-02-12 08:36:27 +00009137 { "idle check (online)" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009138};
9139
9140static int bnx2x_self_test_count(struct net_device *dev)
9141{
9142 return BNX2X_NUM_TESTS;
9143}
9144
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009145static int bnx2x_test_registers(struct bnx2x *bp)
9146{
9147 int idx, i, rc = -ENODEV;
9148 u32 wr_val = 0;
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009149 int port = BP_PORT(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009150 static const struct {
9151 u32 offset0;
9152 u32 offset1;
9153 u32 mask;
9154 } reg_tbl[] = {
9155/* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
9156 { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
9157 { HC_REG_AGG_INT_0, 4, 0x000003ff },
9158 { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
9159 { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
9160 { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
9161 { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
9162 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
9163 { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
9164 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
9165/* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
9166 { QM_REG_CONNNUM_0, 4, 0x000fffff },
9167 { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
9168 { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
9169 { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
9170 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
9171 { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
9172 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
9173 { NIG_REG_EGRESS_MNG0_FIFO, 20, 0xffffffff },
9174 { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
9175/* 20 */ { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
9176 { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
9177 { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
9178 { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
9179 { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
9180 { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
9181 { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
9182 { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
9183 { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
9184 { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
9185/* 30 */ { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
9186 { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
9187 { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
9188 { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
9189 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
9190 { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
9191 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
9192 { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
9193
9194 { 0xffffffff, 0, 0x00000000 }
9195 };
9196
9197 if (!netif_running(bp->dev))
9198 return rc;
9199
9200 /* Repeat the test twice:
9201 First by writing 0x00000000, second by writing 0xffffffff */
9202 for (idx = 0; idx < 2; idx++) {
9203
9204 switch (idx) {
9205 case 0:
9206 wr_val = 0;
9207 break;
9208 case 1:
9209 wr_val = 0xffffffff;
9210 break;
9211 }
9212
9213 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
9214 u32 offset, mask, save_val, val;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009215
9216 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
9217 mask = reg_tbl[i].mask;
9218
9219 save_val = REG_RD(bp, offset);
9220
9221 REG_WR(bp, offset, wr_val);
9222 val = REG_RD(bp, offset);
9223
9224 /* Restore the original register's value */
9225 REG_WR(bp, offset, save_val);
9226
9227 /* verify that value is as expected value */
9228 if ((val & mask) != (wr_val & mask))
9229 goto test_reg_exit;
9230 }
9231 }
9232
9233 rc = 0;
9234
9235test_reg_exit:
9236 return rc;
9237}
9238
9239static int bnx2x_test_memory(struct bnx2x *bp)
9240{
9241 int i, j, rc = -ENODEV;
9242 u32 val;
9243 static const struct {
9244 u32 offset;
9245 int size;
9246 } mem_tbl[] = {
9247 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
9248 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
9249 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
9250 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
9251 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
9252 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
9253 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
9254
9255 { 0xffffffff, 0 }
9256 };
9257 static const struct {
9258 char *name;
9259 u32 offset;
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009260 u32 e1_mask;
9261 u32 e1h_mask;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009262 } prty_tbl[] = {
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009263 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
9264 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
9265 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
9266 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
9267 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
9268 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009269
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009270 { NULL, 0xffffffff, 0, 0 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009271 };
9272
9273 if (!netif_running(bp->dev))
9274 return rc;
9275
9276 /* Go through all the memories */
9277 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
9278 for (j = 0; j < mem_tbl[i].size; j++)
9279 REG_RD(bp, mem_tbl[i].offset + j*4);
9280
9281 /* Check the parity status */
9282 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
9283 val = REG_RD(bp, prty_tbl[i].offset);
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009284 if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
9285 (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009286 DP(NETIF_MSG_HW,
9287 "%s is 0x%x\n", prty_tbl[i].name, val);
9288 goto test_mem_exit;
9289 }
9290 }
9291
9292 rc = 0;
9293
9294test_mem_exit:
9295 return rc;
9296}
9297
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009298static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
9299{
9300 int cnt = 1000;
9301
9302 if (link_up)
9303 while (bnx2x_link_test(bp) && cnt--)
9304 msleep(10);
9305}
9306
9307static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
9308{
9309 unsigned int pkt_size, num_pkts, i;
9310 struct sk_buff *skb;
9311 unsigned char *packet;
9312 struct bnx2x_fastpath *fp = &bp->fp[0];
9313 u16 tx_start_idx, tx_idx;
9314 u16 rx_start_idx, rx_idx;
9315 u16 pkt_prod;
9316 struct sw_tx_bd *tx_buf;
9317 struct eth_tx_bd *tx_bd;
9318 dma_addr_t mapping;
9319 union eth_rx_cqe *cqe;
9320 u8 cqe_fp_flags;
9321 struct sw_rx_bd *rx_buf;
9322 u16 len;
9323 int rc = -ENODEV;
9324
9325 if (loopback_mode == BNX2X_MAC_LOOPBACK) {
9326 bp->link_params.loopback_mode = LOOPBACK_BMAC;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009327 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009328
9329 } else if (loopback_mode == BNX2X_PHY_LOOPBACK) {
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009330 u16 cnt = 1000;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009331 bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009332 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009333 /* wait until link state is restored */
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009334 if (link_up)
9335 while (cnt-- && bnx2x_test_link(&bp->link_params,
9336 &bp->link_vars))
9337 msleep(10);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009338 } else
9339 return -EINVAL;
9340
9341 pkt_size = 1514;
9342 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
9343 if (!skb) {
9344 rc = -ENOMEM;
9345 goto test_loopback_exit;
9346 }
9347 packet = skb_put(skb, pkt_size);
9348 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
9349 memset(packet + ETH_ALEN, 0, (ETH_HLEN - ETH_ALEN));
9350 for (i = ETH_HLEN; i < pkt_size; i++)
9351 packet[i] = (unsigned char) (i & 0xff);
9352
9353 num_pkts = 0;
9354 tx_start_idx = le16_to_cpu(*fp->tx_cons_sb);
9355 rx_start_idx = le16_to_cpu(*fp->rx_cons_sb);
9356
9357 pkt_prod = fp->tx_pkt_prod++;
9358 tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
9359 tx_buf->first_bd = fp->tx_bd_prod;
9360 tx_buf->skb = skb;
9361
9362 tx_bd = &fp->tx_desc_ring[TX_BD(fp->tx_bd_prod)];
9363 mapping = pci_map_single(bp->pdev, skb->data,
9364 skb_headlen(skb), PCI_DMA_TODEVICE);
9365 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
9366 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
9367 tx_bd->nbd = cpu_to_le16(1);
9368 tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
9369 tx_bd->vlan = cpu_to_le16(pkt_prod);
9370 tx_bd->bd_flags.as_bitfield = (ETH_TX_BD_FLAGS_START_BD |
9371 ETH_TX_BD_FLAGS_END_BD);
9372 tx_bd->general_data = ((UNICAST_ADDRESS <<
9373 ETH_TX_BD_ETH_ADDR_TYPE_SHIFT) | 1);
9374
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08009375 wmb();
9376
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009377 fp->hw_tx_prods->bds_prod =
9378 cpu_to_le16(le16_to_cpu(fp->hw_tx_prods->bds_prod) + 1);
9379 mb(); /* FW restriction: must not reorder writing nbd and packets */
9380 fp->hw_tx_prods->packets_prod =
9381 cpu_to_le32(le32_to_cpu(fp->hw_tx_prods->packets_prod) + 1);
9382 DOORBELL(bp, FP_IDX(fp), 0);
9383
9384 mmiowb();
9385
9386 num_pkts++;
9387 fp->tx_bd_prod++;
9388 bp->dev->trans_start = jiffies;
9389
9390 udelay(100);
9391
9392 tx_idx = le16_to_cpu(*fp->tx_cons_sb);
9393 if (tx_idx != tx_start_idx + num_pkts)
9394 goto test_loopback_exit;
9395
9396 rx_idx = le16_to_cpu(*fp->rx_cons_sb);
9397 if (rx_idx != rx_start_idx + num_pkts)
9398 goto test_loopback_exit;
9399
9400 cqe = &fp->rx_comp_ring[RCQ_BD(fp->rx_comp_cons)];
9401 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
9402 if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
9403 goto test_loopback_rx_exit;
9404
9405 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
9406 if (len != pkt_size)
9407 goto test_loopback_rx_exit;
9408
9409 rx_buf = &fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)];
9410 skb = rx_buf->skb;
9411 skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
9412 for (i = ETH_HLEN; i < pkt_size; i++)
9413 if (*(skb->data + i) != (unsigned char) (i & 0xff))
9414 goto test_loopback_rx_exit;
9415
9416 rc = 0;
9417
9418test_loopback_rx_exit:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009419
9420 fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons);
9421 fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod);
9422 fp->rx_comp_cons = NEXT_RCQ_IDX(fp->rx_comp_cons);
9423 fp->rx_comp_prod = NEXT_RCQ_IDX(fp->rx_comp_prod);
9424
9425 /* Update producers */
9426 bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
9427 fp->rx_sge_prod);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009428
9429test_loopback_exit:
9430 bp->link_params.loopback_mode = LOOPBACK_NONE;
9431
9432 return rc;
9433}
9434
9435static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
9436{
9437 int rc = 0;
9438
9439 if (!netif_running(bp->dev))
9440 return BNX2X_LOOPBACK_FAILED;
9441
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07009442 bnx2x_netif_stop(bp, 1);
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009443 bnx2x_acquire_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009444
9445 if (bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up)) {
9446 DP(NETIF_MSG_PROBE, "MAC loopback failed\n");
9447 rc |= BNX2X_MAC_LOOPBACK_FAILED;
9448 }
9449
9450 if (bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up)) {
9451 DP(NETIF_MSG_PROBE, "PHY loopback failed\n");
9452 rc |= BNX2X_PHY_LOOPBACK_FAILED;
9453 }
9454
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009455 bnx2x_release_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009456 bnx2x_netif_start(bp);
9457
9458 return rc;
9459}
9460
9461#define CRC32_RESIDUAL 0xdebb20e3
9462
9463static int bnx2x_test_nvram(struct bnx2x *bp)
9464{
9465 static const struct {
9466 int offset;
9467 int size;
9468 } nvram_tbl[] = {
9469 { 0, 0x14 }, /* bootstrap */
9470 { 0x14, 0xec }, /* dir */
9471 { 0x100, 0x350 }, /* manuf_info */
9472 { 0x450, 0xf0 }, /* feature_info */
9473 { 0x640, 0x64 }, /* upgrade_key_info */
9474 { 0x6a4, 0x64 },
9475 { 0x708, 0x70 }, /* manuf_key_info */
9476 { 0x778, 0x70 },
9477 { 0, 0 }
9478 };
9479 u32 buf[0x350 / 4];
9480 u8 *data = (u8 *)buf;
9481 int i, rc;
9482 u32 magic, csum;
9483
9484 rc = bnx2x_nvram_read(bp, 0, data, 4);
9485 if (rc) {
9486 DP(NETIF_MSG_PROBE, "magic value read (rc -%d)\n", -rc);
9487 goto test_nvram_exit;
9488 }
9489
9490 magic = be32_to_cpu(buf[0]);
9491 if (magic != 0x669955aa) {
9492 DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
9493 rc = -ENODEV;
9494 goto test_nvram_exit;
9495 }
9496
9497 for (i = 0; nvram_tbl[i].size; i++) {
9498
9499 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
9500 nvram_tbl[i].size);
9501 if (rc) {
9502 DP(NETIF_MSG_PROBE,
9503 "nvram_tbl[%d] read data (rc -%d)\n", i, -rc);
9504 goto test_nvram_exit;
9505 }
9506
9507 csum = ether_crc_le(nvram_tbl[i].size, data);
9508 if (csum != CRC32_RESIDUAL) {
9509 DP(NETIF_MSG_PROBE,
9510 "nvram_tbl[%d] csum value (0x%08x)\n", i, csum);
9511 rc = -ENODEV;
9512 goto test_nvram_exit;
9513 }
9514 }
9515
9516test_nvram_exit:
9517 return rc;
9518}
9519
9520static int bnx2x_test_intr(struct bnx2x *bp)
9521{
9522 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
9523 int i, rc;
9524
9525 if (!netif_running(bp->dev))
9526 return -ENODEV;
9527
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08009528 config->hdr.length = 0;
Eilon Greensteinaf246402009-01-14 06:43:59 +00009529 if (CHIP_IS_E1(bp))
9530 config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
9531 else
9532 config->hdr.offset = BP_FUNC(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009533 config->hdr.client_id = BP_CL_ID(bp);
9534 config->hdr.reserved1 = 0;
9535
9536 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
9537 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
9538 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
9539 if (rc == 0) {
9540 bp->set_mac_pending++;
9541 for (i = 0; i < 10; i++) {
9542 if (!bp->set_mac_pending)
9543 break;
9544 msleep_interruptible(10);
9545 }
9546 if (i == 10)
9547 rc = -ENODEV;
9548 }
9549
9550 return rc;
9551}
9552
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009553static void bnx2x_self_test(struct net_device *dev,
9554 struct ethtool_test *etest, u64 *buf)
9555{
9556 struct bnx2x *bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009557
9558 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
9559
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009560 if (!netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009561 return;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009562
Eilon Greenstein33471622008-08-13 15:59:08 -07009563 /* offline tests are not supported in MF mode */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009564 if (IS_E1HMF(bp))
9565 etest->flags &= ~ETH_TEST_FL_OFFLINE;
9566
9567 if (etest->flags & ETH_TEST_FL_OFFLINE) {
9568 u8 link_up;
9569
9570 link_up = bp->link_vars.link_up;
9571 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9572 bnx2x_nic_load(bp, LOAD_DIAG);
9573 /* wait until link state is restored */
9574 bnx2x_wait_for_link(bp, link_up);
9575
9576 if (bnx2x_test_registers(bp) != 0) {
9577 buf[0] = 1;
9578 etest->flags |= ETH_TEST_FL_FAILED;
9579 }
9580 if (bnx2x_test_memory(bp) != 0) {
9581 buf[1] = 1;
9582 etest->flags |= ETH_TEST_FL_FAILED;
9583 }
9584 buf[2] = bnx2x_test_loopback(bp, link_up);
9585 if (buf[2] != 0)
9586 etest->flags |= ETH_TEST_FL_FAILED;
9587
9588 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9589 bnx2x_nic_load(bp, LOAD_NORMAL);
9590 /* wait until link state is restored */
9591 bnx2x_wait_for_link(bp, link_up);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009592 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009593 if (bnx2x_test_nvram(bp) != 0) {
9594 buf[3] = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009595 etest->flags |= ETH_TEST_FL_FAILED;
9596 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009597 if (bnx2x_test_intr(bp) != 0) {
9598 buf[4] = 1;
9599 etest->flags |= ETH_TEST_FL_FAILED;
9600 }
9601 if (bp->port.pmf)
9602 if (bnx2x_link_test(bp) != 0) {
9603 buf[5] = 1;
9604 etest->flags |= ETH_TEST_FL_FAILED;
9605 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009606
9607#ifdef BNX2X_EXTRA_DEBUG
9608 bnx2x_panic_dump(bp);
9609#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009610}
9611
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009612static const struct {
9613 long offset;
9614 int size;
Eilon Greensteinde832a52009-02-12 08:36:33 +00009615 u8 string[ETH_GSTRING_LEN];
9616} bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
9617/* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
9618 { Q_STATS_OFFSET32(error_bytes_received_hi),
9619 8, "[%d]: rx_error_bytes" },
9620 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
9621 8, "[%d]: rx_ucast_packets" },
9622 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
9623 8, "[%d]: rx_mcast_packets" },
9624 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
9625 8, "[%d]: rx_bcast_packets" },
9626 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
9627 { Q_STATS_OFFSET32(rx_err_discard_pkt),
9628 4, "[%d]: rx_phy_ip_err_discards"},
9629 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
9630 4, "[%d]: rx_skb_alloc_discard" },
9631 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
9632
9633/* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
9634 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
9635 8, "[%d]: tx_packets" }
9636};
9637
9638static const struct {
9639 long offset;
9640 int size;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009641 u32 flags;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009642#define STATS_FLAGS_PORT 1
9643#define STATS_FLAGS_FUNC 2
Eilon Greensteinde832a52009-02-12 08:36:33 +00009644#define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009645 u8 string[ETH_GSTRING_LEN];
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009646} bnx2x_stats_arr[BNX2X_NUM_STATS] = {
Eilon Greensteinde832a52009-02-12 08:36:33 +00009647/* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
9648 8, STATS_FLAGS_BOTH, "rx_bytes" },
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009649 { STATS_OFFSET32(error_bytes_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009650 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009651 { STATS_OFFSET32(total_unicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009652 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009653 { STATS_OFFSET32(total_multicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009654 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009655 { STATS_OFFSET32(total_broadcast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009656 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009657 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009658 8, STATS_FLAGS_PORT, "rx_crc_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009659 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009660 8, STATS_FLAGS_PORT, "rx_align_errors" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009661 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
9662 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
9663 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
9664 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
9665/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
9666 8, STATS_FLAGS_PORT, "rx_fragments" },
9667 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
9668 8, STATS_FLAGS_PORT, "rx_jabbers" },
9669 { STATS_OFFSET32(no_buff_discard_hi),
9670 8, STATS_FLAGS_BOTH, "rx_discards" },
9671 { STATS_OFFSET32(mac_filter_discard),
9672 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
9673 { STATS_OFFSET32(xxoverflow_discard),
9674 4, STATS_FLAGS_PORT, "rx_fw_discards" },
9675 { STATS_OFFSET32(brb_drop_hi),
9676 8, STATS_FLAGS_PORT, "rx_brb_discard" },
9677 { STATS_OFFSET32(brb_truncate_hi),
9678 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
9679 { STATS_OFFSET32(pause_frames_received_hi),
9680 8, STATS_FLAGS_PORT, "rx_pause_frames" },
9681 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
9682 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
9683 { STATS_OFFSET32(nig_timer_max),
9684 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
9685/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
9686 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
9687 { STATS_OFFSET32(rx_skb_alloc_failed),
9688 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
9689 { STATS_OFFSET32(hw_csum_err),
9690 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
9691
9692 { STATS_OFFSET32(total_bytes_transmitted_hi),
9693 8, STATS_FLAGS_BOTH, "tx_bytes" },
9694 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
9695 8, STATS_FLAGS_PORT, "tx_error_bytes" },
9696 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
9697 8, STATS_FLAGS_BOTH, "tx_packets" },
9698 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
9699 8, STATS_FLAGS_PORT, "tx_mac_errors" },
9700 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
9701 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009702 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009703 8, STATS_FLAGS_PORT, "tx_single_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009704 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009705 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009706/* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009707 8, STATS_FLAGS_PORT, "tx_deferred" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009708 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009709 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009710 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009711 8, STATS_FLAGS_PORT, "tx_late_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009712 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009713 8, STATS_FLAGS_PORT, "tx_total_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009714 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009715 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009716 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009717 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009718 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009719 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009720 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009721 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009722 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009723 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009724 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009725 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009726/* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009727 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009728 { STATS_OFFSET32(pause_frames_sent_hi),
9729 8, STATS_FLAGS_PORT, "tx_pause_frames" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009730};
9731
Eilon Greensteinde832a52009-02-12 08:36:33 +00009732#define IS_PORT_STAT(i) \
9733 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
9734#define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
9735#define IS_E1HMF_MODE_STAT(bp) \
9736 (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS))
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009737
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009738static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
9739{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009740 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009741 int i, j, k;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009742
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009743 switch (stringset) {
9744 case ETH_SS_STATS:
Eilon Greensteinde832a52009-02-12 08:36:33 +00009745 if (is_multi(bp)) {
9746 k = 0;
9747 for_each_queue(bp, i) {
9748 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
9749 sprintf(buf + (k + j)*ETH_GSTRING_LEN,
9750 bnx2x_q_stats_arr[j].string, i);
9751 k += BNX2X_NUM_Q_STATS;
9752 }
9753 if (IS_E1HMF_MODE_STAT(bp))
9754 break;
9755 for (j = 0; j < BNX2X_NUM_STATS; j++)
9756 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
9757 bnx2x_stats_arr[j].string);
9758 } else {
9759 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
9760 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
9761 continue;
9762 strcpy(buf + j*ETH_GSTRING_LEN,
9763 bnx2x_stats_arr[i].string);
9764 j++;
9765 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009766 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009767 break;
9768
9769 case ETH_SS_TEST:
9770 memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
9771 break;
9772 }
9773}
9774
9775static int bnx2x_get_stats_count(struct net_device *dev)
9776{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009777 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009778 int i, num_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009779
Eilon Greensteinde832a52009-02-12 08:36:33 +00009780 if (is_multi(bp)) {
9781 num_stats = BNX2X_NUM_Q_STATS * BNX2X_NUM_QUEUES(bp);
9782 if (!IS_E1HMF_MODE_STAT(bp))
9783 num_stats += BNX2X_NUM_STATS;
9784 } else {
9785 if (IS_E1HMF_MODE_STAT(bp)) {
9786 num_stats = 0;
9787 for (i = 0; i < BNX2X_NUM_STATS; i++)
9788 if (IS_FUNC_STAT(i))
9789 num_stats++;
9790 } else
9791 num_stats = BNX2X_NUM_STATS;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009792 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009793
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009794 return num_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009795}
9796
9797static void bnx2x_get_ethtool_stats(struct net_device *dev,
9798 struct ethtool_stats *stats, u64 *buf)
9799{
9800 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009801 u32 *hw_stats, *offset;
9802 int i, j, k;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009803
Eilon Greensteinde832a52009-02-12 08:36:33 +00009804 if (is_multi(bp)) {
9805 k = 0;
9806 for_each_queue(bp, i) {
9807 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
9808 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
9809 if (bnx2x_q_stats_arr[j].size == 0) {
9810 /* skip this counter */
9811 buf[k + j] = 0;
9812 continue;
9813 }
9814 offset = (hw_stats +
9815 bnx2x_q_stats_arr[j].offset);
9816 if (bnx2x_q_stats_arr[j].size == 4) {
9817 /* 4-byte counter */
9818 buf[k + j] = (u64) *offset;
9819 continue;
9820 }
9821 /* 8-byte counter */
9822 buf[k + j] = HILO_U64(*offset, *(offset + 1));
9823 }
9824 k += BNX2X_NUM_Q_STATS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009825 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009826 if (IS_E1HMF_MODE_STAT(bp))
9827 return;
9828 hw_stats = (u32 *)&bp->eth_stats;
9829 for (j = 0; j < BNX2X_NUM_STATS; j++) {
9830 if (bnx2x_stats_arr[j].size == 0) {
9831 /* skip this counter */
9832 buf[k + j] = 0;
9833 continue;
9834 }
9835 offset = (hw_stats + bnx2x_stats_arr[j].offset);
9836 if (bnx2x_stats_arr[j].size == 4) {
9837 /* 4-byte counter */
9838 buf[k + j] = (u64) *offset;
9839 continue;
9840 }
9841 /* 8-byte counter */
9842 buf[k + j] = HILO_U64(*offset, *(offset + 1));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009843 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009844 } else {
9845 hw_stats = (u32 *)&bp->eth_stats;
9846 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
9847 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
9848 continue;
9849 if (bnx2x_stats_arr[i].size == 0) {
9850 /* skip this counter */
9851 buf[j] = 0;
9852 j++;
9853 continue;
9854 }
9855 offset = (hw_stats + bnx2x_stats_arr[i].offset);
9856 if (bnx2x_stats_arr[i].size == 4) {
9857 /* 4-byte counter */
9858 buf[j] = (u64) *offset;
9859 j++;
9860 continue;
9861 }
9862 /* 8-byte counter */
9863 buf[j] = HILO_U64(*offset, *(offset + 1));
9864 j++;
9865 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009866 }
9867}
9868
9869static int bnx2x_phys_id(struct net_device *dev, u32 data)
9870{
9871 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009872 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009873 int i;
9874
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009875 if (!netif_running(dev))
9876 return 0;
9877
9878 if (!bp->port.pmf)
9879 return 0;
9880
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009881 if (data == 0)
9882 data = 2;
9883
9884 for (i = 0; i < (data * 2); i++) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009885 if ((i % 2) == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009886 bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009887 bp->link_params.hw_led_mode,
9888 bp->link_params.chip_id);
9889 else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009890 bnx2x_set_led(bp, port, LED_MODE_OFF, 0,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009891 bp->link_params.hw_led_mode,
9892 bp->link_params.chip_id);
9893
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009894 msleep_interruptible(500);
9895 if (signal_pending(current))
9896 break;
9897 }
9898
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009899 if (bp->link_vars.link_up)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009900 bnx2x_set_led(bp, port, LED_MODE_OPER,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009901 bp->link_vars.line_speed,
9902 bp->link_params.hw_led_mode,
9903 bp->link_params.chip_id);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009904
9905 return 0;
9906}
9907
9908static struct ethtool_ops bnx2x_ethtool_ops = {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009909 .get_settings = bnx2x_get_settings,
9910 .set_settings = bnx2x_set_settings,
9911 .get_drvinfo = bnx2x_get_drvinfo,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009912 .get_wol = bnx2x_get_wol,
9913 .set_wol = bnx2x_set_wol,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009914 .get_msglevel = bnx2x_get_msglevel,
9915 .set_msglevel = bnx2x_set_msglevel,
9916 .nway_reset = bnx2x_nway_reset,
9917 .get_link = ethtool_op_get_link,
9918 .get_eeprom_len = bnx2x_get_eeprom_len,
9919 .get_eeprom = bnx2x_get_eeprom,
9920 .set_eeprom = bnx2x_set_eeprom,
9921 .get_coalesce = bnx2x_get_coalesce,
9922 .set_coalesce = bnx2x_set_coalesce,
9923 .get_ringparam = bnx2x_get_ringparam,
9924 .set_ringparam = bnx2x_set_ringparam,
9925 .get_pauseparam = bnx2x_get_pauseparam,
9926 .set_pauseparam = bnx2x_set_pauseparam,
9927 .get_rx_csum = bnx2x_get_rx_csum,
9928 .set_rx_csum = bnx2x_set_rx_csum,
9929 .get_tx_csum = ethtool_op_get_tx_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -07009930 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009931 .set_flags = bnx2x_set_flags,
9932 .get_flags = ethtool_op_get_flags,
9933 .get_sg = ethtool_op_get_sg,
9934 .set_sg = ethtool_op_set_sg,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009935 .get_tso = ethtool_op_get_tso,
9936 .set_tso = bnx2x_set_tso,
9937 .self_test_count = bnx2x_self_test_count,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009938 .self_test = bnx2x_self_test,
9939 .get_strings = bnx2x_get_strings,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009940 .phys_id = bnx2x_phys_id,
9941 .get_stats_count = bnx2x_get_stats_count,
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009942 .get_ethtool_stats = bnx2x_get_ethtool_stats,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009943};
9944
9945/* end of ethtool_ops */
9946
9947/****************************************************************************
9948* General service functions
9949****************************************************************************/
9950
9951static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
9952{
9953 u16 pmcsr;
9954
9955 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
9956
9957 switch (state) {
9958 case PCI_D0:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009959 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009960 ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
9961 PCI_PM_CTRL_PME_STATUS));
9962
9963 if (pmcsr & PCI_PM_CTRL_STATE_MASK)
Eilon Greenstein33471622008-08-13 15:59:08 -07009964 /* delay required during transition out of D3hot */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009965 msleep(20);
9966 break;
9967
9968 case PCI_D3hot:
9969 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
9970 pmcsr |= 3;
9971
9972 if (bp->wol)
9973 pmcsr |= PCI_PM_CTRL_PME_ENABLE;
9974
9975 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
9976 pmcsr);
9977
9978 /* No more memory access after this point until
9979 * device is brought back to D0.
9980 */
9981 break;
9982
9983 default:
9984 return -EINVAL;
9985 }
9986 return 0;
9987}
9988
Eilon Greenstein237907c2009-01-14 06:42:44 +00009989static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
9990{
9991 u16 rx_cons_sb;
9992
9993 /* Tell compiler that status block fields can change */
9994 barrier();
9995 rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
9996 if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
9997 rx_cons_sb++;
9998 return (fp->rx_comp_cons != rx_cons_sb);
9999}
10000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010001/*
10002 * net_device service functions
10003 */
10004
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010005static int bnx2x_poll(struct napi_struct *napi, int budget)
10006{
10007 struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
10008 napi);
10009 struct bnx2x *bp = fp->bp;
10010 int work_done = 0;
10011
10012#ifdef BNX2X_STOP_ON_ERROR
10013 if (unlikely(bp->panic))
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010014 goto poll_panic;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010015#endif
10016
10017 prefetch(fp->tx_buf_ring[TX_BD(fp->tx_pkt_cons)].skb);
10018 prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
10019 prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
10020
10021 bnx2x_update_fpsb_idx(fp);
10022
Eilon Greenstein237907c2009-01-14 06:42:44 +000010023 if (bnx2x_has_tx_work(fp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010024 bnx2x_tx_int(fp, budget);
10025
Eilon Greenstein237907c2009-01-14 06:42:44 +000010026 if (bnx2x_has_rx_work(fp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010027 work_done = bnx2x_rx_int(fp, budget);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070010028 rmb(); /* BNX2X_HAS_WORK() reads the status block */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010029
10030 /* must not complete if we consumed full budget */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070010031 if ((work_done < budget) && !BNX2X_HAS_WORK(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010032
10033#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010034poll_panic:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010035#endif
Ben Hutchings288379f2009-01-19 16:43:59 -080010036 napi_complete(napi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010037
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010038 bnx2x_ack_sb(bp, FP_SB_ID(fp), USTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010039 le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010040 bnx2x_ack_sb(bp, FP_SB_ID(fp), CSTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010041 le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
10042 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010043 return work_done;
10044}
10045
Eilon Greenstein755735e2008-06-23 20:35:13 -070010046
10047/* we split the first BD into headers and data BDs
Eilon Greenstein33471622008-08-13 15:59:08 -070010048 * to ease the pain of our fellow microcode engineers
Eilon Greenstein755735e2008-06-23 20:35:13 -070010049 * we use one mapping for both BDs
10050 * So far this has only been observed to happen
10051 * in Other Operating Systems(TM)
10052 */
10053static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
10054 struct bnx2x_fastpath *fp,
10055 struct eth_tx_bd **tx_bd, u16 hlen,
10056 u16 bd_prod, int nbd)
10057{
10058 struct eth_tx_bd *h_tx_bd = *tx_bd;
10059 struct eth_tx_bd *d_tx_bd;
10060 dma_addr_t mapping;
10061 int old_len = le16_to_cpu(h_tx_bd->nbytes);
10062
10063 /* first fix first BD */
10064 h_tx_bd->nbd = cpu_to_le16(nbd);
10065 h_tx_bd->nbytes = cpu_to_le16(hlen);
10066
10067 DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
10068 "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
10069 h_tx_bd->addr_lo, h_tx_bd->nbd);
10070
10071 /* now get a new data BD
10072 * (after the pbd) and fill it */
10073 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10074 d_tx_bd = &fp->tx_desc_ring[bd_prod];
10075
10076 mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
10077 le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
10078
10079 d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10080 d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
10081 d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
10082 d_tx_bd->vlan = 0;
10083 /* this marks the BD as one that has no individual mapping
10084 * the FW ignores this flag in a BD not marked start
10085 */
10086 d_tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_SW_LSO;
10087 DP(NETIF_MSG_TX_QUEUED,
10088 "TSO split data size is %d (%x:%x)\n",
10089 d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
10090
10091 /* update tx_bd for marking the last BD flag */
10092 *tx_bd = d_tx_bd;
10093
10094 return bd_prod;
10095}
10096
10097static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
10098{
10099 if (fix > 0)
10100 csum = (u16) ~csum_fold(csum_sub(csum,
10101 csum_partial(t_header - fix, fix, 0)));
10102
10103 else if (fix < 0)
10104 csum = (u16) ~csum_fold(csum_add(csum,
10105 csum_partial(t_header, -fix, 0)));
10106
10107 return swab16(csum);
10108}
10109
10110static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
10111{
10112 u32 rc;
10113
10114 if (skb->ip_summed != CHECKSUM_PARTIAL)
10115 rc = XMIT_PLAIN;
10116
10117 else {
10118 if (skb->protocol == ntohs(ETH_P_IPV6)) {
10119 rc = XMIT_CSUM_V6;
10120 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
10121 rc |= XMIT_CSUM_TCP;
10122
10123 } else {
10124 rc = XMIT_CSUM_V4;
10125 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
10126 rc |= XMIT_CSUM_TCP;
10127 }
10128 }
10129
10130 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
10131 rc |= XMIT_GSO_V4;
10132
10133 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
10134 rc |= XMIT_GSO_V6;
10135
10136 return rc;
10137}
10138
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010139#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greenstein755735e2008-06-23 20:35:13 -070010140/* check if packet requires linearization (packet is too fragmented) */
10141static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
10142 u32 xmit_type)
10143{
10144 int to_copy = 0;
10145 int hlen = 0;
10146 int first_bd_sz = 0;
10147
10148 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
10149 if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
10150
10151 if (xmit_type & XMIT_GSO) {
10152 unsigned short lso_mss = skb_shinfo(skb)->gso_size;
10153 /* Check if LSO packet needs to be copied:
10154 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
10155 int wnd_size = MAX_FETCH_BD - 3;
Eilon Greenstein33471622008-08-13 15:59:08 -070010156 /* Number of windows to check */
Eilon Greenstein755735e2008-06-23 20:35:13 -070010157 int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
10158 int wnd_idx = 0;
10159 int frag_idx = 0;
10160 u32 wnd_sum = 0;
10161
10162 /* Headers length */
10163 hlen = (int)(skb_transport_header(skb) - skb->data) +
10164 tcp_hdrlen(skb);
10165
10166 /* Amount of data (w/o headers) on linear part of SKB*/
10167 first_bd_sz = skb_headlen(skb) - hlen;
10168
10169 wnd_sum = first_bd_sz;
10170
10171 /* Calculate the first sum - it's special */
10172 for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
10173 wnd_sum +=
10174 skb_shinfo(skb)->frags[frag_idx].size;
10175
10176 /* If there was data on linear skb data - check it */
10177 if (first_bd_sz > 0) {
10178 if (unlikely(wnd_sum < lso_mss)) {
10179 to_copy = 1;
10180 goto exit_lbl;
10181 }
10182
10183 wnd_sum -= first_bd_sz;
10184 }
10185
10186 /* Others are easier: run through the frag list and
10187 check all windows */
10188 for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
10189 wnd_sum +=
10190 skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
10191
10192 if (unlikely(wnd_sum < lso_mss)) {
10193 to_copy = 1;
10194 break;
10195 }
10196 wnd_sum -=
10197 skb_shinfo(skb)->frags[wnd_idx].size;
10198 }
10199
10200 } else {
10201 /* in non-LSO too fragmented packet should always
10202 be linearized */
10203 to_copy = 1;
10204 }
10205 }
10206
10207exit_lbl:
10208 if (unlikely(to_copy))
10209 DP(NETIF_MSG_TX_QUEUED,
10210 "Linearization IS REQUIRED for %s packet. "
10211 "num_frags %d hlen %d first_bd_sz %d\n",
10212 (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
10213 skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
10214
10215 return to_copy;
10216}
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010217#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070010218
10219/* called with netif_tx_lock
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010220 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
Eilon Greenstein755735e2008-06-23 20:35:13 -070010221 * netif_wake_queue()
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010222 */
10223static int bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
10224{
10225 struct bnx2x *bp = netdev_priv(dev);
10226 struct bnx2x_fastpath *fp;
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010227 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010228 struct sw_tx_bd *tx_buf;
10229 struct eth_tx_bd *tx_bd;
10230 struct eth_tx_parse_bd *pbd = NULL;
10231 u16 pkt_prod, bd_prod;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010232 int nbd, fp_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010233 dma_addr_t mapping;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010234 u32 xmit_type = bnx2x_xmit_type(bp, skb);
10235 int vlan_off = (bp->e1hov ? 4 : 0);
10236 int i;
10237 u8 hlen = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010238
10239#ifdef BNX2X_STOP_ON_ERROR
10240 if (unlikely(bp->panic))
10241 return NETDEV_TX_BUSY;
10242#endif
10243
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010244 fp_index = skb_get_queue_mapping(skb);
10245 txq = netdev_get_tx_queue(dev, fp_index);
10246
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010247 fp = &bp->fp[fp_index];
Eilon Greenstein755735e2008-06-23 20:35:13 -070010248
Yitchak Gertner231fd582008-08-25 15:27:06 -070010249 if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
Eilon Greensteinde832a52009-02-12 08:36:33 +000010250 fp->eth_q_stats.driver_xoff++,
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010251 netif_tx_stop_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010252 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
10253 return NETDEV_TX_BUSY;
10254 }
10255
Eilon Greenstein755735e2008-06-23 20:35:13 -070010256 DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)"
10257 " gso type %x xmit_type %x\n",
10258 skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
10259 ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
10260
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010261#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greenstein33471622008-08-13 15:59:08 -070010262 /* First, check if we need to linearize the skb
Eilon Greenstein755735e2008-06-23 20:35:13 -070010263 (due to FW restrictions) */
10264 if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
10265 /* Statistics of linearization */
10266 bp->lin_cnt++;
10267 if (skb_linearize(skb) != 0) {
10268 DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
10269 "silently dropping this SKB\n");
10270 dev_kfree_skb_any(skb);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070010271 return NETDEV_TX_OK;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010272 }
10273 }
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010274#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070010275
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010276 /*
Eilon Greenstein755735e2008-06-23 20:35:13 -070010277 Please read carefully. First we use one BD which we mark as start,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010278 then for TSO or xsum we have a parsing info BD,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010279 and only then we have the rest of the TSO BDs.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010280 (don't forget to mark the last one as last,
10281 and to unmap only AFTER you write to the BD ...)
Eilon Greenstein755735e2008-06-23 20:35:13 -070010282 And above all, all pdb sizes are in words - NOT DWORDS!
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010283 */
10284
10285 pkt_prod = fp->tx_pkt_prod++;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010286 bd_prod = TX_BD(fp->tx_bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010287
Eilon Greenstein755735e2008-06-23 20:35:13 -070010288 /* get a tx_buf and first BD */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010289 tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
10290 tx_bd = &fp->tx_desc_ring[bd_prod];
10291
10292 tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
10293 tx_bd->general_data = (UNICAST_ADDRESS <<
10294 ETH_TX_BD_ETH_ADDR_TYPE_SHIFT);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010295 /* header nbd */
10296 tx_bd->general_data |= (1 << ETH_TX_BD_HDR_NBDS_SHIFT);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010297
Eilon Greenstein755735e2008-06-23 20:35:13 -070010298 /* remember the first BD of the packet */
10299 tx_buf->first_bd = fp->tx_bd_prod;
10300 tx_buf->skb = skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010301
10302 DP(NETIF_MSG_TX_QUEUED,
10303 "sending pkt %u @%p next_idx %u bd %u @%p\n",
10304 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_bd);
10305
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010306#ifdef BCM_VLAN
10307 if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) &&
10308 (bp->flags & HW_VLAN_TX_FLAG)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010309 tx_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb));
10310 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010311 vlan_off += 4;
10312 } else
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010313#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010314 tx_bd->vlan = cpu_to_le16(pkt_prod);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010315
10316 if (xmit_type) {
Eilon Greenstein755735e2008-06-23 20:35:13 -070010317 /* turn on parsing and get a BD */
10318 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10319 pbd = (void *)&fp->tx_desc_ring[bd_prod];
10320
10321 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
10322 }
10323
10324 if (xmit_type & XMIT_CSUM) {
10325 hlen = (skb_network_header(skb) - skb->data + vlan_off) / 2;
10326
10327 /* for now NS flag is not used in Linux */
10328 pbd->global_data = (hlen |
10329 ((skb->protocol == ntohs(ETH_P_8021Q)) <<
10330 ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT));
10331
10332 pbd->ip_hlen = (skb_transport_header(skb) -
10333 skb_network_header(skb)) / 2;
10334
10335 hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2;
10336
10337 pbd->total_hlen = cpu_to_le16(hlen);
10338 hlen = hlen*2 - vlan_off;
10339
10340 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_TCP_CSUM;
10341
10342 if (xmit_type & XMIT_CSUM_V4)
10343 tx_bd->bd_flags.as_bitfield |=
10344 ETH_TX_BD_FLAGS_IP_CSUM;
10345 else
10346 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IPV6;
10347
10348 if (xmit_type & XMIT_CSUM_TCP) {
10349 pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
10350
10351 } else {
10352 s8 fix = SKB_CS_OFF(skb); /* signed! */
10353
10354 pbd->global_data |= ETH_TX_PARSE_BD_CS_ANY_FLG;
10355 pbd->cs_offset = fix / 2;
10356
10357 DP(NETIF_MSG_TX_QUEUED,
10358 "hlen %d offset %d fix %d csum before fix %x\n",
10359 le16_to_cpu(pbd->total_hlen), pbd->cs_offset, fix,
10360 SKB_CS(skb));
10361
10362 /* HW bug: fixup the CSUM */
10363 pbd->tcp_pseudo_csum =
10364 bnx2x_csum_fix(skb_transport_header(skb),
10365 SKB_CS(skb), fix);
10366
10367 DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
10368 pbd->tcp_pseudo_csum);
10369 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010370 }
10371
10372 mapping = pci_map_single(bp->pdev, skb->data,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010373 skb_headlen(skb), PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010374
10375 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10376 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
Eilon Greenstein6378c022008-08-13 15:59:25 -070010377 nbd = skb_shinfo(skb)->nr_frags + ((pbd == NULL) ? 1 : 2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010378 tx_bd->nbd = cpu_to_le16(nbd);
10379 tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
10380
10381 DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
Eilon Greenstein755735e2008-06-23 20:35:13 -070010382 " nbytes %d flags %x vlan %x\n",
10383 tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, le16_to_cpu(tx_bd->nbd),
10384 le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield,
10385 le16_to_cpu(tx_bd->vlan));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010386
Eilon Greenstein755735e2008-06-23 20:35:13 -070010387 if (xmit_type & XMIT_GSO) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010388
10389 DP(NETIF_MSG_TX_QUEUED,
10390 "TSO packet len %d hlen %d total len %d tso size %d\n",
10391 skb->len, hlen, skb_headlen(skb),
10392 skb_shinfo(skb)->gso_size);
10393
10394 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
10395
Eilon Greenstein755735e2008-06-23 20:35:13 -070010396 if (unlikely(skb_headlen(skb) > hlen))
10397 bd_prod = bnx2x_tx_split(bp, fp, &tx_bd, hlen,
10398 bd_prod, ++nbd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010399
10400 pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
10401 pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010402 pbd->tcp_flags = pbd_tcp_flags(skb);
10403
10404 if (xmit_type & XMIT_GSO_V4) {
10405 pbd->ip_id = swab16(ip_hdr(skb)->id);
10406 pbd->tcp_pseudo_csum =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010407 swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
10408 ip_hdr(skb)->daddr,
10409 0, IPPROTO_TCP, 0));
Eilon Greenstein755735e2008-06-23 20:35:13 -070010410
10411 } else
10412 pbd->tcp_pseudo_csum =
10413 swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
10414 &ipv6_hdr(skb)->daddr,
10415 0, IPPROTO_TCP, 0));
10416
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010417 pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN;
10418 }
10419
Eilon Greenstein755735e2008-06-23 20:35:13 -070010420 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
10421 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010422
Eilon Greenstein755735e2008-06-23 20:35:13 -070010423 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10424 tx_bd = &fp->tx_desc_ring[bd_prod];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010425
Eilon Greenstein755735e2008-06-23 20:35:13 -070010426 mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
10427 frag->size, PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010428
Eilon Greenstein755735e2008-06-23 20:35:13 -070010429 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10430 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
10431 tx_bd->nbytes = cpu_to_le16(frag->size);
10432 tx_bd->vlan = cpu_to_le16(pkt_prod);
10433 tx_bd->bd_flags.as_bitfield = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010434
Eilon Greenstein755735e2008-06-23 20:35:13 -070010435 DP(NETIF_MSG_TX_QUEUED,
10436 "frag %d bd @%p addr (%x:%x) nbytes %d flags %x\n",
10437 i, tx_bd, tx_bd->addr_hi, tx_bd->addr_lo,
10438 le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010439 }
10440
Eilon Greenstein755735e2008-06-23 20:35:13 -070010441 /* now at last mark the BD as the last BD */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010442 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_END_BD;
10443
10444 DP(NETIF_MSG_TX_QUEUED, "last bd @%p flags %x\n",
10445 tx_bd, tx_bd->bd_flags.as_bitfield);
10446
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010447 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10448
Eilon Greenstein755735e2008-06-23 20:35:13 -070010449 /* now send a tx doorbell, counting the next BD
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010450 * if the packet contains or ends with it
10451 */
10452 if (TX_BD_POFF(bd_prod) < nbd)
10453 nbd++;
10454
10455 if (pbd)
10456 DP(NETIF_MSG_TX_QUEUED,
10457 "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
10458 " tcp_flags %x xsum %x seq %u hlen %u\n",
10459 pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id,
10460 pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010461 pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010462
Eilon Greenstein755735e2008-06-23 20:35:13 -070010463 DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010464
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080010465 /*
10466 * Make sure that the BD data is updated before updating the producer
10467 * since FW might read the BD right after the producer is updated.
10468 * This is only applicable for weak-ordered memory model archs such
10469 * as IA-64. The following barrier is also mandatory since FW will
10470 * assumes packets must have BDs.
10471 */
10472 wmb();
10473
Eliezer Tamir96fc1782008-02-28 11:57:55 -080010474 fp->hw_tx_prods->bds_prod =
10475 cpu_to_le16(le16_to_cpu(fp->hw_tx_prods->bds_prod) + nbd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010476 mb(); /* FW restriction: must not reorder writing nbd and packets */
Eliezer Tamir96fc1782008-02-28 11:57:55 -080010477 fp->hw_tx_prods->packets_prod =
10478 cpu_to_le32(le32_to_cpu(fp->hw_tx_prods->packets_prod) + 1);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010479 DOORBELL(bp, FP_IDX(fp), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010480
10481 mmiowb();
10482
Eilon Greenstein755735e2008-06-23 20:35:13 -070010483 fp->tx_bd_prod += nbd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010484 dev->trans_start = jiffies;
10485
10486 if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080010487 /* We want bnx2x_tx_int to "see" the updated tx_bd_prod
10488 if we put Tx into XOFF state. */
10489 smp_mb();
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010490 netif_tx_stop_queue(txq);
Eilon Greensteinde832a52009-02-12 08:36:33 +000010491 fp->eth_q_stats.driver_xoff++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010492 if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010493 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010494 }
10495 fp->tx_pkt++;
10496
10497 return NETDEV_TX_OK;
10498}
10499
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010500/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010501static int bnx2x_open(struct net_device *dev)
10502{
10503 struct bnx2x *bp = netdev_priv(dev);
10504
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000010505 netif_carrier_off(dev);
10506
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010507 bnx2x_set_power_state(bp, PCI_D0);
10508
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010509 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010510}
10511
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010512/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010513static int bnx2x_close(struct net_device *dev)
10514{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010515 struct bnx2x *bp = netdev_priv(dev);
10516
10517 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010518 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
10519 if (atomic_read(&bp->pdev->enable_cnt) == 1)
10520 if (!CHIP_REV_IS_SLOW(bp))
10521 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010522
10523 return 0;
10524}
10525
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010526/* called with netif_tx_lock from set_multicast */
10527static void bnx2x_set_rx_mode(struct net_device *dev)
10528{
10529 struct bnx2x *bp = netdev_priv(dev);
10530 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
10531 int port = BP_PORT(bp);
10532
10533 if (bp->state != BNX2X_STATE_OPEN) {
10534 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
10535 return;
10536 }
10537
10538 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
10539
10540 if (dev->flags & IFF_PROMISC)
10541 rx_mode = BNX2X_RX_MODE_PROMISC;
10542
10543 else if ((dev->flags & IFF_ALLMULTI) ||
10544 ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp)))
10545 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10546
10547 else { /* some multicasts */
10548 if (CHIP_IS_E1(bp)) {
10549 int i, old, offset;
10550 struct dev_mc_list *mclist;
10551 struct mac_configuration_cmd *config =
10552 bnx2x_sp(bp, mcast_config);
10553
10554 for (i = 0, mclist = dev->mc_list;
10555 mclist && (i < dev->mc_count);
10556 i++, mclist = mclist->next) {
10557
10558 config->config_table[i].
10559 cam_entry.msb_mac_addr =
10560 swab16(*(u16 *)&mclist->dmi_addr[0]);
10561 config->config_table[i].
10562 cam_entry.middle_mac_addr =
10563 swab16(*(u16 *)&mclist->dmi_addr[2]);
10564 config->config_table[i].
10565 cam_entry.lsb_mac_addr =
10566 swab16(*(u16 *)&mclist->dmi_addr[4]);
10567 config->config_table[i].cam_entry.flags =
10568 cpu_to_le16(port);
10569 config->config_table[i].
10570 target_table_entry.flags = 0;
10571 config->config_table[i].
10572 target_table_entry.client_id = 0;
10573 config->config_table[i].
10574 target_table_entry.vlan_id = 0;
10575
10576 DP(NETIF_MSG_IFUP,
10577 "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
10578 config->config_table[i].
10579 cam_entry.msb_mac_addr,
10580 config->config_table[i].
10581 cam_entry.middle_mac_addr,
10582 config->config_table[i].
10583 cam_entry.lsb_mac_addr);
10584 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010585 old = config->hdr.length;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010586 if (old > i) {
10587 for (; i < old; i++) {
10588 if (CAM_IS_INVALID(config->
10589 config_table[i])) {
Eilon Greensteinaf246402009-01-14 06:43:59 +000010590 /* already invalidated */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010591 break;
10592 }
10593 /* invalidate */
10594 CAM_INVALIDATE(config->
10595 config_table[i]);
10596 }
10597 }
10598
10599 if (CHIP_REV_IS_SLOW(bp))
10600 offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
10601 else
10602 offset = BNX2X_MAX_MULTICAST*(1 + port);
10603
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010604 config->hdr.length = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010605 config->hdr.offset = offset;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010606 config->hdr.client_id = bp->fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010607 config->hdr.reserved1 = 0;
10608
10609 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
10610 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
10611 U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
10612 0);
10613 } else { /* E1H */
10614 /* Accept one or more multicasts */
10615 struct dev_mc_list *mclist;
10616 u32 mc_filter[MC_HASH_SIZE];
10617 u32 crc, bit, regidx;
10618 int i;
10619
10620 memset(mc_filter, 0, 4 * MC_HASH_SIZE);
10621
10622 for (i = 0, mclist = dev->mc_list;
10623 mclist && (i < dev->mc_count);
10624 i++, mclist = mclist->next) {
10625
Johannes Berg7c510e42008-10-27 17:47:26 -070010626 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
10627 mclist->dmi_addr);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010628
10629 crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
10630 bit = (crc >> 24) & 0xff;
10631 regidx = bit >> 5;
10632 bit &= 0x1f;
10633 mc_filter[regidx] |= (1 << bit);
10634 }
10635
10636 for (i = 0; i < MC_HASH_SIZE; i++)
10637 REG_WR(bp, MC_HASH_OFFSET(bp, i),
10638 mc_filter[i]);
10639 }
10640 }
10641
10642 bp->rx_mode = rx_mode;
10643 bnx2x_set_storm_rx_mode(bp);
10644}
10645
10646/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010647static int bnx2x_change_mac_addr(struct net_device *dev, void *p)
10648{
10649 struct sockaddr *addr = p;
10650 struct bnx2x *bp = netdev_priv(dev);
10651
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010652 if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010653 return -EINVAL;
10654
10655 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010656 if (netif_running(dev)) {
10657 if (CHIP_IS_E1(bp))
Yitchak Gertner3101c2b2008-08-13 15:52:28 -070010658 bnx2x_set_mac_addr_e1(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010659 else
Yitchak Gertner3101c2b2008-08-13 15:52:28 -070010660 bnx2x_set_mac_addr_e1h(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010661 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010662
10663 return 0;
10664}
10665
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010666/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010667static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10668{
10669 struct mii_ioctl_data *data = if_mii(ifr);
10670 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010671 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010672 int err;
10673
10674 switch (cmd) {
10675 case SIOCGMIIPHY:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010676 data->phy_id = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010677
Eliezer Tamirc14423f2008-02-28 11:49:42 -080010678 /* fallthrough */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010679
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010680 case SIOCGMIIREG: {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010681 u16 mii_regval;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010682
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010683 if (!netif_running(dev))
10684 return -EAGAIN;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010685
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010686 mutex_lock(&bp->port.phy_mutex);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010687 err = bnx2x_cl45_read(bp, port, 0, bp->port.phy_addr,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010688 DEFAULT_PHY_DEV_ADDR,
10689 (data->reg_num & 0x1f), &mii_regval);
10690 data->val_out = mii_regval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010691 mutex_unlock(&bp->port.phy_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010692 return err;
10693 }
10694
10695 case SIOCSMIIREG:
10696 if (!capable(CAP_NET_ADMIN))
10697 return -EPERM;
10698
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010699 if (!netif_running(dev))
10700 return -EAGAIN;
10701
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010702 mutex_lock(&bp->port.phy_mutex);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010703 err = bnx2x_cl45_write(bp, port, 0, bp->port.phy_addr,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010704 DEFAULT_PHY_DEV_ADDR,
10705 (data->reg_num & 0x1f), data->val_in);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010706 mutex_unlock(&bp->port.phy_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010707 return err;
10708
10709 default:
10710 /* do nothing */
10711 break;
10712 }
10713
10714 return -EOPNOTSUPP;
10715}
10716
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010717/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010718static int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
10719{
10720 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010721 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010722
10723 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
10724 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
10725 return -EINVAL;
10726
10727 /* This does not race with packet allocation
Eliezer Tamirc14423f2008-02-28 11:49:42 -080010728 * because the actual alloc size is
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010729 * only updated as part of load
10730 */
10731 dev->mtu = new_mtu;
10732
10733 if (netif_running(dev)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010734 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
10735 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010736 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010737
10738 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010739}
10740
10741static void bnx2x_tx_timeout(struct net_device *dev)
10742{
10743 struct bnx2x *bp = netdev_priv(dev);
10744
10745#ifdef BNX2X_STOP_ON_ERROR
10746 if (!bp->panic)
10747 bnx2x_panic();
10748#endif
10749 /* This allows the netif to be shutdown gracefully before resetting */
10750 schedule_work(&bp->reset_task);
10751}
10752
10753#ifdef BCM_VLAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010754/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010755static void bnx2x_vlan_rx_register(struct net_device *dev,
10756 struct vlan_group *vlgrp)
10757{
10758 struct bnx2x *bp = netdev_priv(dev);
10759
10760 bp->vlgrp = vlgrp;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010761
10762 /* Set flags according to the required capabilities */
10763 bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
10764
10765 if (dev->features & NETIF_F_HW_VLAN_TX)
10766 bp->flags |= HW_VLAN_TX_FLAG;
10767
10768 if (dev->features & NETIF_F_HW_VLAN_RX)
10769 bp->flags |= HW_VLAN_RX_FLAG;
10770
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010771 if (netif_running(dev))
Eliezer Tamir49d66772008-02-28 11:53:13 -080010772 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010773}
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010774
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010775#endif
10776
10777#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
10778static void poll_bnx2x(struct net_device *dev)
10779{
10780 struct bnx2x *bp = netdev_priv(dev);
10781
10782 disable_irq(bp->pdev->irq);
10783 bnx2x_interrupt(bp->pdev->irq, dev);
10784 enable_irq(bp->pdev->irq);
10785}
10786#endif
10787
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080010788static const struct net_device_ops bnx2x_netdev_ops = {
10789 .ndo_open = bnx2x_open,
10790 .ndo_stop = bnx2x_close,
10791 .ndo_start_xmit = bnx2x_start_xmit,
10792 .ndo_set_multicast_list = bnx2x_set_rx_mode,
10793 .ndo_set_mac_address = bnx2x_change_mac_addr,
10794 .ndo_validate_addr = eth_validate_addr,
10795 .ndo_do_ioctl = bnx2x_ioctl,
10796 .ndo_change_mtu = bnx2x_change_mtu,
10797 .ndo_tx_timeout = bnx2x_tx_timeout,
10798#ifdef BCM_VLAN
10799 .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
10800#endif
10801#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
10802 .ndo_poll_controller = poll_bnx2x,
10803#endif
10804};
10805
10806
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010807static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
10808 struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010809{
10810 struct bnx2x *bp;
10811 int rc;
10812
10813 SET_NETDEV_DEV(dev, &pdev->dev);
10814 bp = netdev_priv(dev);
10815
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010816 bp->dev = dev;
10817 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010818 bp->flags = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010819 bp->func = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010820
10821 rc = pci_enable_device(pdev);
10822 if (rc) {
10823 printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n");
10824 goto err_out;
10825 }
10826
10827 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
10828 printk(KERN_ERR PFX "Cannot find PCI device base address,"
10829 " aborting\n");
10830 rc = -ENODEV;
10831 goto err_out_disable;
10832 }
10833
10834 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
10835 printk(KERN_ERR PFX "Cannot find second PCI device"
10836 " base address, aborting\n");
10837 rc = -ENODEV;
10838 goto err_out_disable;
10839 }
10840
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010841 if (atomic_read(&pdev->enable_cnt) == 1) {
10842 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10843 if (rc) {
10844 printk(KERN_ERR PFX "Cannot obtain PCI resources,"
10845 " aborting\n");
10846 goto err_out_disable;
10847 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010848
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010849 pci_set_master(pdev);
10850 pci_save_state(pdev);
10851 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010852
10853 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10854 if (bp->pm_cap == 0) {
10855 printk(KERN_ERR PFX "Cannot find power management"
10856 " capability, aborting\n");
10857 rc = -EIO;
10858 goto err_out_release;
10859 }
10860
10861 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
10862 if (bp->pcie_cap == 0) {
10863 printk(KERN_ERR PFX "Cannot find PCI Express capability,"
10864 " aborting\n");
10865 rc = -EIO;
10866 goto err_out_release;
10867 }
10868
10869 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
10870 bp->flags |= USING_DAC_FLAG;
10871 if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
10872 printk(KERN_ERR PFX "pci_set_consistent_dma_mask"
10873 " failed, aborting\n");
10874 rc = -EIO;
10875 goto err_out_release;
10876 }
10877
10878 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
10879 printk(KERN_ERR PFX "System does not support DMA,"
10880 " aborting\n");
10881 rc = -EIO;
10882 goto err_out_release;
10883 }
10884
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010885 dev->mem_start = pci_resource_start(pdev, 0);
10886 dev->base_addr = dev->mem_start;
10887 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010888
10889 dev->irq = pdev->irq;
10890
Arjan van de Ven275f1652008-10-20 21:42:39 -070010891 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010892 if (!bp->regview) {
10893 printk(KERN_ERR PFX "Cannot map register space, aborting\n");
10894 rc = -ENOMEM;
10895 goto err_out_release;
10896 }
10897
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010898 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
10899 min_t(u64, BNX2X_DB_SIZE,
10900 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010901 if (!bp->doorbells) {
10902 printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n");
10903 rc = -ENOMEM;
10904 goto err_out_unmap;
10905 }
10906
10907 bnx2x_set_power_state(bp, PCI_D0);
10908
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010909 /* clean indirect addresses */
10910 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10911 PCICFG_VENDOR_ID_OFFSET);
10912 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
10913 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
10914 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
10915 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010916
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010917 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010918
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080010919 dev->netdev_ops = &bnx2x_netdev_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010920 dev->ethtool_ops = &bnx2x_ethtool_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010921 dev->features |= NETIF_F_SG;
10922 dev->features |= NETIF_F_HW_CSUM;
10923 if (bp->flags & USING_DAC_FLAG)
10924 dev->features |= NETIF_F_HIGHDMA;
10925#ifdef BCM_VLAN
10926 dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010927 bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010928#endif
10929 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010930 dev->features |= NETIF_F_TSO6;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010931
10932 return 0;
10933
10934err_out_unmap:
10935 if (bp->regview) {
10936 iounmap(bp->regview);
10937 bp->regview = NULL;
10938 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010939 if (bp->doorbells) {
10940 iounmap(bp->doorbells);
10941 bp->doorbells = NULL;
10942 }
10943
10944err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010945 if (atomic_read(&pdev->enable_cnt) == 1)
10946 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010947
10948err_out_disable:
10949 pci_disable_device(pdev);
10950 pci_set_drvdata(pdev, NULL);
10951
10952err_out:
10953 return rc;
10954}
10955
Eliezer Tamir25047952008-02-28 11:50:16 -080010956static int __devinit bnx2x_get_pcie_width(struct bnx2x *bp)
10957{
10958 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10959
10960 val = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
10961 return val;
10962}
10963
10964/* return value of 1=2.5GHz 2=5GHz */
10965static int __devinit bnx2x_get_pcie_speed(struct bnx2x *bp)
10966{
10967 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10968
10969 val = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
10970 return val;
10971}
10972
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010973static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10974 const struct pci_device_id *ent)
10975{
10976 static int version_printed;
10977 struct net_device *dev = NULL;
10978 struct bnx2x *bp;
Eliezer Tamir25047952008-02-28 11:50:16 -080010979 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010980
10981 if (version_printed++ == 0)
10982 printk(KERN_INFO "%s", version);
10983
10984 /* dev zeroed in init_etherdev */
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010985 dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010986 if (!dev) {
10987 printk(KERN_ERR PFX "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010988 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010989 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010990
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010991 bp = netdev_priv(dev);
10992 bp->msglevel = debug;
10993
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010994 rc = bnx2x_init_dev(pdev, dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010995 if (rc < 0) {
10996 free_netdev(dev);
10997 return rc;
10998 }
10999
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011000 pci_set_drvdata(pdev, dev);
11001
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011002 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000011003 if (rc)
11004 goto init_one_exit;
11005
11006 rc = register_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011007 if (rc) {
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000011008 dev_err(&pdev->dev, "Cannot register net device\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011009 goto init_one_exit;
11010 }
11011
Eliezer Tamir25047952008-02-28 11:50:16 -080011012 printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
Eilon Greenstein87942b42009-02-12 08:36:49 +000011013 " IRQ %d, ", dev->name, board_info[ent->driver_data].name,
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011014 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
Eliezer Tamir25047952008-02-28 11:50:16 -080011015 bnx2x_get_pcie_width(bp),
11016 (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz",
11017 dev->base_addr, bp->pdev->irq);
Johannes Berge1749612008-10-27 15:59:26 -070011018 printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011019 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011020
11021init_one_exit:
11022 if (bp->regview)
11023 iounmap(bp->regview);
11024
11025 if (bp->doorbells)
11026 iounmap(bp->doorbells);
11027
11028 free_netdev(dev);
11029
11030 if (atomic_read(&pdev->enable_cnt) == 1)
11031 pci_release_regions(pdev);
11032
11033 pci_disable_device(pdev);
11034 pci_set_drvdata(pdev, NULL);
11035
11036 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011037}
11038
11039static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11040{
11041 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011042 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011043
Eliezer Tamir228241e2008-02-28 11:56:57 -080011044 if (!dev) {
Eliezer Tamir228241e2008-02-28 11:56:57 -080011045 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11046 return;
11047 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011048 bp = netdev_priv(dev);
11049
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011050 unregister_netdev(dev);
11051
11052 if (bp->regview)
11053 iounmap(bp->regview);
11054
11055 if (bp->doorbells)
11056 iounmap(bp->doorbells);
11057
11058 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011059
11060 if (atomic_read(&pdev->enable_cnt) == 1)
11061 pci_release_regions(pdev);
11062
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011063 pci_disable_device(pdev);
11064 pci_set_drvdata(pdev, NULL);
11065}
11066
11067static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
11068{
11069 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011070 struct bnx2x *bp;
11071
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011072 if (!dev) {
11073 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11074 return -ENODEV;
11075 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011076 bp = netdev_priv(dev);
11077
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011078 rtnl_lock();
11079
11080 pci_save_state(pdev);
11081
11082 if (!netif_running(dev)) {
11083 rtnl_unlock();
11084 return 0;
11085 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011086
11087 netif_device_detach(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011088
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070011089 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011090
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011091 bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
Eliezer Tamir228241e2008-02-28 11:56:57 -080011092
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011093 rtnl_unlock();
11094
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011095 return 0;
11096}
11097
11098static int bnx2x_resume(struct pci_dev *pdev)
11099{
11100 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011101 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011102 int rc;
11103
Eliezer Tamir228241e2008-02-28 11:56:57 -080011104 if (!dev) {
11105 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11106 return -ENODEV;
11107 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011108 bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011109
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011110 rtnl_lock();
11111
Eliezer Tamir228241e2008-02-28 11:56:57 -080011112 pci_restore_state(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011113
11114 if (!netif_running(dev)) {
11115 rtnl_unlock();
11116 return 0;
11117 }
11118
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011119 bnx2x_set_power_state(bp, PCI_D0);
11120 netif_device_attach(dev);
11121
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070011122 rc = bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011123
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011124 rtnl_unlock();
11125
11126 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011127}
11128
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011129static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
11130{
11131 int i;
11132
11133 bp->state = BNX2X_STATE_ERROR;
11134
11135 bp->rx_mode = BNX2X_RX_MODE_NONE;
11136
11137 bnx2x_netif_stop(bp, 0);
11138
11139 del_timer_sync(&bp->timer);
11140 bp->stats_state = STATS_STATE_DISABLED;
11141 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
11142
11143 /* Release IRQs */
11144 bnx2x_free_irq(bp);
11145
11146 if (CHIP_IS_E1(bp)) {
11147 struct mac_configuration_cmd *config =
11148 bnx2x_sp(bp, mcast_config);
11149
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080011150 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011151 CAM_INVALIDATE(config->config_table[i]);
11152 }
11153
11154 /* Free SKBs, SGEs, TPA pool and driver internals */
11155 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011156 for_each_rx_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011157 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011158 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +000011159 netif_napi_del(&bnx2x_fp(bp, i, napi));
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011160 bnx2x_free_mem(bp);
11161
11162 bp->state = BNX2X_STATE_CLOSED;
11163
11164 netif_carrier_off(bp->dev);
11165
11166 return 0;
11167}
11168
11169static void bnx2x_eeh_recover(struct bnx2x *bp)
11170{
11171 u32 val;
11172
11173 mutex_init(&bp->port.phy_mutex);
11174
11175 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
11176 bp->link_params.shmem_base = bp->common.shmem_base;
11177 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
11178
11179 if (!bp->common.shmem_base ||
11180 (bp->common.shmem_base < 0xA0000) ||
11181 (bp->common.shmem_base >= 0xC0000)) {
11182 BNX2X_DEV_INFO("MCP not active\n");
11183 bp->flags |= NO_MCP_FLAG;
11184 return;
11185 }
11186
11187 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
11188 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11189 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11190 BNX2X_ERR("BAD MCP validity signature\n");
11191
11192 if (!BP_NOMCP(bp)) {
11193 bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
11194 & DRV_MSG_SEQ_NUMBER_MASK);
11195 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11196 }
11197}
11198
Wendy Xiong493adb12008-06-23 20:36:22 -070011199/**
11200 * bnx2x_io_error_detected - called when PCI error is detected
11201 * @pdev: Pointer to PCI device
11202 * @state: The current pci connection state
11203 *
11204 * This function is called after a PCI bus error affecting
11205 * this device has been detected.
11206 */
11207static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
11208 pci_channel_state_t state)
11209{
11210 struct net_device *dev = pci_get_drvdata(pdev);
11211 struct bnx2x *bp = netdev_priv(dev);
11212
11213 rtnl_lock();
11214
11215 netif_device_detach(dev);
11216
11217 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011218 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070011219
11220 pci_disable_device(pdev);
11221
11222 rtnl_unlock();
11223
11224 /* Request a slot reset */
11225 return PCI_ERS_RESULT_NEED_RESET;
11226}
11227
11228/**
11229 * bnx2x_io_slot_reset - called after the PCI bus has been reset
11230 * @pdev: Pointer to PCI device
11231 *
11232 * Restart the card from scratch, as if from a cold-boot.
11233 */
11234static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
11235{
11236 struct net_device *dev = pci_get_drvdata(pdev);
11237 struct bnx2x *bp = netdev_priv(dev);
11238
11239 rtnl_lock();
11240
11241 if (pci_enable_device(pdev)) {
11242 dev_err(&pdev->dev,
11243 "Cannot re-enable PCI device after reset\n");
11244 rtnl_unlock();
11245 return PCI_ERS_RESULT_DISCONNECT;
11246 }
11247
11248 pci_set_master(pdev);
11249 pci_restore_state(pdev);
11250
11251 if (netif_running(dev))
11252 bnx2x_set_power_state(bp, PCI_D0);
11253
11254 rtnl_unlock();
11255
11256 return PCI_ERS_RESULT_RECOVERED;
11257}
11258
11259/**
11260 * bnx2x_io_resume - called when traffic can start flowing again
11261 * @pdev: Pointer to PCI device
11262 *
11263 * This callback is called when the error recovery driver tells us that
11264 * its OK to resume normal operation.
11265 */
11266static void bnx2x_io_resume(struct pci_dev *pdev)
11267{
11268 struct net_device *dev = pci_get_drvdata(pdev);
11269 struct bnx2x *bp = netdev_priv(dev);
11270
11271 rtnl_lock();
11272
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011273 bnx2x_eeh_recover(bp);
11274
Wendy Xiong493adb12008-06-23 20:36:22 -070011275 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011276 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070011277
11278 netif_device_attach(dev);
11279
11280 rtnl_unlock();
11281}
11282
11283static struct pci_error_handlers bnx2x_err_handler = {
11284 .error_detected = bnx2x_io_error_detected,
11285 .slot_reset = bnx2x_io_slot_reset,
11286 .resume = bnx2x_io_resume,
11287};
11288
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011289static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070011290 .name = DRV_MODULE_NAME,
11291 .id_table = bnx2x_pci_tbl,
11292 .probe = bnx2x_init_one,
11293 .remove = __devexit_p(bnx2x_remove_one),
11294 .suspend = bnx2x_suspend,
11295 .resume = bnx2x_resume,
11296 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011297};
11298
11299static int __init bnx2x_init(void)
11300{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011301 bnx2x_wq = create_singlethread_workqueue("bnx2x");
11302 if (bnx2x_wq == NULL) {
11303 printk(KERN_ERR PFX "Cannot create workqueue\n");
11304 return -ENOMEM;
11305 }
11306
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011307 return pci_register_driver(&bnx2x_pci_driver);
11308}
11309
11310static void __exit bnx2x_cleanup(void)
11311{
11312 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011313
11314 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011315}
11316
11317module_init(bnx2x_init);
11318module_exit(bnx2x_cleanup);
11319