blob: 46e2492fc9d072f6d573a69e3bbb8a8810999792 [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
Eilon Greenstein359d8b12009-02-12 08:38:25 +000053
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020054#include "bnx2x.h"
55#include "bnx2x_init.h"
56
Eilon Greenstein2b144022009-02-12 08:38:35 +000057#define DRV_MODULE_VERSION "1.48.102"
58#define DRV_MODULE_RELDATE "2009/02/12"
Eilon Greenstein34f80b02008-06-23 20:33:01 -070059#define BNX2X_BC_VER 0x040200
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020060
Eilon Greenstein34f80b02008-06-23 20:33:01 -070061/* Time in jiffies before concluding the transmitter is hung */
62#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020063
Andrew Morton53a10562008-02-09 23:16:41 -080064static char version[] __devinitdata =
Eilon Greenstein34f80b02008-06-23 20:33:01 -070065 "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020066 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
67
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070068MODULE_AUTHOR("Eliezer Tamir");
Eilon Greensteine47d7e62009-01-14 06:44:28 +000069MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020070MODULE_LICENSE("GPL");
71MODULE_VERSION(DRV_MODULE_VERSION);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020072
Eilon Greenstein555f6c72009-02-12 08:36:11 +000073static int multi_mode = 1;
74module_param(multi_mode, int, 0);
Eilon Greenstein2059aba2009-03-02 07:59:48 +000075MODULE_PARM_DESC(multi_mode, " Use per-CPU queues");
Eilon Greenstein555f6c72009-02-12 08:36:11 +000076
Eilon Greenstein19680c42008-08-13 15:47:33 -070077static int disable_tpa;
Eilon Greenstein19680c42008-08-13 15:47:33 -070078module_param(disable_tpa, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +000079MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
Eilon Greenstein8badd272009-02-12 08:36:15 +000080
81static int int_mode;
82module_param(int_mode, int, 0);
83MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)");
84
Eilon Greenstein9898f862009-02-12 08:38:27 +000085static int poll;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020086module_param(poll, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +000087MODULE_PARM_DESC(poll, " Use polling (for debug)");
Eilon Greenstein8d5726c2009-02-12 08:37:19 +000088
89static int mrrs = -1;
90module_param(mrrs, int, 0);
91MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
92
Eilon Greenstein9898f862009-02-12 08:38:27 +000093static int debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020094module_param(debug, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +000095MODULE_PARM_DESC(debug, " Default debug msglevel");
96
97static int load_count[3]; /* 0-common, 1-port0, 2-port1 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020098
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080099static struct workqueue_struct *bnx2x_wq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200100
101enum bnx2x_board_type {
102 BCM57710 = 0,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700103 BCM57711 = 1,
104 BCM57711E = 2,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200105};
106
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700107/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800108static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200109 char *name;
110} board_info[] __devinitdata = {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700111 { "Broadcom NetXtreme II BCM57710 XGb" },
112 { "Broadcom NetXtreme II BCM57711 XGb" },
113 { "Broadcom NetXtreme II BCM57711E XGb" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200114};
115
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700116
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200117static const struct pci_device_id bnx2x_pci_tbl[] = {
118 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710,
119 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57710 },
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700120 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711,
121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711 },
122 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E,
123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711E },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200124 { 0 }
125};
126
127MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
128
129/****************************************************************************
130* General service functions
131****************************************************************************/
132
133/* used only at init
134 * locking is done by mcp
135 */
136static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
137{
138 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
139 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
140 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
141 PCICFG_VENDOR_ID_OFFSET);
142}
143
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200144static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
145{
146 u32 val;
147
148 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
149 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
150 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
151 PCICFG_VENDOR_ID_OFFSET);
152
153 return val;
154}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200155
156static const u32 dmae_reg_go_c[] = {
157 DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
158 DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
159 DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
160 DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
161};
162
163/* copy command into DMAE command memory and set DMAE command go */
164static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
165 int idx)
166{
167 u32 cmd_offset;
168 int i;
169
170 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
171 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
172 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
173
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700174 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
175 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200176 }
177 REG_WR(bp, dmae_reg_go_c[idx], 1);
178}
179
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700180void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
181 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200182{
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700183 struct dmae_command *dmae = &bp->init_dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200184 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700185 int cnt = 200;
186
187 if (!bp->dmae_ready) {
188 u32 *data = bnx2x_sp(bp, wb_data[0]);
189
190 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
191 " using indirect\n", dst_addr, len32);
192 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
193 return;
194 }
195
196 mutex_lock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200197
198 memset(dmae, 0, sizeof(struct dmae_command));
199
200 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
201 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
202 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
203#ifdef __BIG_ENDIAN
204 DMAE_CMD_ENDIANITY_B_DW_SWAP |
205#else
206 DMAE_CMD_ENDIANITY_DW_SWAP |
207#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700208 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
209 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200210 dmae->src_addr_lo = U64_LO(dma_addr);
211 dmae->src_addr_hi = U64_HI(dma_addr);
212 dmae->dst_addr_lo = dst_addr >> 2;
213 dmae->dst_addr_hi = 0;
214 dmae->len = len32;
215 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
216 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700217 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200218
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700219 DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200220 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
221 "dst_addr [%x:%08x (%08x)]\n"
222 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
223 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
224 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr,
225 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700226 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200227 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
228 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200229
230 *wb_comp = 0;
231
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700232 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200233
234 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700235
236 while (*wb_comp != DMAE_COMP_VAL) {
237 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
238
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700239 if (!cnt) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200240 BNX2X_ERR("dmae timeout!\n");
241 break;
242 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700243 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700244 /* adjust delay for emulation/FPGA */
245 if (CHIP_REV_IS_SLOW(bp))
246 msleep(100);
247 else
248 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200249 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700250
251 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200252}
253
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700254void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200255{
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700256 struct dmae_command *dmae = &bp->init_dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200257 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700258 int cnt = 200;
259
260 if (!bp->dmae_ready) {
261 u32 *data = bnx2x_sp(bp, wb_data[0]);
262 int i;
263
264 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
265 " using indirect\n", src_addr, len32);
266 for (i = 0; i < len32; i++)
267 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
268 return;
269 }
270
271 mutex_lock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200272
273 memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
274 memset(dmae, 0, sizeof(struct dmae_command));
275
276 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
277 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
278 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
279#ifdef __BIG_ENDIAN
280 DMAE_CMD_ENDIANITY_B_DW_SWAP |
281#else
282 DMAE_CMD_ENDIANITY_DW_SWAP |
283#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700284 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
285 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200286 dmae->src_addr_lo = src_addr >> 2;
287 dmae->src_addr_hi = 0;
288 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
289 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
290 dmae->len = len32;
291 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
292 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700293 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200294
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700295 DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200296 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
297 "dst_addr [%x:%08x (%08x)]\n"
298 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
299 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
300 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr,
301 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200302
303 *wb_comp = 0;
304
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700305 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200306
307 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700308
309 while (*wb_comp != DMAE_COMP_VAL) {
310
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700311 if (!cnt) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200312 BNX2X_ERR("dmae timeout!\n");
313 break;
314 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700315 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700316 /* adjust delay for emulation/FPGA */
317 if (CHIP_REV_IS_SLOW(bp))
318 msleep(100);
319 else
320 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200321 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700322 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200323 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
324 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700325
326 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200327}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200328
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700329/* used only for slowpath so not inlined */
330static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
331{
332 u32 wb_write[2];
333
334 wb_write[0] = val_hi;
335 wb_write[1] = val_lo;
336 REG_WR_DMAE(bp, reg, wb_write, 2);
337}
338
339#ifdef USE_WB_RD
340static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
341{
342 u32 wb_data[2];
343
344 REG_RD_DMAE(bp, reg, wb_data, 2);
345
346 return HILO_U64(wb_data[0], wb_data[1]);
347}
348#endif
349
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200350static int bnx2x_mc_assert(struct bnx2x *bp)
351{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200352 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700353 int i, rc = 0;
354 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200355
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700356 /* XSTORM */
357 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
358 XSTORM_ASSERT_LIST_INDEX_OFFSET);
359 if (last_idx)
360 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200361
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700362 /* print the asserts */
363 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200364
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700365 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
366 XSTORM_ASSERT_LIST_OFFSET(i));
367 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
368 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
369 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
370 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
371 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
372 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200373
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700374 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
375 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
376 " 0x%08x 0x%08x 0x%08x\n",
377 i, row3, row2, row1, row0);
378 rc++;
379 } else {
380 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200381 }
382 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700383
384 /* TSTORM */
385 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
386 TSTORM_ASSERT_LIST_INDEX_OFFSET);
387 if (last_idx)
388 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
389
390 /* print the asserts */
391 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
392
393 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
394 TSTORM_ASSERT_LIST_OFFSET(i));
395 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
396 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
397 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
398 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
399 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
400 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
401
402 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
403 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
404 " 0x%08x 0x%08x 0x%08x\n",
405 i, row3, row2, row1, row0);
406 rc++;
407 } else {
408 break;
409 }
410 }
411
412 /* CSTORM */
413 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
414 CSTORM_ASSERT_LIST_INDEX_OFFSET);
415 if (last_idx)
416 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
417
418 /* print the asserts */
419 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
420
421 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
422 CSTORM_ASSERT_LIST_OFFSET(i));
423 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
424 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
425 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
426 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
427 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
428 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
429
430 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
431 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
432 " 0x%08x 0x%08x 0x%08x\n",
433 i, row3, row2, row1, row0);
434 rc++;
435 } else {
436 break;
437 }
438 }
439
440 /* USTORM */
441 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
442 USTORM_ASSERT_LIST_INDEX_OFFSET);
443 if (last_idx)
444 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
445
446 /* print the asserts */
447 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
448
449 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
450 USTORM_ASSERT_LIST_OFFSET(i));
451 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
452 USTORM_ASSERT_LIST_OFFSET(i) + 4);
453 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
454 USTORM_ASSERT_LIST_OFFSET(i) + 8);
455 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
456 USTORM_ASSERT_LIST_OFFSET(i) + 12);
457
458 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
459 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
460 " 0x%08x 0x%08x 0x%08x\n",
461 i, row3, row2, row1, row0);
462 rc++;
463 } else {
464 break;
465 }
466 }
467
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200468 return rc;
469}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800470
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200471static void bnx2x_fw_dump(struct bnx2x *bp)
472{
473 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000474 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200475 int word;
476
477 mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800478 mark = ((mark + 0x3) & ~0x3);
479 printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n" KERN_ERR, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200480
481 for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) {
482 for (word = 0; word < 8; word++)
483 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
484 offset + 4*word));
485 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800486 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200487 }
488 for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) {
489 for (word = 0; word < 8; word++)
490 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
491 offset + 4*word));
492 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800493 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200494 }
495 printk("\n" KERN_ERR PFX "end of fw dump\n");
496}
497
498static void bnx2x_panic_dump(struct bnx2x *bp)
499{
500 int i;
501 u16 j, start, end;
502
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700503 bp->stats_state = STATS_STATE_DISABLED;
504 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
505
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200506 BNX2X_ERR("begin crash dump -----------------\n");
507
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000508 /* Indices */
509 /* Common */
510 BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)"
511 " def_t_idx(%u) def_att_idx(%u) attn_state(%u)"
512 " spq_prod_idx(%u)\n",
513 bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
514 bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
515
516 /* Rx */
517 for_each_rx_queue(bp, i) {
518 struct bnx2x_fastpath *fp = &bp->fp[i];
519
520 BNX2X_ERR("queue[%d]: rx_bd_prod(%x) rx_bd_cons(%x)"
521 " *rx_bd_cons_sb(%x) rx_comp_prod(%x)"
522 " rx_comp_cons(%x) *rx_cons_sb(%x)\n",
523 i, fp->rx_bd_prod, fp->rx_bd_cons,
524 le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
525 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
526 BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)"
527 " fp_u_idx(%x) *sb_u_idx(%x)\n",
528 fp->rx_sge_prod, fp->last_max_sge,
529 le16_to_cpu(fp->fp_u_idx),
530 fp->status_blk->u_status_block.status_block_index);
531 }
532
533 /* Tx */
534 for_each_tx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200535 struct bnx2x_fastpath *fp = &bp->fp[i];
536 struct eth_tx_db_data *hw_prods = fp->hw_tx_prods;
537
538 BNX2X_ERR("queue[%d]: tx_pkt_prod(%x) tx_pkt_cons(%x)"
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700539 " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200540 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700541 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000542 BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)"
543 " bd data(%x,%x)\n", le16_to_cpu(fp->fp_c_idx),
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700544 fp->status_blk->c_status_block.status_block_index,
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700545 hw_prods->packets_prod, hw_prods->bds_prod);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000546 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200547
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000548 /* Rings */
549 /* Rx */
550 for_each_rx_queue(bp, i) {
551 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200552
553 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
554 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000555 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200556 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
557 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
558
559 BNX2X_ERR("rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700560 j, rx_bd[1], rx_bd[0], sw_bd->skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200561 }
562
Eilon Greenstein3196a882008-08-13 15:58:49 -0700563 start = RX_SGE(fp->rx_sge_prod);
564 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000565 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700566 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
567 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
568
569 BNX2X_ERR("rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
570 j, rx_sge[1], rx_sge[0], sw_page->page);
571 }
572
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200573 start = RCQ_BD(fp->rx_comp_cons - 10);
574 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000575 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200576 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
577
578 BNX2X_ERR("cqe[%x]=[%x:%x:%x:%x]\n",
579 j, cqe[0], cqe[1], cqe[2], cqe[3]);
580 }
581 }
582
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000583 /* Tx */
584 for_each_tx_queue(bp, i) {
585 struct bnx2x_fastpath *fp = &bp->fp[i];
586
587 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
588 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
589 for (j = start; j != end; j = TX_BD(j + 1)) {
590 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
591
592 BNX2X_ERR("packet[%x]=[%p,%x]\n", j,
593 sw_bd->skb, sw_bd->first_bd);
594 }
595
596 start = TX_BD(fp->tx_bd_cons - 10);
597 end = TX_BD(fp->tx_bd_cons + 254);
598 for (j = start; j != end; j = TX_BD(j + 1)) {
599 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
600
601 BNX2X_ERR("tx_bd[%x]=[%x:%x:%x:%x]\n",
602 j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
603 }
604 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200605
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700606 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200607 bnx2x_mc_assert(bp);
608 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200609}
610
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800611static void bnx2x_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200612{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700613 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200614 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
615 u32 val = REG_RD(bp, addr);
616 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000617 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200618
619 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000620 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
621 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200622 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
623 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eilon Greenstein8badd272009-02-12 08:36:15 +0000624 } else if (msi) {
625 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
626 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
627 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
628 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200629 } else {
630 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800631 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200632 HC_CONFIG_0_REG_INT_LINE_EN_0 |
633 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800634
Eilon Greenstein8badd272009-02-12 08:36:15 +0000635 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
636 val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800637
638 REG_WR(bp, addr, val);
639
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200640 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
641 }
642
Eilon Greenstein8badd272009-02-12 08:36:15 +0000643 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
644 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200645
646 REG_WR(bp, addr, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700647
648 if (CHIP_IS_E1H(bp)) {
649 /* init leading/trailing edge */
650 if (IS_E1HMF(bp)) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000651 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700652 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +0000653 /* enable nig and gpio3 attention */
654 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700655 } else
656 val = 0xffff;
657
658 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
659 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
660 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200661}
662
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800663static void bnx2x_int_disable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200664{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700665 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200666 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
667 u32 val = REG_RD(bp, addr);
668
669 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
670 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
671 HC_CONFIG_0_REG_INT_LINE_EN_0 |
672 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
673
674 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
675 val, port, addr);
676
Eilon Greenstein8badd272009-02-12 08:36:15 +0000677 /* flush all outstanding writes */
678 mmiowb();
679
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200680 REG_WR(bp, addr, val);
681 if (REG_RD(bp, addr) != val)
682 BNX2X_ERR("BUG! proper val not read from IGU!\n");
Eilon Greenstein356e2382009-02-12 08:38:32 +0000683
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200684}
685
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700686static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200687{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200688 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000689 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200690
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700691 /* disable interrupt handling */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200692 atomic_inc(&bp->intr_sem);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700693 if (disable_hw)
694 /* prevent the HW from sending interrupts */
695 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200696
697 /* make sure all ISRs are done */
698 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000699 synchronize_irq(bp->msix_table[0].vector);
700 offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200701 for_each_queue(bp, i)
Eilon Greenstein8badd272009-02-12 08:36:15 +0000702 synchronize_irq(bp->msix_table[i + offset].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200703 } else
704 synchronize_irq(bp->pdev->irq);
705
706 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800707 cancel_delayed_work(&bp->sp_task);
708 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200709}
710
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700711/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200712
713/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700714 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200715 */
716
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700717static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200718 u8 storm, u16 index, u8 op, u8 update)
719{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700720 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
721 COMMAND_REG_INT_ACK);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200722 struct igu_ack_register igu_ack;
723
724 igu_ack.status_block_index = index;
725 igu_ack.sb_id_and_flags =
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700726 ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200727 (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
728 (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
729 (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
730
Eilon Greenstein5c862842008-08-13 15:51:48 -0700731 DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
732 (*(u32 *)&igu_ack), hc_addr);
733 REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200734}
735
736static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
737{
738 struct host_status_block *fpsb = fp->status_blk;
739 u16 rc = 0;
740
741 barrier(); /* status block is written to by the chip */
742 if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
743 fp->fp_c_idx = fpsb->c_status_block.status_block_index;
744 rc |= 1;
745 }
746 if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
747 fp->fp_u_idx = fpsb->u_status_block.status_block_index;
748 rc |= 2;
749 }
750 return rc;
751}
752
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200753static u16 bnx2x_ack_int(struct bnx2x *bp)
754{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700755 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
756 COMMAND_REG_SIMD_MASK);
757 u32 result = REG_RD(bp, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200758
Eilon Greenstein5c862842008-08-13 15:51:48 -0700759 DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
760 result, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200761
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200762 return result;
763}
764
765
766/*
767 * fast path service functions
768 */
769
Eilon Greenstein237907c2009-01-14 06:42:44 +0000770static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
771{
772 u16 tx_cons_sb;
773
774 /* Tell compiler that status block fields can change */
775 barrier();
776 tx_cons_sb = le16_to_cpu(*fp->tx_cons_sb);
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -0800777 return (fp->tx_pkt_cons != tx_cons_sb);
778}
779
780static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
781{
782 /* Tell compiler that consumer and producer can change */
783 barrier();
784 return (fp->tx_pkt_prod != fp->tx_pkt_cons);
Eilon Greenstein237907c2009-01-14 06:42:44 +0000785}
786
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200787/* free skb in the packet ring at pos idx
788 * return idx of last bd freed
789 */
790static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
791 u16 idx)
792{
793 struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
794 struct eth_tx_bd *tx_bd;
795 struct sk_buff *skb = tx_buf->skb;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700796 u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200797 int nbd;
798
799 DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
800 idx, tx_buf, skb);
801
802 /* unmap first bd */
803 DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
804 tx_bd = &fp->tx_desc_ring[bd_idx];
805 pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_bd),
806 BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
807
808 nbd = le16_to_cpu(tx_bd->nbd) - 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700809 new_cons = nbd + tx_buf->first_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200810#ifdef BNX2X_STOP_ON_ERROR
811 if (nbd > (MAX_SKB_FRAGS + 2)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700812 BNX2X_ERR("BAD nbd!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200813 bnx2x_panic();
814 }
815#endif
816
817 /* Skip a parse bd and the TSO split header bd
818 since they have no mapping */
819 if (nbd)
820 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
821
822 if (tx_bd->bd_flags.as_bitfield & (ETH_TX_BD_FLAGS_IP_CSUM |
823 ETH_TX_BD_FLAGS_TCP_CSUM |
824 ETH_TX_BD_FLAGS_SW_LSO)) {
825 if (--nbd)
826 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
827 tx_bd = &fp->tx_desc_ring[bd_idx];
828 /* is this a TSO split header bd? */
829 if (tx_bd->bd_flags.as_bitfield & ETH_TX_BD_FLAGS_SW_LSO) {
830 if (--nbd)
831 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
832 }
833 }
834
835 /* now free frags */
836 while (nbd > 0) {
837
838 DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
839 tx_bd = &fp->tx_desc_ring[bd_idx];
840 pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_bd),
841 BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
842 if (--nbd)
843 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
844 }
845
846 /* release skb */
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700847 WARN_ON(!skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200848 dev_kfree_skb(skb);
849 tx_buf->first_bd = 0;
850 tx_buf->skb = NULL;
851
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700852 return new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200853}
854
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700855static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200856{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700857 s16 used;
858 u16 prod;
859 u16 cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200860
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700861 barrier(); /* Tell compiler that prod and cons can change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200862 prod = fp->tx_bd_prod;
863 cons = fp->tx_bd_cons;
864
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700865 /* NUM_TX_RINGS = number of "next-page" entries
866 It will be used as a threshold */
867 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200868
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700869#ifdef BNX2X_STOP_ON_ERROR
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700870 WARN_ON(used < 0);
871 WARN_ON(used > fp->bp->tx_ring_size);
872 WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700873#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200874
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700875 return (s16)(fp->bp->tx_ring_size) - used;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200876}
877
Eilon Greenstein7961f792009-03-02 07:59:31 +0000878static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200879{
880 struct bnx2x *bp = fp->bp;
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000881 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200882 u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
883 int done = 0;
884
885#ifdef BNX2X_STOP_ON_ERROR
886 if (unlikely(bp->panic))
887 return;
888#endif
889
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000890 txq = netdev_get_tx_queue(bp->dev, fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200891 hw_cons = le16_to_cpu(*fp->tx_cons_sb);
892 sw_cons = fp->tx_pkt_cons;
893
894 while (sw_cons != hw_cons) {
895 u16 pkt_cons;
896
897 pkt_cons = TX_BD(sw_cons);
898
899 /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
900
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700901 DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200902 hw_cons, sw_cons, pkt_cons);
903
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700904/* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200905 rmb();
906 prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
907 }
908*/
909 bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
910 sw_cons++;
911 done++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200912 }
913
914 fp->tx_pkt_cons = sw_cons;
915 fp->tx_bd_cons = bd_cons;
916
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200917 /* TBD need a thresh? */
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000918 if (unlikely(netif_tx_queue_stopped(txq))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200919
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000920 __netif_tx_lock(txq, smp_processor_id());
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200921
Eilon Greenstein60447352009-03-02 07:59:24 +0000922 /* Need to make the tx_bd_cons update visible to start_xmit()
923 * before checking for netif_tx_queue_stopped(). Without the
924 * memory barrier, there is a small possibility that
925 * start_xmit() will miss it and cause the queue to be stopped
926 * forever.
927 */
928 smp_mb();
929
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000930 if ((netif_tx_queue_stopped(txq)) &&
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -0700931 (bp->state == BNX2X_STATE_OPEN) &&
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200932 (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000933 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200934
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000935 __netif_tx_unlock(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200936 }
937}
938
Eilon Greenstein3196a882008-08-13 15:58:49 -0700939
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200940static void bnx2x_sp_event(struct bnx2x_fastpath *fp,
941 union eth_rx_cqe *rr_cqe)
942{
943 struct bnx2x *bp = fp->bp;
944 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
945 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
946
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700947 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200948 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +0000949 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700950 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200951
952 bp->spq_left++;
953
Eilon Greenstein0626b892009-02-12 08:38:14 +0000954 if (fp->index) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200955 switch (command | fp->state) {
956 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
957 BNX2X_FP_STATE_OPENING):
958 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
959 cid);
960 fp->state = BNX2X_FP_STATE_OPEN;
961 break;
962
963 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
964 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
965 cid);
966 fp->state = BNX2X_FP_STATE_HALTED;
967 break;
968
969 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700970 BNX2X_ERR("unexpected MC reply (%d) "
971 "fp->state is %x\n", command, fp->state);
972 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200973 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700974 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200975 return;
976 }
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800977
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200978 switch (command | bp->state) {
979 case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
980 DP(NETIF_MSG_IFUP, "got setup ramrod\n");
981 bp->state = BNX2X_STATE_OPEN;
982 break;
983
984 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
985 DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
986 bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
987 fp->state = BNX2X_FP_STATE_HALTED;
988 break;
989
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200990 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700991 DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800992 bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200993 break;
994
Eilon Greenstein3196a882008-08-13 15:58:49 -0700995
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200996 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700997 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200998 DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700999 bp->set_mac_pending = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001000 break;
1001
Eliezer Tamir49d66772008-02-28 11:53:13 -08001002 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001003 DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
Eliezer Tamir49d66772008-02-28 11:53:13 -08001004 break;
1005
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001006 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001007 BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001008 command, bp->state);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001009 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001010 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001011 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001012}
1013
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001014static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
1015 struct bnx2x_fastpath *fp, u16 index)
1016{
1017 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1018 struct page *page = sw_buf->page;
1019 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1020
1021 /* Skip "next page" elements */
1022 if (!page)
1023 return;
1024
1025 pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001026 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001027 __free_pages(page, PAGES_PER_SGE_SHIFT);
1028
1029 sw_buf->page = NULL;
1030 sge->addr_hi = 0;
1031 sge->addr_lo = 0;
1032}
1033
1034static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
1035 struct bnx2x_fastpath *fp, int last)
1036{
1037 int i;
1038
1039 for (i = 0; i < last; i++)
1040 bnx2x_free_rx_sge(bp, fp, i);
1041}
1042
1043static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
1044 struct bnx2x_fastpath *fp, u16 index)
1045{
1046 struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
1047 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1048 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1049 dma_addr_t mapping;
1050
1051 if (unlikely(page == NULL))
1052 return -ENOMEM;
1053
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001054 mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001055 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001056 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001057 __free_pages(page, PAGES_PER_SGE_SHIFT);
1058 return -ENOMEM;
1059 }
1060
1061 sw_buf->page = page;
1062 pci_unmap_addr_set(sw_buf, mapping, mapping);
1063
1064 sge->addr_hi = cpu_to_le32(U64_HI(mapping));
1065 sge->addr_lo = cpu_to_le32(U64_LO(mapping));
1066
1067 return 0;
1068}
1069
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001070static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
1071 struct bnx2x_fastpath *fp, u16 index)
1072{
1073 struct sk_buff *skb;
1074 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
1075 struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
1076 dma_addr_t mapping;
1077
1078 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1079 if (unlikely(skb == NULL))
1080 return -ENOMEM;
1081
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001082 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001083 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001084 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001085 dev_kfree_skb(skb);
1086 return -ENOMEM;
1087 }
1088
1089 rx_buf->skb = skb;
1090 pci_unmap_addr_set(rx_buf, mapping, mapping);
1091
1092 rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1093 rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1094
1095 return 0;
1096}
1097
1098/* note that we are not allocating a new skb,
1099 * we are just moving one from cons to prod
1100 * we are not creating a new mapping,
1101 * so there is no need to check for dma_mapping_error().
1102 */
1103static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
1104 struct sk_buff *skb, u16 cons, u16 prod)
1105{
1106 struct bnx2x *bp = fp->bp;
1107 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1108 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1109 struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
1110 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1111
1112 pci_dma_sync_single_for_device(bp->pdev,
1113 pci_unmap_addr(cons_rx_buf, mapping),
Eilon Greenstein87942b42009-02-12 08:36:49 +00001114 RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001115
1116 prod_rx_buf->skb = cons_rx_buf->skb;
1117 pci_unmap_addr_set(prod_rx_buf, mapping,
1118 pci_unmap_addr(cons_rx_buf, mapping));
1119 *prod_bd = *cons_bd;
1120}
1121
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001122static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
1123 u16 idx)
1124{
1125 u16 last_max = fp->last_max_sge;
1126
1127 if (SUB_S16(idx, last_max) > 0)
1128 fp->last_max_sge = idx;
1129}
1130
1131static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
1132{
1133 int i, j;
1134
1135 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
1136 int idx = RX_SGE_CNT * i - 1;
1137
1138 for (j = 0; j < 2; j++) {
1139 SGE_MASK_CLEAR_BIT(fp, idx);
1140 idx--;
1141 }
1142 }
1143}
1144
1145static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
1146 struct eth_fast_path_rx_cqe *fp_cqe)
1147{
1148 struct bnx2x *bp = fp->bp;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001149 u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001150 le16_to_cpu(fp_cqe->len_on_bd)) >>
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001151 SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001152 u16 last_max, last_elem, first_elem;
1153 u16 delta = 0;
1154 u16 i;
1155
1156 if (!sge_len)
1157 return;
1158
1159 /* First mark all used pages */
1160 for (i = 0; i < sge_len; i++)
1161 SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i])));
1162
1163 DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
1164 sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1165
1166 /* Here we assume that the last SGE index is the biggest */
1167 prefetch((void *)(fp->sge_mask));
1168 bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1169
1170 last_max = RX_SGE(fp->last_max_sge);
1171 last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
1172 first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
1173
1174 /* If ring is not full */
1175 if (last_elem + 1 != first_elem)
1176 last_elem++;
1177
1178 /* Now update the prod */
1179 for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
1180 if (likely(fp->sge_mask[i]))
1181 break;
1182
1183 fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
1184 delta += RX_SGE_MASK_ELEM_SZ;
1185 }
1186
1187 if (delta > 0) {
1188 fp->rx_sge_prod += delta;
1189 /* clear page-end entries */
1190 bnx2x_clear_sge_mask_next_elems(fp);
1191 }
1192
1193 DP(NETIF_MSG_RX_STATUS,
1194 "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
1195 fp->last_max_sge, fp->rx_sge_prod);
1196}
1197
1198static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
1199{
1200 /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
1201 memset(fp->sge_mask, 0xff,
1202 (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
1203
Eilon Greenstein33471622008-08-13 15:59:08 -07001204 /* Clear the two last indices in the page to 1:
1205 these are the indices that correspond to the "next" element,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001206 hence will never be indicated and should be removed from
1207 the calculations. */
1208 bnx2x_clear_sge_mask_next_elems(fp);
1209}
1210
1211static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
1212 struct sk_buff *skb, u16 cons, u16 prod)
1213{
1214 struct bnx2x *bp = fp->bp;
1215 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1216 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1217 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1218 dma_addr_t mapping;
1219
1220 /* move empty skb from pool to prod and map it */
1221 prod_rx_buf->skb = fp->tpa_pool[queue].skb;
1222 mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001223 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001224 pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
1225
1226 /* move partial skb from cons to pool (don't unmap yet) */
1227 fp->tpa_pool[queue] = *cons_rx_buf;
1228
1229 /* mark bin state as start - print error if current state != stop */
1230 if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
1231 BNX2X_ERR("start of bin not in stop [%d]\n", queue);
1232
1233 fp->tpa_state[queue] = BNX2X_TPA_START;
1234
1235 /* point prod_bd to new skb */
1236 prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1237 prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1238
1239#ifdef BNX2X_STOP_ON_ERROR
1240 fp->tpa_queue_used |= (1 << queue);
1241#ifdef __powerpc64__
1242 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
1243#else
1244 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
1245#endif
1246 fp->tpa_queue_used);
1247#endif
1248}
1249
1250static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1251 struct sk_buff *skb,
1252 struct eth_fast_path_rx_cqe *fp_cqe,
1253 u16 cqe_idx)
1254{
1255 struct sw_rx_page *rx_pg, old_rx_pg;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001256 u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
1257 u32 i, frag_len, frag_size, pages;
1258 int err;
1259 int j;
1260
1261 frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001262 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001263
1264 /* This is needed in order to enable forwarding support */
1265 if (frag_size)
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001266 skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001267 max(frag_size, (u32)len_on_bd));
1268
1269#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001270 if (pages >
1271 min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001272 BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
1273 pages, cqe_idx);
1274 BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
1275 fp_cqe->pkt_len, len_on_bd);
1276 bnx2x_panic();
1277 return -EINVAL;
1278 }
1279#endif
1280
1281 /* Run through the SGL and compose the fragmented skb */
1282 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
1283 u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j]));
1284
1285 /* FW gives the indices of the SGE as if the ring is an array
1286 (meaning that "next" element will consume 2 indices) */
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001287 frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001288 rx_pg = &fp->rx_page_ring[sge_idx];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001289 old_rx_pg = *rx_pg;
1290
1291 /* If we fail to allocate a substitute page, we simply stop
1292 where we are and drop the whole packet */
1293 err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
1294 if (unlikely(err)) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00001295 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001296 return err;
1297 }
1298
1299 /* Unmap the page as we r going to pass it to the stack */
1300 pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001301 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001302
1303 /* Add one frag and update the appropriate fields in the skb */
1304 skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
1305
1306 skb->data_len += frag_len;
1307 skb->truesize += frag_len;
1308 skb->len += frag_len;
1309
1310 frag_size -= frag_len;
1311 }
1312
1313 return 0;
1314}
1315
1316static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1317 u16 queue, int pad, int len, union eth_rx_cqe *cqe,
1318 u16 cqe_idx)
1319{
1320 struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
1321 struct sk_buff *skb = rx_buf->skb;
1322 /* alloc new skb */
1323 struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1324
1325 /* Unmap skb in the pool anyway, as we are going to change
1326 pool entry status to BNX2X_TPA_STOP even if new skb allocation
1327 fails. */
1328 pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001329 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001330
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001331 if (likely(new_skb)) {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001332 /* fix ip xsum and give it to the stack */
1333 /* (no need to map the new skb) */
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001334#ifdef BCM_VLAN
1335 int is_vlan_cqe =
1336 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1337 PARSING_FLAGS_VLAN);
1338 int is_not_hwaccel_vlan_cqe =
1339 (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG)));
1340#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001341
1342 prefetch(skb);
1343 prefetch(((char *)(skb)) + 128);
1344
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001345#ifdef BNX2X_STOP_ON_ERROR
1346 if (pad + len > bp->rx_buf_size) {
1347 BNX2X_ERR("skb_put is about to fail... "
1348 "pad %d len %d rx_buf_size %d\n",
1349 pad, len, bp->rx_buf_size);
1350 bnx2x_panic();
1351 return;
1352 }
1353#endif
1354
1355 skb_reserve(skb, pad);
1356 skb_put(skb, len);
1357
1358 skb->protocol = eth_type_trans(skb, bp->dev);
1359 skb->ip_summed = CHECKSUM_UNNECESSARY;
1360
1361 {
1362 struct iphdr *iph;
1363
1364 iph = (struct iphdr *)skb->data;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001365#ifdef BCM_VLAN
1366 /* If there is no Rx VLAN offloading -
1367 take VLAN tag into an account */
1368 if (unlikely(is_not_hwaccel_vlan_cqe))
1369 iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN);
1370#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001371 iph->check = 0;
1372 iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
1373 }
1374
1375 if (!bnx2x_fill_frag_skb(bp, fp, skb,
1376 &cqe->fast_path_cqe, cqe_idx)) {
1377#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001378 if ((bp->vlgrp != NULL) && is_vlan_cqe &&
1379 (!is_not_hwaccel_vlan_cqe))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001380 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1381 le16_to_cpu(cqe->fast_path_cqe.
1382 vlan_tag));
1383 else
1384#endif
1385 netif_receive_skb(skb);
1386 } else {
1387 DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
1388 " - dropping packet!\n");
1389 dev_kfree_skb(skb);
1390 }
1391
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001392
1393 /* put new skb in bin */
1394 fp->tpa_pool[queue].skb = new_skb;
1395
1396 } else {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001397 /* else drop the packet and keep the buffer in the bin */
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001398 DP(NETIF_MSG_RX_STATUS,
1399 "Failed to allocate new skb - dropping packet!\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001400 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001401 }
1402
1403 fp->tpa_state[queue] = BNX2X_TPA_STOP;
1404}
1405
1406static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
1407 struct bnx2x_fastpath *fp,
1408 u16 bd_prod, u16 rx_comp_prod,
1409 u16 rx_sge_prod)
1410{
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001411 struct ustorm_eth_rx_producers rx_prods = {0};
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001412 int i;
1413
1414 /* Update producers */
1415 rx_prods.bd_prod = bd_prod;
1416 rx_prods.cqe_prod = rx_comp_prod;
1417 rx_prods.sge_prod = rx_sge_prod;
1418
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001419 /*
1420 * Make sure that the BD and SGE data is updated before updating the
1421 * producers since FW might read the BD/SGE right after the producer
1422 * is updated.
1423 * This is only applicable for weak-ordered memory model archs such
1424 * as IA-64. The following barrier is also mandatory since FW will
1425 * assumes BDs must have buffers.
1426 */
1427 wmb();
1428
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001429 for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
1430 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00001431 USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001432 ((u32 *)&rx_prods)[i]);
1433
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001434 mmiowb(); /* keep prod updates ordered */
1435
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001436 DP(NETIF_MSG_RX_STATUS,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001437 "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
1438 fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001439}
1440
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001441static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
1442{
1443 struct bnx2x *bp = fp->bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001444 u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001445 u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
1446 int rx_pkt = 0;
1447
1448#ifdef BNX2X_STOP_ON_ERROR
1449 if (unlikely(bp->panic))
1450 return 0;
1451#endif
1452
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001453 /* CQ "next element" is of the size of the regular element,
1454 that's why it's ok here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001455 hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
1456 if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
1457 hw_comp_cons++;
1458
1459 bd_cons = fp->rx_bd_cons;
1460 bd_prod = fp->rx_bd_prod;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001461 bd_prod_fw = bd_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001462 sw_comp_cons = fp->rx_comp_cons;
1463 sw_comp_prod = fp->rx_comp_prod;
1464
1465 /* Memory barrier necessary as speculative reads of the rx
1466 * buffer can be ahead of the index in the status block
1467 */
1468 rmb();
1469
1470 DP(NETIF_MSG_RX_STATUS,
1471 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001472 fp->index, hw_comp_cons, sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001473
1474 while (sw_comp_cons != hw_comp_cons) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001475 struct sw_rx_bd *rx_buf = NULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001476 struct sk_buff *skb;
1477 union eth_rx_cqe *cqe;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001478 u8 cqe_fp_flags;
1479 u16 len, pad;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001480
1481 comp_ring_cons = RCQ_BD(sw_comp_cons);
1482 bd_prod = RX_BD(bd_prod);
1483 bd_cons = RX_BD(bd_cons);
1484
1485 cqe = &fp->rx_comp_ring[comp_ring_cons];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001486 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001487
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001488 DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001489 " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
1490 cqe_fp_flags, cqe->fast_path_cqe.status_flags,
Eilon Greenstein68d59482009-01-14 21:27:36 -08001491 le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001492 le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
1493 le16_to_cpu(cqe->fast_path_cqe.pkt_len));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001494
1495 /* is this a slowpath msg? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001496 if (unlikely(CQE_TYPE(cqe_fp_flags))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001497 bnx2x_sp_event(fp, cqe);
1498 goto next_cqe;
1499
1500 /* this is an rx packet */
1501 } else {
1502 rx_buf = &fp->rx_buf_ring[bd_cons];
1503 skb = rx_buf->skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001504 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
1505 pad = cqe->fast_path_cqe.placement_offset;
1506
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001507 /* If CQE is marked both TPA_START and TPA_END
1508 it is a non-TPA CQE */
1509 if ((!fp->disable_tpa) &&
1510 (TPA_TYPE(cqe_fp_flags) !=
1511 (TPA_TYPE_START | TPA_TYPE_END))) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07001512 u16 queue = cqe->fast_path_cqe.queue_index;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001513
1514 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
1515 DP(NETIF_MSG_RX_STATUS,
1516 "calling tpa_start on queue %d\n",
1517 queue);
1518
1519 bnx2x_tpa_start(fp, queue, skb,
1520 bd_cons, bd_prod);
1521 goto next_rx;
1522 }
1523
1524 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) {
1525 DP(NETIF_MSG_RX_STATUS,
1526 "calling tpa_stop on queue %d\n",
1527 queue);
1528
1529 if (!BNX2X_RX_SUM_FIX(cqe))
1530 BNX2X_ERR("STOP on none TCP "
1531 "data\n");
1532
1533 /* This is a size of the linear data
1534 on this skb */
1535 len = le16_to_cpu(cqe->fast_path_cqe.
1536 len_on_bd);
1537 bnx2x_tpa_stop(bp, fp, queue, pad,
1538 len, cqe, comp_ring_cons);
1539#ifdef BNX2X_STOP_ON_ERROR
1540 if (bp->panic)
1541 return -EINVAL;
1542#endif
1543
1544 bnx2x_update_sge_prod(fp,
1545 &cqe->fast_path_cqe);
1546 goto next_cqe;
1547 }
1548 }
1549
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001550 pci_dma_sync_single_for_device(bp->pdev,
1551 pci_unmap_addr(rx_buf, mapping),
1552 pad + RX_COPY_THRESH,
1553 PCI_DMA_FROMDEVICE);
1554 prefetch(skb);
1555 prefetch(((char *)(skb)) + 128);
1556
1557 /* is this an error packet? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001558 if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001559 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001560 "ERROR flags %x rx packet %u\n",
1561 cqe_fp_flags, sw_comp_cons);
Eilon Greensteinde832a52009-02-12 08:36:33 +00001562 fp->eth_q_stats.rx_err_discard_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001563 goto reuse_rx;
1564 }
1565
1566 /* Since we don't have a jumbo ring
1567 * copy small packets if mtu > 1500
1568 */
1569 if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
1570 (len <= RX_COPY_THRESH)) {
1571 struct sk_buff *new_skb;
1572
1573 new_skb = netdev_alloc_skb(bp->dev,
1574 len + pad);
1575 if (new_skb == NULL) {
1576 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001577 "ERROR packet dropped "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001578 "because of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001579 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001580 goto reuse_rx;
1581 }
1582
1583 /* aligned copy */
1584 skb_copy_from_linear_data_offset(skb, pad,
1585 new_skb->data + pad, len);
1586 skb_reserve(new_skb, pad);
1587 skb_put(new_skb, len);
1588
1589 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1590
1591 skb = new_skb;
1592
1593 } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) {
1594 pci_unmap_single(bp->pdev,
1595 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001596 bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001597 PCI_DMA_FROMDEVICE);
1598 skb_reserve(skb, pad);
1599 skb_put(skb, len);
1600
1601 } else {
1602 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001603 "ERROR packet dropped because "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001604 "of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001605 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001606reuse_rx:
1607 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1608 goto next_rx;
1609 }
1610
1611 skb->protocol = eth_type_trans(skb, bp->dev);
1612
1613 skb->ip_summed = CHECKSUM_NONE;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001614 if (bp->rx_csum) {
Eilon Greenstein1adcd8b2008-08-13 15:48:29 -07001615 if (likely(BNX2X_RX_CSUM_OK(cqe)))
1616 skb->ip_summed = CHECKSUM_UNNECESSARY;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001617 else
Eilon Greensteinde832a52009-02-12 08:36:33 +00001618 fp->eth_q_stats.hw_csum_err++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001619 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001620 }
1621
Eilon Greenstein748e5432009-02-12 08:36:37 +00001622 skb_record_rx_queue(skb, fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001623#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001624 if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001625 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1626 PARSING_FLAGS_VLAN))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001627 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1628 le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
1629 else
1630#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001631 netif_receive_skb(skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001632
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001633
1634next_rx:
1635 rx_buf->skb = NULL;
1636
1637 bd_cons = NEXT_RX_IDX(bd_cons);
1638 bd_prod = NEXT_RX_IDX(bd_prod);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001639 bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
1640 rx_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001641next_cqe:
1642 sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
1643 sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001644
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001645 if (rx_pkt == budget)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001646 break;
1647 } /* while */
1648
1649 fp->rx_bd_cons = bd_cons;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001650 fp->rx_bd_prod = bd_prod_fw;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001651 fp->rx_comp_cons = sw_comp_cons;
1652 fp->rx_comp_prod = sw_comp_prod;
1653
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001654 /* Update producers */
1655 bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
1656 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001657
1658 fp->rx_pkt += rx_pkt;
1659 fp->rx_calls++;
1660
1661 return rx_pkt;
1662}
1663
1664static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
1665{
1666 struct bnx2x_fastpath *fp = fp_cookie;
1667 struct bnx2x *bp = fp->bp;
Eilon Greenstein0626b892009-02-12 08:38:14 +00001668 int index = fp->index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001669
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07001670 /* Return here if interrupt is disabled */
1671 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1672 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1673 return IRQ_HANDLED;
1674 }
1675
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001676 DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001677 index, fp->sb_id);
1678 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001679
1680#ifdef BNX2X_STOP_ON_ERROR
1681 if (unlikely(bp->panic))
1682 return IRQ_HANDLED;
1683#endif
1684
1685 prefetch(fp->rx_cons_sb);
1686 prefetch(fp->tx_cons_sb);
1687 prefetch(&fp->status_blk->c_status_block.status_block_index);
1688 prefetch(&fp->status_blk->u_status_block.status_block_index);
1689
Ben Hutchings288379f2009-01-19 16:43:59 -08001690 napi_schedule(&bnx2x_fp(bp, index, napi));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001691
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001692 return IRQ_HANDLED;
1693}
1694
1695static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1696{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001697 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001698 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001699 u16 mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001700
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001701 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001702 if (unlikely(status == 0)) {
1703 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1704 return IRQ_NONE;
1705 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001706 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001707
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001708 /* Return here if interrupt is disabled */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001709 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1710 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1711 return IRQ_HANDLED;
1712 }
1713
Eilon Greenstein3196a882008-08-13 15:58:49 -07001714#ifdef BNX2X_STOP_ON_ERROR
1715 if (unlikely(bp->panic))
1716 return IRQ_HANDLED;
1717#endif
1718
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001719 mask = 0x2 << bp->fp[0].sb_id;
1720 if (status & mask) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001721 struct bnx2x_fastpath *fp = &bp->fp[0];
1722
1723 prefetch(fp->rx_cons_sb);
1724 prefetch(fp->tx_cons_sb);
1725 prefetch(&fp->status_blk->c_status_block.status_block_index);
1726 prefetch(&fp->status_blk->u_status_block.status_block_index);
1727
Ben Hutchings288379f2009-01-19 16:43:59 -08001728 napi_schedule(&bnx2x_fp(bp, 0, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001729
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001730 status &= ~mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001731 }
1732
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001733
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001734 if (unlikely(status & 0x1)) {
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001735 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001736
1737 status &= ~0x1;
1738 if (!status)
1739 return IRQ_HANDLED;
1740 }
1741
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001742 if (status)
1743 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n",
1744 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001745
1746 return IRQ_HANDLED;
1747}
1748
1749/* end of fast path */
1750
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001751static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001752
1753/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001754
1755/*
1756 * General service functions
1757 */
1758
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001759static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001760{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001761 u32 lock_status;
1762 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001763 int func = BP_FUNC(bp);
1764 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001765 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001766
1767 /* Validating that the resource is within range */
1768 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1769 DP(NETIF_MSG_HW,
1770 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1771 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1772 return -EINVAL;
1773 }
1774
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001775 if (func <= 5) {
1776 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1777 } else {
1778 hw_lock_control_reg =
1779 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1780 }
1781
Eliezer Tamirf1410642008-02-28 11:51:50 -08001782 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001783 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001784 if (lock_status & resource_bit) {
1785 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1786 lock_status, resource_bit);
1787 return -EEXIST;
1788 }
1789
Eilon Greenstein46230472008-08-25 15:23:30 -07001790 /* Try for 5 second every 5ms */
1791 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001792 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001793 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1794 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001795 if (lock_status & resource_bit)
1796 return 0;
1797
1798 msleep(5);
1799 }
1800 DP(NETIF_MSG_HW, "Timeout\n");
1801 return -EAGAIN;
1802}
1803
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001804static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001805{
1806 u32 lock_status;
1807 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001808 int func = BP_FUNC(bp);
1809 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001810
1811 /* Validating that the resource is within range */
1812 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1813 DP(NETIF_MSG_HW,
1814 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1815 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1816 return -EINVAL;
1817 }
1818
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001819 if (func <= 5) {
1820 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1821 } else {
1822 hw_lock_control_reg =
1823 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1824 }
1825
Eliezer Tamirf1410642008-02-28 11:51:50 -08001826 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001827 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001828 if (!(lock_status & resource_bit)) {
1829 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1830 lock_status, resource_bit);
1831 return -EFAULT;
1832 }
1833
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001834 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001835 return 0;
1836}
1837
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001838/* HW Lock for shared dual port PHYs */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001839static void bnx2x_acquire_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001840{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001841 mutex_lock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001842
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001843 if (bp->port.need_hw_lock)
1844 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001845}
1846
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001847static void bnx2x_release_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001848{
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001849 if (bp->port.need_hw_lock)
1850 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001851
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001852 mutex_unlock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001853}
1854
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001855int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1856{
1857 /* The GPIO should be swapped if swap register is set and active */
1858 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1859 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1860 int gpio_shift = gpio_num +
1861 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1862 u32 gpio_mask = (1 << gpio_shift);
1863 u32 gpio_reg;
1864 int value;
1865
1866 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1867 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1868 return -EINVAL;
1869 }
1870
1871 /* read GPIO value */
1872 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1873
1874 /* get the requested pin value */
1875 if ((gpio_reg & gpio_mask) == gpio_mask)
1876 value = 1;
1877 else
1878 value = 0;
1879
1880 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1881
1882 return value;
1883}
1884
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001885int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001886{
1887 /* The GPIO should be swapped if swap register is set and active */
1888 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001889 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001890 int gpio_shift = gpio_num +
1891 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1892 u32 gpio_mask = (1 << gpio_shift);
1893 u32 gpio_reg;
1894
1895 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1896 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1897 return -EINVAL;
1898 }
1899
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001900 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001901 /* read GPIO and mask except the float bits */
1902 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1903
1904 switch (mode) {
1905 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1906 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1907 gpio_num, gpio_shift);
1908 /* clear FLOAT and set CLR */
1909 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1910 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1911 break;
1912
1913 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1914 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1915 gpio_num, gpio_shift);
1916 /* clear FLOAT and set SET */
1917 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1918 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1919 break;
1920
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001921 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001922 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1923 gpio_num, gpio_shift);
1924 /* set FLOAT */
1925 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1926 break;
1927
1928 default:
1929 break;
1930 }
1931
1932 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001933 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001934
1935 return 0;
1936}
1937
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001938int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1939{
1940 /* The GPIO should be swapped if swap register is set and active */
1941 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1942 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1943 int gpio_shift = gpio_num +
1944 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1945 u32 gpio_mask = (1 << gpio_shift);
1946 u32 gpio_reg;
1947
1948 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1949 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1950 return -EINVAL;
1951 }
1952
1953 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1954 /* read GPIO int */
1955 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1956
1957 switch (mode) {
1958 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1959 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
1960 "output low\n", gpio_num, gpio_shift);
1961 /* clear SET and set CLR */
1962 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1963 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1964 break;
1965
1966 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1967 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
1968 "output high\n", gpio_num, gpio_shift);
1969 /* clear CLR and set SET */
1970 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1971 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1972 break;
1973
1974 default:
1975 break;
1976 }
1977
1978 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1979 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1980
1981 return 0;
1982}
1983
Eliezer Tamirf1410642008-02-28 11:51:50 -08001984static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
1985{
1986 u32 spio_mask = (1 << spio_num);
1987 u32 spio_reg;
1988
1989 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
1990 (spio_num > MISC_REGISTERS_SPIO_7)) {
1991 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
1992 return -EINVAL;
1993 }
1994
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001995 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001996 /* read SPIO and mask except the float bits */
1997 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
1998
1999 switch (mode) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07002000 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002001 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2002 /* clear FLOAT and set CLR */
2003 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2004 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2005 break;
2006
Eilon Greenstein6378c022008-08-13 15:59:25 -07002007 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002008 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2009 /* clear FLOAT and set SET */
2010 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2011 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2012 break;
2013
2014 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2015 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2016 /* set FLOAT */
2017 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2018 break;
2019
2020 default:
2021 break;
2022 }
2023
2024 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002025 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002026
2027 return 0;
2028}
2029
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002030static void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002031{
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002032 switch (bp->link_vars.ieee_fc &
2033 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002034 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002035 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002036 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002037 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002038
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002039 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002040 bp->port.advertising |= (ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002041 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002042 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002043
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002044 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002045 bp->port.advertising |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002046 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002047
Eliezer Tamirf1410642008-02-28 11:51:50 -08002048 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002049 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002050 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002051 break;
2052 }
2053}
2054
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002055static void bnx2x_link_report(struct bnx2x *bp)
2056{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002057 if (bp->link_vars.link_up) {
2058 if (bp->state == BNX2X_STATE_OPEN)
2059 netif_carrier_on(bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002060 printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
2061
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002062 printk("%d Mbps ", bp->link_vars.line_speed);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002063
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002064 if (bp->link_vars.duplex == DUPLEX_FULL)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002065 printk("full duplex");
2066 else
2067 printk("half duplex");
2068
David S. Millerc0700f92008-12-16 23:53:20 -08002069 if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) {
2070 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002071 printk(", receive ");
Eilon Greenstein356e2382009-02-12 08:38:32 +00002072 if (bp->link_vars.flow_ctrl &
2073 BNX2X_FLOW_CTRL_TX)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002074 printk("& transmit ");
2075 } else {
2076 printk(", transmit ");
2077 }
2078 printk("flow control ON");
2079 }
2080 printk("\n");
2081
2082 } else { /* link_down */
2083 netif_carrier_off(bp->dev);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002084 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002085 }
2086}
2087
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002088static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002089{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002090 if (!BP_NOMCP(bp)) {
2091 u8 rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002092
Eilon Greenstein19680c42008-08-13 15:47:33 -07002093 /* Initialize link parameters structure variables */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002094 /* It is recommended to turn off RX FC for jumbo frames
2095 for better performance */
2096 if (IS_E1HMF(bp))
David S. Millerc0700f92008-12-16 23:53:20 -08002097 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002098 else if (bp->dev->mtu > 5000)
David S. Millerc0700f92008-12-16 23:53:20 -08002099 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002100 else
David S. Millerc0700f92008-12-16 23:53:20 -08002101 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002102
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002103 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002104
2105 if (load_mode == LOAD_DIAG)
2106 bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
2107
Eilon Greenstein19680c42008-08-13 15:47:33 -07002108 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002109
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002110 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002111
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002112 bnx2x_calc_fc_adv(bp);
2113
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002114 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2115 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002116 bnx2x_link_report(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002117 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002118
Eilon Greenstein19680c42008-08-13 15:47:33 -07002119 return rc;
2120 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002121 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002122 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002123}
2124
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002125static void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002126{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002127 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002128 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002129 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002130 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002131
Eilon Greenstein19680c42008-08-13 15:47:33 -07002132 bnx2x_calc_fc_adv(bp);
2133 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002134 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002135}
2136
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002137static void bnx2x__link_reset(struct bnx2x *bp)
2138{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002139 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002140 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002141 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002142 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002143 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002144 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002145}
2146
2147static u8 bnx2x_link_test(struct bnx2x *bp)
2148{
2149 u8 rc;
2150
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002151 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002152 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002153 bnx2x_release_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002154
2155 return rc;
2156}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002157
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002158static void bnx2x_init_port_minmax(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002159{
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002160 u32 r_param = bp->link_vars.line_speed / 8;
2161 u32 fair_periodic_timeout_usec;
2162 u32 t_fair;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002163
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002164 memset(&(bp->cmng.rs_vars), 0,
2165 sizeof(struct rate_shaping_vars_per_port));
2166 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002167
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002168 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2169 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002170
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002171 /* this is the threshold below which no timer arming will occur
2172 1.25 coefficient is for the threshold to be a little bigger
2173 than the real time, to compensate for timer in-accuracy */
2174 bp->cmng.rs_vars.rs_threshold =
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002175 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2176
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002177 /* resolution of fairness timer */
2178 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2179 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2180 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002181
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002182 /* this is the threshold below which we won't arm the timer anymore */
2183 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002184
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002185 /* we multiply by 1e3/8 to get bytes/msec.
2186 We don't want the credits to pass a credit
2187 of the t_fair*FAIR_MEM (algorithm resolution) */
2188 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2189 /* since each tick is 4 usec */
2190 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002191}
2192
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002193static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002194{
2195 struct rate_shaping_vars_per_vn m_rs_vn;
2196 struct fairness_vars_per_vn m_fair_vn;
2197 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
2198 u16 vn_min_rate, vn_max_rate;
2199 int i;
2200
2201 /* If function is hidden - set min and max to zeroes */
2202 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2203 vn_min_rate = 0;
2204 vn_max_rate = 0;
2205
2206 } else {
2207 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2208 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002209 /* If fairness is enabled (not all min rates are zeroes) and
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002210 if current min rate is zero - set it to 1.
Eilon Greenstein33471622008-08-13 15:59:08 -07002211 This is a requirement of the algorithm. */
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002212 if (bp->vn_weight_sum && (vn_min_rate == 0))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002213 vn_min_rate = DEF_MIN_RATE;
2214 vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
2215 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
2216 }
2217
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002218 DP(NETIF_MSG_IFUP,
2219 "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n",
2220 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002221
2222 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2223 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2224
2225 /* global vn counter - maximal Mbps for this vn */
2226 m_rs_vn.vn_counter.rate = vn_max_rate;
2227
2228 /* quota - number of bytes transmitted in this period */
2229 m_rs_vn.vn_counter.quota =
2230 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2231
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002232 if (bp->vn_weight_sum) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002233 /* credit for each period of the fairness algorithm:
2234 number of bytes in T_FAIR (the vn share the port rate).
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002235 vn_weight_sum should not be larger than 10000, thus
2236 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2237 than zero */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002238 m_fair_vn.vn_credit_delta =
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002239 max((u32)(vn_min_rate * (T_FAIR_COEF /
2240 (8 * bp->vn_weight_sum))),
2241 (u32)(bp->cmng.fair_vars.fair_threshold * 2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002242 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n",
2243 m_fair_vn.vn_credit_delta);
2244 }
2245
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002246 /* Store it to internal memory */
2247 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2248 REG_WR(bp, BAR_XSTRORM_INTMEM +
2249 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2250 ((u32 *)(&m_rs_vn))[i]);
2251
2252 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2253 REG_WR(bp, BAR_XSTRORM_INTMEM +
2254 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2255 ((u32 *)(&m_fair_vn))[i]);
2256}
2257
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002258
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002259/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002260static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002261{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002262 /* Make sure that we are synced with the current statistics */
2263 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2264
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002265 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002266
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002267 if (bp->link_vars.link_up) {
2268
Eilon Greenstein1c063282009-02-12 08:36:43 +00002269 /* dropless flow control */
2270 if (CHIP_IS_E1H(bp)) {
2271 int port = BP_PORT(bp);
2272 u32 pause_enabled = 0;
2273
2274 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2275 pause_enabled = 1;
2276
2277 REG_WR(bp, BAR_USTRORM_INTMEM +
2278 USTORM_PAUSE_ENABLED_OFFSET(port),
2279 pause_enabled);
2280 }
2281
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002282 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
2283 struct host_port_stats *pstats;
2284
2285 pstats = bnx2x_sp(bp, port_stats);
2286 /* reset old bmac stats */
2287 memset(&(pstats->mac_stx[0]), 0,
2288 sizeof(struct mac_stx));
2289 }
2290 if ((bp->state == BNX2X_STATE_OPEN) ||
2291 (bp->state == BNX2X_STATE_DISABLED))
2292 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2293 }
2294
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002295 /* indicate link status */
2296 bnx2x_link_report(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002297
2298 if (IS_E1HMF(bp)) {
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002299 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002300 int func;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002301 int vn;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002302
2303 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2304 if (vn == BP_E1HVN(bp))
2305 continue;
2306
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002307 func = ((vn << 1) | port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002308
2309 /* Set the attention towards other drivers
2310 on the same port */
2311 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2312 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2313 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002314
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002315 if (bp->link_vars.link_up) {
2316 int i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002317
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002318 /* Init rate shaping and fairness contexts */
2319 bnx2x_init_port_minmax(bp);
2320
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002321 for (vn = VN_0; vn < E1HVN_MAX; vn++)
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002322 bnx2x_init_vn_minmax(bp, 2*vn + port);
2323
2324 /* Store it to internal memory */
2325 for (i = 0;
2326 i < sizeof(struct cmng_struct_per_port) / 4; i++)
2327 REG_WR(bp, BAR_XSTRORM_INTMEM +
2328 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
2329 ((u32 *)(&bp->cmng))[i]);
2330 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002331 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002332}
2333
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002334static void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002335{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002336 if (bp->state != BNX2X_STATE_OPEN)
2337 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002338
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002339 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2340
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002341 if (bp->link_vars.link_up)
2342 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2343 else
2344 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2345
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002346 /* indicate link status */
2347 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002348}
2349
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002350static void bnx2x_pmf_update(struct bnx2x *bp)
2351{
2352 int port = BP_PORT(bp);
2353 u32 val;
2354
2355 bp->port.pmf = 1;
2356 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2357
2358 /* enable nig attention */
2359 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2360 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2361 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002362
2363 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002364}
2365
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002366/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002367
2368/* slow path */
2369
2370/*
2371 * General service functions
2372 */
2373
2374/* the slow path queue is odd since completions arrive on the fastpath ring */
2375static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
2376 u32 data_hi, u32 data_lo, int common)
2377{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002378 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002379
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002380 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
2381 "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002382 (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) +
2383 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
2384 HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
2385
2386#ifdef BNX2X_STOP_ON_ERROR
2387 if (unlikely(bp->panic))
2388 return -EIO;
2389#endif
2390
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002391 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002392
2393 if (!bp->spq_left) {
2394 BNX2X_ERR("BUG! SPQ ring full!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002395 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002396 bnx2x_panic();
2397 return -EBUSY;
2398 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08002399
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002400 /* CID needs port number to be encoded int it */
2401 bp->spq_prod_bd->hdr.conn_and_cmd_data =
2402 cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) |
2403 HW_CID(bp, cid)));
2404 bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
2405 if (common)
2406 bp->spq_prod_bd->hdr.type |=
2407 cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
2408
2409 bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi);
2410 bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo);
2411
2412 bp->spq_left--;
2413
2414 if (bp->spq_prod_bd == bp->spq_last_bd) {
2415 bp->spq_prod_bd = bp->spq;
2416 bp->spq_prod_idx = 0;
2417 DP(NETIF_MSG_TIMER, "end of spq\n");
2418
2419 } else {
2420 bp->spq_prod_bd++;
2421 bp->spq_prod_idx++;
2422 }
2423
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002424 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002425 bp->spq_prod_idx);
2426
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002427 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002428 return 0;
2429}
2430
2431/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002432static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002433{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002434 u32 i, j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002435 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002436
2437 might_sleep();
2438 i = 100;
2439 for (j = 0; j < i*10; j++) {
2440 val = (1UL << 31);
2441 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2442 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
2443 if (val & (1L << 31))
2444 break;
2445
2446 msleep(5);
2447 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002448 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07002449 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002450 rc = -EBUSY;
2451 }
2452
2453 return rc;
2454}
2455
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002456/* release split MCP access lock register */
2457static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002458{
2459 u32 val = 0;
2460
2461 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2462}
2463
2464static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
2465{
2466 struct host_def_status_block *def_sb = bp->def_status_blk;
2467 u16 rc = 0;
2468
2469 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002470 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
2471 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
2472 rc |= 1;
2473 }
2474 if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
2475 bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
2476 rc |= 2;
2477 }
2478 if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
2479 bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
2480 rc |= 4;
2481 }
2482 if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
2483 bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
2484 rc |= 8;
2485 }
2486 if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
2487 bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
2488 rc |= 16;
2489 }
2490 return rc;
2491}
2492
2493/*
2494 * slow path service functions
2495 */
2496
2497static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
2498{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002499 int port = BP_PORT(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002500 u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
2501 COMMAND_REG_ATTN_BITS_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002502 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2503 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002504 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
2505 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002506 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00002507 u32 nig_mask = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002508
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002509 if (bp->attn_state & asserted)
2510 BNX2X_ERR("IGU ERROR\n");
2511
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002512 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2513 aeu_mask = REG_RD(bp, aeu_addr);
2514
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002515 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002516 aeu_mask, asserted);
2517 aeu_mask &= ~(asserted & 0xff);
2518 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002519
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002520 REG_WR(bp, aeu_addr, aeu_mask);
2521 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002522
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002523 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002524 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002525 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002526
2527 if (asserted & ATTN_HARD_WIRED_MASK) {
2528 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002529
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002530 bnx2x_acquire_phy_lock(bp);
2531
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002532 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00002533 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002534 REG_WR(bp, nig_int_mask_addr, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002535
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002536 bnx2x_link_attn(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002537
2538 /* handle unicore attn? */
2539 }
2540 if (asserted & ATTN_SW_TIMER_4_FUNC)
2541 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
2542
2543 if (asserted & GPIO_2_FUNC)
2544 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
2545
2546 if (asserted & GPIO_3_FUNC)
2547 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
2548
2549 if (asserted & GPIO_4_FUNC)
2550 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
2551
2552 if (port == 0) {
2553 if (asserted & ATTN_GENERAL_ATTN_1) {
2554 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
2555 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
2556 }
2557 if (asserted & ATTN_GENERAL_ATTN_2) {
2558 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
2559 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
2560 }
2561 if (asserted & ATTN_GENERAL_ATTN_3) {
2562 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
2563 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
2564 }
2565 } else {
2566 if (asserted & ATTN_GENERAL_ATTN_4) {
2567 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
2568 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
2569 }
2570 if (asserted & ATTN_GENERAL_ATTN_5) {
2571 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
2572 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
2573 }
2574 if (asserted & ATTN_GENERAL_ATTN_6) {
2575 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
2576 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
2577 }
2578 }
2579
2580 } /* if hardwired */
2581
Eilon Greenstein5c862842008-08-13 15:51:48 -07002582 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2583 asserted, hc_addr);
2584 REG_WR(bp, hc_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002585
2586 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002587 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00002588 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002589 bnx2x_release_phy_lock(bp);
2590 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002591}
2592
2593static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
2594{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002595 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002596 int reg_offset;
2597 u32 val;
2598
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002599 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
2600 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002601
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002602 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002603
2604 val = REG_RD(bp, reg_offset);
2605 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
2606 REG_WR(bp, reg_offset, val);
2607
2608 BNX2X_ERR("SPIO5 hw attention\n");
2609
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00002610 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
2611 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002612 /* Fan failure attention */
2613
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002614 /* The PHY reset is controlled by GPIO 1 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002615 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002616 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
2617 /* Low power mode is controlled by GPIO 2 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002618 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002619 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002620 /* mark the failure */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002621 bp->link_params.ext_phy_config &=
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002622 ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002623 bp->link_params.ext_phy_config |=
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002624 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
2625 SHMEM_WR(bp,
2626 dev_info.port_hw_config[port].
2627 external_phy_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002628 bp->link_params.ext_phy_config);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002629 /* log the failure */
2630 printk(KERN_ERR PFX "Fan Failure on Network"
2631 " Controller %s has caused the driver to"
2632 " shutdown the card to prevent permanent"
2633 " damage. Please contact Dell Support for"
2634 " assistance\n", bp->dev->name);
2635 break;
2636
2637 default:
2638 break;
2639 }
2640 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002641
Eilon Greenstein589abe32009-02-12 08:36:55 +00002642 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
2643 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
2644 bnx2x_acquire_phy_lock(bp);
2645 bnx2x_handle_module_detect_int(&bp->link_params);
2646 bnx2x_release_phy_lock(bp);
2647 }
2648
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002649 if (attn & HW_INTERRUT_ASSERT_SET_0) {
2650
2651 val = REG_RD(bp, reg_offset);
2652 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
2653 REG_WR(bp, reg_offset, val);
2654
2655 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
2656 (attn & HW_INTERRUT_ASSERT_SET_0));
2657 bnx2x_panic();
2658 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002659}
2660
2661static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
2662{
2663 u32 val;
2664
Eilon Greenstein0626b892009-02-12 08:38:14 +00002665 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002666
2667 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
2668 BNX2X_ERR("DB hw attention 0x%x\n", val);
2669 /* DORQ discard attention */
2670 if (val & 0x2)
2671 BNX2X_ERR("FATAL error from DORQ\n");
2672 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002673
2674 if (attn & HW_INTERRUT_ASSERT_SET_1) {
2675
2676 int port = BP_PORT(bp);
2677 int reg_offset;
2678
2679 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
2680 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
2681
2682 val = REG_RD(bp, reg_offset);
2683 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
2684 REG_WR(bp, reg_offset, val);
2685
2686 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
2687 (attn & HW_INTERRUT_ASSERT_SET_1));
2688 bnx2x_panic();
2689 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002690}
2691
2692static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
2693{
2694 u32 val;
2695
2696 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
2697
2698 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
2699 BNX2X_ERR("CFC hw attention 0x%x\n", val);
2700 /* CFC error attention */
2701 if (val & 0x2)
2702 BNX2X_ERR("FATAL error from CFC\n");
2703 }
2704
2705 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
2706
2707 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
2708 BNX2X_ERR("PXP hw attention 0x%x\n", val);
2709 /* RQ_USDMDP_FIFO_OVERFLOW */
2710 if (val & 0x18000)
2711 BNX2X_ERR("FATAL error from PXP\n");
2712 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002713
2714 if (attn & HW_INTERRUT_ASSERT_SET_2) {
2715
2716 int port = BP_PORT(bp);
2717 int reg_offset;
2718
2719 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
2720 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
2721
2722 val = REG_RD(bp, reg_offset);
2723 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
2724 REG_WR(bp, reg_offset, val);
2725
2726 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
2727 (attn & HW_INTERRUT_ASSERT_SET_2));
2728 bnx2x_panic();
2729 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002730}
2731
2732static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
2733{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002734 u32 val;
2735
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002736 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
2737
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002738 if (attn & BNX2X_PMF_LINK_ASSERT) {
2739 int func = BP_FUNC(bp);
2740
2741 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
2742 bnx2x__link_status_update(bp);
2743 if (SHMEM_RD(bp, func_mb[func].drv_status) &
2744 DRV_STATUS_PMF)
2745 bnx2x_pmf_update(bp);
2746
2747 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002748
2749 BNX2X_ERR("MC assert!\n");
2750 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
2751 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
2752 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
2753 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
2754 bnx2x_panic();
2755
2756 } else if (attn & BNX2X_MCP_ASSERT) {
2757
2758 BNX2X_ERR("MCP assert!\n");
2759 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002760 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002761
2762 } else
2763 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
2764 }
2765
2766 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002767 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
2768 if (attn & BNX2X_GRC_TIMEOUT) {
2769 val = CHIP_IS_E1H(bp) ?
2770 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
2771 BNX2X_ERR("GRC time-out 0x%08x\n", val);
2772 }
2773 if (attn & BNX2X_GRC_RSV) {
2774 val = CHIP_IS_E1H(bp) ?
2775 REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
2776 BNX2X_ERR("GRC reserved 0x%08x\n", val);
2777 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002778 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002779 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002780}
2781
2782static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
2783{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002784 struct attn_route attn;
2785 struct attn_route group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002786 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002787 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002788 u32 reg_addr;
2789 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002790 u32 aeu_mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002791
2792 /* need to take HW lock because MCP or other port might also
2793 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002794 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002795
2796 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
2797 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
2798 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
2799 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002800 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
2801 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002802
2803 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
2804 if (deasserted & (1 << index)) {
2805 group_mask = bp->attn_group[index];
2806
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002807 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
2808 index, group_mask.sig[0], group_mask.sig[1],
2809 group_mask.sig[2], group_mask.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002810
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002811 bnx2x_attn_int_deasserted3(bp,
2812 attn.sig[3] & group_mask.sig[3]);
2813 bnx2x_attn_int_deasserted1(bp,
2814 attn.sig[1] & group_mask.sig[1]);
2815 bnx2x_attn_int_deasserted2(bp,
2816 attn.sig[2] & group_mask.sig[2]);
2817 bnx2x_attn_int_deasserted0(bp,
2818 attn.sig[0] & group_mask.sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002819
2820 if ((attn.sig[0] & group_mask.sig[0] &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002821 HW_PRTY_ASSERT_SET_0) ||
2822 (attn.sig[1] & group_mask.sig[1] &
2823 HW_PRTY_ASSERT_SET_1) ||
2824 (attn.sig[2] & group_mask.sig[2] &
2825 HW_PRTY_ASSERT_SET_2))
Eilon Greenstein6378c022008-08-13 15:59:25 -07002826 BNX2X_ERR("FATAL HW block parity attention\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002827 }
2828 }
2829
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002830 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002831
Eilon Greenstein5c862842008-08-13 15:51:48 -07002832 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002833
2834 val = ~deasserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002835 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2836 val, reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002837 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002838
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002839 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002840 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002841
2842 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2843 MISC_REG_AEU_MASK_ATTN_FUNC_0;
2844
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002845 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2846 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002847
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002848 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
2849 aeu_mask, deasserted);
2850 aeu_mask |= (deasserted & 0xff);
2851 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
2852
2853 REG_WR(bp, reg_addr, aeu_mask);
2854 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002855
2856 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
2857 bp->attn_state &= ~deasserted;
2858 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
2859}
2860
2861static void bnx2x_attn_int(struct bnx2x *bp)
2862{
2863 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08002864 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
2865 attn_bits);
2866 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
2867 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002868 u32 attn_state = bp->attn_state;
2869
2870 /* look for changed bits */
2871 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
2872 u32 deasserted = ~attn_bits & attn_ack & attn_state;
2873
2874 DP(NETIF_MSG_HW,
2875 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
2876 attn_bits, attn_ack, asserted, deasserted);
2877
2878 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002879 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002880
2881 /* handle bits that were raised */
2882 if (asserted)
2883 bnx2x_attn_int_asserted(bp, asserted);
2884
2885 if (deasserted)
2886 bnx2x_attn_int_deasserted(bp, deasserted);
2887}
2888
2889static void bnx2x_sp_task(struct work_struct *work)
2890{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002891 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002892 u16 status;
2893
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002894
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002895 /* Return here if interrupt is disabled */
2896 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002897 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002898 return;
2899 }
2900
2901 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002902/* if (status == 0) */
2903/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002904
Eilon Greenstein3196a882008-08-13 15:58:49 -07002905 DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002906
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002907 /* HW attentions */
2908 if (status & 0x1)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002909 bnx2x_attn_int(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002910
Eilon Greenstein68d59482009-01-14 21:27:36 -08002911 bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002912 IGU_INT_NOP, 1);
2913 bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
2914 IGU_INT_NOP, 1);
2915 bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
2916 IGU_INT_NOP, 1);
2917 bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
2918 IGU_INT_NOP, 1);
2919 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
2920 IGU_INT_ENABLE, 1);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002921
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002922}
2923
2924static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
2925{
2926 struct net_device *dev = dev_instance;
2927 struct bnx2x *bp = netdev_priv(dev);
2928
2929 /* Return here if interrupt is disabled */
2930 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002931 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002932 return IRQ_HANDLED;
2933 }
2934
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08002935 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002936
2937#ifdef BNX2X_STOP_ON_ERROR
2938 if (unlikely(bp->panic))
2939 return IRQ_HANDLED;
2940#endif
2941
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002942 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002943
2944 return IRQ_HANDLED;
2945}
2946
2947/* end of slow path */
2948
2949/* Statistics */
2950
2951/****************************************************************************
2952* Macros
2953****************************************************************************/
2954
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002955/* sum[hi:lo] += add[hi:lo] */
2956#define ADD_64(s_hi, a_hi, s_lo, a_lo) \
2957 do { \
2958 s_lo += a_lo; \
Eilon Greensteinf5ba6772009-01-14 21:29:18 -08002959 s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002960 } while (0)
2961
2962/* difference = minuend - subtrahend */
2963#define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
2964 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002965 if (m_lo < s_lo) { \
2966 /* underflow */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002967 d_hi = m_hi - s_hi; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002968 if (d_hi > 0) { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002969 /* we can 'loan' 1 */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002970 d_hi--; \
2971 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002972 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002973 /* m_hi <= s_hi */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002974 d_hi = 0; \
2975 d_lo = 0; \
2976 } \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002977 } else { \
2978 /* m_lo >= s_lo */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002979 if (m_hi < s_hi) { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002980 d_hi = 0; \
2981 d_lo = 0; \
2982 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002983 /* m_hi >= s_hi */ \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002984 d_hi = m_hi - s_hi; \
2985 d_lo = m_lo - s_lo; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002986 } \
2987 } \
2988 } while (0)
2989
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002990#define UPDATE_STAT64(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002991 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002992 DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
2993 diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
2994 pstats->mac_stx[0].t##_hi = new->s##_hi; \
2995 pstats->mac_stx[0].t##_lo = new->s##_lo; \
2996 ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
2997 pstats->mac_stx[1].t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002998 } while (0)
2999
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003000#define UPDATE_STAT64_NIG(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003001 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003002 DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
3003 diff.lo, new->s##_lo, old->s##_lo); \
3004 ADD_64(estats->t##_hi, diff.hi, \
3005 estats->t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003006 } while (0)
3007
3008/* sum[hi:lo] += add */
3009#define ADD_EXTEND_64(s_hi, s_lo, a) \
3010 do { \
3011 s_lo += a; \
3012 s_hi += (s_lo < a) ? 1 : 0; \
3013 } while (0)
3014
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003015#define UPDATE_EXTEND_STAT(s) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003016 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003017 ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
3018 pstats->mac_stx[1].s##_lo, \
3019 new->s); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003020 } while (0)
3021
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003022#define UPDATE_EXTEND_TSTAT(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003023 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003024 diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
3025 old_tclient->s = tclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00003026 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3027 } while (0)
3028
3029#define UPDATE_EXTEND_USTAT(s, t) \
3030 do { \
3031 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3032 old_uclient->s = uclient->s; \
3033 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003034 } while (0)
3035
3036#define UPDATE_EXTEND_XSTAT(s, t) \
3037 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003038 diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
3039 old_xclient->s = xclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00003040 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3041 } while (0)
3042
3043/* minuend -= subtrahend */
3044#define SUB_64(m_hi, s_hi, m_lo, s_lo) \
3045 do { \
3046 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
3047 } while (0)
3048
3049/* minuend[hi:lo] -= subtrahend */
3050#define SUB_EXTEND_64(m_hi, m_lo, s) \
3051 do { \
3052 SUB_64(m_hi, 0, m_lo, s); \
3053 } while (0)
3054
3055#define SUB_EXTEND_USTAT(s, t) \
3056 do { \
3057 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3058 SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003059 } while (0)
3060
3061/*
3062 * General service functions
3063 */
3064
3065static inline long bnx2x_hilo(u32 *hiref)
3066{
3067 u32 lo = *(hiref + 1);
3068#if (BITS_PER_LONG == 64)
3069 u32 hi = *hiref;
3070
3071 return HILO_U64(hi, lo);
3072#else
3073 return lo;
3074#endif
3075}
3076
3077/*
3078 * Init service functions
3079 */
3080
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003081static void bnx2x_storm_stats_post(struct bnx2x *bp)
3082{
3083 if (!bp->stats_pending) {
3084 struct eth_query_ramrod_data ramrod_data = {0};
Eilon Greensteinde832a52009-02-12 08:36:33 +00003085 int i, rc;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003086
3087 ramrod_data.drv_counter = bp->stats_counter++;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08003088 ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003089 for_each_queue(bp, i)
3090 ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003091
3092 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
3093 ((u32 *)&ramrod_data)[1],
3094 ((u32 *)&ramrod_data)[0], 0);
3095 if (rc == 0) {
3096 /* stats ramrod has it's own slot on the spq */
3097 bp->spq_left++;
3098 bp->stats_pending = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003099 }
3100 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003101}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003102
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003103static void bnx2x_stats_init(struct bnx2x *bp)
3104{
3105 int port = BP_PORT(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003106 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003107
Eilon Greensteinde832a52009-02-12 08:36:33 +00003108 bp->stats_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003109 bp->executer_idx = 0;
3110 bp->stats_counter = 0;
3111
3112 /* port stats */
3113 if (!BP_NOMCP(bp))
3114 bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
3115 else
3116 bp->port.port_stx = 0;
3117 DP(BNX2X_MSG_STATS, "port_stx 0x%x\n", bp->port.port_stx);
3118
3119 memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
3120 bp->port.old_nig_stats.brb_discard =
3121 REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003122 bp->port.old_nig_stats.brb_truncate =
3123 REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003124 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
3125 &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
3126 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
3127 &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
3128
3129 /* function stats */
Eilon Greensteinde832a52009-02-12 08:36:33 +00003130 for_each_queue(bp, i) {
3131 struct bnx2x_fastpath *fp = &bp->fp[i];
3132
3133 memset(&fp->old_tclient, 0,
3134 sizeof(struct tstorm_per_client_stats));
3135 memset(&fp->old_uclient, 0,
3136 sizeof(struct ustorm_per_client_stats));
3137 memset(&fp->old_xclient, 0,
3138 sizeof(struct xstorm_per_client_stats));
3139 memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
3140 }
3141
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003142 memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003143 memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
3144
3145 bp->stats_state = STATS_STATE_DISABLED;
3146 if (IS_E1HMF(bp) && bp->port.pmf && bp->port.port_stx)
3147 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
3148}
3149
3150static void bnx2x_hw_stats_post(struct bnx2x *bp)
3151{
3152 struct dmae_command *dmae = &bp->stats_dmae;
3153 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3154
3155 *stats_comp = DMAE_COMP_VAL;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003156 if (CHIP_REV_IS_SLOW(bp))
3157 return;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003158
3159 /* loader */
3160 if (bp->executer_idx) {
3161 int loader_idx = PMF_DMAE_C(bp);
3162
3163 memset(dmae, 0, sizeof(struct dmae_command));
3164
3165 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3166 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3167 DMAE_CMD_DST_RESET |
3168#ifdef __BIG_ENDIAN
3169 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3170#else
3171 DMAE_CMD_ENDIANITY_DW_SWAP |
3172#endif
3173 (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
3174 DMAE_CMD_PORT_0) |
3175 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3176 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
3177 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
3178 dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
3179 sizeof(struct dmae_command) *
3180 (loader_idx + 1)) >> 2;
3181 dmae->dst_addr_hi = 0;
3182 dmae->len = sizeof(struct dmae_command) >> 2;
3183 if (CHIP_IS_E1(bp))
3184 dmae->len--;
3185 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
3186 dmae->comp_addr_hi = 0;
3187 dmae->comp_val = 1;
3188
3189 *stats_comp = 0;
3190 bnx2x_post_dmae(bp, dmae, loader_idx);
3191
3192 } else if (bp->func_stx) {
3193 *stats_comp = 0;
3194 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
3195 }
3196}
3197
3198static int bnx2x_stats_comp(struct bnx2x *bp)
3199{
3200 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3201 int cnt = 10;
3202
3203 might_sleep();
3204 while (*stats_comp != DMAE_COMP_VAL) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003205 if (!cnt) {
3206 BNX2X_ERR("timeout waiting for stats finished\n");
3207 break;
3208 }
3209 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -07003210 msleep(1);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003211 }
3212 return 1;
3213}
3214
3215/*
3216 * Statistics service functions
3217 */
3218
3219static void bnx2x_stats_pmf_update(struct bnx2x *bp)
3220{
3221 struct dmae_command *dmae;
3222 u32 opcode;
3223 int loader_idx = PMF_DMAE_C(bp);
3224 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3225
3226 /* sanity */
3227 if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
3228 BNX2X_ERR("BUG!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003229 return;
3230 }
3231
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003232 bp->executer_idx = 0;
3233
3234 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3235 DMAE_CMD_C_ENABLE |
3236 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3237#ifdef __BIG_ENDIAN
3238 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3239#else
3240 DMAE_CMD_ENDIANITY_DW_SWAP |
3241#endif
3242 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3243 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3244
3245 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3246 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
3247 dmae->src_addr_lo = bp->port.port_stx >> 2;
3248 dmae->src_addr_hi = 0;
3249 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3250 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3251 dmae->len = DMAE_LEN32_RD_MAX;
3252 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3253 dmae->comp_addr_hi = 0;
3254 dmae->comp_val = 1;
3255
3256 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3257 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
3258 dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
3259 dmae->src_addr_hi = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07003260 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
3261 DMAE_LEN32_RD_MAX * 4);
3262 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
3263 DMAE_LEN32_RD_MAX * 4);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003264 dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
3265 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3266 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3267 dmae->comp_val = DMAE_COMP_VAL;
3268
3269 *stats_comp = 0;
3270 bnx2x_hw_stats_post(bp);
3271 bnx2x_stats_comp(bp);
3272}
3273
3274static void bnx2x_port_stats_init(struct bnx2x *bp)
3275{
3276 struct dmae_command *dmae;
3277 int port = BP_PORT(bp);
3278 int vn = BP_E1HVN(bp);
3279 u32 opcode;
3280 int loader_idx = PMF_DMAE_C(bp);
3281 u32 mac_addr;
3282 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3283
3284 /* sanity */
3285 if (!bp->link_vars.link_up || !bp->port.pmf) {
3286 BNX2X_ERR("BUG!\n");
3287 return;
3288 }
3289
3290 bp->executer_idx = 0;
3291
3292 /* MCP */
3293 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3294 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3295 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3296#ifdef __BIG_ENDIAN
3297 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3298#else
3299 DMAE_CMD_ENDIANITY_DW_SWAP |
3300#endif
3301 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3302 (vn << DMAE_CMD_E1HVN_SHIFT));
3303
3304 if (bp->port.port_stx) {
3305
3306 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3307 dmae->opcode = opcode;
3308 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3309 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3310 dmae->dst_addr_lo = bp->port.port_stx >> 2;
3311 dmae->dst_addr_hi = 0;
3312 dmae->len = sizeof(struct host_port_stats) >> 2;
3313 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3314 dmae->comp_addr_hi = 0;
3315 dmae->comp_val = 1;
3316 }
3317
3318 if (bp->func_stx) {
3319
3320 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3321 dmae->opcode = opcode;
3322 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3323 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3324 dmae->dst_addr_lo = bp->func_stx >> 2;
3325 dmae->dst_addr_hi = 0;
3326 dmae->len = sizeof(struct host_func_stats) >> 2;
3327 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3328 dmae->comp_addr_hi = 0;
3329 dmae->comp_val = 1;
3330 }
3331
3332 /* MAC */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003333 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3334 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3335 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3336#ifdef __BIG_ENDIAN
3337 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3338#else
3339 DMAE_CMD_ENDIANITY_DW_SWAP |
3340#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003341 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3342 (vn << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003343
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003344 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003345
3346 mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
3347 NIG_REG_INGRESS_BMAC0_MEM);
3348
3349 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
3350 BIGMAC_REGISTER_TX_STAT_GTBYT */
3351 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3352 dmae->opcode = opcode;
3353 dmae->src_addr_lo = (mac_addr +
3354 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3355 dmae->src_addr_hi = 0;
3356 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3357 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3358 dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
3359 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3360 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3361 dmae->comp_addr_hi = 0;
3362 dmae->comp_val = 1;
3363
3364 /* BIGMAC_REGISTER_RX_STAT_GR64 ..
3365 BIGMAC_REGISTER_RX_STAT_GRIPJ */
3366 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3367 dmae->opcode = opcode;
3368 dmae->src_addr_lo = (mac_addr +
3369 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3370 dmae->src_addr_hi = 0;
3371 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003372 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003373 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003374 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003375 dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
3376 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3377 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3378 dmae->comp_addr_hi = 0;
3379 dmae->comp_val = 1;
3380
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003381 } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003382
3383 mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
3384
3385 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
3386 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3387 dmae->opcode = opcode;
3388 dmae->src_addr_lo = (mac_addr +
3389 EMAC_REG_EMAC_RX_STAT_AC) >> 2;
3390 dmae->src_addr_hi = 0;
3391 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3392 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3393 dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
3394 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3395 dmae->comp_addr_hi = 0;
3396 dmae->comp_val = 1;
3397
3398 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
3399 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3400 dmae->opcode = opcode;
3401 dmae->src_addr_lo = (mac_addr +
3402 EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
3403 dmae->src_addr_hi = 0;
3404 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003405 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003406 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003407 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003408 dmae->len = 1;
3409 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3410 dmae->comp_addr_hi = 0;
3411 dmae->comp_val = 1;
3412
3413 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
3414 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3415 dmae->opcode = opcode;
3416 dmae->src_addr_lo = (mac_addr +
3417 EMAC_REG_EMAC_TX_STAT_AC) >> 2;
3418 dmae->src_addr_hi = 0;
3419 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003420 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003421 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003422 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003423 dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
3424 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3425 dmae->comp_addr_hi = 0;
3426 dmae->comp_val = 1;
3427 }
3428
3429 /* NIG */
3430 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003431 dmae->opcode = opcode;
3432 dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
3433 NIG_REG_STAT0_BRB_DISCARD) >> 2;
3434 dmae->src_addr_hi = 0;
3435 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
3436 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
3437 dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
3438 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3439 dmae->comp_addr_hi = 0;
3440 dmae->comp_val = 1;
3441
3442 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3443 dmae->opcode = opcode;
3444 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
3445 NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
3446 dmae->src_addr_hi = 0;
3447 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3448 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3449 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3450 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3451 dmae->len = (2*sizeof(u32)) >> 2;
3452 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3453 dmae->comp_addr_hi = 0;
3454 dmae->comp_val = 1;
3455
3456 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003457 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3458 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3459 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3460#ifdef __BIG_ENDIAN
3461 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3462#else
3463 DMAE_CMD_ENDIANITY_DW_SWAP |
3464#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003465 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3466 (vn << DMAE_CMD_E1HVN_SHIFT));
3467 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
3468 NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003469 dmae->src_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003470 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3471 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3472 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3473 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3474 dmae->len = (2*sizeof(u32)) >> 2;
3475 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3476 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3477 dmae->comp_val = DMAE_COMP_VAL;
3478
3479 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003480}
3481
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003482static void bnx2x_func_stats_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003483{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003484 struct dmae_command *dmae = &bp->stats_dmae;
3485 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003486
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003487 /* sanity */
3488 if (!bp->func_stx) {
3489 BNX2X_ERR("BUG!\n");
3490 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003491 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003492
3493 bp->executer_idx = 0;
3494 memset(dmae, 0, sizeof(struct dmae_command));
3495
3496 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3497 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3498 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3499#ifdef __BIG_ENDIAN
3500 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3501#else
3502 DMAE_CMD_ENDIANITY_DW_SWAP |
3503#endif
3504 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3505 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3506 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3507 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3508 dmae->dst_addr_lo = bp->func_stx >> 2;
3509 dmae->dst_addr_hi = 0;
3510 dmae->len = sizeof(struct host_func_stats) >> 2;
3511 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3512 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3513 dmae->comp_val = DMAE_COMP_VAL;
3514
3515 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003516}
3517
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003518static void bnx2x_stats_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003519{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003520 if (bp->port.pmf)
3521 bnx2x_port_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003522
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003523 else if (bp->func_stx)
3524 bnx2x_func_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003525
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003526 bnx2x_hw_stats_post(bp);
3527 bnx2x_storm_stats_post(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003528}
3529
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003530static void bnx2x_stats_pmf_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003531{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003532 bnx2x_stats_comp(bp);
3533 bnx2x_stats_pmf_update(bp);
3534 bnx2x_stats_start(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003535}
3536
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003537static void bnx2x_stats_restart(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003538{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003539 bnx2x_stats_comp(bp);
3540 bnx2x_stats_start(bp);
3541}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003542
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003543static void bnx2x_bmac_stats_update(struct bnx2x *bp)
3544{
3545 struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
3546 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003547 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003548 struct {
3549 u32 lo;
3550 u32 hi;
3551 } diff;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003552
3553 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
3554 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
3555 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
3556 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
3557 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
3558 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003559 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003560 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003561 UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003562 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
3563 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
3564 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
3565 UPDATE_STAT64(tx_stat_gt127,
3566 tx_stat_etherstatspkts65octetsto127octets);
3567 UPDATE_STAT64(tx_stat_gt255,
3568 tx_stat_etherstatspkts128octetsto255octets);
3569 UPDATE_STAT64(tx_stat_gt511,
3570 tx_stat_etherstatspkts256octetsto511octets);
3571 UPDATE_STAT64(tx_stat_gt1023,
3572 tx_stat_etherstatspkts512octetsto1023octets);
3573 UPDATE_STAT64(tx_stat_gt1518,
3574 tx_stat_etherstatspkts1024octetsto1522octets);
3575 UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
3576 UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
3577 UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
3578 UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
3579 UPDATE_STAT64(tx_stat_gterr,
3580 tx_stat_dot3statsinternalmactransmiterrors);
3581 UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003582
3583 estats->pause_frames_received_hi =
3584 pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
3585 estats->pause_frames_received_lo =
3586 pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
3587
3588 estats->pause_frames_sent_hi =
3589 pstats->mac_stx[1].tx_stat_outxoffsent_hi;
3590 estats->pause_frames_sent_lo =
3591 pstats->mac_stx[1].tx_stat_outxoffsent_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003592}
3593
3594static void bnx2x_emac_stats_update(struct bnx2x *bp)
3595{
3596 struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
3597 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003598 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003599
3600 UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
3601 UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
3602 UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
3603 UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
3604 UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
3605 UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
3606 UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
3607 UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
3608 UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
3609 UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
3610 UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
3611 UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
3612 UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
3613 UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
3614 UPDATE_EXTEND_STAT(tx_stat_outxonsent);
3615 UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
3616 UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
3617 UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
3618 UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
3619 UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
3620 UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
3621 UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
3622 UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
3623 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
3624 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
3625 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
3626 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
3627 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
3628 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
3629 UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
3630 UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003631
3632 estats->pause_frames_received_hi =
3633 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
3634 estats->pause_frames_received_lo =
3635 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
3636 ADD_64(estats->pause_frames_received_hi,
3637 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
3638 estats->pause_frames_received_lo,
3639 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
3640
3641 estats->pause_frames_sent_hi =
3642 pstats->mac_stx[1].tx_stat_outxonsent_hi;
3643 estats->pause_frames_sent_lo =
3644 pstats->mac_stx[1].tx_stat_outxonsent_lo;
3645 ADD_64(estats->pause_frames_sent_hi,
3646 pstats->mac_stx[1].tx_stat_outxoffsent_hi,
3647 estats->pause_frames_sent_lo,
3648 pstats->mac_stx[1].tx_stat_outxoffsent_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003649}
3650
3651static int bnx2x_hw_stats_update(struct bnx2x *bp)
3652{
3653 struct nig_stats *new = bnx2x_sp(bp, nig_stats);
3654 struct nig_stats *old = &(bp->port.old_nig_stats);
3655 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
3656 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003657 struct {
3658 u32 lo;
3659 u32 hi;
3660 } diff;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003661 u32 nig_timer_max;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003662
3663 if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
3664 bnx2x_bmac_stats_update(bp);
3665
3666 else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
3667 bnx2x_emac_stats_update(bp);
3668
3669 else { /* unreached */
3670 BNX2X_ERR("stats updated by dmae but no MAC active\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003671 return -1;
3672 }
3673
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003674 ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
3675 new->brb_discard - old->brb_discard);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003676 ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
3677 new->brb_truncate - old->brb_truncate);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003678
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003679 UPDATE_STAT64_NIG(egress_mac_pkt0,
3680 etherstatspkts1024octetsto1522octets);
3681 UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003682
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003683 memcpy(old, new, sizeof(struct nig_stats));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003684
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003685 memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
3686 sizeof(struct mac_stx));
3687 estats->brb_drop_hi = pstats->brb_drop_hi;
3688 estats->brb_drop_lo = pstats->brb_drop_lo;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003689
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003690 pstats->host_port_stats_start = ++pstats->host_port_stats_end;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003691
Eilon Greensteinde832a52009-02-12 08:36:33 +00003692 nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
3693 if (nig_timer_max != estats->nig_timer_max) {
3694 estats->nig_timer_max = nig_timer_max;
3695 BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max);
3696 }
3697
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003698 return 0;
3699}
3700
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003701static int bnx2x_storm_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003702{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003703 struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003704 struct tstorm_per_port_stats *tport =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003705 &stats->tstorm_common.port_statistics;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003706 struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
3707 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003708 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003709
Eilon Greensteinde832a52009-02-12 08:36:33 +00003710 memset(&(fstats->total_bytes_received_hi), 0,
3711 sizeof(struct host_func_stats) - 2*sizeof(u32));
3712 estats->error_bytes_received_hi = 0;
3713 estats->error_bytes_received_lo = 0;
3714 estats->etherstatsoverrsizepkts_hi = 0;
3715 estats->etherstatsoverrsizepkts_lo = 0;
3716 estats->no_buff_discard_hi = 0;
3717 estats->no_buff_discard_lo = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003718
Eilon Greensteinde832a52009-02-12 08:36:33 +00003719 for_each_queue(bp, i) {
3720 struct bnx2x_fastpath *fp = &bp->fp[i];
3721 int cl_id = fp->cl_id;
3722 struct tstorm_per_client_stats *tclient =
3723 &stats->tstorm_common.client_statistics[cl_id];
3724 struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
3725 struct ustorm_per_client_stats *uclient =
3726 &stats->ustorm_common.client_statistics[cl_id];
3727 struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
3728 struct xstorm_per_client_stats *xclient =
3729 &stats->xstorm_common.client_statistics[cl_id];
3730 struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
3731 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
3732 u32 diff;
3733
3734 /* are storm stats valid? */
3735 if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
3736 bp->stats_counter) {
3737 DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
3738 " xstorm counter (%d) != stats_counter (%d)\n",
3739 i, xclient->stats_counter, bp->stats_counter);
3740 return -1;
3741 }
3742 if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
3743 bp->stats_counter) {
3744 DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
3745 " tstorm counter (%d) != stats_counter (%d)\n",
3746 i, tclient->stats_counter, bp->stats_counter);
3747 return -2;
3748 }
3749 if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
3750 bp->stats_counter) {
3751 DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
3752 " ustorm counter (%d) != stats_counter (%d)\n",
3753 i, uclient->stats_counter, bp->stats_counter);
3754 return -4;
3755 }
3756
3757 qstats->total_bytes_received_hi =
3758 qstats->valid_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003759 le32_to_cpu(tclient->total_rcv_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003760 qstats->total_bytes_received_lo =
3761 qstats->valid_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003762 le32_to_cpu(tclient->total_rcv_bytes.lo);
3763
Eilon Greensteinde832a52009-02-12 08:36:33 +00003764 qstats->error_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003765 le32_to_cpu(tclient->rcv_error_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003766 qstats->error_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003767 le32_to_cpu(tclient->rcv_error_bytes.lo);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003768
3769 ADD_64(qstats->total_bytes_received_hi,
3770 qstats->error_bytes_received_hi,
3771 qstats->total_bytes_received_lo,
3772 qstats->error_bytes_received_lo);
3773
3774 UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
3775 total_unicast_packets_received);
3776 UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
3777 total_multicast_packets_received);
3778 UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
3779 total_broadcast_packets_received);
3780 UPDATE_EXTEND_TSTAT(packets_too_big_discard,
3781 etherstatsoverrsizepkts);
3782 UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
3783
3784 SUB_EXTEND_USTAT(ucast_no_buff_pkts,
3785 total_unicast_packets_received);
3786 SUB_EXTEND_USTAT(mcast_no_buff_pkts,
3787 total_multicast_packets_received);
3788 SUB_EXTEND_USTAT(bcast_no_buff_pkts,
3789 total_broadcast_packets_received);
3790 UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
3791 UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
3792 UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
3793
3794 qstats->total_bytes_transmitted_hi =
3795 le32_to_cpu(xclient->total_sent_bytes.hi);
3796 qstats->total_bytes_transmitted_lo =
3797 le32_to_cpu(xclient->total_sent_bytes.lo);
3798
3799 UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
3800 total_unicast_packets_transmitted);
3801 UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
3802 total_multicast_packets_transmitted);
3803 UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
3804 total_broadcast_packets_transmitted);
3805
3806 old_tclient->checksum_discard = tclient->checksum_discard;
3807 old_tclient->ttl0_discard = tclient->ttl0_discard;
3808
3809 ADD_64(fstats->total_bytes_received_hi,
3810 qstats->total_bytes_received_hi,
3811 fstats->total_bytes_received_lo,
3812 qstats->total_bytes_received_lo);
3813 ADD_64(fstats->total_bytes_transmitted_hi,
3814 qstats->total_bytes_transmitted_hi,
3815 fstats->total_bytes_transmitted_lo,
3816 qstats->total_bytes_transmitted_lo);
3817 ADD_64(fstats->total_unicast_packets_received_hi,
3818 qstats->total_unicast_packets_received_hi,
3819 fstats->total_unicast_packets_received_lo,
3820 qstats->total_unicast_packets_received_lo);
3821 ADD_64(fstats->total_multicast_packets_received_hi,
3822 qstats->total_multicast_packets_received_hi,
3823 fstats->total_multicast_packets_received_lo,
3824 qstats->total_multicast_packets_received_lo);
3825 ADD_64(fstats->total_broadcast_packets_received_hi,
3826 qstats->total_broadcast_packets_received_hi,
3827 fstats->total_broadcast_packets_received_lo,
3828 qstats->total_broadcast_packets_received_lo);
3829 ADD_64(fstats->total_unicast_packets_transmitted_hi,
3830 qstats->total_unicast_packets_transmitted_hi,
3831 fstats->total_unicast_packets_transmitted_lo,
3832 qstats->total_unicast_packets_transmitted_lo);
3833 ADD_64(fstats->total_multicast_packets_transmitted_hi,
3834 qstats->total_multicast_packets_transmitted_hi,
3835 fstats->total_multicast_packets_transmitted_lo,
3836 qstats->total_multicast_packets_transmitted_lo);
3837 ADD_64(fstats->total_broadcast_packets_transmitted_hi,
3838 qstats->total_broadcast_packets_transmitted_hi,
3839 fstats->total_broadcast_packets_transmitted_lo,
3840 qstats->total_broadcast_packets_transmitted_lo);
3841 ADD_64(fstats->valid_bytes_received_hi,
3842 qstats->valid_bytes_received_hi,
3843 fstats->valid_bytes_received_lo,
3844 qstats->valid_bytes_received_lo);
3845
3846 ADD_64(estats->error_bytes_received_hi,
3847 qstats->error_bytes_received_hi,
3848 estats->error_bytes_received_lo,
3849 qstats->error_bytes_received_lo);
3850 ADD_64(estats->etherstatsoverrsizepkts_hi,
3851 qstats->etherstatsoverrsizepkts_hi,
3852 estats->etherstatsoverrsizepkts_lo,
3853 qstats->etherstatsoverrsizepkts_lo);
3854 ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
3855 estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
3856 }
3857
3858 ADD_64(fstats->total_bytes_received_hi,
3859 estats->rx_stat_ifhcinbadoctets_hi,
3860 fstats->total_bytes_received_lo,
3861 estats->rx_stat_ifhcinbadoctets_lo);
3862
3863 memcpy(estats, &(fstats->total_bytes_received_hi),
3864 sizeof(struct host_func_stats) - 2*sizeof(u32));
3865
3866 ADD_64(estats->etherstatsoverrsizepkts_hi,
3867 estats->rx_stat_dot3statsframestoolong_hi,
3868 estats->etherstatsoverrsizepkts_lo,
3869 estats->rx_stat_dot3statsframestoolong_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003870 ADD_64(estats->error_bytes_received_hi,
3871 estats->rx_stat_ifhcinbadoctets_hi,
3872 estats->error_bytes_received_lo,
3873 estats->rx_stat_ifhcinbadoctets_lo);
3874
Eilon Greensteinde832a52009-02-12 08:36:33 +00003875 if (bp->port.pmf) {
3876 estats->mac_filter_discard =
3877 le32_to_cpu(tport->mac_filter_discard);
3878 estats->xxoverflow_discard =
3879 le32_to_cpu(tport->xxoverflow_discard);
3880 estats->brb_truncate_discard =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003881 le32_to_cpu(tport->brb_truncate_discard);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003882 estats->mac_discard = le32_to_cpu(tport->mac_discard);
3883 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003884
3885 fstats->host_func_stats_start = ++fstats->host_func_stats_end;
3886
Eilon Greensteinde832a52009-02-12 08:36:33 +00003887 bp->stats_pending = 0;
3888
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003889 return 0;
3890}
3891
3892static void bnx2x_net_stats_update(struct bnx2x *bp)
3893{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003894 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003895 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003896 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003897
3898 nstats->rx_packets =
3899 bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
3900 bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
3901 bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
3902
3903 nstats->tx_packets =
3904 bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
3905 bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
3906 bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
3907
Eilon Greensteinde832a52009-02-12 08:36:33 +00003908 nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003909
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003910 nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003911
Eilon Greensteinde832a52009-02-12 08:36:33 +00003912 nstats->rx_dropped = estats->mac_discard;
3913 for_each_queue(bp, i)
3914 nstats->rx_dropped +=
3915 le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
3916
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003917 nstats->tx_dropped = 0;
3918
3919 nstats->multicast =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003920 bnx2x_hilo(&estats->total_multicast_packets_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003921
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003922 nstats->collisions =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003923 bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003924
3925 nstats->rx_length_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003926 bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
3927 bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
3928 nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
3929 bnx2x_hilo(&estats->brb_truncate_hi);
3930 nstats->rx_crc_errors =
3931 bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
3932 nstats->rx_frame_errors =
3933 bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
3934 nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003935 nstats->rx_missed_errors = estats->xxoverflow_discard;
3936
3937 nstats->rx_errors = nstats->rx_length_errors +
3938 nstats->rx_over_errors +
3939 nstats->rx_crc_errors +
3940 nstats->rx_frame_errors +
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003941 nstats->rx_fifo_errors +
3942 nstats->rx_missed_errors;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003943
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003944 nstats->tx_aborted_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003945 bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
3946 bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
3947 nstats->tx_carrier_errors =
3948 bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003949 nstats->tx_fifo_errors = 0;
3950 nstats->tx_heartbeat_errors = 0;
3951 nstats->tx_window_errors = 0;
3952
3953 nstats->tx_errors = nstats->tx_aborted_errors +
Eilon Greensteinde832a52009-02-12 08:36:33 +00003954 nstats->tx_carrier_errors +
3955 bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
3956}
3957
3958static void bnx2x_drv_stats_update(struct bnx2x *bp)
3959{
3960 struct bnx2x_eth_stats *estats = &bp->eth_stats;
3961 int i;
3962
3963 estats->driver_xoff = 0;
3964 estats->rx_err_discard_pkt = 0;
3965 estats->rx_skb_alloc_failed = 0;
3966 estats->hw_csum_err = 0;
3967 for_each_queue(bp, i) {
3968 struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
3969
3970 estats->driver_xoff += qstats->driver_xoff;
3971 estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
3972 estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
3973 estats->hw_csum_err += qstats->hw_csum_err;
3974 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003975}
3976
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003977static void bnx2x_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003978{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003979 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003980
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003981 if (*stats_comp != DMAE_COMP_VAL)
3982 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003983
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003984 if (bp->port.pmf)
Eilon Greensteinde832a52009-02-12 08:36:33 +00003985 bnx2x_hw_stats_update(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003986
Eilon Greensteinde832a52009-02-12 08:36:33 +00003987 if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
3988 BNX2X_ERR("storm stats were not updated for 3 times\n");
3989 bnx2x_panic();
3990 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003991 }
3992
Eilon Greensteinde832a52009-02-12 08:36:33 +00003993 bnx2x_net_stats_update(bp);
3994 bnx2x_drv_stats_update(bp);
3995
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003996 if (bp->msglevel & NETIF_MSG_TIMER) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00003997 struct tstorm_per_client_stats *old_tclient =
3998 &bp->fp->old_tclient;
3999 struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004000 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004001 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004002 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004003
4004 printk(KERN_DEBUG "%s:\n", bp->dev->name);
4005 printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)"
4006 " tx pkt (%lx)\n",
4007 bnx2x_tx_avail(bp->fp),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004008 le16_to_cpu(*bp->fp->tx_cons_sb), nstats->tx_packets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004009 printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)"
4010 " rx pkt (%lx)\n",
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004011 (u16)(le16_to_cpu(*bp->fp->rx_cons_sb) -
4012 bp->fp->rx_comp_cons),
4013 le16_to_cpu(*bp->fp->rx_cons_sb), nstats->rx_packets);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004014 printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u "
4015 "brb truncate %u\n",
4016 (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"),
4017 qstats->driver_xoff,
4018 estats->brb_drop_lo, estats->brb_truncate_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004019 printk(KERN_DEBUG "tstats: checksum_discard %u "
Eilon Greensteinde832a52009-02-12 08:36:33 +00004020 "packets_too_big_discard %lu no_buff_discard %lu "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004021 "mac_discard %u mac_filter_discard %u "
4022 "xxovrflow_discard %u brb_truncate_discard %u "
4023 "ttl0_discard %u\n",
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00004024 le32_to_cpu(old_tclient->checksum_discard),
Eilon Greensteinde832a52009-02-12 08:36:33 +00004025 bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi),
4026 bnx2x_hilo(&qstats->no_buff_discard_hi),
4027 estats->mac_discard, estats->mac_filter_discard,
4028 estats->xxoverflow_discard, estats->brb_truncate_discard,
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00004029 le32_to_cpu(old_tclient->ttl0_discard));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004030
4031 for_each_queue(bp, i) {
4032 printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i,
4033 bnx2x_fp(bp, i, tx_pkt),
4034 bnx2x_fp(bp, i, rx_pkt),
4035 bnx2x_fp(bp, i, rx_calls));
4036 }
4037 }
4038
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004039 bnx2x_hw_stats_post(bp);
4040 bnx2x_storm_stats_post(bp);
4041}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004042
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004043static void bnx2x_port_stats_stop(struct bnx2x *bp)
4044{
4045 struct dmae_command *dmae;
4046 u32 opcode;
4047 int loader_idx = PMF_DMAE_C(bp);
4048 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004049
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004050 bp->executer_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004051
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004052 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
4053 DMAE_CMD_C_ENABLE |
4054 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004055#ifdef __BIG_ENDIAN
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004056 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004057#else
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004058 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004059#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004060 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
4061 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
4062
4063 if (bp->port.port_stx) {
4064
4065 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4066 if (bp->func_stx)
4067 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
4068 else
4069 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4070 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
4071 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
4072 dmae->dst_addr_lo = bp->port.port_stx >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004073 dmae->dst_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004074 dmae->len = sizeof(struct host_port_stats) >> 2;
4075 if (bp->func_stx) {
4076 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
4077 dmae->comp_addr_hi = 0;
4078 dmae->comp_val = 1;
4079 } else {
4080 dmae->comp_addr_lo =
4081 U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4082 dmae->comp_addr_hi =
4083 U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4084 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004085
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004086 *stats_comp = 0;
4087 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004088 }
4089
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004090 if (bp->func_stx) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004091
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004092 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4093 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4094 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
4095 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
4096 dmae->dst_addr_lo = bp->func_stx >> 2;
4097 dmae->dst_addr_hi = 0;
4098 dmae->len = sizeof(struct host_func_stats) >> 2;
4099 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4100 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4101 dmae->comp_val = DMAE_COMP_VAL;
4102
4103 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004104 }
4105}
4106
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004107static void bnx2x_stats_stop(struct bnx2x *bp)
4108{
4109 int update = 0;
4110
4111 bnx2x_stats_comp(bp);
4112
4113 if (bp->port.pmf)
4114 update = (bnx2x_hw_stats_update(bp) == 0);
4115
4116 update |= (bnx2x_storm_stats_update(bp) == 0);
4117
4118 if (update) {
4119 bnx2x_net_stats_update(bp);
4120
4121 if (bp->port.pmf)
4122 bnx2x_port_stats_stop(bp);
4123
4124 bnx2x_hw_stats_post(bp);
4125 bnx2x_stats_comp(bp);
4126 }
4127}
4128
4129static void bnx2x_stats_do_nothing(struct bnx2x *bp)
4130{
4131}
4132
4133static const struct {
4134 void (*action)(struct bnx2x *bp);
4135 enum bnx2x_stats_state next_state;
4136} bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
4137/* state event */
4138{
4139/* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
4140/* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
4141/* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
4142/* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
4143},
4144{
4145/* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
4146/* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
4147/* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
4148/* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
4149}
4150};
4151
4152static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
4153{
4154 enum bnx2x_stats_state state = bp->stats_state;
4155
4156 bnx2x_stats_stm[state][event].action(bp);
4157 bp->stats_state = bnx2x_stats_stm[state][event].next_state;
4158
4159 if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER))
4160 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
4161 state, event, bp->stats_state);
4162}
4163
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004164static void bnx2x_timer(unsigned long data)
4165{
4166 struct bnx2x *bp = (struct bnx2x *) data;
4167
4168 if (!netif_running(bp->dev))
4169 return;
4170
4171 if (atomic_read(&bp->intr_sem) != 0)
Eliezer Tamirf1410642008-02-28 11:51:50 -08004172 goto timer_restart;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004173
4174 if (poll) {
4175 struct bnx2x_fastpath *fp = &bp->fp[0];
4176 int rc;
4177
Eilon Greenstein7961f792009-03-02 07:59:31 +00004178 bnx2x_tx_int(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004179 rc = bnx2x_rx_int(fp, 1000);
4180 }
4181
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004182 if (!BP_NOMCP(bp)) {
4183 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004184 u32 drv_pulse;
4185 u32 mcp_pulse;
4186
4187 ++bp->fw_drv_pulse_wr_seq;
4188 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4189 /* TBD - add SYSTEM_TIME */
4190 drv_pulse = bp->fw_drv_pulse_wr_seq;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004191 SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004192
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004193 mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004194 MCP_PULSE_SEQ_MASK);
4195 /* The delta between driver pulse and mcp response
4196 * should be 1 (before mcp response) or 0 (after mcp response)
4197 */
4198 if ((drv_pulse != mcp_pulse) &&
4199 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4200 /* someone lost a heartbeat... */
4201 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4202 drv_pulse, mcp_pulse);
4203 }
4204 }
4205
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004206 if ((bp->state == BNX2X_STATE_OPEN) ||
4207 (bp->state == BNX2X_STATE_DISABLED))
4208 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004209
Eliezer Tamirf1410642008-02-28 11:51:50 -08004210timer_restart:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004211 mod_timer(&bp->timer, jiffies + bp->current_interval);
4212}
4213
4214/* end of Statistics */
4215
4216/* nic init */
4217
4218/*
4219 * nic init service functions
4220 */
4221
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004222static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004223{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004224 int port = BP_PORT(bp);
4225
4226 bnx2x_init_fill(bp, BAR_USTRORM_INTMEM +
4227 USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
Yitchak Gertner35302982008-08-13 15:53:12 -07004228 sizeof(struct ustorm_status_block)/4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004229 bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM +
4230 CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
Yitchak Gertner35302982008-08-13 15:53:12 -07004231 sizeof(struct cstorm_status_block)/4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004232}
4233
Eilon Greenstein5c862842008-08-13 15:51:48 -07004234static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
4235 dma_addr_t mapping, int sb_id)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004236{
4237 int port = BP_PORT(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004238 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004239 int index;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004240 u64 section;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004241
4242 /* USTORM */
4243 section = ((u64)mapping) + offsetof(struct host_status_block,
4244 u_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004245 sb->u_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004246
4247 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004248 USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004249 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004250 ((USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004251 U64_HI(section));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004252 REG_WR8(bp, BAR_USTRORM_INTMEM + FP_USB_FUNC_OFF +
4253 USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004254
4255 for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
4256 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004257 USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004258
4259 /* CSTORM */
4260 section = ((u64)mapping) + offsetof(struct host_status_block,
4261 c_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004262 sb->c_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004263
4264 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004265 CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004266 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004267 ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004268 U64_HI(section));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004269 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
4270 CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004271
4272 for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
4273 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004274 CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004275
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004276 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
4277}
4278
4279static void bnx2x_zero_def_sb(struct bnx2x *bp)
4280{
4281 int func = BP_FUNC(bp);
4282
4283 bnx2x_init_fill(bp, BAR_USTRORM_INTMEM +
4284 USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4285 sizeof(struct ustorm_def_status_block)/4);
4286 bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM +
4287 CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4288 sizeof(struct cstorm_def_status_block)/4);
4289 bnx2x_init_fill(bp, BAR_XSTRORM_INTMEM +
4290 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4291 sizeof(struct xstorm_def_status_block)/4);
4292 bnx2x_init_fill(bp, BAR_TSTRORM_INTMEM +
4293 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4294 sizeof(struct tstorm_def_status_block)/4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004295}
4296
4297static void bnx2x_init_def_sb(struct bnx2x *bp,
4298 struct host_def_status_block *def_sb,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004299 dma_addr_t mapping, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004300{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004301 int port = BP_PORT(bp);
4302 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004303 int index, val, reg_offset;
4304 u64 section;
4305
4306 /* ATTN */
4307 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4308 atten_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004309 def_sb->atten_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004310
Eliezer Tamir49d66772008-02-28 11:53:13 -08004311 bp->attn_state = 0;
4312
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004313 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4314 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4315
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004316 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004317 bp->attn_group[index].sig[0] = REG_RD(bp,
4318 reg_offset + 0x10*index);
4319 bp->attn_group[index].sig[1] = REG_RD(bp,
4320 reg_offset + 0x4 + 0x10*index);
4321 bp->attn_group[index].sig[2] = REG_RD(bp,
4322 reg_offset + 0x8 + 0x10*index);
4323 bp->attn_group[index].sig[3] = REG_RD(bp,
4324 reg_offset + 0xc + 0x10*index);
4325 }
4326
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004327 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4328 HC_REG_ATTN_MSG0_ADDR_L);
4329
4330 REG_WR(bp, reg_offset, U64_LO(section));
4331 REG_WR(bp, reg_offset + 4, U64_HI(section));
4332
4333 reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
4334
4335 val = REG_RD(bp, reg_offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004336 val |= sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004337 REG_WR(bp, reg_offset, val);
4338
4339 /* USTORM */
4340 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4341 u_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004342 def_sb->u_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004343
4344 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004345 USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004346 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004347 ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004348 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004349 REG_WR8(bp, BAR_USTRORM_INTMEM + DEF_USB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004350 USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004351
4352 for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
4353 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004354 USTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004355
4356 /* CSTORM */
4357 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4358 c_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004359 def_sb->c_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004360
4361 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004362 CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004363 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004364 ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004365 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004366 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004367 CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004368
4369 for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
4370 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004371 CSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004372
4373 /* TSTORM */
4374 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4375 t_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004376 def_sb->t_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004377
4378 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004379 TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004380 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004381 ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004382 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004383 REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004384 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004385
4386 for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
4387 REG_WR16(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004388 TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004389
4390 /* XSTORM */
4391 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4392 x_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004393 def_sb->x_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004394
4395 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004396 XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004397 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004398 ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004399 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004400 REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004401 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004402
4403 for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
4404 REG_WR16(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004405 XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004406
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004407 bp->stats_pending = 0;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004408 bp->set_mac_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004409
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004410 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004411}
4412
4413static void bnx2x_update_coalesce(struct bnx2x *bp)
4414{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004415 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004416 int i;
4417
4418 for_each_queue(bp, i) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004419 int sb_id = bp->fp[i].sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004420
4421 /* HC_INDEX_U_ETH_RX_CQ_CONS */
4422 REG_WR8(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004423 USTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004424 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004425 bp->rx_ticks/12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004426 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004427 USTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004428 U_SB_ETH_RX_CQ_INDEX),
4429 bp->rx_ticks ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004430
4431 /* HC_INDEX_C_ETH_TX_CQ_CONS */
4432 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004433 CSTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004434 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004435 bp->tx_ticks/12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004436 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004437 CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004438 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004439 bp->tx_ticks ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004440 }
4441}
4442
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004443static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
4444 struct bnx2x_fastpath *fp, int last)
4445{
4446 int i;
4447
4448 for (i = 0; i < last; i++) {
4449 struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
4450 struct sk_buff *skb = rx_buf->skb;
4451
4452 if (skb == NULL) {
4453 DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
4454 continue;
4455 }
4456
4457 if (fp->tpa_state[i] == BNX2X_TPA_START)
4458 pci_unmap_single(bp->pdev,
4459 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein356e2382009-02-12 08:38:32 +00004460 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004461
4462 dev_kfree_skb(skb);
4463 rx_buf->skb = NULL;
4464 }
4465}
4466
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004467static void bnx2x_init_rx_rings(struct bnx2x *bp)
4468{
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004469 int func = BP_FUNC(bp);
Eilon Greenstein32626232008-08-13 15:51:07 -07004470 int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
4471 ETH_MAX_AGGREGATION_QUEUES_E1H;
4472 u16 ring_prod, cqe_ring_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004473 int i, j;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004474
Eilon Greenstein87942b42009-02-12 08:36:49 +00004475 bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN;
Eilon Greenstein0f008462009-02-12 08:36:18 +00004476 DP(NETIF_MSG_IFUP,
4477 "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004478
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004479 if (bp->flags & TPA_ENABLE_FLAG) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004480
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004481 for_each_rx_queue(bp, j) {
Eilon Greenstein32626232008-08-13 15:51:07 -07004482 struct bnx2x_fastpath *fp = &bp->fp[j];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004483
Eilon Greenstein32626232008-08-13 15:51:07 -07004484 for (i = 0; i < max_agg_queues; i++) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004485 fp->tpa_pool[i].skb =
4486 netdev_alloc_skb(bp->dev, bp->rx_buf_size);
4487 if (!fp->tpa_pool[i].skb) {
4488 BNX2X_ERR("Failed to allocate TPA "
4489 "skb pool for queue[%d] - "
4490 "disabling TPA on this "
4491 "queue!\n", j);
4492 bnx2x_free_tpa_pool(bp, fp, i);
4493 fp->disable_tpa = 1;
4494 break;
4495 }
4496 pci_unmap_addr_set((struct sw_rx_bd *)
4497 &bp->fp->tpa_pool[i],
4498 mapping, 0);
4499 fp->tpa_state[i] = BNX2X_TPA_STOP;
4500 }
4501 }
4502 }
4503
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004504 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004505 struct bnx2x_fastpath *fp = &bp->fp[j];
4506
4507 fp->rx_bd_cons = 0;
4508 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004509 fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004510
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004511 /* "next page" elements initialization */
4512 /* SGE ring */
4513 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
4514 struct eth_rx_sge *sge;
4515
4516 sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
4517 sge->addr_hi =
4518 cpu_to_le32(U64_HI(fp->rx_sge_mapping +
4519 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
4520 sge->addr_lo =
4521 cpu_to_le32(U64_LO(fp->rx_sge_mapping +
4522 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
4523 }
4524
4525 bnx2x_init_sge_ring_bit_mask(fp);
4526
4527 /* RX BD ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004528 for (i = 1; i <= NUM_RX_RINGS; i++) {
4529 struct eth_rx_bd *rx_bd;
4530
4531 rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
4532 rx_bd->addr_hi =
4533 cpu_to_le32(U64_HI(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004534 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004535 rx_bd->addr_lo =
4536 cpu_to_le32(U64_LO(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004537 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004538 }
4539
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004540 /* CQ ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004541 for (i = 1; i <= NUM_RCQ_RINGS; i++) {
4542 struct eth_rx_cqe_next_page *nextpg;
4543
4544 nextpg = (struct eth_rx_cqe_next_page *)
4545 &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
4546 nextpg->addr_hi =
4547 cpu_to_le32(U64_HI(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004548 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004549 nextpg->addr_lo =
4550 cpu_to_le32(U64_LO(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004551 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004552 }
4553
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004554 /* Allocate SGEs and initialize the ring elements */
4555 for (i = 0, ring_prod = 0;
4556 i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004557
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004558 if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
4559 BNX2X_ERR("was only able to allocate "
4560 "%d rx sges\n", i);
4561 BNX2X_ERR("disabling TPA for queue[%d]\n", j);
4562 /* Cleanup already allocated elements */
4563 bnx2x_free_rx_sge_range(bp, fp, ring_prod);
Eilon Greenstein32626232008-08-13 15:51:07 -07004564 bnx2x_free_tpa_pool(bp, fp, max_agg_queues);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004565 fp->disable_tpa = 1;
4566 ring_prod = 0;
4567 break;
4568 }
4569 ring_prod = NEXT_SGE_IDX(ring_prod);
4570 }
4571 fp->rx_sge_prod = ring_prod;
4572
4573 /* Allocate BDs and initialize BD ring */
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004574 fp->rx_comp_cons = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004575 cqe_ring_prod = ring_prod = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004576 for (i = 0; i < bp->rx_ring_size; i++) {
4577 if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) {
4578 BNX2X_ERR("was only able to allocate "
Eilon Greensteinde832a52009-02-12 08:36:33 +00004579 "%d rx skbs on queue[%d]\n", i, j);
4580 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004581 break;
4582 }
4583 ring_prod = NEXT_RX_IDX(ring_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004584 cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
Ilpo Järvinen53e5e962008-07-25 21:40:45 -07004585 WARN_ON(ring_prod <= i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004586 }
4587
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004588 fp->rx_bd_prod = ring_prod;
4589 /* must not have more available CQEs than BDs */
4590 fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT),
4591 cqe_ring_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004592 fp->rx_pkt = fp->rx_calls = 0;
4593
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004594 /* Warning!
4595 * this will generate an interrupt (to the TSTORM)
4596 * must only be done after chip is initialized
4597 */
4598 bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod,
4599 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004600 if (j != 0)
4601 continue;
4602
4603 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004604 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004605 U64_LO(fp->rx_comp_mapping));
4606 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004607 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004608 U64_HI(fp->rx_comp_mapping));
4609 }
4610}
4611
4612static void bnx2x_init_tx_ring(struct bnx2x *bp)
4613{
4614 int i, j;
4615
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004616 for_each_tx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004617 struct bnx2x_fastpath *fp = &bp->fp[j];
4618
4619 for (i = 1; i <= NUM_TX_RINGS; i++) {
4620 struct eth_tx_bd *tx_bd =
4621 &fp->tx_desc_ring[TX_DESC_CNT * i - 1];
4622
4623 tx_bd->addr_hi =
4624 cpu_to_le32(U64_HI(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004625 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004626 tx_bd->addr_lo =
4627 cpu_to_le32(U64_LO(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004628 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004629 }
4630
4631 fp->tx_pkt_prod = 0;
4632 fp->tx_pkt_cons = 0;
4633 fp->tx_bd_prod = 0;
4634 fp->tx_bd_cons = 0;
4635 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
4636 fp->tx_pkt = 0;
4637 }
4638}
4639
4640static void bnx2x_init_sp_ring(struct bnx2x *bp)
4641{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004642 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004643
4644 spin_lock_init(&bp->spq_lock);
4645
4646 bp->spq_left = MAX_SPQ_PENDING;
4647 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004648 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4649 bp->spq_prod_bd = bp->spq;
4650 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4651
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004652 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004653 U64_LO(bp->spq_mapping));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004654 REG_WR(bp,
4655 XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004656 U64_HI(bp->spq_mapping));
4657
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004658 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004659 bp->spq_prod_idx);
4660}
4661
4662static void bnx2x_init_context(struct bnx2x *bp)
4663{
4664 int i;
4665
4666 for_each_queue(bp, i) {
4667 struct eth_context *context = bnx2x_sp(bp, context[i].eth);
4668 struct bnx2x_fastpath *fp = &bp->fp[i];
Eilon Greensteinde832a52009-02-12 08:36:33 +00004669 u8 cl_id = fp->cl_id;
Eilon Greenstein0626b892009-02-12 08:38:14 +00004670 u8 sb_id = fp->sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004671
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004672 context->ustorm_st_context.common.sb_index_numbers =
4673 BNX2X_RX_SB_INDEX_NUM;
Eilon Greenstein0626b892009-02-12 08:38:14 +00004674 context->ustorm_st_context.common.clientId = cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004675 context->ustorm_st_context.common.status_block_id = sb_id;
4676 context->ustorm_st_context.common.flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004677 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
4678 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
4679 context->ustorm_st_context.common.statistics_counter_id =
4680 cl_id;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004681 context->ustorm_st_context.common.mc_alignment_log_size =
Eilon Greenstein0f008462009-02-12 08:36:18 +00004682 BNX2X_RX_ALIGN_SHIFT;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004683 context->ustorm_st_context.common.bd_buff_size =
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07004684 bp->rx_buf_size;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004685 context->ustorm_st_context.common.bd_page_base_hi =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004686 U64_HI(fp->rx_desc_mapping);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004687 context->ustorm_st_context.common.bd_page_base_lo =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004688 U64_LO(fp->rx_desc_mapping);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004689 if (!fp->disable_tpa) {
4690 context->ustorm_st_context.common.flags |=
4691 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA |
4692 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_SGE_RING);
4693 context->ustorm_st_context.common.sge_buff_size =
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004694 (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE,
4695 (u32)0xffff);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004696 context->ustorm_st_context.common.sge_page_base_hi =
4697 U64_HI(fp->rx_sge_mapping);
4698 context->ustorm_st_context.common.sge_page_base_lo =
4699 U64_LO(fp->rx_sge_mapping);
4700 }
4701
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004702 context->ustorm_ag_context.cdu_usage =
4703 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4704 CDU_REGION_NUMBER_UCM_AG,
4705 ETH_CONNECTION_TYPE);
4706
4707 context->xstorm_st_context.tx_bd_page_base_hi =
4708 U64_HI(fp->tx_desc_mapping);
4709 context->xstorm_st_context.tx_bd_page_base_lo =
4710 U64_LO(fp->tx_desc_mapping);
4711 context->xstorm_st_context.db_data_addr_hi =
4712 U64_HI(fp->tx_prods_mapping);
4713 context->xstorm_st_context.db_data_addr_lo =
4714 U64_LO(fp->tx_prods_mapping);
Eilon Greenstein0626b892009-02-12 08:38:14 +00004715 context->xstorm_st_context.statistics_data = (cl_id |
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004716 XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004717 context->cstorm_st_context.sb_index_number =
Eilon Greenstein5c862842008-08-13 15:51:48 -07004718 C_SB_ETH_TX_CQ_INDEX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004719 context->cstorm_st_context.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004720
4721 context->xstorm_ag_context.cdu_reserved =
4722 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4723 CDU_REGION_NUMBER_XCM_AG,
4724 ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004725 }
4726}
4727
4728static void bnx2x_init_ind_table(struct bnx2x *bp)
4729{
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004730 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004731 int i;
4732
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004733 if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004734 return;
4735
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004736 DP(NETIF_MSG_IFUP,
4737 "Initializing indirection table multi_mode %d\n", bp->multi_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004738 for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004739 REG_WR8(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004740 TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
Eilon Greenstein0626b892009-02-12 08:38:14 +00004741 bp->fp->cl_id + (i % bp->num_rx_queues));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004742}
4743
Eliezer Tamir49d66772008-02-28 11:53:13 -08004744static void bnx2x_set_client_config(struct bnx2x *bp)
4745{
Eliezer Tamir49d66772008-02-28 11:53:13 -08004746 struct tstorm_eth_client_config tstorm_client = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004747 int port = BP_PORT(bp);
4748 int i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004749
Eilon Greensteine7799c52009-01-14 21:30:27 -08004750 tstorm_client.mtu = bp->dev->mtu;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004751 tstorm_client.config_flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004752 (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
4753 TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004754#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08004755 if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
Eliezer Tamir49d66772008-02-28 11:53:13 -08004756 tstorm_client.config_flags |=
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004757 TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004758 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
4759 }
4760#endif
Eliezer Tamir49d66772008-02-28 11:53:13 -08004761
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004762 if (bp->flags & TPA_ENABLE_FLAG) {
4763 tstorm_client.max_sges_for_packet =
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08004764 SGE_PAGE_ALIGN(tstorm_client.mtu) >> SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004765 tstorm_client.max_sges_for_packet =
4766 ((tstorm_client.max_sges_for_packet +
4767 PAGES_PER_SGE - 1) & (~(PAGES_PER_SGE - 1))) >>
4768 PAGES_PER_SGE_SHIFT;
4769
4770 tstorm_client.config_flags |=
4771 TSTORM_ETH_CLIENT_CONFIG_ENABLE_SGE_RING;
4772 }
4773
Eliezer Tamir49d66772008-02-28 11:53:13 -08004774 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00004775 tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
4776
Eliezer Tamir49d66772008-02-28 11:53:13 -08004777 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004778 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
Eliezer Tamir49d66772008-02-28 11:53:13 -08004779 ((u32 *)&tstorm_client)[0]);
4780 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004781 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
Eliezer Tamir49d66772008-02-28 11:53:13 -08004782 ((u32 *)&tstorm_client)[1]);
4783 }
4784
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004785 DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
4786 ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004787}
4788
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004789static void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4790{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004791 struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004792 int mode = bp->rx_mode;
4793 int mask = (1 << BP_L_ID(bp));
4794 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004795 int i;
4796
Eilon Greenstein3196a882008-08-13 15:58:49 -07004797 DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004798
4799 switch (mode) {
4800 case BNX2X_RX_MODE_NONE: /* no Rx */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004801 tstorm_mac_filter.ucast_drop_all = mask;
4802 tstorm_mac_filter.mcast_drop_all = mask;
4803 tstorm_mac_filter.bcast_drop_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004804 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004805
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004806 case BNX2X_RX_MODE_NORMAL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004807 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004808 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004809
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004810 case BNX2X_RX_MODE_ALLMULTI:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004811 tstorm_mac_filter.mcast_accept_all = mask;
4812 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004813 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004814
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004815 case BNX2X_RX_MODE_PROMISC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004816 tstorm_mac_filter.ucast_accept_all = mask;
4817 tstorm_mac_filter.mcast_accept_all = mask;
4818 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004819 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004820
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004821 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004822 BNX2X_ERR("BAD rx mode (%d)\n", mode);
4823 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004824 }
4825
4826 for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
4827 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004828 TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004829 ((u32 *)&tstorm_mac_filter)[i]);
4830
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004831/* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004832 ((u32 *)&tstorm_mac_filter)[i]); */
4833 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004834
Eliezer Tamir49d66772008-02-28 11:53:13 -08004835 if (mode != BNX2X_RX_MODE_NONE)
4836 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004837}
4838
Eilon Greenstein471de712008-08-13 15:49:35 -07004839static void bnx2x_init_internal_common(struct bnx2x *bp)
4840{
4841 int i;
4842
Yitchak Gertner3cdf1db2008-08-25 15:24:21 -07004843 if (bp->flags & TPA_ENABLE_FLAG) {
4844 struct tstorm_eth_tpa_exist tpa = {0};
4845
4846 tpa.tpa_exist = 1;
4847
4848 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET,
4849 ((u32 *)&tpa)[0]);
4850 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET + 4,
4851 ((u32 *)&tpa)[1]);
4852 }
4853
Eilon Greenstein471de712008-08-13 15:49:35 -07004854 /* Zero this manually as its initialization is
4855 currently missing in the initTool */
4856 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4857 REG_WR(bp, BAR_USTRORM_INTMEM +
4858 USTORM_AGG_DATA_OFFSET + i * 4, 0);
4859}
4860
4861static void bnx2x_init_internal_port(struct bnx2x *bp)
4862{
4863 int port = BP_PORT(bp);
4864
4865 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4866 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4867 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4868 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4869}
4870
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004871/* Calculates the sum of vn_min_rates.
4872 It's needed for further normalizing of the min_rates.
4873 Returns:
4874 sum of vn_min_rates.
4875 or
4876 0 - if all the min_rates are 0.
4877 In the later case fainess algorithm should be deactivated.
4878 If not all min_rates are zero then those that are zeroes will be set to 1.
4879 */
4880static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
4881{
4882 int all_zero = 1;
4883 int port = BP_PORT(bp);
4884 int vn;
4885
4886 bp->vn_weight_sum = 0;
4887 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
4888 int func = 2*vn + port;
4889 u32 vn_cfg =
4890 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
4891 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
4892 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
4893
4894 /* Skip hidden vns */
4895 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
4896 continue;
4897
4898 /* If min rate is zero - set it to 1 */
4899 if (!vn_min_rate)
4900 vn_min_rate = DEF_MIN_RATE;
4901 else
4902 all_zero = 0;
4903
4904 bp->vn_weight_sum += vn_min_rate;
4905 }
4906
4907 /* ... only if all min rates are zeros - disable fairness */
4908 if (all_zero)
4909 bp->vn_weight_sum = 0;
4910}
4911
Eilon Greenstein471de712008-08-13 15:49:35 -07004912static void bnx2x_init_internal_func(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004913{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004914 struct tstorm_eth_function_common_config tstorm_config = {0};
4915 struct stats_indication_flags stats_flags = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004916 int port = BP_PORT(bp);
4917 int func = BP_FUNC(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004918 int i, j;
4919 u32 offset;
Eilon Greenstein471de712008-08-13 15:49:35 -07004920 u16 max_agg_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004921
4922 if (is_multi(bp)) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004923 tstorm_config.config_flags = MULTI_FLAGS(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004924 tstorm_config.rss_result_mask = MULTI_MASK;
4925 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004926 if (IS_E1HMF(bp))
4927 tstorm_config.config_flags |=
4928 TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004929
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004930 tstorm_config.leading_client_id = BP_L_ID(bp);
4931
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004932 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004933 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004934 (*(u32 *)&tstorm_config));
4935
Eliezer Tamirc14423f2008-02-28 11:49:42 -08004936 bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004937 bnx2x_set_storm_rx_mode(bp);
4938
Eilon Greensteinde832a52009-02-12 08:36:33 +00004939 for_each_queue(bp, i) {
4940 u8 cl_id = bp->fp[i].cl_id;
4941
4942 /* reset xstorm per client statistics */
4943 offset = BAR_XSTRORM_INTMEM +
4944 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4945 for (j = 0;
4946 j < sizeof(struct xstorm_per_client_stats) / 4; j++)
4947 REG_WR(bp, offset + j*4, 0);
4948
4949 /* reset tstorm per client statistics */
4950 offset = BAR_TSTRORM_INTMEM +
4951 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4952 for (j = 0;
4953 j < sizeof(struct tstorm_per_client_stats) / 4; j++)
4954 REG_WR(bp, offset + j*4, 0);
4955
4956 /* reset ustorm per client statistics */
4957 offset = BAR_USTRORM_INTMEM +
4958 USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4959 for (j = 0;
4960 j < sizeof(struct ustorm_per_client_stats) / 4; j++)
4961 REG_WR(bp, offset + j*4, 0);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004962 }
4963
4964 /* Init statistics related context */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004965 stats_flags.collect_eth = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004966
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004967 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004968 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004969 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004970 ((u32 *)&stats_flags)[1]);
4971
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004972 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004973 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004974 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004975 ((u32 *)&stats_flags)[1]);
4976
Eilon Greensteinde832a52009-02-12 08:36:33 +00004977 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
4978 ((u32 *)&stats_flags)[0]);
4979 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
4980 ((u32 *)&stats_flags)[1]);
4981
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004982 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004983 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004984 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004985 ((u32 *)&stats_flags)[1]);
4986
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004987 REG_WR(bp, BAR_XSTRORM_INTMEM +
4988 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4989 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4990 REG_WR(bp, BAR_XSTRORM_INTMEM +
4991 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4992 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
4993
4994 REG_WR(bp, BAR_TSTRORM_INTMEM +
4995 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4996 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4997 REG_WR(bp, BAR_TSTRORM_INTMEM +
4998 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4999 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005000
Eilon Greensteinde832a52009-02-12 08:36:33 +00005001 REG_WR(bp, BAR_USTRORM_INTMEM +
5002 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
5003 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
5004 REG_WR(bp, BAR_USTRORM_INTMEM +
5005 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
5006 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
5007
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005008 if (CHIP_IS_E1H(bp)) {
5009 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
5010 IS_E1HMF(bp));
5011 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
5012 IS_E1HMF(bp));
5013 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
5014 IS_E1HMF(bp));
5015 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
5016 IS_E1HMF(bp));
5017
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005018 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
5019 bp->e1hov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005020 }
5021
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08005022 /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
5023 max_agg_size =
5024 min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
5025 SGE_PAGE_SIZE * PAGES_PER_SGE),
5026 (u32)0xffff);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005027 for_each_rx_queue(bp, i) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005028 struct bnx2x_fastpath *fp = &bp->fp[i];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005029
5030 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005031 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005032 U64_LO(fp->rx_comp_mapping));
5033 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005034 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005035 U64_HI(fp->rx_comp_mapping));
5036
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005037 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005038 USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005039 max_agg_size);
5040 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005041
Eilon Greenstein1c063282009-02-12 08:36:43 +00005042 /* dropless flow control */
5043 if (CHIP_IS_E1H(bp)) {
5044 struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
5045
5046 rx_pause.bd_thr_low = 250;
5047 rx_pause.cqe_thr_low = 250;
5048 rx_pause.cos = 1;
5049 rx_pause.sge_thr_low = 0;
5050 rx_pause.bd_thr_high = 350;
5051 rx_pause.cqe_thr_high = 350;
5052 rx_pause.sge_thr_high = 0;
5053
5054 for_each_rx_queue(bp, i) {
5055 struct bnx2x_fastpath *fp = &bp->fp[i];
5056
5057 if (!fp->disable_tpa) {
5058 rx_pause.sge_thr_low = 150;
5059 rx_pause.sge_thr_high = 250;
5060 }
5061
5062
5063 offset = BAR_USTRORM_INTMEM +
5064 USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
5065 fp->cl_id);
5066 for (j = 0;
5067 j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
5068 j++)
5069 REG_WR(bp, offset + j*4,
5070 ((u32 *)&rx_pause)[j]);
5071 }
5072 }
5073
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005074 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
5075
5076 /* Init rate shaping and fairness contexts */
5077 if (IS_E1HMF(bp)) {
5078 int vn;
5079
5080 /* During init there is no active link
5081 Until link is up, set link rate to 10Gbps */
5082 bp->link_vars.line_speed = SPEED_10000;
5083 bnx2x_init_port_minmax(bp);
5084
5085 bnx2x_calc_vn_weight_sum(bp);
5086
5087 for (vn = VN_0; vn < E1HVN_MAX; vn++)
5088 bnx2x_init_vn_minmax(bp, 2*vn + port);
5089
5090 /* Enable rate shaping and fairness */
5091 bp->cmng.flags.cmng_enables =
5092 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
5093 if (bp->vn_weight_sum)
5094 bp->cmng.flags.cmng_enables |=
5095 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
5096 else
5097 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
5098 " fairness will be disabled\n");
5099 } else {
5100 /* rate shaping and fairness are disabled */
5101 DP(NETIF_MSG_IFUP,
5102 "single function mode minmax will be disabled\n");
5103 }
5104
5105
5106 /* Store it to internal memory */
5107 if (bp->port.pmf)
5108 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
5109 REG_WR(bp, BAR_XSTRORM_INTMEM +
5110 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
5111 ((u32 *)(&bp->cmng))[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005112}
5113
Eilon Greenstein471de712008-08-13 15:49:35 -07005114static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5115{
5116 switch (load_code) {
5117 case FW_MSG_CODE_DRV_LOAD_COMMON:
5118 bnx2x_init_internal_common(bp);
5119 /* no break */
5120
5121 case FW_MSG_CODE_DRV_LOAD_PORT:
5122 bnx2x_init_internal_port(bp);
5123 /* no break */
5124
5125 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5126 bnx2x_init_internal_func(bp);
5127 break;
5128
5129 default:
5130 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5131 break;
5132 }
5133}
5134
5135static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005136{
5137 int i;
5138
5139 for_each_queue(bp, i) {
5140 struct bnx2x_fastpath *fp = &bp->fp[i];
5141
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005142 fp->bp = bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005143 fp->state = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005144 fp->index = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005145 fp->cl_id = BP_L_ID(bp) + i;
5146 fp->sb_id = fp->cl_id;
5147 DP(NETIF_MSG_IFUP,
Eilon Greensteinf5372252009-02-12 08:38:30 +00005148 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
5149 i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005150 bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
Eilon Greenstein0626b892009-02-12 08:38:14 +00005151 fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005152 bnx2x_update_fpsb_idx(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005153 }
5154
Eilon Greenstein16119782009-03-02 07:59:27 +00005155 /* ensure status block indices were read */
5156 rmb();
5157
5158
Eilon Greenstein5c862842008-08-13 15:51:48 -07005159 bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
5160 DEF_SB_ID);
5161 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005162 bnx2x_update_coalesce(bp);
5163 bnx2x_init_rx_rings(bp);
5164 bnx2x_init_tx_ring(bp);
5165 bnx2x_init_sp_ring(bp);
5166 bnx2x_init_context(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07005167 bnx2x_init_internal(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005168 bnx2x_init_ind_table(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005169 bnx2x_stats_init(bp);
5170
5171 /* At this point, we are ready for interrupts */
5172 atomic_set(&bp->intr_sem, 0);
5173
5174 /* flush all before enabling interrupts */
5175 mb();
5176 mmiowb();
5177
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08005178 bnx2x_int_enable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005179}
5180
5181/* end of nic init */
5182
5183/*
5184 * gzip service functions
5185 */
5186
5187static int bnx2x_gunzip_init(struct bnx2x *bp)
5188{
5189 bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE,
5190 &bp->gunzip_mapping);
5191 if (bp->gunzip_buf == NULL)
5192 goto gunzip_nomem1;
5193
5194 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5195 if (bp->strm == NULL)
5196 goto gunzip_nomem2;
5197
5198 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5199 GFP_KERNEL);
5200 if (bp->strm->workspace == NULL)
5201 goto gunzip_nomem3;
5202
5203 return 0;
5204
5205gunzip_nomem3:
5206 kfree(bp->strm);
5207 bp->strm = NULL;
5208
5209gunzip_nomem2:
5210 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5211 bp->gunzip_mapping);
5212 bp->gunzip_buf = NULL;
5213
5214gunzip_nomem1:
5215 printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005216 " un-compression\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005217 return -ENOMEM;
5218}
5219
5220static void bnx2x_gunzip_end(struct bnx2x *bp)
5221{
5222 kfree(bp->strm->workspace);
5223
5224 kfree(bp->strm);
5225 bp->strm = NULL;
5226
5227 if (bp->gunzip_buf) {
5228 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5229 bp->gunzip_mapping);
5230 bp->gunzip_buf = NULL;
5231 }
5232}
5233
5234static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len)
5235{
5236 int n, rc;
5237
5238 /* check gzip header */
5239 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
5240 return -EINVAL;
5241
5242 n = 10;
5243
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005244#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005245
5246 if (zbuf[3] & FNAME)
5247 while ((zbuf[n++] != 0) && (n < len));
5248
5249 bp->strm->next_in = zbuf + n;
5250 bp->strm->avail_in = len - n;
5251 bp->strm->next_out = bp->gunzip_buf;
5252 bp->strm->avail_out = FW_BUF_SIZE;
5253
5254 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5255 if (rc != Z_OK)
5256 return rc;
5257
5258 rc = zlib_inflate(bp->strm, Z_FINISH);
5259 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5260 printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
5261 bp->dev->name, bp->strm->msg);
5262
5263 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5264 if (bp->gunzip_outlen & 0x3)
5265 printk(KERN_ERR PFX "%s: Firmware decompression error:"
5266 " gunzip_outlen (%d) not aligned\n",
5267 bp->dev->name, bp->gunzip_outlen);
5268 bp->gunzip_outlen >>= 2;
5269
5270 zlib_inflateEnd(bp->strm);
5271
5272 if (rc == Z_STREAM_END)
5273 return 0;
5274
5275 return rc;
5276}
5277
5278/* nic load/unload */
5279
5280/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005281 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005282 */
5283
5284/* send a NIG loopback debug packet */
5285static void bnx2x_lb_pckt(struct bnx2x *bp)
5286{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005287 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005288
5289 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005290 wb_write[0] = 0x55555555;
5291 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005292 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005293 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005294
5295 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005296 wb_write[0] = 0x09000000;
5297 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005298 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005299 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005300}
5301
5302/* some of the internal memories
5303 * are not directly readable from the driver
5304 * to test them we send debug packets
5305 */
5306static int bnx2x_int_mem_test(struct bnx2x *bp)
5307{
5308 int factor;
5309 int count, i;
5310 u32 val = 0;
5311
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005312 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005313 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005314 else if (CHIP_REV_IS_EMUL(bp))
5315 factor = 200;
5316 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005317 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005318
5319 DP(NETIF_MSG_HW, "start part1\n");
5320
5321 /* Disable inputs of parser neighbor blocks */
5322 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5323 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5324 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005325 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005326
5327 /* Write 0 to parser credits for CFC search request */
5328 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5329
5330 /* send Ethernet packet */
5331 bnx2x_lb_pckt(bp);
5332
5333 /* TODO do i reset NIG statistic? */
5334 /* Wait until NIG register shows 1 packet of size 0x10 */
5335 count = 1000 * factor;
5336 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005337
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005338 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5339 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005340 if (val == 0x10)
5341 break;
5342
5343 msleep(10);
5344 count--;
5345 }
5346 if (val != 0x10) {
5347 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5348 return -1;
5349 }
5350
5351 /* Wait until PRS register shows 1 packet */
5352 count = 1000 * factor;
5353 while (count) {
5354 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005355 if (val == 1)
5356 break;
5357
5358 msleep(10);
5359 count--;
5360 }
5361 if (val != 0x1) {
5362 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5363 return -2;
5364 }
5365
5366 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005367 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005368 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005369 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005370 msleep(50);
5371 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
5372 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
5373
5374 DP(NETIF_MSG_HW, "part2\n");
5375
5376 /* Disable inputs of parser neighbor blocks */
5377 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5378 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5379 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005380 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005381
5382 /* Write 0 to parser credits for CFC search request */
5383 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5384
5385 /* send 10 Ethernet packets */
5386 for (i = 0; i < 10; i++)
5387 bnx2x_lb_pckt(bp);
5388
5389 /* Wait until NIG register shows 10 + 1
5390 packets of size 11*0x10 = 0xb0 */
5391 count = 1000 * factor;
5392 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005393
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005394 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5395 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005396 if (val == 0xb0)
5397 break;
5398
5399 msleep(10);
5400 count--;
5401 }
5402 if (val != 0xb0) {
5403 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5404 return -3;
5405 }
5406
5407 /* Wait until PRS register shows 2 packets */
5408 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5409 if (val != 2)
5410 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5411
5412 /* Write 1 to parser credits for CFC search request */
5413 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5414
5415 /* Wait until PRS register shows 3 packets */
5416 msleep(10 * factor);
5417 /* Wait until NIG register shows 1 packet of size 0x10 */
5418 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5419 if (val != 3)
5420 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5421
5422 /* clear NIG EOP FIFO */
5423 for (i = 0; i < 11; i++)
5424 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5425 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5426 if (val != 1) {
5427 BNX2X_ERR("clear of NIG failed\n");
5428 return -4;
5429 }
5430
5431 /* Reset and init BRB, PRS, NIG */
5432 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5433 msleep(50);
5434 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5435 msleep(50);
5436 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
5437 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
5438#ifndef BCM_ISCSI
5439 /* set NIC mode */
5440 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5441#endif
5442
5443 /* Enable inputs of parser neighbor blocks */
5444 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5445 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5446 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005447 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005448
5449 DP(NETIF_MSG_HW, "done\n");
5450
5451 return 0; /* OK */
5452}
5453
5454static void enable_blocks_attention(struct bnx2x *bp)
5455{
5456 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5457 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5458 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5459 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5460 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5461 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5462 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5463 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5464 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005465/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5466/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005467 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5468 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5469 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005470/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5471/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005472 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5473 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5474 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5475 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005476/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5477/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5478 if (CHIP_REV_IS_FPGA(bp))
5479 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5480 else
5481 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005482 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5483 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5484 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005485/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5486/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005487 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5488 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005489/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5490 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005491}
5492
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005493
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005494static void bnx2x_reset_common(struct bnx2x *bp)
5495{
5496 /* reset_common */
5497 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5498 0xd3ffff7f);
5499 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
5500}
5501
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005502static int bnx2x_init_common(struct bnx2x *bp)
5503{
5504 u32 val, i;
5505
5506 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
5507
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005508 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005509 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5510 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
5511
5512 bnx2x_init_block(bp, MISC_COMMON_START, MISC_COMMON_END);
5513 if (CHIP_IS_E1H(bp))
5514 REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
5515
5516 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
5517 msleep(30);
5518 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
5519
5520 bnx2x_init_block(bp, PXP_COMMON_START, PXP_COMMON_END);
5521 if (CHIP_IS_E1(bp)) {
5522 /* enable HW interrupt from PXP on USDM overflow
5523 bit 16 on INT_MASK_0 */
5524 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005525 }
5526
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005527 bnx2x_init_block(bp, PXP2_COMMON_START, PXP2_COMMON_END);
5528 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005529
5530#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005531 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5532 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5533 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5534 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5535 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005536 /* make sure this value is 0 */
5537 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005538
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005539/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5540 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5541 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5542 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5543 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005544#endif
5545
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005546 REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005547#ifdef BCM_ISCSI
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005548 REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
5549 REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
5550 REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005551#endif
5552
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005553 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5554 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005555
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005556 /* let the HW do it's magic ... */
5557 msleep(100);
5558 /* finish PXP init */
5559 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5560 if (val != 1) {
5561 BNX2X_ERR("PXP2 CFG failed\n");
5562 return -EBUSY;
5563 }
5564 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5565 if (val != 1) {
5566 BNX2X_ERR("PXP2 RD_INIT failed\n");
5567 return -EBUSY;
5568 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005569
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005570 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5571 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005572
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005573 bnx2x_init_block(bp, DMAE_COMMON_START, DMAE_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005574
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005575 /* clean the DMAE memory */
5576 bp->dmae_ready = 1;
5577 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005578
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005579 bnx2x_init_block(bp, TCM_COMMON_START, TCM_COMMON_END);
5580 bnx2x_init_block(bp, UCM_COMMON_START, UCM_COMMON_END);
5581 bnx2x_init_block(bp, CCM_COMMON_START, CCM_COMMON_END);
5582 bnx2x_init_block(bp, XCM_COMMON_START, XCM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005583
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005584 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5585 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5586 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5587 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5588
5589 bnx2x_init_block(bp, QM_COMMON_START, QM_COMMON_END);
5590 /* soft reset pulse */
5591 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5592 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005593
5594#ifdef BCM_ISCSI
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005595 bnx2x_init_block(bp, TIMERS_COMMON_START, TIMERS_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005596#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005597
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005598 bnx2x_init_block(bp, DQ_COMMON_START, DQ_COMMON_END);
5599 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
5600 if (!CHIP_REV_IS_SLOW(bp)) {
5601 /* enable hw interrupt from doorbell Q */
5602 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5603 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005604
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005605 bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005606 bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005607 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005608 /* set NIC mode */
5609 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005610 if (CHIP_IS_E1H(bp))
5611 REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005612
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005613 bnx2x_init_block(bp, TSDM_COMMON_START, TSDM_COMMON_END);
5614 bnx2x_init_block(bp, CSDM_COMMON_START, CSDM_COMMON_END);
5615 bnx2x_init_block(bp, USDM_COMMON_START, USDM_COMMON_END);
5616 bnx2x_init_block(bp, XSDM_COMMON_START, XSDM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005617
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005618 if (CHIP_IS_E1H(bp)) {
5619 bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0,
5620 STORM_INTMEM_SIZE_E1H/2);
5621 bnx2x_init_fill(bp,
5622 TSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5623 0, STORM_INTMEM_SIZE_E1H/2);
5624 bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0,
5625 STORM_INTMEM_SIZE_E1H/2);
5626 bnx2x_init_fill(bp,
5627 CSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5628 0, STORM_INTMEM_SIZE_E1H/2);
5629 bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0,
5630 STORM_INTMEM_SIZE_E1H/2);
5631 bnx2x_init_fill(bp,
5632 XSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5633 0, STORM_INTMEM_SIZE_E1H/2);
5634 bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0,
5635 STORM_INTMEM_SIZE_E1H/2);
5636 bnx2x_init_fill(bp,
5637 USTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2,
5638 0, STORM_INTMEM_SIZE_E1H/2);
5639 } else { /* E1 */
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005640 bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0,
5641 STORM_INTMEM_SIZE_E1);
5642 bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0,
5643 STORM_INTMEM_SIZE_E1);
5644 bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0,
5645 STORM_INTMEM_SIZE_E1);
5646 bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0,
5647 STORM_INTMEM_SIZE_E1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005648 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005649
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005650 bnx2x_init_block(bp, TSEM_COMMON_START, TSEM_COMMON_END);
5651 bnx2x_init_block(bp, USEM_COMMON_START, USEM_COMMON_END);
5652 bnx2x_init_block(bp, CSEM_COMMON_START, CSEM_COMMON_END);
5653 bnx2x_init_block(bp, XSEM_COMMON_START, XSEM_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005654
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005655 /* sync semi rtc */
5656 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5657 0x80000000);
5658 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5659 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005660
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005661 bnx2x_init_block(bp, UPB_COMMON_START, UPB_COMMON_END);
5662 bnx2x_init_block(bp, XPB_COMMON_START, XPB_COMMON_END);
5663 bnx2x_init_block(bp, PBF_COMMON_START, PBF_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005664
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005665 REG_WR(bp, SRC_REG_SOFT_RST, 1);
5666 for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) {
5667 REG_WR(bp, i, 0xc0cac01a);
5668 /* TODO: replace with something meaningful */
5669 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005670 bnx2x_init_block(bp, SRCH_COMMON_START, SRCH_COMMON_END);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005671 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005672
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005673 if (sizeof(union cdu_context) != 1024)
5674 /* we currently assume that a context is 1024 bytes */
5675 printk(KERN_ALERT PFX "please adjust the size of"
5676 " cdu_context(%ld)\n", (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005677
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005678 bnx2x_init_block(bp, CDU_COMMON_START, CDU_COMMON_END);
5679 val = (4 << 24) + (0 << 12) + 1024;
5680 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
5681 if (CHIP_IS_E1(bp)) {
5682 /* !!! fix pxp client crdit until excel update */
5683 REG_WR(bp, CDU_REG_CDU_DEBUG, 0x264);
5684 REG_WR(bp, CDU_REG_CDU_DEBUG, 0);
5685 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005686
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005687 bnx2x_init_block(bp, CFC_COMMON_START, CFC_COMMON_END);
5688 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005689 /* enable context validation interrupt from CFC */
5690 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5691
5692 /* set the thresholds to prevent CFC/CDU race */
5693 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005694
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005695 bnx2x_init_block(bp, HC_COMMON_START, HC_COMMON_END);
5696 bnx2x_init_block(bp, MISC_AEU_COMMON_START, MISC_AEU_COMMON_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005697
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005698 /* PXPCS COMMON comes here */
5699 /* Reset PCIE errors for debug */
5700 REG_WR(bp, 0x2814, 0xffffffff);
5701 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005702
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005703 /* EMAC0 COMMON comes here */
5704 /* EMAC1 COMMON comes here */
5705 /* DBU COMMON comes here */
5706 /* DBG COMMON comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005707
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005708 bnx2x_init_block(bp, NIG_COMMON_START, NIG_COMMON_END);
5709 if (CHIP_IS_E1H(bp)) {
5710 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
5711 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
5712 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005713
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005714 if (CHIP_REV_IS_SLOW(bp))
5715 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005716
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005717 /* finish CFC init */
5718 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5719 if (val != 1) {
5720 BNX2X_ERR("CFC LL_INIT failed\n");
5721 return -EBUSY;
5722 }
5723 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5724 if (val != 1) {
5725 BNX2X_ERR("CFC AC_INIT failed\n");
5726 return -EBUSY;
5727 }
5728 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5729 if (val != 1) {
5730 BNX2X_ERR("CFC CAM_INIT failed\n");
5731 return -EBUSY;
5732 }
5733 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005734
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005735 /* read NIG statistic
5736 to see if this is our first up since powerup */
5737 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5738 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005739
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005740 /* do internal memory self test */
5741 if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
5742 BNX2X_ERR("internal mem self test failed\n");
5743 return -EBUSY;
5744 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005745
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005746 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein46c6a672009-02-12 08:36:58 +00005747 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
5748 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
5749 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5750 bp->port.need_hw_lock = 1;
5751 break;
5752
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005753 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005754 /* Fan failure is indicated by SPIO 5 */
5755 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5756 MISC_REGISTERS_SPIO_INPUT_HI_Z);
Eliezer Tamirf1410642008-02-28 11:51:50 -08005757
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005758 /* set to active low mode */
5759 val = REG_RD(bp, MISC_REG_SPIO_INT);
5760 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
Eliezer Tamirf1410642008-02-28 11:51:50 -08005761 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005762 REG_WR(bp, MISC_REG_SPIO_INT, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08005763
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005764 /* enable interrupt to signal the IGU */
5765 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5766 val |= (1 << MISC_REGISTERS_SPIO_5);
5767 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5768 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08005769
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005770 default:
5771 break;
5772 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08005773
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005774 /* clear PXP2 attentions */
5775 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005776
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005777 enable_blocks_attention(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005778
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005779 if (!BP_NOMCP(bp)) {
5780 bnx2x_acquire_phy_lock(bp);
5781 bnx2x_common_init_phy(bp, bp->common.shmem_base);
5782 bnx2x_release_phy_lock(bp);
5783 } else
5784 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5785
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005786 return 0;
5787}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005788
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005789static int bnx2x_init_port(struct bnx2x *bp)
5790{
5791 int port = BP_PORT(bp);
Eilon Greenstein1c063282009-02-12 08:36:43 +00005792 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005793 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005794
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005795 DP(BNX2X_MSG_MCP, "starting port init port %x\n", port);
5796
5797 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005798
5799 /* Port PXP comes here */
5800 /* Port PXP2 comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005801#ifdef BCM_ISCSI
5802 /* Port0 1
5803 * Port1 385 */
5804 i++;
5805 wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping);
5806 wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping);
5807 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5808 REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
5809
5810 /* Port0 2
5811 * Port1 386 */
5812 i++;
5813 wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping);
5814 wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping);
5815 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5816 REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
5817
5818 /* Port0 3
5819 * Port1 387 */
5820 i++;
5821 wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping);
5822 wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping);
5823 REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
5824 REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
5825#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005826 /* Port CMs come here */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005827 bnx2x_init_block(bp, (port ? XCM_PORT1_START : XCM_PORT0_START),
5828 (port ? XCM_PORT1_END : XCM_PORT0_END));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005829
5830 /* Port QM comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005831#ifdef BCM_ISCSI
5832 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20);
5833 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31);
5834
5835 bnx2x_init_block(bp, func ? TIMERS_PORT1_START : TIMERS_PORT0_START,
5836 func ? TIMERS_PORT1_END : TIMERS_PORT0_END);
5837#endif
5838 /* Port DQ comes here */
Eilon Greenstein1c063282009-02-12 08:36:43 +00005839
5840 bnx2x_init_block(bp, (port ? BRB1_PORT1_START : BRB1_PORT0_START),
5841 (port ? BRB1_PORT1_END : BRB1_PORT0_END));
5842 if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
5843 /* no pause for emulation and FPGA */
5844 low = 0;
5845 high = 513;
5846 } else {
5847 if (IS_E1HMF(bp))
5848 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
5849 else if (bp->dev->mtu > 4096) {
5850 if (bp->flags & ONE_PORT_FLAG)
5851 low = 160;
5852 else {
5853 val = bp->dev->mtu;
5854 /* (24*1024 + val*4)/256 */
5855 low = 96 + (val/64) + ((val % 64) ? 1 : 0);
5856 }
5857 } else
5858 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
5859 high = low + 56; /* 14*1024/256 */
5860 }
5861 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
5862 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
5863
5864
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005865 /* Port PRS comes here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005866 /* Port TSDM comes here */
5867 /* Port CSDM comes here */
5868 /* Port USDM comes here */
5869 /* Port XSDM comes here */
Eilon Greenstein356e2382009-02-12 08:38:32 +00005870
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005871 bnx2x_init_block(bp, port ? TSEM_PORT1_START : TSEM_PORT0_START,
5872 port ? TSEM_PORT1_END : TSEM_PORT0_END);
5873 bnx2x_init_block(bp, port ? USEM_PORT1_START : USEM_PORT0_START,
5874 port ? USEM_PORT1_END : USEM_PORT0_END);
5875 bnx2x_init_block(bp, port ? CSEM_PORT1_START : CSEM_PORT0_START,
5876 port ? CSEM_PORT1_END : CSEM_PORT0_END);
5877 bnx2x_init_block(bp, port ? XSEM_PORT1_START : XSEM_PORT0_START,
5878 port ? XSEM_PORT1_END : XSEM_PORT0_END);
Eilon Greenstein356e2382009-02-12 08:38:32 +00005879
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005880 /* Port UPB comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005881 /* Port XPB comes here */
5882
5883 bnx2x_init_block(bp, port ? PBF_PORT1_START : PBF_PORT0_START,
5884 port ? PBF_PORT1_END : PBF_PORT0_END);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005885
5886 /* configure PBF to work without PAUSE mtu 9000 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005887 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005888
5889 /* update threshold */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005890 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005891 /* update init credit */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005892 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005893
5894 /* probe changes */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005895 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005896 msleep(5);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005897 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005898
5899#ifdef BCM_ISCSI
5900 /* tell the searcher where the T2 table is */
5901 REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64);
5902
5903 wb_write[0] = U64_LO(bp->t2_mapping);
5904 wb_write[1] = U64_HI(bp->t2_mapping);
5905 REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2);
5906 wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64);
5907 wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64);
5908 REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2);
5909
5910 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10);
5911 /* Port SRCH comes here */
5912#endif
5913 /* Port CDU comes here */
5914 /* Port CFC comes here */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005915
5916 if (CHIP_IS_E1(bp)) {
5917 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
5918 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
5919 }
5920 bnx2x_init_block(bp, port ? HC_PORT1_START : HC_PORT0_START,
5921 port ? HC_PORT1_END : HC_PORT0_END);
5922
5923 bnx2x_init_block(bp, port ? MISC_AEU_PORT1_START :
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005924 MISC_AEU_PORT0_START,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005925 port ? MISC_AEU_PORT1_END : MISC_AEU_PORT0_END);
5926 /* init aeu_mask_attn_func_0/1:
5927 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
5928 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
5929 * bits 4-7 are used for "per vn group attention" */
5930 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
5931 (IS_E1HMF(bp) ? 0xF7 : 0x7));
5932
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005933 /* Port PXPCS comes here */
5934 /* Port EMAC0 comes here */
5935 /* Port EMAC1 comes here */
5936 /* Port DBU comes here */
5937 /* Port DBG comes here */
Eilon Greenstein356e2382009-02-12 08:38:32 +00005938
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005939 bnx2x_init_block(bp, port ? NIG_PORT1_START : NIG_PORT0_START,
5940 port ? NIG_PORT1_END : NIG_PORT0_END);
5941
5942 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
5943
5944 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005945 /* 0x2 disable e1hov, 0x1 enable */
5946 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
5947 (IS_E1HMF(bp) ? 0x1 : 0x2));
5948
Eilon Greenstein1c063282009-02-12 08:36:43 +00005949 /* support pause requests from USDM, TSDM and BRB */
5950 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0 + port*4, 0x7);
5951
5952 {
5953 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
5954 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
5955 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
5956 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005957 }
5958
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005959 /* Port MCP comes here */
5960 /* Port DMAE comes here */
5961
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005962 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00005963 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5964 {
5965 u32 swap_val, swap_override, aeu_gpio_mask, offset;
5966
5967 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
5968 MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
5969
5970 /* The GPIO should be swapped if the swap register is
5971 set and active */
5972 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5973 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5974
5975 /* Select function upon port-swap configuration */
5976 if (port == 0) {
5977 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5978 aeu_gpio_mask = (swap_val && swap_override) ?
5979 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
5980 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
5981 } else {
5982 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
5983 aeu_gpio_mask = (swap_val && swap_override) ?
5984 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
5985 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
5986 }
5987 val = REG_RD(bp, offset);
5988 /* add GPIO3 to group */
5989 val |= aeu_gpio_mask;
5990 REG_WR(bp, offset, val);
5991 }
5992 break;
5993
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005994 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eliezer Tamirf1410642008-02-28 11:51:50 -08005995 /* add SPIO 5 to group 0 */
5996 val = REG_RD(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5997 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
5998 REG_WR(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0, val);
5999 break;
6000
6001 default:
6002 break;
6003 }
6004
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07006005 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006006
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006007 return 0;
6008}
6009
6010#define ILT_PER_FUNC (768/2)
6011#define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
6012/* the phys address is shifted right 12 bits and has an added
6013 1=valid bit added to the 53rd bit
6014 then since this is a wide register(TM)
6015 we split it into two 32 bit writes
6016 */
6017#define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
6018#define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
6019#define PXP_ONE_ILT(x) (((x) << 10) | x)
6020#define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
6021
6022#define CNIC_ILT_LINES 0
6023
6024static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6025{
6026 int reg;
6027
6028 if (CHIP_IS_E1H(bp))
6029 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6030 else /* E1 */
6031 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6032
6033 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6034}
6035
6036static int bnx2x_init_func(struct bnx2x *bp)
6037{
6038 int port = BP_PORT(bp);
6039 int func = BP_FUNC(bp);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006040 u32 addr, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006041 int i;
6042
6043 DP(BNX2X_MSG_MCP, "starting func init func %x\n", func);
6044
Eilon Greenstein8badd272009-02-12 08:36:15 +00006045 /* set MSI reconfigure capability */
6046 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6047 val = REG_RD(bp, addr);
6048 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6049 REG_WR(bp, addr, val);
6050
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006051 i = FUNC_ILT_BASE(func);
6052
6053 bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
6054 if (CHIP_IS_E1H(bp)) {
6055 REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
6056 REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
6057 } else /* E1 */
6058 REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
6059 PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
6060
6061
6062 if (CHIP_IS_E1H(bp)) {
6063 for (i = 0; i < 9; i++)
6064 bnx2x_init_block(bp,
6065 cm_start[func][i], cm_end[func][i]);
6066
6067 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6068 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
6069 }
6070
6071 /* HC init per function */
6072 if (CHIP_IS_E1H(bp)) {
6073 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6074
6075 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6076 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6077 }
6078 bnx2x_init_block(bp, hc_limits[func][0], hc_limits[func][1]);
6079
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006080 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006081 REG_WR(bp, 0x2114, 0xffffffff);
6082 REG_WR(bp, 0x2120, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006083
6084 return 0;
6085}
6086
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006087static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
6088{
6089 int i, rc = 0;
6090
6091 DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
6092 BP_FUNC(bp), load_code);
6093
6094 bp->dmae_ready = 0;
6095 mutex_init(&bp->dmae_mutex);
6096 bnx2x_gunzip_init(bp);
6097
6098 switch (load_code) {
6099 case FW_MSG_CODE_DRV_LOAD_COMMON:
6100 rc = bnx2x_init_common(bp);
6101 if (rc)
6102 goto init_hw_err;
6103 /* no break */
6104
6105 case FW_MSG_CODE_DRV_LOAD_PORT:
6106 bp->dmae_ready = 1;
6107 rc = bnx2x_init_port(bp);
6108 if (rc)
6109 goto init_hw_err;
6110 /* no break */
6111
6112 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
6113 bp->dmae_ready = 1;
6114 rc = bnx2x_init_func(bp);
6115 if (rc)
6116 goto init_hw_err;
6117 break;
6118
6119 default:
6120 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6121 break;
6122 }
6123
6124 if (!BP_NOMCP(bp)) {
6125 int func = BP_FUNC(bp);
6126
6127 bp->fw_drv_pulse_wr_seq =
6128 (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
6129 DRV_PULSE_SEQ_MASK);
6130 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
6131 DP(BNX2X_MSG_MCP, "drv_pulse 0x%x func_stx 0x%x\n",
6132 bp->fw_drv_pulse_wr_seq, bp->func_stx);
6133 } else
6134 bp->func_stx = 0;
6135
6136 /* this needs to be done before gunzip end */
6137 bnx2x_zero_def_sb(bp);
6138 for_each_queue(bp, i)
6139 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
6140
6141init_hw_err:
6142 bnx2x_gunzip_end(bp);
6143
6144 return rc;
6145}
6146
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006147/* send the MCP a request, block until there is a reply */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006148static u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
6149{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006150 int func = BP_FUNC(bp);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006151 u32 seq = ++bp->fw_seq;
6152 u32 rc = 0;
Eilon Greenstein19680c42008-08-13 15:47:33 -07006153 u32 cnt = 1;
6154 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006155
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006156 SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
Eliezer Tamirf1410642008-02-28 11:51:50 -08006157 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006158
Eilon Greenstein19680c42008-08-13 15:47:33 -07006159 do {
6160 /* let the FW do it's magic ... */
6161 msleep(delay);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006162
Eilon Greenstein19680c42008-08-13 15:47:33 -07006163 rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006164
Eilon Greenstein19680c42008-08-13 15:47:33 -07006165 /* Give the FW up to 2 second (200*10ms) */
6166 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200));
6167
6168 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
6169 cnt*delay, rc, seq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006170
6171 /* is this a reply to our command? */
6172 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
6173 rc &= FW_MSG_CODE_MASK;
Eliezer Tamirf1410642008-02-28 11:51:50 -08006174
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006175 } else {
6176 /* FW BUG! */
6177 BNX2X_ERR("FW failed to respond!\n");
6178 bnx2x_fw_dump(bp);
6179 rc = 0;
6180 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08006181
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006182 return rc;
6183}
6184
6185static void bnx2x_free_mem(struct bnx2x *bp)
6186{
6187
6188#define BNX2X_PCI_FREE(x, y, size) \
6189 do { \
6190 if (x) { \
6191 pci_free_consistent(bp->pdev, size, x, y); \
6192 x = NULL; \
6193 y = 0; \
6194 } \
6195 } while (0)
6196
6197#define BNX2X_FREE(x) \
6198 do { \
6199 if (x) { \
6200 vfree(x); \
6201 x = NULL; \
6202 } \
6203 } while (0)
6204
6205 int i;
6206
6207 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006208 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006209 for_each_queue(bp, i) {
6210
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006211 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006212 BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
6213 bnx2x_fp(bp, i, status_blk_mapping),
6214 sizeof(struct host_status_block) +
6215 sizeof(struct eth_tx_db_data));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006216 }
6217 /* Rx */
6218 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006219
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006220 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006221 BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
6222 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
6223 bnx2x_fp(bp, i, rx_desc_mapping),
6224 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6225
6226 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
6227 bnx2x_fp(bp, i, rx_comp_mapping),
6228 sizeof(struct eth_fast_path_rx_cqe) *
6229 NUM_RCQ_BD);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006230
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006231 /* SGE ring */
Eilon Greenstein32626232008-08-13 15:51:07 -07006232 BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006233 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
6234 bnx2x_fp(bp, i, rx_sge_mapping),
6235 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
6236 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006237 /* Tx */
6238 for_each_tx_queue(bp, i) {
6239
6240 /* fastpath tx rings: tx_buf tx_desc */
6241 BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
6242 BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
6243 bnx2x_fp(bp, i, tx_desc_mapping),
6244 sizeof(struct eth_tx_bd) * NUM_TX_BD);
6245 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006246 /* end of fastpath */
6247
6248 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006249 sizeof(struct host_def_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006250
6251 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006252 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006253
6254#ifdef BCM_ISCSI
6255 BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
6256 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
6257 BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
6258 BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
6259#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006260 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006261
6262#undef BNX2X_PCI_FREE
6263#undef BNX2X_KFREE
6264}
6265
6266static int bnx2x_alloc_mem(struct bnx2x *bp)
6267{
6268
6269#define BNX2X_PCI_ALLOC(x, y, size) \
6270 do { \
6271 x = pci_alloc_consistent(bp->pdev, size, y); \
6272 if (x == NULL) \
6273 goto alloc_mem_err; \
6274 memset(x, 0, size); \
6275 } while (0)
6276
6277#define BNX2X_ALLOC(x, size) \
6278 do { \
6279 x = vmalloc(size); \
6280 if (x == NULL) \
6281 goto alloc_mem_err; \
6282 memset(x, 0, size); \
6283 } while (0)
6284
6285 int i;
6286
6287 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006288 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006289 for_each_queue(bp, i) {
6290 bnx2x_fp(bp, i, bp) = bp;
6291
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006292 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006293 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
6294 &bnx2x_fp(bp, i, status_blk_mapping),
6295 sizeof(struct host_status_block) +
6296 sizeof(struct eth_tx_db_data));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006297 }
6298 /* Rx */
6299 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006300
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006301 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006302 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
6303 sizeof(struct sw_rx_bd) * NUM_RX_BD);
6304 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
6305 &bnx2x_fp(bp, i, rx_desc_mapping),
6306 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6307
6308 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
6309 &bnx2x_fp(bp, i, rx_comp_mapping),
6310 sizeof(struct eth_fast_path_rx_cqe) *
6311 NUM_RCQ_BD);
6312
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006313 /* SGE ring */
6314 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
6315 sizeof(struct sw_rx_page) * NUM_RX_SGE);
6316 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
6317 &bnx2x_fp(bp, i, rx_sge_mapping),
6318 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006319 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006320 /* Tx */
6321 for_each_tx_queue(bp, i) {
6322
6323 bnx2x_fp(bp, i, hw_tx_prods) =
6324 (void *)(bnx2x_fp(bp, i, status_blk) + 1);
6325
6326 bnx2x_fp(bp, i, tx_prods_mapping) =
6327 bnx2x_fp(bp, i, status_blk_mapping) +
6328 sizeof(struct host_status_block);
6329
6330 /* fastpath tx rings: tx_buf tx_desc */
6331 BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
6332 sizeof(struct sw_tx_bd) * NUM_TX_BD);
6333 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
6334 &bnx2x_fp(bp, i, tx_desc_mapping),
6335 sizeof(struct eth_tx_bd) * NUM_TX_BD);
6336 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006337 /* end of fastpath */
6338
6339 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6340 sizeof(struct host_def_status_block));
6341
6342 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6343 sizeof(struct bnx2x_slowpath));
6344
6345#ifdef BCM_ISCSI
6346 BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
6347
6348 /* Initialize T1 */
6349 for (i = 0; i < 64*1024; i += 64) {
6350 *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL;
6351 *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL;
6352 }
6353
6354 /* allocate searcher T2 table
6355 we allocate 1/4 of alloc num for T2
6356 (which is not entered into the ILT) */
6357 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
6358
6359 /* Initialize T2 */
6360 for (i = 0; i < 16*1024; i += 64)
6361 * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
6362
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006363 /* now fixup the last line in the block to point to the next block */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006364 *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping;
6365
6366 /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */
6367 BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
6368
6369 /* QM queues (128*MAX_CONN) */
6370 BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
6371#endif
6372
6373 /* Slow path ring */
6374 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6375
6376 return 0;
6377
6378alloc_mem_err:
6379 bnx2x_free_mem(bp);
6380 return -ENOMEM;
6381
6382#undef BNX2X_PCI_ALLOC
6383#undef BNX2X_ALLOC
6384}
6385
6386static void bnx2x_free_tx_skbs(struct bnx2x *bp)
6387{
6388 int i;
6389
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006390 for_each_tx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006391 struct bnx2x_fastpath *fp = &bp->fp[i];
6392
6393 u16 bd_cons = fp->tx_bd_cons;
6394 u16 sw_prod = fp->tx_pkt_prod;
6395 u16 sw_cons = fp->tx_pkt_cons;
6396
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006397 while (sw_cons != sw_prod) {
6398 bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
6399 sw_cons++;
6400 }
6401 }
6402}
6403
6404static void bnx2x_free_rx_skbs(struct bnx2x *bp)
6405{
6406 int i, j;
6407
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006408 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006409 struct bnx2x_fastpath *fp = &bp->fp[j];
6410
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006411 for (i = 0; i < NUM_RX_BD; i++) {
6412 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
6413 struct sk_buff *skb = rx_buf->skb;
6414
6415 if (skb == NULL)
6416 continue;
6417
6418 pci_unmap_single(bp->pdev,
6419 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein356e2382009-02-12 08:38:32 +00006420 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006421
6422 rx_buf->skb = NULL;
6423 dev_kfree_skb(skb);
6424 }
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006425 if (!fp->disable_tpa)
Eilon Greenstein32626232008-08-13 15:51:07 -07006426 bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
6427 ETH_MAX_AGGREGATION_QUEUES_E1 :
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006428 ETH_MAX_AGGREGATION_QUEUES_E1H);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006429 }
6430}
6431
6432static void bnx2x_free_skbs(struct bnx2x *bp)
6433{
6434 bnx2x_free_tx_skbs(bp);
6435 bnx2x_free_rx_skbs(bp);
6436}
6437
6438static void bnx2x_free_msix_irqs(struct bnx2x *bp)
6439{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006440 int i, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006441
6442 free_irq(bp->msix_table[0].vector, bp->dev);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006443 DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006444 bp->msix_table[0].vector);
6445
6446 for_each_queue(bp, i) {
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006447 DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006448 "state %x\n", i, bp->msix_table[i + offset].vector,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006449 bnx2x_fp(bp, i, state));
6450
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006451 free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006452 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006453}
6454
6455static void bnx2x_free_irq(struct bnx2x *bp)
6456{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006457 if (bp->flags & USING_MSIX_FLAG) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006458 bnx2x_free_msix_irqs(bp);
6459 pci_disable_msix(bp->pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006460 bp->flags &= ~USING_MSIX_FLAG;
6461
Eilon Greenstein8badd272009-02-12 08:36:15 +00006462 } else if (bp->flags & USING_MSI_FLAG) {
6463 free_irq(bp->pdev->irq, bp->dev);
6464 pci_disable_msi(bp->pdev);
6465 bp->flags &= ~USING_MSI_FLAG;
6466
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006467 } else
6468 free_irq(bp->pdev->irq, bp->dev);
6469}
6470
6471static int bnx2x_enable_msix(struct bnx2x *bp)
6472{
Eilon Greenstein8badd272009-02-12 08:36:15 +00006473 int i, rc, offset = 1;
6474 int igu_vec = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006475
Eilon Greenstein8badd272009-02-12 08:36:15 +00006476 bp->msix_table[0].entry = igu_vec;
6477 DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006478
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006479 for_each_queue(bp, i) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006480 igu_vec = BP_L_ID(bp) + offset + i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006481 bp->msix_table[i + offset].entry = igu_vec;
6482 DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
6483 "(fastpath #%u)\n", i + offset, igu_vec, i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006484 }
6485
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006486 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0],
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006487 BNX2X_NUM_QUEUES(bp) + offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006488 if (rc) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006489 DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
6490 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006491 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006492
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006493 bp->flags |= USING_MSIX_FLAG;
6494
6495 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006496}
6497
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006498static int bnx2x_req_msix_irqs(struct bnx2x *bp)
6499{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006500 int i, rc, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006501
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006502 rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
6503 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006504 if (rc) {
6505 BNX2X_ERR("request sp irq failed\n");
6506 return -EBUSY;
6507 }
6508
6509 for_each_queue(bp, i) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006510 struct bnx2x_fastpath *fp = &bp->fp[i];
6511
6512 sprintf(fp->name, "%s.fp%d", bp->dev->name, i);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006513 rc = request_irq(bp->msix_table[i + offset].vector,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006514 bnx2x_msix_fp_int, 0, fp->name, fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006515 if (rc) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006516 BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006517 bnx2x_free_msix_irqs(bp);
6518 return -EBUSY;
6519 }
6520
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006521 fp->state = BNX2X_FP_STATE_IRQ;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006522 }
6523
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006524 i = BNX2X_NUM_QUEUES(bp);
6525 if (is_multi(bp))
6526 printk(KERN_INFO PFX
6527 "%s: using MSI-X IRQs: sp %d fp %d - %d\n",
6528 bp->dev->name, bp->msix_table[0].vector,
6529 bp->msix_table[offset].vector,
6530 bp->msix_table[offset + i - 1].vector);
6531 else
6532 printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp %d\n",
6533 bp->dev->name, bp->msix_table[0].vector,
6534 bp->msix_table[offset + i - 1].vector);
6535
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006536 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006537}
6538
Eilon Greenstein8badd272009-02-12 08:36:15 +00006539static int bnx2x_enable_msi(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006540{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006541 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006542
Eilon Greenstein8badd272009-02-12 08:36:15 +00006543 rc = pci_enable_msi(bp->pdev);
6544 if (rc) {
6545 DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
6546 return -1;
6547 }
6548 bp->flags |= USING_MSI_FLAG;
6549
6550 return 0;
6551}
6552
6553static int bnx2x_req_irq(struct bnx2x *bp)
6554{
6555 unsigned long flags;
6556 int rc;
6557
6558 if (bp->flags & USING_MSI_FLAG)
6559 flags = 0;
6560 else
6561 flags = IRQF_SHARED;
6562
6563 rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006564 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006565 if (!rc)
6566 bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
6567
6568 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006569}
6570
Yitchak Gertner65abd742008-08-25 15:26:24 -07006571static void bnx2x_napi_enable(struct bnx2x *bp)
6572{
6573 int i;
6574
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006575 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006576 napi_enable(&bnx2x_fp(bp, i, napi));
6577}
6578
6579static void bnx2x_napi_disable(struct bnx2x *bp)
6580{
6581 int i;
6582
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006583 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006584 napi_disable(&bnx2x_fp(bp, i, napi));
6585}
6586
6587static void bnx2x_netif_start(struct bnx2x *bp)
6588{
6589 if (atomic_dec_and_test(&bp->intr_sem)) {
6590 if (netif_running(bp->dev)) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07006591 bnx2x_napi_enable(bp);
6592 bnx2x_int_enable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006593 if (bp->state == BNX2X_STATE_OPEN)
6594 netif_tx_wake_all_queues(bp->dev);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006595 }
6596 }
6597}
6598
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07006599static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006600{
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07006601 bnx2x_int_disable_sync(bp, disable_hw);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00006602 bnx2x_napi_disable(bp);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006603 if (netif_running(bp->dev)) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07006604 netif_tx_disable(bp->dev);
6605 bp->dev->trans_start = jiffies; /* prevent tx timeout */
6606 }
6607}
6608
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006609/*
6610 * Init service functions
6611 */
6612
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006613static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006614{
6615 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006616 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006617
6618 /* CAM allocation
6619 * unicasts 0-31:port0 32-63:port1
6620 * multicast 64-127:port0 128-191:port1
6621 */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006622 config->hdr.length = 2;
Eilon Greensteinaf246402009-01-14 06:43:59 +00006623 config->hdr.offset = port ? 32 : 0;
Eilon Greenstein0626b892009-02-12 08:38:14 +00006624 config->hdr.client_id = bp->fp->cl_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006625 config->hdr.reserved1 = 0;
6626
6627 /* primary MAC */
6628 config->config_table[0].cam_entry.msb_mac_addr =
6629 swab16(*(u16 *)&bp->dev->dev_addr[0]);
6630 config->config_table[0].cam_entry.middle_mac_addr =
6631 swab16(*(u16 *)&bp->dev->dev_addr[2]);
6632 config->config_table[0].cam_entry.lsb_mac_addr =
6633 swab16(*(u16 *)&bp->dev->dev_addr[4]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006634 config->config_table[0].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006635 if (set)
6636 config->config_table[0].target_table_entry.flags = 0;
6637 else
6638 CAM_INVALIDATE(config->config_table[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006639 config->config_table[0].target_table_entry.client_id = 0;
6640 config->config_table[0].target_table_entry.vlan_id = 0;
6641
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006642 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
6643 (set ? "setting" : "clearing"),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006644 config->config_table[0].cam_entry.msb_mac_addr,
6645 config->config_table[0].cam_entry.middle_mac_addr,
6646 config->config_table[0].cam_entry.lsb_mac_addr);
6647
6648 /* broadcast */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00006649 config->config_table[1].cam_entry.msb_mac_addr = cpu_to_le16(0xffff);
6650 config->config_table[1].cam_entry.middle_mac_addr = cpu_to_le16(0xffff);
6651 config->config_table[1].cam_entry.lsb_mac_addr = cpu_to_le16(0xffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006652 config->config_table[1].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006653 if (set)
6654 config->config_table[1].target_table_entry.flags =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006655 TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006656 else
6657 CAM_INVALIDATE(config->config_table[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006658 config->config_table[1].target_table_entry.client_id = 0;
6659 config->config_table[1].target_table_entry.vlan_id = 0;
6660
6661 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6662 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6663 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6664}
6665
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006666static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006667{
6668 struct mac_configuration_cmd_e1h *config =
6669 (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
6670
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006671 if (set && (bp->state != BNX2X_STATE_OPEN)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006672 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
6673 return;
6674 }
6675
6676 /* CAM allocation for E1H
6677 * unicasts: by func number
6678 * multicast: 20+FUNC*20, 20 each
6679 */
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006680 config->hdr.length = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006681 config->hdr.offset = BP_FUNC(bp);
Eilon Greenstein0626b892009-02-12 08:38:14 +00006682 config->hdr.client_id = bp->fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006683 config->hdr.reserved1 = 0;
6684
6685 /* primary MAC */
6686 config->config_table[0].msb_mac_addr =
6687 swab16(*(u16 *)&bp->dev->dev_addr[0]);
6688 config->config_table[0].middle_mac_addr =
6689 swab16(*(u16 *)&bp->dev->dev_addr[2]);
6690 config->config_table[0].lsb_mac_addr =
6691 swab16(*(u16 *)&bp->dev->dev_addr[4]);
6692 config->config_table[0].client_id = BP_L_ID(bp);
6693 config->config_table[0].vlan_id = 0;
6694 config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006695 if (set)
6696 config->config_table[0].flags = BP_PORT(bp);
6697 else
6698 config->config_table[0].flags =
6699 MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006700
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006701 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n",
6702 (set ? "setting" : "clearing"),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006703 config->config_table[0].msb_mac_addr,
6704 config->config_table[0].middle_mac_addr,
6705 config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp));
6706
6707 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6708 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6709 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6710}
6711
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006712static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6713 int *state_p, int poll)
6714{
6715 /* can take a while if any port is running */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006716 int cnt = 5000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006717
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006718 DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
6719 poll ? "polling" : "waiting", state, idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006720
6721 might_sleep();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006722 while (cnt--) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006723 if (poll) {
6724 bnx2x_rx_int(bp->fp, 10);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006725 /* if index is different from 0
6726 * the reply for some commands will
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006727 * be on the non default queue
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006728 */
6729 if (idx)
6730 bnx2x_rx_int(&bp->fp[idx], 10);
6731 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006732
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006733 mb(); /* state is changed by bnx2x_sp_event() */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006734 if (*state_p == state) {
6735#ifdef BNX2X_STOP_ON_ERROR
6736 DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
6737#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006738 return 0;
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006739 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006740
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006741 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006742 }
6743
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006744 /* timeout! */
Eliezer Tamir49d66772008-02-28 11:53:13 -08006745 BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
6746 poll ? "polling" : "waiting", state, idx);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006747#ifdef BNX2X_STOP_ON_ERROR
6748 bnx2x_panic();
6749#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006750
Eliezer Tamir49d66772008-02-28 11:53:13 -08006751 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006752}
6753
6754static int bnx2x_setup_leading(struct bnx2x *bp)
6755{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006756 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006757
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006758 /* reset IGU state */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006759 bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006760
6761 /* SETUP ramrod */
6762 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
6763
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006764 /* Wait for completion */
6765 rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006766
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006767 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006768}
6769
6770static int bnx2x_setup_multi(struct bnx2x *bp, int index)
6771{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006772 struct bnx2x_fastpath *fp = &bp->fp[index];
6773
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006774 /* reset IGU state */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006775 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006776
Eliezer Tamir228241e2008-02-28 11:56:57 -08006777 /* SETUP ramrod */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006778 fp->state = BNX2X_FP_STATE_OPENING;
6779 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
6780 fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006781
6782 /* Wait for completion */
6783 return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006784 &(fp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006785}
6786
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006787static int bnx2x_poll(struct napi_struct *napi, int budget);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006788
Eilon Greenstein8badd272009-02-12 08:36:15 +00006789static void bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006790{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006791 int num_queues;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006792
Eilon Greenstein8badd272009-02-12 08:36:15 +00006793 switch (int_mode) {
6794 case INT_MODE_INTx:
6795 case INT_MODE_MSI:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006796 num_queues = 1;
6797 bp->num_rx_queues = num_queues;
6798 bp->num_tx_queues = num_queues;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006799 DP(NETIF_MSG_IFUP,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006800 "set number of queues to %d\n", num_queues);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006801 break;
6802
6803 case INT_MODE_MSIX:
6804 default:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006805 if (bp->multi_mode == ETH_RSS_MODE_REGULAR)
6806 num_queues = min_t(u32, num_online_cpus(),
6807 BNX2X_MAX_QUEUES(bp));
6808 else
6809 num_queues = 1;
6810 bp->num_rx_queues = num_queues;
6811 bp->num_tx_queues = num_queues;
6812 DP(NETIF_MSG_IFUP, "set number of rx queues to %d"
6813 " number of tx queues to %d\n",
6814 bp->num_rx_queues, bp->num_tx_queues);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006815 /* if we can't use MSI-X we only need one fp,
6816 * so try to enable MSI-X with the requested number of fp's
6817 * and fallback to MSI or legacy INTx with one fp
6818 */
Eilon Greenstein8badd272009-02-12 08:36:15 +00006819 if (bnx2x_enable_msix(bp)) {
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006820 /* failed to enable MSI-X */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006821 num_queues = 1;
6822 bp->num_rx_queues = num_queues;
6823 bp->num_tx_queues = num_queues;
6824 if (bp->multi_mode)
6825 BNX2X_ERR("Multi requested but failed to "
6826 "enable MSI-X set number of "
6827 "queues to %d\n", num_queues);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006828 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006829 break;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006830 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006831 bp->dev->real_num_tx_queues = bp->num_tx_queues;
Eilon Greenstein8badd272009-02-12 08:36:15 +00006832}
6833
6834static void bnx2x_set_rx_mode(struct net_device *dev);
6835
6836/* must be called with rtnl_lock */
6837static int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
6838{
6839 u32 load_code;
6840 int i, rc = 0;
6841#ifdef BNX2X_STOP_ON_ERROR
6842 DP(NETIF_MSG_IFUP, "enter load_mode %d\n", load_mode);
6843 if (unlikely(bp->panic))
6844 return -EPERM;
6845#endif
6846
6847 bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
6848
6849 bnx2x_set_int_mode(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006850
6851 if (bnx2x_alloc_mem(bp))
6852 return -ENOMEM;
6853
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006854 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006855 bnx2x_fp(bp, i, disable_tpa) =
6856 ((bp->flags & TPA_ENABLE_FLAG) == 0);
6857
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006858 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006859 netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
6860 bnx2x_poll, 128);
6861
6862#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006863 for_each_rx_queue(bp, i) {
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006864 struct bnx2x_fastpath *fp = &bp->fp[i];
6865
6866 fp->poll_no_work = 0;
6867 fp->poll_calls = 0;
6868 fp->poll_max_calls = 0;
6869 fp->poll_complete = 0;
6870 fp->poll_exit = 0;
6871 }
6872#endif
6873 bnx2x_napi_enable(bp);
6874
6875 if (bp->flags & USING_MSIX_FLAG) {
6876 rc = bnx2x_req_msix_irqs(bp);
6877 if (rc) {
6878 pci_disable_msix(bp->pdev);
6879 goto load_error1;
6880 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006881 } else {
Eilon Greenstein8badd272009-02-12 08:36:15 +00006882 if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
6883 bnx2x_enable_msi(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006884 bnx2x_ack_int(bp);
6885 rc = bnx2x_req_irq(bp);
6886 if (rc) {
6887 BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006888 if (bp->flags & USING_MSI_FLAG)
6889 pci_disable_msi(bp->pdev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006890 goto load_error1;
6891 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006892 if (bp->flags & USING_MSI_FLAG) {
6893 bp->dev->irq = bp->pdev->irq;
6894 printk(KERN_INFO PFX "%s: using MSI IRQ %d\n",
6895 bp->dev->name, bp->pdev->irq);
6896 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006897 }
6898
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006899 /* Send LOAD_REQUEST command to MCP
6900 Returns the type of LOAD command:
6901 if it is the first port to be initialized
6902 common blocks should be initialized, otherwise - not
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006903 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006904 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08006905 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ);
6906 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006907 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006908 rc = -EBUSY;
6909 goto load_error2;
Eliezer Tamir228241e2008-02-28 11:56:57 -08006910 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006911 if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6912 rc = -EBUSY; /* other port in diagnostic mode */
6913 goto load_error2;
6914 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006915
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006916 } else {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006917 int port = BP_PORT(bp);
6918
Eilon Greensteinf5372252009-02-12 08:38:30 +00006919 DP(NETIF_MSG_IFUP, "NO MCP - load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006920 load_count[0], load_count[1], load_count[2]);
6921 load_count[0]++;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006922 load_count[1 + port]++;
Eilon Greensteinf5372252009-02-12 08:38:30 +00006923 DP(NETIF_MSG_IFUP, "NO MCP - new load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006924 load_count[0], load_count[1], load_count[2]);
6925 if (load_count[0] == 1)
6926 load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006927 else if (load_count[1 + port] == 1)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006928 load_code = FW_MSG_CODE_DRV_LOAD_PORT;
6929 else
6930 load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006931 }
6932
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006933 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6934 (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
6935 bp->port.pmf = 1;
6936 else
6937 bp->port.pmf = 0;
6938 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
6939
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006940 /* Initialize HW */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006941 rc = bnx2x_init_hw(bp, load_code);
6942 if (rc) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006943 BNX2X_ERR("HW init failed, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006944 goto load_error2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006945 }
6946
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006947 /* Setup NIC internals and enable interrupts */
Eilon Greenstein471de712008-08-13 15:49:35 -07006948 bnx2x_nic_init(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006949
6950 /* Send LOAD_DONE command to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006951 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08006952 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE);
6953 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006954 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006955 rc = -EBUSY;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006956 goto load_error3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006957 }
6958 }
6959
6960 bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
6961
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006962 rc = bnx2x_setup_leading(bp);
6963 if (rc) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006964 BNX2X_ERR("Setup leading failed!\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006965 goto load_error3;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006966 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006967
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006968 if (CHIP_IS_E1H(bp))
6969 if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00006970 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006971 bp->state = BNX2X_STATE_DISABLED;
6972 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006973
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006974 if (bp->state == BNX2X_STATE_OPEN)
6975 for_each_nondefault_queue(bp, i) {
6976 rc = bnx2x_setup_multi(bp, i);
6977 if (rc)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006978 goto load_error3;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006979 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006980
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006981 if (CHIP_IS_E1(bp))
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006982 bnx2x_set_mac_addr_e1(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006983 else
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006984 bnx2x_set_mac_addr_e1h(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006985
6986 if (bp->port.pmf)
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00006987 bnx2x_initial_phy_init(bp, load_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006988
6989 /* Start fast path */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006990 switch (load_mode) {
6991 case LOAD_NORMAL:
6992 /* Tx queue should be only reenabled */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006993 netif_tx_wake_all_queues(bp->dev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00006994 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006995 bnx2x_set_rx_mode(bp->dev);
6996 break;
6997
6998 case LOAD_OPEN:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006999 netif_tx_start_all_queues(bp->dev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007000 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007001 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007002 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007003
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007004 case LOAD_DIAG:
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007005 /* Initialize the receive filter. */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007006 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007007 bp->state = BNX2X_STATE_DIAG;
7008 break;
7009
7010 default:
7011 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007012 }
7013
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007014 if (!bp->port.pmf)
7015 bnx2x__link_status_update(bp);
7016
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007017 /* start the timer */
7018 mod_timer(&bp->timer, jiffies + bp->current_interval);
7019
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007020
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007021 return 0;
7022
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007023load_error3:
7024 bnx2x_int_disable_sync(bp, 1);
7025 if (!BP_NOMCP(bp)) {
7026 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP);
7027 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7028 }
7029 bp->port.pmf = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007030 /* Free SKBs, SGEs, TPA pool and driver internals */
7031 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007032 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07007033 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007034load_error2:
Yitchak Gertnerd1014632008-08-25 15:25:45 -07007035 /* Release IRQs */
7036 bnx2x_free_irq(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007037load_error1:
7038 bnx2x_napi_disable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007039 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00007040 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007041 bnx2x_free_mem(bp);
7042
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007043 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007044}
7045
7046static int bnx2x_stop_multi(struct bnx2x *bp, int index)
7047{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007048 struct bnx2x_fastpath *fp = &bp->fp[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007049 int rc;
7050
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007051 /* halt the connection */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007052 fp->state = BNX2X_FP_STATE_HALTING;
7053 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007054
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007055 /* Wait for completion */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007056 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007057 &(fp->state), 1);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007058 if (rc) /* timeout */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007059 return rc;
7060
7061 /* delete cfc entry */
7062 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
7063
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007064 /* Wait for completion */
7065 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007066 &(fp->state), 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007067 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007068}
7069
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007070static int bnx2x_stop_leading(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007071{
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00007072 __le16 dsb_sp_prod_idx;
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007073 /* if the other port is handling traffic,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007074 this can take a lot of time */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007075 int cnt = 500;
7076 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007077
7078 might_sleep();
7079
7080 /* Send HALT ramrod */
7081 bp->fp[0].state = BNX2X_FP_STATE_HALTING;
Eilon Greenstein0626b892009-02-12 08:38:14 +00007082 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007083
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007084 /* Wait for completion */
7085 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
7086 &(bp->fp[0].state), 1);
7087 if (rc) /* timeout */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007088 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007089
Eliezer Tamir49d66772008-02-28 11:53:13 -08007090 dsb_sp_prod_idx = *bp->dsb_sp_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007091
Eliezer Tamir228241e2008-02-28 11:56:57 -08007092 /* Send PORT_DELETE ramrod */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007093 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
7094
Eliezer Tamir49d66772008-02-28 11:53:13 -08007095 /* Wait for completion to arrive on default status block
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007096 we are going to reset the chip anyway
7097 so there is not much to do if this times out
7098 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007099 while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007100 if (!cnt) {
7101 DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
7102 "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
7103 *bp->dsb_sp_prod, dsb_sp_prod_idx);
7104#ifdef BNX2X_STOP_ON_ERROR
7105 bnx2x_panic();
7106#endif
Eilon Greenstein36e552a2009-02-12 08:37:21 +00007107 rc = -EBUSY;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007108 break;
7109 }
7110 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007111 msleep(1);
Eilon Greenstein5650d9d2009-01-22 06:01:29 +00007112 rmb(); /* Refresh the dsb_sp_prod */
Eliezer Tamir49d66772008-02-28 11:53:13 -08007113 }
7114 bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
7115 bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007116
7117 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007118}
7119
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007120static void bnx2x_reset_func(struct bnx2x *bp)
7121{
7122 int port = BP_PORT(bp);
7123 int func = BP_FUNC(bp);
7124 int base, i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08007125
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007126 /* Configure IGU */
7127 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7128 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7129
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007130 /* Clear ILT */
7131 base = FUNC_ILT_BASE(func);
7132 for (i = base; i < base + ILT_PER_FUNC; i++)
7133 bnx2x_ilt_wr(bp, i, 0);
7134}
7135
7136static void bnx2x_reset_port(struct bnx2x *bp)
7137{
7138 int port = BP_PORT(bp);
7139 u32 val;
7140
7141 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7142
7143 /* Do not rcv packets to BRB */
7144 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7145 /* Do not direct rcv packets that are not for MCP to the BRB */
7146 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7147 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7148
7149 /* Configure AEU */
7150 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7151
7152 msleep(100);
7153 /* Check for BRB port occupancy */
7154 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7155 if (val)
7156 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07007157 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007158
7159 /* TODO: Close Doorbell port? */
7160}
7161
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007162static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
7163{
7164 DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
7165 BP_FUNC(bp), reset_code);
7166
7167 switch (reset_code) {
7168 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
7169 bnx2x_reset_port(bp);
7170 bnx2x_reset_func(bp);
7171 bnx2x_reset_common(bp);
7172 break;
7173
7174 case FW_MSG_CODE_DRV_UNLOAD_PORT:
7175 bnx2x_reset_port(bp);
7176 bnx2x_reset_func(bp);
7177 break;
7178
7179 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
7180 bnx2x_reset_func(bp);
7181 break;
7182
7183 default:
7184 BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
7185 break;
7186 }
7187}
7188
Eilon Greenstein33471622008-08-13 15:59:08 -07007189/* must be called with rtnl_lock */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007190static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007191{
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007192 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007193 u32 reset_code = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007194 int i, cnt, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007195
7196 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
7197
Eliezer Tamir228241e2008-02-28 11:56:57 -08007198 bp->rx_mode = BNX2X_RX_MODE_NONE;
7199 bnx2x_set_storm_rx_mode(bp);
7200
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07007201 bnx2x_netif_stop(bp, 1);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00007202
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007203 del_timer_sync(&bp->timer);
7204 SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb,
7205 (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07007206 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007207
Eilon Greenstein70b99862009-01-14 06:43:48 +00007208 /* Release IRQs */
7209 bnx2x_free_irq(bp);
7210
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007211 /* Wait until tx fastpath tasks complete */
7212 for_each_tx_queue(bp, i) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08007213 struct bnx2x_fastpath *fp = &bp->fp[i];
7214
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007215 cnt = 1000;
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -08007216 while (bnx2x_has_tx_work_unload(fp)) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007217
Eilon Greenstein7961f792009-03-02 07:59:31 +00007218 bnx2x_tx_int(fp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007219 if (!cnt) {
7220 BNX2X_ERR("timeout waiting for queue[%d]\n",
7221 i);
7222#ifdef BNX2X_STOP_ON_ERROR
7223 bnx2x_panic();
7224 return -EBUSY;
7225#else
7226 break;
7227#endif
7228 }
7229 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007230 msleep(1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007231 }
Eliezer Tamir228241e2008-02-28 11:56:57 -08007232 }
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007233 /* Give HW time to discard old tx messages */
7234 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007235
Yitchak Gertner65abd742008-08-25 15:26:24 -07007236 if (CHIP_IS_E1(bp)) {
7237 struct mac_configuration_cmd *config =
7238 bnx2x_sp(bp, mcast_config);
7239
7240 bnx2x_set_mac_addr_e1(bp, 0);
7241
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007242 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007243 CAM_INVALIDATE(config->config_table[i]);
7244
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007245 config->hdr.length = i;
Yitchak Gertner65abd742008-08-25 15:26:24 -07007246 if (CHIP_REV_IS_SLOW(bp))
7247 config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
7248 else
7249 config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
Eilon Greenstein0626b892009-02-12 08:38:14 +00007250 config->hdr.client_id = bp->fp->cl_id;
Yitchak Gertner65abd742008-08-25 15:26:24 -07007251 config->hdr.reserved1 = 0;
7252
7253 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
7254 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
7255 U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
7256
7257 } else { /* E1H */
7258 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7259
7260 bnx2x_set_mac_addr_e1h(bp, 0);
7261
7262 for (i = 0; i < MC_HASH_SIZE; i++)
7263 REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
7264 }
7265
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007266 if (unload_mode == UNLOAD_NORMAL)
7267 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007268
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007269 else if (bp->flags & NO_WOL_FLAG) {
7270 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7271 if (CHIP_IS_E1H(bp))
7272 REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
7273
7274 } else if (bp->wol) {
7275 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007276 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007277 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007278 /* The mac address is written to entries 1-4 to
7279 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007280 u8 entry = (BP_E1HVN(bp) + 1)*8;
7281
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007282 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007283 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007284
7285 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7286 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007287 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007288
7289 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007290
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007291 } else
7292 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7293
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007294 /* Close multi and leading connections
7295 Completions for ramrods are collected in a synchronous way */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007296 for_each_nondefault_queue(bp, i)
7297 if (bnx2x_stop_multi(bp, i))
Eliezer Tamir228241e2008-02-28 11:56:57 -08007298 goto unload_error;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007299
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007300 rc = bnx2x_stop_leading(bp);
7301 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007302 BNX2X_ERR("Stop leading failed!\n");
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007303#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007304 return -EBUSY;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007305#else
7306 goto unload_error;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007307#endif
Eliezer Tamir228241e2008-02-28 11:56:57 -08007308 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007309
Eliezer Tamir228241e2008-02-28 11:56:57 -08007310unload_error:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007311 if (!BP_NOMCP(bp))
Eliezer Tamir228241e2008-02-28 11:56:57 -08007312 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007313 else {
Eilon Greensteinf5372252009-02-12 08:38:30 +00007314 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007315 load_count[0], load_count[1], load_count[2]);
7316 load_count[0]--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007317 load_count[1 + port]--;
Eilon Greensteinf5372252009-02-12 08:38:30 +00007318 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007319 load_count[0], load_count[1], load_count[2]);
7320 if (load_count[0] == 0)
7321 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007322 else if (load_count[1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007323 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7324 else
7325 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7326 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007327
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007328 if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
7329 (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
7330 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007331
7332 /* Reset the chip */
Eliezer Tamir228241e2008-02-28 11:56:57 -08007333 bnx2x_reset_chip(bp, reset_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007334
7335 /* Report UNLOAD_DONE to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007336 if (!BP_NOMCP(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007337 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007338
Eilon Greenstein9a035442008-11-03 16:45:55 -08007339 bp->port.pmf = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007340
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007341 /* Free SKBs, SGEs, TPA pool and driver internals */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007342 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007343 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07007344 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007345 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00007346 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007347 bnx2x_free_mem(bp);
7348
7349 bp->state = BNX2X_STATE_CLOSED;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007350
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007351 netif_carrier_off(bp->dev);
7352
7353 return 0;
7354}
7355
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007356static void bnx2x_reset_task(struct work_struct *work)
7357{
7358 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task);
7359
7360#ifdef BNX2X_STOP_ON_ERROR
7361 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7362 " so reset not done to allow debug dump,\n"
7363 KERN_ERR " you will need to reboot when done\n");
7364 return;
7365#endif
7366
7367 rtnl_lock();
7368
7369 if (!netif_running(bp->dev))
7370 goto reset_task_exit;
7371
7372 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7373 bnx2x_nic_load(bp, LOAD_NORMAL);
7374
7375reset_task_exit:
7376 rtnl_unlock();
7377}
7378
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007379/* end of nic load/unload */
7380
7381/* ethtool_ops */
7382
7383/*
7384 * Init service functions
7385 */
7386
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007387static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
7388{
7389 switch (func) {
7390 case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
7391 case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
7392 case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
7393 case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
7394 case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
7395 case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
7396 case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
7397 case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
7398 default:
7399 BNX2X_ERR("Unsupported function index: %d\n", func);
7400 return (u32)(-1);
7401 }
7402}
7403
7404static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
7405{
7406 u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
7407
7408 /* Flush all outstanding writes */
7409 mmiowb();
7410
7411 /* Pretend to be function 0 */
7412 REG_WR(bp, reg, 0);
7413 /* Flush the GRC transaction (in the chip) */
7414 new_val = REG_RD(bp, reg);
7415 if (new_val != 0) {
7416 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
7417 new_val);
7418 BUG();
7419 }
7420
7421 /* From now we are in the "like-E1" mode */
7422 bnx2x_int_disable(bp);
7423
7424 /* Flush all outstanding writes */
7425 mmiowb();
7426
7427 /* Restore the original funtion settings */
7428 REG_WR(bp, reg, orig_func);
7429 new_val = REG_RD(bp, reg);
7430 if (new_val != orig_func) {
7431 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
7432 orig_func, new_val);
7433 BUG();
7434 }
7435}
7436
7437static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
7438{
7439 if (CHIP_IS_E1H(bp))
7440 bnx2x_undi_int_disable_e1h(bp, func);
7441 else
7442 bnx2x_int_disable(bp);
7443}
7444
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007445static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007446{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007447 u32 val;
7448
7449 /* Check if there is any driver already loaded */
7450 val = REG_RD(bp, MISC_REG_UNPREPARED);
7451 if (val == 0x1) {
7452 /* Check if it is the UNDI driver
7453 * UNDI driver initializes CID offset for normal bell to 0x7
7454 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07007455 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007456 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
7457 if (val == 0x7) {
7458 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007459 /* save our func */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007460 int func = BP_FUNC(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007461 u32 swap_en;
7462 u32 swap_val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007463
Eilon Greensteinb4661732009-01-14 06:43:56 +00007464 /* clear the UNDI indication */
7465 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
7466
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007467 BNX2X_DEV_INFO("UNDI is active! reset device\n");
7468
7469 /* try unload UNDI on port 0 */
7470 bp->func = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007471 bp->fw_seq =
7472 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7473 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007474 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007475
7476 /* if UNDI is loaded on the other port */
7477 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
7478
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007479 /* send "DONE" for previous unload */
7480 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7481
7482 /* unload UNDI on port 1 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007483 bp->func = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007484 bp->fw_seq =
7485 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7486 DRV_MSG_SEQ_NUMBER_MASK);
7487 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007488
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007489 bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007490 }
7491
Eilon Greensteinb4661732009-01-14 06:43:56 +00007492 /* now it's safe to release the lock */
7493 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
7494
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007495 bnx2x_undi_int_disable(bp, func);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007496
7497 /* close input traffic and wait for it */
7498 /* Do not rcv packets to BRB */
7499 REG_WR(bp,
7500 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
7501 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
7502 /* Do not direct rcv packets that are not for MCP to
7503 * the BRB */
7504 REG_WR(bp,
7505 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
7506 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7507 /* clear AEU */
7508 REG_WR(bp,
7509 (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7510 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
7511 msleep(10);
7512
7513 /* save NIG port swap info */
7514 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7515 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007516 /* reset device */
7517 REG_WR(bp,
7518 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007519 0xd3ffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007520 REG_WR(bp,
7521 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7522 0x1403);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007523 /* take the NIG out of reset and restore swap values */
7524 REG_WR(bp,
7525 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7526 MISC_REGISTERS_RESET_REG_1_RST_NIG);
7527 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
7528 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
7529
7530 /* send unload done to the MCP */
7531 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7532
7533 /* restore our func and fw_seq */
7534 bp->func = func;
7535 bp->fw_seq =
7536 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7537 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00007538
7539 } else
7540 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007541 }
7542}
7543
7544static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
7545{
7546 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007547 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007548
7549 /* Get the chip revision id and number. */
7550 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
7551 val = REG_RD(bp, MISC_REG_CHIP_NUM);
7552 id = ((val & 0xffff) << 16);
7553 val = REG_RD(bp, MISC_REG_CHIP_REV);
7554 id |= ((val & 0xf) << 12);
7555 val = REG_RD(bp, MISC_REG_CHIP_METAL);
7556 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00007557 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007558 id |= (val & 0xf);
7559 bp->common.chip_id = id;
7560 bp->link_params.chip_id = bp->common.chip_id;
7561 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
7562
Eilon Greenstein1c063282009-02-12 08:36:43 +00007563 val = (REG_RD(bp, 0x2874) & 0x55);
7564 if ((bp->common.chip_id & 0x1) ||
7565 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
7566 bp->flags |= ONE_PORT_FLAG;
7567 BNX2X_DEV_INFO("single port device\n");
7568 }
7569
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007570 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
7571 bp->common.flash_size = (NVRAM_1MB_SIZE <<
7572 (val & MCPR_NVM_CFG4_FLASH_SIZE));
7573 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
7574 bp->common.flash_size, bp->common.flash_size);
7575
7576 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7577 bp->link_params.shmem_base = bp->common.shmem_base;
7578 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
7579
7580 if (!bp->common.shmem_base ||
7581 (bp->common.shmem_base < 0xA0000) ||
7582 (bp->common.shmem_base >= 0xC0000)) {
7583 BNX2X_DEV_INFO("MCP not active\n");
7584 bp->flags |= NO_MCP_FLAG;
7585 return;
7586 }
7587
7588 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7589 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
7590 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
7591 BNX2X_ERR("BAD MCP validity signature\n");
7592
7593 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00007594 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007595
7596 bp->link_params.hw_led_mode = ((bp->common.hw_config &
7597 SHARED_HW_CFG_LED_MODE_MASK) >>
7598 SHARED_HW_CFG_LED_MODE_SHIFT);
7599
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007600 bp->link_params.feature_config_flags = 0;
7601 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
7602 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
7603 bp->link_params.feature_config_flags |=
7604 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7605 else
7606 bp->link_params.feature_config_flags &=
7607 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7608
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007609 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
7610 bp->common.bc_ver = val;
7611 BNX2X_DEV_INFO("bc_ver %X\n", val);
7612 if (val < BNX2X_BC_VER) {
7613 /* for now only warn
7614 * later we might need to enforce this */
7615 BNX2X_ERR("This driver needs bc_ver %X but found %X,"
7616 " please upgrade BC\n", BNX2X_BC_VER, val);
7617 }
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007618
7619 if (BP_E1HVN(bp) == 0) {
7620 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
7621 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
7622 } else {
7623 /* no WOL capability for E1HVN != 0 */
7624 bp->flags |= NO_WOL_FLAG;
7625 }
7626 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +00007627 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007628
7629 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
7630 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
7631 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
7632 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
7633
7634 printk(KERN_INFO PFX "part number %X-%X-%X-%X\n",
7635 val, val2, val3, val4);
7636}
7637
7638static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
7639 u32 switch_cfg)
7640{
7641 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007642 u32 ext_phy_type;
7643
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007644 switch (switch_cfg) {
7645 case SWITCH_CFG_1G:
7646 BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
7647
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007648 ext_phy_type =
7649 SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007650 switch (ext_phy_type) {
7651 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
7652 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7653 ext_phy_type);
7654
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007655 bp->port.supported |= (SUPPORTED_10baseT_Half |
7656 SUPPORTED_10baseT_Full |
7657 SUPPORTED_100baseT_Half |
7658 SUPPORTED_100baseT_Full |
7659 SUPPORTED_1000baseT_Full |
7660 SUPPORTED_2500baseX_Full |
7661 SUPPORTED_TP |
7662 SUPPORTED_FIBRE |
7663 SUPPORTED_Autoneg |
7664 SUPPORTED_Pause |
7665 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007666 break;
7667
7668 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
7669 BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
7670 ext_phy_type);
7671
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007672 bp->port.supported |= (SUPPORTED_10baseT_Half |
7673 SUPPORTED_10baseT_Full |
7674 SUPPORTED_100baseT_Half |
7675 SUPPORTED_100baseT_Full |
7676 SUPPORTED_1000baseT_Full |
7677 SUPPORTED_TP |
7678 SUPPORTED_FIBRE |
7679 SUPPORTED_Autoneg |
7680 SUPPORTED_Pause |
7681 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007682 break;
7683
7684 default:
7685 BNX2X_ERR("NVRAM config error. "
7686 "BAD SerDes ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007687 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007688 return;
7689 }
7690
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007691 bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
7692 port*0x10);
7693 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007694 break;
7695
7696 case SWITCH_CFG_10G:
7697 BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
7698
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007699 ext_phy_type =
7700 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007701 switch (ext_phy_type) {
7702 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7703 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7704 ext_phy_type);
7705
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007706 bp->port.supported |= (SUPPORTED_10baseT_Half |
7707 SUPPORTED_10baseT_Full |
7708 SUPPORTED_100baseT_Half |
7709 SUPPORTED_100baseT_Full |
7710 SUPPORTED_1000baseT_Full |
7711 SUPPORTED_2500baseX_Full |
7712 SUPPORTED_10000baseT_Full |
7713 SUPPORTED_TP |
7714 SUPPORTED_FIBRE |
7715 SUPPORTED_Autoneg |
7716 SUPPORTED_Pause |
7717 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007718 break;
7719
Eliezer Tamirf1410642008-02-28 11:51:50 -08007720 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
7721 BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
7722 ext_phy_type);
7723
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007724 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7725 SUPPORTED_1000baseT_Full |
7726 SUPPORTED_FIBRE |
7727 SUPPORTED_Autoneg |
7728 SUPPORTED_Pause |
7729 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007730 break;
7731
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007732 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
7733 BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
7734 ext_phy_type);
7735
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007736 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7737 SUPPORTED_2500baseX_Full |
7738 SUPPORTED_1000baseT_Full |
7739 SUPPORTED_FIBRE |
7740 SUPPORTED_Autoneg |
7741 SUPPORTED_Pause |
7742 SUPPORTED_Asym_Pause);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007743 break;
7744
Eilon Greenstein589abe32009-02-12 08:36:55 +00007745 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7746 BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
7747 ext_phy_type);
7748
7749 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7750 SUPPORTED_FIBRE |
7751 SUPPORTED_Pause |
7752 SUPPORTED_Asym_Pause);
7753 break;
7754
7755 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7756 BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
7757 ext_phy_type);
7758
7759 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7760 SUPPORTED_1000baseT_Full |
7761 SUPPORTED_FIBRE |
7762 SUPPORTED_Pause |
7763 SUPPORTED_Asym_Pause);
7764 break;
7765
7766 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7767 BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
7768 ext_phy_type);
7769
7770 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7771 SUPPORTED_1000baseT_Full |
7772 SUPPORTED_Autoneg |
7773 SUPPORTED_FIBRE |
7774 SUPPORTED_Pause |
7775 SUPPORTED_Asym_Pause);
7776 break;
7777
Eliezer Tamirf1410642008-02-28 11:51:50 -08007778 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7779 BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
7780 ext_phy_type);
7781
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007782 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7783 SUPPORTED_TP |
7784 SUPPORTED_Autoneg |
7785 SUPPORTED_Pause |
7786 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007787 break;
7788
Eilon Greenstein28577182009-02-12 08:37:00 +00007789 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7790 BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
7791 ext_phy_type);
7792
7793 bp->port.supported |= (SUPPORTED_10baseT_Half |
7794 SUPPORTED_10baseT_Full |
7795 SUPPORTED_100baseT_Half |
7796 SUPPORTED_100baseT_Full |
7797 SUPPORTED_1000baseT_Full |
7798 SUPPORTED_10000baseT_Full |
7799 SUPPORTED_TP |
7800 SUPPORTED_Autoneg |
7801 SUPPORTED_Pause |
7802 SUPPORTED_Asym_Pause);
7803 break;
7804
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007805 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7806 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
7807 bp->link_params.ext_phy_config);
7808 break;
7809
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007810 default:
7811 BNX2X_ERR("NVRAM config error. "
7812 "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007813 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007814 return;
7815 }
7816
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007817 bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
7818 port*0x18);
7819 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007820
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007821 break;
7822
7823 default:
7824 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007825 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007826 return;
7827 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007828 bp->link_params.phy_addr = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007829
7830 /* mask what we support according to speed_cap_mask */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007831 if (!(bp->link_params.speed_cap_mask &
7832 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007833 bp->port.supported &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007834
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007835 if (!(bp->link_params.speed_cap_mask &
7836 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007837 bp->port.supported &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007838
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007839 if (!(bp->link_params.speed_cap_mask &
7840 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007841 bp->port.supported &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007842
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007843 if (!(bp->link_params.speed_cap_mask &
7844 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007845 bp->port.supported &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007846
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007847 if (!(bp->link_params.speed_cap_mask &
7848 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007849 bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
7850 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007851
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007852 if (!(bp->link_params.speed_cap_mask &
7853 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007854 bp->port.supported &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007855
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007856 if (!(bp->link_params.speed_cap_mask &
7857 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007858 bp->port.supported &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007859
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007860 BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007861}
7862
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007863static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007864{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007865 bp->link_params.req_duplex = DUPLEX_FULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007866
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007867 switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007868 case PORT_FEATURE_LINK_SPEED_AUTO:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007869 if (bp->port.supported & SUPPORTED_Autoneg) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007870 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007871 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007872 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007873 u32 ext_phy_type =
7874 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
7875
7876 if ((ext_phy_type ==
7877 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
7878 (ext_phy_type ==
7879 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007880 /* force 10G, no AN */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007881 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007882 bp->port.advertising =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007883 (ADVERTISED_10000baseT_Full |
7884 ADVERTISED_FIBRE);
7885 break;
7886 }
7887 BNX2X_ERR("NVRAM config error. "
7888 "Invalid link_config 0x%x"
7889 " Autoneg not supported\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007890 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007891 return;
7892 }
7893 break;
7894
7895 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007896 if (bp->port.supported & SUPPORTED_10baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007897 bp->link_params.req_line_speed = SPEED_10;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007898 bp->port.advertising = (ADVERTISED_10baseT_Full |
7899 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007900 } else {
7901 BNX2X_ERR("NVRAM config error. "
7902 "Invalid link_config 0x%x"
7903 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007904 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007905 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007906 return;
7907 }
7908 break;
7909
7910 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007911 if (bp->port.supported & SUPPORTED_10baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007912 bp->link_params.req_line_speed = SPEED_10;
7913 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007914 bp->port.advertising = (ADVERTISED_10baseT_Half |
7915 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007916 } else {
7917 BNX2X_ERR("NVRAM config error. "
7918 "Invalid link_config 0x%x"
7919 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007920 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007921 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007922 return;
7923 }
7924 break;
7925
7926 case PORT_FEATURE_LINK_SPEED_100M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007927 if (bp->port.supported & SUPPORTED_100baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007928 bp->link_params.req_line_speed = SPEED_100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007929 bp->port.advertising = (ADVERTISED_100baseT_Full |
7930 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007931 } else {
7932 BNX2X_ERR("NVRAM config error. "
7933 "Invalid link_config 0x%x"
7934 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007935 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007936 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007937 return;
7938 }
7939 break;
7940
7941 case PORT_FEATURE_LINK_SPEED_100M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007942 if (bp->port.supported & SUPPORTED_100baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007943 bp->link_params.req_line_speed = SPEED_100;
7944 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007945 bp->port.advertising = (ADVERTISED_100baseT_Half |
7946 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007947 } else {
7948 BNX2X_ERR("NVRAM config error. "
7949 "Invalid link_config 0x%x"
7950 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007951 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007952 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007953 return;
7954 }
7955 break;
7956
7957 case PORT_FEATURE_LINK_SPEED_1G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007958 if (bp->port.supported & SUPPORTED_1000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007959 bp->link_params.req_line_speed = SPEED_1000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007960 bp->port.advertising = (ADVERTISED_1000baseT_Full |
7961 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007962 } else {
7963 BNX2X_ERR("NVRAM config error. "
7964 "Invalid link_config 0x%x"
7965 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007966 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007967 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007968 return;
7969 }
7970 break;
7971
7972 case PORT_FEATURE_LINK_SPEED_2_5G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007973 if (bp->port.supported & SUPPORTED_2500baseX_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007974 bp->link_params.req_line_speed = SPEED_2500;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007975 bp->port.advertising = (ADVERTISED_2500baseX_Full |
7976 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007977 } else {
7978 BNX2X_ERR("NVRAM config error. "
7979 "Invalid link_config 0x%x"
7980 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007981 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007982 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007983 return;
7984 }
7985 break;
7986
7987 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7988 case PORT_FEATURE_LINK_SPEED_10G_KX4:
7989 case PORT_FEATURE_LINK_SPEED_10G_KR:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007990 if (bp->port.supported & SUPPORTED_10000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007991 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007992 bp->port.advertising = (ADVERTISED_10000baseT_Full |
7993 ADVERTISED_FIBRE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007994 } else {
7995 BNX2X_ERR("NVRAM config error. "
7996 "Invalid link_config 0x%x"
7997 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007998 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007999 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008000 return;
8001 }
8002 break;
8003
8004 default:
8005 BNX2X_ERR("NVRAM config error. "
8006 "BAD link speed link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008007 bp->port.link_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008008 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008009 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008010 break;
8011 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008012
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008013 bp->link_params.req_flow_ctrl = (bp->port.link_config &
8014 PORT_FEATURE_FLOW_CONTROL_MASK);
David S. Millerc0700f92008-12-16 23:53:20 -08008015 if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Randy Dunlap4ab84d42008-08-07 20:33:19 -07008016 !(bp->port.supported & SUPPORTED_Autoneg))
David S. Millerc0700f92008-12-16 23:53:20 -08008017 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008018
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008019 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
Eliezer Tamirf1410642008-02-28 11:51:50 -08008020 " advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008021 bp->link_params.req_line_speed,
8022 bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008023 bp->link_params.req_flow_ctrl, bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008024}
8025
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008026static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008027{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008028 int port = BP_PORT(bp);
8029 u32 val, val2;
Eilon Greenstein589abe32009-02-12 08:36:55 +00008030 u32 config;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008031 u16 i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008032
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008033 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008034 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008035
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008036 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008037 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008038 bp->link_params.ext_phy_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008039 SHMEM_RD(bp,
8040 dev_info.port_hw_config[port].external_phy_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008041 bp->link_params.speed_cap_mask =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008042 SHMEM_RD(bp,
8043 dev_info.port_hw_config[port].speed_capability_mask);
8044
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008045 bp->port.link_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008046 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8047
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008048 /* Get the 4 lanes xgxs config rx and tx */
8049 for (i = 0; i < 2; i++) {
8050 val = SHMEM_RD(bp,
8051 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
8052 bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
8053 bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
8054
8055 val = SHMEM_RD(bp,
8056 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
8057 bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
8058 bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
8059 }
8060
Eilon Greenstein589abe32009-02-12 08:36:55 +00008061 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
8062 if (config & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_ENABLED)
8063 bp->link_params.feature_config_flags |=
8064 FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
8065 else
8066 bp->link_params.feature_config_flags &=
8067 ~FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
8068
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008069 /* If the device is capable of WoL, set the default state according
8070 * to the HW
8071 */
8072 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8073 (config & PORT_FEATURE_WOL_ENABLED));
8074
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008075 BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
8076 " speed_cap_mask 0x%08x link_config 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008077 bp->link_params.lane_config,
8078 bp->link_params.ext_phy_config,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008079 bp->link_params.speed_cap_mask, bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008080
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008081 bp->link_params.switch_cfg = (bp->port.link_config &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008082 PORT_FEATURE_CONNECTED_SWITCH_MASK);
8083 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008084
8085 bnx2x_link_settings_requested(bp);
8086
8087 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8088 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8089 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
8090 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8091 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8092 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8093 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8094 bp->dev->dev_addr[5] = (u8)(val & 0xff);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008095 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8096 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008097}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008098
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008099static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8100{
8101 int func = BP_FUNC(bp);
8102 u32 val, val2;
8103 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008104
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008105 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008106
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008107 bp->e1hov = 0;
8108 bp->e1hmf = 0;
8109 if (CHIP_IS_E1H(bp)) {
8110 bp->mf_config =
8111 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008112
Eilon Greenstein3196a882008-08-13 15:58:49 -07008113 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].e1hov_tag) &
8114 FUNC_MF_CFG_E1HOV_TAG_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008115 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008116
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008117 bp->e1hov = val;
8118 bp->e1hmf = 1;
8119 BNX2X_DEV_INFO("MF mode E1HOV for func %d is %d "
8120 "(0x%04x)\n",
8121 func, bp->e1hov, bp->e1hov);
8122 } else {
Eilon Greensteinf5372252009-02-12 08:38:30 +00008123 BNX2X_DEV_INFO("single function mode\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008124 if (BP_E1HVN(bp)) {
8125 BNX2X_ERR("!!! No valid E1HOV for func %d,"
8126 " aborting\n", func);
8127 rc = -EPERM;
8128 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008129 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008130 }
8131
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008132 if (!BP_NOMCP(bp)) {
8133 bnx2x_get_port_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008134
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008135 bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
8136 DRV_MSG_SEQ_NUMBER_MASK);
8137 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
8138 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008139
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008140 if (IS_E1HMF(bp)) {
8141 val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
8142 val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
8143 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8144 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
8145 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
8146 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8147 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8148 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8149 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8150 bp->dev->dev_addr[5] = (u8)(val & 0xff);
8151 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
8152 ETH_ALEN);
8153 memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
8154 ETH_ALEN);
8155 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008156
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008157 return rc;
8158 }
8159
8160 if (BP_NOMCP(bp)) {
8161 /* only supposed to happen on emulation/FPGA */
Eilon Greenstein33471622008-08-13 15:59:08 -07008162 BNX2X_ERR("warning random MAC workaround active\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008163 random_ether_addr(bp->dev->dev_addr);
8164 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8165 }
8166
8167 return rc;
8168}
8169
8170static int __devinit bnx2x_init_bp(struct bnx2x *bp)
8171{
8172 int func = BP_FUNC(bp);
Eilon Greenstein87942b42009-02-12 08:36:49 +00008173 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008174 int rc;
8175
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008176 /* Disable interrupt handling until HW is initialized */
8177 atomic_set(&bp->intr_sem, 1);
8178
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008179 mutex_init(&bp->port.phy_mutex);
8180
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08008181 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008182 INIT_WORK(&bp->reset_task, bnx2x_reset_task);
8183
8184 rc = bnx2x_get_hwinfo(bp);
8185
8186 /* need to reset chip if undi was active */
8187 if (!BP_NOMCP(bp))
8188 bnx2x_undi_unload(bp);
8189
8190 if (CHIP_REV_IS_FPGA(bp))
8191 printk(KERN_ERR PFX "FPGA detected\n");
8192
8193 if (BP_NOMCP(bp) && (func == 0))
8194 printk(KERN_ERR PFX
8195 "MCP disabled, must load devices in order!\n");
8196
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008197 /* Set multi queue mode */
Eilon Greenstein8badd272009-02-12 08:36:15 +00008198 if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
8199 ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008200 printk(KERN_ERR PFX
Eilon Greenstein8badd272009-02-12 08:36:15 +00008201 "Multi disabled since int_mode requested is not MSI-X\n");
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008202 multi_mode = ETH_RSS_MODE_DISABLED;
8203 }
8204 bp->multi_mode = multi_mode;
8205
8206
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008207 /* Set TPA flags */
8208 if (disable_tpa) {
8209 bp->flags &= ~TPA_ENABLE_FLAG;
8210 bp->dev->features &= ~NETIF_F_LRO;
8211 } else {
8212 bp->flags |= TPA_ENABLE_FLAG;
8213 bp->dev->features |= NETIF_F_LRO;
8214 }
8215
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00008216 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008217
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008218 bp->tx_ring_size = MAX_TX_AVAIL;
8219 bp->rx_ring_size = MAX_RX_AVAIL;
8220
8221 bp->rx_csum = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008222
8223 bp->tx_ticks = 50;
8224 bp->rx_ticks = 25;
8225
Eilon Greenstein87942b42009-02-12 08:36:49 +00008226 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
8227 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008228
8229 init_timer(&bp->timer);
8230 bp->timer.expires = jiffies + bp->current_interval;
8231 bp->timer.data = (unsigned long) bp;
8232 bp->timer.function = bnx2x_timer;
8233
8234 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008235}
8236
8237/*
8238 * ethtool service functions
8239 */
8240
8241/* All ethtool functions called with rtnl_lock */
8242
8243static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8244{
8245 struct bnx2x *bp = netdev_priv(dev);
8246
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008247 cmd->supported = bp->port.supported;
8248 cmd->advertising = bp->port.advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008249
8250 if (netif_carrier_ok(dev)) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008251 cmd->speed = bp->link_vars.line_speed;
8252 cmd->duplex = bp->link_vars.duplex;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008253 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008254 cmd->speed = bp->link_params.req_line_speed;
8255 cmd->duplex = bp->link_params.req_duplex;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008256 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008257 if (IS_E1HMF(bp)) {
8258 u16 vn_max_rate;
8259
8260 vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
8261 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
8262 if (vn_max_rate < cmd->speed)
8263 cmd->speed = vn_max_rate;
8264 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008265
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008266 if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
8267 u32 ext_phy_type =
8268 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamirf1410642008-02-28 11:51:50 -08008269
8270 switch (ext_phy_type) {
8271 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008272 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008273 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greenstein589abe32009-02-12 08:36:55 +00008274 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
8275 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
8276 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008277 cmd->port = PORT_FIBRE;
8278 break;
8279
8280 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein28577182009-02-12 08:37:00 +00008281 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008282 cmd->port = PORT_TP;
8283 break;
8284
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008285 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8286 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
8287 bp->link_params.ext_phy_config);
8288 break;
8289
Eliezer Tamirf1410642008-02-28 11:51:50 -08008290 default:
8291 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008292 bp->link_params.ext_phy_config);
8293 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008294 }
8295 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008296 cmd->port = PORT_TP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008297
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008298 cmd->phy_address = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008299 cmd->transceiver = XCVR_INTERNAL;
8300
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008301 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008302 cmd->autoneg = AUTONEG_ENABLE;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008303 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008304 cmd->autoneg = AUTONEG_DISABLE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008305
8306 cmd->maxtxpkt = 0;
8307 cmd->maxrxpkt = 0;
8308
8309 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
8310 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
8311 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
8312 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
8313 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
8314 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
8315 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
8316
8317 return 0;
8318}
8319
8320static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8321{
8322 struct bnx2x *bp = netdev_priv(dev);
8323 u32 advertising;
8324
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008325 if (IS_E1HMF(bp))
8326 return 0;
8327
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008328 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
8329 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
8330 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
8331 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
8332 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
8333 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
8334 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
8335
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008336 if (cmd->autoneg == AUTONEG_ENABLE) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008337 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
8338 DP(NETIF_MSG_LINK, "Autoneg not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008339 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008340 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008341
8342 /* advertise the requested speed and duplex if supported */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008343 cmd->advertising &= bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008344
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008345 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
8346 bp->link_params.req_duplex = DUPLEX_FULL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008347 bp->port.advertising |= (ADVERTISED_Autoneg |
8348 cmd->advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008349
8350 } else { /* forced speed */
8351 /* advertise the requested speed and duplex if supported */
8352 switch (cmd->speed) {
8353 case SPEED_10:
8354 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008355 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008356 SUPPORTED_10baseT_Full)) {
8357 DP(NETIF_MSG_LINK,
8358 "10M full 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
8362 advertising = (ADVERTISED_10baseT_Full |
8363 ADVERTISED_TP);
8364 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008365 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008366 SUPPORTED_10baseT_Half)) {
8367 DP(NETIF_MSG_LINK,
8368 "10M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008369 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008370 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008371
8372 advertising = (ADVERTISED_10baseT_Half |
8373 ADVERTISED_TP);
8374 }
8375 break;
8376
8377 case SPEED_100:
8378 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008379 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008380 SUPPORTED_100baseT_Full)) {
8381 DP(NETIF_MSG_LINK,
8382 "100M full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008383 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008384 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008385
8386 advertising = (ADVERTISED_100baseT_Full |
8387 ADVERTISED_TP);
8388 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008389 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08008390 SUPPORTED_100baseT_Half)) {
8391 DP(NETIF_MSG_LINK,
8392 "100M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008393 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008394 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008395
8396 advertising = (ADVERTISED_100baseT_Half |
8397 ADVERTISED_TP);
8398 }
8399 break;
8400
8401 case SPEED_1000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008402 if (cmd->duplex != DUPLEX_FULL) {
8403 DP(NETIF_MSG_LINK, "1G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008404 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008405 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008406
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008407 if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008408 DP(NETIF_MSG_LINK, "1G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008409 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008410 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008411
8412 advertising = (ADVERTISED_1000baseT_Full |
8413 ADVERTISED_TP);
8414 break;
8415
8416 case SPEED_2500:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008417 if (cmd->duplex != DUPLEX_FULL) {
8418 DP(NETIF_MSG_LINK,
8419 "2.5G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008420 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008421 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008422
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008423 if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008424 DP(NETIF_MSG_LINK,
8425 "2.5G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008426 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008427 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008428
Eliezer Tamirf1410642008-02-28 11:51:50 -08008429 advertising = (ADVERTISED_2500baseX_Full |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008430 ADVERTISED_TP);
8431 break;
8432
8433 case SPEED_10000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008434 if (cmd->duplex != DUPLEX_FULL) {
8435 DP(NETIF_MSG_LINK, "10G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008436 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008437 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008438
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008439 if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08008440 DP(NETIF_MSG_LINK, "10G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008441 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08008442 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008443
8444 advertising = (ADVERTISED_10000baseT_Full |
8445 ADVERTISED_FIBRE);
8446 break;
8447
8448 default:
Eliezer Tamirf1410642008-02-28 11:51:50 -08008449 DP(NETIF_MSG_LINK, "Unsupported speed\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008450 return -EINVAL;
8451 }
8452
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008453 bp->link_params.req_line_speed = cmd->speed;
8454 bp->link_params.req_duplex = cmd->duplex;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008455 bp->port.advertising = advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008456 }
8457
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008458 DP(NETIF_MSG_LINK, "req_line_speed %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008459 DP_LEVEL " req_duplex %d advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008460 bp->link_params.req_line_speed, bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008461 bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008462
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008463 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008464 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008465 bnx2x_link_set(bp);
8466 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008467
8468 return 0;
8469}
8470
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008471#define PHY_FW_VER_LEN 10
8472
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008473static void bnx2x_get_drvinfo(struct net_device *dev,
8474 struct ethtool_drvinfo *info)
8475{
8476 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinf0e53a82008-08-13 15:58:30 -07008477 u8 phy_fw_ver[PHY_FW_VER_LEN];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008478
8479 strcpy(info->driver, DRV_MODULE_NAME);
8480 strcpy(info->version, DRV_MODULE_VERSION);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008481
8482 phy_fw_ver[0] = '\0';
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008483 if (bp->port.pmf) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008484 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008485 bnx2x_get_ext_phy_fw_version(&bp->link_params,
8486 (bp->state != BNX2X_STATE_CLOSED),
8487 phy_fw_ver, PHY_FW_VER_LEN);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008488 bnx2x_release_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008489 }
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008490
Eilon Greensteinf0e53a82008-08-13 15:58:30 -07008491 snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s",
8492 (bp->common.bc_ver & 0xff0000) >> 16,
8493 (bp->common.bc_ver & 0xff00) >> 8,
8494 (bp->common.bc_ver & 0xff),
8495 ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008496 strcpy(info->bus_info, pci_name(bp->pdev));
8497 info->n_stats = BNX2X_NUM_STATS;
8498 info->testinfo_len = BNX2X_NUM_TESTS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008499 info->eedump_len = bp->common.flash_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008500 info->regdump_len = 0;
8501}
8502
8503static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8504{
8505 struct bnx2x *bp = netdev_priv(dev);
8506
8507 if (bp->flags & NO_WOL_FLAG) {
8508 wol->supported = 0;
8509 wol->wolopts = 0;
8510 } else {
8511 wol->supported = WAKE_MAGIC;
8512 if (bp->wol)
8513 wol->wolopts = WAKE_MAGIC;
8514 else
8515 wol->wolopts = 0;
8516 }
8517 memset(&wol->sopass, 0, sizeof(wol->sopass));
8518}
8519
8520static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8521{
8522 struct bnx2x *bp = netdev_priv(dev);
8523
8524 if (wol->wolopts & ~WAKE_MAGIC)
8525 return -EINVAL;
8526
8527 if (wol->wolopts & WAKE_MAGIC) {
8528 if (bp->flags & NO_WOL_FLAG)
8529 return -EINVAL;
8530
8531 bp->wol = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008532 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008533 bp->wol = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008534
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008535 return 0;
8536}
8537
8538static u32 bnx2x_get_msglevel(struct net_device *dev)
8539{
8540 struct bnx2x *bp = netdev_priv(dev);
8541
8542 return bp->msglevel;
8543}
8544
8545static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
8546{
8547 struct bnx2x *bp = netdev_priv(dev);
8548
8549 if (capable(CAP_NET_ADMIN))
8550 bp->msglevel = level;
8551}
8552
8553static int bnx2x_nway_reset(struct net_device *dev)
8554{
8555 struct bnx2x *bp = netdev_priv(dev);
8556
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008557 if (!bp->port.pmf)
8558 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008559
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008560 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008561 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008562 bnx2x_link_set(bp);
8563 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008564
8565 return 0;
8566}
8567
8568static int bnx2x_get_eeprom_len(struct net_device *dev)
8569{
8570 struct bnx2x *bp = netdev_priv(dev);
8571
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008572 return bp->common.flash_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008573}
8574
8575static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
8576{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008577 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008578 int count, i;
8579 u32 val = 0;
8580
8581 /* adjust timeout for emulation/FPGA */
8582 count = NVRAM_TIMEOUT_COUNT;
8583 if (CHIP_REV_IS_SLOW(bp))
8584 count *= 100;
8585
8586 /* request access to nvram interface */
8587 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
8588 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
8589
8590 for (i = 0; i < count*10; i++) {
8591 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
8592 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
8593 break;
8594
8595 udelay(5);
8596 }
8597
8598 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008599 DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008600 return -EBUSY;
8601 }
8602
8603 return 0;
8604}
8605
8606static int bnx2x_release_nvram_lock(struct bnx2x *bp)
8607{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008608 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008609 int count, i;
8610 u32 val = 0;
8611
8612 /* adjust timeout for emulation/FPGA */
8613 count = NVRAM_TIMEOUT_COUNT;
8614 if (CHIP_REV_IS_SLOW(bp))
8615 count *= 100;
8616
8617 /* relinquish nvram interface */
8618 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
8619 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
8620
8621 for (i = 0; i < count*10; i++) {
8622 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
8623 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
8624 break;
8625
8626 udelay(5);
8627 }
8628
8629 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008630 DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008631 return -EBUSY;
8632 }
8633
8634 return 0;
8635}
8636
8637static void bnx2x_enable_nvram_access(struct bnx2x *bp)
8638{
8639 u32 val;
8640
8641 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
8642
8643 /* enable both bits, even on read */
8644 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
8645 (val | MCPR_NVM_ACCESS_ENABLE_EN |
8646 MCPR_NVM_ACCESS_ENABLE_WR_EN));
8647}
8648
8649static void bnx2x_disable_nvram_access(struct bnx2x *bp)
8650{
8651 u32 val;
8652
8653 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
8654
8655 /* disable both bits, even after read */
8656 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
8657 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
8658 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
8659}
8660
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00008661static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008662 u32 cmd_flags)
8663{
Eliezer Tamirf1410642008-02-28 11:51:50 -08008664 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008665 u32 val;
8666
8667 /* build the command word */
8668 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
8669
8670 /* need to clear DONE bit separately */
8671 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
8672
8673 /* address of the NVRAM to read from */
8674 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
8675 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
8676
8677 /* issue a read command */
8678 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
8679
8680 /* adjust timeout for emulation/FPGA */
8681 count = NVRAM_TIMEOUT_COUNT;
8682 if (CHIP_REV_IS_SLOW(bp))
8683 count *= 100;
8684
8685 /* wait for completion */
8686 *ret_val = 0;
8687 rc = -EBUSY;
8688 for (i = 0; i < count; i++) {
8689 udelay(5);
8690 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
8691
8692 if (val & MCPR_NVM_COMMAND_DONE) {
8693 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008694 /* we read nvram data in cpu order
8695 * but ethtool sees it as an array of bytes
8696 * converting to big-endian will do the work */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00008697 *ret_val = cpu_to_be32(val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008698 rc = 0;
8699 break;
8700 }
8701 }
8702
8703 return rc;
8704}
8705
8706static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
8707 int buf_size)
8708{
8709 int rc;
8710 u32 cmd_flags;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00008711 __be32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008712
8713 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008714 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08008715 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008716 offset, buf_size);
8717 return -EINVAL;
8718 }
8719
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008720 if (offset + buf_size > bp->common.flash_size) {
8721 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008722 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008723 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008724 return -EINVAL;
8725 }
8726
8727 /* request access to nvram interface */
8728 rc = bnx2x_acquire_nvram_lock(bp);
8729 if (rc)
8730 return rc;
8731
8732 /* enable access to nvram interface */
8733 bnx2x_enable_nvram_access(bp);
8734
8735 /* read the first word(s) */
8736 cmd_flags = MCPR_NVM_COMMAND_FIRST;
8737 while ((buf_size > sizeof(u32)) && (rc == 0)) {
8738 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
8739 memcpy(ret_buf, &val, 4);
8740
8741 /* advance to the next dword */
8742 offset += sizeof(u32);
8743 ret_buf += sizeof(u32);
8744 buf_size -= sizeof(u32);
8745 cmd_flags = 0;
8746 }
8747
8748 if (rc == 0) {
8749 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8750 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
8751 memcpy(ret_buf, &val, 4);
8752 }
8753
8754 /* disable access to nvram interface */
8755 bnx2x_disable_nvram_access(bp);
8756 bnx2x_release_nvram_lock(bp);
8757
8758 return rc;
8759}
8760
8761static int bnx2x_get_eeprom(struct net_device *dev,
8762 struct ethtool_eeprom *eeprom, u8 *eebuf)
8763{
8764 struct bnx2x *bp = netdev_priv(dev);
8765 int rc;
8766
Eilon Greenstein2add3ac2009-01-14 06:44:07 +00008767 if (!netif_running(dev))
8768 return -EAGAIN;
8769
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008770 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008771 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
8772 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
8773 eeprom->len, eeprom->len);
8774
8775 /* parameters already validated in ethtool_get_eeprom */
8776
8777 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
8778
8779 return rc;
8780}
8781
8782static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
8783 u32 cmd_flags)
8784{
Eliezer Tamirf1410642008-02-28 11:51:50 -08008785 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008786
8787 /* build the command word */
8788 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
8789
8790 /* need to clear DONE bit separately */
8791 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
8792
8793 /* write the data */
8794 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
8795
8796 /* address of the NVRAM to write to */
8797 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
8798 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
8799
8800 /* issue the write command */
8801 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
8802
8803 /* adjust timeout for emulation/FPGA */
8804 count = NVRAM_TIMEOUT_COUNT;
8805 if (CHIP_REV_IS_SLOW(bp))
8806 count *= 100;
8807
8808 /* wait for completion */
8809 rc = -EBUSY;
8810 for (i = 0; i < count; i++) {
8811 udelay(5);
8812 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
8813 if (val & MCPR_NVM_COMMAND_DONE) {
8814 rc = 0;
8815 break;
8816 }
8817 }
8818
8819 return rc;
8820}
8821
Eliezer Tamirf1410642008-02-28 11:51:50 -08008822#define BYTE_OFFSET(offset) (8 * (offset & 0x03))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008823
8824static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
8825 int buf_size)
8826{
8827 int rc;
8828 u32 cmd_flags;
8829 u32 align_offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00008830 __be32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008831
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008832 if (offset + buf_size > bp->common.flash_size) {
8833 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008834 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008835 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008836 return -EINVAL;
8837 }
8838
8839 /* request access to nvram interface */
8840 rc = bnx2x_acquire_nvram_lock(bp);
8841 if (rc)
8842 return rc;
8843
8844 /* enable access to nvram interface */
8845 bnx2x_enable_nvram_access(bp);
8846
8847 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
8848 align_offset = (offset & ~0x03);
8849 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
8850
8851 if (rc == 0) {
8852 val &= ~(0xff << BYTE_OFFSET(offset));
8853 val |= (*data_buf << BYTE_OFFSET(offset));
8854
8855 /* nvram data is returned as an array of bytes
8856 * convert it back to cpu order */
8857 val = be32_to_cpu(val);
8858
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008859 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
8860 cmd_flags);
8861 }
8862
8863 /* disable access to nvram interface */
8864 bnx2x_disable_nvram_access(bp);
8865 bnx2x_release_nvram_lock(bp);
8866
8867 return rc;
8868}
8869
8870static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
8871 int buf_size)
8872{
8873 int rc;
8874 u32 cmd_flags;
8875 u32 val;
8876 u32 written_so_far;
8877
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008878 if (buf_size == 1) /* ethtool */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008879 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008880
8881 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008882 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08008883 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008884 offset, buf_size);
8885 return -EINVAL;
8886 }
8887
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008888 if (offset + buf_size > bp->common.flash_size) {
8889 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008890 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008891 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008892 return -EINVAL;
8893 }
8894
8895 /* request access to nvram interface */
8896 rc = bnx2x_acquire_nvram_lock(bp);
8897 if (rc)
8898 return rc;
8899
8900 /* enable access to nvram interface */
8901 bnx2x_enable_nvram_access(bp);
8902
8903 written_so_far = 0;
8904 cmd_flags = MCPR_NVM_COMMAND_FIRST;
8905 while ((written_so_far < buf_size) && (rc == 0)) {
8906 if (written_so_far == (buf_size - sizeof(u32)))
8907 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8908 else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
8909 cmd_flags |= MCPR_NVM_COMMAND_LAST;
8910 else if ((offset % NVRAM_PAGE_SIZE) == 0)
8911 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
8912
8913 memcpy(&val, data_buf, 4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008914
8915 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
8916
8917 /* advance to the next dword */
8918 offset += sizeof(u32);
8919 data_buf += sizeof(u32);
8920 written_so_far += sizeof(u32);
8921 cmd_flags = 0;
8922 }
8923
8924 /* disable access to nvram interface */
8925 bnx2x_disable_nvram_access(bp);
8926 bnx2x_release_nvram_lock(bp);
8927
8928 return rc;
8929}
8930
8931static int bnx2x_set_eeprom(struct net_device *dev,
8932 struct ethtool_eeprom *eeprom, u8 *eebuf)
8933{
8934 struct bnx2x *bp = netdev_priv(dev);
8935 int rc;
8936
Eilon Greenstein9f4c9582009-01-08 11:21:43 -08008937 if (!netif_running(dev))
8938 return -EAGAIN;
8939
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008940 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008941 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
8942 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
8943 eeprom->len, eeprom->len);
8944
8945 /* parameters already validated in ethtool_set_eeprom */
8946
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008947 /* If the magic number is PHY (0x00504859) upgrade the PHY FW */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008948 if (eeprom->magic == 0x00504859)
8949 if (bp->port.pmf) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008950
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008951 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008952 rc = bnx2x_flash_download(bp, BP_PORT(bp),
8953 bp->link_params.ext_phy_config,
8954 (bp->state != BNX2X_STATE_CLOSED),
8955 eebuf, eeprom->len);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008956 if ((bp->state == BNX2X_STATE_OPEN) ||
8957 (bp->state == BNX2X_STATE_DISABLED)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008958 rc |= bnx2x_link_reset(&bp->link_params,
Eilon Greenstein589abe32009-02-12 08:36:55 +00008959 &bp->link_vars, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008960 rc |= bnx2x_phy_init(&bp->link_params,
8961 &bp->link_vars);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008962 }
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008963 bnx2x_release_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008964
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008965 } else /* Only the PMF can access the PHY */
8966 return -EINVAL;
8967 else
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008968 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008969
8970 return rc;
8971}
8972
8973static int bnx2x_get_coalesce(struct net_device *dev,
8974 struct ethtool_coalesce *coal)
8975{
8976 struct bnx2x *bp = netdev_priv(dev);
8977
8978 memset(coal, 0, sizeof(struct ethtool_coalesce));
8979
8980 coal->rx_coalesce_usecs = bp->rx_ticks;
8981 coal->tx_coalesce_usecs = bp->tx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008982
8983 return 0;
8984}
8985
8986static int bnx2x_set_coalesce(struct net_device *dev,
8987 struct ethtool_coalesce *coal)
8988{
8989 struct bnx2x *bp = netdev_priv(dev);
8990
8991 bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
8992 if (bp->rx_ticks > 3000)
8993 bp->rx_ticks = 3000;
8994
8995 bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
8996 if (bp->tx_ticks > 0x3000)
8997 bp->tx_ticks = 0x3000;
8998
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008999 if (netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009000 bnx2x_update_coalesce(bp);
9001
9002 return 0;
9003}
9004
9005static void bnx2x_get_ringparam(struct net_device *dev,
9006 struct ethtool_ringparam *ering)
9007{
9008 struct bnx2x *bp = netdev_priv(dev);
9009
9010 ering->rx_max_pending = MAX_RX_AVAIL;
9011 ering->rx_mini_max_pending = 0;
9012 ering->rx_jumbo_max_pending = 0;
9013
9014 ering->rx_pending = bp->rx_ring_size;
9015 ering->rx_mini_pending = 0;
9016 ering->rx_jumbo_pending = 0;
9017
9018 ering->tx_max_pending = MAX_TX_AVAIL;
9019 ering->tx_pending = bp->tx_ring_size;
9020}
9021
9022static int bnx2x_set_ringparam(struct net_device *dev,
9023 struct ethtool_ringparam *ering)
9024{
9025 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009026 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009027
9028 if ((ering->rx_pending > MAX_RX_AVAIL) ||
9029 (ering->tx_pending > MAX_TX_AVAIL) ||
9030 (ering->tx_pending <= MAX_SKB_FRAGS + 4))
9031 return -EINVAL;
9032
9033 bp->rx_ring_size = ering->rx_pending;
9034 bp->tx_ring_size = ering->tx_pending;
9035
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009036 if (netif_running(dev)) {
9037 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9038 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009039 }
9040
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009041 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009042}
9043
9044static void bnx2x_get_pauseparam(struct net_device *dev,
9045 struct ethtool_pauseparam *epause)
9046{
9047 struct bnx2x *bp = netdev_priv(dev);
9048
Eilon Greenstein356e2382009-02-12 08:38:32 +00009049 epause->autoneg = (bp->link_params.req_flow_ctrl ==
9050 BNX2X_FLOW_CTRL_AUTO) &&
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009051 (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
9052
David S. Millerc0700f92008-12-16 23:53:20 -08009053 epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
9054 BNX2X_FLOW_CTRL_RX);
9055 epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
9056 BNX2X_FLOW_CTRL_TX);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009057
9058 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9059 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9060 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9061}
9062
9063static int bnx2x_set_pauseparam(struct net_device *dev,
9064 struct ethtool_pauseparam *epause)
9065{
9066 struct bnx2x *bp = netdev_priv(dev);
9067
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009068 if (IS_E1HMF(bp))
9069 return 0;
9070
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009071 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9072 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9073 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9074
David S. Millerc0700f92008-12-16 23:53:20 -08009075 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009076
9077 if (epause->rx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -08009078 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009079
9080 if (epause->tx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -08009081 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009082
David S. Millerc0700f92008-12-16 23:53:20 -08009083 if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
9084 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009085
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009086 if (epause->autoneg) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009087 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07009088 DP(NETIF_MSG_LINK, "autoneg not supported\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -08009089 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009090 }
9091
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009092 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
David S. Millerc0700f92008-12-16 23:53:20 -08009093 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009094 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009095
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009096 DP(NETIF_MSG_LINK,
9097 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009098
9099 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009100 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009101 bnx2x_link_set(bp);
9102 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009103
9104 return 0;
9105}
9106
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009107static int bnx2x_set_flags(struct net_device *dev, u32 data)
9108{
9109 struct bnx2x *bp = netdev_priv(dev);
9110 int changed = 0;
9111 int rc = 0;
9112
9113 /* TPA requires Rx CSUM offloading */
9114 if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
9115 if (!(dev->features & NETIF_F_LRO)) {
9116 dev->features |= NETIF_F_LRO;
9117 bp->flags |= TPA_ENABLE_FLAG;
9118 changed = 1;
9119 }
9120
9121 } else if (dev->features & NETIF_F_LRO) {
9122 dev->features &= ~NETIF_F_LRO;
9123 bp->flags &= ~TPA_ENABLE_FLAG;
9124 changed = 1;
9125 }
9126
9127 if (changed && netif_running(dev)) {
9128 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9129 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
9130 }
9131
9132 return rc;
9133}
9134
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009135static u32 bnx2x_get_rx_csum(struct net_device *dev)
9136{
9137 struct bnx2x *bp = netdev_priv(dev);
9138
9139 return bp->rx_csum;
9140}
9141
9142static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
9143{
9144 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009145 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009146
9147 bp->rx_csum = data;
Vladislav Zolotarovdf0f2342008-08-13 15:53:38 -07009148
9149 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
9150 TPA'ed packets will be discarded due to wrong TCP CSUM */
9151 if (!data) {
9152 u32 flags = ethtool_op_get_flags(dev);
9153
9154 rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
9155 }
9156
9157 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009158}
9159
9160static int bnx2x_set_tso(struct net_device *dev, u32 data)
9161{
Eilon Greenstein755735e2008-06-23 20:35:13 -07009162 if (data) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009163 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -07009164 dev->features |= NETIF_F_TSO6;
9165 } else {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009166 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -07009167 dev->features &= ~NETIF_F_TSO6;
9168 }
9169
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009170 return 0;
9171}
9172
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009173static const struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009174 char string[ETH_GSTRING_LEN];
9175} bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009176 { "register_test (offline)" },
9177 { "memory_test (offline)" },
9178 { "loopback_test (offline)" },
9179 { "nvram_test (online)" },
9180 { "interrupt_test (online)" },
9181 { "link_test (online)" },
Eilon Greensteind3d4f492009-02-12 08:36:27 +00009182 { "idle check (online)" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009183};
9184
9185static int bnx2x_self_test_count(struct net_device *dev)
9186{
9187 return BNX2X_NUM_TESTS;
9188}
9189
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009190static int bnx2x_test_registers(struct bnx2x *bp)
9191{
9192 int idx, i, rc = -ENODEV;
9193 u32 wr_val = 0;
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009194 int port = BP_PORT(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009195 static const struct {
9196 u32 offset0;
9197 u32 offset1;
9198 u32 mask;
9199 } reg_tbl[] = {
9200/* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
9201 { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
9202 { HC_REG_AGG_INT_0, 4, 0x000003ff },
9203 { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
9204 { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
9205 { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
9206 { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
9207 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
9208 { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
9209 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
9210/* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
9211 { QM_REG_CONNNUM_0, 4, 0x000fffff },
9212 { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
9213 { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
9214 { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
9215 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
9216 { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
9217 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
9218 { NIG_REG_EGRESS_MNG0_FIFO, 20, 0xffffffff },
9219 { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
9220/* 20 */ { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
9221 { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
9222 { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
9223 { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
9224 { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
9225 { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
9226 { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
9227 { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
9228 { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
9229 { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
9230/* 30 */ { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
9231 { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
9232 { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
9233 { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
9234 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
9235 { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
9236 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
9237 { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
9238
9239 { 0xffffffff, 0, 0x00000000 }
9240 };
9241
9242 if (!netif_running(bp->dev))
9243 return rc;
9244
9245 /* Repeat the test twice:
9246 First by writing 0x00000000, second by writing 0xffffffff */
9247 for (idx = 0; idx < 2; idx++) {
9248
9249 switch (idx) {
9250 case 0:
9251 wr_val = 0;
9252 break;
9253 case 1:
9254 wr_val = 0xffffffff;
9255 break;
9256 }
9257
9258 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
9259 u32 offset, mask, save_val, val;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009260
9261 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
9262 mask = reg_tbl[i].mask;
9263
9264 save_val = REG_RD(bp, offset);
9265
9266 REG_WR(bp, offset, wr_val);
9267 val = REG_RD(bp, offset);
9268
9269 /* Restore the original register's value */
9270 REG_WR(bp, offset, save_val);
9271
9272 /* verify that value is as expected value */
9273 if ((val & mask) != (wr_val & mask))
9274 goto test_reg_exit;
9275 }
9276 }
9277
9278 rc = 0;
9279
9280test_reg_exit:
9281 return rc;
9282}
9283
9284static int bnx2x_test_memory(struct bnx2x *bp)
9285{
9286 int i, j, rc = -ENODEV;
9287 u32 val;
9288 static const struct {
9289 u32 offset;
9290 int size;
9291 } mem_tbl[] = {
9292 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
9293 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
9294 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
9295 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
9296 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
9297 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
9298 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
9299
9300 { 0xffffffff, 0 }
9301 };
9302 static const struct {
9303 char *name;
9304 u32 offset;
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009305 u32 e1_mask;
9306 u32 e1h_mask;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009307 } prty_tbl[] = {
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009308 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
9309 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
9310 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
9311 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
9312 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
9313 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009314
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009315 { NULL, 0xffffffff, 0, 0 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009316 };
9317
9318 if (!netif_running(bp->dev))
9319 return rc;
9320
9321 /* Go through all the memories */
9322 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
9323 for (j = 0; j < mem_tbl[i].size; j++)
9324 REG_RD(bp, mem_tbl[i].offset + j*4);
9325
9326 /* Check the parity status */
9327 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
9328 val = REG_RD(bp, prty_tbl[i].offset);
Yitchak Gertner9dabc422008-08-13 15:51:28 -07009329 if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
9330 (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009331 DP(NETIF_MSG_HW,
9332 "%s is 0x%x\n", prty_tbl[i].name, val);
9333 goto test_mem_exit;
9334 }
9335 }
9336
9337 rc = 0;
9338
9339test_mem_exit:
9340 return rc;
9341}
9342
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009343static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
9344{
9345 int cnt = 1000;
9346
9347 if (link_up)
9348 while (bnx2x_link_test(bp) && cnt--)
9349 msleep(10);
9350}
9351
9352static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
9353{
9354 unsigned int pkt_size, num_pkts, i;
9355 struct sk_buff *skb;
9356 unsigned char *packet;
9357 struct bnx2x_fastpath *fp = &bp->fp[0];
9358 u16 tx_start_idx, tx_idx;
9359 u16 rx_start_idx, rx_idx;
9360 u16 pkt_prod;
9361 struct sw_tx_bd *tx_buf;
9362 struct eth_tx_bd *tx_bd;
9363 dma_addr_t mapping;
9364 union eth_rx_cqe *cqe;
9365 u8 cqe_fp_flags;
9366 struct sw_rx_bd *rx_buf;
9367 u16 len;
9368 int rc = -ENODEV;
9369
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009370 /* check the loopback mode */
9371 switch (loopback_mode) {
9372 case BNX2X_PHY_LOOPBACK:
9373 if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10)
9374 return -EINVAL;
9375 break;
9376 case BNX2X_MAC_LOOPBACK:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009377 bp->link_params.loopback_mode = LOOPBACK_BMAC;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009378 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009379 break;
9380 default:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009381 return -EINVAL;
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009382 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009383
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009384 /* prepare the loopback packet */
9385 pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
9386 bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009387 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
9388 if (!skb) {
9389 rc = -ENOMEM;
9390 goto test_loopback_exit;
9391 }
9392 packet = skb_put(skb, pkt_size);
9393 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
9394 memset(packet + ETH_ALEN, 0, (ETH_HLEN - ETH_ALEN));
9395 for (i = ETH_HLEN; i < pkt_size; i++)
9396 packet[i] = (unsigned char) (i & 0xff);
9397
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009398 /* send the loopback packet */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009399 num_pkts = 0;
9400 tx_start_idx = le16_to_cpu(*fp->tx_cons_sb);
9401 rx_start_idx = le16_to_cpu(*fp->rx_cons_sb);
9402
9403 pkt_prod = fp->tx_pkt_prod++;
9404 tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
9405 tx_buf->first_bd = fp->tx_bd_prod;
9406 tx_buf->skb = skb;
9407
9408 tx_bd = &fp->tx_desc_ring[TX_BD(fp->tx_bd_prod)];
9409 mapping = pci_map_single(bp->pdev, skb->data,
9410 skb_headlen(skb), PCI_DMA_TODEVICE);
9411 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
9412 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
9413 tx_bd->nbd = cpu_to_le16(1);
9414 tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
9415 tx_bd->vlan = cpu_to_le16(pkt_prod);
9416 tx_bd->bd_flags.as_bitfield = (ETH_TX_BD_FLAGS_START_BD |
9417 ETH_TX_BD_FLAGS_END_BD);
9418 tx_bd->general_data = ((UNICAST_ADDRESS <<
9419 ETH_TX_BD_ETH_ADDR_TYPE_SHIFT) | 1);
9420
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08009421 wmb();
9422
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009423 le16_add_cpu(&fp->hw_tx_prods->bds_prod, 1);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009424 mb(); /* FW restriction: must not reorder writing nbd and packets */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009425 le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1);
Eilon Greenstein0626b892009-02-12 08:38:14 +00009426 DOORBELL(bp, fp->index, 0);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009427
9428 mmiowb();
9429
9430 num_pkts++;
9431 fp->tx_bd_prod++;
9432 bp->dev->trans_start = jiffies;
9433
9434 udelay(100);
9435
9436 tx_idx = le16_to_cpu(*fp->tx_cons_sb);
9437 if (tx_idx != tx_start_idx + num_pkts)
9438 goto test_loopback_exit;
9439
9440 rx_idx = le16_to_cpu(*fp->rx_cons_sb);
9441 if (rx_idx != rx_start_idx + num_pkts)
9442 goto test_loopback_exit;
9443
9444 cqe = &fp->rx_comp_ring[RCQ_BD(fp->rx_comp_cons)];
9445 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
9446 if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
9447 goto test_loopback_rx_exit;
9448
9449 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
9450 if (len != pkt_size)
9451 goto test_loopback_rx_exit;
9452
9453 rx_buf = &fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)];
9454 skb = rx_buf->skb;
9455 skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
9456 for (i = ETH_HLEN; i < pkt_size; i++)
9457 if (*(skb->data + i) != (unsigned char) (i & 0xff))
9458 goto test_loopback_rx_exit;
9459
9460 rc = 0;
9461
9462test_loopback_rx_exit:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009463
9464 fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons);
9465 fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod);
9466 fp->rx_comp_cons = NEXT_RCQ_IDX(fp->rx_comp_cons);
9467 fp->rx_comp_prod = NEXT_RCQ_IDX(fp->rx_comp_prod);
9468
9469 /* Update producers */
9470 bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
9471 fp->rx_sge_prod);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009472
9473test_loopback_exit:
9474 bp->link_params.loopback_mode = LOOPBACK_NONE;
9475
9476 return rc;
9477}
9478
9479static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
9480{
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009481 int rc = 0, res;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009482
9483 if (!netif_running(bp->dev))
9484 return BNX2X_LOOPBACK_FAILED;
9485
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07009486 bnx2x_netif_stop(bp, 1);
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009487 bnx2x_acquire_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009488
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009489 res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
9490 if (res) {
9491 DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
9492 rc |= BNX2X_PHY_LOOPBACK_FAILED;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009493 }
9494
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00009495 res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
9496 if (res) {
9497 DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
9498 rc |= BNX2X_MAC_LOOPBACK_FAILED;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009499 }
9500
Eilon Greenstein3910c8a2009-01-22 06:01:32 +00009501 bnx2x_release_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009502 bnx2x_netif_start(bp);
9503
9504 return rc;
9505}
9506
9507#define CRC32_RESIDUAL 0xdebb20e3
9508
9509static int bnx2x_test_nvram(struct bnx2x *bp)
9510{
9511 static const struct {
9512 int offset;
9513 int size;
9514 } nvram_tbl[] = {
9515 { 0, 0x14 }, /* bootstrap */
9516 { 0x14, 0xec }, /* dir */
9517 { 0x100, 0x350 }, /* manuf_info */
9518 { 0x450, 0xf0 }, /* feature_info */
9519 { 0x640, 0x64 }, /* upgrade_key_info */
9520 { 0x6a4, 0x64 },
9521 { 0x708, 0x70 }, /* manuf_key_info */
9522 { 0x778, 0x70 },
9523 { 0, 0 }
9524 };
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009525 __be32 buf[0x350 / 4];
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009526 u8 *data = (u8 *)buf;
9527 int i, rc;
9528 u32 magic, csum;
9529
9530 rc = bnx2x_nvram_read(bp, 0, data, 4);
9531 if (rc) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00009532 DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009533 goto test_nvram_exit;
9534 }
9535
9536 magic = be32_to_cpu(buf[0]);
9537 if (magic != 0x669955aa) {
9538 DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
9539 rc = -ENODEV;
9540 goto test_nvram_exit;
9541 }
9542
9543 for (i = 0; nvram_tbl[i].size; i++) {
9544
9545 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
9546 nvram_tbl[i].size);
9547 if (rc) {
9548 DP(NETIF_MSG_PROBE,
Eilon Greensteinf5372252009-02-12 08:38:30 +00009549 "nvram_tbl[%d] read data (rc %d)\n", i, rc);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009550 goto test_nvram_exit;
9551 }
9552
9553 csum = ether_crc_le(nvram_tbl[i].size, data);
9554 if (csum != CRC32_RESIDUAL) {
9555 DP(NETIF_MSG_PROBE,
9556 "nvram_tbl[%d] csum value (0x%08x)\n", i, csum);
9557 rc = -ENODEV;
9558 goto test_nvram_exit;
9559 }
9560 }
9561
9562test_nvram_exit:
9563 return rc;
9564}
9565
9566static int bnx2x_test_intr(struct bnx2x *bp)
9567{
9568 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
9569 int i, rc;
9570
9571 if (!netif_running(bp->dev))
9572 return -ENODEV;
9573
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08009574 config->hdr.length = 0;
Eilon Greensteinaf246402009-01-14 06:43:59 +00009575 if (CHIP_IS_E1(bp))
9576 config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
9577 else
9578 config->hdr.offset = BP_FUNC(bp);
Eilon Greenstein0626b892009-02-12 08:38:14 +00009579 config->hdr.client_id = bp->fp->cl_id;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009580 config->hdr.reserved1 = 0;
9581
9582 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
9583 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
9584 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
9585 if (rc == 0) {
9586 bp->set_mac_pending++;
9587 for (i = 0; i < 10; i++) {
9588 if (!bp->set_mac_pending)
9589 break;
9590 msleep_interruptible(10);
9591 }
9592 if (i == 10)
9593 rc = -ENODEV;
9594 }
9595
9596 return rc;
9597}
9598
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009599static void bnx2x_self_test(struct net_device *dev,
9600 struct ethtool_test *etest, u64 *buf)
9601{
9602 struct bnx2x *bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009603
9604 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
9605
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009606 if (!netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009607 return;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009608
Eilon Greenstein33471622008-08-13 15:59:08 -07009609 /* offline tests are not supported in MF mode */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009610 if (IS_E1HMF(bp))
9611 etest->flags &= ~ETH_TEST_FL_OFFLINE;
9612
9613 if (etest->flags & ETH_TEST_FL_OFFLINE) {
9614 u8 link_up;
9615
9616 link_up = bp->link_vars.link_up;
9617 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9618 bnx2x_nic_load(bp, LOAD_DIAG);
9619 /* wait until link state is restored */
9620 bnx2x_wait_for_link(bp, link_up);
9621
9622 if (bnx2x_test_registers(bp) != 0) {
9623 buf[0] = 1;
9624 etest->flags |= ETH_TEST_FL_FAILED;
9625 }
9626 if (bnx2x_test_memory(bp) != 0) {
9627 buf[1] = 1;
9628 etest->flags |= ETH_TEST_FL_FAILED;
9629 }
9630 buf[2] = bnx2x_test_loopback(bp, link_up);
9631 if (buf[2] != 0)
9632 etest->flags |= ETH_TEST_FL_FAILED;
9633
9634 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9635 bnx2x_nic_load(bp, LOAD_NORMAL);
9636 /* wait until link state is restored */
9637 bnx2x_wait_for_link(bp, link_up);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009638 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009639 if (bnx2x_test_nvram(bp) != 0) {
9640 buf[3] = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009641 etest->flags |= ETH_TEST_FL_FAILED;
9642 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009643 if (bnx2x_test_intr(bp) != 0) {
9644 buf[4] = 1;
9645 etest->flags |= ETH_TEST_FL_FAILED;
9646 }
9647 if (bp->port.pmf)
9648 if (bnx2x_link_test(bp) != 0) {
9649 buf[5] = 1;
9650 etest->flags |= ETH_TEST_FL_FAILED;
9651 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -07009652
9653#ifdef BNX2X_EXTRA_DEBUG
9654 bnx2x_panic_dump(bp);
9655#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009656}
9657
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009658static const struct {
9659 long offset;
9660 int size;
Eilon Greensteinde832a52009-02-12 08:36:33 +00009661 u8 string[ETH_GSTRING_LEN];
9662} bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
9663/* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
9664 { Q_STATS_OFFSET32(error_bytes_received_hi),
9665 8, "[%d]: rx_error_bytes" },
9666 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
9667 8, "[%d]: rx_ucast_packets" },
9668 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
9669 8, "[%d]: rx_mcast_packets" },
9670 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
9671 8, "[%d]: rx_bcast_packets" },
9672 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
9673 { Q_STATS_OFFSET32(rx_err_discard_pkt),
9674 4, "[%d]: rx_phy_ip_err_discards"},
9675 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
9676 4, "[%d]: rx_skb_alloc_discard" },
9677 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
9678
9679/* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
9680 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
9681 8, "[%d]: tx_packets" }
9682};
9683
9684static const struct {
9685 long offset;
9686 int size;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009687 u32 flags;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009688#define STATS_FLAGS_PORT 1
9689#define STATS_FLAGS_FUNC 2
Eilon Greensteinde832a52009-02-12 08:36:33 +00009690#define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009691 u8 string[ETH_GSTRING_LEN];
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009692} bnx2x_stats_arr[BNX2X_NUM_STATS] = {
Eilon Greensteinde832a52009-02-12 08:36:33 +00009693/* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
9694 8, STATS_FLAGS_BOTH, "rx_bytes" },
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009695 { STATS_OFFSET32(error_bytes_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009696 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009697 { STATS_OFFSET32(total_unicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009698 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009699 { STATS_OFFSET32(total_multicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009700 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009701 { STATS_OFFSET32(total_broadcast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00009702 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009703 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009704 8, STATS_FLAGS_PORT, "rx_crc_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009705 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009706 8, STATS_FLAGS_PORT, "rx_align_errors" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009707 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
9708 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
9709 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
9710 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
9711/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
9712 8, STATS_FLAGS_PORT, "rx_fragments" },
9713 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
9714 8, STATS_FLAGS_PORT, "rx_jabbers" },
9715 { STATS_OFFSET32(no_buff_discard_hi),
9716 8, STATS_FLAGS_BOTH, "rx_discards" },
9717 { STATS_OFFSET32(mac_filter_discard),
9718 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
9719 { STATS_OFFSET32(xxoverflow_discard),
9720 4, STATS_FLAGS_PORT, "rx_fw_discards" },
9721 { STATS_OFFSET32(brb_drop_hi),
9722 8, STATS_FLAGS_PORT, "rx_brb_discard" },
9723 { STATS_OFFSET32(brb_truncate_hi),
9724 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
9725 { STATS_OFFSET32(pause_frames_received_hi),
9726 8, STATS_FLAGS_PORT, "rx_pause_frames" },
9727 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
9728 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
9729 { STATS_OFFSET32(nig_timer_max),
9730 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
9731/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
9732 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
9733 { STATS_OFFSET32(rx_skb_alloc_failed),
9734 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
9735 { STATS_OFFSET32(hw_csum_err),
9736 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
9737
9738 { STATS_OFFSET32(total_bytes_transmitted_hi),
9739 8, STATS_FLAGS_BOTH, "tx_bytes" },
9740 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
9741 8, STATS_FLAGS_PORT, "tx_error_bytes" },
9742 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
9743 8, STATS_FLAGS_BOTH, "tx_packets" },
9744 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
9745 8, STATS_FLAGS_PORT, "tx_mac_errors" },
9746 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
9747 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009748 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009749 8, STATS_FLAGS_PORT, "tx_single_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009750 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009751 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009752/* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009753 8, STATS_FLAGS_PORT, "tx_deferred" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009754 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009755 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009756 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009757 8, STATS_FLAGS_PORT, "tx_late_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009758 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009759 8, STATS_FLAGS_PORT, "tx_total_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009760 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009761 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009762 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009763 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009764 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009765 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009766 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009767 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009768 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009769 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009770 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009771 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009772/* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009773 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +00009774 { STATS_OFFSET32(pause_frames_sent_hi),
9775 8, STATS_FLAGS_PORT, "tx_pause_frames" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009776};
9777
Eilon Greensteinde832a52009-02-12 08:36:33 +00009778#define IS_PORT_STAT(i) \
9779 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
9780#define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
9781#define IS_E1HMF_MODE_STAT(bp) \
9782 (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS))
Yitchak Gertner66e855f2008-08-13 15:49:05 -07009783
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009784static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
9785{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009786 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009787 int i, j, k;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009788
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009789 switch (stringset) {
9790 case ETH_SS_STATS:
Eilon Greensteinde832a52009-02-12 08:36:33 +00009791 if (is_multi(bp)) {
9792 k = 0;
9793 for_each_queue(bp, i) {
9794 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
9795 sprintf(buf + (k + j)*ETH_GSTRING_LEN,
9796 bnx2x_q_stats_arr[j].string, i);
9797 k += BNX2X_NUM_Q_STATS;
9798 }
9799 if (IS_E1HMF_MODE_STAT(bp))
9800 break;
9801 for (j = 0; j < BNX2X_NUM_STATS; j++)
9802 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
9803 bnx2x_stats_arr[j].string);
9804 } else {
9805 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
9806 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
9807 continue;
9808 strcpy(buf + j*ETH_GSTRING_LEN,
9809 bnx2x_stats_arr[i].string);
9810 j++;
9811 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009812 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009813 break;
9814
9815 case ETH_SS_TEST:
9816 memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
9817 break;
9818 }
9819}
9820
9821static int bnx2x_get_stats_count(struct net_device *dev)
9822{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009823 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009824 int i, num_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009825
Eilon Greensteinde832a52009-02-12 08:36:33 +00009826 if (is_multi(bp)) {
9827 num_stats = BNX2X_NUM_Q_STATS * BNX2X_NUM_QUEUES(bp);
9828 if (!IS_E1HMF_MODE_STAT(bp))
9829 num_stats += BNX2X_NUM_STATS;
9830 } else {
9831 if (IS_E1HMF_MODE_STAT(bp)) {
9832 num_stats = 0;
9833 for (i = 0; i < BNX2X_NUM_STATS; i++)
9834 if (IS_FUNC_STAT(i))
9835 num_stats++;
9836 } else
9837 num_stats = BNX2X_NUM_STATS;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009838 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009839
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009840 return num_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009841}
9842
9843static void bnx2x_get_ethtool_stats(struct net_device *dev,
9844 struct ethtool_stats *stats, u64 *buf)
9845{
9846 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +00009847 u32 *hw_stats, *offset;
9848 int i, j, k;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009849
Eilon Greensteinde832a52009-02-12 08:36:33 +00009850 if (is_multi(bp)) {
9851 k = 0;
9852 for_each_queue(bp, i) {
9853 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
9854 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
9855 if (bnx2x_q_stats_arr[j].size == 0) {
9856 /* skip this counter */
9857 buf[k + j] = 0;
9858 continue;
9859 }
9860 offset = (hw_stats +
9861 bnx2x_q_stats_arr[j].offset);
9862 if (bnx2x_q_stats_arr[j].size == 4) {
9863 /* 4-byte counter */
9864 buf[k + j] = (u64) *offset;
9865 continue;
9866 }
9867 /* 8-byte counter */
9868 buf[k + j] = HILO_U64(*offset, *(offset + 1));
9869 }
9870 k += BNX2X_NUM_Q_STATS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009871 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009872 if (IS_E1HMF_MODE_STAT(bp))
9873 return;
9874 hw_stats = (u32 *)&bp->eth_stats;
9875 for (j = 0; j < BNX2X_NUM_STATS; j++) {
9876 if (bnx2x_stats_arr[j].size == 0) {
9877 /* skip this counter */
9878 buf[k + j] = 0;
9879 continue;
9880 }
9881 offset = (hw_stats + bnx2x_stats_arr[j].offset);
9882 if (bnx2x_stats_arr[j].size == 4) {
9883 /* 4-byte counter */
9884 buf[k + j] = (u64) *offset;
9885 continue;
9886 }
9887 /* 8-byte counter */
9888 buf[k + j] = HILO_U64(*offset, *(offset + 1));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009889 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00009890 } else {
9891 hw_stats = (u32 *)&bp->eth_stats;
9892 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
9893 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
9894 continue;
9895 if (bnx2x_stats_arr[i].size == 0) {
9896 /* skip this counter */
9897 buf[j] = 0;
9898 j++;
9899 continue;
9900 }
9901 offset = (hw_stats + bnx2x_stats_arr[i].offset);
9902 if (bnx2x_stats_arr[i].size == 4) {
9903 /* 4-byte counter */
9904 buf[j] = (u64) *offset;
9905 j++;
9906 continue;
9907 }
9908 /* 8-byte counter */
9909 buf[j] = HILO_U64(*offset, *(offset + 1));
9910 j++;
9911 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009912 }
9913}
9914
9915static int bnx2x_phys_id(struct net_device *dev, u32 data)
9916{
9917 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009918 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009919 int i;
9920
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009921 if (!netif_running(dev))
9922 return 0;
9923
9924 if (!bp->port.pmf)
9925 return 0;
9926
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009927 if (data == 0)
9928 data = 2;
9929
9930 for (i = 0; i < (data * 2); i++) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009931 if ((i % 2) == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009932 bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009933 bp->link_params.hw_led_mode,
9934 bp->link_params.chip_id);
9935 else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009936 bnx2x_set_led(bp, port, LED_MODE_OFF, 0,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009937 bp->link_params.hw_led_mode,
9938 bp->link_params.chip_id);
9939
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009940 msleep_interruptible(500);
9941 if (signal_pending(current))
9942 break;
9943 }
9944
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009945 if (bp->link_vars.link_up)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009946 bnx2x_set_led(bp, port, LED_MODE_OPER,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009947 bp->link_vars.line_speed,
9948 bp->link_params.hw_led_mode,
9949 bp->link_params.chip_id);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009950
9951 return 0;
9952}
9953
9954static struct ethtool_ops bnx2x_ethtool_ops = {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009955 .get_settings = bnx2x_get_settings,
9956 .set_settings = bnx2x_set_settings,
9957 .get_drvinfo = bnx2x_get_drvinfo,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009958 .get_wol = bnx2x_get_wol,
9959 .set_wol = bnx2x_set_wol,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009960 .get_msglevel = bnx2x_get_msglevel,
9961 .set_msglevel = bnx2x_set_msglevel,
9962 .nway_reset = bnx2x_nway_reset,
9963 .get_link = ethtool_op_get_link,
9964 .get_eeprom_len = bnx2x_get_eeprom_len,
9965 .get_eeprom = bnx2x_get_eeprom,
9966 .set_eeprom = bnx2x_set_eeprom,
9967 .get_coalesce = bnx2x_get_coalesce,
9968 .set_coalesce = bnx2x_set_coalesce,
9969 .get_ringparam = bnx2x_get_ringparam,
9970 .set_ringparam = bnx2x_set_ringparam,
9971 .get_pauseparam = bnx2x_get_pauseparam,
9972 .set_pauseparam = bnx2x_set_pauseparam,
9973 .get_rx_csum = bnx2x_get_rx_csum,
9974 .set_rx_csum = bnx2x_set_rx_csum,
9975 .get_tx_csum = ethtool_op_get_tx_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -07009976 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009977 .set_flags = bnx2x_set_flags,
9978 .get_flags = ethtool_op_get_flags,
9979 .get_sg = ethtool_op_get_sg,
9980 .set_sg = ethtool_op_set_sg,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009981 .get_tso = ethtool_op_get_tso,
9982 .set_tso = bnx2x_set_tso,
9983 .self_test_count = bnx2x_self_test_count,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009984 .self_test = bnx2x_self_test,
9985 .get_strings = bnx2x_get_strings,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009986 .phys_id = bnx2x_phys_id,
9987 .get_stats_count = bnx2x_get_stats_count,
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009988 .get_ethtool_stats = bnx2x_get_ethtool_stats,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009989};
9990
9991/* end of ethtool_ops */
9992
9993/****************************************************************************
9994* General service functions
9995****************************************************************************/
9996
9997static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
9998{
9999 u16 pmcsr;
10000
10001 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
10002
10003 switch (state) {
10004 case PCI_D0:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010005 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010006 ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
10007 PCI_PM_CTRL_PME_STATUS));
10008
10009 if (pmcsr & PCI_PM_CTRL_STATE_MASK)
Eilon Greenstein33471622008-08-13 15:59:08 -070010010 /* delay required during transition out of D3hot */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010011 msleep(20);
10012 break;
10013
10014 case PCI_D3hot:
10015 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
10016 pmcsr |= 3;
10017
10018 if (bp->wol)
10019 pmcsr |= PCI_PM_CTRL_PME_ENABLE;
10020
10021 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
10022 pmcsr);
10023
10024 /* No more memory access after this point until
10025 * device is brought back to D0.
10026 */
10027 break;
10028
10029 default:
10030 return -EINVAL;
10031 }
10032 return 0;
10033}
10034
Eilon Greenstein237907c2009-01-14 06:42:44 +000010035static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
10036{
10037 u16 rx_cons_sb;
10038
10039 /* Tell compiler that status block fields can change */
10040 barrier();
10041 rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
10042 if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
10043 rx_cons_sb++;
10044 return (fp->rx_comp_cons != rx_cons_sb);
10045}
10046
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010047/*
10048 * net_device service functions
10049 */
10050
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010051static int bnx2x_poll(struct napi_struct *napi, int budget)
10052{
10053 struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
10054 napi);
10055 struct bnx2x *bp = fp->bp;
10056 int work_done = 0;
10057
10058#ifdef BNX2X_STOP_ON_ERROR
10059 if (unlikely(bp->panic))
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010060 goto poll_panic;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010061#endif
10062
10063 prefetch(fp->tx_buf_ring[TX_BD(fp->tx_pkt_cons)].skb);
10064 prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
10065 prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
10066
10067 bnx2x_update_fpsb_idx(fp);
10068
Eilon Greenstein237907c2009-01-14 06:42:44 +000010069 if (bnx2x_has_tx_work(fp))
Eilon Greenstein7961f792009-03-02 07:59:31 +000010070 bnx2x_tx_int(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010071
Eilon Greenstein8534f322009-03-02 07:59:45 +000010072 if (bnx2x_has_rx_work(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010073 work_done = bnx2x_rx_int(fp, budget);
Eilon Greenstein356e2382009-02-12 08:38:32 +000010074
Eilon Greenstein8534f322009-03-02 07:59:45 +000010075 /* must not complete if we consumed full budget */
10076 if (work_done >= budget)
10077 goto poll_again;
10078 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010079
Eilon Greenstein8534f322009-03-02 07:59:45 +000010080 /* BNX2X_HAS_WORK() reads the status block, thus we need to
10081 * ensure that status block indices have been actually read
10082 * (bnx2x_update_fpsb_idx) prior to this check (BNX2X_HAS_WORK)
10083 * so that we won't write the "newer" value of the status block to IGU
10084 * (if there was a DMA right after BNX2X_HAS_WORK and
10085 * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx)
10086 * may be postponed to right before bnx2x_ack_sb). In this case
10087 * there will never be another interrupt until there is another update
10088 * of the status block, while there is still unhandled work.
10089 */
10090 rmb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010091
Eilon Greenstein8534f322009-03-02 07:59:45 +000010092 if (!BNX2X_HAS_WORK(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010093#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010094poll_panic:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010095#endif
Ben Hutchings288379f2009-01-19 16:43:59 -080010096 napi_complete(napi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010097
Eilon Greenstein0626b892009-02-12 08:38:14 +000010098 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010099 le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
Eilon Greenstein0626b892009-02-12 08:38:14 +000010100 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010101 le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
10102 }
Eilon Greenstein356e2382009-02-12 08:38:32 +000010103
Eilon Greenstein8534f322009-03-02 07:59:45 +000010104poll_again:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010105 return work_done;
10106}
10107
Eilon Greenstein755735e2008-06-23 20:35:13 -070010108
10109/* we split the first BD into headers and data BDs
Eilon Greenstein33471622008-08-13 15:59:08 -070010110 * to ease the pain of our fellow microcode engineers
Eilon Greenstein755735e2008-06-23 20:35:13 -070010111 * we use one mapping for both BDs
10112 * So far this has only been observed to happen
10113 * in Other Operating Systems(TM)
10114 */
10115static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
10116 struct bnx2x_fastpath *fp,
10117 struct eth_tx_bd **tx_bd, u16 hlen,
10118 u16 bd_prod, int nbd)
10119{
10120 struct eth_tx_bd *h_tx_bd = *tx_bd;
10121 struct eth_tx_bd *d_tx_bd;
10122 dma_addr_t mapping;
10123 int old_len = le16_to_cpu(h_tx_bd->nbytes);
10124
10125 /* first fix first BD */
10126 h_tx_bd->nbd = cpu_to_le16(nbd);
10127 h_tx_bd->nbytes = cpu_to_le16(hlen);
10128
10129 DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
10130 "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
10131 h_tx_bd->addr_lo, h_tx_bd->nbd);
10132
10133 /* now get a new data BD
10134 * (after the pbd) and fill it */
10135 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10136 d_tx_bd = &fp->tx_desc_ring[bd_prod];
10137
10138 mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
10139 le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
10140
10141 d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10142 d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
10143 d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
10144 d_tx_bd->vlan = 0;
10145 /* this marks the BD as one that has no individual mapping
10146 * the FW ignores this flag in a BD not marked start
10147 */
10148 d_tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_SW_LSO;
10149 DP(NETIF_MSG_TX_QUEUED,
10150 "TSO split data size is %d (%x:%x)\n",
10151 d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
10152
10153 /* update tx_bd for marking the last BD flag */
10154 *tx_bd = d_tx_bd;
10155
10156 return bd_prod;
10157}
10158
10159static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
10160{
10161 if (fix > 0)
10162 csum = (u16) ~csum_fold(csum_sub(csum,
10163 csum_partial(t_header - fix, fix, 0)));
10164
10165 else if (fix < 0)
10166 csum = (u16) ~csum_fold(csum_add(csum,
10167 csum_partial(t_header, -fix, 0)));
10168
10169 return swab16(csum);
10170}
10171
10172static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
10173{
10174 u32 rc;
10175
10176 if (skb->ip_summed != CHECKSUM_PARTIAL)
10177 rc = XMIT_PLAIN;
10178
10179 else {
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000010180 if (skb->protocol == htons(ETH_P_IPV6)) {
Eilon Greenstein755735e2008-06-23 20:35:13 -070010181 rc = XMIT_CSUM_V6;
10182 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
10183 rc |= XMIT_CSUM_TCP;
10184
10185 } else {
10186 rc = XMIT_CSUM_V4;
10187 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
10188 rc |= XMIT_CSUM_TCP;
10189 }
10190 }
10191
10192 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
10193 rc |= XMIT_GSO_V4;
10194
10195 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
10196 rc |= XMIT_GSO_V6;
10197
10198 return rc;
10199}
10200
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010201#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greensteinf5372252009-02-12 08:38:30 +000010202/* check if packet requires linearization (packet is too fragmented)
10203 no need to check fragmentation if page size > 8K (there will be no
10204 violation to FW restrictions) */
Eilon Greenstein755735e2008-06-23 20:35:13 -070010205static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
10206 u32 xmit_type)
10207{
10208 int to_copy = 0;
10209 int hlen = 0;
10210 int first_bd_sz = 0;
10211
10212 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
10213 if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
10214
10215 if (xmit_type & XMIT_GSO) {
10216 unsigned short lso_mss = skb_shinfo(skb)->gso_size;
10217 /* Check if LSO packet needs to be copied:
10218 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
10219 int wnd_size = MAX_FETCH_BD - 3;
Eilon Greenstein33471622008-08-13 15:59:08 -070010220 /* Number of windows to check */
Eilon Greenstein755735e2008-06-23 20:35:13 -070010221 int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
10222 int wnd_idx = 0;
10223 int frag_idx = 0;
10224 u32 wnd_sum = 0;
10225
10226 /* Headers length */
10227 hlen = (int)(skb_transport_header(skb) - skb->data) +
10228 tcp_hdrlen(skb);
10229
10230 /* Amount of data (w/o headers) on linear part of SKB*/
10231 first_bd_sz = skb_headlen(skb) - hlen;
10232
10233 wnd_sum = first_bd_sz;
10234
10235 /* Calculate the first sum - it's special */
10236 for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
10237 wnd_sum +=
10238 skb_shinfo(skb)->frags[frag_idx].size;
10239
10240 /* If there was data on linear skb data - check it */
10241 if (first_bd_sz > 0) {
10242 if (unlikely(wnd_sum < lso_mss)) {
10243 to_copy = 1;
10244 goto exit_lbl;
10245 }
10246
10247 wnd_sum -= first_bd_sz;
10248 }
10249
10250 /* Others are easier: run through the frag list and
10251 check all windows */
10252 for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
10253 wnd_sum +=
10254 skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
10255
10256 if (unlikely(wnd_sum < lso_mss)) {
10257 to_copy = 1;
10258 break;
10259 }
10260 wnd_sum -=
10261 skb_shinfo(skb)->frags[wnd_idx].size;
10262 }
Eilon Greenstein755735e2008-06-23 20:35:13 -070010263 } else {
10264 /* in non-LSO too fragmented packet should always
10265 be linearized */
10266 to_copy = 1;
10267 }
10268 }
10269
10270exit_lbl:
10271 if (unlikely(to_copy))
10272 DP(NETIF_MSG_TX_QUEUED,
10273 "Linearization IS REQUIRED for %s packet. "
10274 "num_frags %d hlen %d first_bd_sz %d\n",
10275 (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
10276 skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
10277
10278 return to_copy;
10279}
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010280#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070010281
10282/* called with netif_tx_lock
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010283 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
Eilon Greenstein755735e2008-06-23 20:35:13 -070010284 * netif_wake_queue()
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010285 */
10286static int bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
10287{
10288 struct bnx2x *bp = netdev_priv(dev);
10289 struct bnx2x_fastpath *fp;
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010290 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010291 struct sw_tx_bd *tx_buf;
10292 struct eth_tx_bd *tx_bd;
10293 struct eth_tx_parse_bd *pbd = NULL;
10294 u16 pkt_prod, bd_prod;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010295 int nbd, fp_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010296 dma_addr_t mapping;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010297 u32 xmit_type = bnx2x_xmit_type(bp, skb);
10298 int vlan_off = (bp->e1hov ? 4 : 0);
10299 int i;
10300 u8 hlen = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010301
10302#ifdef BNX2X_STOP_ON_ERROR
10303 if (unlikely(bp->panic))
10304 return NETDEV_TX_BUSY;
10305#endif
10306
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010307 fp_index = skb_get_queue_mapping(skb);
10308 txq = netdev_get_tx_queue(dev, fp_index);
10309
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010310 fp = &bp->fp[fp_index];
Eilon Greenstein755735e2008-06-23 20:35:13 -070010311
Yitchak Gertner231fd582008-08-25 15:27:06 -070010312 if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
Eilon Greensteinde832a52009-02-12 08:36:33 +000010313 fp->eth_q_stats.driver_xoff++,
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010314 netif_tx_stop_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010315 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
10316 return NETDEV_TX_BUSY;
10317 }
10318
Eilon Greenstein755735e2008-06-23 20:35:13 -070010319 DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)"
10320 " gso type %x xmit_type %x\n",
10321 skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
10322 ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
10323
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010324#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greensteinf5372252009-02-12 08:38:30 +000010325 /* First, check if we need to linearize the skb (due to FW
10326 restrictions). No need to check fragmentation if page size > 8K
10327 (there will be no violation to FW restrictions) */
Eilon Greenstein755735e2008-06-23 20:35:13 -070010328 if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
10329 /* Statistics of linearization */
10330 bp->lin_cnt++;
10331 if (skb_linearize(skb) != 0) {
10332 DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
10333 "silently dropping this SKB\n");
10334 dev_kfree_skb_any(skb);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070010335 return NETDEV_TX_OK;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010336 }
10337 }
Eilon Greenstein632da4d2009-01-14 06:44:10 +000010338#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070010339
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010340 /*
Eilon Greenstein755735e2008-06-23 20:35:13 -070010341 Please read carefully. First we use one BD which we mark as start,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010342 then for TSO or xsum we have a parsing info BD,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010343 and only then we have the rest of the TSO BDs.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010344 (don't forget to mark the last one as last,
10345 and to unmap only AFTER you write to the BD ...)
Eilon Greenstein755735e2008-06-23 20:35:13 -070010346 And above all, all pdb sizes are in words - NOT DWORDS!
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010347 */
10348
10349 pkt_prod = fp->tx_pkt_prod++;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010350 bd_prod = TX_BD(fp->tx_bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010351
Eilon Greenstein755735e2008-06-23 20:35:13 -070010352 /* get a tx_buf and first BD */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010353 tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
10354 tx_bd = &fp->tx_desc_ring[bd_prod];
10355
10356 tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
10357 tx_bd->general_data = (UNICAST_ADDRESS <<
10358 ETH_TX_BD_ETH_ADDR_TYPE_SHIFT);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010359 /* header nbd */
10360 tx_bd->general_data |= (1 << ETH_TX_BD_HDR_NBDS_SHIFT);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010361
Eilon Greenstein755735e2008-06-23 20:35:13 -070010362 /* remember the first BD of the packet */
10363 tx_buf->first_bd = fp->tx_bd_prod;
10364 tx_buf->skb = skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010365
10366 DP(NETIF_MSG_TX_QUEUED,
10367 "sending pkt %u @%p next_idx %u bd %u @%p\n",
10368 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_bd);
10369
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010370#ifdef BCM_VLAN
10371 if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) &&
10372 (bp->flags & HW_VLAN_TX_FLAG)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010373 tx_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb));
10374 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG;
Eilon Greenstein755735e2008-06-23 20:35:13 -070010375 vlan_off += 4;
10376 } else
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010377#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010378 tx_bd->vlan = cpu_to_le16(pkt_prod);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010379
10380 if (xmit_type) {
Eilon Greenstein755735e2008-06-23 20:35:13 -070010381 /* turn on parsing and get a BD */
10382 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10383 pbd = (void *)&fp->tx_desc_ring[bd_prod];
10384
10385 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
10386 }
10387
10388 if (xmit_type & XMIT_CSUM) {
10389 hlen = (skb_network_header(skb) - skb->data + vlan_off) / 2;
10390
10391 /* for now NS flag is not used in Linux */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000010392 pbd->global_data =
10393 (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
10394 ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT));
Eilon Greenstein755735e2008-06-23 20:35:13 -070010395
10396 pbd->ip_hlen = (skb_transport_header(skb) -
10397 skb_network_header(skb)) / 2;
10398
10399 hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2;
10400
10401 pbd->total_hlen = cpu_to_le16(hlen);
10402 hlen = hlen*2 - vlan_off;
10403
10404 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_TCP_CSUM;
10405
10406 if (xmit_type & XMIT_CSUM_V4)
10407 tx_bd->bd_flags.as_bitfield |=
10408 ETH_TX_BD_FLAGS_IP_CSUM;
10409 else
10410 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IPV6;
10411
10412 if (xmit_type & XMIT_CSUM_TCP) {
10413 pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
10414
10415 } else {
10416 s8 fix = SKB_CS_OFF(skb); /* signed! */
10417
10418 pbd->global_data |= ETH_TX_PARSE_BD_CS_ANY_FLG;
10419 pbd->cs_offset = fix / 2;
10420
10421 DP(NETIF_MSG_TX_QUEUED,
10422 "hlen %d offset %d fix %d csum before fix %x\n",
10423 le16_to_cpu(pbd->total_hlen), pbd->cs_offset, fix,
10424 SKB_CS(skb));
10425
10426 /* HW bug: fixup the CSUM */
10427 pbd->tcp_pseudo_csum =
10428 bnx2x_csum_fix(skb_transport_header(skb),
10429 SKB_CS(skb), fix);
10430
10431 DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
10432 pbd->tcp_pseudo_csum);
10433 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010434 }
10435
10436 mapping = pci_map_single(bp->pdev, skb->data,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010437 skb_headlen(skb), PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010438
10439 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10440 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
Eilon Greenstein6378c022008-08-13 15:59:25 -070010441 nbd = skb_shinfo(skb)->nr_frags + ((pbd == NULL) ? 1 : 2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010442 tx_bd->nbd = cpu_to_le16(nbd);
10443 tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
10444
10445 DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
Eilon Greenstein755735e2008-06-23 20:35:13 -070010446 " nbytes %d flags %x vlan %x\n",
10447 tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, le16_to_cpu(tx_bd->nbd),
10448 le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield,
10449 le16_to_cpu(tx_bd->vlan));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010450
Eilon Greenstein755735e2008-06-23 20:35:13 -070010451 if (xmit_type & XMIT_GSO) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010452
10453 DP(NETIF_MSG_TX_QUEUED,
10454 "TSO packet len %d hlen %d total len %d tso size %d\n",
10455 skb->len, hlen, skb_headlen(skb),
10456 skb_shinfo(skb)->gso_size);
10457
10458 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
10459
Eilon Greenstein755735e2008-06-23 20:35:13 -070010460 if (unlikely(skb_headlen(skb) > hlen))
10461 bd_prod = bnx2x_tx_split(bp, fp, &tx_bd, hlen,
10462 bd_prod, ++nbd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010463
10464 pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
10465 pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010466 pbd->tcp_flags = pbd_tcp_flags(skb);
10467
10468 if (xmit_type & XMIT_GSO_V4) {
10469 pbd->ip_id = swab16(ip_hdr(skb)->id);
10470 pbd->tcp_pseudo_csum =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010471 swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
10472 ip_hdr(skb)->daddr,
10473 0, IPPROTO_TCP, 0));
Eilon Greenstein755735e2008-06-23 20:35:13 -070010474
10475 } else
10476 pbd->tcp_pseudo_csum =
10477 swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
10478 &ipv6_hdr(skb)->daddr,
10479 0, IPPROTO_TCP, 0));
10480
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010481 pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN;
10482 }
10483
Eilon Greenstein755735e2008-06-23 20:35:13 -070010484 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
10485 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010486
Eilon Greenstein755735e2008-06-23 20:35:13 -070010487 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10488 tx_bd = &fp->tx_desc_ring[bd_prod];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010489
Eilon Greenstein755735e2008-06-23 20:35:13 -070010490 mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
10491 frag->size, PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010492
Eilon Greenstein755735e2008-06-23 20:35:13 -070010493 tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10494 tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
10495 tx_bd->nbytes = cpu_to_le16(frag->size);
10496 tx_bd->vlan = cpu_to_le16(pkt_prod);
10497 tx_bd->bd_flags.as_bitfield = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010498
Eilon Greenstein755735e2008-06-23 20:35:13 -070010499 DP(NETIF_MSG_TX_QUEUED,
10500 "frag %d bd @%p addr (%x:%x) nbytes %d flags %x\n",
10501 i, tx_bd, tx_bd->addr_hi, tx_bd->addr_lo,
10502 le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010503 }
10504
Eilon Greenstein755735e2008-06-23 20:35:13 -070010505 /* now at last mark the BD as the last BD */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010506 tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_END_BD;
10507
10508 DP(NETIF_MSG_TX_QUEUED, "last bd @%p flags %x\n",
10509 tx_bd, tx_bd->bd_flags.as_bitfield);
10510
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010511 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10512
Eilon Greenstein755735e2008-06-23 20:35:13 -070010513 /* now send a tx doorbell, counting the next BD
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010514 * if the packet contains or ends with it
10515 */
10516 if (TX_BD_POFF(bd_prod) < nbd)
10517 nbd++;
10518
10519 if (pbd)
10520 DP(NETIF_MSG_TX_QUEUED,
10521 "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
10522 " tcp_flags %x xsum %x seq %u hlen %u\n",
10523 pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id,
10524 pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010525 pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010526
Eilon Greenstein755735e2008-06-23 20:35:13 -070010527 DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010528
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080010529 /*
10530 * Make sure that the BD data is updated before updating the producer
10531 * since FW might read the BD right after the producer is updated.
10532 * This is only applicable for weak-ordered memory model archs such
10533 * as IA-64. The following barrier is also mandatory since FW will
10534 * assumes packets must have BDs.
10535 */
10536 wmb();
10537
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000010538 le16_add_cpu(&fp->hw_tx_prods->bds_prod, nbd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010539 mb(); /* FW restriction: must not reorder writing nbd and packets */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000010540 le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1);
Eilon Greenstein0626b892009-02-12 08:38:14 +000010541 DOORBELL(bp, fp->index, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010542
10543 mmiowb();
10544
Eilon Greenstein755735e2008-06-23 20:35:13 -070010545 fp->tx_bd_prod += nbd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010546 dev->trans_start = jiffies;
10547
10548 if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080010549 /* We want bnx2x_tx_int to "see" the updated tx_bd_prod
10550 if we put Tx into XOFF state. */
10551 smp_mb();
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010552 netif_tx_stop_queue(txq);
Eilon Greensteinde832a52009-02-12 08:36:33 +000010553 fp->eth_q_stats.driver_xoff++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010554 if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
Eilon Greenstein555f6c72009-02-12 08:36:11 +000010555 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010556 }
10557 fp->tx_pkt++;
10558
10559 return NETDEV_TX_OK;
10560}
10561
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010562/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010563static int bnx2x_open(struct net_device *dev)
10564{
10565 struct bnx2x *bp = netdev_priv(dev);
10566
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000010567 netif_carrier_off(dev);
10568
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010569 bnx2x_set_power_state(bp, PCI_D0);
10570
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010571 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010572}
10573
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010574/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010575static int bnx2x_close(struct net_device *dev)
10576{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010577 struct bnx2x *bp = netdev_priv(dev);
10578
10579 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010580 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
10581 if (atomic_read(&bp->pdev->enable_cnt) == 1)
10582 if (!CHIP_REV_IS_SLOW(bp))
10583 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010584
10585 return 0;
10586}
10587
Eilon Greensteinf5372252009-02-12 08:38:30 +000010588/* called with netif_tx_lock from dev_mcast.c */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010589static void bnx2x_set_rx_mode(struct net_device *dev)
10590{
10591 struct bnx2x *bp = netdev_priv(dev);
10592 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
10593 int port = BP_PORT(bp);
10594
10595 if (bp->state != BNX2X_STATE_OPEN) {
10596 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
10597 return;
10598 }
10599
10600 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
10601
10602 if (dev->flags & IFF_PROMISC)
10603 rx_mode = BNX2X_RX_MODE_PROMISC;
10604
10605 else if ((dev->flags & IFF_ALLMULTI) ||
10606 ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp)))
10607 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10608
10609 else { /* some multicasts */
10610 if (CHIP_IS_E1(bp)) {
10611 int i, old, offset;
10612 struct dev_mc_list *mclist;
10613 struct mac_configuration_cmd *config =
10614 bnx2x_sp(bp, mcast_config);
10615
10616 for (i = 0, mclist = dev->mc_list;
10617 mclist && (i < dev->mc_count);
10618 i++, mclist = mclist->next) {
10619
10620 config->config_table[i].
10621 cam_entry.msb_mac_addr =
10622 swab16(*(u16 *)&mclist->dmi_addr[0]);
10623 config->config_table[i].
10624 cam_entry.middle_mac_addr =
10625 swab16(*(u16 *)&mclist->dmi_addr[2]);
10626 config->config_table[i].
10627 cam_entry.lsb_mac_addr =
10628 swab16(*(u16 *)&mclist->dmi_addr[4]);
10629 config->config_table[i].cam_entry.flags =
10630 cpu_to_le16(port);
10631 config->config_table[i].
10632 target_table_entry.flags = 0;
10633 config->config_table[i].
10634 target_table_entry.client_id = 0;
10635 config->config_table[i].
10636 target_table_entry.vlan_id = 0;
10637
10638 DP(NETIF_MSG_IFUP,
10639 "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
10640 config->config_table[i].
10641 cam_entry.msb_mac_addr,
10642 config->config_table[i].
10643 cam_entry.middle_mac_addr,
10644 config->config_table[i].
10645 cam_entry.lsb_mac_addr);
10646 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010647 old = config->hdr.length;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010648 if (old > i) {
10649 for (; i < old; i++) {
10650 if (CAM_IS_INVALID(config->
10651 config_table[i])) {
Eilon Greensteinaf246402009-01-14 06:43:59 +000010652 /* already invalidated */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010653 break;
10654 }
10655 /* invalidate */
10656 CAM_INVALIDATE(config->
10657 config_table[i]);
10658 }
10659 }
10660
10661 if (CHIP_REV_IS_SLOW(bp))
10662 offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
10663 else
10664 offset = BNX2X_MAX_MULTICAST*(1 + port);
10665
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010666 config->hdr.length = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010667 config->hdr.offset = offset;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010668 config->hdr.client_id = bp->fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010669 config->hdr.reserved1 = 0;
10670
10671 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
10672 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
10673 U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
10674 0);
10675 } else { /* E1H */
10676 /* Accept one or more multicasts */
10677 struct dev_mc_list *mclist;
10678 u32 mc_filter[MC_HASH_SIZE];
10679 u32 crc, bit, regidx;
10680 int i;
10681
10682 memset(mc_filter, 0, 4 * MC_HASH_SIZE);
10683
10684 for (i = 0, mclist = dev->mc_list;
10685 mclist && (i < dev->mc_count);
10686 i++, mclist = mclist->next) {
10687
Johannes Berg7c510e42008-10-27 17:47:26 -070010688 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
10689 mclist->dmi_addr);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010690
10691 crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
10692 bit = (crc >> 24) & 0xff;
10693 regidx = bit >> 5;
10694 bit &= 0x1f;
10695 mc_filter[regidx] |= (1 << bit);
10696 }
10697
10698 for (i = 0; i < MC_HASH_SIZE; i++)
10699 REG_WR(bp, MC_HASH_OFFSET(bp, i),
10700 mc_filter[i]);
10701 }
10702 }
10703
10704 bp->rx_mode = rx_mode;
10705 bnx2x_set_storm_rx_mode(bp);
10706}
10707
10708/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010709static int bnx2x_change_mac_addr(struct net_device *dev, void *p)
10710{
10711 struct sockaddr *addr = p;
10712 struct bnx2x *bp = netdev_priv(dev);
10713
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010714 if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010715 return -EINVAL;
10716
10717 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010718 if (netif_running(dev)) {
10719 if (CHIP_IS_E1(bp))
Yitchak Gertner3101c2b2008-08-13 15:52:28 -070010720 bnx2x_set_mac_addr_e1(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010721 else
Yitchak Gertner3101c2b2008-08-13 15:52:28 -070010722 bnx2x_set_mac_addr_e1h(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010723 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010724
10725 return 0;
10726}
10727
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010728/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010729static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10730{
10731 struct mii_ioctl_data *data = if_mii(ifr);
10732 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010733 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010734 int err;
10735
10736 switch (cmd) {
10737 case SIOCGMIIPHY:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010738 data->phy_id = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010739
Eliezer Tamirc14423f2008-02-28 11:49:42 -080010740 /* fallthrough */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010741
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010742 case SIOCGMIIREG: {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010743 u16 mii_regval;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010744
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010745 if (!netif_running(dev))
10746 return -EAGAIN;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010747
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010748 mutex_lock(&bp->port.phy_mutex);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010749 err = bnx2x_cl45_read(bp, port, 0, bp->port.phy_addr,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010750 DEFAULT_PHY_DEV_ADDR,
10751 (data->reg_num & 0x1f), &mii_regval);
10752 data->val_out = mii_regval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010753 mutex_unlock(&bp->port.phy_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010754 return err;
10755 }
10756
10757 case SIOCSMIIREG:
10758 if (!capable(CAP_NET_ADMIN))
10759 return -EPERM;
10760
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010761 if (!netif_running(dev))
10762 return -EAGAIN;
10763
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010764 mutex_lock(&bp->port.phy_mutex);
Eilon Greenstein3196a882008-08-13 15:58:49 -070010765 err = bnx2x_cl45_write(bp, port, 0, bp->port.phy_addr,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010766 DEFAULT_PHY_DEV_ADDR,
10767 (data->reg_num & 0x1f), data->val_in);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010768 mutex_unlock(&bp->port.phy_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010769 return err;
10770
10771 default:
10772 /* do nothing */
10773 break;
10774 }
10775
10776 return -EOPNOTSUPP;
10777}
10778
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010779/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010780static int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
10781{
10782 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010783 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010784
10785 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
10786 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
10787 return -EINVAL;
10788
10789 /* This does not race with packet allocation
Eliezer Tamirc14423f2008-02-28 11:49:42 -080010790 * because the actual alloc size is
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010791 * only updated as part of load
10792 */
10793 dev->mtu = new_mtu;
10794
10795 if (netif_running(dev)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010796 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
10797 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010798 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010799
10800 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010801}
10802
10803static void bnx2x_tx_timeout(struct net_device *dev)
10804{
10805 struct bnx2x *bp = netdev_priv(dev);
10806
10807#ifdef BNX2X_STOP_ON_ERROR
10808 if (!bp->panic)
10809 bnx2x_panic();
10810#endif
10811 /* This allows the netif to be shutdown gracefully before resetting */
10812 schedule_work(&bp->reset_task);
10813}
10814
10815#ifdef BCM_VLAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010816/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010817static void bnx2x_vlan_rx_register(struct net_device *dev,
10818 struct vlan_group *vlgrp)
10819{
10820 struct bnx2x *bp = netdev_priv(dev);
10821
10822 bp->vlgrp = vlgrp;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010823
10824 /* Set flags according to the required capabilities */
10825 bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
10826
10827 if (dev->features & NETIF_F_HW_VLAN_TX)
10828 bp->flags |= HW_VLAN_TX_FLAG;
10829
10830 if (dev->features & NETIF_F_HW_VLAN_RX)
10831 bp->flags |= HW_VLAN_RX_FLAG;
10832
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010833 if (netif_running(dev))
Eliezer Tamir49d66772008-02-28 11:53:13 -080010834 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010835}
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010836
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010837#endif
10838
10839#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
10840static void poll_bnx2x(struct net_device *dev)
10841{
10842 struct bnx2x *bp = netdev_priv(dev);
10843
10844 disable_irq(bp->pdev->irq);
10845 bnx2x_interrupt(bp->pdev->irq, dev);
10846 enable_irq(bp->pdev->irq);
10847}
10848#endif
10849
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080010850static const struct net_device_ops bnx2x_netdev_ops = {
10851 .ndo_open = bnx2x_open,
10852 .ndo_stop = bnx2x_close,
10853 .ndo_start_xmit = bnx2x_start_xmit,
Eilon Greenstein356e2382009-02-12 08:38:32 +000010854 .ndo_set_multicast_list = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080010855 .ndo_set_mac_address = bnx2x_change_mac_addr,
10856 .ndo_validate_addr = eth_validate_addr,
10857 .ndo_do_ioctl = bnx2x_ioctl,
10858 .ndo_change_mtu = bnx2x_change_mtu,
10859 .ndo_tx_timeout = bnx2x_tx_timeout,
10860#ifdef BCM_VLAN
10861 .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
10862#endif
10863#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
10864 .ndo_poll_controller = poll_bnx2x,
10865#endif
10866};
10867
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010868static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
10869 struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010870{
10871 struct bnx2x *bp;
10872 int rc;
10873
10874 SET_NETDEV_DEV(dev, &pdev->dev);
10875 bp = netdev_priv(dev);
10876
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010877 bp->dev = dev;
10878 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010879 bp->flags = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010880 bp->func = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010881
10882 rc = pci_enable_device(pdev);
10883 if (rc) {
10884 printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n");
10885 goto err_out;
10886 }
10887
10888 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
10889 printk(KERN_ERR PFX "Cannot find PCI device base address,"
10890 " aborting\n");
10891 rc = -ENODEV;
10892 goto err_out_disable;
10893 }
10894
10895 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
10896 printk(KERN_ERR PFX "Cannot find second PCI device"
10897 " base address, aborting\n");
10898 rc = -ENODEV;
10899 goto err_out_disable;
10900 }
10901
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010902 if (atomic_read(&pdev->enable_cnt) == 1) {
10903 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10904 if (rc) {
10905 printk(KERN_ERR PFX "Cannot obtain PCI resources,"
10906 " aborting\n");
10907 goto err_out_disable;
10908 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010909
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010910 pci_set_master(pdev);
10911 pci_save_state(pdev);
10912 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010913
10914 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10915 if (bp->pm_cap == 0) {
10916 printk(KERN_ERR PFX "Cannot find power management"
10917 " capability, aborting\n");
10918 rc = -EIO;
10919 goto err_out_release;
10920 }
10921
10922 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
10923 if (bp->pcie_cap == 0) {
10924 printk(KERN_ERR PFX "Cannot find PCI Express capability,"
10925 " aborting\n");
10926 rc = -EIO;
10927 goto err_out_release;
10928 }
10929
10930 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
10931 bp->flags |= USING_DAC_FLAG;
10932 if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
10933 printk(KERN_ERR PFX "pci_set_consistent_dma_mask"
10934 " failed, aborting\n");
10935 rc = -EIO;
10936 goto err_out_release;
10937 }
10938
10939 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
10940 printk(KERN_ERR PFX "System does not support DMA,"
10941 " aborting\n");
10942 rc = -EIO;
10943 goto err_out_release;
10944 }
10945
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010946 dev->mem_start = pci_resource_start(pdev, 0);
10947 dev->base_addr = dev->mem_start;
10948 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010949
10950 dev->irq = pdev->irq;
10951
Arjan van de Ven275f1652008-10-20 21:42:39 -070010952 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010953 if (!bp->regview) {
10954 printk(KERN_ERR PFX "Cannot map register space, aborting\n");
10955 rc = -ENOMEM;
10956 goto err_out_release;
10957 }
10958
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010959 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
10960 min_t(u64, BNX2X_DB_SIZE,
10961 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010962 if (!bp->doorbells) {
10963 printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n");
10964 rc = -ENOMEM;
10965 goto err_out_unmap;
10966 }
10967
10968 bnx2x_set_power_state(bp, PCI_D0);
10969
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010970 /* clean indirect addresses */
10971 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10972 PCICFG_VENDOR_ID_OFFSET);
10973 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
10974 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
10975 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
10976 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010977
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010978 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010979
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080010980 dev->netdev_ops = &bnx2x_netdev_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010981 dev->ethtool_ops = &bnx2x_ethtool_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010982 dev->features |= NETIF_F_SG;
10983 dev->features |= NETIF_F_HW_CSUM;
10984 if (bp->flags & USING_DAC_FLAG)
10985 dev->features |= NETIF_F_HIGHDMA;
10986#ifdef BCM_VLAN
10987 dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080010988 bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010989#endif
10990 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010991 dev->features |= NETIF_F_TSO6;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010992
10993 return 0;
10994
10995err_out_unmap:
10996 if (bp->regview) {
10997 iounmap(bp->regview);
10998 bp->regview = NULL;
10999 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011000 if (bp->doorbells) {
11001 iounmap(bp->doorbells);
11002 bp->doorbells = NULL;
11003 }
11004
11005err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011006 if (atomic_read(&pdev->enable_cnt) == 1)
11007 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011008
11009err_out_disable:
11010 pci_disable_device(pdev);
11011 pci_set_drvdata(pdev, NULL);
11012
11013err_out:
11014 return rc;
11015}
11016
Eliezer Tamir25047952008-02-28 11:50:16 -080011017static int __devinit bnx2x_get_pcie_width(struct bnx2x *bp)
11018{
11019 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
11020
11021 val = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
11022 return val;
11023}
11024
11025/* return value of 1=2.5GHz 2=5GHz */
11026static int __devinit bnx2x_get_pcie_speed(struct bnx2x *bp)
11027{
11028 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
11029
11030 val = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
11031 return val;
11032}
11033
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011034static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11035 const struct pci_device_id *ent)
11036{
11037 static int version_printed;
11038 struct net_device *dev = NULL;
11039 struct bnx2x *bp;
Eliezer Tamir25047952008-02-28 11:50:16 -080011040 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011041
11042 if (version_printed++ == 0)
11043 printk(KERN_INFO "%s", version);
11044
11045 /* dev zeroed in init_etherdev */
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011046 dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011047 if (!dev) {
11048 printk(KERN_ERR PFX "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011049 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011050 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011051
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011052 bp = netdev_priv(dev);
11053 bp->msglevel = debug;
11054
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011055 rc = bnx2x_init_dev(pdev, dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011056 if (rc < 0) {
11057 free_netdev(dev);
11058 return rc;
11059 }
11060
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011061 pci_set_drvdata(pdev, dev);
11062
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011063 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000011064 if (rc)
11065 goto init_one_exit;
11066
11067 rc = register_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011068 if (rc) {
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000011069 dev_err(&pdev->dev, "Cannot register net device\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011070 goto init_one_exit;
11071 }
11072
Eliezer Tamir25047952008-02-28 11:50:16 -080011073 printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
Eilon Greenstein87942b42009-02-12 08:36:49 +000011074 " IRQ %d, ", dev->name, board_info[ent->driver_data].name,
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011075 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
Eliezer Tamir25047952008-02-28 11:50:16 -080011076 bnx2x_get_pcie_width(bp),
11077 (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz",
11078 dev->base_addr, bp->pdev->irq);
Johannes Berge1749612008-10-27 15:59:26 -070011079 printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011080 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011081
11082init_one_exit:
11083 if (bp->regview)
11084 iounmap(bp->regview);
11085
11086 if (bp->doorbells)
11087 iounmap(bp->doorbells);
11088
11089 free_netdev(dev);
11090
11091 if (atomic_read(&pdev->enable_cnt) == 1)
11092 pci_release_regions(pdev);
11093
11094 pci_disable_device(pdev);
11095 pci_set_drvdata(pdev, NULL);
11096
11097 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011098}
11099
11100static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11101{
11102 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011103 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011104
Eliezer Tamir228241e2008-02-28 11:56:57 -080011105 if (!dev) {
Eliezer Tamir228241e2008-02-28 11:56:57 -080011106 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11107 return;
11108 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011109 bp = netdev_priv(dev);
11110
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011111 unregister_netdev(dev);
11112
11113 if (bp->regview)
11114 iounmap(bp->regview);
11115
11116 if (bp->doorbells)
11117 iounmap(bp->doorbells);
11118
11119 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011120
11121 if (atomic_read(&pdev->enable_cnt) == 1)
11122 pci_release_regions(pdev);
11123
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011124 pci_disable_device(pdev);
11125 pci_set_drvdata(pdev, NULL);
11126}
11127
11128static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
11129{
11130 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011131 struct bnx2x *bp;
11132
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011133 if (!dev) {
11134 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11135 return -ENODEV;
11136 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011137 bp = netdev_priv(dev);
11138
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011139 rtnl_lock();
11140
11141 pci_save_state(pdev);
11142
11143 if (!netif_running(dev)) {
11144 rtnl_unlock();
11145 return 0;
11146 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011147
11148 netif_device_detach(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011149
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070011150 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011151
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011152 bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
Eliezer Tamir228241e2008-02-28 11:56:57 -080011153
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011154 rtnl_unlock();
11155
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011156 return 0;
11157}
11158
11159static int bnx2x_resume(struct pci_dev *pdev)
11160{
11161 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080011162 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011163 int rc;
11164
Eliezer Tamir228241e2008-02-28 11:56:57 -080011165 if (!dev) {
11166 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
11167 return -ENODEV;
11168 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080011169 bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011170
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011171 rtnl_lock();
11172
Eliezer Tamir228241e2008-02-28 11:56:57 -080011173 pci_restore_state(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011174
11175 if (!netif_running(dev)) {
11176 rtnl_unlock();
11177 return 0;
11178 }
11179
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011180 bnx2x_set_power_state(bp, PCI_D0);
11181 netif_device_attach(dev);
11182
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070011183 rc = bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011184
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011185 rtnl_unlock();
11186
11187 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011188}
11189
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011190static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
11191{
11192 int i;
11193
11194 bp->state = BNX2X_STATE_ERROR;
11195
11196 bp->rx_mode = BNX2X_RX_MODE_NONE;
11197
11198 bnx2x_netif_stop(bp, 0);
11199
11200 del_timer_sync(&bp->timer);
11201 bp->stats_state = STATS_STATE_DISABLED;
11202 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
11203
11204 /* Release IRQs */
11205 bnx2x_free_irq(bp);
11206
11207 if (CHIP_IS_E1(bp)) {
11208 struct mac_configuration_cmd *config =
11209 bnx2x_sp(bp, mcast_config);
11210
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080011211 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011212 CAM_INVALIDATE(config->config_table[i]);
11213 }
11214
11215 /* Free SKBs, SGEs, TPA pool and driver internals */
11216 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011217 for_each_rx_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011218 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011219 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +000011220 netif_napi_del(&bnx2x_fp(bp, i, napi));
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011221 bnx2x_free_mem(bp);
11222
11223 bp->state = BNX2X_STATE_CLOSED;
11224
11225 netif_carrier_off(bp->dev);
11226
11227 return 0;
11228}
11229
11230static void bnx2x_eeh_recover(struct bnx2x *bp)
11231{
11232 u32 val;
11233
11234 mutex_init(&bp->port.phy_mutex);
11235
11236 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
11237 bp->link_params.shmem_base = bp->common.shmem_base;
11238 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
11239
11240 if (!bp->common.shmem_base ||
11241 (bp->common.shmem_base < 0xA0000) ||
11242 (bp->common.shmem_base >= 0xC0000)) {
11243 BNX2X_DEV_INFO("MCP not active\n");
11244 bp->flags |= NO_MCP_FLAG;
11245 return;
11246 }
11247
11248 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
11249 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11250 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11251 BNX2X_ERR("BAD MCP validity signature\n");
11252
11253 if (!BP_NOMCP(bp)) {
11254 bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
11255 & DRV_MSG_SEQ_NUMBER_MASK);
11256 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11257 }
11258}
11259
Wendy Xiong493adb12008-06-23 20:36:22 -070011260/**
11261 * bnx2x_io_error_detected - called when PCI error is detected
11262 * @pdev: Pointer to PCI device
11263 * @state: The current pci connection state
11264 *
11265 * This function is called after a PCI bus error affecting
11266 * this device has been detected.
11267 */
11268static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
11269 pci_channel_state_t state)
11270{
11271 struct net_device *dev = pci_get_drvdata(pdev);
11272 struct bnx2x *bp = netdev_priv(dev);
11273
11274 rtnl_lock();
11275
11276 netif_device_detach(dev);
11277
11278 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011279 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070011280
11281 pci_disable_device(pdev);
11282
11283 rtnl_unlock();
11284
11285 /* Request a slot reset */
11286 return PCI_ERS_RESULT_NEED_RESET;
11287}
11288
11289/**
11290 * bnx2x_io_slot_reset - called after the PCI bus has been reset
11291 * @pdev: Pointer to PCI device
11292 *
11293 * Restart the card from scratch, as if from a cold-boot.
11294 */
11295static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
11296{
11297 struct net_device *dev = pci_get_drvdata(pdev);
11298 struct bnx2x *bp = netdev_priv(dev);
11299
11300 rtnl_lock();
11301
11302 if (pci_enable_device(pdev)) {
11303 dev_err(&pdev->dev,
11304 "Cannot re-enable PCI device after reset\n");
11305 rtnl_unlock();
11306 return PCI_ERS_RESULT_DISCONNECT;
11307 }
11308
11309 pci_set_master(pdev);
11310 pci_restore_state(pdev);
11311
11312 if (netif_running(dev))
11313 bnx2x_set_power_state(bp, PCI_D0);
11314
11315 rtnl_unlock();
11316
11317 return PCI_ERS_RESULT_RECOVERED;
11318}
11319
11320/**
11321 * bnx2x_io_resume - called when traffic can start flowing again
11322 * @pdev: Pointer to PCI device
11323 *
11324 * This callback is called when the error recovery driver tells us that
11325 * its OK to resume normal operation.
11326 */
11327static void bnx2x_io_resume(struct pci_dev *pdev)
11328{
11329 struct net_device *dev = pci_get_drvdata(pdev);
11330 struct bnx2x *bp = netdev_priv(dev);
11331
11332 rtnl_lock();
11333
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011334 bnx2x_eeh_recover(bp);
11335
Wendy Xiong493adb12008-06-23 20:36:22 -070011336 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070011337 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070011338
11339 netif_device_attach(dev);
11340
11341 rtnl_unlock();
11342}
11343
11344static struct pci_error_handlers bnx2x_err_handler = {
11345 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000011346 .slot_reset = bnx2x_io_slot_reset,
11347 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070011348};
11349
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011350static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070011351 .name = DRV_MODULE_NAME,
11352 .id_table = bnx2x_pci_tbl,
11353 .probe = bnx2x_init_one,
11354 .remove = __devexit_p(bnx2x_remove_one),
11355 .suspend = bnx2x_suspend,
11356 .resume = bnx2x_resume,
11357 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011358};
11359
11360static int __init bnx2x_init(void)
11361{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011362 bnx2x_wq = create_singlethread_workqueue("bnx2x");
11363 if (bnx2x_wq == NULL) {
11364 printk(KERN_ERR PFX "Cannot create workqueue\n");
11365 return -ENOMEM;
11366 }
11367
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011368 return pci_register_driver(&bnx2x_pci_driver);
11369}
11370
11371static void __exit bnx2x_cleanup(void)
11372{
11373 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011374
11375 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011376}
11377
11378module_init(bnx2x_init);
11379module_exit(bnx2x_cleanup);
11380