blob: 47d67e6aabcf0690d36ed13d4d5001474999c07d [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
Eilon Greensteinca003922009-08-12 22:53:28 -070013 * Slowpath and fastpath 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>
Ben Hutchings45229b42009-11-07 11:53:39 +000052#include <linux/stringify.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020053
Eilon Greenstein359d8b12009-02-12 08:38:25 +000054
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020055#include "bnx2x.h"
56#include "bnx2x_init.h"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070057#include "bnx2x_init_ops.h"
Eilon Greenstein0a64ea52009-03-02 08:01:12 +000058#include "bnx2x_dump.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020059
Yaniv Rosner89794a62009-11-05 20:00:59 -080060#define DRV_MODULE_VERSION "1.52.1-3"
61#define DRV_MODULE_RELDATE "2009/11/05"
Eilon Greenstein34f80b02008-06-23 20:33:01 -070062#define BNX2X_BC_VER 0x040200
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020063
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070064#include <linux/firmware.h>
65#include "bnx2x_fw_file_hdr.h"
66/* FW files */
Ben Hutchings45229b42009-11-07 11:53:39 +000067#define FW_FILE_VERSION \
68 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
69 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
70 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
71 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
72#define FW_FILE_NAME_E1 "bnx2x-e1-" FW_FILE_VERSION ".fw"
73#define FW_FILE_NAME_E1H "bnx2x-e1h-" FW_FILE_VERSION ".fw"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070074
Eilon Greenstein34f80b02008-06-23 20:33:01 -070075/* Time in jiffies before concluding the transmitter is hung */
76#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020077
Andrew Morton53a10562008-02-09 23:16:41 -080078static char version[] __devinitdata =
Eilon Greenstein34f80b02008-06-23 20:33:01 -070079 "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020080 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
81
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070082MODULE_AUTHOR("Eliezer Tamir");
Eilon Greensteine47d7e62009-01-14 06:44:28 +000083MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020084MODULE_LICENSE("GPL");
85MODULE_VERSION(DRV_MODULE_VERSION);
Ben Hutchings45229b42009-11-07 11:53:39 +000086MODULE_FIRMWARE(FW_FILE_NAME_E1);
87MODULE_FIRMWARE(FW_FILE_NAME_E1H);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020088
Eilon Greenstein555f6c72009-02-12 08:36:11 +000089static int multi_mode = 1;
90module_param(multi_mode, int, 0);
Eilon Greensteinca003922009-08-12 22:53:28 -070091MODULE_PARM_DESC(multi_mode, " Multi queue mode "
92 "(0 Disable; 1 Enable (default))");
93
94static int num_rx_queues;
95module_param(num_rx_queues, int, 0);
96MODULE_PARM_DESC(num_rx_queues, " Number of Rx queues for multi_mode=1"
97 " (default is half number of CPUs)");
98
99static int num_tx_queues;
100module_param(num_tx_queues, int, 0);
101MODULE_PARM_DESC(num_tx_queues, " Number of Tx queues for multi_mode=1"
102 " (default is half number of CPUs)");
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000103
Eilon Greenstein19680c42008-08-13 15:47:33 -0700104static int disable_tpa;
Eilon Greenstein19680c42008-08-13 15:47:33 -0700105module_param(disable_tpa, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000106MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000107
108static int int_mode;
109module_param(int_mode, int, 0);
110MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)");
111
Eilon Greensteina18f5122009-08-12 08:23:26 +0000112static int dropless_fc;
113module_param(dropless_fc, int, 0);
114MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
115
Eilon Greenstein9898f862009-02-12 08:38:27 +0000116static int poll;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200117module_param(poll, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000118MODULE_PARM_DESC(poll, " Use polling (for debug)");
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000119
120static int mrrs = -1;
121module_param(mrrs, int, 0);
122MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
123
Eilon Greenstein9898f862009-02-12 08:38:27 +0000124static int debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200125module_param(debug, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000126MODULE_PARM_DESC(debug, " Default debug msglevel");
127
128static int load_count[3]; /* 0-common, 1-port0, 2-port1 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200129
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800130static struct workqueue_struct *bnx2x_wq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200131
132enum bnx2x_board_type {
133 BCM57710 = 0,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700134 BCM57711 = 1,
135 BCM57711E = 2,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200136};
137
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700138/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800139static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200140 char *name;
141} board_info[] __devinitdata = {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700142 { "Broadcom NetXtreme II BCM57710 XGb" },
143 { "Broadcom NetXtreme II BCM57711 XGb" },
144 { "Broadcom NetXtreme II BCM57711E XGb" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200145};
146
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700147
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200148static const struct pci_device_id bnx2x_pci_tbl[] = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000149 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
150 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
151 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200152 { 0 }
153};
154
155MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
156
157/****************************************************************************
158* General service functions
159****************************************************************************/
160
161/* used only at init
162 * locking is done by mcp
163 */
Eilon Greenstein573f2032009-08-12 08:24:14 +0000164void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200165{
166 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
167 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
168 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
169 PCICFG_VENDOR_ID_OFFSET);
170}
171
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200172static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
173{
174 u32 val;
175
176 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
177 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
178 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
179 PCICFG_VENDOR_ID_OFFSET);
180
181 return val;
182}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200183
184static const u32 dmae_reg_go_c[] = {
185 DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
186 DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
187 DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
188 DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
189};
190
191/* copy command into DMAE command memory and set DMAE command go */
192static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
193 int idx)
194{
195 u32 cmd_offset;
196 int i;
197
198 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
199 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
200 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
201
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700202 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
203 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200204 }
205 REG_WR(bp, dmae_reg_go_c[idx], 1);
206}
207
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700208void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
209 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200210{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000211 struct dmae_command dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200212 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700213 int cnt = 200;
214
215 if (!bp->dmae_ready) {
216 u32 *data = bnx2x_sp(bp, wb_data[0]);
217
218 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
219 " using indirect\n", dst_addr, len32);
220 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
221 return;
222 }
223
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000224 memset(&dmae, 0, sizeof(struct dmae_command));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200225
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000226 dmae.opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
227 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
228 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200229#ifdef __BIG_ENDIAN
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000230 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200231#else
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000232 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200233#endif
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000234 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
235 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
236 dmae.src_addr_lo = U64_LO(dma_addr);
237 dmae.src_addr_hi = U64_HI(dma_addr);
238 dmae.dst_addr_lo = dst_addr >> 2;
239 dmae.dst_addr_hi = 0;
240 dmae.len = len32;
241 dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
242 dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
243 dmae.comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200244
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000245 DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200246 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
247 "dst_addr [%x:%08x (%08x)]\n"
248 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000249 dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
250 dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, dst_addr,
251 dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700252 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200253 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
254 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200255
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000256 mutex_lock(&bp->dmae_mutex);
257
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200258 *wb_comp = 0;
259
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000260 bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200261
262 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700263
264 while (*wb_comp != DMAE_COMP_VAL) {
265 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
266
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700267 if (!cnt) {
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000268 BNX2X_ERR("DMAE timeout!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200269 break;
270 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700271 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700272 /* adjust delay for emulation/FPGA */
273 if (CHIP_REV_IS_SLOW(bp))
274 msleep(100);
275 else
276 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200277 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700278
279 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200280}
281
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700282void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200283{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000284 struct dmae_command dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200285 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700286 int cnt = 200;
287
288 if (!bp->dmae_ready) {
289 u32 *data = bnx2x_sp(bp, wb_data[0]);
290 int i;
291
292 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
293 " using indirect\n", src_addr, len32);
294 for (i = 0; i < len32; i++)
295 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
296 return;
297 }
298
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000299 memset(&dmae, 0, sizeof(struct dmae_command));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200300
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000301 dmae.opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
302 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
303 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200304#ifdef __BIG_ENDIAN
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000305 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200306#else
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000307 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200308#endif
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000309 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
310 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
311 dmae.src_addr_lo = src_addr >> 2;
312 dmae.src_addr_hi = 0;
313 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
314 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
315 dmae.len = len32;
316 dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
317 dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
318 dmae.comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200319
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000320 DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200321 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
322 "dst_addr [%x:%08x (%08x)]\n"
323 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000324 dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
325 dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, src_addr,
326 dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200327
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000328 mutex_lock(&bp->dmae_mutex);
329
330 memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200331 *wb_comp = 0;
332
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000333 bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200334
335 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700336
337 while (*wb_comp != DMAE_COMP_VAL) {
338
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700339 if (!cnt) {
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000340 BNX2X_ERR("DMAE timeout!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200341 break;
342 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700343 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700344 /* adjust delay for emulation/FPGA */
345 if (CHIP_REV_IS_SLOW(bp))
346 msleep(100);
347 else
348 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200349 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700350 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200351 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
352 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700353
354 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200355}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200356
Eilon Greenstein573f2032009-08-12 08:24:14 +0000357void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
358 u32 addr, u32 len)
359{
360 int offset = 0;
361
362 while (len > DMAE_LEN32_WR_MAX) {
363 bnx2x_write_dmae(bp, phys_addr + offset,
364 addr + offset, DMAE_LEN32_WR_MAX);
365 offset += DMAE_LEN32_WR_MAX * 4;
366 len -= DMAE_LEN32_WR_MAX;
367 }
368
369 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
370}
371
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700372/* used only for slowpath so not inlined */
373static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
374{
375 u32 wb_write[2];
376
377 wb_write[0] = val_hi;
378 wb_write[1] = val_lo;
379 REG_WR_DMAE(bp, reg, wb_write, 2);
380}
381
382#ifdef USE_WB_RD
383static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
384{
385 u32 wb_data[2];
386
387 REG_RD_DMAE(bp, reg, wb_data, 2);
388
389 return HILO_U64(wb_data[0], wb_data[1]);
390}
391#endif
392
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200393static int bnx2x_mc_assert(struct bnx2x *bp)
394{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200395 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700396 int i, rc = 0;
397 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200398
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700399 /* XSTORM */
400 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
401 XSTORM_ASSERT_LIST_INDEX_OFFSET);
402 if (last_idx)
403 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200404
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700405 /* print the asserts */
406 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200407
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700408 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
409 XSTORM_ASSERT_LIST_OFFSET(i));
410 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
411 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
412 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
413 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
414 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
415 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200416
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700417 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
418 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
419 " 0x%08x 0x%08x 0x%08x\n",
420 i, row3, row2, row1, row0);
421 rc++;
422 } else {
423 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200424 }
425 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700426
427 /* TSTORM */
428 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
429 TSTORM_ASSERT_LIST_INDEX_OFFSET);
430 if (last_idx)
431 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
432
433 /* print the asserts */
434 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
435
436 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
437 TSTORM_ASSERT_LIST_OFFSET(i));
438 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
439 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
440 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
441 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
442 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
443 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
444
445 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
446 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
447 " 0x%08x 0x%08x 0x%08x\n",
448 i, row3, row2, row1, row0);
449 rc++;
450 } else {
451 break;
452 }
453 }
454
455 /* CSTORM */
456 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
457 CSTORM_ASSERT_LIST_INDEX_OFFSET);
458 if (last_idx)
459 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
460
461 /* print the asserts */
462 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
463
464 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
465 CSTORM_ASSERT_LIST_OFFSET(i));
466 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
467 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
468 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
469 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
470 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
471 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
472
473 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
474 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
475 " 0x%08x 0x%08x 0x%08x\n",
476 i, row3, row2, row1, row0);
477 rc++;
478 } else {
479 break;
480 }
481 }
482
483 /* USTORM */
484 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
485 USTORM_ASSERT_LIST_INDEX_OFFSET);
486 if (last_idx)
487 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
488
489 /* print the asserts */
490 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
491
492 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
493 USTORM_ASSERT_LIST_OFFSET(i));
494 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
495 USTORM_ASSERT_LIST_OFFSET(i) + 4);
496 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
497 USTORM_ASSERT_LIST_OFFSET(i) + 8);
498 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
499 USTORM_ASSERT_LIST_OFFSET(i) + 12);
500
501 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
502 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
503 " 0x%08x 0x%08x 0x%08x\n",
504 i, row3, row2, row1, row0);
505 rc++;
506 } else {
507 break;
508 }
509 }
510
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200511 return rc;
512}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800513
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200514static void bnx2x_fw_dump(struct bnx2x *bp)
515{
516 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000517 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200518 int word;
519
520 mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800521 mark = ((mark + 0x3) & ~0x3);
Joe Perchesad361c92009-07-06 13:05:40 -0700522 printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n", mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200523
Joe Perchesad361c92009-07-06 13:05:40 -0700524 printk(KERN_ERR PFX);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200525 for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) {
526 for (word = 0; word < 8; word++)
527 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
528 offset + 4*word));
529 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800530 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200531 }
532 for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) {
533 for (word = 0; word < 8; word++)
534 data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
535 offset + 4*word));
536 data[8] = 0x0;
Eliezer Tamir49d66772008-02-28 11:53:13 -0800537 printk(KERN_CONT "%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200538 }
Joe Perchesad361c92009-07-06 13:05:40 -0700539 printk(KERN_ERR PFX "end of fw dump\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200540}
541
542static void bnx2x_panic_dump(struct bnx2x *bp)
543{
544 int i;
545 u16 j, start, end;
546
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700547 bp->stats_state = STATS_STATE_DISABLED;
548 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
549
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200550 BNX2X_ERR("begin crash dump -----------------\n");
551
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000552 /* Indices */
553 /* Common */
554 BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)"
555 " def_t_idx(%u) def_att_idx(%u) attn_state(%u)"
556 " spq_prod_idx(%u)\n",
557 bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
558 bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
559
560 /* Rx */
561 for_each_rx_queue(bp, i) {
562 struct bnx2x_fastpath *fp = &bp->fp[i];
563
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000564 BNX2X_ERR("fp%d: rx_bd_prod(%x) rx_bd_cons(%x)"
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000565 " *rx_bd_cons_sb(%x) rx_comp_prod(%x)"
566 " rx_comp_cons(%x) *rx_cons_sb(%x)\n",
567 i, fp->rx_bd_prod, fp->rx_bd_cons,
568 le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
569 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000570 BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)"
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000571 " fp_u_idx(%x) *sb_u_idx(%x)\n",
572 fp->rx_sge_prod, fp->last_max_sge,
573 le16_to_cpu(fp->fp_u_idx),
574 fp->status_blk->u_status_block.status_block_index);
575 }
576
577 /* Tx */
578 for_each_tx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200579 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200580
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000581 BNX2X_ERR("fp%d: tx_pkt_prod(%x) tx_pkt_cons(%x)"
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700582 " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200583 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700584 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000585 BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)"
Eilon Greensteinca003922009-08-12 22:53:28 -0700586 " tx_db_prod(%x)\n", le16_to_cpu(fp->fp_c_idx),
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700587 fp->status_blk->c_status_block.status_block_index,
Eilon Greensteinca003922009-08-12 22:53:28 -0700588 fp->tx_db.data.prod);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000589 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200590
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000591 /* Rings */
592 /* Rx */
593 for_each_rx_queue(bp, i) {
594 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200595
596 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
597 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000598 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200599 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
600 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
601
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000602 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
603 i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200604 }
605
Eilon Greenstein3196a882008-08-13 15:58:49 -0700606 start = RX_SGE(fp->rx_sge_prod);
607 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000608 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700609 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
610 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
611
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000612 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
613 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700614 }
615
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200616 start = RCQ_BD(fp->rx_comp_cons - 10);
617 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000618 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200619 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
620
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000621 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
622 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200623 }
624 }
625
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000626 /* Tx */
627 for_each_tx_queue(bp, i) {
628 struct bnx2x_fastpath *fp = &bp->fp[i];
629
630 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
631 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
632 for (j = start; j != end; j = TX_BD(j + 1)) {
633 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
634
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000635 BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
636 i, j, sw_bd->skb, sw_bd->first_bd);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000637 }
638
639 start = TX_BD(fp->tx_bd_cons - 10);
640 end = TX_BD(fp->tx_bd_cons + 254);
641 for (j = start; j != end; j = TX_BD(j + 1)) {
642 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
643
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000644 BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
645 i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000646 }
647 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200648
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700649 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200650 bnx2x_mc_assert(bp);
651 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200652}
653
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800654static void bnx2x_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200655{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700656 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200657 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
658 u32 val = REG_RD(bp, addr);
659 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000660 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200661
662 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000663 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
664 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200665 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
666 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eilon Greenstein8badd272009-02-12 08:36:15 +0000667 } else if (msi) {
668 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
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_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200672 } else {
673 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800674 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200675 HC_CONFIG_0_REG_INT_LINE_EN_0 |
676 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800677
Eilon Greenstein8badd272009-02-12 08:36:15 +0000678 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
679 val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800680
681 REG_WR(bp, addr, val);
682
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200683 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
684 }
685
Eilon Greenstein8badd272009-02-12 08:36:15 +0000686 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
687 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200688
689 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +0000690 /*
691 * Ensure that HC_CONFIG is written before leading/trailing edge config
692 */
693 mmiowb();
694 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700695
696 if (CHIP_IS_E1H(bp)) {
697 /* init leading/trailing edge */
698 if (IS_E1HMF(bp)) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000699 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700700 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +0000701 /* enable nig and gpio3 attention */
702 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700703 } else
704 val = 0xffff;
705
706 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
707 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
708 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +0000709
710 /* Make sure that interrupts are indeed enabled from here on */
711 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200712}
713
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800714static void bnx2x_int_disable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200715{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700716 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200717 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
718 u32 val = REG_RD(bp, addr);
719
720 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
721 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
722 HC_CONFIG_0_REG_INT_LINE_EN_0 |
723 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
724
725 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
726 val, port, addr);
727
Eilon Greenstein8badd272009-02-12 08:36:15 +0000728 /* flush all outstanding writes */
729 mmiowb();
730
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200731 REG_WR(bp, addr, val);
732 if (REG_RD(bp, addr) != val)
733 BNX2X_ERR("BUG! proper val not read from IGU!\n");
734}
735
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700736static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200737{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200738 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000739 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200740
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700741 /* disable interrupt handling */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200742 atomic_inc(&bp->intr_sem);
Eilon Greensteine1510702009-07-21 05:47:41 +0000743 smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
744
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700745 if (disable_hw)
746 /* prevent the HW from sending interrupts */
747 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200748
749 /* make sure all ISRs are done */
750 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000751 synchronize_irq(bp->msix_table[0].vector);
752 offset = 1;
Michael Chan37b091b2009-10-10 13:46:55 +0000753#ifdef BCM_CNIC
754 offset++;
755#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200756 for_each_queue(bp, i)
Eilon Greenstein8badd272009-02-12 08:36:15 +0000757 synchronize_irq(bp->msix_table[i + offset].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200758 } else
759 synchronize_irq(bp->pdev->irq);
760
761 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800762 cancel_delayed_work(&bp->sp_task);
763 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200764}
765
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700766/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200767
768/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700769 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200770 */
771
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700772static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200773 u8 storm, u16 index, u8 op, u8 update)
774{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700775 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
776 COMMAND_REG_INT_ACK);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200777 struct igu_ack_register igu_ack;
778
779 igu_ack.status_block_index = index;
780 igu_ack.sb_id_and_flags =
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700781 ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200782 (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
783 (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
784 (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
785
Eilon Greenstein5c862842008-08-13 15:51:48 -0700786 DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
787 (*(u32 *)&igu_ack), hc_addr);
788 REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
Eilon Greenstein37dbbf32009-07-21 05:47:33 +0000789
790 /* Make sure that ACK is written */
791 mmiowb();
792 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200793}
794
795static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
796{
797 struct host_status_block *fpsb = fp->status_blk;
798 u16 rc = 0;
799
800 barrier(); /* status block is written to by the chip */
801 if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
802 fp->fp_c_idx = fpsb->c_status_block.status_block_index;
803 rc |= 1;
804 }
805 if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
806 fp->fp_u_idx = fpsb->u_status_block.status_block_index;
807 rc |= 2;
808 }
809 return rc;
810}
811
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200812static u16 bnx2x_ack_int(struct bnx2x *bp)
813{
Eilon Greenstein5c862842008-08-13 15:51:48 -0700814 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
815 COMMAND_REG_SIMD_MASK);
816 u32 result = REG_RD(bp, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200817
Eilon Greenstein5c862842008-08-13 15:51:48 -0700818 DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
819 result, hc_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200820
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200821 return result;
822}
823
824
825/*
826 * fast path service functions
827 */
828
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -0800829static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
830{
831 /* Tell compiler that consumer and producer can change */
832 barrier();
833 return (fp->tx_pkt_prod != fp->tx_pkt_cons);
Eilon Greenstein237907c2009-01-14 06:42:44 +0000834}
835
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200836/* free skb in the packet ring at pos idx
837 * return idx of last bd freed
838 */
839static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
840 u16 idx)
841{
842 struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
Eilon Greensteinca003922009-08-12 22:53:28 -0700843 struct eth_tx_start_bd *tx_start_bd;
844 struct eth_tx_bd *tx_data_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200845 struct sk_buff *skb = tx_buf->skb;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700846 u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200847 int nbd;
848
849 DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
850 idx, tx_buf, skb);
851
852 /* unmap first bd */
853 DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
Eilon Greensteinca003922009-08-12 22:53:28 -0700854 tx_start_bd = &fp->tx_desc_ring[bd_idx].start_bd;
855 pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_start_bd),
856 BD_UNMAP_LEN(tx_start_bd), PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200857
Eilon Greensteinca003922009-08-12 22:53:28 -0700858 nbd = le16_to_cpu(tx_start_bd->nbd) - 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200859#ifdef BNX2X_STOP_ON_ERROR
Eilon Greensteinca003922009-08-12 22:53:28 -0700860 if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700861 BNX2X_ERR("BAD nbd!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200862 bnx2x_panic();
863 }
864#endif
Eilon Greensteinca003922009-08-12 22:53:28 -0700865 new_cons = nbd + tx_buf->first_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200866
Eilon Greensteinca003922009-08-12 22:53:28 -0700867 /* Get the next bd */
868 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
869
870 /* Skip a parse bd... */
871 --nbd;
872 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
873
874 /* ...and the TSO split header bd since they have no mapping */
875 if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) {
876 --nbd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200877 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200878 }
879
880 /* now free frags */
881 while (nbd > 0) {
882
883 DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
Eilon Greensteinca003922009-08-12 22:53:28 -0700884 tx_data_bd = &fp->tx_desc_ring[bd_idx].reg_bd;
885 pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_data_bd),
886 BD_UNMAP_LEN(tx_data_bd), PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200887 if (--nbd)
888 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
889 }
890
891 /* release skb */
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700892 WARN_ON(!skb);
Eilon Greensteinca003922009-08-12 22:53:28 -0700893 dev_kfree_skb_any(skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200894 tx_buf->first_bd = 0;
895 tx_buf->skb = NULL;
896
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700897 return new_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200898}
899
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700900static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200901{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700902 s16 used;
903 u16 prod;
904 u16 cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200905
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700906 barrier(); /* Tell compiler that prod and cons can change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200907 prod = fp->tx_bd_prod;
908 cons = fp->tx_bd_cons;
909
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700910 /* NUM_TX_RINGS = number of "next-page" entries
911 It will be used as a threshold */
912 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200913
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700914#ifdef BNX2X_STOP_ON_ERROR
Ilpo Järvinen53e5e962008-07-25 21:40:45 -0700915 WARN_ON(used < 0);
916 WARN_ON(used > fp->bp->tx_ring_size);
917 WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700918#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200919
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700920 return (s16)(fp->bp->tx_ring_size) - used;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200921}
922
Eilon Greenstein7961f792009-03-02 07:59:31 +0000923static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200924{
925 struct bnx2x *bp = fp->bp;
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000926 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200927 u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
928 int done = 0;
929
930#ifdef BNX2X_STOP_ON_ERROR
931 if (unlikely(bp->panic))
932 return;
933#endif
934
Eilon Greensteinca003922009-08-12 22:53:28 -0700935 txq = netdev_get_tx_queue(bp->dev, fp->index - bp->num_rx_queues);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200936 hw_cons = le16_to_cpu(*fp->tx_cons_sb);
937 sw_cons = fp->tx_pkt_cons;
938
939 while (sw_cons != hw_cons) {
940 u16 pkt_cons;
941
942 pkt_cons = TX_BD(sw_cons);
943
944 /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
945
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700946 DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200947 hw_cons, sw_cons, pkt_cons);
948
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700949/* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200950 rmb();
951 prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
952 }
953*/
954 bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
955 sw_cons++;
956 done++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200957 }
958
959 fp->tx_pkt_cons = sw_cons;
960 fp->tx_bd_cons = bd_cons;
961
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200962 /* TBD need a thresh? */
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000963 if (unlikely(netif_tx_queue_stopped(txq))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200964
Eilon Greenstein60447352009-03-02 07:59:24 +0000965 /* Need to make the tx_bd_cons update visible to start_xmit()
966 * before checking for netif_tx_queue_stopped(). Without the
967 * memory barrier, there is a small possibility that
968 * start_xmit() will miss it and cause the queue to be stopped
969 * forever.
970 */
971 smp_mb();
972
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000973 if ((netif_tx_queue_stopped(txq)) &&
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -0700974 (bp->state == BNX2X_STATE_OPEN) &&
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200975 (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000976 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200977 }
978}
979
Michael Chan993ac7b2009-10-10 13:46:56 +0000980#ifdef BCM_CNIC
981static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid);
982#endif
Eilon Greenstein3196a882008-08-13 15:58:49 -0700983
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200984static void bnx2x_sp_event(struct bnx2x_fastpath *fp,
985 union eth_rx_cqe *rr_cqe)
986{
987 struct bnx2x *bp = fp->bp;
988 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
989 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
990
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700991 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200992 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +0000993 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700994 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200995
996 bp->spq_left++;
997
Eilon Greenstein0626b892009-02-12 08:38:14 +0000998 if (fp->index) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200999 switch (command | fp->state) {
1000 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
1001 BNX2X_FP_STATE_OPENING):
1002 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
1003 cid);
1004 fp->state = BNX2X_FP_STATE_OPEN;
1005 break;
1006
1007 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
1008 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
1009 cid);
1010 fp->state = BNX2X_FP_STATE_HALTED;
1011 break;
1012
1013 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001014 BNX2X_ERR("unexpected MC reply (%d) "
1015 "fp->state is %x\n", command, fp->state);
1016 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001017 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001018 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001019 return;
1020 }
Eliezer Tamirc14423f2008-02-28 11:49:42 -08001021
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001022 switch (command | bp->state) {
1023 case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
1024 DP(NETIF_MSG_IFUP, "got setup ramrod\n");
1025 bp->state = BNX2X_STATE_OPEN;
1026 break;
1027
1028 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
1029 DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
1030 bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
1031 fp->state = BNX2X_FP_STATE_HALTED;
1032 break;
1033
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001034 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001035 DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
Eliezer Tamir49d66772008-02-28 11:53:13 -08001036 bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001037 break;
1038
Michael Chan993ac7b2009-10-10 13:46:56 +00001039#ifdef BCM_CNIC
1040 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_OPEN):
1041 DP(NETIF_MSG_IFDOWN, "got delete ramrod for CID %d\n", cid);
1042 bnx2x_cnic_cfc_comp(bp, cid);
1043 break;
1044#endif
Eilon Greenstein3196a882008-08-13 15:58:49 -07001045
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001046 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001047 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001048 DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
Michael Chane665bfd2009-10-10 13:46:54 +00001049 bp->set_mac_pending--;
1050 smp_wmb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001051 break;
1052
Eliezer Tamir49d66772008-02-28 11:53:13 -08001053 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001054 DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
Michael Chane665bfd2009-10-10 13:46:54 +00001055 bp->set_mac_pending--;
1056 smp_wmb();
Eliezer Tamir49d66772008-02-28 11:53:13 -08001057 break;
1058
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001059 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001060 BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001061 command, bp->state);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001062 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001063 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001064 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001065}
1066
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001067static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
1068 struct bnx2x_fastpath *fp, u16 index)
1069{
1070 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1071 struct page *page = sw_buf->page;
1072 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1073
1074 /* Skip "next page" elements */
1075 if (!page)
1076 return;
1077
1078 pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001079 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001080 __free_pages(page, PAGES_PER_SGE_SHIFT);
1081
1082 sw_buf->page = NULL;
1083 sge->addr_hi = 0;
1084 sge->addr_lo = 0;
1085}
1086
1087static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
1088 struct bnx2x_fastpath *fp, int last)
1089{
1090 int i;
1091
1092 for (i = 0; i < last; i++)
1093 bnx2x_free_rx_sge(bp, fp, i);
1094}
1095
1096static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
1097 struct bnx2x_fastpath *fp, u16 index)
1098{
1099 struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
1100 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
1101 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
1102 dma_addr_t mapping;
1103
1104 if (unlikely(page == NULL))
1105 return -ENOMEM;
1106
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001107 mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001108 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001109 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001110 __free_pages(page, PAGES_PER_SGE_SHIFT);
1111 return -ENOMEM;
1112 }
1113
1114 sw_buf->page = page;
1115 pci_unmap_addr_set(sw_buf, mapping, mapping);
1116
1117 sge->addr_hi = cpu_to_le32(U64_HI(mapping));
1118 sge->addr_lo = cpu_to_le32(U64_LO(mapping));
1119
1120 return 0;
1121}
1122
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001123static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
1124 struct bnx2x_fastpath *fp, u16 index)
1125{
1126 struct sk_buff *skb;
1127 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
1128 struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
1129 dma_addr_t mapping;
1130
1131 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1132 if (unlikely(skb == NULL))
1133 return -ENOMEM;
1134
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001135 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001136 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001137 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001138 dev_kfree_skb(skb);
1139 return -ENOMEM;
1140 }
1141
1142 rx_buf->skb = skb;
1143 pci_unmap_addr_set(rx_buf, mapping, mapping);
1144
1145 rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1146 rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1147
1148 return 0;
1149}
1150
1151/* note that we are not allocating a new skb,
1152 * we are just moving one from cons to prod
1153 * we are not creating a new mapping,
1154 * so there is no need to check for dma_mapping_error().
1155 */
1156static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
1157 struct sk_buff *skb, u16 cons, u16 prod)
1158{
1159 struct bnx2x *bp = fp->bp;
1160 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1161 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1162 struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
1163 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1164
1165 pci_dma_sync_single_for_device(bp->pdev,
1166 pci_unmap_addr(cons_rx_buf, mapping),
Eilon Greenstein87942b42009-02-12 08:36:49 +00001167 RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001168
1169 prod_rx_buf->skb = cons_rx_buf->skb;
1170 pci_unmap_addr_set(prod_rx_buf, mapping,
1171 pci_unmap_addr(cons_rx_buf, mapping));
1172 *prod_bd = *cons_bd;
1173}
1174
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001175static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
1176 u16 idx)
1177{
1178 u16 last_max = fp->last_max_sge;
1179
1180 if (SUB_S16(idx, last_max) > 0)
1181 fp->last_max_sge = idx;
1182}
1183
1184static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
1185{
1186 int i, j;
1187
1188 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
1189 int idx = RX_SGE_CNT * i - 1;
1190
1191 for (j = 0; j < 2; j++) {
1192 SGE_MASK_CLEAR_BIT(fp, idx);
1193 idx--;
1194 }
1195 }
1196}
1197
1198static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
1199 struct eth_fast_path_rx_cqe *fp_cqe)
1200{
1201 struct bnx2x *bp = fp->bp;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001202 u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001203 le16_to_cpu(fp_cqe->len_on_bd)) >>
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001204 SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001205 u16 last_max, last_elem, first_elem;
1206 u16 delta = 0;
1207 u16 i;
1208
1209 if (!sge_len)
1210 return;
1211
1212 /* First mark all used pages */
1213 for (i = 0; i < sge_len; i++)
1214 SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i])));
1215
1216 DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
1217 sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1218
1219 /* Here we assume that the last SGE index is the biggest */
1220 prefetch((void *)(fp->sge_mask));
1221 bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
1222
1223 last_max = RX_SGE(fp->last_max_sge);
1224 last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
1225 first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
1226
1227 /* If ring is not full */
1228 if (last_elem + 1 != first_elem)
1229 last_elem++;
1230
1231 /* Now update the prod */
1232 for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
1233 if (likely(fp->sge_mask[i]))
1234 break;
1235
1236 fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
1237 delta += RX_SGE_MASK_ELEM_SZ;
1238 }
1239
1240 if (delta > 0) {
1241 fp->rx_sge_prod += delta;
1242 /* clear page-end entries */
1243 bnx2x_clear_sge_mask_next_elems(fp);
1244 }
1245
1246 DP(NETIF_MSG_RX_STATUS,
1247 "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
1248 fp->last_max_sge, fp->rx_sge_prod);
1249}
1250
1251static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
1252{
1253 /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
1254 memset(fp->sge_mask, 0xff,
1255 (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
1256
Eilon Greenstein33471622008-08-13 15:59:08 -07001257 /* Clear the two last indices in the page to 1:
1258 these are the indices that correspond to the "next" element,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001259 hence will never be indicated and should be removed from
1260 the calculations. */
1261 bnx2x_clear_sge_mask_next_elems(fp);
1262}
1263
1264static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
1265 struct sk_buff *skb, u16 cons, u16 prod)
1266{
1267 struct bnx2x *bp = fp->bp;
1268 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
1269 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
1270 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
1271 dma_addr_t mapping;
1272
1273 /* move empty skb from pool to prod and map it */
1274 prod_rx_buf->skb = fp->tpa_pool[queue].skb;
1275 mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001276 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001277 pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
1278
1279 /* move partial skb from cons to pool (don't unmap yet) */
1280 fp->tpa_pool[queue] = *cons_rx_buf;
1281
1282 /* mark bin state as start - print error if current state != stop */
1283 if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
1284 BNX2X_ERR("start of bin not in stop [%d]\n", queue);
1285
1286 fp->tpa_state[queue] = BNX2X_TPA_START;
1287
1288 /* point prod_bd to new skb */
1289 prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1290 prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1291
1292#ifdef BNX2X_STOP_ON_ERROR
1293 fp->tpa_queue_used |= (1 << queue);
1294#ifdef __powerpc64__
1295 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
1296#else
1297 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
1298#endif
1299 fp->tpa_queue_used);
1300#endif
1301}
1302
1303static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1304 struct sk_buff *skb,
1305 struct eth_fast_path_rx_cqe *fp_cqe,
1306 u16 cqe_idx)
1307{
1308 struct sw_rx_page *rx_pg, old_rx_pg;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001309 u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
1310 u32 i, frag_len, frag_size, pages;
1311 int err;
1312 int j;
1313
1314 frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001315 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001316
1317 /* This is needed in order to enable forwarding support */
1318 if (frag_size)
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001319 skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001320 max(frag_size, (u32)len_on_bd));
1321
1322#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001323 if (pages >
1324 min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001325 BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
1326 pages, cqe_idx);
1327 BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
1328 fp_cqe->pkt_len, len_on_bd);
1329 bnx2x_panic();
1330 return -EINVAL;
1331 }
1332#endif
1333
1334 /* Run through the SGL and compose the fragmented skb */
1335 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
1336 u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j]));
1337
1338 /* FW gives the indices of the SGE as if the ring is an array
1339 (meaning that "next" element will consume 2 indices) */
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001340 frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001341 rx_pg = &fp->rx_page_ring[sge_idx];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001342 old_rx_pg = *rx_pg;
1343
1344 /* If we fail to allocate a substitute page, we simply stop
1345 where we are and drop the whole packet */
1346 err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
1347 if (unlikely(err)) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00001348 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001349 return err;
1350 }
1351
1352 /* Unmap the page as we r going to pass it to the stack */
1353 pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping),
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08001354 SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001355
1356 /* Add one frag and update the appropriate fields in the skb */
1357 skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
1358
1359 skb->data_len += frag_len;
1360 skb->truesize += frag_len;
1361 skb->len += frag_len;
1362
1363 frag_size -= frag_len;
1364 }
1365
1366 return 0;
1367}
1368
1369static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1370 u16 queue, int pad, int len, union eth_rx_cqe *cqe,
1371 u16 cqe_idx)
1372{
1373 struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
1374 struct sk_buff *skb = rx_buf->skb;
1375 /* alloc new skb */
1376 struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1377
1378 /* Unmap skb in the pool anyway, as we are going to change
1379 pool entry status to BNX2X_TPA_STOP even if new skb allocation
1380 fails. */
1381 pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001382 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001383
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001384 if (likely(new_skb)) {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001385 /* fix ip xsum and give it to the stack */
1386 /* (no need to map the new skb) */
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001387#ifdef BCM_VLAN
1388 int is_vlan_cqe =
1389 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1390 PARSING_FLAGS_VLAN);
1391 int is_not_hwaccel_vlan_cqe =
1392 (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG)));
1393#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001394
1395 prefetch(skb);
1396 prefetch(((char *)(skb)) + 128);
1397
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001398#ifdef BNX2X_STOP_ON_ERROR
1399 if (pad + len > bp->rx_buf_size) {
1400 BNX2X_ERR("skb_put is about to fail... "
1401 "pad %d len %d rx_buf_size %d\n",
1402 pad, len, bp->rx_buf_size);
1403 bnx2x_panic();
1404 return;
1405 }
1406#endif
1407
1408 skb_reserve(skb, pad);
1409 skb_put(skb, len);
1410
1411 skb->protocol = eth_type_trans(skb, bp->dev);
1412 skb->ip_summed = CHECKSUM_UNNECESSARY;
1413
1414 {
1415 struct iphdr *iph;
1416
1417 iph = (struct iphdr *)skb->data;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001418#ifdef BCM_VLAN
1419 /* If there is no Rx VLAN offloading -
1420 take VLAN tag into an account */
1421 if (unlikely(is_not_hwaccel_vlan_cqe))
1422 iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN);
1423#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001424 iph->check = 0;
1425 iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
1426 }
1427
1428 if (!bnx2x_fill_frag_skb(bp, fp, skb,
1429 &cqe->fast_path_cqe, cqe_idx)) {
1430#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001431 if ((bp->vlgrp != NULL) && is_vlan_cqe &&
1432 (!is_not_hwaccel_vlan_cqe))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001433 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1434 le16_to_cpu(cqe->fast_path_cqe.
1435 vlan_tag));
1436 else
1437#endif
1438 netif_receive_skb(skb);
1439 } else {
1440 DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
1441 " - dropping packet!\n");
1442 dev_kfree_skb(skb);
1443 }
1444
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001445
1446 /* put new skb in bin */
1447 fp->tpa_pool[queue].skb = new_skb;
1448
1449 } else {
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001450 /* else drop the packet and keep the buffer in the bin */
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001451 DP(NETIF_MSG_RX_STATUS,
1452 "Failed to allocate new skb - dropping packet!\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001453 fp->eth_q_stats.rx_skb_alloc_failed++;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001454 }
1455
1456 fp->tpa_state[queue] = BNX2X_TPA_STOP;
1457}
1458
1459static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
1460 struct bnx2x_fastpath *fp,
1461 u16 bd_prod, u16 rx_comp_prod,
1462 u16 rx_sge_prod)
1463{
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001464 struct ustorm_eth_rx_producers rx_prods = {0};
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001465 int i;
1466
1467 /* Update producers */
1468 rx_prods.bd_prod = bd_prod;
1469 rx_prods.cqe_prod = rx_comp_prod;
1470 rx_prods.sge_prod = rx_sge_prod;
1471
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001472 /*
1473 * Make sure that the BD and SGE data is updated before updating the
1474 * producers since FW might read the BD/SGE right after the producer
1475 * is updated.
1476 * This is only applicable for weak-ordered memory model archs such
1477 * as IA-64. The following barrier is also mandatory since FW will
1478 * assumes BDs must have buffers.
1479 */
1480 wmb();
1481
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08001482 for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
1483 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00001484 USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001485 ((u32 *)&rx_prods)[i]);
1486
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -08001487 mmiowb(); /* keep prod updates ordered */
1488
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001489 DP(NETIF_MSG_RX_STATUS,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001490 "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
1491 fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001492}
1493
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001494static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
1495{
1496 struct bnx2x *bp = fp->bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001497 u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001498 u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
1499 int rx_pkt = 0;
1500
1501#ifdef BNX2X_STOP_ON_ERROR
1502 if (unlikely(bp->panic))
1503 return 0;
1504#endif
1505
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001506 /* CQ "next element" is of the size of the regular element,
1507 that's why it's ok here */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001508 hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
1509 if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
1510 hw_comp_cons++;
1511
1512 bd_cons = fp->rx_bd_cons;
1513 bd_prod = fp->rx_bd_prod;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001514 bd_prod_fw = bd_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001515 sw_comp_cons = fp->rx_comp_cons;
1516 sw_comp_prod = fp->rx_comp_prod;
1517
1518 /* Memory barrier necessary as speculative reads of the rx
1519 * buffer can be ahead of the index in the status block
1520 */
1521 rmb();
1522
1523 DP(NETIF_MSG_RX_STATUS,
1524 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001525 fp->index, hw_comp_cons, sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001526
1527 while (sw_comp_cons != hw_comp_cons) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001528 struct sw_rx_bd *rx_buf = NULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001529 struct sk_buff *skb;
1530 union eth_rx_cqe *cqe;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001531 u8 cqe_fp_flags;
1532 u16 len, pad;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001533
1534 comp_ring_cons = RCQ_BD(sw_comp_cons);
1535 bd_prod = RX_BD(bd_prod);
1536 bd_cons = RX_BD(bd_cons);
1537
Eilon Greenstein619e7a62009-08-12 08:23:20 +00001538 /* Prefetch the page containing the BD descriptor
1539 at producer's index. It will be needed when new skb is
1540 allocated */
1541 prefetch((void *)(PAGE_ALIGN((unsigned long)
1542 (&fp->rx_desc_ring[bd_prod])) -
1543 PAGE_SIZE + 1));
1544
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001545 cqe = &fp->rx_comp_ring[comp_ring_cons];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001546 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001547
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001548 DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001549 " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
1550 cqe_fp_flags, cqe->fast_path_cqe.status_flags,
Eilon Greenstein68d59482009-01-14 21:27:36 -08001551 le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001552 le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
1553 le16_to_cpu(cqe->fast_path_cqe.pkt_len));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001554
1555 /* is this a slowpath msg? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001556 if (unlikely(CQE_TYPE(cqe_fp_flags))) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001557 bnx2x_sp_event(fp, cqe);
1558 goto next_cqe;
1559
1560 /* this is an rx packet */
1561 } else {
1562 rx_buf = &fp->rx_buf_ring[bd_cons];
1563 skb = rx_buf->skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001564 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
1565 pad = cqe->fast_path_cqe.placement_offset;
1566
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001567 /* If CQE is marked both TPA_START and TPA_END
1568 it is a non-TPA CQE */
1569 if ((!fp->disable_tpa) &&
1570 (TPA_TYPE(cqe_fp_flags) !=
1571 (TPA_TYPE_START | TPA_TYPE_END))) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07001572 u16 queue = cqe->fast_path_cqe.queue_index;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001573
1574 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
1575 DP(NETIF_MSG_RX_STATUS,
1576 "calling tpa_start on queue %d\n",
1577 queue);
1578
1579 bnx2x_tpa_start(fp, queue, skb,
1580 bd_cons, bd_prod);
1581 goto next_rx;
1582 }
1583
1584 if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) {
1585 DP(NETIF_MSG_RX_STATUS,
1586 "calling tpa_stop on queue %d\n",
1587 queue);
1588
1589 if (!BNX2X_RX_SUM_FIX(cqe))
1590 BNX2X_ERR("STOP on none TCP "
1591 "data\n");
1592
1593 /* This is a size of the linear data
1594 on this skb */
1595 len = le16_to_cpu(cqe->fast_path_cqe.
1596 len_on_bd);
1597 bnx2x_tpa_stop(bp, fp, queue, pad,
1598 len, cqe, comp_ring_cons);
1599#ifdef BNX2X_STOP_ON_ERROR
1600 if (bp->panic)
Stanislaw Gruszka17cb40062009-05-05 23:22:12 +00001601 return 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001602#endif
1603
1604 bnx2x_update_sge_prod(fp,
1605 &cqe->fast_path_cqe);
1606 goto next_cqe;
1607 }
1608 }
1609
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001610 pci_dma_sync_single_for_device(bp->pdev,
1611 pci_unmap_addr(rx_buf, mapping),
1612 pad + RX_COPY_THRESH,
1613 PCI_DMA_FROMDEVICE);
1614 prefetch(skb);
1615 prefetch(((char *)(skb)) + 128);
1616
1617 /* is this an error packet? */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001618 if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001619 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001620 "ERROR flags %x rx packet %u\n",
1621 cqe_fp_flags, sw_comp_cons);
Eilon Greensteinde832a52009-02-12 08:36:33 +00001622 fp->eth_q_stats.rx_err_discard_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001623 goto reuse_rx;
1624 }
1625
1626 /* Since we don't have a jumbo ring
1627 * copy small packets if mtu > 1500
1628 */
1629 if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
1630 (len <= RX_COPY_THRESH)) {
1631 struct sk_buff *new_skb;
1632
1633 new_skb = netdev_alloc_skb(bp->dev,
1634 len + pad);
1635 if (new_skb == NULL) {
1636 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001637 "ERROR packet dropped "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001638 "because of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001639 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001640 goto reuse_rx;
1641 }
1642
1643 /* aligned copy */
1644 skb_copy_from_linear_data_offset(skb, pad,
1645 new_skb->data + pad, len);
1646 skb_reserve(new_skb, pad);
1647 skb_put(new_skb, len);
1648
1649 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1650
1651 skb = new_skb;
1652
Eilon Greensteina119a062009-08-12 08:23:23 +00001653 } else
1654 if (likely(bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001655 pci_unmap_single(bp->pdev,
1656 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07001657 bp->rx_buf_size,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001658 PCI_DMA_FROMDEVICE);
1659 skb_reserve(skb, pad);
1660 skb_put(skb, len);
1661
1662 } else {
1663 DP(NETIF_MSG_RX_ERR,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001664 "ERROR packet dropped because "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001665 "of alloc failure\n");
Eilon Greensteinde832a52009-02-12 08:36:33 +00001666 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001667reuse_rx:
1668 bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
1669 goto next_rx;
1670 }
1671
1672 skb->protocol = eth_type_trans(skb, bp->dev);
1673
1674 skb->ip_summed = CHECKSUM_NONE;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001675 if (bp->rx_csum) {
Eilon Greenstein1adcd8b2008-08-13 15:48:29 -07001676 if (likely(BNX2X_RX_CSUM_OK(cqe)))
1677 skb->ip_summed = CHECKSUM_UNNECESSARY;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001678 else
Eilon Greensteinde832a52009-02-12 08:36:33 +00001679 fp->eth_q_stats.hw_csum_err++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07001680 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001681 }
1682
Eilon Greenstein748e5432009-02-12 08:36:37 +00001683 skb_record_rx_queue(skb, fp->index);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001684
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001685#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08001686 if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001687 (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
1688 PARSING_FLAGS_VLAN))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001689 vlan_hwaccel_receive_skb(skb, bp->vlgrp,
1690 le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
1691 else
1692#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001693 netif_receive_skb(skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001694
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001695
1696next_rx:
1697 rx_buf->skb = NULL;
1698
1699 bd_cons = NEXT_RX_IDX(bd_cons);
1700 bd_prod = NEXT_RX_IDX(bd_prod);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001701 bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
1702 rx_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001703next_cqe:
1704 sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
1705 sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001706
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001707 if (rx_pkt == budget)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001708 break;
1709 } /* while */
1710
1711 fp->rx_bd_cons = bd_cons;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001712 fp->rx_bd_prod = bd_prod_fw;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001713 fp->rx_comp_cons = sw_comp_cons;
1714 fp->rx_comp_prod = sw_comp_prod;
1715
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001716 /* Update producers */
1717 bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
1718 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001719
1720 fp->rx_pkt += rx_pkt;
1721 fp->rx_calls++;
1722
1723 return rx_pkt;
1724}
1725
1726static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
1727{
1728 struct bnx2x_fastpath *fp = fp_cookie;
1729 struct bnx2x *bp = fp->bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001730
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07001731 /* Return here if interrupt is disabled */
1732 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1733 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1734 return IRQ_HANDLED;
1735 }
1736
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001737 DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n",
Eilon Greensteinca003922009-08-12 22:53:28 -07001738 fp->index, fp->sb_id);
Eilon Greenstein0626b892009-02-12 08:38:14 +00001739 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001740
1741#ifdef BNX2X_STOP_ON_ERROR
1742 if (unlikely(bp->panic))
1743 return IRQ_HANDLED;
1744#endif
Eilon Greensteinca003922009-08-12 22:53:28 -07001745 /* Handle Rx or Tx according to MSI-X vector */
1746 if (fp->is_rx_queue) {
1747 prefetch(fp->rx_cons_sb);
1748 prefetch(&fp->status_blk->u_status_block.status_block_index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001749
Eilon Greensteinca003922009-08-12 22:53:28 -07001750 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001751
Eilon Greensteinca003922009-08-12 22:53:28 -07001752 } else {
1753 prefetch(fp->tx_cons_sb);
1754 prefetch(&fp->status_blk->c_status_block.status_block_index);
1755
1756 bnx2x_update_fpsb_idx(fp);
1757 rmb();
1758 bnx2x_tx_int(fp);
1759
1760 /* Re-enable interrupts */
1761 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
1762 le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
1763 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
1764 le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
1765 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001766
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001767 return IRQ_HANDLED;
1768}
1769
1770static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1771{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001772 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001773 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001774 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -07001775 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001776
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001777 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001778 if (unlikely(status == 0)) {
1779 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1780 return IRQ_NONE;
1781 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001782 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001783
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001784 /* Return here if interrupt is disabled */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001785 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
1786 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
1787 return IRQ_HANDLED;
1788 }
1789
Eilon Greenstein3196a882008-08-13 15:58:49 -07001790#ifdef BNX2X_STOP_ON_ERROR
1791 if (unlikely(bp->panic))
1792 return IRQ_HANDLED;
1793#endif
1794
Eilon Greensteinca003922009-08-12 22:53:28 -07001795 for (i = 0; i < BNX2X_NUM_QUEUES(bp); i++) {
1796 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001797
Eilon Greensteinca003922009-08-12 22:53:28 -07001798 mask = 0x2 << fp->sb_id;
1799 if (status & mask) {
1800 /* Handle Rx or Tx according to SB id */
1801 if (fp->is_rx_queue) {
1802 prefetch(fp->rx_cons_sb);
1803 prefetch(&fp->status_blk->u_status_block.
1804 status_block_index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001805
Eilon Greensteinca003922009-08-12 22:53:28 -07001806 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001807
Eilon Greensteinca003922009-08-12 22:53:28 -07001808 } else {
1809 prefetch(fp->tx_cons_sb);
1810 prefetch(&fp->status_blk->c_status_block.
1811 status_block_index);
1812
1813 bnx2x_update_fpsb_idx(fp);
1814 rmb();
1815 bnx2x_tx_int(fp);
1816
1817 /* Re-enable interrupts */
1818 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
1819 le16_to_cpu(fp->fp_u_idx),
1820 IGU_INT_NOP, 1);
1821 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
1822 le16_to_cpu(fp->fp_c_idx),
1823 IGU_INT_ENABLE, 1);
1824 }
1825 status &= ~mask;
1826 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001827 }
1828
Michael Chan993ac7b2009-10-10 13:46:56 +00001829#ifdef BCM_CNIC
1830 mask = 0x2 << CNIC_SB_ID(bp);
1831 if (status & (mask | 0x1)) {
1832 struct cnic_ops *c_ops = NULL;
1833
1834 rcu_read_lock();
1835 c_ops = rcu_dereference(bp->cnic_ops);
1836 if (c_ops)
1837 c_ops->cnic_handler(bp->cnic_data, NULL);
1838 rcu_read_unlock();
1839
1840 status &= ~mask;
1841 }
1842#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001843
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001844 if (unlikely(status & 0x1)) {
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001845 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001846
1847 status &= ~0x1;
1848 if (!status)
1849 return IRQ_HANDLED;
1850 }
1851
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001852 if (status)
1853 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n",
1854 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001855
1856 return IRQ_HANDLED;
1857}
1858
1859/* end of fast path */
1860
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001861static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001862
1863/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001864
1865/*
1866 * General service functions
1867 */
1868
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001869static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001870{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001871 u32 lock_status;
1872 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001873 int func = BP_FUNC(bp);
1874 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001875 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001876
1877 /* Validating that the resource is within range */
1878 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1879 DP(NETIF_MSG_HW,
1880 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1881 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1882 return -EINVAL;
1883 }
1884
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001885 if (func <= 5) {
1886 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1887 } else {
1888 hw_lock_control_reg =
1889 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1890 }
1891
Eliezer Tamirf1410642008-02-28 11:51:50 -08001892 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001893 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001894 if (lock_status & resource_bit) {
1895 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1896 lock_status, resource_bit);
1897 return -EEXIST;
1898 }
1899
Eilon Greenstein46230476b2008-08-25 15:23:30 -07001900 /* Try for 5 second every 5ms */
1901 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001902 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001903 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1904 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001905 if (lock_status & resource_bit)
1906 return 0;
1907
1908 msleep(5);
1909 }
1910 DP(NETIF_MSG_HW, "Timeout\n");
1911 return -EAGAIN;
1912}
1913
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001914static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001915{
1916 u32 lock_status;
1917 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001918 int func = BP_FUNC(bp);
1919 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001920
1921 /* Validating that the resource is within range */
1922 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1923 DP(NETIF_MSG_HW,
1924 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1925 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1926 return -EINVAL;
1927 }
1928
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001929 if (func <= 5) {
1930 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1931 } else {
1932 hw_lock_control_reg =
1933 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1934 }
1935
Eliezer Tamirf1410642008-02-28 11:51:50 -08001936 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001937 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001938 if (!(lock_status & resource_bit)) {
1939 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1940 lock_status, resource_bit);
1941 return -EFAULT;
1942 }
1943
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001944 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001945 return 0;
1946}
1947
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001948/* HW Lock for shared dual port PHYs */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001949static void bnx2x_acquire_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001950{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001951 mutex_lock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001952
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001953 if (bp->port.need_hw_lock)
1954 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001955}
1956
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001957static void bnx2x_release_phy_lock(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001958{
Eilon Greenstein46c6a672009-02-12 08:36:58 +00001959 if (bp->port.need_hw_lock)
1960 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001961
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001962 mutex_unlock(&bp->port.phy_mutex);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001963}
1964
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001965int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1966{
1967 /* The GPIO should be swapped if swap register is set and active */
1968 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1969 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1970 int gpio_shift = gpio_num +
1971 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1972 u32 gpio_mask = (1 << gpio_shift);
1973 u32 gpio_reg;
1974 int value;
1975
1976 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1977 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1978 return -EINVAL;
1979 }
1980
1981 /* read GPIO value */
1982 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1983
1984 /* get the requested pin value */
1985 if ((gpio_reg & gpio_mask) == gpio_mask)
1986 value = 1;
1987 else
1988 value = 0;
1989
1990 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1991
1992 return value;
1993}
1994
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001995int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001996{
1997 /* The GPIO should be swapped if swap register is set and active */
1998 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001999 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002000 int gpio_shift = gpio_num +
2001 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2002 u32 gpio_mask = (1 << gpio_shift);
2003 u32 gpio_reg;
2004
2005 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2006 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2007 return -EINVAL;
2008 }
2009
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002010 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002011 /* read GPIO and mask except the float bits */
2012 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
2013
2014 switch (mode) {
2015 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2016 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
2017 gpio_num, gpio_shift);
2018 /* clear FLOAT and set CLR */
2019 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2020 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2021 break;
2022
2023 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2024 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
2025 gpio_num, gpio_shift);
2026 /* clear FLOAT and set SET */
2027 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2028 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2029 break;
2030
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002031 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002032 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
2033 gpio_num, gpio_shift);
2034 /* set FLOAT */
2035 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2036 break;
2037
2038 default:
2039 break;
2040 }
2041
2042 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002043 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002044
2045 return 0;
2046}
2047
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002048int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2049{
2050 /* The GPIO should be swapped if swap register is set and active */
2051 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2052 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2053 int gpio_shift = gpio_num +
2054 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2055 u32 gpio_mask = (1 << gpio_shift);
2056 u32 gpio_reg;
2057
2058 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2059 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2060 return -EINVAL;
2061 }
2062
2063 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2064 /* read GPIO int */
2065 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2066
2067 switch (mode) {
2068 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2069 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
2070 "output low\n", gpio_num, gpio_shift);
2071 /* clear SET and set CLR */
2072 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2073 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2074 break;
2075
2076 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2077 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
2078 "output high\n", gpio_num, gpio_shift);
2079 /* clear CLR and set SET */
2080 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2081 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2082 break;
2083
2084 default:
2085 break;
2086 }
2087
2088 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2089 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2090
2091 return 0;
2092}
2093
Eliezer Tamirf1410642008-02-28 11:51:50 -08002094static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2095{
2096 u32 spio_mask = (1 << spio_num);
2097 u32 spio_reg;
2098
2099 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2100 (spio_num > MISC_REGISTERS_SPIO_7)) {
2101 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2102 return -EINVAL;
2103 }
2104
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002105 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002106 /* read SPIO and mask except the float bits */
2107 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2108
2109 switch (mode) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07002110 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002111 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2112 /* clear FLOAT and set CLR */
2113 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2114 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2115 break;
2116
Eilon Greenstein6378c022008-08-13 15:59:25 -07002117 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002118 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2119 /* clear FLOAT and set SET */
2120 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2121 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2122 break;
2123
2124 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2125 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2126 /* set FLOAT */
2127 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2128 break;
2129
2130 default:
2131 break;
2132 }
2133
2134 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002135 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002136
2137 return 0;
2138}
2139
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002140static void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002141{
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002142 switch (bp->link_vars.ieee_fc &
2143 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002144 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002145 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002146 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002147 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002148
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002149 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002150 bp->port.advertising |= (ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002151 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002152 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002153
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002154 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002155 bp->port.advertising |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002156 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002157
Eliezer Tamirf1410642008-02-28 11:51:50 -08002158 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002159 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002160 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002161 break;
2162 }
2163}
2164
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002165static void bnx2x_link_report(struct bnx2x *bp)
2166{
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002167 if (bp->flags & MF_FUNC_DIS) {
Eilon Greenstein2691d512009-08-12 08:22:08 +00002168 netif_carrier_off(bp->dev);
2169 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
2170 return;
2171 }
2172
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002173 if (bp->link_vars.link_up) {
Eilon Greenstein35c5f8f2009-10-15 00:19:05 -07002174 u16 line_speed;
2175
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002176 if (bp->state == BNX2X_STATE_OPEN)
2177 netif_carrier_on(bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002178 printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
2179
Eilon Greenstein35c5f8f2009-10-15 00:19:05 -07002180 line_speed = bp->link_vars.line_speed;
2181 if (IS_E1HMF(bp)) {
2182 u16 vn_max_rate;
2183
2184 vn_max_rate =
2185 ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
2186 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
2187 if (vn_max_rate < line_speed)
2188 line_speed = vn_max_rate;
2189 }
2190 printk("%d Mbps ", line_speed);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002191
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002192 if (bp->link_vars.duplex == DUPLEX_FULL)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002193 printk("full duplex");
2194 else
2195 printk("half duplex");
2196
David S. Millerc0700f92008-12-16 23:53:20 -08002197 if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) {
2198 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002199 printk(", receive ");
Eilon Greenstein356e2382009-02-12 08:38:32 +00002200 if (bp->link_vars.flow_ctrl &
2201 BNX2X_FLOW_CTRL_TX)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002202 printk("& transmit ");
2203 } else {
2204 printk(", transmit ");
2205 }
2206 printk("flow control ON");
2207 }
2208 printk("\n");
2209
2210 } else { /* link_down */
2211 netif_carrier_off(bp->dev);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002212 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002213 }
2214}
2215
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002216static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002217{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002218 if (!BP_NOMCP(bp)) {
2219 u8 rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002220
Eilon Greenstein19680c42008-08-13 15:47:33 -07002221 /* Initialize link parameters structure variables */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002222 /* It is recommended to turn off RX FC for jumbo frames
2223 for better performance */
Eilon Greenstein0c593272009-08-12 08:22:13 +00002224 if (bp->dev->mtu > 5000)
David S. Millerc0700f92008-12-16 23:53:20 -08002225 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002226 else
David S. Millerc0700f92008-12-16 23:53:20 -08002227 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002228
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002229 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002230
2231 if (load_mode == LOAD_DIAG)
2232 bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
2233
Eilon Greenstein19680c42008-08-13 15:47:33 -07002234 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002235
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002236 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002237
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002238 bnx2x_calc_fc_adv(bp);
2239
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002240 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2241 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002242 bnx2x_link_report(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002243 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002244
Eilon Greenstein19680c42008-08-13 15:47:33 -07002245 return rc;
2246 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002247 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002248 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002249}
2250
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002251static void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002252{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002253 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002254 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002255 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002256 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002257
Eilon Greenstein19680c42008-08-13 15:47:33 -07002258 bnx2x_calc_fc_adv(bp);
2259 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002260 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002261}
2262
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002263static void bnx2x__link_reset(struct bnx2x *bp)
2264{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002265 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002266 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002267 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002268 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002269 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002270 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002271}
2272
2273static u8 bnx2x_link_test(struct bnx2x *bp)
2274{
2275 u8 rc;
2276
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002277 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002278 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002279 bnx2x_release_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002280
2281 return rc;
2282}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002283
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002284static void bnx2x_init_port_minmax(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002285{
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002286 u32 r_param = bp->link_vars.line_speed / 8;
2287 u32 fair_periodic_timeout_usec;
2288 u32 t_fair;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002289
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002290 memset(&(bp->cmng.rs_vars), 0,
2291 sizeof(struct rate_shaping_vars_per_port));
2292 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002293
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002294 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2295 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002296
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002297 /* this is the threshold below which no timer arming will occur
2298 1.25 coefficient is for the threshold to be a little bigger
2299 than the real time, to compensate for timer in-accuracy */
2300 bp->cmng.rs_vars.rs_threshold =
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002301 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2302
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002303 /* resolution of fairness timer */
2304 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2305 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2306 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002307
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002308 /* this is the threshold below which we won't arm the timer anymore */
2309 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002310
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002311 /* we multiply by 1e3/8 to get bytes/msec.
2312 We don't want the credits to pass a credit
2313 of the t_fair*FAIR_MEM (algorithm resolution) */
2314 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2315 /* since each tick is 4 usec */
2316 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002317}
2318
Eilon Greenstein2691d512009-08-12 08:22:08 +00002319/* Calculates the sum of vn_min_rates.
2320 It's needed for further normalizing of the min_rates.
2321 Returns:
2322 sum of vn_min_rates.
2323 or
2324 0 - if all the min_rates are 0.
2325 In the later case fainess algorithm should be deactivated.
2326 If not all min_rates are zero then those that are zeroes will be set to 1.
2327 */
2328static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2329{
2330 int all_zero = 1;
2331 int port = BP_PORT(bp);
2332 int vn;
2333
2334 bp->vn_weight_sum = 0;
2335 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2336 int func = 2*vn + port;
2337 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
2338 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2339 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2340
2341 /* Skip hidden vns */
2342 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2343 continue;
2344
2345 /* If min rate is zero - set it to 1 */
2346 if (!vn_min_rate)
2347 vn_min_rate = DEF_MIN_RATE;
2348 else
2349 all_zero = 0;
2350
2351 bp->vn_weight_sum += vn_min_rate;
2352 }
2353
2354 /* ... only if all min rates are zeros - disable fairness */
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002355 if (all_zero) {
2356 bp->cmng.flags.cmng_enables &=
2357 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2358 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2359 " fairness will be disabled\n");
2360 } else
2361 bp->cmng.flags.cmng_enables |=
2362 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002363}
2364
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002365static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002366{
2367 struct rate_shaping_vars_per_vn m_rs_vn;
2368 struct fairness_vars_per_vn m_fair_vn;
2369 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
2370 u16 vn_min_rate, vn_max_rate;
2371 int i;
2372
2373 /* If function is hidden - set min and max to zeroes */
2374 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2375 vn_min_rate = 0;
2376 vn_max_rate = 0;
2377
2378 } else {
2379 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2380 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002381 /* If min rate is zero - set it to 1 */
2382 if (!vn_min_rate)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002383 vn_min_rate = DEF_MIN_RATE;
2384 vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
2385 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
2386 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002387 DP(NETIF_MSG_IFUP,
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002388 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002389 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002390
2391 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2392 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2393
2394 /* global vn counter - maximal Mbps for this vn */
2395 m_rs_vn.vn_counter.rate = vn_max_rate;
2396
2397 /* quota - number of bytes transmitted in this period */
2398 m_rs_vn.vn_counter.quota =
2399 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2400
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002401 if (bp->vn_weight_sum) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002402 /* credit for each period of the fairness algorithm:
2403 number of bytes in T_FAIR (the vn share the port rate).
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002404 vn_weight_sum should not be larger than 10000, thus
2405 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2406 than zero */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002407 m_fair_vn.vn_credit_delta =
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002408 max((u32)(vn_min_rate * (T_FAIR_COEF /
2409 (8 * bp->vn_weight_sum))),
2410 (u32)(bp->cmng.fair_vars.fair_threshold * 2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002411 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n",
2412 m_fair_vn.vn_credit_delta);
2413 }
2414
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002415 /* Store it to internal memory */
2416 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2417 REG_WR(bp, BAR_XSTRORM_INTMEM +
2418 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2419 ((u32 *)(&m_rs_vn))[i]);
2420
2421 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2422 REG_WR(bp, BAR_XSTRORM_INTMEM +
2423 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2424 ((u32 *)(&m_fair_vn))[i]);
2425}
2426
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002427
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002428/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002429static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002430{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002431 /* Make sure that we are synced with the current statistics */
2432 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2433
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002434 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002435
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002436 if (bp->link_vars.link_up) {
2437
Eilon Greenstein1c063282009-02-12 08:36:43 +00002438 /* dropless flow control */
Eilon Greensteina18f5122009-08-12 08:23:26 +00002439 if (CHIP_IS_E1H(bp) && bp->dropless_fc) {
Eilon Greenstein1c063282009-02-12 08:36:43 +00002440 int port = BP_PORT(bp);
2441 u32 pause_enabled = 0;
2442
2443 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2444 pause_enabled = 1;
2445
2446 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07002447 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
Eilon Greenstein1c063282009-02-12 08:36:43 +00002448 pause_enabled);
2449 }
2450
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002451 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
2452 struct host_port_stats *pstats;
2453
2454 pstats = bnx2x_sp(bp, port_stats);
2455 /* reset old bmac stats */
2456 memset(&(pstats->mac_stx[0]), 0,
2457 sizeof(struct mac_stx));
2458 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002459 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002460 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2461 }
2462
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002463 /* indicate link status */
2464 bnx2x_link_report(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002465
2466 if (IS_E1HMF(bp)) {
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002467 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002468 int func;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002469 int vn;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002470
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002471 /* Set the attention towards other drivers on the same port */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002472 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2473 if (vn == BP_E1HVN(bp))
2474 continue;
2475
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002476 func = ((vn << 1) | port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002477 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2478 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2479 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002480
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002481 if (bp->link_vars.link_up) {
2482 int i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002483
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002484 /* Init rate shaping and fairness contexts */
2485 bnx2x_init_port_minmax(bp);
2486
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002487 for (vn = VN_0; vn < E1HVN_MAX; vn++)
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002488 bnx2x_init_vn_minmax(bp, 2*vn + port);
2489
2490 /* Store it to internal memory */
2491 for (i = 0;
2492 i < sizeof(struct cmng_struct_per_port) / 4; i++)
2493 REG_WR(bp, BAR_XSTRORM_INTMEM +
2494 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
2495 ((u32 *)(&bp->cmng))[i]);
2496 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002497 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002498}
2499
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002500static void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002501{
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002502 if ((bp->state != BNX2X_STATE_OPEN) || (bp->flags & MF_FUNC_DIS))
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002503 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002504
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002505 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2506
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002507 if (bp->link_vars.link_up)
2508 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2509 else
2510 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2511
Eilon Greenstein2691d512009-08-12 08:22:08 +00002512 bnx2x_calc_vn_weight_sum(bp);
2513
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002514 /* indicate link status */
2515 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002516}
2517
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002518static void bnx2x_pmf_update(struct bnx2x *bp)
2519{
2520 int port = BP_PORT(bp);
2521 u32 val;
2522
2523 bp->port.pmf = 1;
2524 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2525
2526 /* enable nig attention */
2527 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2528 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2529 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002530
2531 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002532}
2533
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002534/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002535
2536/* slow path */
2537
2538/*
2539 * General service functions
2540 */
2541
Eilon Greenstein2691d512009-08-12 08:22:08 +00002542/* send the MCP a request, block until there is a reply */
2543u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
2544{
2545 int func = BP_FUNC(bp);
2546 u32 seq = ++bp->fw_seq;
2547 u32 rc = 0;
2548 u32 cnt = 1;
2549 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2550
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002551 mutex_lock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002552 SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
2553 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
2554
2555 do {
2556 /* let the FW do it's magic ... */
2557 msleep(delay);
2558
2559 rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
2560
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002561 /* Give the FW up to 5 second (500*10ms) */
2562 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002563
2564 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2565 cnt*delay, rc, seq);
2566
2567 /* is this a reply to our command? */
2568 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2569 rc &= FW_MSG_CODE_MASK;
2570 else {
2571 /* FW BUG! */
2572 BNX2X_ERR("FW failed to respond!\n");
2573 bnx2x_fw_dump(bp);
2574 rc = 0;
2575 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002576 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002577
2578 return rc;
2579}
2580
2581static void bnx2x_set_storm_rx_mode(struct bnx2x *bp);
Michael Chane665bfd2009-10-10 13:46:54 +00002582static void bnx2x_set_eth_mac_addr_e1h(struct bnx2x *bp, int set);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002583static void bnx2x_set_rx_mode(struct net_device *dev);
2584
2585static void bnx2x_e1h_disable(struct bnx2x *bp)
2586{
2587 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002588
2589 netif_tx_disable(bp->dev);
2590 bp->dev->trans_start = jiffies; /* prevent tx timeout */
2591
2592 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2593
Eilon Greenstein2691d512009-08-12 08:22:08 +00002594 netif_carrier_off(bp->dev);
2595}
2596
2597static void bnx2x_e1h_enable(struct bnx2x *bp)
2598{
2599 int port = BP_PORT(bp);
2600
2601 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2602
Eilon Greenstein2691d512009-08-12 08:22:08 +00002603 /* Tx queue should be only reenabled */
2604 netif_tx_wake_all_queues(bp->dev);
2605
Eilon Greenstein061bc702009-10-15 00:18:47 -07002606 /*
2607 * Should not call netif_carrier_on since it will be called if the link
2608 * is up when checking for link state
2609 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00002610}
2611
2612static void bnx2x_update_min_max(struct bnx2x *bp)
2613{
2614 int port = BP_PORT(bp);
2615 int vn, i;
2616
2617 /* Init rate shaping and fairness contexts */
2618 bnx2x_init_port_minmax(bp);
2619
2620 bnx2x_calc_vn_weight_sum(bp);
2621
2622 for (vn = VN_0; vn < E1HVN_MAX; vn++)
2623 bnx2x_init_vn_minmax(bp, 2*vn + port);
2624
2625 if (bp->port.pmf) {
2626 int func;
2627
2628 /* Set the attention towards other drivers on the same port */
2629 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2630 if (vn == BP_E1HVN(bp))
2631 continue;
2632
2633 func = ((vn << 1) | port);
2634 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2635 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2636 }
2637
2638 /* Store it to internal memory */
2639 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
2640 REG_WR(bp, BAR_XSTRORM_INTMEM +
2641 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
2642 ((u32 *)(&bp->cmng))[i]);
2643 }
2644}
2645
2646static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2647{
Eilon Greenstein2691d512009-08-12 08:22:08 +00002648 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002649
2650 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2651
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002652 /*
2653 * This is the only place besides the function initialization
2654 * where the bp->flags can change so it is done without any
2655 * locks
2656 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00002657 if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
2658 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002659 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002660
2661 bnx2x_e1h_disable(bp);
2662 } else {
2663 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002664 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002665
2666 bnx2x_e1h_enable(bp);
2667 }
2668 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2669 }
2670 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
2671
2672 bnx2x_update_min_max(bp);
2673 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2674 }
2675
2676 /* Report results to MCP */
2677 if (dcc_event)
2678 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE);
2679 else
2680 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK);
2681}
2682
Michael Chan289129022009-10-10 13:46:53 +00002683/* must be called under the spq lock */
2684static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2685{
2686 struct eth_spe *next_spe = bp->spq_prod_bd;
2687
2688 if (bp->spq_prod_bd == bp->spq_last_bd) {
2689 bp->spq_prod_bd = bp->spq;
2690 bp->spq_prod_idx = 0;
2691 DP(NETIF_MSG_TIMER, "end of spq\n");
2692 } else {
2693 bp->spq_prod_bd++;
2694 bp->spq_prod_idx++;
2695 }
2696 return next_spe;
2697}
2698
2699/* must be called under the spq lock */
2700static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2701{
2702 int func = BP_FUNC(bp);
2703
2704 /* Make sure that BD data is updated before writing the producer */
2705 wmb();
2706
2707 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
2708 bp->spq_prod_idx);
2709 mmiowb();
2710}
2711
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002712/* the slow path queue is odd since completions arrive on the fastpath ring */
2713static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
2714 u32 data_hi, u32 data_lo, int common)
2715{
Michael Chan289129022009-10-10 13:46:53 +00002716 struct eth_spe *spe;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002717
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002718 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
2719 "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002720 (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) +
2721 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
2722 HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
2723
2724#ifdef BNX2X_STOP_ON_ERROR
2725 if (unlikely(bp->panic))
2726 return -EIO;
2727#endif
2728
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002729 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002730
2731 if (!bp->spq_left) {
2732 BNX2X_ERR("BUG! SPQ ring full!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002733 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002734 bnx2x_panic();
2735 return -EBUSY;
2736 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08002737
Michael Chan289129022009-10-10 13:46:53 +00002738 spe = bnx2x_sp_get_next(bp);
2739
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002740 /* CID needs port number to be encoded int it */
Michael Chan289129022009-10-10 13:46:53 +00002741 spe->hdr.conn_and_cmd_data =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002742 cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) |
2743 HW_CID(bp, cid)));
Michael Chan289129022009-10-10 13:46:53 +00002744 spe->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002745 if (common)
Michael Chan289129022009-10-10 13:46:53 +00002746 spe->hdr.type |=
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002747 cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
2748
Michael Chan289129022009-10-10 13:46:53 +00002749 spe->data.mac_config_addr.hi = cpu_to_le32(data_hi);
2750 spe->data.mac_config_addr.lo = cpu_to_le32(data_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002751
2752 bp->spq_left--;
2753
Michael Chan289129022009-10-10 13:46:53 +00002754 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002755 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002756 return 0;
2757}
2758
2759/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002760static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002761{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002762 u32 i, j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002763 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002764
2765 might_sleep();
2766 i = 100;
2767 for (j = 0; j < i*10; j++) {
2768 val = (1UL << 31);
2769 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2770 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
2771 if (val & (1L << 31))
2772 break;
2773
2774 msleep(5);
2775 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002776 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07002777 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002778 rc = -EBUSY;
2779 }
2780
2781 return rc;
2782}
2783
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002784/* release split MCP access lock register */
2785static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002786{
2787 u32 val = 0;
2788
2789 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
2790}
2791
2792static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
2793{
2794 struct host_def_status_block *def_sb = bp->def_status_blk;
2795 u16 rc = 0;
2796
2797 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002798 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
2799 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
2800 rc |= 1;
2801 }
2802 if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
2803 bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
2804 rc |= 2;
2805 }
2806 if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
2807 bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
2808 rc |= 4;
2809 }
2810 if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
2811 bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
2812 rc |= 8;
2813 }
2814 if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
2815 bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
2816 rc |= 16;
2817 }
2818 return rc;
2819}
2820
2821/*
2822 * slow path service functions
2823 */
2824
2825static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
2826{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002827 int port = BP_PORT(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002828 u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
2829 COMMAND_REG_ATTN_BITS_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002830 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2831 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002832 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
2833 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002834 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00002835 u32 nig_mask = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002836
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002837 if (bp->attn_state & asserted)
2838 BNX2X_ERR("IGU ERROR\n");
2839
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002840 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2841 aeu_mask = REG_RD(bp, aeu_addr);
2842
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002843 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002844 aeu_mask, asserted);
2845 aeu_mask &= ~(asserted & 0xff);
2846 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002847
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002848 REG_WR(bp, aeu_addr, aeu_mask);
2849 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002850
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002851 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002852 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002853 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002854
2855 if (asserted & ATTN_HARD_WIRED_MASK) {
2856 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002857
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002858 bnx2x_acquire_phy_lock(bp);
2859
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002860 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00002861 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002862 REG_WR(bp, nig_int_mask_addr, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002863
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002864 bnx2x_link_attn(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002865
2866 /* handle unicore attn? */
2867 }
2868 if (asserted & ATTN_SW_TIMER_4_FUNC)
2869 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
2870
2871 if (asserted & GPIO_2_FUNC)
2872 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
2873
2874 if (asserted & GPIO_3_FUNC)
2875 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
2876
2877 if (asserted & GPIO_4_FUNC)
2878 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
2879
2880 if (port == 0) {
2881 if (asserted & ATTN_GENERAL_ATTN_1) {
2882 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
2883 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
2884 }
2885 if (asserted & ATTN_GENERAL_ATTN_2) {
2886 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
2887 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
2888 }
2889 if (asserted & ATTN_GENERAL_ATTN_3) {
2890 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
2891 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
2892 }
2893 } else {
2894 if (asserted & ATTN_GENERAL_ATTN_4) {
2895 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
2896 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
2897 }
2898 if (asserted & ATTN_GENERAL_ATTN_5) {
2899 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
2900 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
2901 }
2902 if (asserted & ATTN_GENERAL_ATTN_6) {
2903 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
2904 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
2905 }
2906 }
2907
2908 } /* if hardwired */
2909
Eilon Greenstein5c862842008-08-13 15:51:48 -07002910 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2911 asserted, hc_addr);
2912 REG_WR(bp, hc_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002913
2914 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002915 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00002916 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08002917 bnx2x_release_phy_lock(bp);
2918 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002919}
2920
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00002921static inline void bnx2x_fan_failure(struct bnx2x *bp)
2922{
2923 int port = BP_PORT(bp);
2924
2925 /* mark the failure */
2926 bp->link_params.ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
2927 bp->link_params.ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
2928 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
2929 bp->link_params.ext_phy_config);
2930
2931 /* log the failure */
2932 printk(KERN_ERR PFX "Fan Failure on Network Controller %s has caused"
2933 " the driver to shutdown the card to prevent permanent"
2934 " damage. Please contact Dell Support for assistance\n",
2935 bp->dev->name);
2936}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002937
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002938static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
2939{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002940 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002941 int reg_offset;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002942 u32 val, swap_val, swap_override;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002943
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002944 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
2945 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002946
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002947 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002948
2949 val = REG_RD(bp, reg_offset);
2950 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
2951 REG_WR(bp, reg_offset, val);
2952
2953 BNX2X_ERR("SPIO5 hw attention\n");
2954
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00002955 /* Fan failure attention */
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00002956 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
2957 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002958 /* Low power mode is controlled by GPIO 2 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002959 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002960 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00002961 /* The PHY reset is controlled by GPIO 1 */
2962 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
2963 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002964 break;
2965
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002966 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
2967 /* The PHY reset is controlled by GPIO 1 */
2968 /* fake the port number to cancel the swap done in
2969 set_gpio() */
2970 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
2971 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
2972 port = (swap_val && swap_override) ^ 1;
2973 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
2974 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
2975 break;
2976
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002977 default:
2978 break;
2979 }
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00002980 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002981 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002982
Eilon Greenstein589abe32009-02-12 08:36:55 +00002983 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
2984 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
2985 bnx2x_acquire_phy_lock(bp);
2986 bnx2x_handle_module_detect_int(&bp->link_params);
2987 bnx2x_release_phy_lock(bp);
2988 }
2989
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002990 if (attn & HW_INTERRUT_ASSERT_SET_0) {
2991
2992 val = REG_RD(bp, reg_offset);
2993 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
2994 REG_WR(bp, reg_offset, val);
2995
2996 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00002997 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002998 bnx2x_panic();
2999 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003000}
3001
3002static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3003{
3004 u32 val;
3005
Eilon Greenstein0626b892009-02-12 08:38:14 +00003006 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003007
3008 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3009 BNX2X_ERR("DB hw attention 0x%x\n", val);
3010 /* DORQ discard attention */
3011 if (val & 0x2)
3012 BNX2X_ERR("FATAL error from DORQ\n");
3013 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003014
3015 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3016
3017 int port = BP_PORT(bp);
3018 int reg_offset;
3019
3020 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3021 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3022
3023 val = REG_RD(bp, reg_offset);
3024 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3025 REG_WR(bp, reg_offset, val);
3026
3027 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003028 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003029 bnx2x_panic();
3030 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003031}
3032
3033static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3034{
3035 u32 val;
3036
3037 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3038
3039 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3040 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3041 /* CFC error attention */
3042 if (val & 0x2)
3043 BNX2X_ERR("FATAL error from CFC\n");
3044 }
3045
3046 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3047
3048 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3049 BNX2X_ERR("PXP hw attention 0x%x\n", val);
3050 /* RQ_USDMDP_FIFO_OVERFLOW */
3051 if (val & 0x18000)
3052 BNX2X_ERR("FATAL error from PXP\n");
3053 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003054
3055 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3056
3057 int port = BP_PORT(bp);
3058 int reg_offset;
3059
3060 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3061 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3062
3063 val = REG_RD(bp, reg_offset);
3064 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3065 REG_WR(bp, reg_offset, val);
3066
3067 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003068 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003069 bnx2x_panic();
3070 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003071}
3072
3073static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3074{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003075 u32 val;
3076
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003077 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3078
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003079 if (attn & BNX2X_PMF_LINK_ASSERT) {
3080 int func = BP_FUNC(bp);
3081
3082 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07003083 bp->mf_config = SHMEM_RD(bp,
3084 mf_cfg.func_mf_config[func].config);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003085 val = SHMEM_RD(bp, func_mb[func].drv_status);
3086 if (val & DRV_STATUS_DCC_EVENT_MASK)
3087 bnx2x_dcc_event(bp,
3088 (val & DRV_STATUS_DCC_EVENT_MASK));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003089 bnx2x__link_status_update(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003090 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003091 bnx2x_pmf_update(bp);
3092
3093 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003094
3095 BNX2X_ERR("MC assert!\n");
3096 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3097 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3098 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3099 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3100 bnx2x_panic();
3101
3102 } else if (attn & BNX2X_MCP_ASSERT) {
3103
3104 BNX2X_ERR("MCP assert!\n");
3105 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003106 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003107
3108 } else
3109 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3110 }
3111
3112 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003113 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3114 if (attn & BNX2X_GRC_TIMEOUT) {
3115 val = CHIP_IS_E1H(bp) ?
3116 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
3117 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3118 }
3119 if (attn & BNX2X_GRC_RSV) {
3120 val = CHIP_IS_E1H(bp) ?
3121 REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
3122 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3123 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003124 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003125 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003126}
3127
3128static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
3129{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003130 struct attn_route attn;
3131 struct attn_route group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003132 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003133 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003134 u32 reg_addr;
3135 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003136 u32 aeu_mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003137
3138 /* need to take HW lock because MCP or other port might also
3139 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003140 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003141
3142 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
3143 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
3144 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
3145 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003146 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
3147 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003148
3149 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
3150 if (deasserted & (1 << index)) {
3151 group_mask = bp->attn_group[index];
3152
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003153 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
3154 index, group_mask.sig[0], group_mask.sig[1],
3155 group_mask.sig[2], group_mask.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003156
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003157 bnx2x_attn_int_deasserted3(bp,
3158 attn.sig[3] & group_mask.sig[3]);
3159 bnx2x_attn_int_deasserted1(bp,
3160 attn.sig[1] & group_mask.sig[1]);
3161 bnx2x_attn_int_deasserted2(bp,
3162 attn.sig[2] & group_mask.sig[2]);
3163 bnx2x_attn_int_deasserted0(bp,
3164 attn.sig[0] & group_mask.sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003165
3166 if ((attn.sig[0] & group_mask.sig[0] &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003167 HW_PRTY_ASSERT_SET_0) ||
3168 (attn.sig[1] & group_mask.sig[1] &
3169 HW_PRTY_ASSERT_SET_1) ||
3170 (attn.sig[2] & group_mask.sig[2] &
3171 HW_PRTY_ASSERT_SET_2))
Eilon Greenstein6378c022008-08-13 15:59:25 -07003172 BNX2X_ERR("FATAL HW block parity attention\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003173 }
3174 }
3175
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003176 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003177
Eilon Greenstein5c862842008-08-13 15:51:48 -07003178 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003179
3180 val = ~deasserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003181 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
3182 val, reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07003183 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003184
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003185 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003186 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003187
3188 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3189 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3190
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003191 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3192 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003193
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003194 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
3195 aeu_mask, deasserted);
3196 aeu_mask |= (deasserted & 0xff);
3197 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3198
3199 REG_WR(bp, reg_addr, aeu_mask);
3200 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003201
3202 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3203 bp->attn_state &= ~deasserted;
3204 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3205}
3206
3207static void bnx2x_attn_int(struct bnx2x *bp)
3208{
3209 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08003210 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
3211 attn_bits);
3212 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
3213 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003214 u32 attn_state = bp->attn_state;
3215
3216 /* look for changed bits */
3217 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
3218 u32 deasserted = ~attn_bits & attn_ack & attn_state;
3219
3220 DP(NETIF_MSG_HW,
3221 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
3222 attn_bits, attn_ack, asserted, deasserted);
3223
3224 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003225 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003226
3227 /* handle bits that were raised */
3228 if (asserted)
3229 bnx2x_attn_int_asserted(bp, asserted);
3230
3231 if (deasserted)
3232 bnx2x_attn_int_deasserted(bp, deasserted);
3233}
3234
3235static void bnx2x_sp_task(struct work_struct *work)
3236{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08003237 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003238 u16 status;
3239
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003240
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003241 /* Return here if interrupt is disabled */
3242 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07003243 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003244 return;
3245 }
3246
3247 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003248/* if (status == 0) */
3249/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003250
Eilon Greenstein3196a882008-08-13 15:58:49 -07003251 DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003252
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003253 /* HW attentions */
3254 if (status & 0x1)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003255 bnx2x_attn_int(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003256
Eilon Greenstein68d59482009-01-14 21:27:36 -08003257 bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003258 IGU_INT_NOP, 1);
3259 bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
3260 IGU_INT_NOP, 1);
3261 bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
3262 IGU_INT_NOP, 1);
3263 bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
3264 IGU_INT_NOP, 1);
3265 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
3266 IGU_INT_ENABLE, 1);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003267
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003268}
3269
3270static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
3271{
3272 struct net_device *dev = dev_instance;
3273 struct bnx2x *bp = netdev_priv(dev);
3274
3275 /* Return here if interrupt is disabled */
3276 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07003277 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003278 return IRQ_HANDLED;
3279 }
3280
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08003281 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003282
3283#ifdef BNX2X_STOP_ON_ERROR
3284 if (unlikely(bp->panic))
3285 return IRQ_HANDLED;
3286#endif
3287
Michael Chan993ac7b2009-10-10 13:46:56 +00003288#ifdef BCM_CNIC
3289 {
3290 struct cnic_ops *c_ops;
3291
3292 rcu_read_lock();
3293 c_ops = rcu_dereference(bp->cnic_ops);
3294 if (c_ops)
3295 c_ops->cnic_handler(bp->cnic_data, NULL);
3296 rcu_read_unlock();
3297 }
3298#endif
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08003299 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003300
3301 return IRQ_HANDLED;
3302}
3303
3304/* end of slow path */
3305
3306/* Statistics */
3307
3308/****************************************************************************
3309* Macros
3310****************************************************************************/
3311
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003312/* sum[hi:lo] += add[hi:lo] */
3313#define ADD_64(s_hi, a_hi, s_lo, a_lo) \
3314 do { \
3315 s_lo += a_lo; \
Eilon Greensteinf5ba6772009-01-14 21:29:18 -08003316 s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003317 } while (0)
3318
3319/* difference = minuend - subtrahend */
3320#define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
3321 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003322 if (m_lo < s_lo) { \
3323 /* underflow */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003324 d_hi = m_hi - s_hi; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003325 if (d_hi > 0) { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07003326 /* we can 'loan' 1 */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003327 d_hi--; \
3328 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003329 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07003330 /* m_hi <= s_hi */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003331 d_hi = 0; \
3332 d_lo = 0; \
3333 } \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003334 } else { \
3335 /* m_lo >= s_lo */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003336 if (m_hi < s_hi) { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003337 d_hi = 0; \
3338 d_lo = 0; \
3339 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07003340 /* m_hi >= s_hi */ \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003341 d_hi = m_hi - s_hi; \
3342 d_lo = m_lo - s_lo; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003343 } \
3344 } \
3345 } while (0)
3346
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003347#define UPDATE_STAT64(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003348 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003349 DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
3350 diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
3351 pstats->mac_stx[0].t##_hi = new->s##_hi; \
3352 pstats->mac_stx[0].t##_lo = new->s##_lo; \
3353 ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
3354 pstats->mac_stx[1].t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003355 } while (0)
3356
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003357#define UPDATE_STAT64_NIG(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003358 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003359 DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
3360 diff.lo, new->s##_lo, old->s##_lo); \
3361 ADD_64(estats->t##_hi, diff.hi, \
3362 estats->t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003363 } while (0)
3364
3365/* sum[hi:lo] += add */
3366#define ADD_EXTEND_64(s_hi, s_lo, a) \
3367 do { \
3368 s_lo += a; \
3369 s_hi += (s_lo < a) ? 1 : 0; \
3370 } while (0)
3371
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003372#define UPDATE_EXTEND_STAT(s) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003373 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003374 ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
3375 pstats->mac_stx[1].s##_lo, \
3376 new->s); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003377 } while (0)
3378
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003379#define UPDATE_EXTEND_TSTAT(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003380 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003381 diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
3382 old_tclient->s = tclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00003383 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3384 } while (0)
3385
3386#define UPDATE_EXTEND_USTAT(s, t) \
3387 do { \
3388 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3389 old_uclient->s = uclient->s; \
3390 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003391 } while (0)
3392
3393#define UPDATE_EXTEND_XSTAT(s, t) \
3394 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003395 diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
3396 old_xclient->s = xclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00003397 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
3398 } while (0)
3399
3400/* minuend -= subtrahend */
3401#define SUB_64(m_hi, s_hi, m_lo, s_lo) \
3402 do { \
3403 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
3404 } while (0)
3405
3406/* minuend[hi:lo] -= subtrahend */
3407#define SUB_EXTEND_64(m_hi, m_lo, s) \
3408 do { \
3409 SUB_64(m_hi, 0, m_lo, s); \
3410 } while (0)
3411
3412#define SUB_EXTEND_USTAT(s, t) \
3413 do { \
3414 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
3415 SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003416 } while (0)
3417
3418/*
3419 * General service functions
3420 */
3421
3422static inline long bnx2x_hilo(u32 *hiref)
3423{
3424 u32 lo = *(hiref + 1);
3425#if (BITS_PER_LONG == 64)
3426 u32 hi = *hiref;
3427
3428 return HILO_U64(hi, lo);
3429#else
3430 return lo;
3431#endif
3432}
3433
3434/*
3435 * Init service functions
3436 */
3437
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003438static void bnx2x_storm_stats_post(struct bnx2x *bp)
3439{
3440 if (!bp->stats_pending) {
3441 struct eth_query_ramrod_data ramrod_data = {0};
Eilon Greensteinde832a52009-02-12 08:36:33 +00003442 int i, rc;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003443
3444 ramrod_data.drv_counter = bp->stats_counter++;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08003445 ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003446 for_each_queue(bp, i)
3447 ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003448
3449 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
3450 ((u32 *)&ramrod_data)[1],
3451 ((u32 *)&ramrod_data)[0], 0);
3452 if (rc == 0) {
3453 /* stats ramrod has it's own slot on the spq */
3454 bp->spq_left++;
3455 bp->stats_pending = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003456 }
3457 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003458}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003459
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003460static void bnx2x_hw_stats_post(struct bnx2x *bp)
3461{
3462 struct dmae_command *dmae = &bp->stats_dmae;
3463 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3464
3465 *stats_comp = DMAE_COMP_VAL;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003466 if (CHIP_REV_IS_SLOW(bp))
3467 return;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003468
3469 /* loader */
3470 if (bp->executer_idx) {
3471 int loader_idx = PMF_DMAE_C(bp);
3472
3473 memset(dmae, 0, sizeof(struct dmae_command));
3474
3475 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3476 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3477 DMAE_CMD_DST_RESET |
3478#ifdef __BIG_ENDIAN
3479 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3480#else
3481 DMAE_CMD_ENDIANITY_DW_SWAP |
3482#endif
3483 (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
3484 DMAE_CMD_PORT_0) |
3485 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3486 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
3487 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
3488 dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
3489 sizeof(struct dmae_command) *
3490 (loader_idx + 1)) >> 2;
3491 dmae->dst_addr_hi = 0;
3492 dmae->len = sizeof(struct dmae_command) >> 2;
3493 if (CHIP_IS_E1(bp))
3494 dmae->len--;
3495 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
3496 dmae->comp_addr_hi = 0;
3497 dmae->comp_val = 1;
3498
3499 *stats_comp = 0;
3500 bnx2x_post_dmae(bp, dmae, loader_idx);
3501
3502 } else if (bp->func_stx) {
3503 *stats_comp = 0;
3504 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
3505 }
3506}
3507
3508static int bnx2x_stats_comp(struct bnx2x *bp)
3509{
3510 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3511 int cnt = 10;
3512
3513 might_sleep();
3514 while (*stats_comp != DMAE_COMP_VAL) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003515 if (!cnt) {
3516 BNX2X_ERR("timeout waiting for stats finished\n");
3517 break;
3518 }
3519 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -07003520 msleep(1);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003521 }
3522 return 1;
3523}
3524
3525/*
3526 * Statistics service functions
3527 */
3528
3529static void bnx2x_stats_pmf_update(struct bnx2x *bp)
3530{
3531 struct dmae_command *dmae;
3532 u32 opcode;
3533 int loader_idx = PMF_DMAE_C(bp);
3534 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3535
3536 /* sanity */
3537 if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
3538 BNX2X_ERR("BUG!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003539 return;
3540 }
3541
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003542 bp->executer_idx = 0;
3543
3544 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3545 DMAE_CMD_C_ENABLE |
3546 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3547#ifdef __BIG_ENDIAN
3548 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3549#else
3550 DMAE_CMD_ENDIANITY_DW_SWAP |
3551#endif
3552 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3553 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3554
3555 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3556 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
3557 dmae->src_addr_lo = bp->port.port_stx >> 2;
3558 dmae->src_addr_hi = 0;
3559 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3560 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3561 dmae->len = DMAE_LEN32_RD_MAX;
3562 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3563 dmae->comp_addr_hi = 0;
3564 dmae->comp_val = 1;
3565
3566 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3567 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
3568 dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
3569 dmae->src_addr_hi = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07003570 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
3571 DMAE_LEN32_RD_MAX * 4);
3572 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
3573 DMAE_LEN32_RD_MAX * 4);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003574 dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
3575 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3576 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3577 dmae->comp_val = DMAE_COMP_VAL;
3578
3579 *stats_comp = 0;
3580 bnx2x_hw_stats_post(bp);
3581 bnx2x_stats_comp(bp);
3582}
3583
3584static void bnx2x_port_stats_init(struct bnx2x *bp)
3585{
3586 struct dmae_command *dmae;
3587 int port = BP_PORT(bp);
3588 int vn = BP_E1HVN(bp);
3589 u32 opcode;
3590 int loader_idx = PMF_DMAE_C(bp);
3591 u32 mac_addr;
3592 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3593
3594 /* sanity */
3595 if (!bp->link_vars.link_up || !bp->port.pmf) {
3596 BNX2X_ERR("BUG!\n");
3597 return;
3598 }
3599
3600 bp->executer_idx = 0;
3601
3602 /* MCP */
3603 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3604 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3605 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3606#ifdef __BIG_ENDIAN
3607 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3608#else
3609 DMAE_CMD_ENDIANITY_DW_SWAP |
3610#endif
3611 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3612 (vn << DMAE_CMD_E1HVN_SHIFT));
3613
3614 if (bp->port.port_stx) {
3615
3616 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3617 dmae->opcode = opcode;
3618 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3619 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3620 dmae->dst_addr_lo = bp->port.port_stx >> 2;
3621 dmae->dst_addr_hi = 0;
3622 dmae->len = sizeof(struct host_port_stats) >> 2;
3623 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3624 dmae->comp_addr_hi = 0;
3625 dmae->comp_val = 1;
3626 }
3627
3628 if (bp->func_stx) {
3629
3630 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3631 dmae->opcode = opcode;
3632 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3633 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3634 dmae->dst_addr_lo = bp->func_stx >> 2;
3635 dmae->dst_addr_hi = 0;
3636 dmae->len = sizeof(struct host_func_stats) >> 2;
3637 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3638 dmae->comp_addr_hi = 0;
3639 dmae->comp_val = 1;
3640 }
3641
3642 /* MAC */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003643 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3644 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
3645 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3646#ifdef __BIG_ENDIAN
3647 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3648#else
3649 DMAE_CMD_ENDIANITY_DW_SWAP |
3650#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003651 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3652 (vn << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003653
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003654 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003655
3656 mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
3657 NIG_REG_INGRESS_BMAC0_MEM);
3658
3659 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
3660 BIGMAC_REGISTER_TX_STAT_GTBYT */
3661 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3662 dmae->opcode = opcode;
3663 dmae->src_addr_lo = (mac_addr +
3664 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3665 dmae->src_addr_hi = 0;
3666 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3667 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3668 dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
3669 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3670 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3671 dmae->comp_addr_hi = 0;
3672 dmae->comp_val = 1;
3673
3674 /* BIGMAC_REGISTER_RX_STAT_GR64 ..
3675 BIGMAC_REGISTER_RX_STAT_GRIPJ */
3676 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3677 dmae->opcode = opcode;
3678 dmae->src_addr_lo = (mac_addr +
3679 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3680 dmae->src_addr_hi = 0;
3681 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003682 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003683 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003684 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003685 dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
3686 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3687 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3688 dmae->comp_addr_hi = 0;
3689 dmae->comp_val = 1;
3690
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003691 } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003692
3693 mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
3694
3695 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
3696 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3697 dmae->opcode = opcode;
3698 dmae->src_addr_lo = (mac_addr +
3699 EMAC_REG_EMAC_RX_STAT_AC) >> 2;
3700 dmae->src_addr_hi = 0;
3701 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3702 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3703 dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
3704 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3705 dmae->comp_addr_hi = 0;
3706 dmae->comp_val = 1;
3707
3708 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
3709 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3710 dmae->opcode = opcode;
3711 dmae->src_addr_lo = (mac_addr +
3712 EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
3713 dmae->src_addr_hi = 0;
3714 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003715 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003716 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003717 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003718 dmae->len = 1;
3719 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3720 dmae->comp_addr_hi = 0;
3721 dmae->comp_val = 1;
3722
3723 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
3724 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3725 dmae->opcode = opcode;
3726 dmae->src_addr_lo = (mac_addr +
3727 EMAC_REG_EMAC_TX_STAT_AC) >> 2;
3728 dmae->src_addr_hi = 0;
3729 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003730 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003731 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003732 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003733 dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
3734 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3735 dmae->comp_addr_hi = 0;
3736 dmae->comp_val = 1;
3737 }
3738
3739 /* NIG */
3740 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003741 dmae->opcode = opcode;
3742 dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
3743 NIG_REG_STAT0_BRB_DISCARD) >> 2;
3744 dmae->src_addr_hi = 0;
3745 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
3746 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
3747 dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
3748 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3749 dmae->comp_addr_hi = 0;
3750 dmae->comp_val = 1;
3751
3752 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3753 dmae->opcode = opcode;
3754 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
3755 NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
3756 dmae->src_addr_hi = 0;
3757 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3758 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3759 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3760 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3761 dmae->len = (2*sizeof(u32)) >> 2;
3762 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3763 dmae->comp_addr_hi = 0;
3764 dmae->comp_val = 1;
3765
3766 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003767 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3768 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3769 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3770#ifdef __BIG_ENDIAN
3771 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3772#else
3773 DMAE_CMD_ENDIANITY_DW_SWAP |
3774#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003775 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3776 (vn << DMAE_CMD_E1HVN_SHIFT));
3777 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
3778 NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003779 dmae->src_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003780 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3781 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3782 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3783 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3784 dmae->len = (2*sizeof(u32)) >> 2;
3785 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3786 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3787 dmae->comp_val = DMAE_COMP_VAL;
3788
3789 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003790}
3791
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003792static void bnx2x_func_stats_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003793{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003794 struct dmae_command *dmae = &bp->stats_dmae;
3795 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003796
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003797 /* sanity */
3798 if (!bp->func_stx) {
3799 BNX2X_ERR("BUG!\n");
3800 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003801 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003802
3803 bp->executer_idx = 0;
3804 memset(dmae, 0, sizeof(struct dmae_command));
3805
3806 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3807 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3808 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3809#ifdef __BIG_ENDIAN
3810 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3811#else
3812 DMAE_CMD_ENDIANITY_DW_SWAP |
3813#endif
3814 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3815 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3816 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3817 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3818 dmae->dst_addr_lo = bp->func_stx >> 2;
3819 dmae->dst_addr_hi = 0;
3820 dmae->len = sizeof(struct host_func_stats) >> 2;
3821 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3822 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3823 dmae->comp_val = DMAE_COMP_VAL;
3824
3825 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003826}
3827
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003828static void bnx2x_stats_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003829{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003830 if (bp->port.pmf)
3831 bnx2x_port_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003832
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003833 else if (bp->func_stx)
3834 bnx2x_func_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003835
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003836 bnx2x_hw_stats_post(bp);
3837 bnx2x_storm_stats_post(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003838}
3839
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003840static void bnx2x_stats_pmf_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003841{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003842 bnx2x_stats_comp(bp);
3843 bnx2x_stats_pmf_update(bp);
3844 bnx2x_stats_start(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003845}
3846
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003847static void bnx2x_stats_restart(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003848{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003849 bnx2x_stats_comp(bp);
3850 bnx2x_stats_start(bp);
3851}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003852
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003853static void bnx2x_bmac_stats_update(struct bnx2x *bp)
3854{
3855 struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
3856 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003857 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003858 struct {
3859 u32 lo;
3860 u32 hi;
3861 } diff;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003862
3863 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
3864 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
3865 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
3866 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
3867 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
3868 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003869 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003870 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003871 UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003872 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
3873 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
3874 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
3875 UPDATE_STAT64(tx_stat_gt127,
3876 tx_stat_etherstatspkts65octetsto127octets);
3877 UPDATE_STAT64(tx_stat_gt255,
3878 tx_stat_etherstatspkts128octetsto255octets);
3879 UPDATE_STAT64(tx_stat_gt511,
3880 tx_stat_etherstatspkts256octetsto511octets);
3881 UPDATE_STAT64(tx_stat_gt1023,
3882 tx_stat_etherstatspkts512octetsto1023octets);
3883 UPDATE_STAT64(tx_stat_gt1518,
3884 tx_stat_etherstatspkts1024octetsto1522octets);
3885 UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
3886 UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
3887 UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
3888 UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
3889 UPDATE_STAT64(tx_stat_gterr,
3890 tx_stat_dot3statsinternalmactransmiterrors);
3891 UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003892
3893 estats->pause_frames_received_hi =
3894 pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
3895 estats->pause_frames_received_lo =
3896 pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
3897
3898 estats->pause_frames_sent_hi =
3899 pstats->mac_stx[1].tx_stat_outxoffsent_hi;
3900 estats->pause_frames_sent_lo =
3901 pstats->mac_stx[1].tx_stat_outxoffsent_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003902}
3903
3904static void bnx2x_emac_stats_update(struct bnx2x *bp)
3905{
3906 struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
3907 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003908 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003909
3910 UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
3911 UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
3912 UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
3913 UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
3914 UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
3915 UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
3916 UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
3917 UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
3918 UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
3919 UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
3920 UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
3921 UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
3922 UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
3923 UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
3924 UPDATE_EXTEND_STAT(tx_stat_outxonsent);
3925 UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
3926 UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
3927 UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
3928 UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
3929 UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
3930 UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
3931 UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
3932 UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
3933 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
3934 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
3935 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
3936 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
3937 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
3938 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
3939 UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
3940 UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003941
3942 estats->pause_frames_received_hi =
3943 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
3944 estats->pause_frames_received_lo =
3945 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
3946 ADD_64(estats->pause_frames_received_hi,
3947 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
3948 estats->pause_frames_received_lo,
3949 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
3950
3951 estats->pause_frames_sent_hi =
3952 pstats->mac_stx[1].tx_stat_outxonsent_hi;
3953 estats->pause_frames_sent_lo =
3954 pstats->mac_stx[1].tx_stat_outxonsent_lo;
3955 ADD_64(estats->pause_frames_sent_hi,
3956 pstats->mac_stx[1].tx_stat_outxoffsent_hi,
3957 estats->pause_frames_sent_lo,
3958 pstats->mac_stx[1].tx_stat_outxoffsent_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003959}
3960
3961static int bnx2x_hw_stats_update(struct bnx2x *bp)
3962{
3963 struct nig_stats *new = bnx2x_sp(bp, nig_stats);
3964 struct nig_stats *old = &(bp->port.old_nig_stats);
3965 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
3966 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003967 struct {
3968 u32 lo;
3969 u32 hi;
3970 } diff;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003971 u32 nig_timer_max;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003972
3973 if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
3974 bnx2x_bmac_stats_update(bp);
3975
3976 else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
3977 bnx2x_emac_stats_update(bp);
3978
3979 else { /* unreached */
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00003980 BNX2X_ERR("stats updated by DMAE but no MAC active\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003981 return -1;
3982 }
3983
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003984 ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
3985 new->brb_discard - old->brb_discard);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003986 ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
3987 new->brb_truncate - old->brb_truncate);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003988
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003989 UPDATE_STAT64_NIG(egress_mac_pkt0,
3990 etherstatspkts1024octetsto1522octets);
3991 UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003992
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003993 memcpy(old, new, sizeof(struct nig_stats));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003994
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003995 memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
3996 sizeof(struct mac_stx));
3997 estats->brb_drop_hi = pstats->brb_drop_hi;
3998 estats->brb_drop_lo = pstats->brb_drop_lo;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003999
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004000 pstats->host_port_stats_start = ++pstats->host_port_stats_end;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004001
Eilon Greensteinde832a52009-02-12 08:36:33 +00004002 nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
4003 if (nig_timer_max != estats->nig_timer_max) {
4004 estats->nig_timer_max = nig_timer_max;
4005 BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max);
4006 }
4007
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004008 return 0;
4009}
4010
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004011static int bnx2x_storm_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004012{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004013 struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004014 struct tstorm_per_port_stats *tport =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004015 &stats->tstorm_common.port_statistics;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004016 struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
4017 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00004018 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004019
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00004020 memcpy(&(fstats->total_bytes_received_hi),
4021 &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00004022 sizeof(struct host_func_stats) - 2*sizeof(u32));
4023 estats->error_bytes_received_hi = 0;
4024 estats->error_bytes_received_lo = 0;
4025 estats->etherstatsoverrsizepkts_hi = 0;
4026 estats->etherstatsoverrsizepkts_lo = 0;
4027 estats->no_buff_discard_hi = 0;
4028 estats->no_buff_discard_lo = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004029
Eilon Greensteinca003922009-08-12 22:53:28 -07004030 for_each_rx_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00004031 struct bnx2x_fastpath *fp = &bp->fp[i];
4032 int cl_id = fp->cl_id;
4033 struct tstorm_per_client_stats *tclient =
4034 &stats->tstorm_common.client_statistics[cl_id];
4035 struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
4036 struct ustorm_per_client_stats *uclient =
4037 &stats->ustorm_common.client_statistics[cl_id];
4038 struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
4039 struct xstorm_per_client_stats *xclient =
4040 &stats->xstorm_common.client_statistics[cl_id];
4041 struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
4042 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
4043 u32 diff;
4044
4045 /* are storm stats valid? */
4046 if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
4047 bp->stats_counter) {
4048 DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
4049 " xstorm counter (%d) != stats_counter (%d)\n",
4050 i, xclient->stats_counter, bp->stats_counter);
4051 return -1;
4052 }
4053 if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
4054 bp->stats_counter) {
4055 DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
4056 " tstorm counter (%d) != stats_counter (%d)\n",
4057 i, tclient->stats_counter, bp->stats_counter);
4058 return -2;
4059 }
4060 if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
4061 bp->stats_counter) {
4062 DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
4063 " ustorm counter (%d) != stats_counter (%d)\n",
4064 i, uclient->stats_counter, bp->stats_counter);
4065 return -4;
4066 }
4067
4068 qstats->total_bytes_received_hi =
Eilon Greensteinca003922009-08-12 22:53:28 -07004069 le32_to_cpu(tclient->rcv_broadcast_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004070 qstats->total_bytes_received_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07004071 le32_to_cpu(tclient->rcv_broadcast_bytes.lo);
4072
4073 ADD_64(qstats->total_bytes_received_hi,
4074 le32_to_cpu(tclient->rcv_multicast_bytes.hi),
4075 qstats->total_bytes_received_lo,
4076 le32_to_cpu(tclient->rcv_multicast_bytes.lo));
4077
4078 ADD_64(qstats->total_bytes_received_hi,
4079 le32_to_cpu(tclient->rcv_unicast_bytes.hi),
4080 qstats->total_bytes_received_lo,
4081 le32_to_cpu(tclient->rcv_unicast_bytes.lo));
4082
4083 qstats->valid_bytes_received_hi =
4084 qstats->total_bytes_received_hi;
Eilon Greensteinde832a52009-02-12 08:36:33 +00004085 qstats->valid_bytes_received_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07004086 qstats->total_bytes_received_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004087
Eilon Greensteinde832a52009-02-12 08:36:33 +00004088 qstats->error_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004089 le32_to_cpu(tclient->rcv_error_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004090 qstats->error_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004091 le32_to_cpu(tclient->rcv_error_bytes.lo);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004092
4093 ADD_64(qstats->total_bytes_received_hi,
4094 qstats->error_bytes_received_hi,
4095 qstats->total_bytes_received_lo,
4096 qstats->error_bytes_received_lo);
4097
4098 UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
4099 total_unicast_packets_received);
4100 UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
4101 total_multicast_packets_received);
4102 UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
4103 total_broadcast_packets_received);
4104 UPDATE_EXTEND_TSTAT(packets_too_big_discard,
4105 etherstatsoverrsizepkts);
4106 UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
4107
4108 SUB_EXTEND_USTAT(ucast_no_buff_pkts,
4109 total_unicast_packets_received);
4110 SUB_EXTEND_USTAT(mcast_no_buff_pkts,
4111 total_multicast_packets_received);
4112 SUB_EXTEND_USTAT(bcast_no_buff_pkts,
4113 total_broadcast_packets_received);
4114 UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
4115 UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
4116 UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
4117
4118 qstats->total_bytes_transmitted_hi =
Eilon Greensteinca003922009-08-12 22:53:28 -07004119 le32_to_cpu(xclient->unicast_bytes_sent.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004120 qstats->total_bytes_transmitted_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07004121 le32_to_cpu(xclient->unicast_bytes_sent.lo);
4122
4123 ADD_64(qstats->total_bytes_transmitted_hi,
4124 le32_to_cpu(xclient->multicast_bytes_sent.hi),
4125 qstats->total_bytes_transmitted_lo,
4126 le32_to_cpu(xclient->multicast_bytes_sent.lo));
4127
4128 ADD_64(qstats->total_bytes_transmitted_hi,
4129 le32_to_cpu(xclient->broadcast_bytes_sent.hi),
4130 qstats->total_bytes_transmitted_lo,
4131 le32_to_cpu(xclient->broadcast_bytes_sent.lo));
Eilon Greensteinde832a52009-02-12 08:36:33 +00004132
4133 UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
4134 total_unicast_packets_transmitted);
4135 UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
4136 total_multicast_packets_transmitted);
4137 UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
4138 total_broadcast_packets_transmitted);
4139
4140 old_tclient->checksum_discard = tclient->checksum_discard;
4141 old_tclient->ttl0_discard = tclient->ttl0_discard;
4142
4143 ADD_64(fstats->total_bytes_received_hi,
4144 qstats->total_bytes_received_hi,
4145 fstats->total_bytes_received_lo,
4146 qstats->total_bytes_received_lo);
4147 ADD_64(fstats->total_bytes_transmitted_hi,
4148 qstats->total_bytes_transmitted_hi,
4149 fstats->total_bytes_transmitted_lo,
4150 qstats->total_bytes_transmitted_lo);
4151 ADD_64(fstats->total_unicast_packets_received_hi,
4152 qstats->total_unicast_packets_received_hi,
4153 fstats->total_unicast_packets_received_lo,
4154 qstats->total_unicast_packets_received_lo);
4155 ADD_64(fstats->total_multicast_packets_received_hi,
4156 qstats->total_multicast_packets_received_hi,
4157 fstats->total_multicast_packets_received_lo,
4158 qstats->total_multicast_packets_received_lo);
4159 ADD_64(fstats->total_broadcast_packets_received_hi,
4160 qstats->total_broadcast_packets_received_hi,
4161 fstats->total_broadcast_packets_received_lo,
4162 qstats->total_broadcast_packets_received_lo);
4163 ADD_64(fstats->total_unicast_packets_transmitted_hi,
4164 qstats->total_unicast_packets_transmitted_hi,
4165 fstats->total_unicast_packets_transmitted_lo,
4166 qstats->total_unicast_packets_transmitted_lo);
4167 ADD_64(fstats->total_multicast_packets_transmitted_hi,
4168 qstats->total_multicast_packets_transmitted_hi,
4169 fstats->total_multicast_packets_transmitted_lo,
4170 qstats->total_multicast_packets_transmitted_lo);
4171 ADD_64(fstats->total_broadcast_packets_transmitted_hi,
4172 qstats->total_broadcast_packets_transmitted_hi,
4173 fstats->total_broadcast_packets_transmitted_lo,
4174 qstats->total_broadcast_packets_transmitted_lo);
4175 ADD_64(fstats->valid_bytes_received_hi,
4176 qstats->valid_bytes_received_hi,
4177 fstats->valid_bytes_received_lo,
4178 qstats->valid_bytes_received_lo);
4179
4180 ADD_64(estats->error_bytes_received_hi,
4181 qstats->error_bytes_received_hi,
4182 estats->error_bytes_received_lo,
4183 qstats->error_bytes_received_lo);
4184 ADD_64(estats->etherstatsoverrsizepkts_hi,
4185 qstats->etherstatsoverrsizepkts_hi,
4186 estats->etherstatsoverrsizepkts_lo,
4187 qstats->etherstatsoverrsizepkts_lo);
4188 ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
4189 estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
4190 }
4191
4192 ADD_64(fstats->total_bytes_received_hi,
4193 estats->rx_stat_ifhcinbadoctets_hi,
4194 fstats->total_bytes_received_lo,
4195 estats->rx_stat_ifhcinbadoctets_lo);
4196
4197 memcpy(estats, &(fstats->total_bytes_received_hi),
4198 sizeof(struct host_func_stats) - 2*sizeof(u32));
4199
4200 ADD_64(estats->etherstatsoverrsizepkts_hi,
4201 estats->rx_stat_dot3statsframestoolong_hi,
4202 estats->etherstatsoverrsizepkts_lo,
4203 estats->rx_stat_dot3statsframestoolong_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004204 ADD_64(estats->error_bytes_received_hi,
4205 estats->rx_stat_ifhcinbadoctets_hi,
4206 estats->error_bytes_received_lo,
4207 estats->rx_stat_ifhcinbadoctets_lo);
4208
Eilon Greensteinde832a52009-02-12 08:36:33 +00004209 if (bp->port.pmf) {
4210 estats->mac_filter_discard =
4211 le32_to_cpu(tport->mac_filter_discard);
4212 estats->xxoverflow_discard =
4213 le32_to_cpu(tport->xxoverflow_discard);
4214 estats->brb_truncate_discard =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004215 le32_to_cpu(tport->brb_truncate_discard);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004216 estats->mac_discard = le32_to_cpu(tport->mac_discard);
4217 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004218
4219 fstats->host_func_stats_start = ++fstats->host_func_stats_end;
4220
Eilon Greensteinde832a52009-02-12 08:36:33 +00004221 bp->stats_pending = 0;
4222
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004223 return 0;
4224}
4225
4226static void bnx2x_net_stats_update(struct bnx2x *bp)
4227{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004228 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004229 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00004230 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004231
4232 nstats->rx_packets =
4233 bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
4234 bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
4235 bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
4236
4237 nstats->tx_packets =
4238 bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
4239 bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
4240 bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
4241
Eilon Greensteinde832a52009-02-12 08:36:33 +00004242 nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004243
Eliezer Tamir0e39e642008-02-28 11:54:03 -08004244 nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004245
Eilon Greensteinde832a52009-02-12 08:36:33 +00004246 nstats->rx_dropped = estats->mac_discard;
Eilon Greensteinca003922009-08-12 22:53:28 -07004247 for_each_rx_queue(bp, i)
Eilon Greensteinde832a52009-02-12 08:36:33 +00004248 nstats->rx_dropped +=
4249 le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
4250
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004251 nstats->tx_dropped = 0;
4252
4253 nstats->multicast =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004254 bnx2x_hilo(&estats->total_multicast_packets_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004255
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004256 nstats->collisions =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004257 bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004258
4259 nstats->rx_length_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004260 bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
4261 bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
4262 nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
4263 bnx2x_hilo(&estats->brb_truncate_hi);
4264 nstats->rx_crc_errors =
4265 bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
4266 nstats->rx_frame_errors =
4267 bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
4268 nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004269 nstats->rx_missed_errors = estats->xxoverflow_discard;
4270
4271 nstats->rx_errors = nstats->rx_length_errors +
4272 nstats->rx_over_errors +
4273 nstats->rx_crc_errors +
4274 nstats->rx_frame_errors +
Eliezer Tamir0e39e642008-02-28 11:54:03 -08004275 nstats->rx_fifo_errors +
4276 nstats->rx_missed_errors;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004277
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004278 nstats->tx_aborted_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004279 bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
4280 bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
4281 nstats->tx_carrier_errors =
4282 bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004283 nstats->tx_fifo_errors = 0;
4284 nstats->tx_heartbeat_errors = 0;
4285 nstats->tx_window_errors = 0;
4286
4287 nstats->tx_errors = nstats->tx_aborted_errors +
Eilon Greensteinde832a52009-02-12 08:36:33 +00004288 nstats->tx_carrier_errors +
4289 bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
4290}
4291
4292static void bnx2x_drv_stats_update(struct bnx2x *bp)
4293{
4294 struct bnx2x_eth_stats *estats = &bp->eth_stats;
4295 int i;
4296
4297 estats->driver_xoff = 0;
4298 estats->rx_err_discard_pkt = 0;
4299 estats->rx_skb_alloc_failed = 0;
4300 estats->hw_csum_err = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -07004301 for_each_rx_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00004302 struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
4303
4304 estats->driver_xoff += qstats->driver_xoff;
4305 estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
4306 estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
4307 estats->hw_csum_err += qstats->hw_csum_err;
4308 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004309}
4310
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004311static void bnx2x_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004312{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004313 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004314
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004315 if (*stats_comp != DMAE_COMP_VAL)
4316 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004317
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004318 if (bp->port.pmf)
Eilon Greensteinde832a52009-02-12 08:36:33 +00004319 bnx2x_hw_stats_update(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004320
Eilon Greensteinde832a52009-02-12 08:36:33 +00004321 if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
4322 BNX2X_ERR("storm stats were not updated for 3 times\n");
4323 bnx2x_panic();
4324 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004325 }
4326
Eilon Greensteinde832a52009-02-12 08:36:33 +00004327 bnx2x_net_stats_update(bp);
4328 bnx2x_drv_stats_update(bp);
4329
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004330 if (bp->msglevel & NETIF_MSG_TIMER) {
Eilon Greensteinca003922009-08-12 22:53:28 -07004331 struct bnx2x_fastpath *fp0_rx = bp->fp;
4332 struct bnx2x_fastpath *fp0_tx = &(bp->fp[bp->num_rx_queues]);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004333 struct tstorm_per_client_stats *old_tclient =
4334 &bp->fp->old_tclient;
4335 struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004336 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004337 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004338 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004339
4340 printk(KERN_DEBUG "%s:\n", bp->dev->name);
4341 printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)"
4342 " tx pkt (%lx)\n",
Eilon Greensteinca003922009-08-12 22:53:28 -07004343 bnx2x_tx_avail(fp0_tx),
4344 le16_to_cpu(*fp0_tx->tx_cons_sb), nstats->tx_packets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004345 printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)"
4346 " rx pkt (%lx)\n",
Eilon Greensteinca003922009-08-12 22:53:28 -07004347 (u16)(le16_to_cpu(*fp0_rx->rx_cons_sb) -
4348 fp0_rx->rx_comp_cons),
4349 le16_to_cpu(*fp0_rx->rx_cons_sb), nstats->rx_packets);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004350 printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u "
4351 "brb truncate %u\n",
4352 (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"),
4353 qstats->driver_xoff,
4354 estats->brb_drop_lo, estats->brb_truncate_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004355 printk(KERN_DEBUG "tstats: checksum_discard %u "
Eilon Greensteinde832a52009-02-12 08:36:33 +00004356 "packets_too_big_discard %lu no_buff_discard %lu "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004357 "mac_discard %u mac_filter_discard %u "
4358 "xxovrflow_discard %u brb_truncate_discard %u "
4359 "ttl0_discard %u\n",
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00004360 le32_to_cpu(old_tclient->checksum_discard),
Eilon Greensteinde832a52009-02-12 08:36:33 +00004361 bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi),
4362 bnx2x_hilo(&qstats->no_buff_discard_hi),
4363 estats->mac_discard, estats->mac_filter_discard,
4364 estats->xxoverflow_discard, estats->brb_truncate_discard,
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00004365 le32_to_cpu(old_tclient->ttl0_discard));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004366
4367 for_each_queue(bp, i) {
4368 printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i,
4369 bnx2x_fp(bp, i, tx_pkt),
4370 bnx2x_fp(bp, i, rx_pkt),
4371 bnx2x_fp(bp, i, rx_calls));
4372 }
4373 }
4374
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004375 bnx2x_hw_stats_post(bp);
4376 bnx2x_storm_stats_post(bp);
4377}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004378
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004379static void bnx2x_port_stats_stop(struct bnx2x *bp)
4380{
4381 struct dmae_command *dmae;
4382 u32 opcode;
4383 int loader_idx = PMF_DMAE_C(bp);
4384 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004385
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004386 bp->executer_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004387
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004388 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
4389 DMAE_CMD_C_ENABLE |
4390 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004391#ifdef __BIG_ENDIAN
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004392 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004393#else
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004394 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004395#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004396 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
4397 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
4398
4399 if (bp->port.port_stx) {
4400
4401 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4402 if (bp->func_stx)
4403 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
4404 else
4405 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4406 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
4407 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
4408 dmae->dst_addr_lo = bp->port.port_stx >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004409 dmae->dst_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004410 dmae->len = sizeof(struct host_port_stats) >> 2;
4411 if (bp->func_stx) {
4412 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
4413 dmae->comp_addr_hi = 0;
4414 dmae->comp_val = 1;
4415 } else {
4416 dmae->comp_addr_lo =
4417 U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4418 dmae->comp_addr_hi =
4419 U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4420 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004421
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004422 *stats_comp = 0;
4423 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004424 }
4425
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004426 if (bp->func_stx) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004427
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004428 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4429 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
4430 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
4431 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
4432 dmae->dst_addr_lo = bp->func_stx >> 2;
4433 dmae->dst_addr_hi = 0;
4434 dmae->len = sizeof(struct host_func_stats) >> 2;
4435 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4436 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4437 dmae->comp_val = DMAE_COMP_VAL;
4438
4439 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004440 }
4441}
4442
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004443static void bnx2x_stats_stop(struct bnx2x *bp)
4444{
4445 int update = 0;
4446
4447 bnx2x_stats_comp(bp);
4448
4449 if (bp->port.pmf)
4450 update = (bnx2x_hw_stats_update(bp) == 0);
4451
4452 update |= (bnx2x_storm_stats_update(bp) == 0);
4453
4454 if (update) {
4455 bnx2x_net_stats_update(bp);
4456
4457 if (bp->port.pmf)
4458 bnx2x_port_stats_stop(bp);
4459
4460 bnx2x_hw_stats_post(bp);
4461 bnx2x_stats_comp(bp);
4462 }
4463}
4464
4465static void bnx2x_stats_do_nothing(struct bnx2x *bp)
4466{
4467}
4468
4469static const struct {
4470 void (*action)(struct bnx2x *bp);
4471 enum bnx2x_stats_state next_state;
4472} bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
4473/* state event */
4474{
4475/* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
4476/* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
4477/* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
4478/* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
4479},
4480{
4481/* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
4482/* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
4483/* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
4484/* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
4485}
4486};
4487
4488static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
4489{
4490 enum bnx2x_stats_state state = bp->stats_state;
4491
4492 bnx2x_stats_stm[state][event].action(bp);
4493 bp->stats_state = bnx2x_stats_stm[state][event].next_state;
4494
Eilon Greenstein89246652009-08-12 08:23:56 +00004495 /* Make sure the state has been "changed" */
4496 smp_wmb();
4497
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004498 if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER))
4499 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
4500 state, event, bp->stats_state);
4501}
4502
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00004503static void bnx2x_port_stats_base_init(struct bnx2x *bp)
4504{
4505 struct dmae_command *dmae;
4506 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
4507
4508 /* sanity */
4509 if (!bp->port.pmf || !bp->port.port_stx) {
4510 BNX2X_ERR("BUG!\n");
4511 return;
4512 }
4513
4514 bp->executer_idx = 0;
4515
4516 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
4517 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
4518 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
4519 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
4520#ifdef __BIG_ENDIAN
4521 DMAE_CMD_ENDIANITY_B_DW_SWAP |
4522#else
4523 DMAE_CMD_ENDIANITY_DW_SWAP |
4524#endif
4525 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
4526 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
4527 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
4528 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
4529 dmae->dst_addr_lo = bp->port.port_stx >> 2;
4530 dmae->dst_addr_hi = 0;
4531 dmae->len = sizeof(struct host_port_stats) >> 2;
4532 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4533 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4534 dmae->comp_val = DMAE_COMP_VAL;
4535
4536 *stats_comp = 0;
4537 bnx2x_hw_stats_post(bp);
4538 bnx2x_stats_comp(bp);
4539}
4540
4541static void bnx2x_func_stats_base_init(struct bnx2x *bp)
4542{
4543 int vn, vn_max = IS_E1HMF(bp) ? E1HVN_MAX : E1VN_MAX;
4544 int port = BP_PORT(bp);
4545 int func;
4546 u32 func_stx;
4547
4548 /* sanity */
4549 if (!bp->port.pmf || !bp->func_stx) {
4550 BNX2X_ERR("BUG!\n");
4551 return;
4552 }
4553
4554 /* save our func_stx */
4555 func_stx = bp->func_stx;
4556
4557 for (vn = VN_0; vn < vn_max; vn++) {
4558 func = 2*vn + port;
4559
4560 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
4561 bnx2x_func_stats_init(bp);
4562 bnx2x_hw_stats_post(bp);
4563 bnx2x_stats_comp(bp);
4564 }
4565
4566 /* restore our func_stx */
4567 bp->func_stx = func_stx;
4568}
4569
4570static void bnx2x_func_stats_base_update(struct bnx2x *bp)
4571{
4572 struct dmae_command *dmae = &bp->stats_dmae;
4573 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
4574
4575 /* sanity */
4576 if (!bp->func_stx) {
4577 BNX2X_ERR("BUG!\n");
4578 return;
4579 }
4580
4581 bp->executer_idx = 0;
4582 memset(dmae, 0, sizeof(struct dmae_command));
4583
4584 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
4585 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
4586 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
4587#ifdef __BIG_ENDIAN
4588 DMAE_CMD_ENDIANITY_B_DW_SWAP |
4589#else
4590 DMAE_CMD_ENDIANITY_DW_SWAP |
4591#endif
4592 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
4593 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
4594 dmae->src_addr_lo = bp->func_stx >> 2;
4595 dmae->src_addr_hi = 0;
4596 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats_base));
4597 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats_base));
4598 dmae->len = sizeof(struct host_func_stats) >> 2;
4599 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
4600 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
4601 dmae->comp_val = DMAE_COMP_VAL;
4602
4603 *stats_comp = 0;
4604 bnx2x_hw_stats_post(bp);
4605 bnx2x_stats_comp(bp);
4606}
4607
4608static void bnx2x_stats_init(struct bnx2x *bp)
4609{
4610 int port = BP_PORT(bp);
4611 int func = BP_FUNC(bp);
4612 int i;
4613
4614 bp->stats_pending = 0;
4615 bp->executer_idx = 0;
4616 bp->stats_counter = 0;
4617
4618 /* port and func stats for management */
4619 if (!BP_NOMCP(bp)) {
4620 bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
4621 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
4622
4623 } else {
4624 bp->port.port_stx = 0;
4625 bp->func_stx = 0;
4626 }
4627 DP(BNX2X_MSG_STATS, "port_stx 0x%x func_stx 0x%x\n",
4628 bp->port.port_stx, bp->func_stx);
4629
4630 /* port stats */
4631 memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
4632 bp->port.old_nig_stats.brb_discard =
4633 REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
4634 bp->port.old_nig_stats.brb_truncate =
4635 REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
4636 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
4637 &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
4638 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
4639 &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
4640
4641 /* function stats */
4642 for_each_queue(bp, i) {
4643 struct bnx2x_fastpath *fp = &bp->fp[i];
4644
4645 memset(&fp->old_tclient, 0,
4646 sizeof(struct tstorm_per_client_stats));
4647 memset(&fp->old_uclient, 0,
4648 sizeof(struct ustorm_per_client_stats));
4649 memset(&fp->old_xclient, 0,
4650 sizeof(struct xstorm_per_client_stats));
4651 memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
4652 }
4653
4654 memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
4655 memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
4656
4657 bp->stats_state = STATS_STATE_DISABLED;
4658
4659 if (bp->port.pmf) {
4660 if (bp->port.port_stx)
4661 bnx2x_port_stats_base_init(bp);
4662
4663 if (bp->func_stx)
4664 bnx2x_func_stats_base_init(bp);
4665
4666 } else if (bp->func_stx)
4667 bnx2x_func_stats_base_update(bp);
4668}
4669
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004670static void bnx2x_timer(unsigned long data)
4671{
4672 struct bnx2x *bp = (struct bnx2x *) data;
4673
4674 if (!netif_running(bp->dev))
4675 return;
4676
4677 if (atomic_read(&bp->intr_sem) != 0)
Eliezer Tamirf1410642008-02-28 11:51:50 -08004678 goto timer_restart;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004679
4680 if (poll) {
4681 struct bnx2x_fastpath *fp = &bp->fp[0];
4682 int rc;
4683
Eilon Greenstein7961f792009-03-02 07:59:31 +00004684 bnx2x_tx_int(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004685 rc = bnx2x_rx_int(fp, 1000);
4686 }
4687
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004688 if (!BP_NOMCP(bp)) {
4689 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004690 u32 drv_pulse;
4691 u32 mcp_pulse;
4692
4693 ++bp->fw_drv_pulse_wr_seq;
4694 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4695 /* TBD - add SYSTEM_TIME */
4696 drv_pulse = bp->fw_drv_pulse_wr_seq;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004697 SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004698
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004699 mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004700 MCP_PULSE_SEQ_MASK);
4701 /* The delta between driver pulse and mcp response
4702 * should be 1 (before mcp response) or 0 (after mcp response)
4703 */
4704 if ((drv_pulse != mcp_pulse) &&
4705 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4706 /* someone lost a heartbeat... */
4707 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4708 drv_pulse, mcp_pulse);
4709 }
4710 }
4711
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07004712 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004713 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004714
Eliezer Tamirf1410642008-02-28 11:51:50 -08004715timer_restart:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004716 mod_timer(&bp->timer, jiffies + bp->current_interval);
4717}
4718
4719/* end of Statistics */
4720
4721/* nic init */
4722
4723/*
4724 * nic init service functions
4725 */
4726
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004727static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004728{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004729 int port = BP_PORT(bp);
4730
Eilon Greensteinca003922009-08-12 22:53:28 -07004731 /* "CSTORM" */
4732 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4733 CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), 0,
4734 CSTORM_SB_STATUS_BLOCK_U_SIZE / 4);
4735 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4736 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), 0,
4737 CSTORM_SB_STATUS_BLOCK_C_SIZE / 4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004738}
4739
Eilon Greenstein5c862842008-08-13 15:51:48 -07004740static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
4741 dma_addr_t mapping, int sb_id)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004742{
4743 int port = BP_PORT(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004744 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004745 int index;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004746 u64 section;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004747
4748 /* USTORM */
4749 section = ((u64)mapping) + offsetof(struct host_status_block,
4750 u_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004751 sb->u_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004752
Eilon Greensteinca003922009-08-12 22:53:28 -07004753 REG_WR(bp, BAR_CSTRORM_INTMEM +
4754 CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id), U64_LO(section));
4755 REG_WR(bp, BAR_CSTRORM_INTMEM +
4756 ((CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004757 U64_HI(section));
Eilon Greensteinca003922009-08-12 22:53:28 -07004758 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_USB_FUNC_OFF +
4759 CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004760
4761 for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
Eilon Greensteinca003922009-08-12 22:53:28 -07004762 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4763 CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004764
4765 /* CSTORM */
4766 section = ((u64)mapping) + offsetof(struct host_status_block,
4767 c_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004768 sb->c_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004769
4770 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004771 CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004772 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004773 ((CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004774 U64_HI(section));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004775 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
Eilon Greensteinca003922009-08-12 22:53:28 -07004776 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004777
4778 for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
4779 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004780 CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004781
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004782 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
4783}
4784
4785static void bnx2x_zero_def_sb(struct bnx2x *bp)
4786{
4787 int func = BP_FUNC(bp);
4788
Eilon Greensteinca003922009-08-12 22:53:28 -07004789 bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004790 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4791 sizeof(struct tstorm_def_status_block)/4);
Eilon Greensteinca003922009-08-12 22:53:28 -07004792 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4793 CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), 0,
4794 sizeof(struct cstorm_def_status_block_u)/4);
4795 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4796 CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), 0,
4797 sizeof(struct cstorm_def_status_block_c)/4);
4798 bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY +
Eilon Greenstein490c3c92009-03-02 07:59:52 +00004799 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4800 sizeof(struct xstorm_def_status_block)/4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004801}
4802
4803static void bnx2x_init_def_sb(struct bnx2x *bp,
4804 struct host_def_status_block *def_sb,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004805 dma_addr_t mapping, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004806{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004807 int port = BP_PORT(bp);
4808 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004809 int index, val, reg_offset;
4810 u64 section;
4811
4812 /* ATTN */
4813 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4814 atten_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004815 def_sb->atten_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004816
Eliezer Tamir49d66772008-02-28 11:53:13 -08004817 bp->attn_state = 0;
4818
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004819 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4820 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4821
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004822 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004823 bp->attn_group[index].sig[0] = REG_RD(bp,
4824 reg_offset + 0x10*index);
4825 bp->attn_group[index].sig[1] = REG_RD(bp,
4826 reg_offset + 0x4 + 0x10*index);
4827 bp->attn_group[index].sig[2] = REG_RD(bp,
4828 reg_offset + 0x8 + 0x10*index);
4829 bp->attn_group[index].sig[3] = REG_RD(bp,
4830 reg_offset + 0xc + 0x10*index);
4831 }
4832
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004833 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4834 HC_REG_ATTN_MSG0_ADDR_L);
4835
4836 REG_WR(bp, reg_offset, U64_LO(section));
4837 REG_WR(bp, reg_offset + 4, U64_HI(section));
4838
4839 reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
4840
4841 val = REG_RD(bp, reg_offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004842 val |= sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004843 REG_WR(bp, reg_offset, val);
4844
4845 /* USTORM */
4846 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4847 u_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004848 def_sb->u_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004849
Eilon Greensteinca003922009-08-12 22:53:28 -07004850 REG_WR(bp, BAR_CSTRORM_INTMEM +
4851 CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func), U64_LO(section));
4852 REG_WR(bp, BAR_CSTRORM_INTMEM +
4853 ((CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004854 U64_HI(section));
Eilon Greensteinca003922009-08-12 22:53:28 -07004855 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_USB_FUNC_OFF +
4856 CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004857
4858 for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
Eilon Greensteinca003922009-08-12 22:53:28 -07004859 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4860 CSTORM_DEF_SB_HC_DISABLE_U_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004861
4862 /* CSTORM */
4863 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4864 c_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004865 def_sb->c_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004866
4867 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004868 CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004869 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004870 ((CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004871 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004872 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
Eilon Greensteinca003922009-08-12 22:53:28 -07004873 CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004874
4875 for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
4876 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004877 CSTORM_DEF_SB_HC_DISABLE_C_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004878
4879 /* TSTORM */
4880 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4881 t_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004882 def_sb->t_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004883
4884 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004885 TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004886 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004887 ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004888 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004889 REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004890 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004891
4892 for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
4893 REG_WR16(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004894 TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004895
4896 /* XSTORM */
4897 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4898 x_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004899 def_sb->x_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004900
4901 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004902 XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004903 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004904 ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004905 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004906 REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004907 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004908
4909 for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
4910 REG_WR16(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004911 XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004912
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004913 bp->stats_pending = 0;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004914 bp->set_mac_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004915
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004916 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004917}
4918
4919static void bnx2x_update_coalesce(struct bnx2x *bp)
4920{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004921 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004922 int i;
4923
4924 for_each_queue(bp, i) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004925 int sb_id = bp->fp[i].sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004926
4927 /* HC_INDEX_U_ETH_RX_CQ_CONS */
Eilon Greensteinca003922009-08-12 22:53:28 -07004928 REG_WR8(bp, BAR_CSTRORM_INTMEM +
4929 CSTORM_SB_HC_TIMEOUT_U_OFFSET(port, sb_id,
4930 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004931 bp->rx_ticks/12);
Eilon Greensteinca003922009-08-12 22:53:28 -07004932 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4933 CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id,
4934 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein3799cf42009-07-05 04:18:12 +00004935 (bp->rx_ticks/12) ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004936
4937 /* HC_INDEX_C_ETH_TX_CQ_CONS */
4938 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004939 CSTORM_SB_HC_TIMEOUT_C_OFFSET(port, sb_id,
4940 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004941 bp->tx_ticks/12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004942 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004943 CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id,
4944 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein3799cf42009-07-05 04:18:12 +00004945 (bp->tx_ticks/12) ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004946 }
4947}
4948
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004949static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
4950 struct bnx2x_fastpath *fp, int last)
4951{
4952 int i;
4953
4954 for (i = 0; i < last; i++) {
4955 struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
4956 struct sk_buff *skb = rx_buf->skb;
4957
4958 if (skb == NULL) {
4959 DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
4960 continue;
4961 }
4962
4963 if (fp->tpa_state[i] == BNX2X_TPA_START)
4964 pci_unmap_single(bp->pdev,
4965 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein356e2382009-02-12 08:38:32 +00004966 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004967
4968 dev_kfree_skb(skb);
4969 rx_buf->skb = NULL;
4970 }
4971}
4972
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004973static void bnx2x_init_rx_rings(struct bnx2x *bp)
4974{
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004975 int func = BP_FUNC(bp);
Eilon Greenstein32626232008-08-13 15:51:07 -07004976 int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
4977 ETH_MAX_AGGREGATION_QUEUES_E1H;
4978 u16 ring_prod, cqe_ring_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004979 int i, j;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004980
Eilon Greenstein87942b42009-02-12 08:36:49 +00004981 bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN;
Eilon Greenstein0f008462009-02-12 08:36:18 +00004982 DP(NETIF_MSG_IFUP,
4983 "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004984
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004985 if (bp->flags & TPA_ENABLE_FLAG) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004986
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004987 for_each_rx_queue(bp, j) {
Eilon Greenstein32626232008-08-13 15:51:07 -07004988 struct bnx2x_fastpath *fp = &bp->fp[j];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004989
Eilon Greenstein32626232008-08-13 15:51:07 -07004990 for (i = 0; i < max_agg_queues; i++) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004991 fp->tpa_pool[i].skb =
4992 netdev_alloc_skb(bp->dev, bp->rx_buf_size);
4993 if (!fp->tpa_pool[i].skb) {
4994 BNX2X_ERR("Failed to allocate TPA "
4995 "skb pool for queue[%d] - "
4996 "disabling TPA on this "
4997 "queue!\n", j);
4998 bnx2x_free_tpa_pool(bp, fp, i);
4999 fp->disable_tpa = 1;
5000 break;
5001 }
5002 pci_unmap_addr_set((struct sw_rx_bd *)
5003 &bp->fp->tpa_pool[i],
5004 mapping, 0);
5005 fp->tpa_state[i] = BNX2X_TPA_STOP;
5006 }
5007 }
5008 }
5009
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005010 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005011 struct bnx2x_fastpath *fp = &bp->fp[j];
5012
5013 fp->rx_bd_cons = 0;
5014 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005015 fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005016
Eilon Greensteinca003922009-08-12 22:53:28 -07005017 /* Mark queue as Rx */
5018 fp->is_rx_queue = 1;
5019
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005020 /* "next page" elements initialization */
5021 /* SGE ring */
5022 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
5023 struct eth_rx_sge *sge;
5024
5025 sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
5026 sge->addr_hi =
5027 cpu_to_le32(U64_HI(fp->rx_sge_mapping +
5028 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
5029 sge->addr_lo =
5030 cpu_to_le32(U64_LO(fp->rx_sge_mapping +
5031 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
5032 }
5033
5034 bnx2x_init_sge_ring_bit_mask(fp);
5035
5036 /* RX BD ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005037 for (i = 1; i <= NUM_RX_RINGS; i++) {
5038 struct eth_rx_bd *rx_bd;
5039
5040 rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
5041 rx_bd->addr_hi =
5042 cpu_to_le32(U64_HI(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005043 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005044 rx_bd->addr_lo =
5045 cpu_to_le32(U64_LO(fp->rx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005046 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005047 }
5048
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005049 /* CQ ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005050 for (i = 1; i <= NUM_RCQ_RINGS; i++) {
5051 struct eth_rx_cqe_next_page *nextpg;
5052
5053 nextpg = (struct eth_rx_cqe_next_page *)
5054 &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
5055 nextpg->addr_hi =
5056 cpu_to_le32(U64_HI(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005057 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005058 nextpg->addr_lo =
5059 cpu_to_le32(U64_LO(fp->rx_comp_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005060 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005061 }
5062
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005063 /* Allocate SGEs and initialize the ring elements */
5064 for (i = 0, ring_prod = 0;
5065 i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005066
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005067 if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
5068 BNX2X_ERR("was only able to allocate "
5069 "%d rx sges\n", i);
5070 BNX2X_ERR("disabling TPA for queue[%d]\n", j);
5071 /* Cleanup already allocated elements */
5072 bnx2x_free_rx_sge_range(bp, fp, ring_prod);
Eilon Greenstein32626232008-08-13 15:51:07 -07005073 bnx2x_free_tpa_pool(bp, fp, max_agg_queues);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005074 fp->disable_tpa = 1;
5075 ring_prod = 0;
5076 break;
5077 }
5078 ring_prod = NEXT_SGE_IDX(ring_prod);
5079 }
5080 fp->rx_sge_prod = ring_prod;
5081
5082 /* Allocate BDs and initialize BD ring */
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005083 fp->rx_comp_cons = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005084 cqe_ring_prod = ring_prod = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005085 for (i = 0; i < bp->rx_ring_size; i++) {
5086 if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) {
5087 BNX2X_ERR("was only able to allocate "
Eilon Greensteinde832a52009-02-12 08:36:33 +00005088 "%d rx skbs on queue[%d]\n", i, j);
5089 fp->eth_q_stats.rx_skb_alloc_failed++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005090 break;
5091 }
5092 ring_prod = NEXT_RX_IDX(ring_prod);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005093 cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
Ilpo Järvinen53e5e962008-07-25 21:40:45 -07005094 WARN_ON(ring_prod <= i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005095 }
5096
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005097 fp->rx_bd_prod = ring_prod;
5098 /* must not have more available CQEs than BDs */
5099 fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT),
5100 cqe_ring_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005101 fp->rx_pkt = fp->rx_calls = 0;
5102
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005103 /* Warning!
5104 * this will generate an interrupt (to the TSTORM)
5105 * must only be done after chip is initialized
5106 */
5107 bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod,
5108 fp->rx_sge_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005109 if (j != 0)
5110 continue;
5111
5112 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005113 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005114 U64_LO(fp->rx_comp_mapping));
5115 REG_WR(bp, BAR_USTRORM_INTMEM +
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005116 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005117 U64_HI(fp->rx_comp_mapping));
5118 }
5119}
5120
5121static void bnx2x_init_tx_ring(struct bnx2x *bp)
5122{
5123 int i, j;
5124
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005125 for_each_tx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005126 struct bnx2x_fastpath *fp = &bp->fp[j];
5127
5128 for (i = 1; i <= NUM_TX_RINGS; i++) {
Eilon Greensteinca003922009-08-12 22:53:28 -07005129 struct eth_tx_next_bd *tx_next_bd =
5130 &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005131
Eilon Greensteinca003922009-08-12 22:53:28 -07005132 tx_next_bd->addr_hi =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005133 cpu_to_le32(U64_HI(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005134 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eilon Greensteinca003922009-08-12 22:53:28 -07005135 tx_next_bd->addr_lo =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005136 cpu_to_le32(U64_LO(fp->tx_desc_mapping +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005137 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005138 }
5139
Eilon Greensteinca003922009-08-12 22:53:28 -07005140 fp->tx_db.data.header.header = DOORBELL_HDR_DB_TYPE;
5141 fp->tx_db.data.zero_fill1 = 0;
5142 fp->tx_db.data.prod = 0;
5143
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005144 fp->tx_pkt_prod = 0;
5145 fp->tx_pkt_cons = 0;
5146 fp->tx_bd_prod = 0;
5147 fp->tx_bd_cons = 0;
5148 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
5149 fp->tx_pkt = 0;
5150 }
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00005151
5152 /* clean tx statistics */
5153 for_each_rx_queue(bp, i)
5154 bnx2x_fp(bp, i, tx_pkt) = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005155}
5156
5157static void bnx2x_init_sp_ring(struct bnx2x *bp)
5158{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005159 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005160
5161 spin_lock_init(&bp->spq_lock);
5162
5163 bp->spq_left = MAX_SPQ_PENDING;
5164 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005165 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5166 bp->spq_prod_bd = bp->spq;
5167 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
5168
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005169 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005170 U64_LO(bp->spq_mapping));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005171 REG_WR(bp,
5172 XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005173 U64_HI(bp->spq_mapping));
5174
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005175 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005176 bp->spq_prod_idx);
5177}
5178
5179static void bnx2x_init_context(struct bnx2x *bp)
5180{
5181 int i;
5182
Eilon Greensteinca003922009-08-12 22:53:28 -07005183 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005184 struct eth_context *context = bnx2x_sp(bp, context[i].eth);
5185 struct bnx2x_fastpath *fp = &bp->fp[i];
Eilon Greensteinde832a52009-02-12 08:36:33 +00005186 u8 cl_id = fp->cl_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005187
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005188 context->ustorm_st_context.common.sb_index_numbers =
5189 BNX2X_RX_SB_INDEX_NUM;
Eilon Greenstein0626b892009-02-12 08:38:14 +00005190 context->ustorm_st_context.common.clientId = cl_id;
Eilon Greensteinca003922009-08-12 22:53:28 -07005191 context->ustorm_st_context.common.status_block_id = fp->sb_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005192 context->ustorm_st_context.common.flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00005193 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
5194 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
5195 context->ustorm_st_context.common.statistics_counter_id =
5196 cl_id;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005197 context->ustorm_st_context.common.mc_alignment_log_size =
Eilon Greenstein0f008462009-02-12 08:36:18 +00005198 BNX2X_RX_ALIGN_SHIFT;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005199 context->ustorm_st_context.common.bd_buff_size =
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07005200 bp->rx_buf_size;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005201 context->ustorm_st_context.common.bd_page_base_hi =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005202 U64_HI(fp->rx_desc_mapping);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005203 context->ustorm_st_context.common.bd_page_base_lo =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005204 U64_LO(fp->rx_desc_mapping);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005205 if (!fp->disable_tpa) {
5206 context->ustorm_st_context.common.flags |=
Eilon Greensteinca003922009-08-12 22:53:28 -07005207 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005208 context->ustorm_st_context.common.sge_buff_size =
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005209 (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE,
5210 (u32)0xffff);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005211 context->ustorm_st_context.common.sge_page_base_hi =
5212 U64_HI(fp->rx_sge_mapping);
5213 context->ustorm_st_context.common.sge_page_base_lo =
5214 U64_LO(fp->rx_sge_mapping);
Eilon Greensteinca003922009-08-12 22:53:28 -07005215
5216 context->ustorm_st_context.common.max_sges_for_packet =
5217 SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
5218 context->ustorm_st_context.common.max_sges_for_packet =
5219 ((context->ustorm_st_context.common.
5220 max_sges_for_packet + PAGES_PER_SGE - 1) &
5221 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005222 }
5223
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005224 context->ustorm_ag_context.cdu_usage =
5225 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
5226 CDU_REGION_NUMBER_UCM_AG,
5227 ETH_CONNECTION_TYPE);
5228
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005229 context->xstorm_ag_context.cdu_reserved =
5230 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
5231 CDU_REGION_NUMBER_XCM_AG,
5232 ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005233 }
Eilon Greensteinca003922009-08-12 22:53:28 -07005234
5235 for_each_tx_queue(bp, i) {
5236 struct bnx2x_fastpath *fp = &bp->fp[i];
5237 struct eth_context *context =
5238 bnx2x_sp(bp, context[i - bp->num_rx_queues].eth);
5239
5240 context->cstorm_st_context.sb_index_number =
5241 C_SB_ETH_TX_CQ_INDEX;
5242 context->cstorm_st_context.status_block_id = fp->sb_id;
5243
5244 context->xstorm_st_context.tx_bd_page_base_hi =
5245 U64_HI(fp->tx_desc_mapping);
5246 context->xstorm_st_context.tx_bd_page_base_lo =
5247 U64_LO(fp->tx_desc_mapping);
5248 context->xstorm_st_context.statistics_data = (fp->cl_id |
5249 XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
5250 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005251}
5252
5253static void bnx2x_init_ind_table(struct bnx2x *bp)
5254{
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005255 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005256 int i;
5257
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005258 if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005259 return;
5260
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005261 DP(NETIF_MSG_IFUP,
5262 "Initializing indirection table multi_mode %d\n", bp->multi_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005263 for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005264 REG_WR8(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005265 TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
Eilon Greenstein0626b892009-02-12 08:38:14 +00005266 bp->fp->cl_id + (i % bp->num_rx_queues));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005267}
5268
Eliezer Tamir49d66772008-02-28 11:53:13 -08005269static void bnx2x_set_client_config(struct bnx2x *bp)
5270{
Eliezer Tamir49d66772008-02-28 11:53:13 -08005271 struct tstorm_eth_client_config tstorm_client = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005272 int port = BP_PORT(bp);
5273 int i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08005274
Eilon Greensteine7799c52009-01-14 21:30:27 -08005275 tstorm_client.mtu = bp->dev->mtu;
Eliezer Tamir49d66772008-02-28 11:53:13 -08005276 tstorm_client.config_flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00005277 (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
5278 TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
Eliezer Tamir49d66772008-02-28 11:53:13 -08005279#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08005280 if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
Eliezer Tamir49d66772008-02-28 11:53:13 -08005281 tstorm_client.config_flags |=
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005282 TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
Eliezer Tamir49d66772008-02-28 11:53:13 -08005283 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
5284 }
5285#endif
Eliezer Tamir49d66772008-02-28 11:53:13 -08005286
5287 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00005288 tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
5289
Eliezer Tamir49d66772008-02-28 11:53:13 -08005290 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005291 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
Eliezer Tamir49d66772008-02-28 11:53:13 -08005292 ((u32 *)&tstorm_client)[0]);
5293 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005294 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
Eliezer Tamir49d66772008-02-28 11:53:13 -08005295 ((u32 *)&tstorm_client)[1]);
5296 }
5297
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005298 DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
5299 ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
Eliezer Tamir49d66772008-02-28 11:53:13 -08005300}
5301
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005302static void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5303{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005304 struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005305 int mode = bp->rx_mode;
Michael Chan37b091b2009-10-10 13:46:55 +00005306 int mask = bp->rx_mode_cl_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005307 int func = BP_FUNC(bp);
Eilon Greenstein581ce432009-07-29 00:20:04 +00005308 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005309 int i;
Eilon Greenstein581ce432009-07-29 00:20:04 +00005310 /* All but management unicast packets should pass to the host as well */
5311 u32 llh_mask =
5312 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_BRCST |
5313 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_MLCST |
5314 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_VLAN |
5315 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_NO_VLAN;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005316
Eilon Greenstein3196a882008-08-13 15:58:49 -07005317 DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005318
5319 switch (mode) {
5320 case BNX2X_RX_MODE_NONE: /* no Rx */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005321 tstorm_mac_filter.ucast_drop_all = mask;
5322 tstorm_mac_filter.mcast_drop_all = mask;
5323 tstorm_mac_filter.bcast_drop_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005324 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00005325
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005326 case BNX2X_RX_MODE_NORMAL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005327 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005328 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00005329
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005330 case BNX2X_RX_MODE_ALLMULTI:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005331 tstorm_mac_filter.mcast_accept_all = mask;
5332 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005333 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00005334
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005335 case BNX2X_RX_MODE_PROMISC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005336 tstorm_mac_filter.ucast_accept_all = mask;
5337 tstorm_mac_filter.mcast_accept_all = mask;
5338 tstorm_mac_filter.bcast_accept_all = mask;
Eilon Greenstein581ce432009-07-29 00:20:04 +00005339 /* pass management unicast packets as well */
5340 llh_mask |= NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_UNCST;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005341 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00005342
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005343 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005344 BNX2X_ERR("BAD rx mode (%d)\n", mode);
5345 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005346 }
5347
Eilon Greenstein581ce432009-07-29 00:20:04 +00005348 REG_WR(bp,
5349 (port ? NIG_REG_LLH1_BRB1_DRV_MASK : NIG_REG_LLH0_BRB1_DRV_MASK),
5350 llh_mask);
5351
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005352 for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
5353 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005354 TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005355 ((u32 *)&tstorm_mac_filter)[i]);
5356
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005357/* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005358 ((u32 *)&tstorm_mac_filter)[i]); */
5359 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005360
Eliezer Tamir49d66772008-02-28 11:53:13 -08005361 if (mode != BNX2X_RX_MODE_NONE)
5362 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005363}
5364
Eilon Greenstein471de712008-08-13 15:49:35 -07005365static void bnx2x_init_internal_common(struct bnx2x *bp)
5366{
5367 int i;
5368
5369 /* Zero this manually as its initialization is
5370 currently missing in the initTool */
5371 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5372 REG_WR(bp, BAR_USTRORM_INTMEM +
5373 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5374}
5375
5376static void bnx2x_init_internal_port(struct bnx2x *bp)
5377{
5378 int port = BP_PORT(bp);
5379
Eilon Greensteinca003922009-08-12 22:53:28 -07005380 REG_WR(bp,
5381 BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_U_OFFSET(port), BNX2X_BTR);
5382 REG_WR(bp,
5383 BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_C_OFFSET(port), BNX2X_BTR);
Eilon Greenstein471de712008-08-13 15:49:35 -07005384 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
5385 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
5386}
5387
5388static void bnx2x_init_internal_func(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005389{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005390 struct tstorm_eth_function_common_config tstorm_config = {0};
5391 struct stats_indication_flags stats_flags = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005392 int port = BP_PORT(bp);
5393 int func = BP_FUNC(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00005394 int i, j;
5395 u32 offset;
Eilon Greenstein471de712008-08-13 15:49:35 -07005396 u16 max_agg_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005397
5398 if (is_multi(bp)) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005399 tstorm_config.config_flags = MULTI_FLAGS(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005400 tstorm_config.rss_result_mask = MULTI_MASK;
5401 }
Eilon Greensteinca003922009-08-12 22:53:28 -07005402
5403 /* Enable TPA if needed */
5404 if (bp->flags & TPA_ENABLE_FLAG)
5405 tstorm_config.config_flags |=
5406 TSTORM_ETH_FUNCTION_COMMON_CONFIG_ENABLE_TPA;
5407
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005408 if (IS_E1HMF(bp))
5409 tstorm_config.config_flags |=
5410 TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005411
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005412 tstorm_config.leading_client_id = BP_L_ID(bp);
5413
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005414 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005415 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005416 (*(u32 *)&tstorm_config));
5417
Eliezer Tamirc14423f2008-02-28 11:49:42 -08005418 bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
Michael Chan37b091b2009-10-10 13:46:55 +00005419 bp->rx_mode_cl_mask = (1 << BP_L_ID(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005420 bnx2x_set_storm_rx_mode(bp);
5421
Eilon Greensteinde832a52009-02-12 08:36:33 +00005422 for_each_queue(bp, i) {
5423 u8 cl_id = bp->fp[i].cl_id;
5424
5425 /* reset xstorm per client statistics */
5426 offset = BAR_XSTRORM_INTMEM +
5427 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
5428 for (j = 0;
5429 j < sizeof(struct xstorm_per_client_stats) / 4; j++)
5430 REG_WR(bp, offset + j*4, 0);
5431
5432 /* reset tstorm per client statistics */
5433 offset = BAR_TSTRORM_INTMEM +
5434 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
5435 for (j = 0;
5436 j < sizeof(struct tstorm_per_client_stats) / 4; j++)
5437 REG_WR(bp, offset + j*4, 0);
5438
5439 /* reset ustorm per client statistics */
5440 offset = BAR_USTRORM_INTMEM +
5441 USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
5442 for (j = 0;
5443 j < sizeof(struct ustorm_per_client_stats) / 4; j++)
5444 REG_WR(bp, offset + j*4, 0);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005445 }
5446
5447 /* Init statistics related context */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005448 stats_flags.collect_eth = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005449
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005450 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005451 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005452 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005453 ((u32 *)&stats_flags)[1]);
5454
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005455 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005456 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005457 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005458 ((u32 *)&stats_flags)[1]);
5459
Eilon Greensteinde832a52009-02-12 08:36:33 +00005460 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
5461 ((u32 *)&stats_flags)[0]);
5462 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
5463 ((u32 *)&stats_flags)[1]);
5464
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005465 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005466 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005467 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005468 ((u32 *)&stats_flags)[1]);
5469
Yitchak Gertner66e855f2008-08-13 15:49:05 -07005470 REG_WR(bp, BAR_XSTRORM_INTMEM +
5471 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
5472 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
5473 REG_WR(bp, BAR_XSTRORM_INTMEM +
5474 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
5475 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
5476
5477 REG_WR(bp, BAR_TSTRORM_INTMEM +
5478 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
5479 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
5480 REG_WR(bp, BAR_TSTRORM_INTMEM +
5481 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
5482 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005483
Eilon Greensteinde832a52009-02-12 08:36:33 +00005484 REG_WR(bp, BAR_USTRORM_INTMEM +
5485 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
5486 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
5487 REG_WR(bp, BAR_USTRORM_INTMEM +
5488 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
5489 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
5490
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005491 if (CHIP_IS_E1H(bp)) {
5492 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
5493 IS_E1HMF(bp));
5494 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
5495 IS_E1HMF(bp));
5496 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
5497 IS_E1HMF(bp));
5498 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
5499 IS_E1HMF(bp));
5500
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005501 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
5502 bp->e1hov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005503 }
5504
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08005505 /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
5506 max_agg_size =
5507 min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
5508 SGE_PAGE_SIZE * PAGES_PER_SGE),
5509 (u32)0xffff);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005510 for_each_rx_queue(bp, i) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005511 struct bnx2x_fastpath *fp = &bp->fp[i];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005512
5513 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005514 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005515 U64_LO(fp->rx_comp_mapping));
5516 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005517 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005518 U64_HI(fp->rx_comp_mapping));
5519
Eilon Greensteinca003922009-08-12 22:53:28 -07005520 /* Next page */
5521 REG_WR(bp, BAR_USTRORM_INTMEM +
5522 USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id),
5523 U64_LO(fp->rx_comp_mapping + BCM_PAGE_SIZE));
5524 REG_WR(bp, BAR_USTRORM_INTMEM +
5525 USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id) + 4,
5526 U64_HI(fp->rx_comp_mapping + BCM_PAGE_SIZE));
5527
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005528 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00005529 USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005530 max_agg_size);
5531 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005532
Eilon Greenstein1c063282009-02-12 08:36:43 +00005533 /* dropless flow control */
5534 if (CHIP_IS_E1H(bp)) {
5535 struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
5536
5537 rx_pause.bd_thr_low = 250;
5538 rx_pause.cqe_thr_low = 250;
5539 rx_pause.cos = 1;
5540 rx_pause.sge_thr_low = 0;
5541 rx_pause.bd_thr_high = 350;
5542 rx_pause.cqe_thr_high = 350;
5543 rx_pause.sge_thr_high = 0;
5544
5545 for_each_rx_queue(bp, i) {
5546 struct bnx2x_fastpath *fp = &bp->fp[i];
5547
5548 if (!fp->disable_tpa) {
5549 rx_pause.sge_thr_low = 150;
5550 rx_pause.sge_thr_high = 250;
5551 }
5552
5553
5554 offset = BAR_USTRORM_INTMEM +
5555 USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
5556 fp->cl_id);
5557 for (j = 0;
5558 j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
5559 j++)
5560 REG_WR(bp, offset + j*4,
5561 ((u32 *)&rx_pause)[j]);
5562 }
5563 }
5564
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005565 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
5566
5567 /* Init rate shaping and fairness contexts */
5568 if (IS_E1HMF(bp)) {
5569 int vn;
5570
5571 /* During init there is no active link
5572 Until link is up, set link rate to 10Gbps */
5573 bp->link_vars.line_speed = SPEED_10000;
5574 bnx2x_init_port_minmax(bp);
5575
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07005576 if (!BP_NOMCP(bp))
5577 bp->mf_config =
5578 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005579 bnx2x_calc_vn_weight_sum(bp);
5580
5581 for (vn = VN_0; vn < E1HVN_MAX; vn++)
5582 bnx2x_init_vn_minmax(bp, 2*vn + port);
5583
5584 /* Enable rate shaping and fairness */
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07005585 bp->cmng.flags.cmng_enables |=
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005586 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07005587
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00005588 } else {
5589 /* rate shaping and fairness are disabled */
5590 DP(NETIF_MSG_IFUP,
5591 "single function mode minmax will be disabled\n");
5592 }
5593
5594
5595 /* Store it to internal memory */
5596 if (bp->port.pmf)
5597 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
5598 REG_WR(bp, BAR_XSTRORM_INTMEM +
5599 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
5600 ((u32 *)(&bp->cmng))[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005601}
5602
Eilon Greenstein471de712008-08-13 15:49:35 -07005603static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5604{
5605 switch (load_code) {
5606 case FW_MSG_CODE_DRV_LOAD_COMMON:
5607 bnx2x_init_internal_common(bp);
5608 /* no break */
5609
5610 case FW_MSG_CODE_DRV_LOAD_PORT:
5611 bnx2x_init_internal_port(bp);
5612 /* no break */
5613
5614 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5615 bnx2x_init_internal_func(bp);
5616 break;
5617
5618 default:
5619 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5620 break;
5621 }
5622}
5623
5624static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005625{
5626 int i;
5627
5628 for_each_queue(bp, i) {
5629 struct bnx2x_fastpath *fp = &bp->fp[i];
5630
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005631 fp->bp = bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005632 fp->state = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005633 fp->index = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005634 fp->cl_id = BP_L_ID(bp) + i;
Michael Chan37b091b2009-10-10 13:46:55 +00005635#ifdef BCM_CNIC
5636 fp->sb_id = fp->cl_id + 1;
5637#else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005638 fp->sb_id = fp->cl_id;
Michael Chan37b091b2009-10-10 13:46:55 +00005639#endif
Eilon Greensteinca003922009-08-12 22:53:28 -07005640 /* Suitable Rx and Tx SBs are served by the same client */
5641 if (i >= bp->num_rx_queues)
5642 fp->cl_id -= bp->num_rx_queues;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005643 DP(NETIF_MSG_IFUP,
Eilon Greensteinf5372252009-02-12 08:38:30 +00005644 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
5645 i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005646 bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
Eilon Greenstein0626b892009-02-12 08:38:14 +00005647 fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005648 bnx2x_update_fpsb_idx(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005649 }
5650
Eilon Greenstein16119782009-03-02 07:59:27 +00005651 /* ensure status block indices were read */
5652 rmb();
5653
5654
Eilon Greenstein5c862842008-08-13 15:51:48 -07005655 bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
5656 DEF_SB_ID);
5657 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005658 bnx2x_update_coalesce(bp);
5659 bnx2x_init_rx_rings(bp);
5660 bnx2x_init_tx_ring(bp);
5661 bnx2x_init_sp_ring(bp);
5662 bnx2x_init_context(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07005663 bnx2x_init_internal(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005664 bnx2x_init_ind_table(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005665 bnx2x_stats_init(bp);
5666
5667 /* At this point, we are ready for interrupts */
5668 atomic_set(&bp->intr_sem, 0);
5669
5670 /* flush all before enabling interrupts */
5671 mb();
5672 mmiowb();
5673
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08005674 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00005675
5676 /* Check for SPIO5 */
5677 bnx2x_attn_int_deasserted0(bp,
5678 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5679 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005680}
5681
5682/* end of nic init */
5683
5684/*
5685 * gzip service functions
5686 */
5687
5688static int bnx2x_gunzip_init(struct bnx2x *bp)
5689{
5690 bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE,
5691 &bp->gunzip_mapping);
5692 if (bp->gunzip_buf == NULL)
5693 goto gunzip_nomem1;
5694
5695 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5696 if (bp->strm == NULL)
5697 goto gunzip_nomem2;
5698
5699 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5700 GFP_KERNEL);
5701 if (bp->strm->workspace == NULL)
5702 goto gunzip_nomem3;
5703
5704 return 0;
5705
5706gunzip_nomem3:
5707 kfree(bp->strm);
5708 bp->strm = NULL;
5709
5710gunzip_nomem2:
5711 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5712 bp->gunzip_mapping);
5713 bp->gunzip_buf = NULL;
5714
5715gunzip_nomem1:
5716 printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for"
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005717 " un-compression\n", bp->dev->name);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005718 return -ENOMEM;
5719}
5720
5721static void bnx2x_gunzip_end(struct bnx2x *bp)
5722{
5723 kfree(bp->strm->workspace);
5724
5725 kfree(bp->strm);
5726 bp->strm = NULL;
5727
5728 if (bp->gunzip_buf) {
5729 pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
5730 bp->gunzip_mapping);
5731 bp->gunzip_buf = NULL;
5732 }
5733}
5734
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005735static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005736{
5737 int n, rc;
5738
5739 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005740 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5741 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005742 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005743 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005744
5745 n = 10;
5746
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005747#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005748
5749 if (zbuf[3] & FNAME)
5750 while ((zbuf[n++] != 0) && (n < len));
5751
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005752 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005753 bp->strm->avail_in = len - n;
5754 bp->strm->next_out = bp->gunzip_buf;
5755 bp->strm->avail_out = FW_BUF_SIZE;
5756
5757 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5758 if (rc != Z_OK)
5759 return rc;
5760
5761 rc = zlib_inflate(bp->strm, Z_FINISH);
5762 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5763 printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
5764 bp->dev->name, bp->strm->msg);
5765
5766 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5767 if (bp->gunzip_outlen & 0x3)
5768 printk(KERN_ERR PFX "%s: Firmware decompression error:"
5769 " gunzip_outlen (%d) not aligned\n",
5770 bp->dev->name, bp->gunzip_outlen);
5771 bp->gunzip_outlen >>= 2;
5772
5773 zlib_inflateEnd(bp->strm);
5774
5775 if (rc == Z_STREAM_END)
5776 return 0;
5777
5778 return rc;
5779}
5780
5781/* nic load/unload */
5782
5783/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005784 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005785 */
5786
5787/* send a NIG loopback debug packet */
5788static void bnx2x_lb_pckt(struct bnx2x *bp)
5789{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005790 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005791
5792 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005793 wb_write[0] = 0x55555555;
5794 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005795 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005796 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005797
5798 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005799 wb_write[0] = 0x09000000;
5800 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005801 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005802 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005803}
5804
5805/* some of the internal memories
5806 * are not directly readable from the driver
5807 * to test them we send debug packets
5808 */
5809static int bnx2x_int_mem_test(struct bnx2x *bp)
5810{
5811 int factor;
5812 int count, i;
5813 u32 val = 0;
5814
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005815 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005816 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005817 else if (CHIP_REV_IS_EMUL(bp))
5818 factor = 200;
5819 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005820 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005821
5822 DP(NETIF_MSG_HW, "start part1\n");
5823
5824 /* Disable inputs of parser neighbor blocks */
5825 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5826 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5827 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005828 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005829
5830 /* Write 0 to parser credits for CFC search request */
5831 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5832
5833 /* send Ethernet packet */
5834 bnx2x_lb_pckt(bp);
5835
5836 /* TODO do i reset NIG statistic? */
5837 /* Wait until NIG register shows 1 packet of size 0x10 */
5838 count = 1000 * factor;
5839 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005840
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005841 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5842 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005843 if (val == 0x10)
5844 break;
5845
5846 msleep(10);
5847 count--;
5848 }
5849 if (val != 0x10) {
5850 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5851 return -1;
5852 }
5853
5854 /* Wait until PRS register shows 1 packet */
5855 count = 1000 * factor;
5856 while (count) {
5857 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005858 if (val == 1)
5859 break;
5860
5861 msleep(10);
5862 count--;
5863 }
5864 if (val != 0x1) {
5865 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5866 return -2;
5867 }
5868
5869 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005870 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005871 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005872 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005873 msleep(50);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005874 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
5875 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005876
5877 DP(NETIF_MSG_HW, "part2\n");
5878
5879 /* Disable inputs of parser neighbor blocks */
5880 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5881 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5882 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005883 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005884
5885 /* Write 0 to parser credits for CFC search request */
5886 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5887
5888 /* send 10 Ethernet packets */
5889 for (i = 0; i < 10; i++)
5890 bnx2x_lb_pckt(bp);
5891
5892 /* Wait until NIG register shows 10 + 1
5893 packets of size 11*0x10 = 0xb0 */
5894 count = 1000 * factor;
5895 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005896
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005897 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5898 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005899 if (val == 0xb0)
5900 break;
5901
5902 msleep(10);
5903 count--;
5904 }
5905 if (val != 0xb0) {
5906 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5907 return -3;
5908 }
5909
5910 /* Wait until PRS register shows 2 packets */
5911 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5912 if (val != 2)
5913 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5914
5915 /* Write 1 to parser credits for CFC search request */
5916 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5917
5918 /* Wait until PRS register shows 3 packets */
5919 msleep(10 * factor);
5920 /* Wait until NIG register shows 1 packet of size 0x10 */
5921 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5922 if (val != 3)
5923 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5924
5925 /* clear NIG EOP FIFO */
5926 for (i = 0; i < 11; i++)
5927 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5928 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5929 if (val != 1) {
5930 BNX2X_ERR("clear of NIG failed\n");
5931 return -4;
5932 }
5933
5934 /* Reset and init BRB, PRS, NIG */
5935 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5936 msleep(50);
5937 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5938 msleep(50);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005939 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
5940 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00005941#ifndef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005942 /* set NIC mode */
5943 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5944#endif
5945
5946 /* Enable inputs of parser neighbor blocks */
5947 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5948 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5949 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005950 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005951
5952 DP(NETIF_MSG_HW, "done\n");
5953
5954 return 0; /* OK */
5955}
5956
5957static void enable_blocks_attention(struct bnx2x *bp)
5958{
5959 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5960 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5961 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5962 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5963 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5964 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5965 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5966 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5967 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005968/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5969/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005970 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5971 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5972 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005973/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5974/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005975 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5976 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5977 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5978 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005979/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5980/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5981 if (CHIP_REV_IS_FPGA(bp))
5982 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5983 else
5984 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005985 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5986 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5987 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005988/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5989/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005990 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5991 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005992/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5993 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005994}
5995
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005996
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005997static void bnx2x_reset_common(struct bnx2x *bp)
5998{
5999 /* reset_common */
6000 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6001 0xd3ffff7f);
6002 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
6003}
6004
Eilon Greenstein573f2032009-08-12 08:24:14 +00006005static void bnx2x_init_pxp(struct bnx2x *bp)
6006{
6007 u16 devctl;
6008 int r_order, w_order;
6009
6010 pci_read_config_word(bp->pdev,
6011 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
6012 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6013 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6014 if (bp->mrrs == -1)
6015 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6016 else {
6017 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6018 r_order = bp->mrrs;
6019 }
6020
6021 bnx2x_init_pxp_arb(bp, r_order, w_order);
6022}
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006023
6024static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6025{
6026 u32 val;
6027 u8 port;
6028 u8 is_required = 0;
6029
6030 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6031 SHARED_HW_CFG_FAN_FAILURE_MASK;
6032
6033 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6034 is_required = 1;
6035
6036 /*
6037 * The fan failure mechanism is usually related to the PHY type since
6038 * the power consumption of the board is affected by the PHY. Currently,
6039 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6040 */
6041 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6042 for (port = PORT_0; port < PORT_MAX; port++) {
6043 u32 phy_type =
6044 SHMEM_RD(bp, dev_info.port_hw_config[port].
6045 external_phy_config) &
6046 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
6047 is_required |=
6048 ((phy_type ==
6049 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) ||
6050 (phy_type ==
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006051 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
6052 (phy_type ==
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006053 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481));
6054 }
6055
6056 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6057
6058 if (is_required == 0)
6059 return;
6060
6061 /* Fan failure is indicated by SPIO 5 */
6062 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
6063 MISC_REGISTERS_SPIO_INPUT_HI_Z);
6064
6065 /* set to active low mode */
6066 val = REG_RD(bp, MISC_REG_SPIO_INT);
6067 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
6068 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
6069 REG_WR(bp, MISC_REG_SPIO_INT, val);
6070
6071 /* enable interrupt to signal the IGU */
6072 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6073 val |= (1 << MISC_REGISTERS_SPIO_5);
6074 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6075}
6076
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006077static int bnx2x_init_common(struct bnx2x *bp)
6078{
6079 u32 val, i;
Michael Chan37b091b2009-10-10 13:46:55 +00006080#ifdef BCM_CNIC
6081 u32 wb_write[2];
6082#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006083
6084 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
6085
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006086 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006087 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
6088 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
6089
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006090 bnx2x_init_block(bp, MISC_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006091 if (CHIP_IS_E1H(bp))
6092 REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
6093
6094 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
6095 msleep(30);
6096 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
6097
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006098 bnx2x_init_block(bp, PXP_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006099 if (CHIP_IS_E1(bp)) {
6100 /* enable HW interrupt from PXP on USDM overflow
6101 bit 16 on INT_MASK_0 */
6102 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006103 }
6104
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006105 bnx2x_init_block(bp, PXP2_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006106 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006107
6108#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006109 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6110 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6111 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6112 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6113 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006114 /* make sure this value is 0 */
6115 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006116
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006117/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6118 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6119 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6120 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6121 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006122#endif
6123
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006124 REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
Michael Chan37b091b2009-10-10 13:46:55 +00006125#ifdef BCM_CNIC
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006126 REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
6127 REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
6128 REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006129#endif
6130
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006131 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6132 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006133
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006134 /* let the HW do it's magic ... */
6135 msleep(100);
6136 /* finish PXP init */
6137 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6138 if (val != 1) {
6139 BNX2X_ERR("PXP2 CFG failed\n");
6140 return -EBUSY;
6141 }
6142 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6143 if (val != 1) {
6144 BNX2X_ERR("PXP2 RD_INIT failed\n");
6145 return -EBUSY;
6146 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006147
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006148 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6149 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006150
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006151 bnx2x_init_block(bp, DMAE_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006152
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006153 /* clean the DMAE memory */
6154 bp->dmae_ready = 1;
6155 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006156
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006157 bnx2x_init_block(bp, TCM_BLOCK, COMMON_STAGE);
6158 bnx2x_init_block(bp, UCM_BLOCK, COMMON_STAGE);
6159 bnx2x_init_block(bp, CCM_BLOCK, COMMON_STAGE);
6160 bnx2x_init_block(bp, XCM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006161
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006162 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6163 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6164 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6165 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6166
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006167 bnx2x_init_block(bp, QM_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00006168
6169#ifdef BCM_CNIC
6170 wb_write[0] = 0;
6171 wb_write[1] = 0;
6172 for (i = 0; i < 64; i++) {
6173 REG_WR(bp, QM_REG_BASEADDR + i*4, 1024 * 4 * (i%16));
6174 bnx2x_init_ind_wr(bp, QM_REG_PTRTBL + i*8, wb_write, 2);
6175
6176 if (CHIP_IS_E1H(bp)) {
6177 REG_WR(bp, QM_REG_BASEADDR_EXT_A + i*4, 1024*4*(i%16));
6178 bnx2x_init_ind_wr(bp, QM_REG_PTRTBL_EXT_A + i*8,
6179 wb_write, 2);
6180 }
6181 }
6182#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006183 /* soft reset pulse */
6184 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6185 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006186
Michael Chan37b091b2009-10-10 13:46:55 +00006187#ifdef BCM_CNIC
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006188 bnx2x_init_block(bp, TIMERS_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006189#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006190
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006191 bnx2x_init_block(bp, DQ_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006192 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
6193 if (!CHIP_REV_IS_SLOW(bp)) {
6194 /* enable hw interrupt from doorbell Q */
6195 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6196 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006197
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006198 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
6199 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08006200 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Michael Chan37b091b2009-10-10 13:46:55 +00006201#ifndef BCM_CNIC
Eilon Greenstein3196a882008-08-13 15:58:49 -07006202 /* set NIC mode */
6203 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Michael Chan37b091b2009-10-10 13:46:55 +00006204#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006205 if (CHIP_IS_E1H(bp))
6206 REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006207
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006208 bnx2x_init_block(bp, TSDM_BLOCK, COMMON_STAGE);
6209 bnx2x_init_block(bp, CSDM_BLOCK, COMMON_STAGE);
6210 bnx2x_init_block(bp, USDM_BLOCK, COMMON_STAGE);
6211 bnx2x_init_block(bp, XSDM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006212
Eilon Greensteinca003922009-08-12 22:53:28 -07006213 bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
6214 bnx2x_init_fill(bp, USEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
6215 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
6216 bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006217
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006218 bnx2x_init_block(bp, TSEM_BLOCK, COMMON_STAGE);
6219 bnx2x_init_block(bp, USEM_BLOCK, COMMON_STAGE);
6220 bnx2x_init_block(bp, CSEM_BLOCK, COMMON_STAGE);
6221 bnx2x_init_block(bp, XSEM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006222
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006223 /* sync semi rtc */
6224 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6225 0x80000000);
6226 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6227 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006228
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006229 bnx2x_init_block(bp, UPB_BLOCK, COMMON_STAGE);
6230 bnx2x_init_block(bp, XPB_BLOCK, COMMON_STAGE);
6231 bnx2x_init_block(bp, PBF_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006232
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006233 REG_WR(bp, SRC_REG_SOFT_RST, 1);
6234 for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) {
6235 REG_WR(bp, i, 0xc0cac01a);
6236 /* TODO: replace with something meaningful */
6237 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006238 bnx2x_init_block(bp, SRCH_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00006239#ifdef BCM_CNIC
6240 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6241 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6242 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6243 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6244 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6245 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6246 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6247 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6248 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6249 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6250#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006251 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006252
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006253 if (sizeof(union cdu_context) != 1024)
6254 /* we currently assume that a context is 1024 bytes */
6255 printk(KERN_ALERT PFX "please adjust the size of"
6256 " cdu_context(%ld)\n", (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006257
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006258 bnx2x_init_block(bp, CDU_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006259 val = (4 << 24) + (0 << 12) + 1024;
6260 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006261
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006262 bnx2x_init_block(bp, CFC_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006263 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006264 /* enable context validation interrupt from CFC */
6265 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6266
6267 /* set the thresholds to prevent CFC/CDU race */
6268 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006269
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006270 bnx2x_init_block(bp, HC_BLOCK, COMMON_STAGE);
6271 bnx2x_init_block(bp, MISC_AEU_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006272
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006273 bnx2x_init_block(bp, PXPCS_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006274 /* Reset PCIE errors for debug */
6275 REG_WR(bp, 0x2814, 0xffffffff);
6276 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006277
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006278 bnx2x_init_block(bp, EMAC0_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006279 bnx2x_init_block(bp, EMAC1_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006280 bnx2x_init_block(bp, DBU_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006281 bnx2x_init_block(bp, DBG_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006282
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006283 bnx2x_init_block(bp, NIG_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006284 if (CHIP_IS_E1H(bp)) {
6285 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
6286 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
6287 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006288
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006289 if (CHIP_REV_IS_SLOW(bp))
6290 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006291
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006292 /* finish CFC init */
6293 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6294 if (val != 1) {
6295 BNX2X_ERR("CFC LL_INIT failed\n");
6296 return -EBUSY;
6297 }
6298 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6299 if (val != 1) {
6300 BNX2X_ERR("CFC AC_INIT failed\n");
6301 return -EBUSY;
6302 }
6303 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6304 if (val != 1) {
6305 BNX2X_ERR("CFC CAM_INIT failed\n");
6306 return -EBUSY;
6307 }
6308 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006309
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006310 /* read NIG statistic
6311 to see if this is our first up since powerup */
6312 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6313 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006314
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006315 /* do internal memory self test */
6316 if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
6317 BNX2X_ERR("internal mem self test failed\n");
6318 return -EBUSY;
6319 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006320
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00006321 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein46c6a672009-02-12 08:36:58 +00006322 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
6323 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
6324 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006325 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eilon Greenstein46c6a672009-02-12 08:36:58 +00006326 bp->port.need_hw_lock = 1;
6327 break;
6328
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006329 default:
6330 break;
6331 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08006332
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006333 bnx2x_setup_fan_failure_detection(bp);
6334
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006335 /* clear PXP2 attentions */
6336 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006337
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006338 enable_blocks_attention(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006339
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006340 if (!BP_NOMCP(bp)) {
6341 bnx2x_acquire_phy_lock(bp);
6342 bnx2x_common_init_phy(bp, bp->common.shmem_base);
6343 bnx2x_release_phy_lock(bp);
6344 } else
6345 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6346
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006347 return 0;
6348}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006349
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006350static int bnx2x_init_port(struct bnx2x *bp)
6351{
6352 int port = BP_PORT(bp);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006353 int init_stage = port ? PORT1_STAGE : PORT0_STAGE;
Eilon Greenstein1c063282009-02-12 08:36:43 +00006354 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006355 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006356
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006357 DP(BNX2X_MSG_MCP, "starting port init port %x\n", port);
6358
6359 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006360
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006361 bnx2x_init_block(bp, PXP_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006362 bnx2x_init_block(bp, PXP2_BLOCK, init_stage);
Eilon Greensteinca003922009-08-12 22:53:28 -07006363
6364 bnx2x_init_block(bp, TCM_BLOCK, init_stage);
6365 bnx2x_init_block(bp, UCM_BLOCK, init_stage);
6366 bnx2x_init_block(bp, CCM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006367 bnx2x_init_block(bp, XCM_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006368
Michael Chan37b091b2009-10-10 13:46:55 +00006369#ifdef BCM_CNIC
6370 REG_WR(bp, QM_REG_CONNNUM_0 + port*4, 1024/16 - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006371
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006372 bnx2x_init_block(bp, TIMERS_BLOCK, init_stage);
Michael Chan37b091b2009-10-10 13:46:55 +00006373 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6374 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006375#endif
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006376 bnx2x_init_block(bp, DQ_BLOCK, init_stage);
Eilon Greenstein1c063282009-02-12 08:36:43 +00006377
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006378 bnx2x_init_block(bp, BRB1_BLOCK, init_stage);
Eilon Greenstein1c063282009-02-12 08:36:43 +00006379 if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
6380 /* no pause for emulation and FPGA */
6381 low = 0;
6382 high = 513;
6383 } else {
6384 if (IS_E1HMF(bp))
6385 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6386 else if (bp->dev->mtu > 4096) {
6387 if (bp->flags & ONE_PORT_FLAG)
6388 low = 160;
6389 else {
6390 val = bp->dev->mtu;
6391 /* (24*1024 + val*4)/256 */
6392 low = 96 + (val/64) + ((val % 64) ? 1 : 0);
6393 }
6394 } else
6395 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6396 high = low + 56; /* 14*1024/256 */
6397 }
6398 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6399 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6400
6401
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006402 bnx2x_init_block(bp, PRS_BLOCK, init_stage);
Eilon Greensteinca003922009-08-12 22:53:28 -07006403
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006404 bnx2x_init_block(bp, TSDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006405 bnx2x_init_block(bp, CSDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006406 bnx2x_init_block(bp, USDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006407 bnx2x_init_block(bp, XSDM_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006408
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006409 bnx2x_init_block(bp, TSEM_BLOCK, init_stage);
6410 bnx2x_init_block(bp, USEM_BLOCK, init_stage);
6411 bnx2x_init_block(bp, CSEM_BLOCK, init_stage);
6412 bnx2x_init_block(bp, XSEM_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006413
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006414 bnx2x_init_block(bp, UPB_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006415 bnx2x_init_block(bp, XPB_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006416
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006417 bnx2x_init_block(bp, PBF_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006418
6419 /* configure PBF to work without PAUSE mtu 9000 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006420 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006421
6422 /* update threshold */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006423 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006424 /* update init credit */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006425 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006426
6427 /* probe changes */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006428 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006429 msleep(5);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006430 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006431
Michael Chan37b091b2009-10-10 13:46:55 +00006432#ifdef BCM_CNIC
6433 bnx2x_init_block(bp, SRCH_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006434#endif
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006435 bnx2x_init_block(bp, CDU_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006436 bnx2x_init_block(bp, CFC_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006437
6438 if (CHIP_IS_E1(bp)) {
6439 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6440 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6441 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006442 bnx2x_init_block(bp, HC_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006443
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006444 bnx2x_init_block(bp, MISC_AEU_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006445 /* init aeu_mask_attn_func_0/1:
6446 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6447 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6448 * bits 4-7 are used for "per vn group attention" */
6449 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
6450 (IS_E1HMF(bp) ? 0xF7 : 0x7));
6451
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006452 bnx2x_init_block(bp, PXPCS_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006453 bnx2x_init_block(bp, EMAC0_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006454 bnx2x_init_block(bp, EMAC1_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006455 bnx2x_init_block(bp, DBU_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006456 bnx2x_init_block(bp, DBG_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006457
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006458 bnx2x_init_block(bp, NIG_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006459
6460 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6461
6462 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006463 /* 0x2 disable e1hov, 0x1 enable */
6464 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6465 (IS_E1HMF(bp) ? 0x1 : 0x2));
6466
Eilon Greenstein1c063282009-02-12 08:36:43 +00006467 {
6468 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6469 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6470 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6471 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006472 }
6473
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006474 bnx2x_init_block(bp, MCP_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006475 bnx2x_init_block(bp, DMAE_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006476
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00006477 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00006478 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
6479 {
6480 u32 swap_val, swap_override, aeu_gpio_mask, offset;
6481
6482 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
6483 MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
6484
6485 /* The GPIO should be swapped if the swap register is
6486 set and active */
6487 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
6488 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
6489
6490 /* Select function upon port-swap configuration */
6491 if (port == 0) {
6492 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
6493 aeu_gpio_mask = (swap_val && swap_override) ?
6494 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
6495 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
6496 } else {
6497 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
6498 aeu_gpio_mask = (swap_val && swap_override) ?
6499 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
6500 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
6501 }
6502 val = REG_RD(bp, offset);
6503 /* add GPIO3 to group */
6504 val |= aeu_gpio_mask;
6505 REG_WR(bp, offset, val);
6506 }
6507 break;
6508
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00006509 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006510 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eliezer Tamirf1410642008-02-28 11:51:50 -08006511 /* add SPIO 5 to group 0 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006512 {
6513 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6514 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6515 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006516 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006517 REG_WR(bp, reg_addr, val);
6518 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08006519 break;
6520
6521 default:
6522 break;
6523 }
6524
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07006525 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006526
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006527 return 0;
6528}
6529
6530#define ILT_PER_FUNC (768/2)
6531#define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
6532/* the phys address is shifted right 12 bits and has an added
6533 1=valid bit added to the 53rd bit
6534 then since this is a wide register(TM)
6535 we split it into two 32 bit writes
6536 */
6537#define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
6538#define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
6539#define PXP_ONE_ILT(x) (((x) << 10) | x)
6540#define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
6541
Michael Chan37b091b2009-10-10 13:46:55 +00006542#ifdef BCM_CNIC
6543#define CNIC_ILT_LINES 127
6544#define CNIC_CTX_PER_ILT 16
6545#else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006546#define CNIC_ILT_LINES 0
Michael Chan37b091b2009-10-10 13:46:55 +00006547#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006548
6549static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6550{
6551 int reg;
6552
6553 if (CHIP_IS_E1H(bp))
6554 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6555 else /* E1 */
6556 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6557
6558 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6559}
6560
6561static int bnx2x_init_func(struct bnx2x *bp)
6562{
6563 int port = BP_PORT(bp);
6564 int func = BP_FUNC(bp);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006565 u32 addr, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006566 int i;
6567
6568 DP(BNX2X_MSG_MCP, "starting func init func %x\n", func);
6569
Eilon Greenstein8badd272009-02-12 08:36:15 +00006570 /* set MSI reconfigure capability */
6571 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6572 val = REG_RD(bp, addr);
6573 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6574 REG_WR(bp, addr, val);
6575
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006576 i = FUNC_ILT_BASE(func);
6577
6578 bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
6579 if (CHIP_IS_E1H(bp)) {
6580 REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
6581 REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
6582 } else /* E1 */
6583 REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
6584 PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
6585
Michael Chan37b091b2009-10-10 13:46:55 +00006586#ifdef BCM_CNIC
6587 i += 1 + CNIC_ILT_LINES;
6588 bnx2x_ilt_wr(bp, i, bp->timers_mapping);
6589 if (CHIP_IS_E1(bp))
6590 REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
6591 else {
6592 REG_WR(bp, PXP2_REG_RQ_TM_FIRST_ILT, i);
6593 REG_WR(bp, PXP2_REG_RQ_TM_LAST_ILT, i);
6594 }
6595
6596 i++;
6597 bnx2x_ilt_wr(bp, i, bp->qm_mapping);
6598 if (CHIP_IS_E1(bp))
6599 REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
6600 else {
6601 REG_WR(bp, PXP2_REG_RQ_QM_FIRST_ILT, i);
6602 REG_WR(bp, PXP2_REG_RQ_QM_LAST_ILT, i);
6603 }
6604
6605 i++;
6606 bnx2x_ilt_wr(bp, i, bp->t1_mapping);
6607 if (CHIP_IS_E1(bp))
6608 REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
6609 else {
6610 REG_WR(bp, PXP2_REG_RQ_SRC_FIRST_ILT, i);
6611 REG_WR(bp, PXP2_REG_RQ_SRC_LAST_ILT, i);
6612 }
6613
6614 /* tell the searcher where the T2 table is */
6615 REG_WR(bp, SRC_REG_COUNTFREE0 + port*4, 16*1024/64);
6616
6617 bnx2x_wb_wr(bp, SRC_REG_FIRSTFREE0 + port*16,
6618 U64_LO(bp->t2_mapping), U64_HI(bp->t2_mapping));
6619
6620 bnx2x_wb_wr(bp, SRC_REG_LASTFREE0 + port*16,
6621 U64_LO((u64)bp->t2_mapping + 16*1024 - 64),
6622 U64_HI((u64)bp->t2_mapping + 16*1024 - 64));
6623
6624 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, 10);
6625#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006626
6627 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein573f2032009-08-12 08:24:14 +00006628 bnx2x_init_block(bp, MISC_BLOCK, FUNC0_STAGE + func);
6629 bnx2x_init_block(bp, TCM_BLOCK, FUNC0_STAGE + func);
6630 bnx2x_init_block(bp, UCM_BLOCK, FUNC0_STAGE + func);
6631 bnx2x_init_block(bp, CCM_BLOCK, FUNC0_STAGE + func);
6632 bnx2x_init_block(bp, XCM_BLOCK, FUNC0_STAGE + func);
6633 bnx2x_init_block(bp, TSEM_BLOCK, FUNC0_STAGE + func);
6634 bnx2x_init_block(bp, USEM_BLOCK, FUNC0_STAGE + func);
6635 bnx2x_init_block(bp, CSEM_BLOCK, FUNC0_STAGE + func);
6636 bnx2x_init_block(bp, XSEM_BLOCK, FUNC0_STAGE + func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006637
6638 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6639 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
6640 }
6641
6642 /* HC init per function */
6643 if (CHIP_IS_E1H(bp)) {
6644 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6645
6646 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6647 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6648 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006649 bnx2x_init_block(bp, HC_BLOCK, FUNC0_STAGE + func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006650
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006651 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006652 REG_WR(bp, 0x2114, 0xffffffff);
6653 REG_WR(bp, 0x2120, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006654
6655 return 0;
6656}
6657
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006658static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
6659{
6660 int i, rc = 0;
6661
6662 DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
6663 BP_FUNC(bp), load_code);
6664
6665 bp->dmae_ready = 0;
6666 mutex_init(&bp->dmae_mutex);
Eilon Greenstein54016b22009-08-12 08:23:48 +00006667 rc = bnx2x_gunzip_init(bp);
6668 if (rc)
6669 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006670
6671 switch (load_code) {
6672 case FW_MSG_CODE_DRV_LOAD_COMMON:
6673 rc = bnx2x_init_common(bp);
6674 if (rc)
6675 goto init_hw_err;
6676 /* no break */
6677
6678 case FW_MSG_CODE_DRV_LOAD_PORT:
6679 bp->dmae_ready = 1;
6680 rc = bnx2x_init_port(bp);
6681 if (rc)
6682 goto init_hw_err;
6683 /* no break */
6684
6685 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
6686 bp->dmae_ready = 1;
6687 rc = bnx2x_init_func(bp);
6688 if (rc)
6689 goto init_hw_err;
6690 break;
6691
6692 default:
6693 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6694 break;
6695 }
6696
6697 if (!BP_NOMCP(bp)) {
6698 int func = BP_FUNC(bp);
6699
6700 bp->fw_drv_pulse_wr_seq =
6701 (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
6702 DRV_PULSE_SEQ_MASK);
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00006703 DP(BNX2X_MSG_MCP, "drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
6704 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006705
6706 /* this needs to be done before gunzip end */
6707 bnx2x_zero_def_sb(bp);
6708 for_each_queue(bp, i)
6709 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
Michael Chan37b091b2009-10-10 13:46:55 +00006710#ifdef BCM_CNIC
6711 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
6712#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006713
6714init_hw_err:
6715 bnx2x_gunzip_end(bp);
6716
6717 return rc;
6718}
6719
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006720static void bnx2x_free_mem(struct bnx2x *bp)
6721{
6722
6723#define BNX2X_PCI_FREE(x, y, size) \
6724 do { \
6725 if (x) { \
6726 pci_free_consistent(bp->pdev, size, x, y); \
6727 x = NULL; \
6728 y = 0; \
6729 } \
6730 } while (0)
6731
6732#define BNX2X_FREE(x) \
6733 do { \
6734 if (x) { \
6735 vfree(x); \
6736 x = NULL; \
6737 } \
6738 } while (0)
6739
6740 int i;
6741
6742 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006743 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006744 for_each_queue(bp, i) {
6745
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006746 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006747 BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
6748 bnx2x_fp(bp, i, status_blk_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006749 sizeof(struct host_status_block));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006750 }
6751 /* Rx */
6752 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006753
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006754 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006755 BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
6756 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
6757 bnx2x_fp(bp, i, rx_desc_mapping),
6758 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6759
6760 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
6761 bnx2x_fp(bp, i, rx_comp_mapping),
6762 sizeof(struct eth_fast_path_rx_cqe) *
6763 NUM_RCQ_BD);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006764
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006765 /* SGE ring */
Eilon Greenstein32626232008-08-13 15:51:07 -07006766 BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006767 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
6768 bnx2x_fp(bp, i, rx_sge_mapping),
6769 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
6770 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006771 /* Tx */
6772 for_each_tx_queue(bp, i) {
6773
6774 /* fastpath tx rings: tx_buf tx_desc */
6775 BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
6776 BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
6777 bnx2x_fp(bp, i, tx_desc_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006778 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006779 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006780 /* end of fastpath */
6781
6782 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006783 sizeof(struct host_def_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006784
6785 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006786 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006787
Michael Chan37b091b2009-10-10 13:46:55 +00006788#ifdef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006789 BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
6790 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
6791 BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
6792 BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
Michael Chan37b091b2009-10-10 13:46:55 +00006793 BNX2X_PCI_FREE(bp->cnic_sb, bp->cnic_sb_mapping,
6794 sizeof(struct host_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006795#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006796 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006797
6798#undef BNX2X_PCI_FREE
6799#undef BNX2X_KFREE
6800}
6801
6802static int bnx2x_alloc_mem(struct bnx2x *bp)
6803{
6804
6805#define BNX2X_PCI_ALLOC(x, y, size) \
6806 do { \
6807 x = pci_alloc_consistent(bp->pdev, size, y); \
6808 if (x == NULL) \
6809 goto alloc_mem_err; \
6810 memset(x, 0, size); \
6811 } while (0)
6812
6813#define BNX2X_ALLOC(x, size) \
6814 do { \
6815 x = vmalloc(size); \
6816 if (x == NULL) \
6817 goto alloc_mem_err; \
6818 memset(x, 0, size); \
6819 } while (0)
6820
6821 int i;
6822
6823 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006824 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006825 for_each_queue(bp, i) {
6826 bnx2x_fp(bp, i, bp) = bp;
6827
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006828 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006829 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
6830 &bnx2x_fp(bp, i, status_blk_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006831 sizeof(struct host_status_block));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006832 }
6833 /* Rx */
6834 for_each_rx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006835
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006836 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006837 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
6838 sizeof(struct sw_rx_bd) * NUM_RX_BD);
6839 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
6840 &bnx2x_fp(bp, i, rx_desc_mapping),
6841 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6842
6843 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
6844 &bnx2x_fp(bp, i, rx_comp_mapping),
6845 sizeof(struct eth_fast_path_rx_cqe) *
6846 NUM_RCQ_BD);
6847
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006848 /* SGE ring */
6849 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
6850 sizeof(struct sw_rx_page) * NUM_RX_SGE);
6851 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
6852 &bnx2x_fp(bp, i, rx_sge_mapping),
6853 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006854 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006855 /* Tx */
6856 for_each_tx_queue(bp, i) {
6857
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006858 /* fastpath tx rings: tx_buf tx_desc */
6859 BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
6860 sizeof(struct sw_tx_bd) * NUM_TX_BD);
6861 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
6862 &bnx2x_fp(bp, i, tx_desc_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006863 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006864 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006865 /* end of fastpath */
6866
6867 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6868 sizeof(struct host_def_status_block));
6869
6870 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6871 sizeof(struct bnx2x_slowpath));
6872
Michael Chan37b091b2009-10-10 13:46:55 +00006873#ifdef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006874 BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
6875
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006876 /* allocate searcher T2 table
6877 we allocate 1/4 of alloc num for T2
6878 (which is not entered into the ILT) */
6879 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
6880
Michael Chan37b091b2009-10-10 13:46:55 +00006881 /* Initialize T2 (for 1024 connections) */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006882 for (i = 0; i < 16*1024; i += 64)
Michael Chan37b091b2009-10-10 13:46:55 +00006883 *(u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006884
Michael Chan37b091b2009-10-10 13:46:55 +00006885 /* Timer block array (8*MAX_CONN) phys uncached for now 1024 conns */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006886 BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
6887
6888 /* QM queues (128*MAX_CONN) */
6889 BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
Michael Chan37b091b2009-10-10 13:46:55 +00006890
6891 BNX2X_PCI_ALLOC(bp->cnic_sb, &bp->cnic_sb_mapping,
6892 sizeof(struct host_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006893#endif
6894
6895 /* Slow path ring */
6896 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6897
6898 return 0;
6899
6900alloc_mem_err:
6901 bnx2x_free_mem(bp);
6902 return -ENOMEM;
6903
6904#undef BNX2X_PCI_ALLOC
6905#undef BNX2X_ALLOC
6906}
6907
6908static void bnx2x_free_tx_skbs(struct bnx2x *bp)
6909{
6910 int i;
6911
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006912 for_each_tx_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006913 struct bnx2x_fastpath *fp = &bp->fp[i];
6914
6915 u16 bd_cons = fp->tx_bd_cons;
6916 u16 sw_prod = fp->tx_pkt_prod;
6917 u16 sw_cons = fp->tx_pkt_cons;
6918
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006919 while (sw_cons != sw_prod) {
6920 bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
6921 sw_cons++;
6922 }
6923 }
6924}
6925
6926static void bnx2x_free_rx_skbs(struct bnx2x *bp)
6927{
6928 int i, j;
6929
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006930 for_each_rx_queue(bp, j) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006931 struct bnx2x_fastpath *fp = &bp->fp[j];
6932
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006933 for (i = 0; i < NUM_RX_BD; i++) {
6934 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
6935 struct sk_buff *skb = rx_buf->skb;
6936
6937 if (skb == NULL)
6938 continue;
6939
6940 pci_unmap_single(bp->pdev,
6941 pci_unmap_addr(rx_buf, mapping),
Eilon Greenstein356e2382009-02-12 08:38:32 +00006942 bp->rx_buf_size, PCI_DMA_FROMDEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006943
6944 rx_buf->skb = NULL;
6945 dev_kfree_skb(skb);
6946 }
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006947 if (!fp->disable_tpa)
Eilon Greenstein32626232008-08-13 15:51:07 -07006948 bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
6949 ETH_MAX_AGGREGATION_QUEUES_E1 :
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006950 ETH_MAX_AGGREGATION_QUEUES_E1H);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006951 }
6952}
6953
6954static void bnx2x_free_skbs(struct bnx2x *bp)
6955{
6956 bnx2x_free_tx_skbs(bp);
6957 bnx2x_free_rx_skbs(bp);
6958}
6959
6960static void bnx2x_free_msix_irqs(struct bnx2x *bp)
6961{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006962 int i, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006963
6964 free_irq(bp->msix_table[0].vector, bp->dev);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006965 DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006966 bp->msix_table[0].vector);
6967
Michael Chan37b091b2009-10-10 13:46:55 +00006968#ifdef BCM_CNIC
6969 offset++;
6970#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006971 for_each_queue(bp, i) {
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006972 DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006973 "state %x\n", i, bp->msix_table[i + offset].vector,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006974 bnx2x_fp(bp, i, state));
6975
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006976 free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006977 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006978}
6979
6980static void bnx2x_free_irq(struct bnx2x *bp)
6981{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006982 if (bp->flags & USING_MSIX_FLAG) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006983 bnx2x_free_msix_irqs(bp);
6984 pci_disable_msix(bp->pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006985 bp->flags &= ~USING_MSIX_FLAG;
6986
Eilon Greenstein8badd272009-02-12 08:36:15 +00006987 } else if (bp->flags & USING_MSI_FLAG) {
6988 free_irq(bp->pdev->irq, bp->dev);
6989 pci_disable_msi(bp->pdev);
6990 bp->flags &= ~USING_MSI_FLAG;
6991
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006992 } else
6993 free_irq(bp->pdev->irq, bp->dev);
6994}
6995
6996static int bnx2x_enable_msix(struct bnx2x *bp)
6997{
Eilon Greenstein8badd272009-02-12 08:36:15 +00006998 int i, rc, offset = 1;
6999 int igu_vec = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007000
Eilon Greenstein8badd272009-02-12 08:36:15 +00007001 bp->msix_table[0].entry = igu_vec;
7002 DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007003
Michael Chan37b091b2009-10-10 13:46:55 +00007004#ifdef BCM_CNIC
7005 igu_vec = BP_L_ID(bp) + offset;
7006 bp->msix_table[1].entry = igu_vec;
7007 DP(NETIF_MSG_IFUP, "msix_table[1].entry = %d (CNIC)\n", igu_vec);
7008 offset++;
7009#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007010 for_each_queue(bp, i) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00007011 igu_vec = BP_L_ID(bp) + offset + i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007012 bp->msix_table[i + offset].entry = igu_vec;
7013 DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
7014 "(fastpath #%u)\n", i + offset, igu_vec, i);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007015 }
7016
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007017 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0],
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007018 BNX2X_NUM_QUEUES(bp) + offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007019 if (rc) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00007020 DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
7021 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007022 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007023
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007024 bp->flags |= USING_MSIX_FLAG;
7025
7026 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007027}
7028
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007029static int bnx2x_req_msix_irqs(struct bnx2x *bp)
7030{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007031 int i, rc, offset = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007032
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007033 rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
7034 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007035 if (rc) {
7036 BNX2X_ERR("request sp irq failed\n");
7037 return -EBUSY;
7038 }
7039
Michael Chan37b091b2009-10-10 13:46:55 +00007040#ifdef BCM_CNIC
7041 offset++;
7042#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007043 for_each_queue(bp, i) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007044 struct bnx2x_fastpath *fp = &bp->fp[i];
7045
Eilon Greensteinca003922009-08-12 22:53:28 -07007046 if (i < bp->num_rx_queues)
7047 sprintf(fp->name, "%s-rx-%d", bp->dev->name, i);
7048 else
7049 sprintf(fp->name, "%s-tx-%d",
7050 bp->dev->name, i - bp->num_rx_queues);
7051
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007052 rc = request_irq(bp->msix_table[i + offset].vector,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007053 bnx2x_msix_fp_int, 0, fp->name, fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007054 if (rc) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007055 BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007056 bnx2x_free_msix_irqs(bp);
7057 return -EBUSY;
7058 }
7059
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007060 fp->state = BNX2X_FP_STATE_IRQ;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007061 }
7062
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007063 i = BNX2X_NUM_QUEUES(bp);
Eilon Greensteinca003922009-08-12 22:53:28 -07007064 printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp[%d] %d"
7065 " ... fp[%d] %d\n",
7066 bp->dev->name, bp->msix_table[0].vector,
7067 0, bp->msix_table[offset].vector,
7068 i - 1, bp->msix_table[offset + i - 1].vector);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007069
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007070 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007071}
7072
Eilon Greenstein8badd272009-02-12 08:36:15 +00007073static int bnx2x_enable_msi(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007074{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007075 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007076
Eilon Greenstein8badd272009-02-12 08:36:15 +00007077 rc = pci_enable_msi(bp->pdev);
7078 if (rc) {
7079 DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
7080 return -1;
7081 }
7082 bp->flags |= USING_MSI_FLAG;
7083
7084 return 0;
7085}
7086
7087static int bnx2x_req_irq(struct bnx2x *bp)
7088{
7089 unsigned long flags;
7090 int rc;
7091
7092 if (bp->flags & USING_MSI_FLAG)
7093 flags = 0;
7094 else
7095 flags = IRQF_SHARED;
7096
7097 rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007098 bp->dev->name, bp->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007099 if (!rc)
7100 bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
7101
7102 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007103}
7104
Yitchak Gertner65abd742008-08-25 15:26:24 -07007105static void bnx2x_napi_enable(struct bnx2x *bp)
7106{
7107 int i;
7108
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007109 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007110 napi_enable(&bnx2x_fp(bp, i, napi));
7111}
7112
7113static void bnx2x_napi_disable(struct bnx2x *bp)
7114{
7115 int i;
7116
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007117 for_each_rx_queue(bp, i)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007118 napi_disable(&bnx2x_fp(bp, i, napi));
7119}
7120
7121static void bnx2x_netif_start(struct bnx2x *bp)
7122{
Eilon Greensteine1510702009-07-21 05:47:41 +00007123 int intr_sem;
7124
7125 intr_sem = atomic_dec_and_test(&bp->intr_sem);
7126 smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
7127
7128 if (intr_sem) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07007129 if (netif_running(bp->dev)) {
Yitchak Gertner65abd742008-08-25 15:26:24 -07007130 bnx2x_napi_enable(bp);
7131 bnx2x_int_enable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007132 if (bp->state == BNX2X_STATE_OPEN)
7133 netif_tx_wake_all_queues(bp->dev);
Yitchak Gertner65abd742008-08-25 15:26:24 -07007134 }
7135 }
7136}
7137
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07007138static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007139{
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07007140 bnx2x_int_disable_sync(bp, disable_hw);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00007141 bnx2x_napi_disable(bp);
Eilon Greenstein762d5f62009-03-02 07:59:56 +00007142 netif_tx_disable(bp->dev);
7143 bp->dev->trans_start = jiffies; /* prevent tx timeout */
Yitchak Gertner65abd742008-08-25 15:26:24 -07007144}
7145
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007146/*
7147 * Init service functions
7148 */
7149
Michael Chane665bfd2009-10-10 13:46:54 +00007150/**
7151 * Sets a MAC in a CAM for a few L2 Clients for E1 chip
7152 *
7153 * @param bp driver descriptor
7154 * @param set set or clear an entry (1 or 0)
7155 * @param mac pointer to a buffer containing a MAC
7156 * @param cl_bit_vec bit vector of clients to register a MAC for
7157 * @param cam_offset offset in a CAM to use
7158 * @param with_bcast set broadcast MAC as well
7159 */
7160static void bnx2x_set_mac_addr_e1_gen(struct bnx2x *bp, int set, u8 *mac,
7161 u32 cl_bit_vec, u8 cam_offset,
7162 u8 with_bcast)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007163{
7164 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007165 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007166
7167 /* CAM allocation
7168 * unicasts 0-31:port0 32-63:port1
7169 * multicast 64-127:port0 128-191:port1
7170 */
Michael Chane665bfd2009-10-10 13:46:54 +00007171 config->hdr.length = 1 + (with_bcast ? 1 : 0);
7172 config->hdr.offset = cam_offset;
7173 config->hdr.client_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007174 config->hdr.reserved1 = 0;
7175
7176 /* primary MAC */
7177 config->config_table[0].cam_entry.msb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007178 swab16(*(u16 *)&mac[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007179 config->config_table[0].cam_entry.middle_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007180 swab16(*(u16 *)&mac[2]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007181 config->config_table[0].cam_entry.lsb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007182 swab16(*(u16 *)&mac[4]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007183 config->config_table[0].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007184 if (set)
7185 config->config_table[0].target_table_entry.flags = 0;
7186 else
7187 CAM_INVALIDATE(config->config_table[0]);
Eilon Greensteinca003922009-08-12 22:53:28 -07007188 config->config_table[0].target_table_entry.clients_bit_vector =
Michael Chane665bfd2009-10-10 13:46:54 +00007189 cpu_to_le32(cl_bit_vec);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007190 config->config_table[0].target_table_entry.vlan_id = 0;
7191
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007192 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
7193 (set ? "setting" : "clearing"),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007194 config->config_table[0].cam_entry.msb_mac_addr,
7195 config->config_table[0].cam_entry.middle_mac_addr,
7196 config->config_table[0].cam_entry.lsb_mac_addr);
7197
7198 /* broadcast */
Michael Chane665bfd2009-10-10 13:46:54 +00007199 if (with_bcast) {
7200 config->config_table[1].cam_entry.msb_mac_addr =
7201 cpu_to_le16(0xffff);
7202 config->config_table[1].cam_entry.middle_mac_addr =
7203 cpu_to_le16(0xffff);
7204 config->config_table[1].cam_entry.lsb_mac_addr =
7205 cpu_to_le16(0xffff);
7206 config->config_table[1].cam_entry.flags = cpu_to_le16(port);
7207 if (set)
7208 config->config_table[1].target_table_entry.flags =
7209 TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
7210 else
7211 CAM_INVALIDATE(config->config_table[1]);
7212 config->config_table[1].target_table_entry.clients_bit_vector =
7213 cpu_to_le32(cl_bit_vec);
7214 config->config_table[1].target_table_entry.vlan_id = 0;
7215 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007216
7217 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
7218 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
7219 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
7220}
7221
Michael Chane665bfd2009-10-10 13:46:54 +00007222/**
7223 * Sets a MAC in a CAM for a few L2 Clients for E1H chip
7224 *
7225 * @param bp driver descriptor
7226 * @param set set or clear an entry (1 or 0)
7227 * @param mac pointer to a buffer containing a MAC
7228 * @param cl_bit_vec bit vector of clients to register a MAC for
7229 * @param cam_offset offset in a CAM to use
7230 */
7231static void bnx2x_set_mac_addr_e1h_gen(struct bnx2x *bp, int set, u8 *mac,
7232 u32 cl_bit_vec, u8 cam_offset)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007233{
7234 struct mac_configuration_cmd_e1h *config =
7235 (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
7236
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007237 config->hdr.length = 1;
Michael Chane665bfd2009-10-10 13:46:54 +00007238 config->hdr.offset = cam_offset;
7239 config->hdr.client_id = 0xff;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007240 config->hdr.reserved1 = 0;
7241
7242 /* primary MAC */
7243 config->config_table[0].msb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007244 swab16(*(u16 *)&mac[0]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007245 config->config_table[0].middle_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007246 swab16(*(u16 *)&mac[2]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007247 config->config_table[0].lsb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00007248 swab16(*(u16 *)&mac[4]);
Eilon Greensteinca003922009-08-12 22:53:28 -07007249 config->config_table[0].clients_bit_vector =
Michael Chane665bfd2009-10-10 13:46:54 +00007250 cpu_to_le32(cl_bit_vec);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007251 config->config_table[0].vlan_id = 0;
7252 config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007253 if (set)
7254 config->config_table[0].flags = BP_PORT(bp);
7255 else
7256 config->config_table[0].flags =
7257 MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007258
Michael Chane665bfd2009-10-10 13:46:54 +00007259 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID mask %d\n",
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007260 (set ? "setting" : "clearing"),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007261 config->config_table[0].msb_mac_addr,
7262 config->config_table[0].middle_mac_addr,
Michael Chane665bfd2009-10-10 13:46:54 +00007263 config->config_table[0].lsb_mac_addr, bp->e1hov, cl_bit_vec);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007264
7265 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
7266 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
7267 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
7268}
7269
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007270static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
7271 int *state_p, int poll)
7272{
7273 /* can take a while if any port is running */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00007274 int cnt = 5000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007275
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007276 DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
7277 poll ? "polling" : "waiting", state, idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007278
7279 might_sleep();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007280 while (cnt--) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007281 if (poll) {
7282 bnx2x_rx_int(bp->fp, 10);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007283 /* if index is different from 0
7284 * the reply for some commands will
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007285 * be on the non default queue
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007286 */
7287 if (idx)
7288 bnx2x_rx_int(&bp->fp[idx], 10);
7289 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007290
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07007291 mb(); /* state is changed by bnx2x_sp_event() */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00007292 if (*state_p == state) {
7293#ifdef BNX2X_STOP_ON_ERROR
7294 DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
7295#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007296 return 0;
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00007297 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007298
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007299 msleep(1);
Eilon Greensteine3553b22009-08-12 08:23:31 +00007300
7301 if (bp->panic)
7302 return -EIO;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007303 }
7304
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007305 /* timeout! */
Eliezer Tamir49d66772008-02-28 11:53:13 -08007306 BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
7307 poll ? "polling" : "waiting", state, idx);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007308#ifdef BNX2X_STOP_ON_ERROR
7309 bnx2x_panic();
7310#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007311
Eliezer Tamir49d66772008-02-28 11:53:13 -08007312 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007313}
7314
Michael Chane665bfd2009-10-10 13:46:54 +00007315static void bnx2x_set_eth_mac_addr_e1h(struct bnx2x *bp, int set)
7316{
7317 bp->set_mac_pending++;
7318 smp_wmb();
7319
7320 bnx2x_set_mac_addr_e1h_gen(bp, set, bp->dev->dev_addr,
7321 (1 << bp->fp->cl_id), BP_FUNC(bp));
7322
7323 /* Wait for a completion */
7324 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
7325}
7326
7327static void bnx2x_set_eth_mac_addr_e1(struct bnx2x *bp, int set)
7328{
7329 bp->set_mac_pending++;
7330 smp_wmb();
7331
7332 bnx2x_set_mac_addr_e1_gen(bp, set, bp->dev->dev_addr,
7333 (1 << bp->fp->cl_id), (BP_PORT(bp) ? 32 : 0),
7334 1);
7335
7336 /* Wait for a completion */
7337 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
7338}
7339
Michael Chan993ac7b2009-10-10 13:46:56 +00007340#ifdef BCM_CNIC
7341/**
7342 * Set iSCSI MAC(s) at the next enties in the CAM after the ETH
7343 * MAC(s). This function will wait until the ramdord completion
7344 * returns.
7345 *
7346 * @param bp driver handle
7347 * @param set set or clear the CAM entry
7348 *
7349 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
7350 */
7351static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set)
7352{
7353 u32 cl_bit_vec = (1 << BCM_ISCSI_ETH_CL_ID);
7354
7355 bp->set_mac_pending++;
7356 smp_wmb();
7357
7358 /* Send a SET_MAC ramrod */
7359 if (CHIP_IS_E1(bp))
7360 bnx2x_set_mac_addr_e1_gen(bp, set, bp->iscsi_mac,
7361 cl_bit_vec, (BP_PORT(bp) ? 32 : 0) + 2,
7362 1);
7363 else
7364 /* CAM allocation for E1H
7365 * unicasts: by func number
7366 * multicast: 20+FUNC*20, 20 each
7367 */
7368 bnx2x_set_mac_addr_e1h_gen(bp, set, bp->iscsi_mac,
7369 cl_bit_vec, E1H_FUNC_MAX + BP_FUNC(bp));
7370
7371 /* Wait for a completion when setting */
7372 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
7373
7374 return 0;
7375}
7376#endif
7377
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007378static int bnx2x_setup_leading(struct bnx2x *bp)
7379{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007380 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007381
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007382 /* reset IGU state */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007383 bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007384
7385 /* SETUP ramrod */
7386 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
7387
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007388 /* Wait for completion */
7389 rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007390
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007391 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007392}
7393
7394static int bnx2x_setup_multi(struct bnx2x *bp, int index)
7395{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007396 struct bnx2x_fastpath *fp = &bp->fp[index];
7397
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007398 /* reset IGU state */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007399 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007400
Eliezer Tamir228241e2008-02-28 11:56:57 -08007401 /* SETUP ramrod */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007402 fp->state = BNX2X_FP_STATE_OPENING;
7403 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
7404 fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007405
7406 /* Wait for completion */
7407 return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007408 &(fp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007409}
7410
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007411static int bnx2x_poll(struct napi_struct *napi, int budget);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007412
Eilon Greensteinca003922009-08-12 22:53:28 -07007413static void bnx2x_set_int_mode_msix(struct bnx2x *bp, int *num_rx_queues_out,
7414 int *num_tx_queues_out)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007415{
Eilon Greensteinca003922009-08-12 22:53:28 -07007416 int _num_rx_queues = 0, _num_tx_queues = 0;
7417
7418 switch (bp->multi_mode) {
7419 case ETH_RSS_MODE_DISABLED:
7420 _num_rx_queues = 1;
7421 _num_tx_queues = 1;
7422 break;
7423
7424 case ETH_RSS_MODE_REGULAR:
7425 if (num_rx_queues)
7426 _num_rx_queues = min_t(u32, num_rx_queues,
7427 BNX2X_MAX_QUEUES(bp));
7428 else
7429 _num_rx_queues = min_t(u32, num_online_cpus(),
7430 BNX2X_MAX_QUEUES(bp));
7431
7432 if (num_tx_queues)
7433 _num_tx_queues = min_t(u32, num_tx_queues,
7434 BNX2X_MAX_QUEUES(bp));
7435 else
7436 _num_tx_queues = min_t(u32, num_online_cpus(),
7437 BNX2X_MAX_QUEUES(bp));
7438
7439 /* There must be not more Tx queues than Rx queues */
7440 if (_num_tx_queues > _num_rx_queues) {
7441 BNX2X_ERR("number of tx queues (%d) > "
7442 "number of rx queues (%d)"
7443 " defaulting to %d\n",
7444 _num_tx_queues, _num_rx_queues,
7445 _num_rx_queues);
7446 _num_tx_queues = _num_rx_queues;
7447 }
7448 break;
7449
7450
7451 default:
7452 _num_rx_queues = 1;
7453 _num_tx_queues = 1;
7454 break;
7455 }
7456
7457 *num_rx_queues_out = _num_rx_queues;
7458 *num_tx_queues_out = _num_tx_queues;
7459}
7460
7461static int bnx2x_set_int_mode(struct bnx2x *bp)
7462{
7463 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007464
Eilon Greenstein8badd272009-02-12 08:36:15 +00007465 switch (int_mode) {
7466 case INT_MODE_INTx:
7467 case INT_MODE_MSI:
Eilon Greensteinca003922009-08-12 22:53:28 -07007468 bp->num_rx_queues = 1;
7469 bp->num_tx_queues = 1;
7470 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
Eilon Greenstein8badd272009-02-12 08:36:15 +00007471 break;
7472
7473 case INT_MODE_MSIX:
7474 default:
Eilon Greensteinca003922009-08-12 22:53:28 -07007475 /* Set interrupt mode according to bp->multi_mode value */
7476 bnx2x_set_int_mode_msix(bp, &bp->num_rx_queues,
7477 &bp->num_tx_queues);
7478
7479 DP(NETIF_MSG_IFUP, "set number of queues to: rx %d tx %d\n",
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007480 bp->num_rx_queues, bp->num_tx_queues);
Eilon Greensteinca003922009-08-12 22:53:28 -07007481
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007482 /* if we can't use MSI-X we only need one fp,
7483 * so try to enable MSI-X with the requested number of fp's
7484 * and fallback to MSI or legacy INTx with one fp
7485 */
Eilon Greensteinca003922009-08-12 22:53:28 -07007486 rc = bnx2x_enable_msix(bp);
7487 if (rc) {
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007488 /* failed to enable MSI-X */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007489 if (bp->multi_mode)
7490 BNX2X_ERR("Multi requested but failed to "
Eilon Greensteinca003922009-08-12 22:53:28 -07007491 "enable MSI-X (rx %d tx %d), "
7492 "set number of queues to 1\n",
7493 bp->num_rx_queues, bp->num_tx_queues);
7494 bp->num_rx_queues = 1;
7495 bp->num_tx_queues = 1;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007496 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007497 break;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007498 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007499 bp->dev->real_num_tx_queues = bp->num_tx_queues;
Eilon Greensteinca003922009-08-12 22:53:28 -07007500 return rc;
Eilon Greenstein8badd272009-02-12 08:36:15 +00007501}
7502
Michael Chan993ac7b2009-10-10 13:46:56 +00007503#ifdef BCM_CNIC
7504static int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
7505static void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
7506#endif
Eilon Greenstein8badd272009-02-12 08:36:15 +00007507
7508/* must be called with rtnl_lock */
7509static int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
7510{
7511 u32 load_code;
Eilon Greensteinca003922009-08-12 22:53:28 -07007512 int i, rc;
7513
Eilon Greenstein8badd272009-02-12 08:36:15 +00007514#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein8badd272009-02-12 08:36:15 +00007515 if (unlikely(bp->panic))
7516 return -EPERM;
7517#endif
7518
7519 bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
7520
Eilon Greensteinca003922009-08-12 22:53:28 -07007521 rc = bnx2x_set_int_mode(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007522
7523 if (bnx2x_alloc_mem(bp))
7524 return -ENOMEM;
7525
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007526 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007527 bnx2x_fp(bp, i, disable_tpa) =
7528 ((bp->flags & TPA_ENABLE_FLAG) == 0);
7529
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007530 for_each_rx_queue(bp, i)
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007531 netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
7532 bnx2x_poll, 128);
7533
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007534 bnx2x_napi_enable(bp);
7535
7536 if (bp->flags & USING_MSIX_FLAG) {
7537 rc = bnx2x_req_msix_irqs(bp);
7538 if (rc) {
7539 pci_disable_msix(bp->pdev);
7540 goto load_error1;
7541 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007542 } else {
Eilon Greensteinca003922009-08-12 22:53:28 -07007543 /* Fall to INTx if failed to enable MSI-X due to lack of
7544 memory (in bnx2x_set_int_mode()) */
Eilon Greenstein8badd272009-02-12 08:36:15 +00007545 if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
7546 bnx2x_enable_msi(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007547 bnx2x_ack_int(bp);
7548 rc = bnx2x_req_irq(bp);
7549 if (rc) {
7550 BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
Eilon Greenstein8badd272009-02-12 08:36:15 +00007551 if (bp->flags & USING_MSI_FLAG)
7552 pci_disable_msi(bp->pdev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007553 goto load_error1;
7554 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007555 if (bp->flags & USING_MSI_FLAG) {
7556 bp->dev->irq = bp->pdev->irq;
7557 printk(KERN_INFO PFX "%s: using MSI IRQ %d\n",
7558 bp->dev->name, bp->pdev->irq);
7559 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007560 }
7561
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007562 /* Send LOAD_REQUEST command to MCP
7563 Returns the type of LOAD command:
7564 if it is the first port to be initialized
7565 common blocks should be initialized, otherwise - not
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007566 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007567 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08007568 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ);
7569 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007570 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007571 rc = -EBUSY;
7572 goto load_error2;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007573 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007574 if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
7575 rc = -EBUSY; /* other port in diagnostic mode */
7576 goto load_error2;
7577 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007578
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007579 } else {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007580 int port = BP_PORT(bp);
7581
Eilon Greensteinf5372252009-02-12 08:38:30 +00007582 DP(NETIF_MSG_IFUP, "NO MCP - load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007583 load_count[0], load_count[1], load_count[2]);
7584 load_count[0]++;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007585 load_count[1 + port]++;
Eilon Greensteinf5372252009-02-12 08:38:30 +00007586 DP(NETIF_MSG_IFUP, "NO MCP - new load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007587 load_count[0], load_count[1], load_count[2]);
7588 if (load_count[0] == 1)
7589 load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007590 else if (load_count[1 + port] == 1)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007591 load_code = FW_MSG_CODE_DRV_LOAD_PORT;
7592 else
7593 load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007594 }
7595
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007596 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
7597 (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
7598 bp->port.pmf = 1;
7599 else
7600 bp->port.pmf = 0;
7601 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
7602
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007603 /* Initialize HW */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007604 rc = bnx2x_init_hw(bp, load_code);
7605 if (rc) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007606 BNX2X_ERR("HW init failed, aborting\n");
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007607 goto load_error2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007608 }
7609
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007610 /* Setup NIC internals and enable interrupts */
Eilon Greenstein471de712008-08-13 15:49:35 -07007611 bnx2x_nic_init(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007612
Eilon Greenstein2691d512009-08-12 08:22:08 +00007613 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) &&
7614 (bp->common.shmem2_base))
7615 SHMEM2_WR(bp, dcc_support,
7616 (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV |
7617 SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV));
7618
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007619 /* Send LOAD_DONE command to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007620 if (!BP_NOMCP(bp)) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08007621 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE);
7622 if (!load_code) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007623 BNX2X_ERR("MCP response failure, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007624 rc = -EBUSY;
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007625 goto load_error3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007626 }
7627 }
7628
7629 bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
7630
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007631 rc = bnx2x_setup_leading(bp);
7632 if (rc) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007633 BNX2X_ERR("Setup leading failed!\n");
Eilon Greensteine3553b22009-08-12 08:23:31 +00007634#ifndef BNX2X_STOP_ON_ERROR
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007635 goto load_error3;
Eilon Greensteine3553b22009-08-12 08:23:31 +00007636#else
7637 bp->panic = 1;
7638 return -EBUSY;
7639#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007640 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007641
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007642 if (CHIP_IS_E1H(bp))
7643 if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00007644 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07007645 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007646 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007647
Eilon Greensteinca003922009-08-12 22:53:28 -07007648 if (bp->state == BNX2X_STATE_OPEN) {
Michael Chan37b091b2009-10-10 13:46:55 +00007649#ifdef BCM_CNIC
7650 /* Enable Timer scan */
7651 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 1);
7652#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007653 for_each_nondefault_queue(bp, i) {
7654 rc = bnx2x_setup_multi(bp, i);
7655 if (rc)
Michael Chan37b091b2009-10-10 13:46:55 +00007656#ifdef BCM_CNIC
7657 goto load_error4;
7658#else
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007659 goto load_error3;
Michael Chan37b091b2009-10-10 13:46:55 +00007660#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007661 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007662
Eilon Greensteinca003922009-08-12 22:53:28 -07007663 if (CHIP_IS_E1(bp))
Michael Chane665bfd2009-10-10 13:46:54 +00007664 bnx2x_set_eth_mac_addr_e1(bp, 1);
Eilon Greensteinca003922009-08-12 22:53:28 -07007665 else
Michael Chane665bfd2009-10-10 13:46:54 +00007666 bnx2x_set_eth_mac_addr_e1h(bp, 1);
Michael Chan993ac7b2009-10-10 13:46:56 +00007667#ifdef BCM_CNIC
7668 /* Set iSCSI L2 MAC */
7669 mutex_lock(&bp->cnic_mutex);
7670 if (bp->cnic_eth_dev.drv_state & CNIC_DRV_STATE_REGD) {
7671 bnx2x_set_iscsi_eth_mac_addr(bp, 1);
7672 bp->cnic_flags |= BNX2X_CNIC_FLAG_MAC_SET;
7673 }
7674 mutex_unlock(&bp->cnic_mutex);
7675#endif
Eilon Greensteinca003922009-08-12 22:53:28 -07007676 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007677
7678 if (bp->port.pmf)
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00007679 bnx2x_initial_phy_init(bp, load_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007680
7681 /* Start fast path */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007682 switch (load_mode) {
7683 case LOAD_NORMAL:
Eilon Greensteinca003922009-08-12 22:53:28 -07007684 if (bp->state == BNX2X_STATE_OPEN) {
7685 /* Tx queue should be only reenabled */
7686 netif_tx_wake_all_queues(bp->dev);
7687 }
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007688 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007689 bnx2x_set_rx_mode(bp->dev);
7690 break;
7691
7692 case LOAD_OPEN:
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007693 netif_tx_start_all_queues(bp->dev);
Eilon Greensteinca003922009-08-12 22:53:28 -07007694 if (bp->state != BNX2X_STATE_OPEN)
7695 netif_tx_disable(bp->dev);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007696 /* Initialize the receive filter. */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007697 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007698 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007699
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007700 case LOAD_DIAG:
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007701 /* Initialize the receive filter. */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007702 bnx2x_set_rx_mode(bp->dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007703 bp->state = BNX2X_STATE_DIAG;
7704 break;
7705
7706 default:
7707 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007708 }
7709
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007710 if (!bp->port.pmf)
7711 bnx2x__link_status_update(bp);
7712
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007713 /* start the timer */
7714 mod_timer(&bp->timer, jiffies + bp->current_interval);
7715
Michael Chan993ac7b2009-10-10 13:46:56 +00007716#ifdef BCM_CNIC
7717 bnx2x_setup_cnic_irq_info(bp);
7718 if (bp->state == BNX2X_STATE_OPEN)
7719 bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
7720#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007721
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007722 return 0;
7723
Michael Chan37b091b2009-10-10 13:46:55 +00007724#ifdef BCM_CNIC
7725load_error4:
7726 /* Disable Timer scan */
7727 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 0);
7728#endif
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007729load_error3:
7730 bnx2x_int_disable_sync(bp, 1);
7731 if (!BP_NOMCP(bp)) {
7732 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP);
7733 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7734 }
7735 bp->port.pmf = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007736 /* Free SKBs, SGEs, TPA pool and driver internals */
7737 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007738 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07007739 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007740load_error2:
Yitchak Gertnerd1014632008-08-25 15:25:45 -07007741 /* Release IRQs */
7742 bnx2x_free_irq(bp);
Eilon Greenstein2dfe0e12009-01-22 03:37:44 +00007743load_error1:
7744 bnx2x_napi_disable(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007745 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00007746 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007747 bnx2x_free_mem(bp);
7748
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007749 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007750}
7751
7752static int bnx2x_stop_multi(struct bnx2x *bp, int index)
7753{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007754 struct bnx2x_fastpath *fp = &bp->fp[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007755 int rc;
7756
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007757 /* halt the connection */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007758 fp->state = BNX2X_FP_STATE_HALTING;
7759 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007760
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007761 /* Wait for completion */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007762 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007763 &(fp->state), 1);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007764 if (rc) /* timeout */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007765 return rc;
7766
7767 /* delete cfc entry */
7768 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
7769
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007770 /* Wait for completion */
7771 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007772 &(fp->state), 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007773 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007774}
7775
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007776static int bnx2x_stop_leading(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007777{
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00007778 __le16 dsb_sp_prod_idx;
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007779 /* if the other port is handling traffic,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007780 this can take a lot of time */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007781 int cnt = 500;
7782 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007783
7784 might_sleep();
7785
7786 /* Send HALT ramrod */
7787 bp->fp[0].state = BNX2X_FP_STATE_HALTING;
Eilon Greenstein0626b892009-02-12 08:38:14 +00007788 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007789
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007790 /* Wait for completion */
7791 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
7792 &(bp->fp[0].state), 1);
7793 if (rc) /* timeout */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007794 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007795
Eliezer Tamir49d66772008-02-28 11:53:13 -08007796 dsb_sp_prod_idx = *bp->dsb_sp_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007797
Eliezer Tamir228241e2008-02-28 11:56:57 -08007798 /* Send PORT_DELETE ramrod */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007799 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
7800
Eliezer Tamir49d66772008-02-28 11:53:13 -08007801 /* Wait for completion to arrive on default status block
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007802 we are going to reset the chip anyway
7803 so there is not much to do if this times out
7804 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007805 while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007806 if (!cnt) {
7807 DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
7808 "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
7809 *bp->dsb_sp_prod, dsb_sp_prod_idx);
7810#ifdef BNX2X_STOP_ON_ERROR
7811 bnx2x_panic();
7812#endif
Eilon Greenstein36e552ab2009-02-12 08:37:21 +00007813 rc = -EBUSY;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007814 break;
7815 }
7816 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007817 msleep(1);
Eilon Greenstein5650d9d2009-01-22 06:01:29 +00007818 rmb(); /* Refresh the dsb_sp_prod */
Eliezer Tamir49d66772008-02-28 11:53:13 -08007819 }
7820 bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
7821 bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007822
7823 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007824}
7825
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007826static void bnx2x_reset_func(struct bnx2x *bp)
7827{
7828 int port = BP_PORT(bp);
7829 int func = BP_FUNC(bp);
7830 int base, i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08007831
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007832 /* Configure IGU */
7833 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7834 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7835
Michael Chan37b091b2009-10-10 13:46:55 +00007836#ifdef BCM_CNIC
7837 /* Disable Timer scan */
7838 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7839 /*
7840 * Wait for at least 10ms and up to 2 second for the timers scan to
7841 * complete
7842 */
7843 for (i = 0; i < 200; i++) {
7844 msleep(10);
7845 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7846 break;
7847 }
7848#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007849 /* Clear ILT */
7850 base = FUNC_ILT_BASE(func);
7851 for (i = base; i < base + ILT_PER_FUNC; i++)
7852 bnx2x_ilt_wr(bp, i, 0);
7853}
7854
7855static void bnx2x_reset_port(struct bnx2x *bp)
7856{
7857 int port = BP_PORT(bp);
7858 u32 val;
7859
7860 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7861
7862 /* Do not rcv packets to BRB */
7863 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7864 /* Do not direct rcv packets that are not for MCP to the BRB */
7865 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7866 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7867
7868 /* Configure AEU */
7869 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7870
7871 msleep(100);
7872 /* Check for BRB port occupancy */
7873 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7874 if (val)
7875 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07007876 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007877
7878 /* TODO: Close Doorbell port? */
7879}
7880
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007881static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
7882{
7883 DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
7884 BP_FUNC(bp), reset_code);
7885
7886 switch (reset_code) {
7887 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
7888 bnx2x_reset_port(bp);
7889 bnx2x_reset_func(bp);
7890 bnx2x_reset_common(bp);
7891 break;
7892
7893 case FW_MSG_CODE_DRV_UNLOAD_PORT:
7894 bnx2x_reset_port(bp);
7895 bnx2x_reset_func(bp);
7896 break;
7897
7898 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
7899 bnx2x_reset_func(bp);
7900 break;
7901
7902 default:
7903 BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
7904 break;
7905 }
7906}
7907
Eilon Greenstein33471622008-08-13 15:59:08 -07007908/* must be called with rtnl_lock */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007909static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007910{
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007911 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007912 u32 reset_code = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007913 int i, cnt, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007914
Michael Chan993ac7b2009-10-10 13:46:56 +00007915#ifdef BCM_CNIC
7916 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
7917#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007918 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
7919
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00007920 /* Set "drop all" */
Eliezer Tamir228241e2008-02-28 11:56:57 -08007921 bp->rx_mode = BNX2X_RX_MODE_NONE;
7922 bnx2x_set_storm_rx_mode(bp);
7923
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00007924 /* Disable HW interrupts, NAPI and Tx */
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07007925 bnx2x_netif_stop(bp, 1);
Eilon Greensteine94d8af2009-01-22 03:37:36 +00007926
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007927 del_timer_sync(&bp->timer);
7928 SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb,
7929 (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07007930 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007931
Eilon Greenstein70b99862009-01-14 06:43:48 +00007932 /* Release IRQs */
7933 bnx2x_free_irq(bp);
7934
Eilon Greenstein555f6c72009-02-12 08:36:11 +00007935 /* Wait until tx fastpath tasks complete */
7936 for_each_tx_queue(bp, i) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08007937 struct bnx2x_fastpath *fp = &bp->fp[i];
7938
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007939 cnt = 1000;
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -08007940 while (bnx2x_has_tx_work_unload(fp)) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007941
Eilon Greenstein7961f792009-03-02 07:59:31 +00007942 bnx2x_tx_int(fp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007943 if (!cnt) {
7944 BNX2X_ERR("timeout waiting for queue[%d]\n",
7945 i);
7946#ifdef BNX2X_STOP_ON_ERROR
7947 bnx2x_panic();
7948 return -EBUSY;
7949#else
7950 break;
7951#endif
7952 }
7953 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007954 msleep(1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007955 }
Eliezer Tamir228241e2008-02-28 11:56:57 -08007956 }
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007957 /* Give HW time to discard old tx messages */
7958 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007959
Yitchak Gertner65abd742008-08-25 15:26:24 -07007960 if (CHIP_IS_E1(bp)) {
7961 struct mac_configuration_cmd *config =
7962 bnx2x_sp(bp, mcast_config);
7963
Michael Chane665bfd2009-10-10 13:46:54 +00007964 bnx2x_set_eth_mac_addr_e1(bp, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07007965
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007966 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertner65abd742008-08-25 15:26:24 -07007967 CAM_INVALIDATE(config->config_table[i]);
7968
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007969 config->hdr.length = i;
Yitchak Gertner65abd742008-08-25 15:26:24 -07007970 if (CHIP_REV_IS_SLOW(bp))
7971 config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
7972 else
7973 config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
Eilon Greenstein0626b892009-02-12 08:38:14 +00007974 config->hdr.client_id = bp->fp->cl_id;
Yitchak Gertner65abd742008-08-25 15:26:24 -07007975 config->hdr.reserved1 = 0;
7976
Michael Chane665bfd2009-10-10 13:46:54 +00007977 bp->set_mac_pending++;
7978 smp_wmb();
7979
Yitchak Gertner65abd742008-08-25 15:26:24 -07007980 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
7981 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
7982 U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
7983
7984 } else { /* E1H */
7985 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7986
Michael Chane665bfd2009-10-10 13:46:54 +00007987 bnx2x_set_eth_mac_addr_e1h(bp, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07007988
7989 for (i = 0; i < MC_HASH_SIZE; i++)
7990 REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00007991
7992 REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07007993 }
Michael Chan993ac7b2009-10-10 13:46:56 +00007994#ifdef BCM_CNIC
7995 /* Clear iSCSI L2 MAC */
7996 mutex_lock(&bp->cnic_mutex);
7997 if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
7998 bnx2x_set_iscsi_eth_mac_addr(bp, 0);
7999 bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
8000 }
8001 mutex_unlock(&bp->cnic_mutex);
8002#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07008003
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008004 if (unload_mode == UNLOAD_NORMAL)
8005 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008006
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008007 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008008 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008009
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008010 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008011 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008012 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008013 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008014 /* The mac address is written to entries 1-4 to
8015 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008016 u8 entry = (BP_E1HVN(bp) + 1)*8;
8017
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008018 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008019 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008020
8021 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8022 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008023 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008024
8025 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008026
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008027 } else
8028 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8029
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008030 /* Close multi and leading connections
8031 Completions for ramrods are collected in a synchronous way */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008032 for_each_nondefault_queue(bp, i)
8033 if (bnx2x_stop_multi(bp, i))
Eliezer Tamir228241e2008-02-28 11:56:57 -08008034 goto unload_error;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008035
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008036 rc = bnx2x_stop_leading(bp);
8037 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008038 BNX2X_ERR("Stop leading failed!\n");
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008039#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008040 return -EBUSY;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008041#else
8042 goto unload_error;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008043#endif
Eliezer Tamir228241e2008-02-28 11:56:57 -08008044 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008045
Eliezer Tamir228241e2008-02-28 11:56:57 -08008046unload_error:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008047 if (!BP_NOMCP(bp))
Eliezer Tamir228241e2008-02-28 11:56:57 -08008048 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008049 else {
Eilon Greensteinf5372252009-02-12 08:38:30 +00008050 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008051 load_count[0], load_count[1], load_count[2]);
8052 load_count[0]--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008053 load_count[1 + port]--;
Eilon Greensteinf5372252009-02-12 08:38:30 +00008054 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008055 load_count[0], load_count[1], load_count[2]);
8056 if (load_count[0] == 0)
8057 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008058 else if (load_count[1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008059 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8060 else
8061 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8062 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008063
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008064 if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
8065 (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
8066 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008067
8068 /* Reset the chip */
Eliezer Tamir228241e2008-02-28 11:56:57 -08008069 bnx2x_reset_chip(bp, reset_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008070
8071 /* Report UNLOAD_DONE to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008072 if (!BP_NOMCP(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008073 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
Eilon Greenstein356e2382009-02-12 08:38:32 +00008074
Eilon Greenstein9a035442008-11-03 16:45:55 -08008075 bp->port.pmf = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008076
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008077 /* Free SKBs, SGEs, TPA pool and driver internals */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008078 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008079 for_each_rx_queue(bp, i)
Eilon Greenstein3196a882008-08-13 15:58:49 -07008080 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008081 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00008082 netif_napi_del(&bnx2x_fp(bp, i, napi));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008083 bnx2x_free_mem(bp);
8084
8085 bp->state = BNX2X_STATE_CLOSED;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008086
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008087 netif_carrier_off(bp->dev);
8088
8089 return 0;
8090}
8091
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008092static void bnx2x_reset_task(struct work_struct *work)
8093{
8094 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task);
8095
8096#ifdef BNX2X_STOP_ON_ERROR
8097 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
8098 " so reset not done to allow debug dump,\n"
Joe Perchesad361c92009-07-06 13:05:40 -07008099 " you will need to reboot when done\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008100 return;
8101#endif
8102
8103 rtnl_lock();
8104
8105 if (!netif_running(bp->dev))
8106 goto reset_task_exit;
8107
8108 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8109 bnx2x_nic_load(bp, LOAD_NORMAL);
8110
8111reset_task_exit:
8112 rtnl_unlock();
8113}
8114
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008115/* end of nic load/unload */
8116
8117/* ethtool_ops */
8118
8119/*
8120 * Init service functions
8121 */
8122
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008123static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
8124{
8125 switch (func) {
8126 case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
8127 case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
8128 case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
8129 case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
8130 case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
8131 case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
8132 case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
8133 case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
8134 default:
8135 BNX2X_ERR("Unsupported function index: %d\n", func);
8136 return (u32)(-1);
8137 }
8138}
8139
8140static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
8141{
8142 u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
8143
8144 /* Flush all outstanding writes */
8145 mmiowb();
8146
8147 /* Pretend to be function 0 */
8148 REG_WR(bp, reg, 0);
8149 /* Flush the GRC transaction (in the chip) */
8150 new_val = REG_RD(bp, reg);
8151 if (new_val != 0) {
8152 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
8153 new_val);
8154 BUG();
8155 }
8156
8157 /* From now we are in the "like-E1" mode */
8158 bnx2x_int_disable(bp);
8159
8160 /* Flush all outstanding writes */
8161 mmiowb();
8162
8163 /* Restore the original funtion settings */
8164 REG_WR(bp, reg, orig_func);
8165 new_val = REG_RD(bp, reg);
8166 if (new_val != orig_func) {
8167 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
8168 orig_func, new_val);
8169 BUG();
8170 }
8171}
8172
8173static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
8174{
8175 if (CHIP_IS_E1H(bp))
8176 bnx2x_undi_int_disable_e1h(bp, func);
8177 else
8178 bnx2x_int_disable(bp);
8179}
8180
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008181static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008182{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008183 u32 val;
8184
8185 /* Check if there is any driver already loaded */
8186 val = REG_RD(bp, MISC_REG_UNPREPARED);
8187 if (val == 0x1) {
8188 /* Check if it is the UNDI driver
8189 * UNDI driver initializes CID offset for normal bell to 0x7
8190 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008191 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008192 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8193 if (val == 0x7) {
8194 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008195 /* save our func */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008196 int func = BP_FUNC(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008197 u32 swap_en;
8198 u32 swap_val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008199
Eilon Greensteinb4661732009-01-14 06:43:56 +00008200 /* clear the UNDI indication */
8201 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8202
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008203 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8204
8205 /* try unload UNDI on port 0 */
8206 bp->func = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008207 bp->fw_seq =
8208 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
8209 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008210 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008211
8212 /* if UNDI is loaded on the other port */
8213 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8214
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008215 /* send "DONE" for previous unload */
8216 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
8217
8218 /* unload UNDI on port 1 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008219 bp->func = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008220 bp->fw_seq =
8221 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
8222 DRV_MSG_SEQ_NUMBER_MASK);
8223 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008224
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008225 bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008226 }
8227
Eilon Greensteinb4661732009-01-14 06:43:56 +00008228 /* now it's safe to release the lock */
8229 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8230
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008231 bnx2x_undi_int_disable(bp, func);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008232
8233 /* close input traffic and wait for it */
8234 /* Do not rcv packets to BRB */
8235 REG_WR(bp,
8236 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
8237 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
8238 /* Do not direct rcv packets that are not for MCP to
8239 * the BRB */
8240 REG_WR(bp,
8241 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
8242 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8243 /* clear AEU */
8244 REG_WR(bp,
8245 (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8246 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
8247 msleep(10);
8248
8249 /* save NIG port swap info */
8250 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8251 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008252 /* reset device */
8253 REG_WR(bp,
8254 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008255 0xd3ffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008256 REG_WR(bp,
8257 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8258 0x1403);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008259 /* take the NIG out of reset and restore swap values */
8260 REG_WR(bp,
8261 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8262 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8263 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8264 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8265
8266 /* send unload done to the MCP */
8267 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
8268
8269 /* restore our func and fw_seq */
8270 bp->func = func;
8271 bp->fw_seq =
8272 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
8273 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00008274
8275 } else
8276 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008277 }
8278}
8279
8280static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8281{
8282 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c32008-08-13 15:52:46 -07008283 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008284
8285 /* Get the chip revision id and number. */
8286 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8287 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8288 id = ((val & 0xffff) << 16);
8289 val = REG_RD(bp, MISC_REG_CHIP_REV);
8290 id |= ((val & 0xf) << 12);
8291 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8292 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00008293 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008294 id |= (val & 0xf);
8295 bp->common.chip_id = id;
8296 bp->link_params.chip_id = bp->common.chip_id;
8297 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
8298
Eilon Greenstein1c063282009-02-12 08:36:43 +00008299 val = (REG_RD(bp, 0x2874) & 0x55);
8300 if ((bp->common.chip_id & 0x1) ||
8301 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8302 bp->flags |= ONE_PORT_FLAG;
8303 BNX2X_DEV_INFO("single port device\n");
8304 }
8305
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008306 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
8307 bp->common.flash_size = (NVRAM_1MB_SIZE <<
8308 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8309 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8310 bp->common.flash_size, bp->common.flash_size);
8311
8312 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
Eilon Greenstein2691d512009-08-12 08:22:08 +00008313 bp->common.shmem2_base = REG_RD(bp, MISC_REG_GENERIC_CR_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008314 bp->link_params.shmem_base = bp->common.shmem_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008315 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8316 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008317
8318 if (!bp->common.shmem_base ||
8319 (bp->common.shmem_base < 0xA0000) ||
8320 (bp->common.shmem_base >= 0xC0000)) {
8321 BNX2X_DEV_INFO("MCP not active\n");
8322 bp->flags |= NO_MCP_FLAG;
8323 return;
8324 }
8325
8326 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8327 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
8328 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
8329 BNX2X_ERR("BAD MCP validity signature\n");
8330
8331 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00008332 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008333
8334 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8335 SHARED_HW_CFG_LED_MODE_MASK) >>
8336 SHARED_HW_CFG_LED_MODE_SHIFT);
8337
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008338 bp->link_params.feature_config_flags = 0;
8339 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8340 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8341 bp->link_params.feature_config_flags |=
8342 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8343 else
8344 bp->link_params.feature_config_flags &=
8345 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8346
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008347 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8348 bp->common.bc_ver = val;
8349 BNX2X_DEV_INFO("bc_ver %X\n", val);
8350 if (val < BNX2X_BC_VER) {
8351 /* for now only warn
8352 * later we might need to enforce this */
8353 BNX2X_ERR("This driver needs bc_ver %X but found %X,"
8354 " please upgrade BC\n", BNX2X_BC_VER, val);
8355 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008356 bp->link_params.feature_config_flags |=
8357 (val >= REQ_BC_VER_4_VRFY_OPT_MDL) ?
8358 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
Eilon Greenstein72ce58c32008-08-13 15:52:46 -07008359
8360 if (BP_E1HVN(bp) == 0) {
8361 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8362 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8363 } else {
8364 /* no WOL capability for E1HVN != 0 */
8365 bp->flags |= NO_WOL_FLAG;
8366 }
8367 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +00008368 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008369
8370 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8371 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8372 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8373 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8374
8375 printk(KERN_INFO PFX "part number %X-%X-%X-%X\n",
8376 val, val2, val3, val4);
8377}
8378
8379static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8380 u32 switch_cfg)
8381{
8382 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008383 u32 ext_phy_type;
8384
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008385 switch (switch_cfg) {
8386 case SWITCH_CFG_1G:
8387 BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
8388
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008389 ext_phy_type =
8390 SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008391 switch (ext_phy_type) {
8392 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
8393 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
8394 ext_phy_type);
8395
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008396 bp->port.supported |= (SUPPORTED_10baseT_Half |
8397 SUPPORTED_10baseT_Full |
8398 SUPPORTED_100baseT_Half |
8399 SUPPORTED_100baseT_Full |
8400 SUPPORTED_1000baseT_Full |
8401 SUPPORTED_2500baseX_Full |
8402 SUPPORTED_TP |
8403 SUPPORTED_FIBRE |
8404 SUPPORTED_Autoneg |
8405 SUPPORTED_Pause |
8406 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008407 break;
8408
8409 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
8410 BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
8411 ext_phy_type);
8412
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008413 bp->port.supported |= (SUPPORTED_10baseT_Half |
8414 SUPPORTED_10baseT_Full |
8415 SUPPORTED_100baseT_Half |
8416 SUPPORTED_100baseT_Full |
8417 SUPPORTED_1000baseT_Full |
8418 SUPPORTED_TP |
8419 SUPPORTED_FIBRE |
8420 SUPPORTED_Autoneg |
8421 SUPPORTED_Pause |
8422 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008423 break;
8424
8425 default:
8426 BNX2X_ERR("NVRAM config error. "
8427 "BAD SerDes ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008428 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008429 return;
8430 }
8431
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008432 bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
8433 port*0x10);
8434 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008435 break;
8436
8437 case SWITCH_CFG_10G:
8438 BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
8439
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008440 ext_phy_type =
8441 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008442 switch (ext_phy_type) {
8443 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8444 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
8445 ext_phy_type);
8446
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008447 bp->port.supported |= (SUPPORTED_10baseT_Half |
8448 SUPPORTED_10baseT_Full |
8449 SUPPORTED_100baseT_Half |
8450 SUPPORTED_100baseT_Full |
8451 SUPPORTED_1000baseT_Full |
8452 SUPPORTED_2500baseX_Full |
8453 SUPPORTED_10000baseT_Full |
8454 SUPPORTED_TP |
8455 SUPPORTED_FIBRE |
8456 SUPPORTED_Autoneg |
8457 SUPPORTED_Pause |
8458 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008459 break;
8460
Eliezer Tamirf1410642008-02-28 11:51:50 -08008461 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
8462 BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
8463 ext_phy_type);
8464
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008465 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8466 SUPPORTED_1000baseT_Full |
8467 SUPPORTED_FIBRE |
8468 SUPPORTED_Autoneg |
8469 SUPPORTED_Pause |
8470 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08008471 break;
8472
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008473 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
8474 BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
8475 ext_phy_type);
8476
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008477 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8478 SUPPORTED_2500baseX_Full |
8479 SUPPORTED_1000baseT_Full |
8480 SUPPORTED_FIBRE |
8481 SUPPORTED_Autoneg |
8482 SUPPORTED_Pause |
8483 SUPPORTED_Asym_Pause);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008484 break;
8485
Eilon Greenstein589abe32009-02-12 08:36:55 +00008486 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
8487 BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
8488 ext_phy_type);
8489
8490 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8491 SUPPORTED_FIBRE |
8492 SUPPORTED_Pause |
8493 SUPPORTED_Asym_Pause);
8494 break;
8495
8496 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
8497 BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
8498 ext_phy_type);
8499
8500 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8501 SUPPORTED_1000baseT_Full |
8502 SUPPORTED_FIBRE |
8503 SUPPORTED_Pause |
8504 SUPPORTED_Asym_Pause);
8505 break;
8506
8507 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8508 BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
8509 ext_phy_type);
8510
8511 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8512 SUPPORTED_1000baseT_Full |
8513 SUPPORTED_Autoneg |
8514 SUPPORTED_FIBRE |
8515 SUPPORTED_Pause |
8516 SUPPORTED_Asym_Pause);
8517 break;
8518
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008519 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8520 BNX2X_DEV_INFO("ext_phy_type 0x%x (8727)\n",
8521 ext_phy_type);
8522
8523 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8524 SUPPORTED_1000baseT_Full |
8525 SUPPORTED_Autoneg |
8526 SUPPORTED_FIBRE |
8527 SUPPORTED_Pause |
8528 SUPPORTED_Asym_Pause);
8529 break;
8530
Eliezer Tamirf1410642008-02-28 11:51:50 -08008531 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
8532 BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
8533 ext_phy_type);
8534
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008535 bp->port.supported |= (SUPPORTED_10000baseT_Full |
8536 SUPPORTED_TP |
8537 SUPPORTED_Autoneg |
8538 SUPPORTED_Pause |
8539 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08008540 break;
8541
Eilon Greenstein28577182009-02-12 08:37:00 +00008542 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
8543 BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
8544 ext_phy_type);
8545
8546 bp->port.supported |= (SUPPORTED_10baseT_Half |
8547 SUPPORTED_10baseT_Full |
8548 SUPPORTED_100baseT_Half |
8549 SUPPORTED_100baseT_Full |
8550 SUPPORTED_1000baseT_Full |
8551 SUPPORTED_10000baseT_Full |
8552 SUPPORTED_TP |
8553 SUPPORTED_Autoneg |
8554 SUPPORTED_Pause |
8555 SUPPORTED_Asym_Pause);
8556 break;
8557
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008558 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8559 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
8560 bp->link_params.ext_phy_config);
8561 break;
8562
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008563 default:
8564 BNX2X_ERR("NVRAM config error. "
8565 "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008566 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008567 return;
8568 }
8569
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008570 bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
8571 port*0x18);
8572 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008573
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008574 break;
8575
8576 default:
8577 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008578 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008579 return;
8580 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008581 bp->link_params.phy_addr = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008582
8583 /* mask what we support according to speed_cap_mask */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008584 if (!(bp->link_params.speed_cap_mask &
8585 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008586 bp->port.supported &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008587
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008588 if (!(bp->link_params.speed_cap_mask &
8589 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008590 bp->port.supported &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008591
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008592 if (!(bp->link_params.speed_cap_mask &
8593 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008594 bp->port.supported &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008595
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008596 if (!(bp->link_params.speed_cap_mask &
8597 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008598 bp->port.supported &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008599
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008600 if (!(bp->link_params.speed_cap_mask &
8601 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008602 bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
8603 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008604
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008605 if (!(bp->link_params.speed_cap_mask &
8606 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008607 bp->port.supported &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008608
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008609 if (!(bp->link_params.speed_cap_mask &
8610 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008611 bp->port.supported &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008612
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008613 BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008614}
8615
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008616static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008617{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008618 bp->link_params.req_duplex = DUPLEX_FULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008619
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008620 switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008621 case PORT_FEATURE_LINK_SPEED_AUTO:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008622 if (bp->port.supported & SUPPORTED_Autoneg) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008623 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008624 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008625 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008626 u32 ext_phy_type =
8627 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
8628
8629 if ((ext_phy_type ==
8630 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
8631 (ext_phy_type ==
8632 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008633 /* force 10G, no AN */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008634 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008635 bp->port.advertising =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008636 (ADVERTISED_10000baseT_Full |
8637 ADVERTISED_FIBRE);
8638 break;
8639 }
8640 BNX2X_ERR("NVRAM config error. "
8641 "Invalid link_config 0x%x"
8642 " Autoneg not supported\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008643 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008644 return;
8645 }
8646 break;
8647
8648 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008649 if (bp->port.supported & SUPPORTED_10baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008650 bp->link_params.req_line_speed = SPEED_10;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008651 bp->port.advertising = (ADVERTISED_10baseT_Full |
8652 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008653 } else {
8654 BNX2X_ERR("NVRAM config error. "
8655 "Invalid link_config 0x%x"
8656 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008657 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008658 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008659 return;
8660 }
8661 break;
8662
8663 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008664 if (bp->port.supported & SUPPORTED_10baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008665 bp->link_params.req_line_speed = SPEED_10;
8666 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008667 bp->port.advertising = (ADVERTISED_10baseT_Half |
8668 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008669 } else {
8670 BNX2X_ERR("NVRAM config error. "
8671 "Invalid link_config 0x%x"
8672 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008673 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008674 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008675 return;
8676 }
8677 break;
8678
8679 case PORT_FEATURE_LINK_SPEED_100M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008680 if (bp->port.supported & SUPPORTED_100baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008681 bp->link_params.req_line_speed = SPEED_100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008682 bp->port.advertising = (ADVERTISED_100baseT_Full |
8683 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008684 } else {
8685 BNX2X_ERR("NVRAM config error. "
8686 "Invalid link_config 0x%x"
8687 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008688 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008689 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008690 return;
8691 }
8692 break;
8693
8694 case PORT_FEATURE_LINK_SPEED_100M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008695 if (bp->port.supported & SUPPORTED_100baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008696 bp->link_params.req_line_speed = SPEED_100;
8697 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008698 bp->port.advertising = (ADVERTISED_100baseT_Half |
8699 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008700 } else {
8701 BNX2X_ERR("NVRAM config error. "
8702 "Invalid link_config 0x%x"
8703 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008704 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008705 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008706 return;
8707 }
8708 break;
8709
8710 case PORT_FEATURE_LINK_SPEED_1G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008711 if (bp->port.supported & SUPPORTED_1000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008712 bp->link_params.req_line_speed = SPEED_1000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008713 bp->port.advertising = (ADVERTISED_1000baseT_Full |
8714 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008715 } else {
8716 BNX2X_ERR("NVRAM config error. "
8717 "Invalid link_config 0x%x"
8718 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008719 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008720 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008721 return;
8722 }
8723 break;
8724
8725 case PORT_FEATURE_LINK_SPEED_2_5G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008726 if (bp->port.supported & SUPPORTED_2500baseX_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008727 bp->link_params.req_line_speed = SPEED_2500;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008728 bp->port.advertising = (ADVERTISED_2500baseX_Full |
8729 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008730 } else {
8731 BNX2X_ERR("NVRAM config error. "
8732 "Invalid link_config 0x%x"
8733 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008734 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008735 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008736 return;
8737 }
8738 break;
8739
8740 case PORT_FEATURE_LINK_SPEED_10G_CX4:
8741 case PORT_FEATURE_LINK_SPEED_10G_KX4:
8742 case PORT_FEATURE_LINK_SPEED_10G_KR:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008743 if (bp->port.supported & SUPPORTED_10000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008744 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008745 bp->port.advertising = (ADVERTISED_10000baseT_Full |
8746 ADVERTISED_FIBRE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008747 } else {
8748 BNX2X_ERR("NVRAM config error. "
8749 "Invalid link_config 0x%x"
8750 " speed_cap_mask 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008751 bp->port.link_config,
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008752 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008753 return;
8754 }
8755 break;
8756
8757 default:
8758 BNX2X_ERR("NVRAM config error. "
8759 "BAD link speed link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008760 bp->port.link_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008761 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008762 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008763 break;
8764 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008765
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008766 bp->link_params.req_flow_ctrl = (bp->port.link_config &
8767 PORT_FEATURE_FLOW_CONTROL_MASK);
David S. Millerc0700f92008-12-16 23:53:20 -08008768 if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Randy Dunlap4ab84d42008-08-07 20:33:19 -07008769 !(bp->port.supported & SUPPORTED_Autoneg))
David S. Millerc0700f92008-12-16 23:53:20 -08008770 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008771
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008772 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
Eliezer Tamirf1410642008-02-28 11:51:50 -08008773 " advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008774 bp->link_params.req_line_speed,
8775 bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008776 bp->link_params.req_flow_ctrl, bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008777}
8778
Michael Chane665bfd2009-10-10 13:46:54 +00008779static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
8780{
8781 mac_hi = cpu_to_be16(mac_hi);
8782 mac_lo = cpu_to_be32(mac_lo);
8783 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
8784 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
8785}
8786
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008787static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008788{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008789 int port = BP_PORT(bp);
8790 u32 val, val2;
Eilon Greenstein589abe32009-02-12 08:36:55 +00008791 u32 config;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008792 u16 i;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008793 u32 ext_phy_type;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008794
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008795 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008796 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008797
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008798 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008799 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008800 bp->link_params.ext_phy_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008801 SHMEM_RD(bp,
8802 dev_info.port_hw_config[port].external_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008803 /* BCM8727_NOC => BCM8727 no over current */
8804 if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
8805 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC) {
8806 bp->link_params.ext_phy_config &=
8807 ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
8808 bp->link_params.ext_phy_config |=
8809 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727;
8810 bp->link_params.feature_config_flags |=
8811 FEATURE_CONFIG_BCM8727_NOC;
8812 }
8813
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008814 bp->link_params.speed_cap_mask =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008815 SHMEM_RD(bp,
8816 dev_info.port_hw_config[port].speed_capability_mask);
8817
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008818 bp->port.link_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008819 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8820
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008821 /* Get the 4 lanes xgxs config rx and tx */
8822 for (i = 0; i < 2; i++) {
8823 val = SHMEM_RD(bp,
8824 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
8825 bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
8826 bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
8827
8828 val = SHMEM_RD(bp,
8829 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
8830 bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
8831 bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
8832 }
8833
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008834 /* If the device is capable of WoL, set the default state according
8835 * to the HW
8836 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008837 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008838 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8839 (config & PORT_FEATURE_WOL_ENABLED));
8840
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008841 BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
8842 " speed_cap_mask 0x%08x link_config 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008843 bp->link_params.lane_config,
8844 bp->link_params.ext_phy_config,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008845 bp->link_params.speed_cap_mask, bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008846
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008847 bp->link_params.switch_cfg |= (bp->port.link_config &
8848 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008849 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008850
8851 bnx2x_link_settings_requested(bp);
8852
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008853 /*
8854 * If connected directly, work with the internal PHY, otherwise, work
8855 * with the external PHY
8856 */
8857 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
8858 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
8859 bp->mdio.prtad = bp->link_params.phy_addr;
8860
8861 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
8862 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
8863 bp->mdio.prtad =
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00008864 XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008865
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008866 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8867 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
Michael Chane665bfd2009-10-10 13:46:54 +00008868 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008869 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8870 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +00008871
8872#ifdef BCM_CNIC
8873 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_upper);
8874 val = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_lower);
8875 bnx2x_set_mac_buf(bp->iscsi_mac, val, val2);
8876#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008877}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008878
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008879static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8880{
8881 int func = BP_FUNC(bp);
8882 u32 val, val2;
8883 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008884
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008885 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008886
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008887 bp->e1hov = 0;
8888 bp->e1hmf = 0;
8889 if (CHIP_IS_E1H(bp)) {
8890 bp->mf_config =
8891 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008892
Eilon Greenstein2691d512009-08-12 08:22:08 +00008893 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[FUNC_0].e1hov_tag) &
Eilon Greenstein3196a882008-08-13 15:58:49 -07008894 FUNC_MF_CFG_E1HOV_TAG_MASK);
Eilon Greenstein2691d512009-08-12 08:22:08 +00008895 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008896 bp->e1hmf = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008897 BNX2X_DEV_INFO("%s function mode\n",
8898 IS_E1HMF(bp) ? "multi" : "single");
8899
8900 if (IS_E1HMF(bp)) {
8901 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].
8902 e1hov_tag) &
8903 FUNC_MF_CFG_E1HOV_TAG_MASK);
8904 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
8905 bp->e1hov = val;
8906 BNX2X_DEV_INFO("E1HOV for func %d is %d "
8907 "(0x%04x)\n",
8908 func, bp->e1hov, bp->e1hov);
8909 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008910 BNX2X_ERR("!!! No valid E1HOV for func %d,"
8911 " aborting\n", func);
8912 rc = -EPERM;
8913 }
Eilon Greenstein2691d512009-08-12 08:22:08 +00008914 } else {
8915 if (BP_E1HVN(bp)) {
8916 BNX2X_ERR("!!! VN %d in single function mode,"
8917 " aborting\n", BP_E1HVN(bp));
8918 rc = -EPERM;
8919 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008920 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008921 }
8922
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008923 if (!BP_NOMCP(bp)) {
8924 bnx2x_get_port_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008925
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008926 bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
8927 DRV_MSG_SEQ_NUMBER_MASK);
8928 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
8929 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008930
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008931 if (IS_E1HMF(bp)) {
8932 val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
8933 val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
8934 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8935 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
8936 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
8937 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8938 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8939 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8940 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8941 bp->dev->dev_addr[5] = (u8)(val & 0xff);
8942 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
8943 ETH_ALEN);
8944 memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
8945 ETH_ALEN);
8946 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008947
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008948 return rc;
8949 }
8950
8951 if (BP_NOMCP(bp)) {
8952 /* only supposed to happen on emulation/FPGA */
Eilon Greenstein33471622008-08-13 15:59:08 -07008953 BNX2X_ERR("warning random MAC workaround active\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008954 random_ether_addr(bp->dev->dev_addr);
8955 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8956 }
8957
8958 return rc;
8959}
8960
8961static int __devinit bnx2x_init_bp(struct bnx2x *bp)
8962{
8963 int func = BP_FUNC(bp);
Eilon Greenstein87942b42009-02-12 08:36:49 +00008964 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008965 int rc;
8966
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008967 /* Disable interrupt handling until HW is initialized */
8968 atomic_set(&bp->intr_sem, 1);
Eilon Greensteine1510702009-07-21 05:47:41 +00008969 smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008970
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008971 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07008972 mutex_init(&bp->fw_mb_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +00008973#ifdef BCM_CNIC
8974 mutex_init(&bp->cnic_mutex);
8975#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008976
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08008977 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008978 INIT_WORK(&bp->reset_task, bnx2x_reset_task);
8979
8980 rc = bnx2x_get_hwinfo(bp);
8981
8982 /* need to reset chip if undi was active */
8983 if (!BP_NOMCP(bp))
8984 bnx2x_undi_unload(bp);
8985
8986 if (CHIP_REV_IS_FPGA(bp))
8987 printk(KERN_ERR PFX "FPGA detected\n");
8988
8989 if (BP_NOMCP(bp) && (func == 0))
8990 printk(KERN_ERR PFX
8991 "MCP disabled, must load devices in order!\n");
8992
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008993 /* Set multi queue mode */
Eilon Greenstein8badd272009-02-12 08:36:15 +00008994 if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
8995 ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008996 printk(KERN_ERR PFX
Eilon Greenstein8badd272009-02-12 08:36:15 +00008997 "Multi disabled since int_mode requested is not MSI-X\n");
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008998 multi_mode = ETH_RSS_MODE_DISABLED;
8999 }
9000 bp->multi_mode = multi_mode;
9001
9002
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009003 /* Set TPA flags */
9004 if (disable_tpa) {
9005 bp->flags &= ~TPA_ENABLE_FLAG;
9006 bp->dev->features &= ~NETIF_F_LRO;
9007 } else {
9008 bp->flags |= TPA_ENABLE_FLAG;
9009 bp->dev->features |= NETIF_F_LRO;
9010 }
9011
Eilon Greensteina18f5122009-08-12 08:23:26 +00009012 if (CHIP_IS_E1(bp))
9013 bp->dropless_fc = 0;
9014 else
9015 bp->dropless_fc = dropless_fc;
9016
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00009017 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009018
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009019 bp->tx_ring_size = MAX_TX_AVAIL;
9020 bp->rx_ring_size = MAX_RX_AVAIL;
9021
9022 bp->rx_csum = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009023
9024 bp->tx_ticks = 50;
9025 bp->rx_ticks = 25;
9026
Eilon Greenstein87942b42009-02-12 08:36:49 +00009027 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9028 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009029
9030 init_timer(&bp->timer);
9031 bp->timer.expires = jiffies + bp->current_interval;
9032 bp->timer.data = (unsigned long) bp;
9033 bp->timer.function = bnx2x_timer;
9034
9035 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009036}
9037
9038/*
9039 * ethtool service functions
9040 */
9041
9042/* All ethtool functions called with rtnl_lock */
9043
9044static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
9045{
9046 struct bnx2x *bp = netdev_priv(dev);
9047
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009048 cmd->supported = bp->port.supported;
9049 cmd->advertising = bp->port.advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009050
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07009051 if ((bp->state == BNX2X_STATE_OPEN) &&
9052 !(bp->flags & MF_FUNC_DIS) &&
9053 (bp->link_vars.link_up)) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009054 cmd->speed = bp->link_vars.line_speed;
9055 cmd->duplex = bp->link_vars.duplex;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07009056 if (IS_E1HMF(bp)) {
9057 u16 vn_max_rate;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009058
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07009059 vn_max_rate =
9060 ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009061 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07009062 if (vn_max_rate < cmd->speed)
9063 cmd->speed = vn_max_rate;
9064 }
9065 } else {
9066 cmd->speed = -1;
9067 cmd->duplex = -1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009068 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009069
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009070 if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
9071 u32 ext_phy_type =
9072 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamirf1410642008-02-28 11:51:50 -08009073
9074 switch (ext_phy_type) {
9075 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009076 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009077 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greenstein589abe32009-02-12 08:36:55 +00009078 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
9079 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
9080 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00009081 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009082 cmd->port = PORT_FIBRE;
9083 break;
9084
9085 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein28577182009-02-12 08:37:00 +00009086 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009087 cmd->port = PORT_TP;
9088 break;
9089
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009090 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
9091 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
9092 bp->link_params.ext_phy_config);
9093 break;
9094
Eliezer Tamirf1410642008-02-28 11:51:50 -08009095 default:
9096 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009097 bp->link_params.ext_phy_config);
9098 break;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009099 }
9100 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009101 cmd->port = PORT_TP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009102
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009103 cmd->phy_address = bp->mdio.prtad;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009104 cmd->transceiver = XCVR_INTERNAL;
9105
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009106 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009107 cmd->autoneg = AUTONEG_ENABLE;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009108 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009109 cmd->autoneg = AUTONEG_DISABLE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009110
9111 cmd->maxtxpkt = 0;
9112 cmd->maxrxpkt = 0;
9113
9114 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
9115 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
9116 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
9117 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
9118 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
9119 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
9120 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
9121
9122 return 0;
9123}
9124
9125static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
9126{
9127 struct bnx2x *bp = netdev_priv(dev);
9128 u32 advertising;
9129
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009130 if (IS_E1HMF(bp))
9131 return 0;
9132
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009133 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
9134 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
9135 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
9136 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
9137 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
9138 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
9139 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
9140
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009141 if (cmd->autoneg == AUTONEG_ENABLE) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009142 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
9143 DP(NETIF_MSG_LINK, "Autoneg not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009144 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009145 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009146
9147 /* advertise the requested speed and duplex if supported */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009148 cmd->advertising &= bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009149
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009150 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
9151 bp->link_params.req_duplex = DUPLEX_FULL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009152 bp->port.advertising |= (ADVERTISED_Autoneg |
9153 cmd->advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009154
9155 } else { /* forced speed */
9156 /* advertise the requested speed and duplex if supported */
9157 switch (cmd->speed) {
9158 case SPEED_10:
9159 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009160 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08009161 SUPPORTED_10baseT_Full)) {
9162 DP(NETIF_MSG_LINK,
9163 "10M full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009164 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009165 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009166
9167 advertising = (ADVERTISED_10baseT_Full |
9168 ADVERTISED_TP);
9169 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009170 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08009171 SUPPORTED_10baseT_Half)) {
9172 DP(NETIF_MSG_LINK,
9173 "10M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009174 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009175 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009176
9177 advertising = (ADVERTISED_10baseT_Half |
9178 ADVERTISED_TP);
9179 }
9180 break;
9181
9182 case SPEED_100:
9183 if (cmd->duplex == DUPLEX_FULL) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009184 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08009185 SUPPORTED_100baseT_Full)) {
9186 DP(NETIF_MSG_LINK,
9187 "100M full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009188 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009189 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009190
9191 advertising = (ADVERTISED_100baseT_Full |
9192 ADVERTISED_TP);
9193 } else {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009194 if (!(bp->port.supported &
Eliezer Tamirf1410642008-02-28 11:51:50 -08009195 SUPPORTED_100baseT_Half)) {
9196 DP(NETIF_MSG_LINK,
9197 "100M half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009198 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009199 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009200
9201 advertising = (ADVERTISED_100baseT_Half |
9202 ADVERTISED_TP);
9203 }
9204 break;
9205
9206 case SPEED_1000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009207 if (cmd->duplex != DUPLEX_FULL) {
9208 DP(NETIF_MSG_LINK, "1G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009209 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009210 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009211
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009212 if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08009213 DP(NETIF_MSG_LINK, "1G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009214 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009215 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009216
9217 advertising = (ADVERTISED_1000baseT_Full |
9218 ADVERTISED_TP);
9219 break;
9220
9221 case SPEED_2500:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009222 if (cmd->duplex != DUPLEX_FULL) {
9223 DP(NETIF_MSG_LINK,
9224 "2.5G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009225 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009226 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009227
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009228 if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08009229 DP(NETIF_MSG_LINK,
9230 "2.5G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009231 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009232 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009233
Eliezer Tamirf1410642008-02-28 11:51:50 -08009234 advertising = (ADVERTISED_2500baseX_Full |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009235 ADVERTISED_TP);
9236 break;
9237
9238 case SPEED_10000:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009239 if (cmd->duplex != DUPLEX_FULL) {
9240 DP(NETIF_MSG_LINK, "10G half not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009241 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009242 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009243
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009244 if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08009245 DP(NETIF_MSG_LINK, "10G full not supported\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009246 return -EINVAL;
Eliezer Tamirf1410642008-02-28 11:51:50 -08009247 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009248
9249 advertising = (ADVERTISED_10000baseT_Full |
9250 ADVERTISED_FIBRE);
9251 break;
9252
9253 default:
Eliezer Tamirf1410642008-02-28 11:51:50 -08009254 DP(NETIF_MSG_LINK, "Unsupported speed\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009255 return -EINVAL;
9256 }
9257
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009258 bp->link_params.req_line_speed = cmd->speed;
9259 bp->link_params.req_duplex = cmd->duplex;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009260 bp->port.advertising = advertising;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009261 }
9262
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009263 DP(NETIF_MSG_LINK, "req_line_speed %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009264 DP_LEVEL " req_duplex %d advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009265 bp->link_params.req_line_speed, bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009266 bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009267
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009268 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009269 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009270 bnx2x_link_set(bp);
9271 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009272
9273 return 0;
9274}
9275
Eilon Greenstein0a64ea52009-03-02 08:01:12 +00009276#define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
9277#define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
9278
9279static int bnx2x_get_regs_len(struct net_device *dev)
9280{
Eilon Greenstein0a64ea52009-03-02 08:01:12 +00009281 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein0d28e492009-08-12 08:23:40 +00009282 int regdump_len = 0;
Eilon Greenstein0a64ea52009-03-02 08:01:12 +00009283 int i;
9284
Eilon Greenstein0a64ea52009-03-02 08:01:12 +00009285 if (CHIP_IS_E1(bp)) {
9286 for (i = 0; i < REGS_COUNT; i++)
9287 if (IS_E1_ONLINE(reg_addrs[i].info))
9288 regdump_len += reg_addrs[i].size;
9289
9290 for (i = 0; i < WREGS_COUNT_E1; i++)
9291 if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
9292 regdump_len += wreg_addrs_e1[i].size *
9293 (1 + wreg_addrs_e1[i].read_regs_count);
9294
9295 } else { /* E1H */
9296 for (i = 0; i < REGS_COUNT; i++)
9297 if (IS_E1H_ONLINE(reg_addrs[i].info))
9298 regdump_len += reg_addrs[i].size;
9299
9300 for (i = 0; i < WREGS_COUNT_E1H; i++)
9301 if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
9302 regdump_len += wreg_addrs_e1h[i].size *
9303 (1 + wreg_addrs_e1h[i].read_regs_count);
9304 }
9305 regdump_len *= 4;
9306 regdump_len += sizeof(struct dump_hdr);
9307
9308 return regdump_len;
9309}
9310
9311static void bnx2x_get_regs(struct net_device *dev,
9312 struct ethtool_regs *regs, void *_p)
9313{
9314 u32 *p = _p, i, j;
9315 struct bnx2x *bp = netdev_priv(dev);
9316 struct dump_hdr dump_hdr = {0};
9317
9318 regs->version = 0;
9319 memset(p, 0, regs->len);
9320
9321 if (!netif_running(bp->dev))
9322 return;
9323
9324 dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
9325 dump_hdr.dump_sign = dump_sign_all;
9326 dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
9327 dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
9328 dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
9329 dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
9330 dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE;
9331
9332 memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
9333 p += dump_hdr.hdr_size + 1;
9334
9335 if (CHIP_IS_E1(bp)) {
9336 for (i = 0; i < REGS_COUNT; i++)
9337 if (IS_E1_ONLINE(reg_addrs[i].info))
9338 for (j = 0; j < reg_addrs[i].size; j++)
9339 *p++ = REG_RD(bp,
9340 reg_addrs[i].addr + j*4);
9341
9342 } else { /* E1H */
9343 for (i = 0; i < REGS_COUNT; i++)
9344 if (IS_E1H_ONLINE(reg_addrs[i].info))
9345 for (j = 0; j < reg_addrs[i].size; j++)
9346 *p++ = REG_RD(bp,
9347 reg_addrs[i].addr + j*4);
9348 }
9349}
9350
Eilon Greenstein0d28e492009-08-12 08:23:40 +00009351#define PHY_FW_VER_LEN 10
9352
9353static void bnx2x_get_drvinfo(struct net_device *dev,
9354 struct ethtool_drvinfo *info)
9355{
9356 struct bnx2x *bp = netdev_priv(dev);
9357 u8 phy_fw_ver[PHY_FW_VER_LEN];
9358
9359 strcpy(info->driver, DRV_MODULE_NAME);
9360 strcpy(info->version, DRV_MODULE_VERSION);
9361
9362 phy_fw_ver[0] = '\0';
9363 if (bp->port.pmf) {
9364 bnx2x_acquire_phy_lock(bp);
9365 bnx2x_get_ext_phy_fw_version(&bp->link_params,
9366 (bp->state != BNX2X_STATE_CLOSED),
9367 phy_fw_ver, PHY_FW_VER_LEN);
9368 bnx2x_release_phy_lock(bp);
9369 }
9370
9371 snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s",
9372 (bp->common.bc_ver & 0xff0000) >> 16,
9373 (bp->common.bc_ver & 0xff00) >> 8,
9374 (bp->common.bc_ver & 0xff),
9375 ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver);
9376 strcpy(info->bus_info, pci_name(bp->pdev));
9377 info->n_stats = BNX2X_NUM_STATS;
9378 info->testinfo_len = BNX2X_NUM_TESTS;
9379 info->eedump_len = bp->common.flash_size;
9380 info->regdump_len = bnx2x_get_regs_len(dev);
9381}
9382
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009383static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9384{
9385 struct bnx2x *bp = netdev_priv(dev);
9386
9387 if (bp->flags & NO_WOL_FLAG) {
9388 wol->supported = 0;
9389 wol->wolopts = 0;
9390 } else {
9391 wol->supported = WAKE_MAGIC;
9392 if (bp->wol)
9393 wol->wolopts = WAKE_MAGIC;
9394 else
9395 wol->wolopts = 0;
9396 }
9397 memset(&wol->sopass, 0, sizeof(wol->sopass));
9398}
9399
9400static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9401{
9402 struct bnx2x *bp = netdev_priv(dev);
9403
9404 if (wol->wolopts & ~WAKE_MAGIC)
9405 return -EINVAL;
9406
9407 if (wol->wolopts & WAKE_MAGIC) {
9408 if (bp->flags & NO_WOL_FLAG)
9409 return -EINVAL;
9410
9411 bp->wol = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009412 } else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009413 bp->wol = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009414
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009415 return 0;
9416}
9417
9418static u32 bnx2x_get_msglevel(struct net_device *dev)
9419{
9420 struct bnx2x *bp = netdev_priv(dev);
9421
9422 return bp->msglevel;
9423}
9424
9425static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
9426{
9427 struct bnx2x *bp = netdev_priv(dev);
9428
9429 if (capable(CAP_NET_ADMIN))
9430 bp->msglevel = level;
9431}
9432
9433static int bnx2x_nway_reset(struct net_device *dev)
9434{
9435 struct bnx2x *bp = netdev_priv(dev);
9436
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009437 if (!bp->port.pmf)
9438 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009439
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009440 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009441 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009442 bnx2x_link_set(bp);
9443 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009444
9445 return 0;
9446}
9447
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009448static u32 bnx2x_get_link(struct net_device *dev)
Naohiro Ooiwa01e53292009-06-30 12:44:19 -07009449{
9450 struct bnx2x *bp = netdev_priv(dev);
9451
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07009452 if (bp->flags & MF_FUNC_DIS)
9453 return 0;
9454
Naohiro Ooiwa01e53292009-06-30 12:44:19 -07009455 return bp->link_vars.link_up;
9456}
9457
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009458static int bnx2x_get_eeprom_len(struct net_device *dev)
9459{
9460 struct bnx2x *bp = netdev_priv(dev);
9461
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009462 return bp->common.flash_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009463}
9464
9465static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
9466{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009467 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009468 int count, i;
9469 u32 val = 0;
9470
9471 /* adjust timeout for emulation/FPGA */
9472 count = NVRAM_TIMEOUT_COUNT;
9473 if (CHIP_REV_IS_SLOW(bp))
9474 count *= 100;
9475
9476 /* request access to nvram interface */
9477 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9478 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
9479
9480 for (i = 0; i < count*10; i++) {
9481 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
9482 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
9483 break;
9484
9485 udelay(5);
9486 }
9487
9488 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009489 DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009490 return -EBUSY;
9491 }
9492
9493 return 0;
9494}
9495
9496static int bnx2x_release_nvram_lock(struct bnx2x *bp)
9497{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009498 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009499 int count, i;
9500 u32 val = 0;
9501
9502 /* adjust timeout for emulation/FPGA */
9503 count = NVRAM_TIMEOUT_COUNT;
9504 if (CHIP_REV_IS_SLOW(bp))
9505 count *= 100;
9506
9507 /* relinquish nvram interface */
9508 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9509 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
9510
9511 for (i = 0; i < count*10; i++) {
9512 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
9513 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
9514 break;
9515
9516 udelay(5);
9517 }
9518
9519 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009520 DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009521 return -EBUSY;
9522 }
9523
9524 return 0;
9525}
9526
9527static void bnx2x_enable_nvram_access(struct bnx2x *bp)
9528{
9529 u32 val;
9530
9531 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
9532
9533 /* enable both bits, even on read */
9534 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
9535 (val | MCPR_NVM_ACCESS_ENABLE_EN |
9536 MCPR_NVM_ACCESS_ENABLE_WR_EN));
9537}
9538
9539static void bnx2x_disable_nvram_access(struct bnx2x *bp)
9540{
9541 u32 val;
9542
9543 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
9544
9545 /* disable both bits, even after read */
9546 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
9547 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
9548 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
9549}
9550
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009551static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009552 u32 cmd_flags)
9553{
Eliezer Tamirf1410642008-02-28 11:51:50 -08009554 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009555 u32 val;
9556
9557 /* build the command word */
9558 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
9559
9560 /* need to clear DONE bit separately */
9561 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
9562
9563 /* address of the NVRAM to read from */
9564 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
9565 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
9566
9567 /* issue a read command */
9568 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
9569
9570 /* adjust timeout for emulation/FPGA */
9571 count = NVRAM_TIMEOUT_COUNT;
9572 if (CHIP_REV_IS_SLOW(bp))
9573 count *= 100;
9574
9575 /* wait for completion */
9576 *ret_val = 0;
9577 rc = -EBUSY;
9578 for (i = 0; i < count; i++) {
9579 udelay(5);
9580 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
9581
9582 if (val & MCPR_NVM_COMMAND_DONE) {
9583 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009584 /* we read nvram data in cpu order
9585 * but ethtool sees it as an array of bytes
9586 * converting to big-endian will do the work */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009587 *ret_val = cpu_to_be32(val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009588 rc = 0;
9589 break;
9590 }
9591 }
9592
9593 return rc;
9594}
9595
9596static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
9597 int buf_size)
9598{
9599 int rc;
9600 u32 cmd_flags;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009601 __be32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009602
9603 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009604 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08009605 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009606 offset, buf_size);
9607 return -EINVAL;
9608 }
9609
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009610 if (offset + buf_size > bp->common.flash_size) {
9611 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009612 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009613 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009614 return -EINVAL;
9615 }
9616
9617 /* request access to nvram interface */
9618 rc = bnx2x_acquire_nvram_lock(bp);
9619 if (rc)
9620 return rc;
9621
9622 /* enable access to nvram interface */
9623 bnx2x_enable_nvram_access(bp);
9624
9625 /* read the first word(s) */
9626 cmd_flags = MCPR_NVM_COMMAND_FIRST;
9627 while ((buf_size > sizeof(u32)) && (rc == 0)) {
9628 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
9629 memcpy(ret_buf, &val, 4);
9630
9631 /* advance to the next dword */
9632 offset += sizeof(u32);
9633 ret_buf += sizeof(u32);
9634 buf_size -= sizeof(u32);
9635 cmd_flags = 0;
9636 }
9637
9638 if (rc == 0) {
9639 cmd_flags |= MCPR_NVM_COMMAND_LAST;
9640 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
9641 memcpy(ret_buf, &val, 4);
9642 }
9643
9644 /* disable access to nvram interface */
9645 bnx2x_disable_nvram_access(bp);
9646 bnx2x_release_nvram_lock(bp);
9647
9648 return rc;
9649}
9650
9651static int bnx2x_get_eeprom(struct net_device *dev,
9652 struct ethtool_eeprom *eeprom, u8 *eebuf)
9653{
9654 struct bnx2x *bp = netdev_priv(dev);
9655 int rc;
9656
Eilon Greenstein2add3ac2009-01-14 06:44:07 +00009657 if (!netif_running(dev))
9658 return -EAGAIN;
9659
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009660 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009661 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
9662 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
9663 eeprom->len, eeprom->len);
9664
9665 /* parameters already validated in ethtool_get_eeprom */
9666
9667 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
9668
9669 return rc;
9670}
9671
9672static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
9673 u32 cmd_flags)
9674{
Eliezer Tamirf1410642008-02-28 11:51:50 -08009675 int count, i, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009676
9677 /* build the command word */
9678 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
9679
9680 /* need to clear DONE bit separately */
9681 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
9682
9683 /* write the data */
9684 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
9685
9686 /* address of the NVRAM to write to */
9687 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
9688 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
9689
9690 /* issue the write command */
9691 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
9692
9693 /* adjust timeout for emulation/FPGA */
9694 count = NVRAM_TIMEOUT_COUNT;
9695 if (CHIP_REV_IS_SLOW(bp))
9696 count *= 100;
9697
9698 /* wait for completion */
9699 rc = -EBUSY;
9700 for (i = 0; i < count; i++) {
9701 udelay(5);
9702 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
9703 if (val & MCPR_NVM_COMMAND_DONE) {
9704 rc = 0;
9705 break;
9706 }
9707 }
9708
9709 return rc;
9710}
9711
Eliezer Tamirf1410642008-02-28 11:51:50 -08009712#define BYTE_OFFSET(offset) (8 * (offset & 0x03))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009713
9714static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
9715 int buf_size)
9716{
9717 int rc;
9718 u32 cmd_flags;
9719 u32 align_offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00009720 __be32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009721
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009722 if (offset + buf_size > bp->common.flash_size) {
9723 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009724 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009725 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009726 return -EINVAL;
9727 }
9728
9729 /* request access to nvram interface */
9730 rc = bnx2x_acquire_nvram_lock(bp);
9731 if (rc)
9732 return rc;
9733
9734 /* enable access to nvram interface */
9735 bnx2x_enable_nvram_access(bp);
9736
9737 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
9738 align_offset = (offset & ~0x03);
9739 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
9740
9741 if (rc == 0) {
9742 val &= ~(0xff << BYTE_OFFSET(offset));
9743 val |= (*data_buf << BYTE_OFFSET(offset));
9744
9745 /* nvram data is returned as an array of bytes
9746 * convert it back to cpu order */
9747 val = be32_to_cpu(val);
9748
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009749 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
9750 cmd_flags);
9751 }
9752
9753 /* disable access to nvram interface */
9754 bnx2x_disable_nvram_access(bp);
9755 bnx2x_release_nvram_lock(bp);
9756
9757 return rc;
9758}
9759
9760static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
9761 int buf_size)
9762{
9763 int rc;
9764 u32 cmd_flags;
9765 u32 val;
9766 u32 written_so_far;
9767
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009768 if (buf_size == 1) /* ethtool */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009769 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009770
9771 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009772 DP(BNX2X_MSG_NVM,
Eliezer Tamirc14423f2008-02-28 11:49:42 -08009773 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009774 offset, buf_size);
9775 return -EINVAL;
9776 }
9777
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009778 if (offset + buf_size > bp->common.flash_size) {
9779 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009780 " buf_size (0x%x) > flash_size (0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009781 offset, buf_size, bp->common.flash_size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009782 return -EINVAL;
9783 }
9784
9785 /* request access to nvram interface */
9786 rc = bnx2x_acquire_nvram_lock(bp);
9787 if (rc)
9788 return rc;
9789
9790 /* enable access to nvram interface */
9791 bnx2x_enable_nvram_access(bp);
9792
9793 written_so_far = 0;
9794 cmd_flags = MCPR_NVM_COMMAND_FIRST;
9795 while ((written_so_far < buf_size) && (rc == 0)) {
9796 if (written_so_far == (buf_size - sizeof(u32)))
9797 cmd_flags |= MCPR_NVM_COMMAND_LAST;
9798 else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
9799 cmd_flags |= MCPR_NVM_COMMAND_LAST;
9800 else if ((offset % NVRAM_PAGE_SIZE) == 0)
9801 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
9802
9803 memcpy(&val, data_buf, 4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009804
9805 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
9806
9807 /* advance to the next dword */
9808 offset += sizeof(u32);
9809 data_buf += sizeof(u32);
9810 written_so_far += sizeof(u32);
9811 cmd_flags = 0;
9812 }
9813
9814 /* disable access to nvram interface */
9815 bnx2x_disable_nvram_access(bp);
9816 bnx2x_release_nvram_lock(bp);
9817
9818 return rc;
9819}
9820
9821static int bnx2x_set_eeprom(struct net_device *dev,
9822 struct ethtool_eeprom *eeprom, u8 *eebuf)
9823{
9824 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinf57a6022009-08-12 08:23:11 +00009825 int port = BP_PORT(bp);
9826 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009827
Eilon Greenstein9f4c9582009-01-08 11:21:43 -08009828 if (!netif_running(dev))
9829 return -EAGAIN;
9830
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009831 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009832 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
9833 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
9834 eeprom->len, eeprom->len);
9835
9836 /* parameters already validated in ethtool_set_eeprom */
9837
Eilon Greensteinf57a6022009-08-12 08:23:11 +00009838 /* PHY eeprom can be accessed only by the PMF */
9839 if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
9840 !bp->port.pmf)
9841 return -EINVAL;
9842
9843 if (eeprom->magic == 0x50485950) {
9844 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
9845 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
9846
9847 bnx2x_acquire_phy_lock(bp);
9848 rc |= bnx2x_link_reset(&bp->link_params,
9849 &bp->link_vars, 0);
9850 if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
9851 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
9852 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
9853 MISC_REGISTERS_GPIO_HIGH, port);
9854 bnx2x_release_phy_lock(bp);
9855 bnx2x_link_report(bp);
9856
9857 } else if (eeprom->magic == 0x50485952) {
9858 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07009859 if (bp->state == BNX2X_STATE_OPEN) {
Eilon Greensteinf57a6022009-08-12 08:23:11 +00009860 bnx2x_acquire_phy_lock(bp);
9861 rc |= bnx2x_link_reset(&bp->link_params,
9862 &bp->link_vars, 1);
9863
9864 rc |= bnx2x_phy_init(&bp->link_params,
9865 &bp->link_vars);
9866 bnx2x_release_phy_lock(bp);
9867 bnx2x_calc_fc_adv(bp);
9868 }
9869 } else if (eeprom->magic == 0x53985943) {
9870 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
9871 if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
9872 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
9873 u8 ext_phy_addr =
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00009874 XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config);
Eilon Greensteinf57a6022009-08-12 08:23:11 +00009875
9876 /* DSP Remove Download Mode */
9877 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
9878 MISC_REGISTERS_GPIO_LOW, port);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009879
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07009880 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009881
Eilon Greensteinf57a6022009-08-12 08:23:11 +00009882 bnx2x_sfx7101_sp_sw_reset(bp, port, ext_phy_addr);
9883
9884 /* wait 0.5 sec to allow it to run */
9885 msleep(500);
9886 bnx2x_ext_phy_hw_reset(bp, port);
9887 msleep(500);
9888 bnx2x_release_phy_lock(bp);
9889 }
9890 } else
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009891 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009892
9893 return rc;
9894}
9895
9896static int bnx2x_get_coalesce(struct net_device *dev,
9897 struct ethtool_coalesce *coal)
9898{
9899 struct bnx2x *bp = netdev_priv(dev);
9900
9901 memset(coal, 0, sizeof(struct ethtool_coalesce));
9902
9903 coal->rx_coalesce_usecs = bp->rx_ticks;
9904 coal->tx_coalesce_usecs = bp->tx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009905
9906 return 0;
9907}
9908
Eilon Greensteinca003922009-08-12 22:53:28 -07009909#define BNX2X_MAX_COALES_TOUT (0xf0*12) /* Maximal coalescing timeout in us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009910static int bnx2x_set_coalesce(struct net_device *dev,
9911 struct ethtool_coalesce *coal)
9912{
9913 struct bnx2x *bp = netdev_priv(dev);
9914
9915 bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
Eilon Greensteinca003922009-08-12 22:53:28 -07009916 if (bp->rx_ticks > BNX2X_MAX_COALES_TOUT)
9917 bp->rx_ticks = BNX2X_MAX_COALES_TOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009918
9919 bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
Eilon Greensteinca003922009-08-12 22:53:28 -07009920 if (bp->tx_ticks > BNX2X_MAX_COALES_TOUT)
9921 bp->tx_ticks = BNX2X_MAX_COALES_TOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009922
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009923 if (netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009924 bnx2x_update_coalesce(bp);
9925
9926 return 0;
9927}
9928
9929static void bnx2x_get_ringparam(struct net_device *dev,
9930 struct ethtool_ringparam *ering)
9931{
9932 struct bnx2x *bp = netdev_priv(dev);
9933
9934 ering->rx_max_pending = MAX_RX_AVAIL;
9935 ering->rx_mini_max_pending = 0;
9936 ering->rx_jumbo_max_pending = 0;
9937
9938 ering->rx_pending = bp->rx_ring_size;
9939 ering->rx_mini_pending = 0;
9940 ering->rx_jumbo_pending = 0;
9941
9942 ering->tx_max_pending = MAX_TX_AVAIL;
9943 ering->tx_pending = bp->tx_ring_size;
9944}
9945
9946static int bnx2x_set_ringparam(struct net_device *dev,
9947 struct ethtool_ringparam *ering)
9948{
9949 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009950 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009951
9952 if ((ering->rx_pending > MAX_RX_AVAIL) ||
9953 (ering->tx_pending > MAX_TX_AVAIL) ||
9954 (ering->tx_pending <= MAX_SKB_FRAGS + 4))
9955 return -EINVAL;
9956
9957 bp->rx_ring_size = ering->rx_pending;
9958 bp->tx_ring_size = ering->tx_pending;
9959
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009960 if (netif_running(dev)) {
9961 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9962 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009963 }
9964
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009965 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009966}
9967
9968static void bnx2x_get_pauseparam(struct net_device *dev,
9969 struct ethtool_pauseparam *epause)
9970{
9971 struct bnx2x *bp = netdev_priv(dev);
9972
Eilon Greenstein356e2382009-02-12 08:38:32 +00009973 epause->autoneg = (bp->link_params.req_flow_ctrl ==
9974 BNX2X_FLOW_CTRL_AUTO) &&
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009975 (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
9976
David S. Millerc0700f92008-12-16 23:53:20 -08009977 epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
9978 BNX2X_FLOW_CTRL_RX);
9979 epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
9980 BNX2X_FLOW_CTRL_TX);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009981
9982 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9983 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9984 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9985}
9986
9987static int bnx2x_set_pauseparam(struct net_device *dev,
9988 struct ethtool_pauseparam *epause)
9989{
9990 struct bnx2x *bp = netdev_priv(dev);
9991
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009992 if (IS_E1HMF(bp))
9993 return 0;
9994
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009995 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
9996 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
9997 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
9998
David S. Millerc0700f92008-12-16 23:53:20 -08009999 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010000
10001 if (epause->rx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -080010002 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010003
10004 if (epause->tx_pause)
David S. Millerc0700f92008-12-16 23:53:20 -080010005 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010006
David S. Millerc0700f92008-12-16 23:53:20 -080010007 if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
10008 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010009
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010010 if (epause->autoneg) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010011 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -070010012 DP(NETIF_MSG_LINK, "autoneg not supported\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -080010013 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010014 }
10015
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010016 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
David S. Millerc0700f92008-12-16 23:53:20 -080010017 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010018 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010019
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010020 DP(NETIF_MSG_LINK,
10021 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010022
10023 if (netif_running(dev)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010024 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010025 bnx2x_link_set(bp);
10026 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010027
10028 return 0;
10029}
10030
Vladislav Zolotarovdf0f23432008-08-13 15:53:38 -070010031static int bnx2x_set_flags(struct net_device *dev, u32 data)
10032{
10033 struct bnx2x *bp = netdev_priv(dev);
10034 int changed = 0;
10035 int rc = 0;
10036
10037 /* TPA requires Rx CSUM offloading */
10038 if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
10039 if (!(dev->features & NETIF_F_LRO)) {
10040 dev->features |= NETIF_F_LRO;
10041 bp->flags |= TPA_ENABLE_FLAG;
10042 changed = 1;
10043 }
10044
10045 } else if (dev->features & NETIF_F_LRO) {
10046 dev->features &= ~NETIF_F_LRO;
10047 bp->flags &= ~TPA_ENABLE_FLAG;
10048 changed = 1;
10049 }
10050
10051 if (changed && netif_running(dev)) {
10052 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
10053 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
10054 }
10055
10056 return rc;
10057}
10058
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010059static u32 bnx2x_get_rx_csum(struct net_device *dev)
10060{
10061 struct bnx2x *bp = netdev_priv(dev);
10062
10063 return bp->rx_csum;
10064}
10065
10066static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
10067{
10068 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovdf0f23432008-08-13 15:53:38 -070010069 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010070
10071 bp->rx_csum = data;
Vladislav Zolotarovdf0f23432008-08-13 15:53:38 -070010072
10073 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
10074 TPA'ed packets will be discarded due to wrong TCP CSUM */
10075 if (!data) {
10076 u32 flags = ethtool_op_get_flags(dev);
10077
10078 rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
10079 }
10080
10081 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010082}
10083
10084static int bnx2x_set_tso(struct net_device *dev, u32 data)
10085{
Eilon Greenstein755735e2008-06-23 20:35:13 -070010086 if (data) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010087 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010088 dev->features |= NETIF_F_TSO6;
10089 } else {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010090 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
Eilon Greenstein755735e2008-06-23 20:35:13 -070010091 dev->features &= ~NETIF_F_TSO6;
10092 }
10093
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010094 return 0;
10095}
10096
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010097static const struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010098 char string[ETH_GSTRING_LEN];
10099} bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010100 { "register_test (offline)" },
10101 { "memory_test (offline)" },
10102 { "loopback_test (offline)" },
10103 { "nvram_test (online)" },
10104 { "interrupt_test (online)" },
10105 { "link_test (online)" },
Eilon Greensteind3d4f492009-02-12 08:36:27 +000010106 { "idle check (online)" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010107};
10108
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010109static int bnx2x_test_registers(struct bnx2x *bp)
10110{
10111 int idx, i, rc = -ENODEV;
10112 u32 wr_val = 0;
Yitchak Gertner9dabc422008-08-13 15:51:28 -070010113 int port = BP_PORT(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010114 static const struct {
10115 u32 offset0;
10116 u32 offset1;
10117 u32 mask;
10118 } reg_tbl[] = {
10119/* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
10120 { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
10121 { HC_REG_AGG_INT_0, 4, 0x000003ff },
10122 { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
10123 { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
10124 { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
10125 { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
10126 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
10127 { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
10128 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
10129/* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
10130 { QM_REG_CONNNUM_0, 4, 0x000fffff },
10131 { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
10132 { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
10133 { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
10134 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
10135 { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
10136 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010137 { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
Eilon Greensteinc1f1a062009-07-29 00:20:08 +000010138 { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
10139/* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010140 { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
10141 { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
10142 { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
10143 { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
10144 { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
10145 { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
10146 { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
10147 { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
Eilon Greensteinc1f1a062009-07-29 00:20:08 +000010148 { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
10149/* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010150 { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
10151 { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
10152 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
10153 { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
10154 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
10155 { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
10156
10157 { 0xffffffff, 0, 0x00000000 }
10158 };
10159
10160 if (!netif_running(bp->dev))
10161 return rc;
10162
10163 /* Repeat the test twice:
10164 First by writing 0x00000000, second by writing 0xffffffff */
10165 for (idx = 0; idx < 2; idx++) {
10166
10167 switch (idx) {
10168 case 0:
10169 wr_val = 0;
10170 break;
10171 case 1:
10172 wr_val = 0xffffffff;
10173 break;
10174 }
10175
10176 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
10177 u32 offset, mask, save_val, val;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010178
10179 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
10180 mask = reg_tbl[i].mask;
10181
10182 save_val = REG_RD(bp, offset);
10183
10184 REG_WR(bp, offset, wr_val);
10185 val = REG_RD(bp, offset);
10186
10187 /* Restore the original register's value */
10188 REG_WR(bp, offset, save_val);
10189
10190 /* verify that value is as expected value */
10191 if ((val & mask) != (wr_val & mask))
10192 goto test_reg_exit;
10193 }
10194 }
10195
10196 rc = 0;
10197
10198test_reg_exit:
10199 return rc;
10200}
10201
10202static int bnx2x_test_memory(struct bnx2x *bp)
10203{
10204 int i, j, rc = -ENODEV;
10205 u32 val;
10206 static const struct {
10207 u32 offset;
10208 int size;
10209 } mem_tbl[] = {
10210 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
10211 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
10212 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
10213 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
10214 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
10215 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
10216 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
10217
10218 { 0xffffffff, 0 }
10219 };
10220 static const struct {
10221 char *name;
10222 u32 offset;
Yitchak Gertner9dabc422008-08-13 15:51:28 -070010223 u32 e1_mask;
10224 u32 e1h_mask;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010225 } prty_tbl[] = {
Yitchak Gertner9dabc422008-08-13 15:51:28 -070010226 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
10227 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
10228 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
10229 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
10230 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
10231 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010232
Yitchak Gertner9dabc422008-08-13 15:51:28 -070010233 { NULL, 0xffffffff, 0, 0 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010234 };
10235
10236 if (!netif_running(bp->dev))
10237 return rc;
10238
10239 /* Go through all the memories */
10240 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
10241 for (j = 0; j < mem_tbl[i].size; j++)
10242 REG_RD(bp, mem_tbl[i].offset + j*4);
10243
10244 /* Check the parity status */
10245 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
10246 val = REG_RD(bp, prty_tbl[i].offset);
Yitchak Gertner9dabc422008-08-13 15:51:28 -070010247 if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
10248 (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010249 DP(NETIF_MSG_HW,
10250 "%s is 0x%x\n", prty_tbl[i].name, val);
10251 goto test_mem_exit;
10252 }
10253 }
10254
10255 rc = 0;
10256
10257test_mem_exit:
10258 return rc;
10259}
10260
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010261static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
10262{
10263 int cnt = 1000;
10264
10265 if (link_up)
10266 while (bnx2x_link_test(bp) && cnt--)
10267 msleep(10);
10268}
10269
10270static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
10271{
10272 unsigned int pkt_size, num_pkts, i;
10273 struct sk_buff *skb;
10274 unsigned char *packet;
Eilon Greensteinca003922009-08-12 22:53:28 -070010275 struct bnx2x_fastpath *fp_rx = &bp->fp[0];
10276 struct bnx2x_fastpath *fp_tx = &bp->fp[bp->num_rx_queues];
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010277 u16 tx_start_idx, tx_idx;
10278 u16 rx_start_idx, rx_idx;
Eilon Greensteinca003922009-08-12 22:53:28 -070010279 u16 pkt_prod, bd_prod;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010280 struct sw_tx_bd *tx_buf;
Eilon Greensteinca003922009-08-12 22:53:28 -070010281 struct eth_tx_start_bd *tx_start_bd;
10282 struct eth_tx_parse_bd *pbd = NULL;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010283 dma_addr_t mapping;
10284 union eth_rx_cqe *cqe;
10285 u8 cqe_fp_flags;
10286 struct sw_rx_bd *rx_buf;
10287 u16 len;
10288 int rc = -ENODEV;
10289
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010290 /* check the loopback mode */
10291 switch (loopback_mode) {
10292 case BNX2X_PHY_LOOPBACK:
10293 if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10)
10294 return -EINVAL;
10295 break;
10296 case BNX2X_MAC_LOOPBACK:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010297 bp->link_params.loopback_mode = LOOPBACK_BMAC;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010298 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010299 break;
10300 default:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010301 return -EINVAL;
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010302 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010303
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010304 /* prepare the loopback packet */
10305 pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
10306 bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010307 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
10308 if (!skb) {
10309 rc = -ENOMEM;
10310 goto test_loopback_exit;
10311 }
10312 packet = skb_put(skb, pkt_size);
10313 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
Eilon Greensteinca003922009-08-12 22:53:28 -070010314 memset(packet + ETH_ALEN, 0, ETH_ALEN);
10315 memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010316 for (i = ETH_HLEN; i < pkt_size; i++)
10317 packet[i] = (unsigned char) (i & 0xff);
10318
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010319 /* send the loopback packet */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010320 num_pkts = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -070010321 tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
10322 rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010323
Eilon Greensteinca003922009-08-12 22:53:28 -070010324 pkt_prod = fp_tx->tx_pkt_prod++;
10325 tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
10326 tx_buf->first_bd = fp_tx->tx_bd_prod;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010327 tx_buf->skb = skb;
Eilon Greensteinca003922009-08-12 22:53:28 -070010328 tx_buf->flags = 0;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010329
Eilon Greensteinca003922009-08-12 22:53:28 -070010330 bd_prod = TX_BD(fp_tx->tx_bd_prod);
10331 tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010332 mapping = pci_map_single(bp->pdev, skb->data,
10333 skb_headlen(skb), PCI_DMA_TODEVICE);
Eilon Greensteinca003922009-08-12 22:53:28 -070010334 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
10335 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
10336 tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
10337 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
10338 tx_start_bd->vlan = cpu_to_le16(pkt_prod);
10339 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
10340 tx_start_bd->general_data = ((UNICAST_ADDRESS <<
10341 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1);
10342
10343 /* turn on parsing and get a BD */
10344 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
10345 pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd;
10346
10347 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010348
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080010349 wmb();
10350
Eilon Greensteinca003922009-08-12 22:53:28 -070010351 fp_tx->tx_db.data.prod += 2;
10352 barrier();
10353 DOORBELL(bp, fp_tx->index - bp->num_rx_queues, fp_tx->tx_db.raw);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010354
10355 mmiowb();
10356
10357 num_pkts++;
Eilon Greensteinca003922009-08-12 22:53:28 -070010358 fp_tx->tx_bd_prod += 2; /* start + pbd */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010359 bp->dev->trans_start = jiffies;
10360
10361 udelay(100);
10362
Eilon Greensteinca003922009-08-12 22:53:28 -070010363 tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010364 if (tx_idx != tx_start_idx + num_pkts)
10365 goto test_loopback_exit;
10366
Eilon Greensteinca003922009-08-12 22:53:28 -070010367 rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010368 if (rx_idx != rx_start_idx + num_pkts)
10369 goto test_loopback_exit;
10370
Eilon Greensteinca003922009-08-12 22:53:28 -070010371 cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010372 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
10373 if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
10374 goto test_loopback_rx_exit;
10375
10376 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
10377 if (len != pkt_size)
10378 goto test_loopback_rx_exit;
10379
Eilon Greensteinca003922009-08-12 22:53:28 -070010380 rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010381 skb = rx_buf->skb;
10382 skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
10383 for (i = ETH_HLEN; i < pkt_size; i++)
10384 if (*(skb->data + i) != (unsigned char) (i & 0xff))
10385 goto test_loopback_rx_exit;
10386
10387 rc = 0;
10388
10389test_loopback_rx_exit:
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010390
Eilon Greensteinca003922009-08-12 22:53:28 -070010391 fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
10392 fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
10393 fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
10394 fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010395
10396 /* Update producers */
Eilon Greensteinca003922009-08-12 22:53:28 -070010397 bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
10398 fp_rx->rx_sge_prod);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010399
10400test_loopback_exit:
10401 bp->link_params.loopback_mode = LOOPBACK_NONE;
10402
10403 return rc;
10404}
10405
10406static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
10407{
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010408 int rc = 0, res;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010409
10410 if (!netif_running(bp->dev))
10411 return BNX2X_LOOPBACK_FAILED;
10412
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010413 bnx2x_netif_stop(bp, 1);
Eilon Greenstein3910c8a2009-01-22 06:01:32 +000010414 bnx2x_acquire_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010415
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010416 res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
10417 if (res) {
10418 DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
10419 rc |= BNX2X_PHY_LOOPBACK_FAILED;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010420 }
10421
Eilon Greensteinb5bf9062009-02-12 08:38:08 +000010422 res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
10423 if (res) {
10424 DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
10425 rc |= BNX2X_MAC_LOOPBACK_FAILED;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010426 }
10427
Eilon Greenstein3910c8a2009-01-22 06:01:32 +000010428 bnx2x_release_phy_lock(bp);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010429 bnx2x_netif_start(bp);
10430
10431 return rc;
10432}
10433
10434#define CRC32_RESIDUAL 0xdebb20e3
10435
10436static int bnx2x_test_nvram(struct bnx2x *bp)
10437{
10438 static const struct {
10439 int offset;
10440 int size;
10441 } nvram_tbl[] = {
10442 { 0, 0x14 }, /* bootstrap */
10443 { 0x14, 0xec }, /* dir */
10444 { 0x100, 0x350 }, /* manuf_info */
10445 { 0x450, 0xf0 }, /* feature_info */
10446 { 0x640, 0x64 }, /* upgrade_key_info */
10447 { 0x6a4, 0x64 },
10448 { 0x708, 0x70 }, /* manuf_key_info */
10449 { 0x778, 0x70 },
10450 { 0, 0 }
10451 };
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000010452 __be32 buf[0x350 / 4];
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010453 u8 *data = (u8 *)buf;
10454 int i, rc;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000010455 u32 magic, crc;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010456
10457 rc = bnx2x_nvram_read(bp, 0, data, 4);
10458 if (rc) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000010459 DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010460 goto test_nvram_exit;
10461 }
10462
10463 magic = be32_to_cpu(buf[0]);
10464 if (magic != 0x669955aa) {
10465 DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
10466 rc = -ENODEV;
10467 goto test_nvram_exit;
10468 }
10469
10470 for (i = 0; nvram_tbl[i].size; i++) {
10471
10472 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
10473 nvram_tbl[i].size);
10474 if (rc) {
10475 DP(NETIF_MSG_PROBE,
Eilon Greensteinf5372252009-02-12 08:38:30 +000010476 "nvram_tbl[%d] read data (rc %d)\n", i, rc);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010477 goto test_nvram_exit;
10478 }
10479
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000010480 crc = ether_crc_le(nvram_tbl[i].size, data);
10481 if (crc != CRC32_RESIDUAL) {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010482 DP(NETIF_MSG_PROBE,
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000010483 "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010484 rc = -ENODEV;
10485 goto test_nvram_exit;
10486 }
10487 }
10488
10489test_nvram_exit:
10490 return rc;
10491}
10492
10493static int bnx2x_test_intr(struct bnx2x *bp)
10494{
10495 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
10496 int i, rc;
10497
10498 if (!netif_running(bp->dev))
10499 return -ENODEV;
10500
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080010501 config->hdr.length = 0;
Eilon Greensteinaf246402009-01-14 06:43:59 +000010502 if (CHIP_IS_E1(bp))
10503 config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
10504 else
10505 config->hdr.offset = BP_FUNC(bp);
Eilon Greenstein0626b892009-02-12 08:38:14 +000010506 config->hdr.client_id = bp->fp->cl_id;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010507 config->hdr.reserved1 = 0;
10508
Michael Chane665bfd2009-10-10 13:46:54 +000010509 bp->set_mac_pending++;
10510 smp_wmb();
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010511 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
10512 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
10513 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
10514 if (rc == 0) {
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010515 for (i = 0; i < 10; i++) {
10516 if (!bp->set_mac_pending)
10517 break;
Michael Chane665bfd2009-10-10 13:46:54 +000010518 smp_rmb();
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010519 msleep_interruptible(10);
10520 }
10521 if (i == 10)
10522 rc = -ENODEV;
10523 }
10524
10525 return rc;
10526}
10527
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010528static void bnx2x_self_test(struct net_device *dev,
10529 struct ethtool_test *etest, u64 *buf)
10530{
10531 struct bnx2x *bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010532
10533 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
10534
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010535 if (!netif_running(dev))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010536 return;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010537
Eilon Greenstein33471622008-08-13 15:59:08 -070010538 /* offline tests are not supported in MF mode */
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010539 if (IS_E1HMF(bp))
10540 etest->flags &= ~ETH_TEST_FL_OFFLINE;
10541
10542 if (etest->flags & ETH_TEST_FL_OFFLINE) {
Eilon Greenstein279abdf2009-07-21 05:47:22 +000010543 int port = BP_PORT(bp);
10544 u32 val;
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010545 u8 link_up;
10546
Eilon Greenstein279abdf2009-07-21 05:47:22 +000010547 /* save current value of input enable for TX port IF */
10548 val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
10549 /* disable input for TX port IF */
10550 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
10551
Eilon Greenstein061bc702009-10-15 00:18:47 -070010552 link_up = (bnx2x_link_test(bp) == 0);
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010553 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
10554 bnx2x_nic_load(bp, LOAD_DIAG);
10555 /* wait until link state is restored */
10556 bnx2x_wait_for_link(bp, link_up);
10557
10558 if (bnx2x_test_registers(bp) != 0) {
10559 buf[0] = 1;
10560 etest->flags |= ETH_TEST_FL_FAILED;
10561 }
10562 if (bnx2x_test_memory(bp) != 0) {
10563 buf[1] = 1;
10564 etest->flags |= ETH_TEST_FL_FAILED;
10565 }
10566 buf[2] = bnx2x_test_loopback(bp, link_up);
10567 if (buf[2] != 0)
10568 etest->flags |= ETH_TEST_FL_FAILED;
10569
10570 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
Eilon Greenstein279abdf2009-07-21 05:47:22 +000010571
10572 /* restore input for TX port IF */
10573 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
10574
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010575 bnx2x_nic_load(bp, LOAD_NORMAL);
10576 /* wait until link state is restored */
10577 bnx2x_wait_for_link(bp, link_up);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010578 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010579 if (bnx2x_test_nvram(bp) != 0) {
10580 buf[3] = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010581 etest->flags |= ETH_TEST_FL_FAILED;
10582 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010583 if (bnx2x_test_intr(bp) != 0) {
10584 buf[4] = 1;
10585 etest->flags |= ETH_TEST_FL_FAILED;
10586 }
10587 if (bp->port.pmf)
10588 if (bnx2x_link_test(bp) != 0) {
10589 buf[5] = 1;
10590 etest->flags |= ETH_TEST_FL_FAILED;
10591 }
Yitchak Gertnerf3c87cd2008-06-23 20:35:51 -070010592
10593#ifdef BNX2X_EXTRA_DEBUG
10594 bnx2x_panic_dump(bp);
10595#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010596}
10597
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010598static const struct {
10599 long offset;
10600 int size;
Eilon Greensteinde832a52009-02-12 08:36:33 +000010601 u8 string[ETH_GSTRING_LEN];
10602} bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
10603/* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
10604 { Q_STATS_OFFSET32(error_bytes_received_hi),
10605 8, "[%d]: rx_error_bytes" },
10606 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
10607 8, "[%d]: rx_ucast_packets" },
10608 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
10609 8, "[%d]: rx_mcast_packets" },
10610 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
10611 8, "[%d]: rx_bcast_packets" },
10612 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
10613 { Q_STATS_OFFSET32(rx_err_discard_pkt),
10614 4, "[%d]: rx_phy_ip_err_discards"},
10615 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
10616 4, "[%d]: rx_skb_alloc_discard" },
10617 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
10618
10619/* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
10620 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
10621 8, "[%d]: tx_packets" }
10622};
10623
10624static const struct {
10625 long offset;
10626 int size;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010627 u32 flags;
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010628#define STATS_FLAGS_PORT 1
10629#define STATS_FLAGS_FUNC 2
Eilon Greensteinde832a52009-02-12 08:36:33 +000010630#define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010631 u8 string[ETH_GSTRING_LEN];
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010632} bnx2x_stats_arr[BNX2X_NUM_STATS] = {
Eilon Greensteinde832a52009-02-12 08:36:33 +000010633/* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
10634 8, STATS_FLAGS_BOTH, "rx_bytes" },
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010635 { STATS_OFFSET32(error_bytes_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +000010636 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010637 { STATS_OFFSET32(total_unicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +000010638 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010639 { STATS_OFFSET32(total_multicast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +000010640 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010641 { STATS_OFFSET32(total_broadcast_packets_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +000010642 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010643 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010644 8, STATS_FLAGS_PORT, "rx_crc_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010645 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010646 8, STATS_FLAGS_PORT, "rx_align_errors" },
Eilon Greensteinde832a52009-02-12 08:36:33 +000010647 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
10648 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
10649 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
10650 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
10651/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
10652 8, STATS_FLAGS_PORT, "rx_fragments" },
10653 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
10654 8, STATS_FLAGS_PORT, "rx_jabbers" },
10655 { STATS_OFFSET32(no_buff_discard_hi),
10656 8, STATS_FLAGS_BOTH, "rx_discards" },
10657 { STATS_OFFSET32(mac_filter_discard),
10658 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
10659 { STATS_OFFSET32(xxoverflow_discard),
10660 4, STATS_FLAGS_PORT, "rx_fw_discards" },
10661 { STATS_OFFSET32(brb_drop_hi),
10662 8, STATS_FLAGS_PORT, "rx_brb_discard" },
10663 { STATS_OFFSET32(brb_truncate_hi),
10664 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
10665 { STATS_OFFSET32(pause_frames_received_hi),
10666 8, STATS_FLAGS_PORT, "rx_pause_frames" },
10667 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
10668 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
10669 { STATS_OFFSET32(nig_timer_max),
10670 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
10671/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
10672 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
10673 { STATS_OFFSET32(rx_skb_alloc_failed),
10674 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
10675 { STATS_OFFSET32(hw_csum_err),
10676 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
10677
10678 { STATS_OFFSET32(total_bytes_transmitted_hi),
10679 8, STATS_FLAGS_BOTH, "tx_bytes" },
10680 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
10681 8, STATS_FLAGS_PORT, "tx_error_bytes" },
10682 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
10683 8, STATS_FLAGS_BOTH, "tx_packets" },
10684 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
10685 8, STATS_FLAGS_PORT, "tx_mac_errors" },
10686 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
10687 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010688 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010689 8, STATS_FLAGS_PORT, "tx_single_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010690 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010691 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
Eilon Greensteinde832a52009-02-12 08:36:33 +000010692/* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010693 8, STATS_FLAGS_PORT, "tx_deferred" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010694 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010695 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010696 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010697 8, STATS_FLAGS_PORT, "tx_late_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010698 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010699 8, STATS_FLAGS_PORT, "tx_total_collisions" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010700 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010701 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010702 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010703 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010704 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010705 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010706 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010707 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010708 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010709 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010710 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010711 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +000010712/* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010713 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
Eilon Greensteinde832a52009-02-12 08:36:33 +000010714 { STATS_OFFSET32(pause_frames_sent_hi),
10715 8, STATS_FLAGS_PORT, "tx_pause_frames" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010716};
10717
Eilon Greensteinde832a52009-02-12 08:36:33 +000010718#define IS_PORT_STAT(i) \
10719 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
10720#define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
10721#define IS_E1HMF_MODE_STAT(bp) \
10722 (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS))
Yitchak Gertner66e855f2008-08-13 15:49:05 -070010723
Ben Hutchings15f0a392009-10-01 11:58:24 +000010724static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
10725{
10726 struct bnx2x *bp = netdev_priv(dev);
10727 int i, num_stats;
10728
10729 switch(stringset) {
10730 case ETH_SS_STATS:
10731 if (is_multi(bp)) {
10732 num_stats = BNX2X_NUM_Q_STATS * bp->num_rx_queues;
10733 if (!IS_E1HMF_MODE_STAT(bp))
10734 num_stats += BNX2X_NUM_STATS;
10735 } else {
10736 if (IS_E1HMF_MODE_STAT(bp)) {
10737 num_stats = 0;
10738 for (i = 0; i < BNX2X_NUM_STATS; i++)
10739 if (IS_FUNC_STAT(i))
10740 num_stats++;
10741 } else
10742 num_stats = BNX2X_NUM_STATS;
10743 }
10744 return num_stats;
10745
10746 case ETH_SS_TEST:
10747 return BNX2X_NUM_TESTS;
10748
10749 default:
10750 return -EINVAL;
10751 }
10752}
10753
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010754static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
10755{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010756 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +000010757 int i, j, k;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010758
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010759 switch (stringset) {
10760 case ETH_SS_STATS:
Eilon Greensteinde832a52009-02-12 08:36:33 +000010761 if (is_multi(bp)) {
10762 k = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -070010763 for_each_rx_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +000010764 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
10765 sprintf(buf + (k + j)*ETH_GSTRING_LEN,
10766 bnx2x_q_stats_arr[j].string, i);
10767 k += BNX2X_NUM_Q_STATS;
10768 }
10769 if (IS_E1HMF_MODE_STAT(bp))
10770 break;
10771 for (j = 0; j < BNX2X_NUM_STATS; j++)
10772 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
10773 bnx2x_stats_arr[j].string);
10774 } else {
10775 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
10776 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
10777 continue;
10778 strcpy(buf + j*ETH_GSTRING_LEN,
10779 bnx2x_stats_arr[i].string);
10780 j++;
10781 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010782 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010783 break;
10784
10785 case ETH_SS_TEST:
10786 memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
10787 break;
10788 }
10789}
10790
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010791static void bnx2x_get_ethtool_stats(struct net_device *dev,
10792 struct ethtool_stats *stats, u64 *buf)
10793{
10794 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinde832a52009-02-12 08:36:33 +000010795 u32 *hw_stats, *offset;
10796 int i, j, k;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010797
Eilon Greensteinde832a52009-02-12 08:36:33 +000010798 if (is_multi(bp)) {
10799 k = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -070010800 for_each_rx_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +000010801 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
10802 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
10803 if (bnx2x_q_stats_arr[j].size == 0) {
10804 /* skip this counter */
10805 buf[k + j] = 0;
10806 continue;
10807 }
10808 offset = (hw_stats +
10809 bnx2x_q_stats_arr[j].offset);
10810 if (bnx2x_q_stats_arr[j].size == 4) {
10811 /* 4-byte counter */
10812 buf[k + j] = (u64) *offset;
10813 continue;
10814 }
10815 /* 8-byte counter */
10816 buf[k + j] = HILO_U64(*offset, *(offset + 1));
10817 }
10818 k += BNX2X_NUM_Q_STATS;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010819 }
Eilon Greensteinde832a52009-02-12 08:36:33 +000010820 if (IS_E1HMF_MODE_STAT(bp))
10821 return;
10822 hw_stats = (u32 *)&bp->eth_stats;
10823 for (j = 0; j < BNX2X_NUM_STATS; j++) {
10824 if (bnx2x_stats_arr[j].size == 0) {
10825 /* skip this counter */
10826 buf[k + j] = 0;
10827 continue;
10828 }
10829 offset = (hw_stats + bnx2x_stats_arr[j].offset);
10830 if (bnx2x_stats_arr[j].size == 4) {
10831 /* 4-byte counter */
10832 buf[k + j] = (u64) *offset;
10833 continue;
10834 }
10835 /* 8-byte counter */
10836 buf[k + j] = HILO_U64(*offset, *(offset + 1));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010837 }
Eilon Greensteinde832a52009-02-12 08:36:33 +000010838 } else {
10839 hw_stats = (u32 *)&bp->eth_stats;
10840 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
10841 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
10842 continue;
10843 if (bnx2x_stats_arr[i].size == 0) {
10844 /* skip this counter */
10845 buf[j] = 0;
10846 j++;
10847 continue;
10848 }
10849 offset = (hw_stats + bnx2x_stats_arr[i].offset);
10850 if (bnx2x_stats_arr[i].size == 4) {
10851 /* 4-byte counter */
10852 buf[j] = (u64) *offset;
10853 j++;
10854 continue;
10855 }
10856 /* 8-byte counter */
10857 buf[j] = HILO_U64(*offset, *(offset + 1));
10858 j++;
10859 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010860 }
10861}
10862
10863static int bnx2x_phys_id(struct net_device *dev, u32 data)
10864{
10865 struct bnx2x *bp = netdev_priv(dev);
10866 int i;
10867
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010868 if (!netif_running(dev))
10869 return 0;
10870
10871 if (!bp->port.pmf)
10872 return 0;
10873
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010874 if (data == 0)
10875 data = 2;
10876
10877 for (i = 0; i < (data * 2); i++) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010878 if ((i % 2) == 0)
Yaniv Rosner7846e472009-11-05 19:18:07 +020010879 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
10880 SPEED_1000);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010881 else
Yaniv Rosner7846e472009-11-05 19:18:07 +020010882 bnx2x_set_led(&bp->link_params, LED_MODE_OFF, 0);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010883
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010884 msleep_interruptible(500);
10885 if (signal_pending(current))
10886 break;
10887 }
10888
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010889 if (bp->link_vars.link_up)
Yaniv Rosner7846e472009-11-05 19:18:07 +020010890 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
10891 bp->link_vars.line_speed);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010892
10893 return 0;
10894}
10895
Stephen Hemminger0fc0b732009-09-02 01:03:33 -070010896static const struct ethtool_ops bnx2x_ethtool_ops = {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010897 .get_settings = bnx2x_get_settings,
10898 .set_settings = bnx2x_set_settings,
10899 .get_drvinfo = bnx2x_get_drvinfo,
Eilon Greenstein0a64ea52009-03-02 08:01:12 +000010900 .get_regs_len = bnx2x_get_regs_len,
10901 .get_regs = bnx2x_get_regs,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010902 .get_wol = bnx2x_get_wol,
10903 .set_wol = bnx2x_set_wol,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010904 .get_msglevel = bnx2x_get_msglevel,
10905 .set_msglevel = bnx2x_set_msglevel,
10906 .nway_reset = bnx2x_nway_reset,
Naohiro Ooiwa01e53292009-06-30 12:44:19 -070010907 .get_link = bnx2x_get_link,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010908 .get_eeprom_len = bnx2x_get_eeprom_len,
10909 .get_eeprom = bnx2x_get_eeprom,
10910 .set_eeprom = bnx2x_set_eeprom,
10911 .get_coalesce = bnx2x_get_coalesce,
10912 .set_coalesce = bnx2x_set_coalesce,
10913 .get_ringparam = bnx2x_get_ringparam,
10914 .set_ringparam = bnx2x_set_ringparam,
10915 .get_pauseparam = bnx2x_get_pauseparam,
10916 .set_pauseparam = bnx2x_set_pauseparam,
10917 .get_rx_csum = bnx2x_get_rx_csum,
10918 .set_rx_csum = bnx2x_set_rx_csum,
10919 .get_tx_csum = ethtool_op_get_tx_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -070010920 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010921 .set_flags = bnx2x_set_flags,
10922 .get_flags = ethtool_op_get_flags,
10923 .get_sg = ethtool_op_get_sg,
10924 .set_sg = ethtool_op_set_sg,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010925 .get_tso = ethtool_op_get_tso,
10926 .set_tso = bnx2x_set_tso,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010927 .self_test = bnx2x_self_test,
Ben Hutchings15f0a392009-10-01 11:58:24 +000010928 .get_sset_count = bnx2x_get_sset_count,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070010929 .get_strings = bnx2x_get_strings,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010930 .phys_id = bnx2x_phys_id,
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070010931 .get_ethtool_stats = bnx2x_get_ethtool_stats,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010932};
10933
10934/* end of ethtool_ops */
10935
10936/****************************************************************************
10937* General service functions
10938****************************************************************************/
10939
10940static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
10941{
10942 u16 pmcsr;
10943
10944 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
10945
10946 switch (state) {
10947 case PCI_D0:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010948 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010949 ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
10950 PCI_PM_CTRL_PME_STATUS));
10951
10952 if (pmcsr & PCI_PM_CTRL_STATE_MASK)
Eilon Greenstein33471622008-08-13 15:59:08 -070010953 /* delay required during transition out of D3hot */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010954 msleep(20);
10955 break;
10956
10957 case PCI_D3hot:
10958 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
10959 pmcsr |= 3;
10960
10961 if (bp->wol)
10962 pmcsr |= PCI_PM_CTRL_PME_ENABLE;
10963
10964 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
10965 pmcsr);
10966
10967 /* No more memory access after this point until
10968 * device is brought back to D0.
10969 */
10970 break;
10971
10972 default:
10973 return -EINVAL;
10974 }
10975 return 0;
10976}
10977
Eilon Greenstein237907c2009-01-14 06:42:44 +000010978static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
10979{
10980 u16 rx_cons_sb;
10981
10982 /* Tell compiler that status block fields can change */
10983 barrier();
10984 rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
10985 if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
10986 rx_cons_sb++;
10987 return (fp->rx_comp_cons != rx_cons_sb);
10988}
10989
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010990/*
10991 * net_device service functions
10992 */
10993
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010994static int bnx2x_poll(struct napi_struct *napi, int budget)
10995{
10996 struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
10997 napi);
10998 struct bnx2x *bp = fp->bp;
10999 int work_done = 0;
11000
11001#ifdef BNX2X_STOP_ON_ERROR
11002 if (unlikely(bp->panic))
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011003 goto poll_panic;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011004#endif
11005
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011006 prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
11007 prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
11008
11009 bnx2x_update_fpsb_idx(fp);
11010
Eilon Greenstein8534f322009-03-02 07:59:45 +000011011 if (bnx2x_has_rx_work(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011012 work_done = bnx2x_rx_int(fp, budget);
Eilon Greenstein356e2382009-02-12 08:38:32 +000011013
Eilon Greenstein8534f322009-03-02 07:59:45 +000011014 /* must not complete if we consumed full budget */
11015 if (work_done >= budget)
11016 goto poll_again;
11017 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011018
Eilon Greensteinca003922009-08-12 22:53:28 -070011019 /* bnx2x_has_rx_work() reads the status block, thus we need to
Eilon Greenstein8534f322009-03-02 07:59:45 +000011020 * ensure that status block indices have been actually read
Eilon Greensteinca003922009-08-12 22:53:28 -070011021 * (bnx2x_update_fpsb_idx) prior to this check (bnx2x_has_rx_work)
Eilon Greenstein8534f322009-03-02 07:59:45 +000011022 * so that we won't write the "newer" value of the status block to IGU
Eilon Greensteinca003922009-08-12 22:53:28 -070011023 * (if there was a DMA right after bnx2x_has_rx_work and
Eilon Greenstein8534f322009-03-02 07:59:45 +000011024 * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx)
11025 * may be postponed to right before bnx2x_ack_sb). In this case
11026 * there will never be another interrupt until there is another update
11027 * of the status block, while there is still unhandled work.
11028 */
11029 rmb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011030
Eilon Greensteinca003922009-08-12 22:53:28 -070011031 if (!bnx2x_has_rx_work(fp)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011032#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011033poll_panic:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011034#endif
Ben Hutchings288379f2009-01-19 16:43:59 -080011035 napi_complete(napi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011036
Eilon Greenstein0626b892009-02-12 08:38:14 +000011037 bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011038 le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
Eilon Greenstein0626b892009-02-12 08:38:14 +000011039 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011040 le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
11041 }
Eilon Greenstein356e2382009-02-12 08:38:32 +000011042
Eilon Greenstein8534f322009-03-02 07:59:45 +000011043poll_again:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011044 return work_done;
11045}
11046
Eilon Greenstein755735e2008-06-23 20:35:13 -070011047
11048/* we split the first BD into headers and data BDs
Eilon Greenstein33471622008-08-13 15:59:08 -070011049 * to ease the pain of our fellow microcode engineers
Eilon Greenstein755735e2008-06-23 20:35:13 -070011050 * we use one mapping for both BDs
11051 * So far this has only been observed to happen
11052 * in Other Operating Systems(TM)
11053 */
11054static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
11055 struct bnx2x_fastpath *fp,
Eilon Greensteinca003922009-08-12 22:53:28 -070011056 struct sw_tx_bd *tx_buf,
11057 struct eth_tx_start_bd **tx_bd, u16 hlen,
Eilon Greenstein755735e2008-06-23 20:35:13 -070011058 u16 bd_prod, int nbd)
11059{
Eilon Greensteinca003922009-08-12 22:53:28 -070011060 struct eth_tx_start_bd *h_tx_bd = *tx_bd;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011061 struct eth_tx_bd *d_tx_bd;
11062 dma_addr_t mapping;
11063 int old_len = le16_to_cpu(h_tx_bd->nbytes);
11064
11065 /* first fix first BD */
11066 h_tx_bd->nbd = cpu_to_le16(nbd);
11067 h_tx_bd->nbytes = cpu_to_le16(hlen);
11068
11069 DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
11070 "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
11071 h_tx_bd->addr_lo, h_tx_bd->nbd);
11072
11073 /* now get a new data BD
11074 * (after the pbd) and fill it */
11075 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
Eilon Greensteinca003922009-08-12 22:53:28 -070011076 d_tx_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011077
11078 mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
11079 le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
11080
11081 d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
11082 d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
11083 d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
Eilon Greensteinca003922009-08-12 22:53:28 -070011084
11085 /* this marks the BD as one that has no individual mapping */
11086 tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
11087
Eilon Greenstein755735e2008-06-23 20:35:13 -070011088 DP(NETIF_MSG_TX_QUEUED,
11089 "TSO split data size is %d (%x:%x)\n",
11090 d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
11091
Eilon Greensteinca003922009-08-12 22:53:28 -070011092 /* update tx_bd */
11093 *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011094
11095 return bd_prod;
11096}
11097
11098static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
11099{
11100 if (fix > 0)
11101 csum = (u16) ~csum_fold(csum_sub(csum,
11102 csum_partial(t_header - fix, fix, 0)));
11103
11104 else if (fix < 0)
11105 csum = (u16) ~csum_fold(csum_add(csum,
11106 csum_partial(t_header, -fix, 0)));
11107
11108 return swab16(csum);
11109}
11110
11111static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
11112{
11113 u32 rc;
11114
11115 if (skb->ip_summed != CHECKSUM_PARTIAL)
11116 rc = XMIT_PLAIN;
11117
11118 else {
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000011119 if (skb->protocol == htons(ETH_P_IPV6)) {
Eilon Greenstein755735e2008-06-23 20:35:13 -070011120 rc = XMIT_CSUM_V6;
11121 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
11122 rc |= XMIT_CSUM_TCP;
11123
11124 } else {
11125 rc = XMIT_CSUM_V4;
11126 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
11127 rc |= XMIT_CSUM_TCP;
11128 }
11129 }
11130
11131 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
Eilon Greensteind6a2f982009-11-09 06:09:22 +000011132 rc |= (XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP);
Eilon Greenstein755735e2008-06-23 20:35:13 -070011133
11134 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
Eilon Greensteind6a2f982009-11-09 06:09:22 +000011135 rc |= (XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6);
Eilon Greenstein755735e2008-06-23 20:35:13 -070011136
11137 return rc;
11138}
11139
Eilon Greenstein632da4d2009-01-14 06:44:10 +000011140#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greensteinf5372252009-02-12 08:38:30 +000011141/* check if packet requires linearization (packet is too fragmented)
11142 no need to check fragmentation if page size > 8K (there will be no
11143 violation to FW restrictions) */
Eilon Greenstein755735e2008-06-23 20:35:13 -070011144static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
11145 u32 xmit_type)
11146{
11147 int to_copy = 0;
11148 int hlen = 0;
11149 int first_bd_sz = 0;
11150
11151 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
11152 if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
11153
11154 if (xmit_type & XMIT_GSO) {
11155 unsigned short lso_mss = skb_shinfo(skb)->gso_size;
11156 /* Check if LSO packet needs to be copied:
11157 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
11158 int wnd_size = MAX_FETCH_BD - 3;
Eilon Greenstein33471622008-08-13 15:59:08 -070011159 /* Number of windows to check */
Eilon Greenstein755735e2008-06-23 20:35:13 -070011160 int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
11161 int wnd_idx = 0;
11162 int frag_idx = 0;
11163 u32 wnd_sum = 0;
11164
11165 /* Headers length */
11166 hlen = (int)(skb_transport_header(skb) - skb->data) +
11167 tcp_hdrlen(skb);
11168
11169 /* Amount of data (w/o headers) on linear part of SKB*/
11170 first_bd_sz = skb_headlen(skb) - hlen;
11171
11172 wnd_sum = first_bd_sz;
11173
11174 /* Calculate the first sum - it's special */
11175 for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
11176 wnd_sum +=
11177 skb_shinfo(skb)->frags[frag_idx].size;
11178
11179 /* If there was data on linear skb data - check it */
11180 if (first_bd_sz > 0) {
11181 if (unlikely(wnd_sum < lso_mss)) {
11182 to_copy = 1;
11183 goto exit_lbl;
11184 }
11185
11186 wnd_sum -= first_bd_sz;
11187 }
11188
11189 /* Others are easier: run through the frag list and
11190 check all windows */
11191 for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
11192 wnd_sum +=
11193 skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
11194
11195 if (unlikely(wnd_sum < lso_mss)) {
11196 to_copy = 1;
11197 break;
11198 }
11199 wnd_sum -=
11200 skb_shinfo(skb)->frags[wnd_idx].size;
11201 }
Eilon Greenstein755735e2008-06-23 20:35:13 -070011202 } else {
11203 /* in non-LSO too fragmented packet should always
11204 be linearized */
11205 to_copy = 1;
11206 }
11207 }
11208
11209exit_lbl:
11210 if (unlikely(to_copy))
11211 DP(NETIF_MSG_TX_QUEUED,
11212 "Linearization IS REQUIRED for %s packet. "
11213 "num_frags %d hlen %d first_bd_sz %d\n",
11214 (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
11215 skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
11216
11217 return to_copy;
11218}
Eilon Greenstein632da4d2009-01-14 06:44:10 +000011219#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070011220
11221/* called with netif_tx_lock
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011222 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
Eilon Greenstein755735e2008-06-23 20:35:13 -070011223 * netif_wake_queue()
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011224 */
Stephen Hemminger613573252009-08-31 19:50:58 +000011225static netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011226{
11227 struct bnx2x *bp = netdev_priv(dev);
Eilon Greensteinca003922009-08-12 22:53:28 -070011228 struct bnx2x_fastpath *fp, *fp_stat;
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011229 struct netdev_queue *txq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011230 struct sw_tx_bd *tx_buf;
Eilon Greensteinca003922009-08-12 22:53:28 -070011231 struct eth_tx_start_bd *tx_start_bd;
11232 struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011233 struct eth_tx_parse_bd *pbd = NULL;
11234 u16 pkt_prod, bd_prod;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011235 int nbd, fp_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011236 dma_addr_t mapping;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011237 u32 xmit_type = bnx2x_xmit_type(bp, skb);
Eilon Greenstein755735e2008-06-23 20:35:13 -070011238 int i;
11239 u8 hlen = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -070011240 __le16 pkt_size = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011241
11242#ifdef BNX2X_STOP_ON_ERROR
11243 if (unlikely(bp->panic))
11244 return NETDEV_TX_BUSY;
11245#endif
11246
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011247 fp_index = skb_get_queue_mapping(skb);
11248 txq = netdev_get_tx_queue(dev, fp_index);
11249
Eilon Greensteinca003922009-08-12 22:53:28 -070011250 fp = &bp->fp[fp_index + bp->num_rx_queues];
11251 fp_stat = &bp->fp[fp_index];
Eilon Greenstein755735e2008-06-23 20:35:13 -070011252
Yitchak Gertner231fd582008-08-25 15:27:06 -070011253 if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
Eilon Greensteinca003922009-08-12 22:53:28 -070011254 fp_stat->eth_q_stats.driver_xoff++;
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011255 netif_tx_stop_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011256 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
11257 return NETDEV_TX_BUSY;
11258 }
11259
Eilon Greenstein755735e2008-06-23 20:35:13 -070011260 DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)"
11261 " gso type %x xmit_type %x\n",
11262 skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
11263 ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
11264
Eilon Greenstein632da4d2009-01-14 06:44:10 +000011265#if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
Eilon Greensteinf5372252009-02-12 08:38:30 +000011266 /* First, check if we need to linearize the skb (due to FW
11267 restrictions). No need to check fragmentation if page size > 8K
11268 (there will be no violation to FW restrictions) */
Eilon Greenstein755735e2008-06-23 20:35:13 -070011269 if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
11270 /* Statistics of linearization */
11271 bp->lin_cnt++;
11272 if (skb_linearize(skb) != 0) {
11273 DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
11274 "silently dropping this SKB\n");
11275 dev_kfree_skb_any(skb);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070011276 return NETDEV_TX_OK;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011277 }
11278 }
Eilon Greenstein632da4d2009-01-14 06:44:10 +000011279#endif
Eilon Greenstein755735e2008-06-23 20:35:13 -070011280
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011281 /*
Eilon Greenstein755735e2008-06-23 20:35:13 -070011282 Please read carefully. First we use one BD which we mark as start,
Eilon Greensteinca003922009-08-12 22:53:28 -070011283 then we have a parsing info BD (used for TSO or xsum),
Eilon Greenstein755735e2008-06-23 20:35:13 -070011284 and only then we have the rest of the TSO BDs.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011285 (don't forget to mark the last one as last,
11286 and to unmap only AFTER you write to the BD ...)
Eilon Greenstein755735e2008-06-23 20:35:13 -070011287 And above all, all pdb sizes are in words - NOT DWORDS!
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011288 */
11289
11290 pkt_prod = fp->tx_pkt_prod++;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011291 bd_prod = TX_BD(fp->tx_bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011292
Eilon Greenstein755735e2008-06-23 20:35:13 -070011293 /* get a tx_buf and first BD */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011294 tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
Eilon Greensteinca003922009-08-12 22:53:28 -070011295 tx_start_bd = &fp->tx_desc_ring[bd_prod].start_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011296
Eilon Greensteinca003922009-08-12 22:53:28 -070011297 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
11298 tx_start_bd->general_data = (UNICAST_ADDRESS <<
11299 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT);
Eilon Greenstein3196a882008-08-13 15:58:49 -070011300 /* header nbd */
Eilon Greensteinca003922009-08-12 22:53:28 -070011301 tx_start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011302
Eilon Greenstein755735e2008-06-23 20:35:13 -070011303 /* remember the first BD of the packet */
11304 tx_buf->first_bd = fp->tx_bd_prod;
11305 tx_buf->skb = skb;
Eilon Greensteinca003922009-08-12 22:53:28 -070011306 tx_buf->flags = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011307
11308 DP(NETIF_MSG_TX_QUEUED,
11309 "sending pkt %u @%p next_idx %u bd %u @%p\n",
Eilon Greensteinca003922009-08-12 22:53:28 -070011310 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011311
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080011312#ifdef BCM_VLAN
11313 if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) &&
11314 (bp->flags & HW_VLAN_TX_FLAG)) {
Eilon Greensteinca003922009-08-12 22:53:28 -070011315 tx_start_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb));
11316 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011317 } else
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080011318#endif
Eilon Greensteinca003922009-08-12 22:53:28 -070011319 tx_start_bd->vlan = cpu_to_le16(pkt_prod);
Eilon Greenstein755735e2008-06-23 20:35:13 -070011320
Eilon Greensteinca003922009-08-12 22:53:28 -070011321 /* turn on parsing and get a BD */
11322 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
11323 pbd = &fp->tx_desc_ring[bd_prod].parse_bd;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011324
Eilon Greensteinca003922009-08-12 22:53:28 -070011325 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
Eilon Greenstein755735e2008-06-23 20:35:13 -070011326
11327 if (xmit_type & XMIT_CSUM) {
Eilon Greensteinca003922009-08-12 22:53:28 -070011328 hlen = (skb_network_header(skb) - skb->data) / 2;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011329
11330 /* for now NS flag is not used in Linux */
Eilon Greenstein4781bfa2009-02-12 08:38:17 +000011331 pbd->global_data =
11332 (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
11333 ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT));
Eilon Greenstein755735e2008-06-23 20:35:13 -070011334
11335 pbd->ip_hlen = (skb_transport_header(skb) -
11336 skb_network_header(skb)) / 2;
11337
11338 hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2;
11339
11340 pbd->total_hlen = cpu_to_le16(hlen);
Eilon Greensteinca003922009-08-12 22:53:28 -070011341 hlen = hlen*2;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011342
Eilon Greensteinca003922009-08-12 22:53:28 -070011343 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011344
11345 if (xmit_type & XMIT_CSUM_V4)
Eilon Greensteinca003922009-08-12 22:53:28 -070011346 tx_start_bd->bd_flags.as_bitfield |=
Eilon Greenstein755735e2008-06-23 20:35:13 -070011347 ETH_TX_BD_FLAGS_IP_CSUM;
11348 else
Eilon Greensteinca003922009-08-12 22:53:28 -070011349 tx_start_bd->bd_flags.as_bitfield |=
11350 ETH_TX_BD_FLAGS_IPV6;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011351
11352 if (xmit_type & XMIT_CSUM_TCP) {
11353 pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
11354
11355 } else {
11356 s8 fix = SKB_CS_OFF(skb); /* signed! */
11357
Eilon Greensteinca003922009-08-12 22:53:28 -070011358 pbd->global_data |= ETH_TX_PARSE_BD_UDP_CS_FLG;
Eilon Greenstein755735e2008-06-23 20:35:13 -070011359
11360 DP(NETIF_MSG_TX_QUEUED,
Eilon Greensteinca003922009-08-12 22:53:28 -070011361 "hlen %d fix %d csum before fix %x\n",
11362 le16_to_cpu(pbd->total_hlen), fix, SKB_CS(skb));
Eilon Greenstein755735e2008-06-23 20:35:13 -070011363
11364 /* HW bug: fixup the CSUM */
11365 pbd->tcp_pseudo_csum =
11366 bnx2x_csum_fix(skb_transport_header(skb),
11367 SKB_CS(skb), fix);
11368
11369 DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
11370 pbd->tcp_pseudo_csum);
11371 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011372 }
11373
11374 mapping = pci_map_single(bp->pdev, skb->data,
Eilon Greenstein755735e2008-06-23 20:35:13 -070011375 skb_headlen(skb), PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011376
Eilon Greensteinca003922009-08-12 22:53:28 -070011377 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
11378 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
11379 nbd = skb_shinfo(skb)->nr_frags + 2; /* start_bd + pbd + frags */
11380 tx_start_bd->nbd = cpu_to_le16(nbd);
11381 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
11382 pkt_size = tx_start_bd->nbytes;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011383
11384 DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
Eilon Greenstein755735e2008-06-23 20:35:13 -070011385 " nbytes %d flags %x vlan %x\n",
Eilon Greensteinca003922009-08-12 22:53:28 -070011386 tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
11387 le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
11388 tx_start_bd->bd_flags.as_bitfield, le16_to_cpu(tx_start_bd->vlan));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011389
Eilon Greenstein755735e2008-06-23 20:35:13 -070011390 if (xmit_type & XMIT_GSO) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011391
11392 DP(NETIF_MSG_TX_QUEUED,
11393 "TSO packet len %d hlen %d total len %d tso size %d\n",
11394 skb->len, hlen, skb_headlen(skb),
11395 skb_shinfo(skb)->gso_size);
11396
Eilon Greensteinca003922009-08-12 22:53:28 -070011397 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011398
Eilon Greenstein755735e2008-06-23 20:35:13 -070011399 if (unlikely(skb_headlen(skb) > hlen))
Eilon Greensteinca003922009-08-12 22:53:28 -070011400 bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd,
11401 hlen, bd_prod, ++nbd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011402
11403 pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
11404 pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
Eilon Greenstein755735e2008-06-23 20:35:13 -070011405 pbd->tcp_flags = pbd_tcp_flags(skb);
11406
11407 if (xmit_type & XMIT_GSO_V4) {
11408 pbd->ip_id = swab16(ip_hdr(skb)->id);
11409 pbd->tcp_pseudo_csum =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011410 swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
11411 ip_hdr(skb)->daddr,
11412 0, IPPROTO_TCP, 0));
Eilon Greenstein755735e2008-06-23 20:35:13 -070011413
11414 } else
11415 pbd->tcp_pseudo_csum =
11416 swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
11417 &ipv6_hdr(skb)->daddr,
11418 0, IPPROTO_TCP, 0));
11419
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011420 pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN;
11421 }
Eilon Greensteinca003922009-08-12 22:53:28 -070011422 tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011423
Eilon Greenstein755735e2008-06-23 20:35:13 -070011424 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
11425 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011426
Eilon Greenstein755735e2008-06-23 20:35:13 -070011427 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
Eilon Greensteinca003922009-08-12 22:53:28 -070011428 tx_data_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
11429 if (total_pkt_bd == NULL)
11430 total_pkt_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011431
Eilon Greenstein755735e2008-06-23 20:35:13 -070011432 mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
11433 frag->size, PCI_DMA_TODEVICE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011434
Eilon Greensteinca003922009-08-12 22:53:28 -070011435 tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
11436 tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
11437 tx_data_bd->nbytes = cpu_to_le16(frag->size);
11438 le16_add_cpu(&pkt_size, frag->size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011439
Eilon Greenstein755735e2008-06-23 20:35:13 -070011440 DP(NETIF_MSG_TX_QUEUED,
Eilon Greensteinca003922009-08-12 22:53:28 -070011441 "frag %d bd @%p addr (%x:%x) nbytes %d\n",
11442 i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
11443 le16_to_cpu(tx_data_bd->nbytes));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011444 }
11445
Eilon Greensteinca003922009-08-12 22:53:28 -070011446 DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011447
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011448 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
11449
Eilon Greenstein755735e2008-06-23 20:35:13 -070011450 /* now send a tx doorbell, counting the next BD
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011451 * if the packet contains or ends with it
11452 */
11453 if (TX_BD_POFF(bd_prod) < nbd)
11454 nbd++;
11455
Eilon Greensteinca003922009-08-12 22:53:28 -070011456 if (total_pkt_bd != NULL)
11457 total_pkt_bd->total_pkt_bytes = pkt_size;
11458
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011459 if (pbd)
11460 DP(NETIF_MSG_TX_QUEUED,
11461 "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
11462 " tcp_flags %x xsum %x seq %u hlen %u\n",
11463 pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id,
11464 pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum,
Eilon Greenstein755735e2008-06-23 20:35:13 -070011465 pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011466
Eilon Greenstein755735e2008-06-23 20:35:13 -070011467 DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011468
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080011469 /*
11470 * Make sure that the BD data is updated before updating the producer
11471 * since FW might read the BD right after the producer is updated.
11472 * This is only applicable for weak-ordered memory model archs such
11473 * as IA-64. The following barrier is also mandatory since FW will
11474 * assumes packets must have BDs.
11475 */
11476 wmb();
11477
Eilon Greensteinca003922009-08-12 22:53:28 -070011478 fp->tx_db.data.prod += nbd;
11479 barrier();
11480 DOORBELL(bp, fp->index - bp->num_rx_queues, fp->tx_db.raw);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011481
11482 mmiowb();
11483
Eilon Greenstein755735e2008-06-23 20:35:13 -070011484 fp->tx_bd_prod += nbd;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011485
11486 if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
Eilon Greensteinca003922009-08-12 22:53:28 -070011487 netif_tx_stop_queue(txq);
Eilon Greenstein58f4c4c2009-01-14 21:23:36 -080011488 /* We want bnx2x_tx_int to "see" the updated tx_bd_prod
11489 if we put Tx into XOFF state. */
11490 smp_mb();
Eilon Greensteinca003922009-08-12 22:53:28 -070011491 fp_stat->eth_q_stats.driver_xoff++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011492 if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
Eilon Greenstein555f6c72009-02-12 08:36:11 +000011493 netif_tx_wake_queue(txq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011494 }
Eilon Greensteinca003922009-08-12 22:53:28 -070011495 fp_stat->tx_pkt++;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011496
11497 return NETDEV_TX_OK;
11498}
11499
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011500/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011501static int bnx2x_open(struct net_device *dev)
11502{
11503 struct bnx2x *bp = netdev_priv(dev);
11504
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000011505 netif_carrier_off(dev);
11506
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011507 bnx2x_set_power_state(bp, PCI_D0);
11508
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011509 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011510}
11511
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011512/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011513static int bnx2x_close(struct net_device *dev)
11514{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011515 struct bnx2x *bp = netdev_priv(dev);
11516
11517 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011518 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
11519 if (atomic_read(&bp->pdev->enable_cnt) == 1)
11520 if (!CHIP_REV_IS_SLOW(bp))
11521 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011522
11523 return 0;
11524}
11525
Eilon Greensteinf5372252009-02-12 08:38:30 +000011526/* called with netif_tx_lock from dev_mcast.c */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011527static void bnx2x_set_rx_mode(struct net_device *dev)
11528{
11529 struct bnx2x *bp = netdev_priv(dev);
11530 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
11531 int port = BP_PORT(bp);
11532
11533 if (bp->state != BNX2X_STATE_OPEN) {
11534 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11535 return;
11536 }
11537
11538 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
11539
11540 if (dev->flags & IFF_PROMISC)
11541 rx_mode = BNX2X_RX_MODE_PROMISC;
11542
11543 else if ((dev->flags & IFF_ALLMULTI) ||
11544 ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp)))
11545 rx_mode = BNX2X_RX_MODE_ALLMULTI;
11546
11547 else { /* some multicasts */
11548 if (CHIP_IS_E1(bp)) {
11549 int i, old, offset;
11550 struct dev_mc_list *mclist;
11551 struct mac_configuration_cmd *config =
11552 bnx2x_sp(bp, mcast_config);
11553
11554 for (i = 0, mclist = dev->mc_list;
11555 mclist && (i < dev->mc_count);
11556 i++, mclist = mclist->next) {
11557
11558 config->config_table[i].
11559 cam_entry.msb_mac_addr =
11560 swab16(*(u16 *)&mclist->dmi_addr[0]);
11561 config->config_table[i].
11562 cam_entry.middle_mac_addr =
11563 swab16(*(u16 *)&mclist->dmi_addr[2]);
11564 config->config_table[i].
11565 cam_entry.lsb_mac_addr =
11566 swab16(*(u16 *)&mclist->dmi_addr[4]);
11567 config->config_table[i].cam_entry.flags =
11568 cpu_to_le16(port);
11569 config->config_table[i].
11570 target_table_entry.flags = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -070011571 config->config_table[i].target_table_entry.
11572 clients_bit_vector =
11573 cpu_to_le32(1 << BP_L_ID(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011574 config->config_table[i].
11575 target_table_entry.vlan_id = 0;
11576
11577 DP(NETIF_MSG_IFUP,
11578 "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
11579 config->config_table[i].
11580 cam_entry.msb_mac_addr,
11581 config->config_table[i].
11582 cam_entry.middle_mac_addr,
11583 config->config_table[i].
11584 cam_entry.lsb_mac_addr);
11585 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080011586 old = config->hdr.length;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011587 if (old > i) {
11588 for (; i < old; i++) {
11589 if (CAM_IS_INVALID(config->
11590 config_table[i])) {
Eilon Greensteinaf246402009-01-14 06:43:59 +000011591 /* already invalidated */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011592 break;
11593 }
11594 /* invalidate */
11595 CAM_INVALIDATE(config->
11596 config_table[i]);
11597 }
11598 }
11599
11600 if (CHIP_REV_IS_SLOW(bp))
11601 offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
11602 else
11603 offset = BNX2X_MAX_MULTICAST*(1 + port);
11604
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080011605 config->hdr.length = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011606 config->hdr.offset = offset;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080011607 config->hdr.client_id = bp->fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011608 config->hdr.reserved1 = 0;
11609
Michael Chane665bfd2009-10-10 13:46:54 +000011610 bp->set_mac_pending++;
11611 smp_wmb();
11612
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011613 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
11614 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
11615 U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
11616 0);
11617 } else { /* E1H */
11618 /* Accept one or more multicasts */
11619 struct dev_mc_list *mclist;
11620 u32 mc_filter[MC_HASH_SIZE];
11621 u32 crc, bit, regidx;
11622 int i;
11623
11624 memset(mc_filter, 0, 4 * MC_HASH_SIZE);
11625
11626 for (i = 0, mclist = dev->mc_list;
11627 mclist && (i < dev->mc_count);
11628 i++, mclist = mclist->next) {
11629
Johannes Berg7c510e42008-10-27 17:47:26 -070011630 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
11631 mclist->dmi_addr);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011632
11633 crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
11634 bit = (crc >> 24) & 0xff;
11635 regidx = bit >> 5;
11636 bit &= 0x1f;
11637 mc_filter[regidx] |= (1 << bit);
11638 }
11639
11640 for (i = 0; i < MC_HASH_SIZE; i++)
11641 REG_WR(bp, MC_HASH_OFFSET(bp, i),
11642 mc_filter[i]);
11643 }
11644 }
11645
11646 bp->rx_mode = rx_mode;
11647 bnx2x_set_storm_rx_mode(bp);
11648}
11649
11650/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011651static int bnx2x_change_mac_addr(struct net_device *dev, void *p)
11652{
11653 struct sockaddr *addr = p;
11654 struct bnx2x *bp = netdev_priv(dev);
11655
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011656 if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011657 return -EINVAL;
11658
11659 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011660 if (netif_running(dev)) {
11661 if (CHIP_IS_E1(bp))
Michael Chane665bfd2009-10-10 13:46:54 +000011662 bnx2x_set_eth_mac_addr_e1(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011663 else
Michael Chane665bfd2009-10-10 13:46:54 +000011664 bnx2x_set_eth_mac_addr_e1h(bp, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011665 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011666
11667 return 0;
11668}
11669
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011670/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011671static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11672 int devad, u16 addr)
11673{
11674 struct bnx2x *bp = netdev_priv(netdev);
11675 u16 value;
11676 int rc;
11677 u32 phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
11678
11679 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11680 prtad, devad, addr);
11681
11682 if (prtad != bp->mdio.prtad) {
11683 DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
11684 prtad, bp->mdio.prtad);
11685 return -EINVAL;
11686 }
11687
11688 /* The HW expects different devad if CL22 is used */
11689 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11690
11691 bnx2x_acquire_phy_lock(bp);
11692 rc = bnx2x_cl45_read(bp, BP_PORT(bp), phy_type, prtad,
11693 devad, addr, &value);
11694 bnx2x_release_phy_lock(bp);
11695 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
11696
11697 if (!rc)
11698 rc = value;
11699 return rc;
11700}
11701
11702/* called with rtnl_lock */
11703static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11704 u16 addr, u16 value)
11705{
11706 struct bnx2x *bp = netdev_priv(netdev);
11707 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
11708 int rc;
11709
11710 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
11711 " value 0x%x\n", prtad, devad, addr, value);
11712
11713 if (prtad != bp->mdio.prtad) {
11714 DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
11715 prtad, bp->mdio.prtad);
11716 return -EINVAL;
11717 }
11718
11719 /* The HW expects different devad if CL22 is used */
11720 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11721
11722 bnx2x_acquire_phy_lock(bp);
11723 rc = bnx2x_cl45_write(bp, BP_PORT(bp), ext_phy_type, prtad,
11724 devad, addr, value);
11725 bnx2x_release_phy_lock(bp);
11726 return rc;
11727}
11728
11729/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011730static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11731{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011732 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011733 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011734
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011735 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11736 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011737
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011738 if (!netif_running(dev))
11739 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011740
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011741 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011742}
11743
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011744/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011745static int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
11746{
11747 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011748 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011749
11750 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
11751 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
11752 return -EINVAL;
11753
11754 /* This does not race with packet allocation
Eliezer Tamirc14423f2008-02-28 11:49:42 -080011755 * because the actual alloc size is
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011756 * only updated as part of load
11757 */
11758 dev->mtu = new_mtu;
11759
11760 if (netif_running(dev)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011761 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
11762 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011763 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011764
11765 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011766}
11767
11768static void bnx2x_tx_timeout(struct net_device *dev)
11769{
11770 struct bnx2x *bp = netdev_priv(dev);
11771
11772#ifdef BNX2X_STOP_ON_ERROR
11773 if (!bp->panic)
11774 bnx2x_panic();
11775#endif
11776 /* This allows the netif to be shutdown gracefully before resetting */
11777 schedule_work(&bp->reset_task);
11778}
11779
11780#ifdef BCM_VLAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011781/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011782static void bnx2x_vlan_rx_register(struct net_device *dev,
11783 struct vlan_group *vlgrp)
11784{
11785 struct bnx2x *bp = netdev_priv(dev);
11786
11787 bp->vlgrp = vlgrp;
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080011788
11789 /* Set flags according to the required capabilities */
11790 bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
11791
11792 if (dev->features & NETIF_F_HW_VLAN_TX)
11793 bp->flags |= HW_VLAN_TX_FLAG;
11794
11795 if (dev->features & NETIF_F_HW_VLAN_RX)
11796 bp->flags |= HW_VLAN_RX_FLAG;
11797
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011798 if (netif_running(dev))
Eliezer Tamir49d66772008-02-28 11:53:13 -080011799 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011800}
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011801
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011802#endif
11803
11804#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
11805static void poll_bnx2x(struct net_device *dev)
11806{
11807 struct bnx2x *bp = netdev_priv(dev);
11808
11809 disable_irq(bp->pdev->irq);
11810 bnx2x_interrupt(bp->pdev->irq, dev);
11811 enable_irq(bp->pdev->irq);
11812}
11813#endif
11814
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080011815static const struct net_device_ops bnx2x_netdev_ops = {
11816 .ndo_open = bnx2x_open,
11817 .ndo_stop = bnx2x_close,
11818 .ndo_start_xmit = bnx2x_start_xmit,
Eilon Greenstein356e2382009-02-12 08:38:32 +000011819 .ndo_set_multicast_list = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080011820 .ndo_set_mac_address = bnx2x_change_mac_addr,
11821 .ndo_validate_addr = eth_validate_addr,
11822 .ndo_do_ioctl = bnx2x_ioctl,
11823 .ndo_change_mtu = bnx2x_change_mtu,
11824 .ndo_tx_timeout = bnx2x_tx_timeout,
11825#ifdef BCM_VLAN
11826 .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
11827#endif
11828#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
11829 .ndo_poll_controller = poll_bnx2x,
11830#endif
11831};
11832
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011833static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
11834 struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011835{
11836 struct bnx2x *bp;
11837 int rc;
11838
11839 SET_NETDEV_DEV(dev, &pdev->dev);
11840 bp = netdev_priv(dev);
11841
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011842 bp->dev = dev;
11843 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011844 bp->flags = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011845 bp->func = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011846
11847 rc = pci_enable_device(pdev);
11848 if (rc) {
11849 printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n");
11850 goto err_out;
11851 }
11852
11853 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
11854 printk(KERN_ERR PFX "Cannot find PCI device base address,"
11855 " aborting\n");
11856 rc = -ENODEV;
11857 goto err_out_disable;
11858 }
11859
11860 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11861 printk(KERN_ERR PFX "Cannot find second PCI device"
11862 " base address, aborting\n");
11863 rc = -ENODEV;
11864 goto err_out_disable;
11865 }
11866
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011867 if (atomic_read(&pdev->enable_cnt) == 1) {
11868 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11869 if (rc) {
11870 printk(KERN_ERR PFX "Cannot obtain PCI resources,"
11871 " aborting\n");
11872 goto err_out_disable;
11873 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011874
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011875 pci_set_master(pdev);
11876 pci_save_state(pdev);
11877 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011878
11879 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11880 if (bp->pm_cap == 0) {
11881 printk(KERN_ERR PFX "Cannot find power management"
11882 " capability, aborting\n");
11883 rc = -EIO;
11884 goto err_out_release;
11885 }
11886
11887 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
11888 if (bp->pcie_cap == 0) {
11889 printk(KERN_ERR PFX "Cannot find PCI Express capability,"
11890 " aborting\n");
11891 rc = -EIO;
11892 goto err_out_release;
11893 }
11894
Yang Hongyang6a355282009-04-06 19:01:13 -070011895 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011896 bp->flags |= USING_DAC_FLAG;
Yang Hongyang6a355282009-04-06 19:01:13 -070011897 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011898 printk(KERN_ERR PFX "pci_set_consistent_dma_mask"
11899 " failed, aborting\n");
11900 rc = -EIO;
11901 goto err_out_release;
11902 }
11903
Yang Hongyang284901a2009-04-06 19:01:15 -070011904 } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011905 printk(KERN_ERR PFX "System does not support DMA,"
11906 " aborting\n");
11907 rc = -EIO;
11908 goto err_out_release;
11909 }
11910
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011911 dev->mem_start = pci_resource_start(pdev, 0);
11912 dev->base_addr = dev->mem_start;
11913 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011914
11915 dev->irq = pdev->irq;
11916
Arjan van de Ven275f1652008-10-20 21:42:39 -070011917 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011918 if (!bp->regview) {
11919 printk(KERN_ERR PFX "Cannot map register space, aborting\n");
11920 rc = -ENOMEM;
11921 goto err_out_release;
11922 }
11923
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011924 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
11925 min_t(u64, BNX2X_DB_SIZE,
11926 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011927 if (!bp->doorbells) {
11928 printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n");
11929 rc = -ENOMEM;
11930 goto err_out_unmap;
11931 }
11932
11933 bnx2x_set_power_state(bp, PCI_D0);
11934
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011935 /* clean indirect addresses */
11936 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11937 PCICFG_VENDOR_ID_OFFSET);
11938 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
11939 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
11940 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
11941 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011942
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011943 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011944
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080011945 dev->netdev_ops = &bnx2x_netdev_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011946 dev->ethtool_ops = &bnx2x_ethtool_ops;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011947 dev->features |= NETIF_F_SG;
11948 dev->features |= NETIF_F_HW_CSUM;
11949 if (bp->flags & USING_DAC_FLAG)
11950 dev->features |= NETIF_F_HIGHDMA;
Eilon Greenstein5316bc02009-07-21 05:47:43 +000011951 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
11952 dev->features |= NETIF_F_TSO6;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011953#ifdef BCM_VLAN
11954 dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080011955 bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
Eilon Greenstein5316bc02009-07-21 05:47:43 +000011956
11957 dev->vlan_features |= NETIF_F_SG;
11958 dev->vlan_features |= NETIF_F_HW_CSUM;
11959 if (bp->flags & USING_DAC_FLAG)
11960 dev->vlan_features |= NETIF_F_HIGHDMA;
11961 dev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
11962 dev->vlan_features |= NETIF_F_TSO6;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011963#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011964
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011965 /* get_port_hwinfo() will set prtad and mmds properly */
11966 bp->mdio.prtad = MDIO_PRTAD_NONE;
11967 bp->mdio.mmds = 0;
11968 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11969 bp->mdio.dev = dev;
11970 bp->mdio.mdio_read = bnx2x_mdio_read;
11971 bp->mdio.mdio_write = bnx2x_mdio_write;
11972
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011973 return 0;
11974
11975err_out_unmap:
11976 if (bp->regview) {
11977 iounmap(bp->regview);
11978 bp->regview = NULL;
11979 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011980 if (bp->doorbells) {
11981 iounmap(bp->doorbells);
11982 bp->doorbells = NULL;
11983 }
11984
11985err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011986 if (atomic_read(&pdev->enable_cnt) == 1)
11987 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011988
11989err_out_disable:
11990 pci_disable_device(pdev);
11991 pci_set_drvdata(pdev, NULL);
11992
11993err_out:
11994 return rc;
11995}
11996
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000011997static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
11998 int *width, int *speed)
Eliezer Tamir25047952008-02-28 11:50:16 -080011999{
12000 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
12001
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012002 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
12003
12004 /* return value of 1=2.5GHz 2=5GHz */
12005 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
Eliezer Tamir25047952008-02-28 11:50:16 -080012006}
12007
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012008static int __devinit bnx2x_check_firmware(struct bnx2x *bp)
12009{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012010 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012011 struct bnx2x_fw_file_hdr *fw_hdr;
12012 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012013 u32 offset, len, num_ops;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012014 u16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012015 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012016 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012017
12018 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
12019 return -EINVAL;
12020
12021 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12022 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12023
12024 /* Make sure none of the offsets and sizes make us read beyond
12025 * the end of the firmware data */
12026 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12027 offset = be32_to_cpu(sections[i].offset);
12028 len = be32_to_cpu(sections[i].len);
12029 if (offset + len > firmware->size) {
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012030 printk(KERN_ERR PFX "Section %d length is out of "
12031 "bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012032 return -EINVAL;
12033 }
12034 }
12035
12036 /* Likewise for the init_ops offsets */
12037 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
12038 ops_offsets = (u16 *)(firmware->data + offset);
12039 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12040
12041 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12042 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012043 printk(KERN_ERR PFX "Section offset %d is out of "
12044 "bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012045 return -EINVAL;
12046 }
12047 }
12048
12049 /* Check FW version */
12050 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12051 fw_ver = firmware->data + offset;
12052 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12053 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12054 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12055 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
12056 printk(KERN_ERR PFX "Bad FW version:%d.%d.%d.%d."
12057 " Should be %d.%d.%d.%d\n",
12058 fw_ver[0], fw_ver[1], fw_ver[2],
12059 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
12060 BCM_5710_FW_MINOR_VERSION,
12061 BCM_5710_FW_REVISION_VERSION,
12062 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012063 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012064 }
12065
12066 return 0;
12067}
12068
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012069static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012070{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012071 const __be32 *source = (const __be32 *)_source;
12072 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012073 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012074
12075 for (i = 0; i < n/4; i++)
12076 target[i] = be32_to_cpu(source[i]);
12077}
12078
12079/*
12080 Ops array is stored in the following format:
12081 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12082 */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012083static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012084{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012085 const __be32 *source = (const __be32 *)_source;
12086 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012087 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012088
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012089 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012090 tmp = be32_to_cpu(source[j]);
12091 target[i].op = (tmp >> 24) & 0xff;
12092 target[i].offset = tmp & 0xffffff;
12093 target[i].raw_data = be32_to_cpu(source[j+1]);
12094 }
12095}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012096
12097static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012098{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012099 const __be16 *source = (const __be16 *)_source;
12100 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012101 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012102
12103 for (i = 0; i < n/2; i++)
12104 target[i] = be16_to_cpu(source[i]);
12105}
12106
12107#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012108 do { \
12109 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12110 bp->arr = kmalloc(len, GFP_KERNEL); \
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012111 if (!bp->arr) { \
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012112 printk(KERN_ERR PFX "Failed to allocate %d bytes " \
12113 "for "#arr"\n", len); \
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012114 goto lbl; \
12115 } \
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012116 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12117 (u8 *)bp->arr, len); \
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012118 } while (0)
12119
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012120static int __devinit bnx2x_init_firmware(struct bnx2x *bp, struct device *dev)
12121{
Ben Hutchings45229b42009-11-07 11:53:39 +000012122 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012123 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +000012124 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012125
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012126 if (CHIP_IS_E1(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +000012127 fw_file_name = FW_FILE_NAME_E1;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012128 else
Ben Hutchings45229b42009-11-07 11:53:39 +000012129 fw_file_name = FW_FILE_NAME_E1H;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012130
12131 printk(KERN_INFO PFX "Loading %s\n", fw_file_name);
12132
12133 rc = request_firmware(&bp->firmware, fw_file_name, dev);
12134 if (rc) {
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012135 printk(KERN_ERR PFX "Can't load firmware file %s\n",
12136 fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012137 goto request_firmware_exit;
12138 }
12139
12140 rc = bnx2x_check_firmware(bp);
12141 if (rc) {
12142 printk(KERN_ERR PFX "Corrupt firmware file %s\n", fw_file_name);
12143 goto request_firmware_exit;
12144 }
12145
12146 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12147
12148 /* Initialize the pointers to the init arrays */
12149 /* Blob */
12150 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12151
12152 /* Opcodes */
12153 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12154
12155 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012156 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12157 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012158
12159 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +000012160 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12161 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12162 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12163 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12164 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12165 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12166 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12167 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12168 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12169 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12170 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12171 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12172 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12173 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12174 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12175 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012176
12177 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012178
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012179init_offsets_alloc_err:
12180 kfree(bp->init_ops);
12181init_ops_alloc_err:
12182 kfree(bp->init_data);
12183request_firmware_exit:
12184 release_firmware(bp->firmware);
12185
12186 return rc;
12187}
12188
12189
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012190static int __devinit bnx2x_init_one(struct pci_dev *pdev,
12191 const struct pci_device_id *ent)
12192{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012193 struct net_device *dev = NULL;
12194 struct bnx2x *bp;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012195 int pcie_width, pcie_speed;
Eliezer Tamir25047952008-02-28 11:50:16 -080012196 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012197
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012198 /* dev zeroed in init_etherdev */
Eilon Greenstein555f6c72009-02-12 08:36:11 +000012199 dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012200 if (!dev) {
12201 printk(KERN_ERR PFX "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012202 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012203 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012204
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012205 bp = netdev_priv(dev);
12206 bp->msglevel = debug;
12207
Eilon Greensteindf4770de2009-08-12 08:23:28 +000012208 pci_set_drvdata(pdev, dev);
12209
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012210 rc = bnx2x_init_dev(pdev, dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012211 if (rc < 0) {
12212 free_netdev(dev);
12213 return rc;
12214 }
12215
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012216 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000012217 if (rc)
12218 goto init_one_exit;
12219
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012220 /* Set init arrays */
12221 rc = bnx2x_init_firmware(bp, &pdev->dev);
12222 if (rc) {
12223 printk(KERN_ERR PFX "Error loading firmware\n");
12224 goto init_one_exit;
12225 }
12226
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000012227 rc = register_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012228 if (rc) {
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000012229 dev_err(&pdev->dev, "Cannot register net device\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012230 goto init_one_exit;
12231 }
12232
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012233 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
Eliezer Tamir25047952008-02-28 11:50:16 -080012234 printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
Eilon Greenstein87942b42009-02-12 08:36:49 +000012235 " IRQ %d, ", dev->name, board_info[ent->driver_data].name,
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012236 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012237 pcie_width, (pcie_speed == 2) ? "5GHz (Gen2)" : "2.5GHz",
Eliezer Tamir25047952008-02-28 11:50:16 -080012238 dev->base_addr, bp->pdev->irq);
Johannes Berge1749612008-10-27 15:59:26 -070012239 printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000012240
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012241 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012242
12243init_one_exit:
12244 if (bp->regview)
12245 iounmap(bp->regview);
12246
12247 if (bp->doorbells)
12248 iounmap(bp->doorbells);
12249
12250 free_netdev(dev);
12251
12252 if (atomic_read(&pdev->enable_cnt) == 1)
12253 pci_release_regions(pdev);
12254
12255 pci_disable_device(pdev);
12256 pci_set_drvdata(pdev, NULL);
12257
12258 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012259}
12260
12261static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
12262{
12263 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080012264 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012265
Eliezer Tamir228241e2008-02-28 11:56:57 -080012266 if (!dev) {
Eliezer Tamir228241e2008-02-28 11:56:57 -080012267 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
12268 return;
12269 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080012270 bp = netdev_priv(dev);
12271
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012272 unregister_netdev(dev);
12273
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012274 kfree(bp->init_ops_offsets);
12275 kfree(bp->init_ops);
12276 kfree(bp->init_data);
12277 release_firmware(bp->firmware);
12278
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012279 if (bp->regview)
12280 iounmap(bp->regview);
12281
12282 if (bp->doorbells)
12283 iounmap(bp->doorbells);
12284
12285 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012286
12287 if (atomic_read(&pdev->enable_cnt) == 1)
12288 pci_release_regions(pdev);
12289
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012290 pci_disable_device(pdev);
12291 pci_set_drvdata(pdev, NULL);
12292}
12293
12294static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
12295{
12296 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080012297 struct bnx2x *bp;
12298
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012299 if (!dev) {
12300 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
12301 return -ENODEV;
12302 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080012303 bp = netdev_priv(dev);
12304
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012305 rtnl_lock();
12306
12307 pci_save_state(pdev);
12308
12309 if (!netif_running(dev)) {
12310 rtnl_unlock();
12311 return 0;
12312 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012313
12314 netif_device_detach(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012315
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070012316 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012317
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012318 bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
Eliezer Tamir228241e2008-02-28 11:56:57 -080012319
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012320 rtnl_unlock();
12321
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012322 return 0;
12323}
12324
12325static int bnx2x_resume(struct pci_dev *pdev)
12326{
12327 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080012328 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012329 int rc;
12330
Eliezer Tamir228241e2008-02-28 11:56:57 -080012331 if (!dev) {
12332 printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
12333 return -ENODEV;
12334 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080012335 bp = netdev_priv(dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012336
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012337 rtnl_lock();
12338
Eliezer Tamir228241e2008-02-28 11:56:57 -080012339 pci_restore_state(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012340
12341 if (!netif_running(dev)) {
12342 rtnl_unlock();
12343 return 0;
12344 }
12345
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012346 bnx2x_set_power_state(bp, PCI_D0);
12347 netif_device_attach(dev);
12348
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -070012349 rc = bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012350
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012351 rtnl_unlock();
12352
12353 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012354}
12355
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012356static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12357{
12358 int i;
12359
12360 bp->state = BNX2X_STATE_ERROR;
12361
12362 bp->rx_mode = BNX2X_RX_MODE_NONE;
12363
12364 bnx2x_netif_stop(bp, 0);
12365
12366 del_timer_sync(&bp->timer);
12367 bp->stats_state = STATS_STATE_DISABLED;
12368 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
12369
12370 /* Release IRQs */
12371 bnx2x_free_irq(bp);
12372
12373 if (CHIP_IS_E1(bp)) {
12374 struct mac_configuration_cmd *config =
12375 bnx2x_sp(bp, mcast_config);
12376
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -080012377 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012378 CAM_INVALIDATE(config->config_table[i]);
12379 }
12380
12381 /* Free SKBs, SGEs, TPA pool and driver internals */
12382 bnx2x_free_skbs(bp);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000012383 for_each_rx_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012384 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Eilon Greenstein555f6c72009-02-12 08:36:11 +000012385 for_each_rx_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +000012386 netif_napi_del(&bnx2x_fp(bp, i, napi));
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012387 bnx2x_free_mem(bp);
12388
12389 bp->state = BNX2X_STATE_CLOSED;
12390
12391 netif_carrier_off(bp->dev);
12392
12393 return 0;
12394}
12395
12396static void bnx2x_eeh_recover(struct bnx2x *bp)
12397{
12398 u32 val;
12399
12400 mutex_init(&bp->port.phy_mutex);
12401
12402 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
12403 bp->link_params.shmem_base = bp->common.shmem_base;
12404 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
12405
12406 if (!bp->common.shmem_base ||
12407 (bp->common.shmem_base < 0xA0000) ||
12408 (bp->common.shmem_base >= 0xC0000)) {
12409 BNX2X_DEV_INFO("MCP not active\n");
12410 bp->flags |= NO_MCP_FLAG;
12411 return;
12412 }
12413
12414 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12415 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12416 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12417 BNX2X_ERR("BAD MCP validity signature\n");
12418
12419 if (!BP_NOMCP(bp)) {
12420 bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
12421 & DRV_MSG_SEQ_NUMBER_MASK);
12422 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
12423 }
12424}
12425
Wendy Xiong493adb12008-06-23 20:36:22 -070012426/**
12427 * bnx2x_io_error_detected - called when PCI error is detected
12428 * @pdev: Pointer to PCI device
12429 * @state: The current pci connection state
12430 *
12431 * This function is called after a PCI bus error affecting
12432 * this device has been detected.
12433 */
12434static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12435 pci_channel_state_t state)
12436{
12437 struct net_device *dev = pci_get_drvdata(pdev);
12438 struct bnx2x *bp = netdev_priv(dev);
12439
12440 rtnl_lock();
12441
12442 netif_device_detach(dev);
12443
Dean Nelson07ce50e42009-07-31 09:13:25 +000012444 if (state == pci_channel_io_perm_failure) {
12445 rtnl_unlock();
12446 return PCI_ERS_RESULT_DISCONNECT;
12447 }
12448
Wendy Xiong493adb12008-06-23 20:36:22 -070012449 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012450 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070012451
12452 pci_disable_device(pdev);
12453
12454 rtnl_unlock();
12455
12456 /* Request a slot reset */
12457 return PCI_ERS_RESULT_NEED_RESET;
12458}
12459
12460/**
12461 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12462 * @pdev: Pointer to PCI device
12463 *
12464 * Restart the card from scratch, as if from a cold-boot.
12465 */
12466static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12467{
12468 struct net_device *dev = pci_get_drvdata(pdev);
12469 struct bnx2x *bp = netdev_priv(dev);
12470
12471 rtnl_lock();
12472
12473 if (pci_enable_device(pdev)) {
12474 dev_err(&pdev->dev,
12475 "Cannot re-enable PCI device after reset\n");
12476 rtnl_unlock();
12477 return PCI_ERS_RESULT_DISCONNECT;
12478 }
12479
12480 pci_set_master(pdev);
12481 pci_restore_state(pdev);
12482
12483 if (netif_running(dev))
12484 bnx2x_set_power_state(bp, PCI_D0);
12485
12486 rtnl_unlock();
12487
12488 return PCI_ERS_RESULT_RECOVERED;
12489}
12490
12491/**
12492 * bnx2x_io_resume - called when traffic can start flowing again
12493 * @pdev: Pointer to PCI device
12494 *
12495 * This callback is called when the error recovery driver tells us that
12496 * its OK to resume normal operation.
12497 */
12498static void bnx2x_io_resume(struct pci_dev *pdev)
12499{
12500 struct net_device *dev = pci_get_drvdata(pdev);
12501 struct bnx2x *bp = netdev_priv(dev);
12502
12503 rtnl_lock();
12504
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012505 bnx2x_eeh_recover(bp);
12506
Wendy Xiong493adb12008-06-23 20:36:22 -070012507 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012508 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070012509
12510 netif_device_attach(dev);
12511
12512 rtnl_unlock();
12513}
12514
12515static struct pci_error_handlers bnx2x_err_handler = {
12516 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000012517 .slot_reset = bnx2x_io_slot_reset,
12518 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070012519};
12520
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012521static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070012522 .name = DRV_MODULE_NAME,
12523 .id_table = bnx2x_pci_tbl,
12524 .probe = bnx2x_init_one,
12525 .remove = __devexit_p(bnx2x_remove_one),
12526 .suspend = bnx2x_suspend,
12527 .resume = bnx2x_resume,
12528 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012529};
12530
12531static int __init bnx2x_init(void)
12532{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000012533 int ret;
12534
Eilon Greenstein938cf542009-08-12 08:23:37 +000012535 printk(KERN_INFO "%s", version);
12536
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080012537 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12538 if (bnx2x_wq == NULL) {
12539 printk(KERN_ERR PFX "Cannot create workqueue\n");
12540 return -ENOMEM;
12541 }
12542
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000012543 ret = pci_register_driver(&bnx2x_pci_driver);
12544 if (ret) {
12545 printk(KERN_ERR PFX "Cannot register driver\n");
12546 destroy_workqueue(bnx2x_wq);
12547 }
12548 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012549}
12550
12551static void __exit bnx2x_cleanup(void)
12552{
12553 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080012554
12555 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012556}
12557
12558module_init(bnx2x_init);
12559module_exit(bnx2x_cleanup);
12560
Michael Chan993ac7b2009-10-10 13:46:56 +000012561#ifdef BCM_CNIC
12562
12563/* count denotes the number of new completions we have seen */
12564static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12565{
12566 struct eth_spe *spe;
12567
12568#ifdef BNX2X_STOP_ON_ERROR
12569 if (unlikely(bp->panic))
12570 return;
12571#endif
12572
12573 spin_lock_bh(&bp->spq_lock);
12574 bp->cnic_spq_pending -= count;
12575
12576 for (; bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending;
12577 bp->cnic_spq_pending++) {
12578
12579 if (!bp->cnic_kwq_pending)
12580 break;
12581
12582 spe = bnx2x_sp_get_next(bp);
12583 *spe = *bp->cnic_kwq_cons;
12584
12585 bp->cnic_kwq_pending--;
12586
12587 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
12588 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12589
12590 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12591 bp->cnic_kwq_cons = bp->cnic_kwq;
12592 else
12593 bp->cnic_kwq_cons++;
12594 }
12595 bnx2x_sp_prod_update(bp);
12596 spin_unlock_bh(&bp->spq_lock);
12597}
12598
12599static int bnx2x_cnic_sp_queue(struct net_device *dev,
12600 struct kwqe_16 *kwqes[], u32 count)
12601{
12602 struct bnx2x *bp = netdev_priv(dev);
12603 int i;
12604
12605#ifdef BNX2X_STOP_ON_ERROR
12606 if (unlikely(bp->panic))
12607 return -EIO;
12608#endif
12609
12610 spin_lock_bh(&bp->spq_lock);
12611
12612 for (i = 0; i < count; i++) {
12613 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12614
12615 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12616 break;
12617
12618 *bp->cnic_kwq_prod = *spe;
12619
12620 bp->cnic_kwq_pending++;
12621
12622 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
12623 spe->hdr.conn_and_cmd_data, spe->hdr.type,
12624 spe->data.mac_config_addr.hi,
12625 spe->data.mac_config_addr.lo,
12626 bp->cnic_kwq_pending);
12627
12628 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12629 bp->cnic_kwq_prod = bp->cnic_kwq;
12630 else
12631 bp->cnic_kwq_prod++;
12632 }
12633
12634 spin_unlock_bh(&bp->spq_lock);
12635
12636 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12637 bnx2x_cnic_sp_post(bp, 0);
12638
12639 return i;
12640}
12641
12642static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12643{
12644 struct cnic_ops *c_ops;
12645 int rc = 0;
12646
12647 mutex_lock(&bp->cnic_mutex);
12648 c_ops = bp->cnic_ops;
12649 if (c_ops)
12650 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12651 mutex_unlock(&bp->cnic_mutex);
12652
12653 return rc;
12654}
12655
12656static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12657{
12658 struct cnic_ops *c_ops;
12659 int rc = 0;
12660
12661 rcu_read_lock();
12662 c_ops = rcu_dereference(bp->cnic_ops);
12663 if (c_ops)
12664 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12665 rcu_read_unlock();
12666
12667 return rc;
12668}
12669
12670/*
12671 * for commands that have no data
12672 */
12673static int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
12674{
12675 struct cnic_ctl_info ctl = {0};
12676
12677 ctl.cmd = cmd;
12678
12679 return bnx2x_cnic_ctl_send(bp, &ctl);
12680}
12681
12682static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid)
12683{
12684 struct cnic_ctl_info ctl;
12685
12686 /* first we tell CNIC and only then we count this as a completion */
12687 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
12688 ctl.data.comp.cid = cid;
12689
12690 bnx2x_cnic_ctl_send_bh(bp, &ctl);
12691 bnx2x_cnic_sp_post(bp, 1);
12692}
12693
12694static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
12695{
12696 struct bnx2x *bp = netdev_priv(dev);
12697 int rc = 0;
12698
12699 switch (ctl->cmd) {
12700 case DRV_CTL_CTXTBL_WR_CMD: {
12701 u32 index = ctl->data.io.offset;
12702 dma_addr_t addr = ctl->data.io.dma_addr;
12703
12704 bnx2x_ilt_wr(bp, index, addr);
12705 break;
12706 }
12707
12708 case DRV_CTL_COMPLETION_CMD: {
12709 int count = ctl->data.comp.comp_count;
12710
12711 bnx2x_cnic_sp_post(bp, count);
12712 break;
12713 }
12714
12715 /* rtnl_lock is held. */
12716 case DRV_CTL_START_L2_CMD: {
12717 u32 cli = ctl->data.ring.client_id;
12718
12719 bp->rx_mode_cl_mask |= (1 << cli);
12720 bnx2x_set_storm_rx_mode(bp);
12721 break;
12722 }
12723
12724 /* rtnl_lock is held. */
12725 case DRV_CTL_STOP_L2_CMD: {
12726 u32 cli = ctl->data.ring.client_id;
12727
12728 bp->rx_mode_cl_mask &= ~(1 << cli);
12729 bnx2x_set_storm_rx_mode(bp);
12730 break;
12731 }
12732
12733 default:
12734 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12735 rc = -EINVAL;
12736 }
12737
12738 return rc;
12739}
12740
12741static void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
12742{
12743 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12744
12745 if (bp->flags & USING_MSIX_FLAG) {
12746 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12747 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12748 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12749 } else {
12750 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12751 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12752 }
12753 cp->irq_arr[0].status_blk = bp->cnic_sb;
12754 cp->irq_arr[0].status_blk_num = CNIC_SB_ID(bp);
12755 cp->irq_arr[1].status_blk = bp->def_status_blk;
12756 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
12757
12758 cp->num_irq = 2;
12759}
12760
12761static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12762 void *data)
12763{
12764 struct bnx2x *bp = netdev_priv(dev);
12765 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12766
12767 if (ops == NULL)
12768 return -EINVAL;
12769
12770 if (atomic_read(&bp->intr_sem) != 0)
12771 return -EBUSY;
12772
12773 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12774 if (!bp->cnic_kwq)
12775 return -ENOMEM;
12776
12777 bp->cnic_kwq_cons = bp->cnic_kwq;
12778 bp->cnic_kwq_prod = bp->cnic_kwq;
12779 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12780
12781 bp->cnic_spq_pending = 0;
12782 bp->cnic_kwq_pending = 0;
12783
12784 bp->cnic_data = data;
12785
12786 cp->num_irq = 0;
12787 cp->drv_state = CNIC_DRV_STATE_REGD;
12788
12789 bnx2x_init_sb(bp, bp->cnic_sb, bp->cnic_sb_mapping, CNIC_SB_ID(bp));
12790
12791 bnx2x_setup_cnic_irq_info(bp);
12792 bnx2x_set_iscsi_eth_mac_addr(bp, 1);
12793 bp->cnic_flags |= BNX2X_CNIC_FLAG_MAC_SET;
12794 rcu_assign_pointer(bp->cnic_ops, ops);
12795
12796 return 0;
12797}
12798
12799static int bnx2x_unregister_cnic(struct net_device *dev)
12800{
12801 struct bnx2x *bp = netdev_priv(dev);
12802 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12803
12804 mutex_lock(&bp->cnic_mutex);
12805 if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
12806 bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
12807 bnx2x_set_iscsi_eth_mac_addr(bp, 0);
12808 }
12809 cp->drv_state = 0;
12810 rcu_assign_pointer(bp->cnic_ops, NULL);
12811 mutex_unlock(&bp->cnic_mutex);
12812 synchronize_rcu();
12813 kfree(bp->cnic_kwq);
12814 bp->cnic_kwq = NULL;
12815
12816 return 0;
12817}
12818
12819struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12820{
12821 struct bnx2x *bp = netdev_priv(dev);
12822 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12823
12824 cp->drv_owner = THIS_MODULE;
12825 cp->chip_id = CHIP_ID(bp);
12826 cp->pdev = bp->pdev;
12827 cp->io_base = bp->regview;
12828 cp->io_base2 = bp->doorbells;
12829 cp->max_kwqe_pending = 8;
12830 cp->ctx_blk_size = CNIC_CTX_PER_ILT * sizeof(union cdu_context);
12831 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + 1;
12832 cp->ctx_tbl_len = CNIC_ILT_LINES;
12833 cp->starting_cid = BCM_CNIC_CID_START;
12834 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12835 cp->drv_ctl = bnx2x_drv_ctl;
12836 cp->drv_register_cnic = bnx2x_register_cnic;
12837 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
12838
12839 return cp;
12840}
12841EXPORT_SYMBOL(bnx2x_cnic_probe);
12842
12843#endif /* BCM_CNIC */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012844