blob: 3abfce2d467e24a065fc6038420c54f608103fdb [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 *
Vladislav Zolotarov3359fce2010-02-17 13:35:01 -08003 * Copyright (c) 2007-2010 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
Dmitry Kravkovb0efbb92010-07-27 12:33:43 +000054#define BNX2X_MAIN
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"
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000058#include "bnx2x_cmn.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020059
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020060
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070061#include <linux/firmware.h>
62#include "bnx2x_fw_file_hdr.h"
63/* FW files */
Ben Hutchings45229b42009-11-07 11:53:39 +000064#define FW_FILE_VERSION \
65 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
66 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
67 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
68 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
69#define FW_FILE_NAME_E1 "bnx2x-e1-" FW_FILE_VERSION ".fw"
70#define FW_FILE_NAME_E1H "bnx2x-e1h-" FW_FILE_VERSION ".fw"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070071
Eilon Greenstein34f80b02008-06-23 20:33:01 -070072/* Time in jiffies before concluding the transmitter is hung */
73#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020074
Andrew Morton53a10562008-02-09 23:16:41 -080075static char version[] __devinitdata =
Eilon Greenstein34f80b02008-06-23 20:33:01 -070076 "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020077 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
78
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070079MODULE_AUTHOR("Eliezer Tamir");
Eilon Greensteine47d7e62009-01-14 06:44:28 +000080MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020081MODULE_LICENSE("GPL");
82MODULE_VERSION(DRV_MODULE_VERSION);
Ben Hutchings45229b42009-11-07 11:53:39 +000083MODULE_FIRMWARE(FW_FILE_NAME_E1);
84MODULE_FIRMWARE(FW_FILE_NAME_E1H);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020085
Eilon Greenstein555f6c72009-02-12 08:36:11 +000086static int multi_mode = 1;
87module_param(multi_mode, int, 0);
Eilon Greensteinca003922009-08-12 22:53:28 -070088MODULE_PARM_DESC(multi_mode, " Multi queue mode "
89 "(0 Disable; 1 Enable (default))");
90
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +000091static int num_queues;
92module_param(num_queues, int, 0);
93MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
94 " (default is as a number of CPUs)");
Eilon Greenstein555f6c72009-02-12 08:36:11 +000095
Eilon Greenstein19680c42008-08-13 15:47:33 -070096static int disable_tpa;
Eilon Greenstein19680c42008-08-13 15:47:33 -070097module_param(disable_tpa, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +000098MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
Eilon Greenstein8badd272009-02-12 08:36:15 +000099
100static int int_mode;
101module_param(int_mode, int, 0);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000102MODULE_PARM_DESC(int_mode, " Force interrupt mode other then MSI-X "
103 "(1 INT#x; 2 MSI)");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000104
Eilon Greensteina18f5122009-08-12 08:23:26 +0000105static int dropless_fc;
106module_param(dropless_fc, int, 0);
107MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
108
Eilon Greenstein9898f862009-02-12 08:38:27 +0000109static int poll;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200110module_param(poll, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000111MODULE_PARM_DESC(poll, " Use polling (for debug)");
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000112
113static int mrrs = -1;
114module_param(mrrs, int, 0);
115MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
116
Eilon Greenstein9898f862009-02-12 08:38:27 +0000117static int debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200118module_param(debug, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000119MODULE_PARM_DESC(debug, " Default debug msglevel");
120
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800121static struct workqueue_struct *bnx2x_wq;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200122
123enum bnx2x_board_type {
124 BCM57710 = 0,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700125 BCM57711 = 1,
126 BCM57711E = 2,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200127};
128
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700129/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800130static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200131 char *name;
132} board_info[] __devinitdata = {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700133 { "Broadcom NetXtreme II BCM57710 XGb" },
134 { "Broadcom NetXtreme II BCM57711 XGb" },
135 { "Broadcom NetXtreme II BCM57711E XGb" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200136};
137
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700138
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000139static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000140 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
141 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
142 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200143 { 0 }
144};
145
146MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
147
148/****************************************************************************
149* General service functions
150****************************************************************************/
151
152/* used only at init
153 * locking is done by mcp
154 */
Eilon Greenstein573f2032009-08-12 08:24:14 +0000155void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200156{
157 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
158 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
159 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
160 PCICFG_VENDOR_ID_OFFSET);
161}
162
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200163static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
164{
165 u32 val;
166
167 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
168 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
169 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
170 PCICFG_VENDOR_ID_OFFSET);
171
172 return val;
173}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200174
175static const u32 dmae_reg_go_c[] = {
176 DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
177 DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
178 DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
179 DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
180};
181
182/* copy command into DMAE command memory and set DMAE command go */
183static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
184 int idx)
185{
186 u32 cmd_offset;
187 int i;
188
189 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
190 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
191 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
192
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700193 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
194 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200195 }
196 REG_WR(bp, dmae_reg_go_c[idx], 1);
197}
198
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700199void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
200 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200201{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000202 struct dmae_command dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200203 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700204 int cnt = 200;
205
206 if (!bp->dmae_ready) {
207 u32 *data = bnx2x_sp(bp, wb_data[0]);
208
209 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
210 " using indirect\n", dst_addr, len32);
211 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
212 return;
213 }
214
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000215 memset(&dmae, 0, sizeof(struct dmae_command));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200216
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000217 dmae.opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
218 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
219 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200220#ifdef __BIG_ENDIAN
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000221 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200222#else
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000223 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200224#endif
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000225 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
226 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
227 dmae.src_addr_lo = U64_LO(dma_addr);
228 dmae.src_addr_hi = U64_HI(dma_addr);
229 dmae.dst_addr_lo = dst_addr >> 2;
230 dmae.dst_addr_hi = 0;
231 dmae.len = len32;
232 dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
233 dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
234 dmae.comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200235
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000236 DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200237 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
238 "dst_addr [%x:%08x (%08x)]\n"
239 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000240 dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
241 dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, dst_addr,
242 dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700243 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200244 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
245 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200246
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000247 mutex_lock(&bp->dmae_mutex);
248
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200249 *wb_comp = 0;
250
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000251 bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200252
253 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700254
255 while (*wb_comp != DMAE_COMP_VAL) {
256 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
257
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700258 if (!cnt) {
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000259 BNX2X_ERR("DMAE timeout!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200260 break;
261 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700262 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700263 /* adjust delay for emulation/FPGA */
264 if (CHIP_REV_IS_SLOW(bp))
265 msleep(100);
266 else
267 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200268 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700269
270 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200271}
272
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700273void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200274{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000275 struct dmae_command dmae;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200276 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700277 int cnt = 200;
278
279 if (!bp->dmae_ready) {
280 u32 *data = bnx2x_sp(bp, wb_data[0]);
281 int i;
282
283 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
284 " using indirect\n", src_addr, len32);
285 for (i = 0; i < len32; i++)
286 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
287 return;
288 }
289
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000290 memset(&dmae, 0, sizeof(struct dmae_command));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200291
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000292 dmae.opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
293 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
294 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200295#ifdef __BIG_ENDIAN
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000296 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200297#else
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000298 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200299#endif
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000300 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
301 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
302 dmae.src_addr_lo = src_addr >> 2;
303 dmae.src_addr_hi = 0;
304 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
305 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
306 dmae.len = len32;
307 dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
308 dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
309 dmae.comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200310
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000311 DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200312 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
313 "dst_addr [%x:%08x (%08x)]\n"
314 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000315 dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
316 dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, src_addr,
317 dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200318
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000319 mutex_lock(&bp->dmae_mutex);
320
321 memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200322 *wb_comp = 0;
323
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000324 bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200325
326 udelay(5);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700327
328 while (*wb_comp != DMAE_COMP_VAL) {
329
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700330 if (!cnt) {
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000331 BNX2X_ERR("DMAE timeout!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200332 break;
333 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700334 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -0700335 /* adjust delay for emulation/FPGA */
336 if (CHIP_REV_IS_SLOW(bp))
337 msleep(100);
338 else
339 udelay(5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200340 }
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700341 DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200342 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
343 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700344
345 mutex_unlock(&bp->dmae_mutex);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200346}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200347
Eilon Greenstein573f2032009-08-12 08:24:14 +0000348void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
349 u32 addr, u32 len)
350{
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000351 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
Eilon Greenstein573f2032009-08-12 08:24:14 +0000352 int offset = 0;
353
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000354 while (len > dmae_wr_max) {
Eilon Greenstein573f2032009-08-12 08:24:14 +0000355 bnx2x_write_dmae(bp, phys_addr + offset,
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000356 addr + offset, dmae_wr_max);
357 offset += dmae_wr_max * 4;
358 len -= dmae_wr_max;
Eilon Greenstein573f2032009-08-12 08:24:14 +0000359 }
360
361 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
362}
363
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700364/* used only for slowpath so not inlined */
365static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
366{
367 u32 wb_write[2];
368
369 wb_write[0] = val_hi;
370 wb_write[1] = val_lo;
371 REG_WR_DMAE(bp, reg, wb_write, 2);
372}
373
374#ifdef USE_WB_RD
375static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
376{
377 u32 wb_data[2];
378
379 REG_RD_DMAE(bp, reg, wb_data, 2);
380
381 return HILO_U64(wb_data[0], wb_data[1]);
382}
383#endif
384
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200385static int bnx2x_mc_assert(struct bnx2x *bp)
386{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200387 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700388 int i, rc = 0;
389 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200390
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700391 /* XSTORM */
392 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
393 XSTORM_ASSERT_LIST_INDEX_OFFSET);
394 if (last_idx)
395 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200396
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700397 /* print the asserts */
398 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200399
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700400 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
401 XSTORM_ASSERT_LIST_OFFSET(i));
402 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
403 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
404 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
405 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
406 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
407 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200408
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700409 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
410 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
411 " 0x%08x 0x%08x 0x%08x\n",
412 i, row3, row2, row1, row0);
413 rc++;
414 } else {
415 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200416 }
417 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700418
419 /* TSTORM */
420 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
421 TSTORM_ASSERT_LIST_INDEX_OFFSET);
422 if (last_idx)
423 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
424
425 /* print the asserts */
426 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
427
428 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
429 TSTORM_ASSERT_LIST_OFFSET(i));
430 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
431 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
432 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
433 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
434 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
435 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
436
437 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
438 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
439 " 0x%08x 0x%08x 0x%08x\n",
440 i, row3, row2, row1, row0);
441 rc++;
442 } else {
443 break;
444 }
445 }
446
447 /* CSTORM */
448 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
449 CSTORM_ASSERT_LIST_INDEX_OFFSET);
450 if (last_idx)
451 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
452
453 /* print the asserts */
454 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
455
456 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
457 CSTORM_ASSERT_LIST_OFFSET(i));
458 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
459 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
460 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
461 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
462 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
463 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
464
465 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
466 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
467 " 0x%08x 0x%08x 0x%08x\n",
468 i, row3, row2, row1, row0);
469 rc++;
470 } else {
471 break;
472 }
473 }
474
475 /* USTORM */
476 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
477 USTORM_ASSERT_LIST_INDEX_OFFSET);
478 if (last_idx)
479 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
480
481 /* print the asserts */
482 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
483
484 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
485 USTORM_ASSERT_LIST_OFFSET(i));
486 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
487 USTORM_ASSERT_LIST_OFFSET(i) + 4);
488 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
489 USTORM_ASSERT_LIST_OFFSET(i) + 8);
490 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
491 USTORM_ASSERT_LIST_OFFSET(i) + 12);
492
493 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
494 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
495 " 0x%08x 0x%08x 0x%08x\n",
496 i, row3, row2, row1, row0);
497 rc++;
498 } else {
499 break;
500 }
501 }
502
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200503 return rc;
504}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800505
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200506static void bnx2x_fw_dump(struct bnx2x *bp)
507{
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000508 u32 addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200509 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000510 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200511 int word;
512
Vladislav Zolotarov2145a922010-04-19 01:13:49 +0000513 if (BP_NOMCP(bp)) {
514 BNX2X_ERR("NO MCP - can not dump\n");
515 return;
516 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000517
518 addr = bp->common.shmem_base - 0x0800 + 4;
519 mark = REG_RD(bp, addr);
520 mark = MCP_REG_MCPR_SCRATCH + ((mark + 0x3) & ~0x3) - 0x08000000;
Joe Perches7995c642010-02-17 15:01:52 +0000521 pr_err("begin fw dump (mark 0x%x)\n", mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200522
Joe Perches7995c642010-02-17 15:01:52 +0000523 pr_err("");
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000524 for (offset = mark; offset <= bp->common.shmem_base; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200525 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000526 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200527 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000528 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200529 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000530 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200531 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000532 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200533 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000534 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200535 }
Joe Perches7995c642010-02-17 15:01:52 +0000536 pr_err("end of fw dump\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200537}
538
539static void bnx2x_panic_dump(struct bnx2x *bp)
540{
541 int i;
542 u16 j, start, end;
543
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700544 bp->stats_state = STATS_STATE_DISABLED;
545 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
546
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200547 BNX2X_ERR("begin crash dump -----------------\n");
548
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000549 /* Indices */
550 /* Common */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000551 BNX2X_ERR("def_c_idx(0x%x) def_u_idx(0x%x) def_x_idx(0x%x)"
552 " def_t_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
553 " spq_prod_idx(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000554 bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
555 bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
556
557 /* Rx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000558 for_each_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000559 struct bnx2x_fastpath *fp = &bp->fp[i];
560
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000561 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
562 " *rx_bd_cons_sb(0x%x) rx_comp_prod(0x%x)"
563 " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000564 i, fp->rx_bd_prod, fp->rx_bd_cons,
565 le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
566 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000567 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
568 " fp_u_idx(0x%x) *sb_u_idx(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000569 fp->rx_sge_prod, fp->last_max_sge,
570 le16_to_cpu(fp->fp_u_idx),
571 fp->status_blk->u_status_block.status_block_index);
572 }
573
574 /* Tx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000575 for_each_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200576 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200577
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000578 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
579 " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
580 " *tx_cons_sb(0x%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200581 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700582 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000583 BNX2X_ERR(" fp_c_idx(0x%x) *sb_c_idx(0x%x)"
584 " tx_db_prod(0x%x)\n", le16_to_cpu(fp->fp_c_idx),
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700585 fp->status_blk->c_status_block.status_block_index,
Eilon Greensteinca003922009-08-12 22:53:28 -0700586 fp->tx_db.data.prod);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000587 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200588
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000589 /* Rings */
590 /* Rx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000591 for_each_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000592 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200593
594 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
595 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000596 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200597 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
598 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
599
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000600 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
601 i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200602 }
603
Eilon Greenstein3196a882008-08-13 15:58:49 -0700604 start = RX_SGE(fp->rx_sge_prod);
605 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000606 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700607 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
608 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
609
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000610 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
611 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700612 }
613
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200614 start = RCQ_BD(fp->rx_comp_cons - 10);
615 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000616 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200617 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
618
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000619 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
620 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200621 }
622 }
623
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000624 /* Tx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000625 for_each_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000626 struct bnx2x_fastpath *fp = &bp->fp[i];
627
628 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
629 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
630 for (j = start; j != end; j = TX_BD(j + 1)) {
631 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
632
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000633 BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
634 i, j, sw_bd->skb, sw_bd->first_bd);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000635 }
636
637 start = TX_BD(fp->tx_bd_cons - 10);
638 end = TX_BD(fp->tx_bd_cons + 254);
639 for (j = start; j != end; j = TX_BD(j + 1)) {
640 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
641
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000642 BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
643 i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000644 }
645 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200646
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700647 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200648 bnx2x_mc_assert(bp);
649 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200650}
651
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000652void bnx2x_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200653{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700654 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200655 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
656 u32 val = REG_RD(bp, addr);
657 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000658 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200659
660 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000661 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
662 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200663 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
664 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eilon Greenstein8badd272009-02-12 08:36:15 +0000665 } else if (msi) {
666 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
667 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
668 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
669 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200670 } else {
671 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800672 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200673 HC_CONFIG_0_REG_INT_LINE_EN_0 |
674 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800675
Eilon Greenstein8badd272009-02-12 08:36:15 +0000676 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
677 val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800678
679 REG_WR(bp, addr, val);
680
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200681 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
682 }
683
Eilon Greenstein8badd272009-02-12 08:36:15 +0000684 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
685 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200686
687 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +0000688 /*
689 * Ensure that HC_CONFIG is written before leading/trailing edge config
690 */
691 mmiowb();
692 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700693
694 if (CHIP_IS_E1H(bp)) {
695 /* init leading/trailing edge */
696 if (IS_E1HMF(bp)) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000697 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700698 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +0000699 /* enable nig and gpio3 attention */
700 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700701 } else
702 val = 0xffff;
703
704 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
705 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
706 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +0000707
708 /* Make sure that interrupts are indeed enabled from here on */
709 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200710}
711
Eliezer Tamir615f8fd2008-02-28 11:54:54 -0800712static void bnx2x_int_disable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200713{
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700714 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200715 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
716 u32 val = REG_RD(bp, addr);
717
718 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
719 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
720 HC_CONFIG_0_REG_INT_LINE_EN_0 |
721 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
722
723 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
724 val, port, addr);
725
Eilon Greenstein8badd272009-02-12 08:36:15 +0000726 /* flush all outstanding writes */
727 mmiowb();
728
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200729 REG_WR(bp, addr, val);
730 if (REG_RD(bp, addr) != val)
731 BNX2X_ERR("BUG! proper val not read from IGU!\n");
732}
733
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000734void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200735{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200736 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000737 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200738
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700739 /* disable interrupt handling */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200740 atomic_inc(&bp->intr_sem);
Eilon Greensteine1510702009-07-21 05:47:41 +0000741 smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
742
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -0700743 if (disable_hw)
744 /* prevent the HW from sending interrupts */
745 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200746
747 /* make sure all ISRs are done */
748 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +0000749 synchronize_irq(bp->msix_table[0].vector);
750 offset = 1;
Michael Chan37b091b2009-10-10 13:46:55 +0000751#ifdef BCM_CNIC
752 offset++;
753#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200754 for_each_queue(bp, i)
Eilon Greenstein8badd272009-02-12 08:36:15 +0000755 synchronize_irq(bp->msix_table[i + offset].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200756 } else
757 synchronize_irq(bp->pdev->irq);
758
759 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800760 cancel_delayed_work(&bp->sp_task);
761 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200762}
763
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700764/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200765
766/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700767 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200768 */
769
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000770/* Return true if succeeded to acquire the lock */
771static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
772{
773 u32 lock_status;
774 u32 resource_bit = (1 << resource);
775 int func = BP_FUNC(bp);
776 u32 hw_lock_control_reg;
777
778 DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
779
780 /* Validating that the resource is within range */
781 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
782 DP(NETIF_MSG_HW,
783 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
784 resource, HW_LOCK_MAX_RESOURCE_VALUE);
785 return -EINVAL;
786 }
787
788 if (func <= 5)
789 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
790 else
791 hw_lock_control_reg =
792 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
793
794 /* Try to acquire the lock */
795 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
796 lock_status = REG_RD(bp, hw_lock_control_reg);
797 if (lock_status & resource_bit)
798 return true;
799
800 DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
801 return false;
802}
803
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200804
Michael Chan993ac7b2009-10-10 13:46:56 +0000805#ifdef BCM_CNIC
806static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid);
807#endif
Eilon Greenstein3196a882008-08-13 15:58:49 -0700808
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000809void bnx2x_sp_event(struct bnx2x_fastpath *fp,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200810 union eth_rx_cqe *rr_cqe)
811{
812 struct bnx2x *bp = fp->bp;
813 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
814 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
815
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700816 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200817 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +0000818 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700819 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200820
821 bp->spq_left++;
822
Eilon Greenstein0626b892009-02-12 08:38:14 +0000823 if (fp->index) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200824 switch (command | fp->state) {
825 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
826 BNX2X_FP_STATE_OPENING):
827 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
828 cid);
829 fp->state = BNX2X_FP_STATE_OPEN;
830 break;
831
832 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
833 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
834 cid);
835 fp->state = BNX2X_FP_STATE_HALTED;
836 break;
837
838 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700839 BNX2X_ERR("unexpected MC reply (%d) "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000840 "fp[%d] state is %x\n",
841 command, fp->index, fp->state);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700842 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200843 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700844 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200845 return;
846 }
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800847
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200848 switch (command | bp->state) {
849 case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
850 DP(NETIF_MSG_IFUP, "got setup ramrod\n");
851 bp->state = BNX2X_STATE_OPEN;
852 break;
853
854 case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
855 DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
856 bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
857 fp->state = BNX2X_FP_STATE_HALTED;
858 break;
859
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200860 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700861 DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
Eliezer Tamir49d66772008-02-28 11:53:13 -0800862 bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200863 break;
864
Michael Chan993ac7b2009-10-10 13:46:56 +0000865#ifdef BCM_CNIC
866 case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_OPEN):
867 DP(NETIF_MSG_IFDOWN, "got delete ramrod for CID %d\n", cid);
868 bnx2x_cnic_cfc_comp(bp, cid);
869 break;
870#endif
Eilon Greenstein3196a882008-08-13 15:58:49 -0700871
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200872 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700873 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200874 DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
Michael Chane665bfd2009-10-10 13:46:54 +0000875 bp->set_mac_pending--;
876 smp_wmb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200877 break;
878
Eliezer Tamir49d66772008-02-28 11:53:13 -0800879 case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700880 DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
Michael Chane665bfd2009-10-10 13:46:54 +0000881 bp->set_mac_pending--;
882 smp_wmb();
Eliezer Tamir49d66772008-02-28 11:53:13 -0800883 break;
884
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200885 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700886 BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200887 command, bp->state);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700888 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200889 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700890 mb(); /* force bnx2x_wait_ramrod() to see the change */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200891}
892
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000893irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200894{
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000895 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200896 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700897 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -0700898 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200899
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700900 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200901 if (unlikely(status == 0)) {
902 DP(NETIF_MSG_INTR, "not our interrupt!\n");
903 return IRQ_NONE;
904 }
Eilon Greensteinf5372252009-02-12 08:38:30 +0000905 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200906
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700907 /* Return here if interrupt is disabled */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200908 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
909 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
910 return IRQ_HANDLED;
911 }
912
Eilon Greenstein3196a882008-08-13 15:58:49 -0700913#ifdef BNX2X_STOP_ON_ERROR
914 if (unlikely(bp->panic))
915 return IRQ_HANDLED;
916#endif
917
Eilon Greensteinca003922009-08-12 22:53:28 -0700918 for (i = 0; i < BNX2X_NUM_QUEUES(bp); i++) {
919 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200920
Eilon Greensteinca003922009-08-12 22:53:28 -0700921 mask = 0x2 << fp->sb_id;
922 if (status & mask) {
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000923 /* Handle Rx and Tx according to SB id */
924 prefetch(fp->rx_cons_sb);
925 prefetch(&fp->status_blk->u_status_block.
926 status_block_index);
927 prefetch(fp->tx_cons_sb);
928 prefetch(&fp->status_blk->c_status_block.
929 status_block_index);
930 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eilon Greensteinca003922009-08-12 22:53:28 -0700931 status &= ~mask;
932 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200933 }
934
Michael Chan993ac7b2009-10-10 13:46:56 +0000935#ifdef BCM_CNIC
936 mask = 0x2 << CNIC_SB_ID(bp);
937 if (status & (mask | 0x1)) {
938 struct cnic_ops *c_ops = NULL;
939
940 rcu_read_lock();
941 c_ops = rcu_dereference(bp->cnic_ops);
942 if (c_ops)
943 c_ops->cnic_handler(bp->cnic_data, NULL);
944 rcu_read_unlock();
945
946 status &= ~mask;
947 }
948#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200949
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700950 if (unlikely(status & 0x1)) {
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800951 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200952
953 status &= ~0x1;
954 if (!status)
955 return IRQ_HANDLED;
956 }
957
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000958 if (unlikely(status))
959 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700960 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200961
962 return IRQ_HANDLED;
963}
964
965/* end of fast path */
966
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700967
968/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200969
970/*
971 * General service functions
972 */
973
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000974int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -0800975{
Eliezer Tamirf1410642008-02-28 11:51:50 -0800976 u32 lock_status;
977 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -0700978 int func = BP_FUNC(bp);
979 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700980 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -0800981
982 /* Validating that the resource is within range */
983 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
984 DP(NETIF_MSG_HW,
985 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
986 resource, HW_LOCK_MAX_RESOURCE_VALUE);
987 return -EINVAL;
988 }
989
Yitchak Gertner4a37fb62008-08-13 15:50:23 -0700990 if (func <= 5) {
991 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
992 } else {
993 hw_lock_control_reg =
994 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
995 }
996
Eliezer Tamirf1410642008-02-28 11:51:50 -0800997 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -0700998 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -0800999 if (lock_status & resource_bit) {
1000 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1001 lock_status, resource_bit);
1002 return -EEXIST;
1003 }
1004
Eilon Greenstein46230476b2008-08-25 15:23:30 -07001005 /* Try for 5 second every 5ms */
1006 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001007 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001008 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1009 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001010 if (lock_status & resource_bit)
1011 return 0;
1012
1013 msleep(5);
1014 }
1015 DP(NETIF_MSG_HW, "Timeout\n");
1016 return -EAGAIN;
1017}
1018
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001019int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001020{
1021 u32 lock_status;
1022 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001023 int func = BP_FUNC(bp);
1024 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001025
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001026 DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
1027
Eliezer Tamirf1410642008-02-28 11:51:50 -08001028 /* Validating that the resource is within range */
1029 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1030 DP(NETIF_MSG_HW,
1031 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1032 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1033 return -EINVAL;
1034 }
1035
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001036 if (func <= 5) {
1037 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1038 } else {
1039 hw_lock_control_reg =
1040 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1041 }
1042
Eliezer Tamirf1410642008-02-28 11:51:50 -08001043 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001044 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001045 if (!(lock_status & resource_bit)) {
1046 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1047 lock_status, resource_bit);
1048 return -EFAULT;
1049 }
1050
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001051 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001052 return 0;
1053}
1054
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001055
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001056int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1057{
1058 /* The GPIO should be swapped if swap register is set and active */
1059 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1060 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1061 int gpio_shift = gpio_num +
1062 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1063 u32 gpio_mask = (1 << gpio_shift);
1064 u32 gpio_reg;
1065 int value;
1066
1067 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1068 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1069 return -EINVAL;
1070 }
1071
1072 /* read GPIO value */
1073 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1074
1075 /* get the requested pin value */
1076 if ((gpio_reg & gpio_mask) == gpio_mask)
1077 value = 1;
1078 else
1079 value = 0;
1080
1081 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1082
1083 return value;
1084}
1085
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001086int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001087{
1088 /* The GPIO should be swapped if swap register is set and active */
1089 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001090 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001091 int gpio_shift = gpio_num +
1092 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1093 u32 gpio_mask = (1 << gpio_shift);
1094 u32 gpio_reg;
1095
1096 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1097 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1098 return -EINVAL;
1099 }
1100
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001101 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001102 /* read GPIO and mask except the float bits */
1103 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1104
1105 switch (mode) {
1106 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1107 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1108 gpio_num, gpio_shift);
1109 /* clear FLOAT and set CLR */
1110 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1111 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1112 break;
1113
1114 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1115 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1116 gpio_num, gpio_shift);
1117 /* clear FLOAT and set SET */
1118 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1119 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1120 break;
1121
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001122 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001123 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1124 gpio_num, gpio_shift);
1125 /* set FLOAT */
1126 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1127 break;
1128
1129 default:
1130 break;
1131 }
1132
1133 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001134 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001135
1136 return 0;
1137}
1138
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001139int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1140{
1141 /* The GPIO should be swapped if swap register is set and active */
1142 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1143 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1144 int gpio_shift = gpio_num +
1145 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1146 u32 gpio_mask = (1 << gpio_shift);
1147 u32 gpio_reg;
1148
1149 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1150 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1151 return -EINVAL;
1152 }
1153
1154 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1155 /* read GPIO int */
1156 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1157
1158 switch (mode) {
1159 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1160 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
1161 "output low\n", gpio_num, gpio_shift);
1162 /* clear SET and set CLR */
1163 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1164 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1165 break;
1166
1167 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1168 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
1169 "output high\n", gpio_num, gpio_shift);
1170 /* clear CLR and set SET */
1171 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1172 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1173 break;
1174
1175 default:
1176 break;
1177 }
1178
1179 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1180 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1181
1182 return 0;
1183}
1184
Eliezer Tamirf1410642008-02-28 11:51:50 -08001185static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
1186{
1187 u32 spio_mask = (1 << spio_num);
1188 u32 spio_reg;
1189
1190 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
1191 (spio_num > MISC_REGISTERS_SPIO_7)) {
1192 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
1193 return -EINVAL;
1194 }
1195
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001196 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001197 /* read SPIO and mask except the float bits */
1198 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
1199
1200 switch (mode) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07001201 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001202 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
1203 /* clear FLOAT and set CLR */
1204 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
1205 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
1206 break;
1207
Eilon Greenstein6378c022008-08-13 15:59:25 -07001208 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001209 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
1210 /* clear FLOAT and set SET */
1211 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
1212 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
1213 break;
1214
1215 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
1216 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
1217 /* set FLOAT */
1218 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
1219 break;
1220
1221 default:
1222 break;
1223 }
1224
1225 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001226 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001227
1228 return 0;
1229}
1230
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001231void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001232{
Eilon Greensteinad33ea32009-01-14 21:24:57 -08001233 switch (bp->link_vars.ieee_fc &
1234 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001235 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001236 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001237 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001238 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00001239
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001240 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001241 bp->port.advertising |= (ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001242 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001243 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00001244
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001245 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001246 bp->port.advertising |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001247 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00001248
Eliezer Tamirf1410642008-02-28 11:51:50 -08001249 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001250 bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001251 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001252 break;
1253 }
1254}
1255
Eilon Greenstein2691d512009-08-12 08:22:08 +00001256
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001257u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001258{
Eilon Greenstein19680c42008-08-13 15:47:33 -07001259 if (!BP_NOMCP(bp)) {
1260 u8 rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001261
Eilon Greenstein19680c42008-08-13 15:47:33 -07001262 /* Initialize link parameters structure variables */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001263 /* It is recommended to turn off RX FC for jumbo frames
1264 for better performance */
Eilon Greenstein0c593272009-08-12 08:22:13 +00001265 if (bp->dev->mtu > 5000)
David S. Millerc0700f92008-12-16 23:53:20 -08001266 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001267 else
David S. Millerc0700f92008-12-16 23:53:20 -08001268 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001269
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001270 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001271
1272 if (load_mode == LOAD_DIAG)
1273 bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
1274
Eilon Greenstein19680c42008-08-13 15:47:33 -07001275 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001276
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001277 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001278
Eilon Greenstein3c96c682009-01-14 21:25:31 -08001279 bnx2x_calc_fc_adv(bp);
1280
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001281 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
1282 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07001283 bnx2x_link_report(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001284 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001285
Eilon Greenstein19680c42008-08-13 15:47:33 -07001286 return rc;
1287 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001288 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07001289 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001290}
1291
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001292void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001293{
Eilon Greenstein19680c42008-08-13 15:47:33 -07001294 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001295 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07001296 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001297 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001298
Eilon Greenstein19680c42008-08-13 15:47:33 -07001299 bnx2x_calc_fc_adv(bp);
1300 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00001301 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001302}
1303
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001304static void bnx2x__link_reset(struct bnx2x *bp)
1305{
Eilon Greenstein19680c42008-08-13 15:47:33 -07001306 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001307 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00001308 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001309 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07001310 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00001311 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001312}
1313
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001314u8 bnx2x_link_test(struct bnx2x *bp)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001315{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00001316 u8 rc = 0;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001317
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00001318 if (!BP_NOMCP(bp)) {
1319 bnx2x_acquire_phy_lock(bp);
1320 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
1321 bnx2x_release_phy_lock(bp);
1322 } else
1323 BNX2X_ERR("Bootcode is missing - can not test link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001324
1325 return rc;
1326}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001327
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001328static void bnx2x_init_port_minmax(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001329{
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001330 u32 r_param = bp->link_vars.line_speed / 8;
1331 u32 fair_periodic_timeout_usec;
1332 u32 t_fair;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001333
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001334 memset(&(bp->cmng.rs_vars), 0,
1335 sizeof(struct rate_shaping_vars_per_port));
1336 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001337
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001338 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
1339 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001340
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001341 /* this is the threshold below which no timer arming will occur
1342 1.25 coefficient is for the threshold to be a little bigger
1343 than the real time, to compensate for timer in-accuracy */
1344 bp->cmng.rs_vars.rs_threshold =
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001345 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
1346
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001347 /* resolution of fairness timer */
1348 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
1349 /* for 10G it is 1000usec. for 1G it is 10000usec. */
1350 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001351
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001352 /* this is the threshold below which we won't arm the timer anymore */
1353 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001354
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001355 /* we multiply by 1e3/8 to get bytes/msec.
1356 We don't want the credits to pass a credit
1357 of the t_fair*FAIR_MEM (algorithm resolution) */
1358 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
1359 /* since each tick is 4 usec */
1360 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001361}
1362
Eilon Greenstein2691d512009-08-12 08:22:08 +00001363/* Calculates the sum of vn_min_rates.
1364 It's needed for further normalizing of the min_rates.
1365 Returns:
1366 sum of vn_min_rates.
1367 or
1368 0 - if all the min_rates are 0.
1369 In the later case fainess algorithm should be deactivated.
1370 If not all min_rates are zero then those that are zeroes will be set to 1.
1371 */
1372static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
1373{
1374 int all_zero = 1;
1375 int port = BP_PORT(bp);
1376 int vn;
1377
1378 bp->vn_weight_sum = 0;
1379 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
1380 int func = 2*vn + port;
1381 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
1382 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
1383 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
1384
1385 /* Skip hidden vns */
1386 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
1387 continue;
1388
1389 /* If min rate is zero - set it to 1 */
1390 if (!vn_min_rate)
1391 vn_min_rate = DEF_MIN_RATE;
1392 else
1393 all_zero = 0;
1394
1395 bp->vn_weight_sum += vn_min_rate;
1396 }
1397
1398 /* ... only if all min rates are zeros - disable fairness */
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07001399 if (all_zero) {
1400 bp->cmng.flags.cmng_enables &=
1401 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
1402 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
1403 " fairness will be disabled\n");
1404 } else
1405 bp->cmng.flags.cmng_enables |=
1406 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00001407}
1408
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001409static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001410{
1411 struct rate_shaping_vars_per_vn m_rs_vn;
1412 struct fairness_vars_per_vn m_fair_vn;
1413 u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
1414 u16 vn_min_rate, vn_max_rate;
1415 int i;
1416
1417 /* If function is hidden - set min and max to zeroes */
1418 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
1419 vn_min_rate = 0;
1420 vn_max_rate = 0;
1421
1422 } else {
1423 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
1424 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07001425 /* If min rate is zero - set it to 1 */
1426 if (!vn_min_rate)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001427 vn_min_rate = DEF_MIN_RATE;
1428 vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
1429 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
1430 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001431 DP(NETIF_MSG_IFUP,
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07001432 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001433 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001434
1435 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
1436 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
1437
1438 /* global vn counter - maximal Mbps for this vn */
1439 m_rs_vn.vn_counter.rate = vn_max_rate;
1440
1441 /* quota - number of bytes transmitted in this period */
1442 m_rs_vn.vn_counter.quota =
1443 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
1444
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001445 if (bp->vn_weight_sum) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001446 /* credit for each period of the fairness algorithm:
1447 number of bytes in T_FAIR (the vn share the port rate).
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001448 vn_weight_sum should not be larger than 10000, thus
1449 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
1450 than zero */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001451 m_fair_vn.vn_credit_delta =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001452 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
1453 (8 * bp->vn_weight_sum))),
1454 (bp->cmng.fair_vars.fair_threshold * 2));
1455 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001456 m_fair_vn.vn_credit_delta);
1457 }
1458
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001459 /* Store it to internal memory */
1460 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
1461 REG_WR(bp, BAR_XSTRORM_INTMEM +
1462 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
1463 ((u32 *)(&m_rs_vn))[i]);
1464
1465 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
1466 REG_WR(bp, BAR_XSTRORM_INTMEM +
1467 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
1468 ((u32 *)(&m_fair_vn))[i]);
1469}
1470
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001471
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001472/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001473static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001474{
Vladislav Zolotarovd9e8b182010-04-19 01:15:08 +00001475 u32 prev_link_status = bp->link_vars.link_status;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001476 /* Make sure that we are synced with the current statistics */
1477 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1478
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001479 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001480
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001481 if (bp->link_vars.link_up) {
1482
Eilon Greenstein1c063282009-02-12 08:36:43 +00001483 /* dropless flow control */
Eilon Greensteina18f5122009-08-12 08:23:26 +00001484 if (CHIP_IS_E1H(bp) && bp->dropless_fc) {
Eilon Greenstein1c063282009-02-12 08:36:43 +00001485 int port = BP_PORT(bp);
1486 u32 pause_enabled = 0;
1487
1488 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
1489 pause_enabled = 1;
1490
1491 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07001492 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
Eilon Greenstein1c063282009-02-12 08:36:43 +00001493 pause_enabled);
1494 }
1495
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001496 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
1497 struct host_port_stats *pstats;
1498
1499 pstats = bnx2x_sp(bp, port_stats);
1500 /* reset old bmac stats */
1501 memset(&(pstats->mac_stx[0]), 0,
1502 sizeof(struct mac_stx));
1503 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07001504 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001505 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
1506 }
1507
Vladislav Zolotarovd9e8b182010-04-19 01:15:08 +00001508 /* indicate link status only if link status actually changed */
1509 if (prev_link_status != bp->link_vars.link_status)
1510 bnx2x_link_report(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001511
1512 if (IS_E1HMF(bp)) {
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001513 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001514 int func;
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001515 int vn;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001516
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001517 /* Set the attention towards other drivers on the same port */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001518 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
1519 if (vn == BP_E1HVN(bp))
1520 continue;
1521
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001522 func = ((vn << 1) | port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001523 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
1524 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
1525 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001526
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001527 if (bp->link_vars.link_up) {
1528 int i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001529
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001530 /* Init rate shaping and fairness contexts */
1531 bnx2x_init_port_minmax(bp);
1532
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001533 for (vn = VN_0; vn < E1HVN_MAX; vn++)
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00001534 bnx2x_init_vn_minmax(bp, 2*vn + port);
1535
1536 /* Store it to internal memory */
1537 for (i = 0;
1538 i < sizeof(struct cmng_struct_per_port) / 4; i++)
1539 REG_WR(bp, BAR_XSTRORM_INTMEM +
1540 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
1541 ((u32 *)(&bp->cmng))[i]);
1542 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001543 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001544}
1545
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001546void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001547{
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07001548 if ((bp->state != BNX2X_STATE_OPEN) || (bp->flags & MF_FUNC_DIS))
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001549 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001550
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001551 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
1552
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001553 if (bp->link_vars.link_up)
1554 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
1555 else
1556 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1557
Eilon Greenstein2691d512009-08-12 08:22:08 +00001558 bnx2x_calc_vn_weight_sum(bp);
1559
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001560 /* indicate link status */
1561 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001562}
1563
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001564static void bnx2x_pmf_update(struct bnx2x *bp)
1565{
1566 int port = BP_PORT(bp);
1567 u32 val;
1568
1569 bp->port.pmf = 1;
1570 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
1571
1572 /* enable nig attention */
1573 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
1574 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1575 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001576
1577 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001578}
1579
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001580/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001581
1582/* slow path */
1583
1584/*
1585 * General service functions
1586 */
1587
Eilon Greenstein2691d512009-08-12 08:22:08 +00001588/* send the MCP a request, block until there is a reply */
1589u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
1590{
1591 int func = BP_FUNC(bp);
1592 u32 seq = ++bp->fw_seq;
1593 u32 rc = 0;
1594 u32 cnt = 1;
1595 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
1596
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07001597 mutex_lock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00001598 SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
1599 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
1600
1601 do {
1602 /* let the FW do it's magic ... */
1603 msleep(delay);
1604
1605 rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
1606
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07001607 /* Give the FW up to 5 second (500*10ms) */
1608 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00001609
1610 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
1611 cnt*delay, rc, seq);
1612
1613 /* is this a reply to our command? */
1614 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
1615 rc &= FW_MSG_CODE_MASK;
1616 else {
1617 /* FW BUG! */
1618 BNX2X_ERR("FW failed to respond!\n");
1619 bnx2x_fw_dump(bp);
1620 rc = 0;
1621 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07001622 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00001623
1624 return rc;
1625}
1626
Eilon Greenstein2691d512009-08-12 08:22:08 +00001627static void bnx2x_e1h_disable(struct bnx2x *bp)
1628{
1629 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00001630
1631 netif_tx_disable(bp->dev);
Eilon Greenstein2691d512009-08-12 08:22:08 +00001632
1633 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
1634
Eilon Greenstein2691d512009-08-12 08:22:08 +00001635 netif_carrier_off(bp->dev);
1636}
1637
1638static void bnx2x_e1h_enable(struct bnx2x *bp)
1639{
1640 int port = BP_PORT(bp);
1641
1642 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
1643
Eilon Greenstein2691d512009-08-12 08:22:08 +00001644 /* Tx queue should be only reenabled */
1645 netif_tx_wake_all_queues(bp->dev);
1646
Eilon Greenstein061bc702009-10-15 00:18:47 -07001647 /*
1648 * Should not call netif_carrier_on since it will be called if the link
1649 * is up when checking for link state
1650 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00001651}
1652
1653static void bnx2x_update_min_max(struct bnx2x *bp)
1654{
1655 int port = BP_PORT(bp);
1656 int vn, i;
1657
1658 /* Init rate shaping and fairness contexts */
1659 bnx2x_init_port_minmax(bp);
1660
1661 bnx2x_calc_vn_weight_sum(bp);
1662
1663 for (vn = VN_0; vn < E1HVN_MAX; vn++)
1664 bnx2x_init_vn_minmax(bp, 2*vn + port);
1665
1666 if (bp->port.pmf) {
1667 int func;
1668
1669 /* Set the attention towards other drivers on the same port */
1670 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
1671 if (vn == BP_E1HVN(bp))
1672 continue;
1673
1674 func = ((vn << 1) | port);
1675 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
1676 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
1677 }
1678
1679 /* Store it to internal memory */
1680 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
1681 REG_WR(bp, BAR_XSTRORM_INTMEM +
1682 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
1683 ((u32 *)(&bp->cmng))[i]);
1684 }
1685}
1686
1687static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
1688{
Eilon Greenstein2691d512009-08-12 08:22:08 +00001689 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00001690
1691 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
1692
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07001693 /*
1694 * This is the only place besides the function initialization
1695 * where the bp->flags can change so it is done without any
1696 * locks
1697 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00001698 if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
1699 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07001700 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00001701
1702 bnx2x_e1h_disable(bp);
1703 } else {
1704 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07001705 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00001706
1707 bnx2x_e1h_enable(bp);
1708 }
1709 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
1710 }
1711 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
1712
1713 bnx2x_update_min_max(bp);
1714 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
1715 }
1716
1717 /* Report results to MCP */
1718 if (dcc_event)
1719 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE);
1720 else
1721 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK);
1722}
1723
Michael Chan28912902009-10-10 13:46:53 +00001724/* must be called under the spq lock */
1725static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
1726{
1727 struct eth_spe *next_spe = bp->spq_prod_bd;
1728
1729 if (bp->spq_prod_bd == bp->spq_last_bd) {
1730 bp->spq_prod_bd = bp->spq;
1731 bp->spq_prod_idx = 0;
1732 DP(NETIF_MSG_TIMER, "end of spq\n");
1733 } else {
1734 bp->spq_prod_bd++;
1735 bp->spq_prod_idx++;
1736 }
1737 return next_spe;
1738}
1739
1740/* must be called under the spq lock */
1741static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
1742{
1743 int func = BP_FUNC(bp);
1744
1745 /* Make sure that BD data is updated before writing the producer */
1746 wmb();
1747
1748 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
1749 bp->spq_prod_idx);
1750 mmiowb();
1751}
1752
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001753/* the slow path queue is odd since completions arrive on the fastpath ring */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001754int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001755 u32 data_hi, u32 data_lo, int common)
1756{
Michael Chan28912902009-10-10 13:46:53 +00001757 struct eth_spe *spe;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001758
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001759#ifdef BNX2X_STOP_ON_ERROR
1760 if (unlikely(bp->panic))
1761 return -EIO;
1762#endif
1763
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001764 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001765
1766 if (!bp->spq_left) {
1767 BNX2X_ERR("BUG! SPQ ring full!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001768 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001769 bnx2x_panic();
1770 return -EBUSY;
1771 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08001772
Michael Chan28912902009-10-10 13:46:53 +00001773 spe = bnx2x_sp_get_next(bp);
1774
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001775 /* CID needs port number to be encoded int it */
Michael Chan28912902009-10-10 13:46:53 +00001776 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001777 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
1778 HW_CID(bp, cid));
Michael Chan28912902009-10-10 13:46:53 +00001779 spe->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001780 if (common)
Michael Chan28912902009-10-10 13:46:53 +00001781 spe->hdr.type |=
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001782 cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
1783
Michael Chan28912902009-10-10 13:46:53 +00001784 spe->data.mac_config_addr.hi = cpu_to_le32(data_hi);
1785 spe->data.mac_config_addr.lo = cpu_to_le32(data_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001786
1787 bp->spq_left--;
1788
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001789 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
1790 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
1791 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
1792 (u32)(U64_LO(bp->spq_mapping) +
1793 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
1794 HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
1795
Michael Chan28912902009-10-10 13:46:53 +00001796 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001797 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001798 return 0;
1799}
1800
1801/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001802static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001803{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001804 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001805 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001806
1807 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001808 for (j = 0; j < 1000; j++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001809 val = (1UL << 31);
1810 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
1811 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
1812 if (val & (1L << 31))
1813 break;
1814
1815 msleep(5);
1816 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001817 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07001818 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001819 rc = -EBUSY;
1820 }
1821
1822 return rc;
1823}
1824
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001825/* release split MCP access lock register */
1826static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001827{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001828 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001829}
1830
1831static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
1832{
1833 struct host_def_status_block *def_sb = bp->def_status_blk;
1834 u16 rc = 0;
1835
1836 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001837 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
1838 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
1839 rc |= 1;
1840 }
1841 if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
1842 bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
1843 rc |= 2;
1844 }
1845 if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
1846 bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
1847 rc |= 4;
1848 }
1849 if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
1850 bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
1851 rc |= 8;
1852 }
1853 if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
1854 bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
1855 rc |= 16;
1856 }
1857 return rc;
1858}
1859
1860/*
1861 * slow path service functions
1862 */
1863
1864static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
1865{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001866 int port = BP_PORT(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07001867 u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
1868 COMMAND_REG_ATTN_BITS_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001869 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
1870 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001871 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
1872 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001873 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00001874 u32 nig_mask = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001875
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001876 if (bp->attn_state & asserted)
1877 BNX2X_ERR("IGU ERROR\n");
1878
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001879 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
1880 aeu_mask = REG_RD(bp, aeu_addr);
1881
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001882 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001883 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001884 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001885 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001886
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001887 REG_WR(bp, aeu_addr, aeu_mask);
1888 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001889
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001890 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001891 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07001892 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001893
1894 if (asserted & ATTN_HARD_WIRED_MASK) {
1895 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001896
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08001897 bnx2x_acquire_phy_lock(bp);
1898
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001899 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00001900 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001901 REG_WR(bp, nig_int_mask_addr, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001902
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001903 bnx2x_link_attn(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001904
1905 /* handle unicore attn? */
1906 }
1907 if (asserted & ATTN_SW_TIMER_4_FUNC)
1908 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
1909
1910 if (asserted & GPIO_2_FUNC)
1911 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
1912
1913 if (asserted & GPIO_3_FUNC)
1914 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
1915
1916 if (asserted & GPIO_4_FUNC)
1917 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
1918
1919 if (port == 0) {
1920 if (asserted & ATTN_GENERAL_ATTN_1) {
1921 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
1922 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
1923 }
1924 if (asserted & ATTN_GENERAL_ATTN_2) {
1925 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
1926 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
1927 }
1928 if (asserted & ATTN_GENERAL_ATTN_3) {
1929 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
1930 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
1931 }
1932 } else {
1933 if (asserted & ATTN_GENERAL_ATTN_4) {
1934 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
1935 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
1936 }
1937 if (asserted & ATTN_GENERAL_ATTN_5) {
1938 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
1939 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
1940 }
1941 if (asserted & ATTN_GENERAL_ATTN_6) {
1942 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
1943 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
1944 }
1945 }
1946
1947 } /* if hardwired */
1948
Eilon Greenstein5c862842008-08-13 15:51:48 -07001949 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
1950 asserted, hc_addr);
1951 REG_WR(bp, hc_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001952
1953 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08001954 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00001955 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08001956 bnx2x_release_phy_lock(bp);
1957 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001958}
1959
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00001960static inline void bnx2x_fan_failure(struct bnx2x *bp)
1961{
1962 int port = BP_PORT(bp);
1963
1964 /* mark the failure */
1965 bp->link_params.ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
1966 bp->link_params.ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
1967 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
1968 bp->link_params.ext_phy_config);
1969
1970 /* log the failure */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001971 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
1972 " the driver to shutdown the card to prevent permanent"
1973 " damage. Please contact OEM Support for assistance\n");
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00001974}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001975
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001976static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
1977{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001978 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001979 int reg_offset;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00001980 u32 val, swap_val, swap_override;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001981
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001982 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
1983 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001984
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001985 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001986
1987 val = REG_RD(bp, reg_offset);
1988 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
1989 REG_WR(bp, reg_offset, val);
1990
1991 BNX2X_ERR("SPIO5 hw attention\n");
1992
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00001993 /* Fan failure attention */
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00001994 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
1995 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001996 /* Low power mode is controlled by GPIO 2 */
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08001997 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001998 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00001999 /* The PHY reset is controlled by GPIO 1 */
2000 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
2001 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002002 break;
2003
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002004 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
2005 /* The PHY reset is controlled by GPIO 1 */
2006 /* fake the port number to cancel the swap done in
2007 set_gpio() */
2008 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
2009 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
2010 port = (swap_val && swap_override) ^ 1;
2011 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
2012 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
2013 break;
2014
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002015 default:
2016 break;
2017 }
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00002018 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002019 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002020
Eilon Greenstein589abe32009-02-12 08:36:55 +00002021 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
2022 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
2023 bnx2x_acquire_phy_lock(bp);
2024 bnx2x_handle_module_detect_int(&bp->link_params);
2025 bnx2x_release_phy_lock(bp);
2026 }
2027
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002028 if (attn & HW_INTERRUT_ASSERT_SET_0) {
2029
2030 val = REG_RD(bp, reg_offset);
2031 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
2032 REG_WR(bp, reg_offset, val);
2033
2034 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00002035 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002036 bnx2x_panic();
2037 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002038}
2039
2040static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
2041{
2042 u32 val;
2043
Eilon Greenstein0626b892009-02-12 08:38:14 +00002044 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002045
2046 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
2047 BNX2X_ERR("DB hw attention 0x%x\n", val);
2048 /* DORQ discard attention */
2049 if (val & 0x2)
2050 BNX2X_ERR("FATAL error from DORQ\n");
2051 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002052
2053 if (attn & HW_INTERRUT_ASSERT_SET_1) {
2054
2055 int port = BP_PORT(bp);
2056 int reg_offset;
2057
2058 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
2059 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
2060
2061 val = REG_RD(bp, reg_offset);
2062 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
2063 REG_WR(bp, reg_offset, val);
2064
2065 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00002066 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002067 bnx2x_panic();
2068 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002069}
2070
2071static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
2072{
2073 u32 val;
2074
2075 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
2076
2077 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
2078 BNX2X_ERR("CFC hw attention 0x%x\n", val);
2079 /* CFC error attention */
2080 if (val & 0x2)
2081 BNX2X_ERR("FATAL error from CFC\n");
2082 }
2083
2084 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
2085
2086 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
2087 BNX2X_ERR("PXP hw attention 0x%x\n", val);
2088 /* RQ_USDMDP_FIFO_OVERFLOW */
2089 if (val & 0x18000)
2090 BNX2X_ERR("FATAL error from PXP\n");
2091 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002092
2093 if (attn & HW_INTERRUT_ASSERT_SET_2) {
2094
2095 int port = BP_PORT(bp);
2096 int reg_offset;
2097
2098 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
2099 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
2100
2101 val = REG_RD(bp, reg_offset);
2102 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
2103 REG_WR(bp, reg_offset, val);
2104
2105 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00002106 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002107 bnx2x_panic();
2108 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002109}
2110
2111static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
2112{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002113 u32 val;
2114
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002115 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
2116
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002117 if (attn & BNX2X_PMF_LINK_ASSERT) {
2118 int func = BP_FUNC(bp);
2119
2120 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002121 bp->mf_config = SHMEM_RD(bp,
2122 mf_cfg.func_mf_config[func].config);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002123 val = SHMEM_RD(bp, func_mb[func].drv_status);
2124 if (val & DRV_STATUS_DCC_EVENT_MASK)
2125 bnx2x_dcc_event(bp,
2126 (val & DRV_STATUS_DCC_EVENT_MASK));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002127 bnx2x__link_status_update(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002128 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002129 bnx2x_pmf_update(bp);
2130
2131 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002132
2133 BNX2X_ERR("MC assert!\n");
2134 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
2135 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
2136 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
2137 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
2138 bnx2x_panic();
2139
2140 } else if (attn & BNX2X_MCP_ASSERT) {
2141
2142 BNX2X_ERR("MCP assert!\n");
2143 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002144 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002145
2146 } else
2147 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
2148 }
2149
2150 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002151 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
2152 if (attn & BNX2X_GRC_TIMEOUT) {
2153 val = CHIP_IS_E1H(bp) ?
2154 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
2155 BNX2X_ERR("GRC time-out 0x%08x\n", val);
2156 }
2157 if (attn & BNX2X_GRC_RSV) {
2158 val = CHIP_IS_E1H(bp) ?
2159 REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
2160 BNX2X_ERR("GRC reserved 0x%08x\n", val);
2161 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002162 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002163 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002164}
2165
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002166#define BNX2X_MISC_GEN_REG MISC_REG_GENERIC_POR_1
2167#define LOAD_COUNTER_BITS 16 /* Number of bits for load counter */
2168#define LOAD_COUNTER_MASK (((u32)0x1 << LOAD_COUNTER_BITS) - 1)
2169#define RESET_DONE_FLAG_MASK (~LOAD_COUNTER_MASK)
2170#define RESET_DONE_FLAG_SHIFT LOAD_COUNTER_BITS
2171#define CHIP_PARITY_SUPPORTED(bp) (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp))
2172/*
2173 * should be run under rtnl lock
2174 */
2175static inline void bnx2x_set_reset_done(struct bnx2x *bp)
2176{
2177 u32 val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2178 val &= ~(1 << RESET_DONE_FLAG_SHIFT);
2179 REG_WR(bp, BNX2X_MISC_GEN_REG, val);
2180 barrier();
2181 mmiowb();
2182}
2183
2184/*
2185 * should be run under rtnl lock
2186 */
2187static inline void bnx2x_set_reset_in_progress(struct bnx2x *bp)
2188{
2189 u32 val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2190 val |= (1 << 16);
2191 REG_WR(bp, BNX2X_MISC_GEN_REG, val);
2192 barrier();
2193 mmiowb();
2194}
2195
2196/*
2197 * should be run under rtnl lock
2198 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002199bool bnx2x_reset_is_done(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002200{
2201 u32 val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2202 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
2203 return (val & RESET_DONE_FLAG_MASK) ? false : true;
2204}
2205
2206/*
2207 * should be run under rtnl lock
2208 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002209inline void bnx2x_inc_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002210{
2211 u32 val1, val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2212
2213 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
2214
2215 val1 = ((val & LOAD_COUNTER_MASK) + 1) & LOAD_COUNTER_MASK;
2216 REG_WR(bp, BNX2X_MISC_GEN_REG, (val & RESET_DONE_FLAG_MASK) | val1);
2217 barrier();
2218 mmiowb();
2219}
2220
2221/*
2222 * should be run under rtnl lock
2223 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002224u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002225{
2226 u32 val1, val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2227
2228 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
2229
2230 val1 = ((val & LOAD_COUNTER_MASK) - 1) & LOAD_COUNTER_MASK;
2231 REG_WR(bp, BNX2X_MISC_GEN_REG, (val & RESET_DONE_FLAG_MASK) | val1);
2232 barrier();
2233 mmiowb();
2234
2235 return val1;
2236}
2237
2238/*
2239 * should be run under rtnl lock
2240 */
2241static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp)
2242{
2243 return REG_RD(bp, BNX2X_MISC_GEN_REG) & LOAD_COUNTER_MASK;
2244}
2245
2246static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
2247{
2248 u32 val = REG_RD(bp, BNX2X_MISC_GEN_REG);
2249 REG_WR(bp, BNX2X_MISC_GEN_REG, val & (~LOAD_COUNTER_MASK));
2250}
2251
2252static inline void _print_next_block(int idx, const char *blk)
2253{
2254 if (idx)
2255 pr_cont(", ");
2256 pr_cont("%s", blk);
2257}
2258
2259static inline int bnx2x_print_blocks_with_parity0(u32 sig, int par_num)
2260{
2261 int i = 0;
2262 u32 cur_bit = 0;
2263 for (i = 0; sig; i++) {
2264 cur_bit = ((u32)0x1 << i);
2265 if (sig & cur_bit) {
2266 switch (cur_bit) {
2267 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
2268 _print_next_block(par_num++, "BRB");
2269 break;
2270 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
2271 _print_next_block(par_num++, "PARSER");
2272 break;
2273 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
2274 _print_next_block(par_num++, "TSDM");
2275 break;
2276 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
2277 _print_next_block(par_num++, "SEARCHER");
2278 break;
2279 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
2280 _print_next_block(par_num++, "TSEMI");
2281 break;
2282 }
2283
2284 /* Clear the bit */
2285 sig &= ~cur_bit;
2286 }
2287 }
2288
2289 return par_num;
2290}
2291
2292static inline int bnx2x_print_blocks_with_parity1(u32 sig, int par_num)
2293{
2294 int i = 0;
2295 u32 cur_bit = 0;
2296 for (i = 0; sig; i++) {
2297 cur_bit = ((u32)0x1 << i);
2298 if (sig & cur_bit) {
2299 switch (cur_bit) {
2300 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
2301 _print_next_block(par_num++, "PBCLIENT");
2302 break;
2303 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
2304 _print_next_block(par_num++, "QM");
2305 break;
2306 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
2307 _print_next_block(par_num++, "XSDM");
2308 break;
2309 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
2310 _print_next_block(par_num++, "XSEMI");
2311 break;
2312 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
2313 _print_next_block(par_num++, "DOORBELLQ");
2314 break;
2315 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
2316 _print_next_block(par_num++, "VAUX PCI CORE");
2317 break;
2318 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
2319 _print_next_block(par_num++, "DEBUG");
2320 break;
2321 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
2322 _print_next_block(par_num++, "USDM");
2323 break;
2324 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
2325 _print_next_block(par_num++, "USEMI");
2326 break;
2327 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
2328 _print_next_block(par_num++, "UPB");
2329 break;
2330 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
2331 _print_next_block(par_num++, "CSDM");
2332 break;
2333 }
2334
2335 /* Clear the bit */
2336 sig &= ~cur_bit;
2337 }
2338 }
2339
2340 return par_num;
2341}
2342
2343static inline int bnx2x_print_blocks_with_parity2(u32 sig, int par_num)
2344{
2345 int i = 0;
2346 u32 cur_bit = 0;
2347 for (i = 0; sig; i++) {
2348 cur_bit = ((u32)0x1 << i);
2349 if (sig & cur_bit) {
2350 switch (cur_bit) {
2351 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
2352 _print_next_block(par_num++, "CSEMI");
2353 break;
2354 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
2355 _print_next_block(par_num++, "PXP");
2356 break;
2357 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
2358 _print_next_block(par_num++,
2359 "PXPPCICLOCKCLIENT");
2360 break;
2361 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
2362 _print_next_block(par_num++, "CFC");
2363 break;
2364 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
2365 _print_next_block(par_num++, "CDU");
2366 break;
2367 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
2368 _print_next_block(par_num++, "IGU");
2369 break;
2370 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
2371 _print_next_block(par_num++, "MISC");
2372 break;
2373 }
2374
2375 /* Clear the bit */
2376 sig &= ~cur_bit;
2377 }
2378 }
2379
2380 return par_num;
2381}
2382
2383static inline int bnx2x_print_blocks_with_parity3(u32 sig, int par_num)
2384{
2385 int i = 0;
2386 u32 cur_bit = 0;
2387 for (i = 0; sig; i++) {
2388 cur_bit = ((u32)0x1 << i);
2389 if (sig & cur_bit) {
2390 switch (cur_bit) {
2391 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
2392 _print_next_block(par_num++, "MCP ROM");
2393 break;
2394 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
2395 _print_next_block(par_num++, "MCP UMP RX");
2396 break;
2397 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
2398 _print_next_block(par_num++, "MCP UMP TX");
2399 break;
2400 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
2401 _print_next_block(par_num++, "MCP SCPAD");
2402 break;
2403 }
2404
2405 /* Clear the bit */
2406 sig &= ~cur_bit;
2407 }
2408 }
2409
2410 return par_num;
2411}
2412
2413static inline bool bnx2x_parity_attn(struct bnx2x *bp, u32 sig0, u32 sig1,
2414 u32 sig2, u32 sig3)
2415{
2416 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
2417 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
2418 int par_num = 0;
2419 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
2420 "[0]:0x%08x [1]:0x%08x "
2421 "[2]:0x%08x [3]:0x%08x\n",
2422 sig0 & HW_PRTY_ASSERT_SET_0,
2423 sig1 & HW_PRTY_ASSERT_SET_1,
2424 sig2 & HW_PRTY_ASSERT_SET_2,
2425 sig3 & HW_PRTY_ASSERT_SET_3);
2426 printk(KERN_ERR"%s: Parity errors detected in blocks: ",
2427 bp->dev->name);
2428 par_num = bnx2x_print_blocks_with_parity0(
2429 sig0 & HW_PRTY_ASSERT_SET_0, par_num);
2430 par_num = bnx2x_print_blocks_with_parity1(
2431 sig1 & HW_PRTY_ASSERT_SET_1, par_num);
2432 par_num = bnx2x_print_blocks_with_parity2(
2433 sig2 & HW_PRTY_ASSERT_SET_2, par_num);
2434 par_num = bnx2x_print_blocks_with_parity3(
2435 sig3 & HW_PRTY_ASSERT_SET_3, par_num);
2436 printk("\n");
2437 return true;
2438 } else
2439 return false;
2440}
2441
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002442bool bnx2x_chk_parity_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002443{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002444 struct attn_route attn;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002445 int port = BP_PORT(bp);
2446
2447 attn.sig[0] = REG_RD(bp,
2448 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
2449 port*4);
2450 attn.sig[1] = REG_RD(bp,
2451 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
2452 port*4);
2453 attn.sig[2] = REG_RD(bp,
2454 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
2455 port*4);
2456 attn.sig[3] = REG_RD(bp,
2457 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
2458 port*4);
2459
2460 return bnx2x_parity_attn(bp, attn.sig[0], attn.sig[1], attn.sig[2],
2461 attn.sig[3]);
2462}
2463
2464static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
2465{
2466 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002467 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002468 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002469 u32 reg_addr;
2470 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002471 u32 aeu_mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002472
2473 /* need to take HW lock because MCP or other port might also
2474 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002475 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002476
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002477 if (bnx2x_chk_parity_attn(bp)) {
2478 bp->recovery_state = BNX2X_RECOVERY_INIT;
2479 bnx2x_set_reset_in_progress(bp);
2480 schedule_delayed_work(&bp->reset_task, 0);
2481 /* Disable HW interrupts */
2482 bnx2x_int_disable(bp);
2483 bnx2x_release_alr(bp);
2484 /* In case of parity errors don't handle attentions so that
2485 * other function would "see" parity errors.
2486 */
2487 return;
2488 }
2489
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002490 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
2491 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
2492 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
2493 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002494 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
2495 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002496
2497 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
2498 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002499 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002500
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002501 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002502 index, group_mask->sig[0], group_mask->sig[1],
2503 group_mask->sig[2], group_mask->sig[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002504
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002505 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002506 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002507 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002508 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002509 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002510 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002511 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002512 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002513 }
2514 }
2515
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002516 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002517
Eilon Greenstein5c862842008-08-13 15:51:48 -07002518 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002519
2520 val = ~deasserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002521 DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
2522 val, reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07002523 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002524
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002525 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002526 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002527
2528 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2529 MISC_REG_AEU_MASK_ATTN_FUNC_0;
2530
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002531 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2532 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002533
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002534 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
2535 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002536 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07002537 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
2538
2539 REG_WR(bp, reg_addr, aeu_mask);
2540 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002541
2542 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
2543 bp->attn_state &= ~deasserted;
2544 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
2545}
2546
2547static void bnx2x_attn_int(struct bnx2x *bp)
2548{
2549 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08002550 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
2551 attn_bits);
2552 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
2553 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002554 u32 attn_state = bp->attn_state;
2555
2556 /* look for changed bits */
2557 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
2558 u32 deasserted = ~attn_bits & attn_ack & attn_state;
2559
2560 DP(NETIF_MSG_HW,
2561 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
2562 attn_bits, attn_ack, asserted, deasserted);
2563
2564 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002565 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002566
2567 /* handle bits that were raised */
2568 if (asserted)
2569 bnx2x_attn_int_asserted(bp, asserted);
2570
2571 if (deasserted)
2572 bnx2x_attn_int_deasserted(bp, deasserted);
2573}
2574
2575static void bnx2x_sp_task(struct work_struct *work)
2576{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002577 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002578 u16 status;
2579
2580 /* Return here if interrupt is disabled */
2581 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002582 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002583 return;
2584 }
2585
2586 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002587/* if (status == 0) */
2588/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002589
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002590 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002591
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08002592 /* HW attentions */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002593 if (status & 0x1) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002594 bnx2x_attn_int(bp);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002595 status &= ~0x1;
2596 }
2597
2598 /* CStorm events: STAT_QUERY */
2599 if (status & 0x2) {
2600 DP(BNX2X_MSG_SP, "CStorm events: STAT_QUERY\n");
2601 status &= ~0x2;
2602 }
2603
2604 if (unlikely(status))
2605 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
2606 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002607
Eilon Greenstein68d59482009-01-14 21:27:36 -08002608 bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002609 IGU_INT_NOP, 1);
2610 bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
2611 IGU_INT_NOP, 1);
2612 bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
2613 IGU_INT_NOP, 1);
2614 bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
2615 IGU_INT_NOP, 1);
2616 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
2617 IGU_INT_ENABLE, 1);
2618}
2619
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002620irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002621{
2622 struct net_device *dev = dev_instance;
2623 struct bnx2x *bp = netdev_priv(dev);
2624
2625 /* Return here if interrupt is disabled */
2626 if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
Eilon Greenstein3196a882008-08-13 15:58:49 -07002627 DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002628 return IRQ_HANDLED;
2629 }
2630
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08002631 bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002632
2633#ifdef BNX2X_STOP_ON_ERROR
2634 if (unlikely(bp->panic))
2635 return IRQ_HANDLED;
2636#endif
2637
Michael Chan993ac7b2009-10-10 13:46:56 +00002638#ifdef BCM_CNIC
2639 {
2640 struct cnic_ops *c_ops;
2641
2642 rcu_read_lock();
2643 c_ops = rcu_dereference(bp->cnic_ops);
2644 if (c_ops)
2645 c_ops->cnic_handler(bp->cnic_data, NULL);
2646 rcu_read_unlock();
2647 }
2648#endif
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08002649 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002650
2651 return IRQ_HANDLED;
2652}
2653
2654/* end of slow path */
2655
2656/* Statistics */
2657
2658/****************************************************************************
2659* Macros
2660****************************************************************************/
2661
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002662/* sum[hi:lo] += add[hi:lo] */
2663#define ADD_64(s_hi, a_hi, s_lo, a_lo) \
2664 do { \
2665 s_lo += a_lo; \
Eilon Greensteinf5ba6772009-01-14 21:29:18 -08002666 s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002667 } while (0)
2668
2669/* difference = minuend - subtrahend */
2670#define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
2671 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002672 if (m_lo < s_lo) { \
2673 /* underflow */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002674 d_hi = m_hi - s_hi; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002675 if (d_hi > 0) { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002676 /* we can 'loan' 1 */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002677 d_hi--; \
2678 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002679 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002680 /* m_hi <= s_hi */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002681 d_hi = 0; \
2682 d_lo = 0; \
2683 } \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002684 } else { \
2685 /* m_lo >= s_lo */ \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002686 if (m_hi < s_hi) { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002687 d_hi = 0; \
2688 d_lo = 0; \
2689 } else { \
Eilon Greenstein6378c022008-08-13 15:59:25 -07002690 /* m_hi >= s_hi */ \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002691 d_hi = m_hi - s_hi; \
2692 d_lo = m_lo - s_lo; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002693 } \
2694 } \
2695 } while (0)
2696
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002697#define UPDATE_STAT64(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002698 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002699 DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
2700 diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
2701 pstats->mac_stx[0].t##_hi = new->s##_hi; \
2702 pstats->mac_stx[0].t##_lo = new->s##_lo; \
2703 ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
2704 pstats->mac_stx[1].t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002705 } while (0)
2706
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002707#define UPDATE_STAT64_NIG(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002708 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002709 DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
2710 diff.lo, new->s##_lo, old->s##_lo); \
2711 ADD_64(estats->t##_hi, diff.hi, \
2712 estats->t##_lo, diff.lo); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002713 } while (0)
2714
2715/* sum[hi:lo] += add */
2716#define ADD_EXTEND_64(s_hi, s_lo, a) \
2717 do { \
2718 s_lo += a; \
2719 s_hi += (s_lo < a) ? 1 : 0; \
2720 } while (0)
2721
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002722#define UPDATE_EXTEND_STAT(s) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002723 do { \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002724 ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
2725 pstats->mac_stx[1].s##_lo, \
2726 new->s); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002727 } while (0)
2728
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002729#define UPDATE_EXTEND_TSTAT(s, t) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002730 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00002731 diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
2732 old_tclient->s = tclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00002733 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
2734 } while (0)
2735
2736#define UPDATE_EXTEND_USTAT(s, t) \
2737 do { \
2738 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
2739 old_uclient->s = uclient->s; \
2740 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002741 } while (0)
2742
2743#define UPDATE_EXTEND_XSTAT(s, t) \
2744 do { \
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00002745 diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
2746 old_xclient->s = xclient->s; \
Eilon Greensteinde832a52009-02-12 08:36:33 +00002747 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
2748 } while (0)
2749
2750/* minuend -= subtrahend */
2751#define SUB_64(m_hi, s_hi, m_lo, s_lo) \
2752 do { \
2753 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
2754 } while (0)
2755
2756/* minuend[hi:lo] -= subtrahend */
2757#define SUB_EXTEND_64(m_hi, m_lo, s) \
2758 do { \
2759 SUB_64(m_hi, 0, m_lo, s); \
2760 } while (0)
2761
2762#define SUB_EXTEND_USTAT(s, t) \
2763 do { \
2764 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
2765 SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002766 } while (0)
2767
2768/*
2769 * General service functions
2770 */
2771
2772static inline long bnx2x_hilo(u32 *hiref)
2773{
2774 u32 lo = *(hiref + 1);
2775#if (BITS_PER_LONG == 64)
2776 u32 hi = *hiref;
2777
2778 return HILO_U64(hi, lo);
2779#else
2780 return lo;
2781#endif
2782}
2783
2784/*
2785 * Init service functions
2786 */
2787
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002788static void bnx2x_storm_stats_post(struct bnx2x *bp)
2789{
2790 if (!bp->stats_pending) {
2791 struct eth_query_ramrod_data ramrod_data = {0};
Eilon Greensteinde832a52009-02-12 08:36:33 +00002792 int i, rc;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002793
2794 ramrod_data.drv_counter = bp->stats_counter++;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08002795 ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
Eilon Greensteinde832a52009-02-12 08:36:33 +00002796 for_each_queue(bp, i)
2797 ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002798
2799 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
2800 ((u32 *)&ramrod_data)[1],
2801 ((u32 *)&ramrod_data)[0], 0);
2802 if (rc == 0) {
2803 /* stats ramrod has it's own slot on the spq */
2804 bp->spq_left++;
2805 bp->stats_pending = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002806 }
2807 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002808}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002809
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002810static void bnx2x_hw_stats_post(struct bnx2x *bp)
2811{
2812 struct dmae_command *dmae = &bp->stats_dmae;
2813 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
2814
2815 *stats_comp = DMAE_COMP_VAL;
Eilon Greensteinde832a52009-02-12 08:36:33 +00002816 if (CHIP_REV_IS_SLOW(bp))
2817 return;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002818
2819 /* loader */
2820 if (bp->executer_idx) {
2821 int loader_idx = PMF_DMAE_C(bp);
2822
2823 memset(dmae, 0, sizeof(struct dmae_command));
2824
2825 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
2826 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
2827 DMAE_CMD_DST_RESET |
2828#ifdef __BIG_ENDIAN
2829 DMAE_CMD_ENDIANITY_B_DW_SWAP |
2830#else
2831 DMAE_CMD_ENDIANITY_DW_SWAP |
2832#endif
2833 (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
2834 DMAE_CMD_PORT_0) |
2835 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
2836 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
2837 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
2838 dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
2839 sizeof(struct dmae_command) *
2840 (loader_idx + 1)) >> 2;
2841 dmae->dst_addr_hi = 0;
2842 dmae->len = sizeof(struct dmae_command) >> 2;
2843 if (CHIP_IS_E1(bp))
2844 dmae->len--;
2845 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
2846 dmae->comp_addr_hi = 0;
2847 dmae->comp_val = 1;
2848
2849 *stats_comp = 0;
2850 bnx2x_post_dmae(bp, dmae, loader_idx);
2851
2852 } else if (bp->func_stx) {
2853 *stats_comp = 0;
2854 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
2855 }
2856}
2857
2858static int bnx2x_stats_comp(struct bnx2x *bp)
2859{
2860 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
2861 int cnt = 10;
2862
2863 might_sleep();
2864 while (*stats_comp != DMAE_COMP_VAL) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002865 if (!cnt) {
2866 BNX2X_ERR("timeout waiting for stats finished\n");
2867 break;
2868 }
2869 cnt--;
Yitchak Gertner12469402008-08-13 15:52:08 -07002870 msleep(1);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002871 }
2872 return 1;
2873}
2874
2875/*
2876 * Statistics service functions
2877 */
2878
2879static void bnx2x_stats_pmf_update(struct bnx2x *bp)
2880{
2881 struct dmae_command *dmae;
2882 u32 opcode;
2883 int loader_idx = PMF_DMAE_C(bp);
2884 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
2885
2886 /* sanity */
2887 if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
2888 BNX2X_ERR("BUG!\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002889 return;
2890 }
2891
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002892 bp->executer_idx = 0;
2893
2894 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
2895 DMAE_CMD_C_ENABLE |
2896 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
2897#ifdef __BIG_ENDIAN
2898 DMAE_CMD_ENDIANITY_B_DW_SWAP |
2899#else
2900 DMAE_CMD_ENDIANITY_DW_SWAP |
2901#endif
2902 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
2903 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
2904
2905 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
2906 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
2907 dmae->src_addr_lo = bp->port.port_stx >> 2;
2908 dmae->src_addr_hi = 0;
2909 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
2910 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
2911 dmae->len = DMAE_LEN32_RD_MAX;
2912 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
2913 dmae->comp_addr_hi = 0;
2914 dmae->comp_val = 1;
2915
2916 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
2917 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
2918 dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
2919 dmae->src_addr_hi = 0;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07002920 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
2921 DMAE_LEN32_RD_MAX * 4);
2922 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
2923 DMAE_LEN32_RD_MAX * 4);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002924 dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
2925 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
2926 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
2927 dmae->comp_val = DMAE_COMP_VAL;
2928
2929 *stats_comp = 0;
2930 bnx2x_hw_stats_post(bp);
2931 bnx2x_stats_comp(bp);
2932}
2933
2934static void bnx2x_port_stats_init(struct bnx2x *bp)
2935{
2936 struct dmae_command *dmae;
2937 int port = BP_PORT(bp);
2938 int vn = BP_E1HVN(bp);
2939 u32 opcode;
2940 int loader_idx = PMF_DMAE_C(bp);
2941 u32 mac_addr;
2942 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
2943
2944 /* sanity */
2945 if (!bp->link_vars.link_up || !bp->port.pmf) {
2946 BNX2X_ERR("BUG!\n");
2947 return;
2948 }
2949
2950 bp->executer_idx = 0;
2951
2952 /* MCP */
2953 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
2954 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
2955 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
2956#ifdef __BIG_ENDIAN
2957 DMAE_CMD_ENDIANITY_B_DW_SWAP |
2958#else
2959 DMAE_CMD_ENDIANITY_DW_SWAP |
2960#endif
2961 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
2962 (vn << DMAE_CMD_E1HVN_SHIFT));
2963
2964 if (bp->port.port_stx) {
2965
2966 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
2967 dmae->opcode = opcode;
2968 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
2969 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
2970 dmae->dst_addr_lo = bp->port.port_stx >> 2;
2971 dmae->dst_addr_hi = 0;
2972 dmae->len = sizeof(struct host_port_stats) >> 2;
2973 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
2974 dmae->comp_addr_hi = 0;
2975 dmae->comp_val = 1;
2976 }
2977
2978 if (bp->func_stx) {
2979
2980 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
2981 dmae->opcode = opcode;
2982 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
2983 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
2984 dmae->dst_addr_lo = bp->func_stx >> 2;
2985 dmae->dst_addr_hi = 0;
2986 dmae->len = sizeof(struct host_func_stats) >> 2;
2987 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
2988 dmae->comp_addr_hi = 0;
2989 dmae->comp_val = 1;
2990 }
2991
2992 /* MAC */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002993 opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
2994 DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
2995 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
2996#ifdef __BIG_ENDIAN
2997 DMAE_CMD_ENDIANITY_B_DW_SWAP |
2998#else
2999 DMAE_CMD_ENDIANITY_DW_SWAP |
3000#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003001 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3002 (vn << DMAE_CMD_E1HVN_SHIFT));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003003
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003004 if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003005
3006 mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
3007 NIG_REG_INGRESS_BMAC0_MEM);
3008
3009 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
3010 BIGMAC_REGISTER_TX_STAT_GTBYT */
3011 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3012 dmae->opcode = opcode;
3013 dmae->src_addr_lo = (mac_addr +
3014 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3015 dmae->src_addr_hi = 0;
3016 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3017 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3018 dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
3019 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
3020 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3021 dmae->comp_addr_hi = 0;
3022 dmae->comp_val = 1;
3023
3024 /* BIGMAC_REGISTER_RX_STAT_GR64 ..
3025 BIGMAC_REGISTER_RX_STAT_GRIPJ */
3026 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3027 dmae->opcode = opcode;
3028 dmae->src_addr_lo = (mac_addr +
3029 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3030 dmae->src_addr_hi = 0;
3031 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003032 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003033 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003034 offsetof(struct bmac_stats, rx_stat_gr64_lo));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003035 dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
3036 BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
3037 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3038 dmae->comp_addr_hi = 0;
3039 dmae->comp_val = 1;
3040
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07003041 } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003042
3043 mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
3044
3045 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
3046 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3047 dmae->opcode = opcode;
3048 dmae->src_addr_lo = (mac_addr +
3049 EMAC_REG_EMAC_RX_STAT_AC) >> 2;
3050 dmae->src_addr_hi = 0;
3051 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
3052 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
3053 dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
3054 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3055 dmae->comp_addr_hi = 0;
3056 dmae->comp_val = 1;
3057
3058 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
3059 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3060 dmae->opcode = opcode;
3061 dmae->src_addr_lo = (mac_addr +
3062 EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
3063 dmae->src_addr_hi = 0;
3064 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003065 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003066 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003067 offsetof(struct emac_stats, rx_stat_falsecarriererrors));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003068 dmae->len = 1;
3069 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3070 dmae->comp_addr_hi = 0;
3071 dmae->comp_val = 1;
3072
3073 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
3074 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3075 dmae->opcode = opcode;
3076 dmae->src_addr_lo = (mac_addr +
3077 EMAC_REG_EMAC_TX_STAT_AC) >> 2;
3078 dmae->src_addr_hi = 0;
3079 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003080 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003081 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003082 offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003083 dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
3084 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3085 dmae->comp_addr_hi = 0;
3086 dmae->comp_val = 1;
3087 }
3088
3089 /* NIG */
3090 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003091 dmae->opcode = opcode;
3092 dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
3093 NIG_REG_STAT0_BRB_DISCARD) >> 2;
3094 dmae->src_addr_hi = 0;
3095 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
3096 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
3097 dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
3098 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3099 dmae->comp_addr_hi = 0;
3100 dmae->comp_val = 1;
3101
3102 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3103 dmae->opcode = opcode;
3104 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
3105 NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
3106 dmae->src_addr_hi = 0;
3107 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3108 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3109 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3110 offsetof(struct nig_stats, egress_mac_pkt0_lo));
3111 dmae->len = (2*sizeof(u32)) >> 2;
3112 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3113 dmae->comp_addr_hi = 0;
3114 dmae->comp_val = 1;
3115
3116 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003117 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3118 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3119 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3120#ifdef __BIG_ENDIAN
3121 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3122#else
3123 DMAE_CMD_ENDIANITY_DW_SWAP |
3124#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003125 (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3126 (vn << DMAE_CMD_E1HVN_SHIFT));
3127 dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
3128 NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003129 dmae->src_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003130 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
3131 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3132 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
3133 offsetof(struct nig_stats, egress_mac_pkt1_lo));
3134 dmae->len = (2*sizeof(u32)) >> 2;
3135 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3136 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3137 dmae->comp_val = DMAE_COMP_VAL;
3138
3139 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003140}
3141
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003142static void bnx2x_func_stats_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003143{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003144 struct dmae_command *dmae = &bp->stats_dmae;
3145 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003146
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003147 /* sanity */
3148 if (!bp->func_stx) {
3149 BNX2X_ERR("BUG!\n");
3150 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003151 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003152
3153 bp->executer_idx = 0;
3154 memset(dmae, 0, sizeof(struct dmae_command));
3155
3156 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3157 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3158 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3159#ifdef __BIG_ENDIAN
3160 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3161#else
3162 DMAE_CMD_ENDIANITY_DW_SWAP |
3163#endif
3164 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3165 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3166 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3167 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3168 dmae->dst_addr_lo = bp->func_stx >> 2;
3169 dmae->dst_addr_hi = 0;
3170 dmae->len = sizeof(struct host_func_stats) >> 2;
3171 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3172 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3173 dmae->comp_val = DMAE_COMP_VAL;
3174
3175 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003176}
3177
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003178static void bnx2x_stats_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003179{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003180 if (bp->port.pmf)
3181 bnx2x_port_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003182
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003183 else if (bp->func_stx)
3184 bnx2x_func_stats_init(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003185
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003186 bnx2x_hw_stats_post(bp);
3187 bnx2x_storm_stats_post(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003188}
3189
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003190static void bnx2x_stats_pmf_start(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003191{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003192 bnx2x_stats_comp(bp);
3193 bnx2x_stats_pmf_update(bp);
3194 bnx2x_stats_start(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003195}
3196
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003197static void bnx2x_stats_restart(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003198{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003199 bnx2x_stats_comp(bp);
3200 bnx2x_stats_start(bp);
3201}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003202
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003203static void bnx2x_bmac_stats_update(struct bnx2x *bp)
3204{
3205 struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
3206 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003207 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003208 struct {
3209 u32 lo;
3210 u32 hi;
3211 } diff;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003212
3213 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
3214 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
3215 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
3216 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
3217 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
3218 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003219 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003220 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003221 UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003222 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
3223 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
3224 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
3225 UPDATE_STAT64(tx_stat_gt127,
3226 tx_stat_etherstatspkts65octetsto127octets);
3227 UPDATE_STAT64(tx_stat_gt255,
3228 tx_stat_etherstatspkts128octetsto255octets);
3229 UPDATE_STAT64(tx_stat_gt511,
3230 tx_stat_etherstatspkts256octetsto511octets);
3231 UPDATE_STAT64(tx_stat_gt1023,
3232 tx_stat_etherstatspkts512octetsto1023octets);
3233 UPDATE_STAT64(tx_stat_gt1518,
3234 tx_stat_etherstatspkts1024octetsto1522octets);
3235 UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
3236 UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
3237 UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
3238 UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
3239 UPDATE_STAT64(tx_stat_gterr,
3240 tx_stat_dot3statsinternalmactransmiterrors);
3241 UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003242
3243 estats->pause_frames_received_hi =
3244 pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
3245 estats->pause_frames_received_lo =
3246 pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
3247
3248 estats->pause_frames_sent_hi =
3249 pstats->mac_stx[1].tx_stat_outxoffsent_hi;
3250 estats->pause_frames_sent_lo =
3251 pstats->mac_stx[1].tx_stat_outxoffsent_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003252}
3253
3254static void bnx2x_emac_stats_update(struct bnx2x *bp)
3255{
3256 struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
3257 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003258 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003259
3260 UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
3261 UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
3262 UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
3263 UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
3264 UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
3265 UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
3266 UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
3267 UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
3268 UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
3269 UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
3270 UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
3271 UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
3272 UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
3273 UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
3274 UPDATE_EXTEND_STAT(tx_stat_outxonsent);
3275 UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
3276 UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
3277 UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
3278 UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
3279 UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
3280 UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
3281 UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
3282 UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
3283 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
3284 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
3285 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
3286 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
3287 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
3288 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
3289 UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
3290 UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003291
3292 estats->pause_frames_received_hi =
3293 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
3294 estats->pause_frames_received_lo =
3295 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
3296 ADD_64(estats->pause_frames_received_hi,
3297 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
3298 estats->pause_frames_received_lo,
3299 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
3300
3301 estats->pause_frames_sent_hi =
3302 pstats->mac_stx[1].tx_stat_outxonsent_hi;
3303 estats->pause_frames_sent_lo =
3304 pstats->mac_stx[1].tx_stat_outxonsent_lo;
3305 ADD_64(estats->pause_frames_sent_hi,
3306 pstats->mac_stx[1].tx_stat_outxoffsent_hi,
3307 estats->pause_frames_sent_lo,
3308 pstats->mac_stx[1].tx_stat_outxoffsent_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003309}
3310
3311static int bnx2x_hw_stats_update(struct bnx2x *bp)
3312{
3313 struct nig_stats *new = bnx2x_sp(bp, nig_stats);
3314 struct nig_stats *old = &(bp->port.old_nig_stats);
3315 struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
3316 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00003317 struct {
3318 u32 lo;
3319 u32 hi;
3320 } diff;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003321
3322 if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
3323 bnx2x_bmac_stats_update(bp);
3324
3325 else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
3326 bnx2x_emac_stats_update(bp);
3327
3328 else { /* unreached */
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00003329 BNX2X_ERR("stats updated by DMAE but no MAC active\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003330 return -1;
3331 }
3332
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003333 ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
3334 new->brb_discard - old->brb_discard);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07003335 ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
3336 new->brb_truncate - old->brb_truncate);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003337
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003338 UPDATE_STAT64_NIG(egress_mac_pkt0,
3339 etherstatspkts1024octetsto1522octets);
3340 UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003341
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003342 memcpy(old, new, sizeof(struct nig_stats));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003343
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003344 memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
3345 sizeof(struct mac_stx));
3346 estats->brb_drop_hi = pstats->brb_drop_hi;
3347 estats->brb_drop_lo = pstats->brb_drop_lo;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003348
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003349 pstats->host_port_stats_start = ++pstats->host_port_stats_end;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003350
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00003351 if (!BP_NOMCP(bp)) {
3352 u32 nig_timer_max =
3353 SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
3354 if (nig_timer_max != estats->nig_timer_max) {
3355 estats->nig_timer_max = nig_timer_max;
3356 BNX2X_ERR("NIG timer max (%u)\n",
3357 estats->nig_timer_max);
3358 }
Eilon Greensteinde832a52009-02-12 08:36:33 +00003359 }
3360
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003361 return 0;
3362}
3363
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003364static int bnx2x_storm_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003365{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003366 struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003367 struct tstorm_per_port_stats *tport =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003368 &stats->tstorm_common.port_statistics;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003369 struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
3370 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003371 int i;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003372
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00003373 memcpy(&(fstats->total_bytes_received_hi),
3374 &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi),
Eilon Greensteinde832a52009-02-12 08:36:33 +00003375 sizeof(struct host_func_stats) - 2*sizeof(u32));
3376 estats->error_bytes_received_hi = 0;
3377 estats->error_bytes_received_lo = 0;
3378 estats->etherstatsoverrsizepkts_hi = 0;
3379 estats->etherstatsoverrsizepkts_lo = 0;
3380 estats->no_buff_discard_hi = 0;
3381 estats->no_buff_discard_lo = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003382
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00003383 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00003384 struct bnx2x_fastpath *fp = &bp->fp[i];
3385 int cl_id = fp->cl_id;
3386 struct tstorm_per_client_stats *tclient =
3387 &stats->tstorm_common.client_statistics[cl_id];
3388 struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
3389 struct ustorm_per_client_stats *uclient =
3390 &stats->ustorm_common.client_statistics[cl_id];
3391 struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
3392 struct xstorm_per_client_stats *xclient =
3393 &stats->xstorm_common.client_statistics[cl_id];
3394 struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
3395 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
3396 u32 diff;
3397
3398 /* are storm stats valid? */
3399 if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
3400 bp->stats_counter) {
3401 DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003402 " xstorm counter (0x%x) != stats_counter (0x%x)\n",
Eilon Greensteinde832a52009-02-12 08:36:33 +00003403 i, xclient->stats_counter, bp->stats_counter);
3404 return -1;
3405 }
3406 if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
3407 bp->stats_counter) {
3408 DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003409 " tstorm counter (0x%x) != stats_counter (0x%x)\n",
Eilon Greensteinde832a52009-02-12 08:36:33 +00003410 i, tclient->stats_counter, bp->stats_counter);
3411 return -2;
3412 }
3413 if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
3414 bp->stats_counter) {
3415 DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003416 " ustorm counter (0x%x) != stats_counter (0x%x)\n",
Eilon Greensteinde832a52009-02-12 08:36:33 +00003417 i, uclient->stats_counter, bp->stats_counter);
3418 return -4;
3419 }
3420
3421 qstats->total_bytes_received_hi =
Eilon Greensteinca003922009-08-12 22:53:28 -07003422 le32_to_cpu(tclient->rcv_broadcast_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003423 qstats->total_bytes_received_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07003424 le32_to_cpu(tclient->rcv_broadcast_bytes.lo);
3425
3426 ADD_64(qstats->total_bytes_received_hi,
3427 le32_to_cpu(tclient->rcv_multicast_bytes.hi),
3428 qstats->total_bytes_received_lo,
3429 le32_to_cpu(tclient->rcv_multicast_bytes.lo));
3430
3431 ADD_64(qstats->total_bytes_received_hi,
3432 le32_to_cpu(tclient->rcv_unicast_bytes.hi),
3433 qstats->total_bytes_received_lo,
3434 le32_to_cpu(tclient->rcv_unicast_bytes.lo));
3435
Vladislav Zolotarovdea7aab2010-04-19 01:14:07 +00003436 SUB_64(qstats->total_bytes_received_hi,
3437 le32_to_cpu(uclient->bcast_no_buff_bytes.hi),
3438 qstats->total_bytes_received_lo,
3439 le32_to_cpu(uclient->bcast_no_buff_bytes.lo));
3440
3441 SUB_64(qstats->total_bytes_received_hi,
3442 le32_to_cpu(uclient->mcast_no_buff_bytes.hi),
3443 qstats->total_bytes_received_lo,
3444 le32_to_cpu(uclient->mcast_no_buff_bytes.lo));
3445
3446 SUB_64(qstats->total_bytes_received_hi,
3447 le32_to_cpu(uclient->ucast_no_buff_bytes.hi),
3448 qstats->total_bytes_received_lo,
3449 le32_to_cpu(uclient->ucast_no_buff_bytes.lo));
3450
Eilon Greensteinca003922009-08-12 22:53:28 -07003451 qstats->valid_bytes_received_hi =
3452 qstats->total_bytes_received_hi;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003453 qstats->valid_bytes_received_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07003454 qstats->total_bytes_received_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003455
Eilon Greensteinde832a52009-02-12 08:36:33 +00003456 qstats->error_bytes_received_hi =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003457 le32_to_cpu(tclient->rcv_error_bytes.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003458 qstats->error_bytes_received_lo =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003459 le32_to_cpu(tclient->rcv_error_bytes.lo);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003460
3461 ADD_64(qstats->total_bytes_received_hi,
3462 qstats->error_bytes_received_hi,
3463 qstats->total_bytes_received_lo,
3464 qstats->error_bytes_received_lo);
3465
3466 UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
3467 total_unicast_packets_received);
3468 UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
3469 total_multicast_packets_received);
3470 UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
3471 total_broadcast_packets_received);
3472 UPDATE_EXTEND_TSTAT(packets_too_big_discard,
3473 etherstatsoverrsizepkts);
3474 UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
3475
3476 SUB_EXTEND_USTAT(ucast_no_buff_pkts,
3477 total_unicast_packets_received);
3478 SUB_EXTEND_USTAT(mcast_no_buff_pkts,
3479 total_multicast_packets_received);
3480 SUB_EXTEND_USTAT(bcast_no_buff_pkts,
3481 total_broadcast_packets_received);
3482 UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
3483 UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
3484 UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
3485
3486 qstats->total_bytes_transmitted_hi =
Eilon Greensteinca003922009-08-12 22:53:28 -07003487 le32_to_cpu(xclient->unicast_bytes_sent.hi);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003488 qstats->total_bytes_transmitted_lo =
Eilon Greensteinca003922009-08-12 22:53:28 -07003489 le32_to_cpu(xclient->unicast_bytes_sent.lo);
3490
3491 ADD_64(qstats->total_bytes_transmitted_hi,
3492 le32_to_cpu(xclient->multicast_bytes_sent.hi),
3493 qstats->total_bytes_transmitted_lo,
3494 le32_to_cpu(xclient->multicast_bytes_sent.lo));
3495
3496 ADD_64(qstats->total_bytes_transmitted_hi,
3497 le32_to_cpu(xclient->broadcast_bytes_sent.hi),
3498 qstats->total_bytes_transmitted_lo,
3499 le32_to_cpu(xclient->broadcast_bytes_sent.lo));
Eilon Greensteinde832a52009-02-12 08:36:33 +00003500
3501 UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
3502 total_unicast_packets_transmitted);
3503 UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
3504 total_multicast_packets_transmitted);
3505 UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
3506 total_broadcast_packets_transmitted);
3507
3508 old_tclient->checksum_discard = tclient->checksum_discard;
3509 old_tclient->ttl0_discard = tclient->ttl0_discard;
3510
3511 ADD_64(fstats->total_bytes_received_hi,
3512 qstats->total_bytes_received_hi,
3513 fstats->total_bytes_received_lo,
3514 qstats->total_bytes_received_lo);
3515 ADD_64(fstats->total_bytes_transmitted_hi,
3516 qstats->total_bytes_transmitted_hi,
3517 fstats->total_bytes_transmitted_lo,
3518 qstats->total_bytes_transmitted_lo);
3519 ADD_64(fstats->total_unicast_packets_received_hi,
3520 qstats->total_unicast_packets_received_hi,
3521 fstats->total_unicast_packets_received_lo,
3522 qstats->total_unicast_packets_received_lo);
3523 ADD_64(fstats->total_multicast_packets_received_hi,
3524 qstats->total_multicast_packets_received_hi,
3525 fstats->total_multicast_packets_received_lo,
3526 qstats->total_multicast_packets_received_lo);
3527 ADD_64(fstats->total_broadcast_packets_received_hi,
3528 qstats->total_broadcast_packets_received_hi,
3529 fstats->total_broadcast_packets_received_lo,
3530 qstats->total_broadcast_packets_received_lo);
3531 ADD_64(fstats->total_unicast_packets_transmitted_hi,
3532 qstats->total_unicast_packets_transmitted_hi,
3533 fstats->total_unicast_packets_transmitted_lo,
3534 qstats->total_unicast_packets_transmitted_lo);
3535 ADD_64(fstats->total_multicast_packets_transmitted_hi,
3536 qstats->total_multicast_packets_transmitted_hi,
3537 fstats->total_multicast_packets_transmitted_lo,
3538 qstats->total_multicast_packets_transmitted_lo);
3539 ADD_64(fstats->total_broadcast_packets_transmitted_hi,
3540 qstats->total_broadcast_packets_transmitted_hi,
3541 fstats->total_broadcast_packets_transmitted_lo,
3542 qstats->total_broadcast_packets_transmitted_lo);
3543 ADD_64(fstats->valid_bytes_received_hi,
3544 qstats->valid_bytes_received_hi,
3545 fstats->valid_bytes_received_lo,
3546 qstats->valid_bytes_received_lo);
3547
3548 ADD_64(estats->error_bytes_received_hi,
3549 qstats->error_bytes_received_hi,
3550 estats->error_bytes_received_lo,
3551 qstats->error_bytes_received_lo);
3552 ADD_64(estats->etherstatsoverrsizepkts_hi,
3553 qstats->etherstatsoverrsizepkts_hi,
3554 estats->etherstatsoverrsizepkts_lo,
3555 qstats->etherstatsoverrsizepkts_lo);
3556 ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
3557 estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
3558 }
3559
3560 ADD_64(fstats->total_bytes_received_hi,
3561 estats->rx_stat_ifhcinbadoctets_hi,
3562 fstats->total_bytes_received_lo,
3563 estats->rx_stat_ifhcinbadoctets_lo);
3564
3565 memcpy(estats, &(fstats->total_bytes_received_hi),
3566 sizeof(struct host_func_stats) - 2*sizeof(u32));
3567
3568 ADD_64(estats->etherstatsoverrsizepkts_hi,
3569 estats->rx_stat_dot3statsframestoolong_hi,
3570 estats->etherstatsoverrsizepkts_lo,
3571 estats->rx_stat_dot3statsframestoolong_lo);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003572 ADD_64(estats->error_bytes_received_hi,
3573 estats->rx_stat_ifhcinbadoctets_hi,
3574 estats->error_bytes_received_lo,
3575 estats->rx_stat_ifhcinbadoctets_lo);
3576
Eilon Greensteinde832a52009-02-12 08:36:33 +00003577 if (bp->port.pmf) {
3578 estats->mac_filter_discard =
3579 le32_to_cpu(tport->mac_filter_discard);
3580 estats->xxoverflow_discard =
3581 le32_to_cpu(tport->xxoverflow_discard);
3582 estats->brb_truncate_discard =
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003583 le32_to_cpu(tport->brb_truncate_discard);
Eilon Greensteinde832a52009-02-12 08:36:33 +00003584 estats->mac_discard = le32_to_cpu(tport->mac_discard);
3585 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003586
3587 fstats->host_func_stats_start = ++fstats->host_func_stats_end;
3588
Eilon Greensteinde832a52009-02-12 08:36:33 +00003589 bp->stats_pending = 0;
3590
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003591 return 0;
3592}
3593
3594static void bnx2x_net_stats_update(struct bnx2x *bp)
3595{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003596 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003597 struct net_device_stats *nstats = &bp->dev->stats;
Eilon Greensteinde832a52009-02-12 08:36:33 +00003598 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003599
3600 nstats->rx_packets =
3601 bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
3602 bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
3603 bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
3604
3605 nstats->tx_packets =
3606 bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
3607 bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
3608 bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
3609
Eilon Greensteinde832a52009-02-12 08:36:33 +00003610 nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003611
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003612 nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003613
Eilon Greensteinde832a52009-02-12 08:36:33 +00003614 nstats->rx_dropped = estats->mac_discard;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00003615 for_each_queue(bp, i)
Eilon Greensteinde832a52009-02-12 08:36:33 +00003616 nstats->rx_dropped +=
3617 le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
3618
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003619 nstats->tx_dropped = 0;
3620
3621 nstats->multicast =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003622 bnx2x_hilo(&estats->total_multicast_packets_received_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003623
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003624 nstats->collisions =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003625 bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003626
3627 nstats->rx_length_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003628 bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
3629 bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
3630 nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
3631 bnx2x_hilo(&estats->brb_truncate_hi);
3632 nstats->rx_crc_errors =
3633 bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
3634 nstats->rx_frame_errors =
3635 bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
3636 nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003637 nstats->rx_missed_errors = estats->xxoverflow_discard;
3638
3639 nstats->rx_errors = nstats->rx_length_errors +
3640 nstats->rx_over_errors +
3641 nstats->rx_crc_errors +
3642 nstats->rx_frame_errors +
Eliezer Tamir0e39e642008-02-28 11:54:03 -08003643 nstats->rx_fifo_errors +
3644 nstats->rx_missed_errors;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003645
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003646 nstats->tx_aborted_errors =
Eilon Greensteinde832a52009-02-12 08:36:33 +00003647 bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
3648 bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
3649 nstats->tx_carrier_errors =
3650 bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003651 nstats->tx_fifo_errors = 0;
3652 nstats->tx_heartbeat_errors = 0;
3653 nstats->tx_window_errors = 0;
3654
3655 nstats->tx_errors = nstats->tx_aborted_errors +
Eilon Greensteinde832a52009-02-12 08:36:33 +00003656 nstats->tx_carrier_errors +
3657 bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
3658}
3659
3660static void bnx2x_drv_stats_update(struct bnx2x *bp)
3661{
3662 struct bnx2x_eth_stats *estats = &bp->eth_stats;
3663 int i;
3664
3665 estats->driver_xoff = 0;
3666 estats->rx_err_discard_pkt = 0;
3667 estats->rx_skb_alloc_failed = 0;
3668 estats->hw_csum_err = 0;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00003669 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00003670 struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
3671
3672 estats->driver_xoff += qstats->driver_xoff;
3673 estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
3674 estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
3675 estats->hw_csum_err += qstats->hw_csum_err;
3676 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003677}
3678
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003679static void bnx2x_stats_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003680{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003681 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003682
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003683 if (*stats_comp != DMAE_COMP_VAL)
3684 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003685
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003686 if (bp->port.pmf)
Eilon Greensteinde832a52009-02-12 08:36:33 +00003687 bnx2x_hw_stats_update(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003688
Eilon Greensteinde832a52009-02-12 08:36:33 +00003689 if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
3690 BNX2X_ERR("storm stats were not updated for 3 times\n");
3691 bnx2x_panic();
3692 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003693 }
3694
Eilon Greensteinde832a52009-02-12 08:36:33 +00003695 bnx2x_net_stats_update(bp);
3696 bnx2x_drv_stats_update(bp);
3697
Joe Perches7995c642010-02-17 15:01:52 +00003698 if (netif_msg_timer(bp)) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003699 struct bnx2x_eth_stats *estats = &bp->eth_stats;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003700 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003701
Vladislav Zolotarovdea7aab2010-04-19 01:14:07 +00003702 printk(KERN_DEBUG "%s: brb drops %u brb truncate %u\n",
3703 bp->dev->name,
Eilon Greensteinde832a52009-02-12 08:36:33 +00003704 estats->brb_drop_lo, estats->brb_truncate_lo);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003705
3706 for_each_queue(bp, i) {
Vladislav Zolotarovdea7aab2010-04-19 01:14:07 +00003707 struct bnx2x_fastpath *fp = &bp->fp[i];
3708 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
3709
3710 printk(KERN_DEBUG "%s: rx usage(%4u) *rx_cons_sb(%u)"
3711 " rx pkt(%lu) rx calls(%lu %lu)\n",
3712 fp->name, (le16_to_cpu(*fp->rx_cons_sb) -
3713 fp->rx_comp_cons),
3714 le16_to_cpu(*fp->rx_cons_sb),
3715 bnx2x_hilo(&qstats->
3716 total_unicast_packets_received_hi),
3717 fp->rx_calls, fp->rx_pkt);
3718 }
3719
3720 for_each_queue(bp, i) {
3721 struct bnx2x_fastpath *fp = &bp->fp[i];
3722 struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
3723 struct netdev_queue *txq =
3724 netdev_get_tx_queue(bp->dev, i);
3725
3726 printk(KERN_DEBUG "%s: tx avail(%4u) *tx_cons_sb(%u)"
3727 " tx pkt(%lu) tx calls (%lu)"
3728 " %s (Xoff events %u)\n",
3729 fp->name, bnx2x_tx_avail(fp),
3730 le16_to_cpu(*fp->tx_cons_sb),
3731 bnx2x_hilo(&qstats->
3732 total_unicast_packets_transmitted_hi),
3733 fp->tx_pkt,
3734 (netif_tx_queue_stopped(txq) ? "Xoff" : "Xon"),
3735 qstats->driver_xoff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003736 }
3737 }
3738
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003739 bnx2x_hw_stats_post(bp);
3740 bnx2x_storm_stats_post(bp);
3741}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003742
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003743static void bnx2x_port_stats_stop(struct bnx2x *bp)
3744{
3745 struct dmae_command *dmae;
3746 u32 opcode;
3747 int loader_idx = PMF_DMAE_C(bp);
3748 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003749
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003750 bp->executer_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003751
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003752 opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3753 DMAE_CMD_C_ENABLE |
3754 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003755#ifdef __BIG_ENDIAN
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003756 DMAE_CMD_ENDIANITY_B_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003757#else
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003758 DMAE_CMD_ENDIANITY_DW_SWAP |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003759#endif
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003760 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3761 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3762
3763 if (bp->port.port_stx) {
3764
3765 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3766 if (bp->func_stx)
3767 dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
3768 else
3769 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
3770 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3771 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3772 dmae->dst_addr_lo = bp->port.port_stx >> 2;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003773 dmae->dst_addr_hi = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003774 dmae->len = sizeof(struct host_port_stats) >> 2;
3775 if (bp->func_stx) {
3776 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
3777 dmae->comp_addr_hi = 0;
3778 dmae->comp_val = 1;
3779 } else {
3780 dmae->comp_addr_lo =
3781 U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3782 dmae->comp_addr_hi =
3783 U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3784 dmae->comp_val = DMAE_COMP_VAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003785
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003786 *stats_comp = 0;
3787 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003788 }
3789
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003790 if (bp->func_stx) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003791
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003792 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3793 dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
3794 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
3795 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
3796 dmae->dst_addr_lo = bp->func_stx >> 2;
3797 dmae->dst_addr_hi = 0;
3798 dmae->len = sizeof(struct host_func_stats) >> 2;
3799 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3800 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3801 dmae->comp_val = DMAE_COMP_VAL;
3802
3803 *stats_comp = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003804 }
3805}
3806
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003807static void bnx2x_stats_stop(struct bnx2x *bp)
3808{
3809 int update = 0;
3810
3811 bnx2x_stats_comp(bp);
3812
3813 if (bp->port.pmf)
3814 update = (bnx2x_hw_stats_update(bp) == 0);
3815
3816 update |= (bnx2x_storm_stats_update(bp) == 0);
3817
3818 if (update) {
3819 bnx2x_net_stats_update(bp);
3820
3821 if (bp->port.pmf)
3822 bnx2x_port_stats_stop(bp);
3823
3824 bnx2x_hw_stats_post(bp);
3825 bnx2x_stats_comp(bp);
3826 }
3827}
3828
3829static void bnx2x_stats_do_nothing(struct bnx2x *bp)
3830{
3831}
3832
3833static const struct {
3834 void (*action)(struct bnx2x *bp);
3835 enum bnx2x_stats_state next_state;
3836} bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
3837/* state event */
3838{
3839/* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
3840/* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
3841/* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
3842/* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
3843},
3844{
3845/* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
3846/* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
3847/* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
3848/* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
3849}
3850};
3851
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003852void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003853{
3854 enum bnx2x_stats_state state = bp->stats_state;
3855
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003856 if (unlikely(bp->panic))
3857 return;
3858
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003859 bnx2x_stats_stm[state][event].action(bp);
3860 bp->stats_state = bnx2x_stats_stm[state][event].next_state;
3861
Eilon Greenstein89246652009-08-12 08:23:56 +00003862 /* Make sure the state has been "changed" */
3863 smp_wmb();
3864
Joe Perches7995c642010-02-17 15:01:52 +00003865 if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp))
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07003866 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
3867 state, event, bp->stats_state);
3868}
3869
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00003870static void bnx2x_port_stats_base_init(struct bnx2x *bp)
3871{
3872 struct dmae_command *dmae;
3873 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3874
3875 /* sanity */
3876 if (!bp->port.pmf || !bp->port.port_stx) {
3877 BNX2X_ERR("BUG!\n");
3878 return;
3879 }
3880
3881 bp->executer_idx = 0;
3882
3883 dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
3884 dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
3885 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3886 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3887#ifdef __BIG_ENDIAN
3888 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3889#else
3890 DMAE_CMD_ENDIANITY_DW_SWAP |
3891#endif
3892 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3893 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3894 dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
3895 dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
3896 dmae->dst_addr_lo = bp->port.port_stx >> 2;
3897 dmae->dst_addr_hi = 0;
3898 dmae->len = sizeof(struct host_port_stats) >> 2;
3899 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3900 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3901 dmae->comp_val = DMAE_COMP_VAL;
3902
3903 *stats_comp = 0;
3904 bnx2x_hw_stats_post(bp);
3905 bnx2x_stats_comp(bp);
3906}
3907
3908static void bnx2x_func_stats_base_init(struct bnx2x *bp)
3909{
3910 int vn, vn_max = IS_E1HMF(bp) ? E1HVN_MAX : E1VN_MAX;
3911 int port = BP_PORT(bp);
3912 int func;
3913 u32 func_stx;
3914
3915 /* sanity */
3916 if (!bp->port.pmf || !bp->func_stx) {
3917 BNX2X_ERR("BUG!\n");
3918 return;
3919 }
3920
3921 /* save our func_stx */
3922 func_stx = bp->func_stx;
3923
3924 for (vn = VN_0; vn < vn_max; vn++) {
3925 func = 2*vn + port;
3926
3927 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
3928 bnx2x_func_stats_init(bp);
3929 bnx2x_hw_stats_post(bp);
3930 bnx2x_stats_comp(bp);
3931 }
3932
3933 /* restore our func_stx */
3934 bp->func_stx = func_stx;
3935}
3936
3937static void bnx2x_func_stats_base_update(struct bnx2x *bp)
3938{
3939 struct dmae_command *dmae = &bp->stats_dmae;
3940 u32 *stats_comp = bnx2x_sp(bp, stats_comp);
3941
3942 /* sanity */
3943 if (!bp->func_stx) {
3944 BNX2X_ERR("BUG!\n");
3945 return;
3946 }
3947
3948 bp->executer_idx = 0;
3949 memset(dmae, 0, sizeof(struct dmae_command));
3950
3951 dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
3952 DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
3953 DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
3954#ifdef __BIG_ENDIAN
3955 DMAE_CMD_ENDIANITY_B_DW_SWAP |
3956#else
3957 DMAE_CMD_ENDIANITY_DW_SWAP |
3958#endif
3959 (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
3960 (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
3961 dmae->src_addr_lo = bp->func_stx >> 2;
3962 dmae->src_addr_hi = 0;
3963 dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats_base));
3964 dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats_base));
3965 dmae->len = sizeof(struct host_func_stats) >> 2;
3966 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
3967 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
3968 dmae->comp_val = DMAE_COMP_VAL;
3969
3970 *stats_comp = 0;
3971 bnx2x_hw_stats_post(bp);
3972 bnx2x_stats_comp(bp);
3973}
3974
3975static void bnx2x_stats_init(struct bnx2x *bp)
3976{
3977 int port = BP_PORT(bp);
3978 int func = BP_FUNC(bp);
3979 int i;
3980
3981 bp->stats_pending = 0;
3982 bp->executer_idx = 0;
3983 bp->stats_counter = 0;
3984
3985 /* port and func stats for management */
3986 if (!BP_NOMCP(bp)) {
3987 bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
3988 bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
3989
3990 } else {
3991 bp->port.port_stx = 0;
3992 bp->func_stx = 0;
3993 }
3994 DP(BNX2X_MSG_STATS, "port_stx 0x%x func_stx 0x%x\n",
3995 bp->port.port_stx, bp->func_stx);
3996
3997 /* port stats */
3998 memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
3999 bp->port.old_nig_stats.brb_discard =
4000 REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
4001 bp->port.old_nig_stats.brb_truncate =
4002 REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
4003 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
4004 &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
4005 REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
4006 &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
4007
4008 /* function stats */
4009 for_each_queue(bp, i) {
4010 struct bnx2x_fastpath *fp = &bp->fp[i];
4011
4012 memset(&fp->old_tclient, 0,
4013 sizeof(struct tstorm_per_client_stats));
4014 memset(&fp->old_uclient, 0,
4015 sizeof(struct ustorm_per_client_stats));
4016 memset(&fp->old_xclient, 0,
4017 sizeof(struct xstorm_per_client_stats));
4018 memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
4019 }
4020
4021 memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
4022 memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
4023
4024 bp->stats_state = STATS_STATE_DISABLED;
4025
4026 if (bp->port.pmf) {
4027 if (bp->port.port_stx)
4028 bnx2x_port_stats_base_init(bp);
4029
4030 if (bp->func_stx)
4031 bnx2x_func_stats_base_init(bp);
4032
4033 } else if (bp->func_stx)
4034 bnx2x_func_stats_base_update(bp);
4035}
4036
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004037static void bnx2x_timer(unsigned long data)
4038{
4039 struct bnx2x *bp = (struct bnx2x *) data;
4040
4041 if (!netif_running(bp->dev))
4042 return;
4043
4044 if (atomic_read(&bp->intr_sem) != 0)
Eliezer Tamirf1410642008-02-28 11:51:50 -08004045 goto timer_restart;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004046
4047 if (poll) {
4048 struct bnx2x_fastpath *fp = &bp->fp[0];
4049 int rc;
4050
Eilon Greenstein7961f792009-03-02 07:59:31 +00004051 bnx2x_tx_int(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004052 rc = bnx2x_rx_int(fp, 1000);
4053 }
4054
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004055 if (!BP_NOMCP(bp)) {
4056 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004057 u32 drv_pulse;
4058 u32 mcp_pulse;
4059
4060 ++bp->fw_drv_pulse_wr_seq;
4061 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4062 /* TBD - add SYSTEM_TIME */
4063 drv_pulse = bp->fw_drv_pulse_wr_seq;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004064 SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004065
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004066 mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004067 MCP_PULSE_SEQ_MASK);
4068 /* The delta between driver pulse and mcp response
4069 * should be 1 (before mcp response) or 0 (after mcp response)
4070 */
4071 if ((drv_pulse != mcp_pulse) &&
4072 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4073 /* someone lost a heartbeat... */
4074 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4075 drv_pulse, mcp_pulse);
4076 }
4077 }
4078
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07004079 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004080 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004081
Eliezer Tamirf1410642008-02-28 11:51:50 -08004082timer_restart:
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004083 mod_timer(&bp->timer, jiffies + bp->current_interval);
4084}
4085
4086/* end of Statistics */
4087
4088/* nic init */
4089
4090/*
4091 * nic init service functions
4092 */
4093
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004094static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004095{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004096 int port = BP_PORT(bp);
4097
Eilon Greensteinca003922009-08-12 22:53:28 -07004098 /* "CSTORM" */
4099 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4100 CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), 0,
4101 CSTORM_SB_STATUS_BLOCK_U_SIZE / 4);
4102 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4103 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), 0,
4104 CSTORM_SB_STATUS_BLOCK_C_SIZE / 4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004105}
4106
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004107void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
Eilon Greenstein5c862842008-08-13 15:51:48 -07004108 dma_addr_t mapping, int sb_id)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004109{
4110 int port = BP_PORT(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004111 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004112 int index;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004113 u64 section;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004114
4115 /* USTORM */
4116 section = ((u64)mapping) + offsetof(struct host_status_block,
4117 u_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004118 sb->u_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004119
Eilon Greensteinca003922009-08-12 22:53:28 -07004120 REG_WR(bp, BAR_CSTRORM_INTMEM +
4121 CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id), U64_LO(section));
4122 REG_WR(bp, BAR_CSTRORM_INTMEM +
4123 ((CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004124 U64_HI(section));
Eilon Greensteinca003922009-08-12 22:53:28 -07004125 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_USB_FUNC_OFF +
4126 CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004127
4128 for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
Eilon Greensteinca003922009-08-12 22:53:28 -07004129 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4130 CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004131
4132 /* CSTORM */
4133 section = ((u64)mapping) + offsetof(struct host_status_block,
4134 c_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004135 sb->c_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004136
4137 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004138 CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004139 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004140 ((CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004141 U64_HI(section));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004142 REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
Eilon Greensteinca003922009-08-12 22:53:28 -07004143 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004144
4145 for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
4146 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004147 CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004148
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004149 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
4150}
4151
4152static void bnx2x_zero_def_sb(struct bnx2x *bp)
4153{
4154 int func = BP_FUNC(bp);
4155
Eilon Greensteinca003922009-08-12 22:53:28 -07004156 bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004157 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4158 sizeof(struct tstorm_def_status_block)/4);
Eilon Greensteinca003922009-08-12 22:53:28 -07004159 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4160 CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), 0,
4161 sizeof(struct cstorm_def_status_block_u)/4);
4162 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
4163 CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), 0,
4164 sizeof(struct cstorm_def_status_block_c)/4);
4165 bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY +
Eilon Greenstein490c3c92009-03-02 07:59:52 +00004166 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
4167 sizeof(struct xstorm_def_status_block)/4);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004168}
4169
4170static void bnx2x_init_def_sb(struct bnx2x *bp,
4171 struct host_def_status_block *def_sb,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004172 dma_addr_t mapping, int sb_id)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004173{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004174 int port = BP_PORT(bp);
4175 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004176 int index, val, reg_offset;
4177 u64 section;
4178
4179 /* ATTN */
4180 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4181 atten_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004182 def_sb->atten_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004183
Eliezer Tamir49d66772008-02-28 11:53:13 -08004184 bp->attn_state = 0;
4185
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004186 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4187 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4188
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004189 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004190 bp->attn_group[index].sig[0] = REG_RD(bp,
4191 reg_offset + 0x10*index);
4192 bp->attn_group[index].sig[1] = REG_RD(bp,
4193 reg_offset + 0x4 + 0x10*index);
4194 bp->attn_group[index].sig[2] = REG_RD(bp,
4195 reg_offset + 0x8 + 0x10*index);
4196 bp->attn_group[index].sig[3] = REG_RD(bp,
4197 reg_offset + 0xc + 0x10*index);
4198 }
4199
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004200 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4201 HC_REG_ATTN_MSG0_ADDR_L);
4202
4203 REG_WR(bp, reg_offset, U64_LO(section));
4204 REG_WR(bp, reg_offset + 4, U64_HI(section));
4205
4206 reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
4207
4208 val = REG_RD(bp, reg_offset);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004209 val |= sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004210 REG_WR(bp, reg_offset, val);
4211
4212 /* USTORM */
4213 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4214 u_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004215 def_sb->u_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004216
Eilon Greensteinca003922009-08-12 22:53:28 -07004217 REG_WR(bp, BAR_CSTRORM_INTMEM +
4218 CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func), U64_LO(section));
4219 REG_WR(bp, BAR_CSTRORM_INTMEM +
4220 ((CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004221 U64_HI(section));
Eilon Greensteinca003922009-08-12 22:53:28 -07004222 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_USB_FUNC_OFF +
4223 CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004224
4225 for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
Eilon Greensteinca003922009-08-12 22:53:28 -07004226 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4227 CSTORM_DEF_SB_HC_DISABLE_U_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004228
4229 /* CSTORM */
4230 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4231 c_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004232 def_sb->c_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004233
4234 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004235 CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004236 REG_WR(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004237 ((CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004238 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004239 REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
Eilon Greensteinca003922009-08-12 22:53:28 -07004240 CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004241
4242 for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
4243 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004244 CSTORM_DEF_SB_HC_DISABLE_C_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004245
4246 /* TSTORM */
4247 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4248 t_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004249 def_sb->t_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004250
4251 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004252 TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004253 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004254 ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004255 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004256 REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004257 TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004258
4259 for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
4260 REG_WR16(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004261 TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004262
4263 /* XSTORM */
4264 section = ((u64)mapping) + offsetof(struct host_def_status_block,
4265 x_def_status_block);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004266 def_sb->x_def_status_block.status_block_id = sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004267
4268 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004269 XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004270 REG_WR(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004271 ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004272 U64_HI(section));
Eilon Greenstein5c862842008-08-13 15:51:48 -07004273 REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004274 XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004275
4276 for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
4277 REG_WR16(bp, BAR_XSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004278 XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004279
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004280 bp->stats_pending = 0;
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004281 bp->set_mac_pending = 0;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004282
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004283 bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004284}
4285
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004286void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004287{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004288 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004289 int i;
4290
4291 for_each_queue(bp, i) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004292 int sb_id = bp->fp[i].sb_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004293
4294 /* HC_INDEX_U_ETH_RX_CQ_CONS */
Eilon Greensteinca003922009-08-12 22:53:28 -07004295 REG_WR8(bp, BAR_CSTRORM_INTMEM +
4296 CSTORM_SB_HC_TIMEOUT_U_OFFSET(port, sb_id,
4297 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00004298 bp->rx_ticks/(4 * BNX2X_BTR));
Eilon Greensteinca003922009-08-12 22:53:28 -07004299 REG_WR16(bp, BAR_CSTRORM_INTMEM +
4300 CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id,
4301 U_SB_ETH_RX_CQ_INDEX),
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00004302 (bp->rx_ticks/(4 * BNX2X_BTR)) ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004303
4304 /* HC_INDEX_C_ETH_TX_CQ_CONS */
4305 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004306 CSTORM_SB_HC_TIMEOUT_C_OFFSET(port, sb_id,
4307 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00004308 bp->tx_ticks/(4 * BNX2X_BTR));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004309 REG_WR16(bp, BAR_CSTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07004310 CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id,
4311 C_SB_ETH_TX_CQ_INDEX),
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00004312 (bp->tx_ticks/(4 * BNX2X_BTR)) ? 0 : 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004313 }
4314}
4315
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004316static void bnx2x_init_sp_ring(struct bnx2x *bp)
4317{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004318 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004319
4320 spin_lock_init(&bp->spq_lock);
4321
4322 bp->spq_left = MAX_SPQ_PENDING;
4323 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004324 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4325 bp->spq_prod_bd = bp->spq;
4326 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4327
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004328 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004329 U64_LO(bp->spq_mapping));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004330 REG_WR(bp,
4331 XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004332 U64_HI(bp->spq_mapping));
4333
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004334 REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004335 bp->spq_prod_idx);
4336}
4337
4338static void bnx2x_init_context(struct bnx2x *bp)
4339{
4340 int i;
4341
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004342 /* Rx */
4343 for_each_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004344 struct eth_context *context = bnx2x_sp(bp, context[i].eth);
4345 struct bnx2x_fastpath *fp = &bp->fp[i];
Eilon Greensteinde832a52009-02-12 08:36:33 +00004346 u8 cl_id = fp->cl_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004347
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004348 context->ustorm_st_context.common.sb_index_numbers =
4349 BNX2X_RX_SB_INDEX_NUM;
Eilon Greenstein0626b892009-02-12 08:38:14 +00004350 context->ustorm_st_context.common.clientId = cl_id;
Eilon Greensteinca003922009-08-12 22:53:28 -07004351 context->ustorm_st_context.common.status_block_id = fp->sb_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004352 context->ustorm_st_context.common.flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004353 (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
4354 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
4355 context->ustorm_st_context.common.statistics_counter_id =
4356 cl_id;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004357 context->ustorm_st_context.common.mc_alignment_log_size =
Eilon Greenstein0f008462009-02-12 08:36:18 +00004358 BNX2X_RX_ALIGN_SHIFT;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004359 context->ustorm_st_context.common.bd_buff_size =
Eilon Greenstein437cf2f2008-09-03 14:38:00 -07004360 bp->rx_buf_size;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004361 context->ustorm_st_context.common.bd_page_base_hi =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004362 U64_HI(fp->rx_desc_mapping);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004363 context->ustorm_st_context.common.bd_page_base_lo =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004364 U64_LO(fp->rx_desc_mapping);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004365 if (!fp->disable_tpa) {
4366 context->ustorm_st_context.common.flags |=
Eilon Greensteinca003922009-08-12 22:53:28 -07004367 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004368 context->ustorm_st_context.common.sge_buff_size =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004369 (u16)min_t(u32, SGE_PAGE_SIZE*PAGES_PER_SGE,
4370 0xffff);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004371 context->ustorm_st_context.common.sge_page_base_hi =
4372 U64_HI(fp->rx_sge_mapping);
4373 context->ustorm_st_context.common.sge_page_base_lo =
4374 U64_LO(fp->rx_sge_mapping);
Eilon Greensteinca003922009-08-12 22:53:28 -07004375
4376 context->ustorm_st_context.common.max_sges_for_packet =
4377 SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
4378 context->ustorm_st_context.common.max_sges_for_packet =
4379 ((context->ustorm_st_context.common.
4380 max_sges_for_packet + PAGES_PER_SGE - 1) &
4381 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004382 }
4383
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004384 context->ustorm_ag_context.cdu_usage =
4385 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4386 CDU_REGION_NUMBER_UCM_AG,
4387 ETH_CONNECTION_TYPE);
4388
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004389 context->xstorm_ag_context.cdu_reserved =
4390 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
4391 CDU_REGION_NUMBER_XCM_AG,
4392 ETH_CONNECTION_TYPE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004393 }
Eilon Greensteinca003922009-08-12 22:53:28 -07004394
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004395 /* Tx */
4396 for_each_queue(bp, i) {
Eilon Greensteinca003922009-08-12 22:53:28 -07004397 struct bnx2x_fastpath *fp = &bp->fp[i];
4398 struct eth_context *context =
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004399 bnx2x_sp(bp, context[i].eth);
Eilon Greensteinca003922009-08-12 22:53:28 -07004400
4401 context->cstorm_st_context.sb_index_number =
4402 C_SB_ETH_TX_CQ_INDEX;
4403 context->cstorm_st_context.status_block_id = fp->sb_id;
4404
4405 context->xstorm_st_context.tx_bd_page_base_hi =
4406 U64_HI(fp->tx_desc_mapping);
4407 context->xstorm_st_context.tx_bd_page_base_lo =
4408 U64_LO(fp->tx_desc_mapping);
4409 context->xstorm_st_context.statistics_data = (fp->cl_id |
4410 XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
4411 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004412}
4413
4414static void bnx2x_init_ind_table(struct bnx2x *bp)
4415{
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004416 int func = BP_FUNC(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004417 int i;
4418
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004419 if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004420 return;
4421
Eilon Greenstein555f6c72009-02-12 08:36:11 +00004422 DP(NETIF_MSG_IFUP,
4423 "Initializing indirection table multi_mode %d\n", bp->multi_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004424 for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004425 REG_WR8(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08004426 TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004427 bp->fp->cl_id + (i % bp->num_queues));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004428}
4429
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004430void bnx2x_set_client_config(struct bnx2x *bp)
Eliezer Tamir49d66772008-02-28 11:53:13 -08004431{
Eliezer Tamir49d66772008-02-28 11:53:13 -08004432 struct tstorm_eth_client_config tstorm_client = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004433 int port = BP_PORT(bp);
4434 int i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004435
Eilon Greensteine7799c52009-01-14 21:30:27 -08004436 tstorm_client.mtu = bp->dev->mtu;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004437 tstorm_client.config_flags =
Eilon Greensteinde832a52009-02-12 08:36:33 +00004438 (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
4439 TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004440#ifdef BCM_VLAN
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08004441 if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
Eliezer Tamir49d66772008-02-28 11:53:13 -08004442 tstorm_client.config_flags |=
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004443 TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
Eliezer Tamir49d66772008-02-28 11:53:13 -08004444 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
4445 }
4446#endif
Eliezer Tamir49d66772008-02-28 11:53:13 -08004447
4448 for_each_queue(bp, i) {
Eilon Greensteinde832a52009-02-12 08:36:33 +00004449 tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
4450
Eliezer Tamir49d66772008-02-28 11:53:13 -08004451 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004452 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
Eliezer Tamir49d66772008-02-28 11:53:13 -08004453 ((u32 *)&tstorm_client)[0]);
4454 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004455 TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
Eliezer Tamir49d66772008-02-28 11:53:13 -08004456 ((u32 *)&tstorm_client)[1]);
4457 }
4458
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004459 DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
4460 ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
Eliezer Tamir49d66772008-02-28 11:53:13 -08004461}
4462
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004463void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004464{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004465 struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004466 int mode = bp->rx_mode;
Michael Chan37b091b2009-10-10 13:46:55 +00004467 int mask = bp->rx_mode_cl_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004468 int func = BP_FUNC(bp);
Eilon Greenstein581ce432009-07-29 00:20:04 +00004469 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004470 int i;
Eilon Greenstein581ce432009-07-29 00:20:04 +00004471 /* All but management unicast packets should pass to the host as well */
4472 u32 llh_mask =
4473 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_BRCST |
4474 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_MLCST |
4475 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_VLAN |
4476 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_NO_VLAN;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004477
Eilon Greenstein3196a882008-08-13 15:58:49 -07004478 DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004479
4480 switch (mode) {
4481 case BNX2X_RX_MODE_NONE: /* no Rx */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004482 tstorm_mac_filter.ucast_drop_all = mask;
4483 tstorm_mac_filter.mcast_drop_all = mask;
4484 tstorm_mac_filter.bcast_drop_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004485 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004486
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004487 case BNX2X_RX_MODE_NORMAL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004488 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004489 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004490
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004491 case BNX2X_RX_MODE_ALLMULTI:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004492 tstorm_mac_filter.mcast_accept_all = mask;
4493 tstorm_mac_filter.bcast_accept_all = mask;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004494 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004495
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004496 case BNX2X_RX_MODE_PROMISC:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004497 tstorm_mac_filter.ucast_accept_all = mask;
4498 tstorm_mac_filter.mcast_accept_all = mask;
4499 tstorm_mac_filter.bcast_accept_all = mask;
Eilon Greenstein581ce432009-07-29 00:20:04 +00004500 /* pass management unicast packets as well */
4501 llh_mask |= NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_UNCST;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004502 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00004503
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004504 default:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004505 BNX2X_ERR("BAD rx mode (%d)\n", mode);
4506 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004507 }
4508
Eilon Greenstein581ce432009-07-29 00:20:04 +00004509 REG_WR(bp,
4510 (port ? NIG_REG_LLH1_BRB1_DRV_MASK : NIG_REG_LLH0_BRB1_DRV_MASK),
4511 llh_mask);
4512
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004513 for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
4514 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004515 TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004516 ((u32 *)&tstorm_mac_filter)[i]);
4517
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004518/* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004519 ((u32 *)&tstorm_mac_filter)[i]); */
4520 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004521
Eliezer Tamir49d66772008-02-28 11:53:13 -08004522 if (mode != BNX2X_RX_MODE_NONE)
4523 bnx2x_set_client_config(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004524}
4525
Eilon Greenstein471de712008-08-13 15:49:35 -07004526static void bnx2x_init_internal_common(struct bnx2x *bp)
4527{
4528 int i;
4529
4530 /* Zero this manually as its initialization is
4531 currently missing in the initTool */
4532 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4533 REG_WR(bp, BAR_USTRORM_INTMEM +
4534 USTORM_AGG_DATA_OFFSET + i * 4, 0);
4535}
4536
4537static void bnx2x_init_internal_port(struct bnx2x *bp)
4538{
4539 int port = BP_PORT(bp);
4540
Eilon Greensteinca003922009-08-12 22:53:28 -07004541 REG_WR(bp,
4542 BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_U_OFFSET(port), BNX2X_BTR);
4543 REG_WR(bp,
4544 BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_C_OFFSET(port), BNX2X_BTR);
Eilon Greenstein471de712008-08-13 15:49:35 -07004545 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4546 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
4547}
4548
4549static void bnx2x_init_internal_func(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004550{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004551 struct tstorm_eth_function_common_config tstorm_config = {0};
4552 struct stats_indication_flags stats_flags = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004553 int port = BP_PORT(bp);
4554 int func = BP_FUNC(bp);
Eilon Greensteinde832a52009-02-12 08:36:33 +00004555 int i, j;
4556 u32 offset;
Eilon Greenstein471de712008-08-13 15:49:35 -07004557 u16 max_agg_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004558
Tom Herbertc68ed252010-04-23 00:10:52 -07004559 tstorm_config.config_flags = RSS_FLAGS(bp);
4560
4561 if (is_multi(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004562 tstorm_config.rss_result_mask = MULTI_MASK;
Eilon Greensteinca003922009-08-12 22:53:28 -07004563
4564 /* Enable TPA if needed */
4565 if (bp->flags & TPA_ENABLE_FLAG)
4566 tstorm_config.config_flags |=
4567 TSTORM_ETH_FUNCTION_COMMON_CONFIG_ENABLE_TPA;
4568
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08004569 if (IS_E1HMF(bp))
4570 tstorm_config.config_flags |=
4571 TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004572
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004573 tstorm_config.leading_client_id = BP_L_ID(bp);
4574
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004575 REG_WR(bp, BAR_TSTRORM_INTMEM +
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004576 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004577 (*(u32 *)&tstorm_config));
4578
Eliezer Tamirc14423f2008-02-28 11:49:42 -08004579 bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
Michael Chan37b091b2009-10-10 13:46:55 +00004580 bp->rx_mode_cl_mask = (1 << BP_L_ID(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004581 bnx2x_set_storm_rx_mode(bp);
4582
Eilon Greensteinde832a52009-02-12 08:36:33 +00004583 for_each_queue(bp, i) {
4584 u8 cl_id = bp->fp[i].cl_id;
4585
4586 /* reset xstorm per client statistics */
4587 offset = BAR_XSTRORM_INTMEM +
4588 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4589 for (j = 0;
4590 j < sizeof(struct xstorm_per_client_stats) / 4; j++)
4591 REG_WR(bp, offset + j*4, 0);
4592
4593 /* reset tstorm per client statistics */
4594 offset = BAR_TSTRORM_INTMEM +
4595 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4596 for (j = 0;
4597 j < sizeof(struct tstorm_per_client_stats) / 4; j++)
4598 REG_WR(bp, offset + j*4, 0);
4599
4600 /* reset ustorm per client statistics */
4601 offset = BAR_USTRORM_INTMEM +
4602 USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
4603 for (j = 0;
4604 j < sizeof(struct ustorm_per_client_stats) / 4; j++)
4605 REG_WR(bp, offset + j*4, 0);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004606 }
4607
4608 /* Init statistics related context */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004609 stats_flags.collect_eth = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004610
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004611 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004612 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004613 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004614 ((u32 *)&stats_flags)[1]);
4615
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004616 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004617 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004618 REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004619 ((u32 *)&stats_flags)[1]);
4620
Eilon Greensteinde832a52009-02-12 08:36:33 +00004621 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
4622 ((u32 *)&stats_flags)[0]);
4623 REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
4624 ((u32 *)&stats_flags)[1]);
4625
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004626 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004627 ((u32 *)&stats_flags)[0]);
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004628 REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004629 ((u32 *)&stats_flags)[1]);
4630
Yitchak Gertner66e855f2008-08-13 15:49:05 -07004631 REG_WR(bp, BAR_XSTRORM_INTMEM +
4632 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4633 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4634 REG_WR(bp, BAR_XSTRORM_INTMEM +
4635 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4636 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
4637
4638 REG_WR(bp, BAR_TSTRORM_INTMEM +
4639 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4640 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4641 REG_WR(bp, BAR_TSTRORM_INTMEM +
4642 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4643 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004644
Eilon Greensteinde832a52009-02-12 08:36:33 +00004645 REG_WR(bp, BAR_USTRORM_INTMEM +
4646 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
4647 U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
4648 REG_WR(bp, BAR_USTRORM_INTMEM +
4649 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
4650 U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
4651
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004652 if (CHIP_IS_E1H(bp)) {
4653 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
4654 IS_E1HMF(bp));
4655 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
4656 IS_E1HMF(bp));
4657 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
4658 IS_E1HMF(bp));
4659 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
4660 IS_E1HMF(bp));
4661
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004662 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
4663 bp->e1hov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004664 }
4665
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -08004666 /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004667 max_agg_size = min_t(u32, (min_t(u32, 8, MAX_SKB_FRAGS) *
4668 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004669 for_each_queue(bp, i) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004670 struct bnx2x_fastpath *fp = &bp->fp[i];
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004671
4672 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00004673 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004674 U64_LO(fp->rx_comp_mapping));
4675 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00004676 USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4,
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004677 U64_HI(fp->rx_comp_mapping));
4678
Eilon Greensteinca003922009-08-12 22:53:28 -07004679 /* Next page */
4680 REG_WR(bp, BAR_USTRORM_INTMEM +
4681 USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id),
4682 U64_LO(fp->rx_comp_mapping + BCM_PAGE_SIZE));
4683 REG_WR(bp, BAR_USTRORM_INTMEM +
4684 USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id) + 4,
4685 U64_HI(fp->rx_comp_mapping + BCM_PAGE_SIZE));
4686
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004687 REG_WR16(bp, BAR_USTRORM_INTMEM +
Eilon Greenstein0626b892009-02-12 08:38:14 +00004688 USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id),
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07004689 max_agg_size);
4690 }
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004691
Eilon Greenstein1c063282009-02-12 08:36:43 +00004692 /* dropless flow control */
4693 if (CHIP_IS_E1H(bp)) {
4694 struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
4695
4696 rx_pause.bd_thr_low = 250;
4697 rx_pause.cqe_thr_low = 250;
4698 rx_pause.cos = 1;
4699 rx_pause.sge_thr_low = 0;
4700 rx_pause.bd_thr_high = 350;
4701 rx_pause.cqe_thr_high = 350;
4702 rx_pause.sge_thr_high = 0;
4703
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00004704 for_each_queue(bp, i) {
Eilon Greenstein1c063282009-02-12 08:36:43 +00004705 struct bnx2x_fastpath *fp = &bp->fp[i];
4706
4707 if (!fp->disable_tpa) {
4708 rx_pause.sge_thr_low = 150;
4709 rx_pause.sge_thr_high = 250;
4710 }
4711
4712
4713 offset = BAR_USTRORM_INTMEM +
4714 USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
4715 fp->cl_id);
4716 for (j = 0;
4717 j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
4718 j++)
4719 REG_WR(bp, offset + j*4,
4720 ((u32 *)&rx_pause)[j]);
4721 }
4722 }
4723
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004724 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
4725
4726 /* Init rate shaping and fairness contexts */
4727 if (IS_E1HMF(bp)) {
4728 int vn;
4729
4730 /* During init there is no active link
4731 Until link is up, set link rate to 10Gbps */
4732 bp->link_vars.line_speed = SPEED_10000;
4733 bnx2x_init_port_minmax(bp);
4734
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07004735 if (!BP_NOMCP(bp))
4736 bp->mf_config =
4737 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004738 bnx2x_calc_vn_weight_sum(bp);
4739
4740 for (vn = VN_0; vn < E1HVN_MAX; vn++)
4741 bnx2x_init_vn_minmax(bp, 2*vn + port);
4742
4743 /* Enable rate shaping and fairness */
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07004744 bp->cmng.flags.cmng_enables |=
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004745 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07004746
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004747 } else {
4748 /* rate shaping and fairness are disabled */
4749 DP(NETIF_MSG_IFUP,
4750 "single function mode minmax will be disabled\n");
4751 }
4752
4753
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004754 /* Store cmng structures to internal memory */
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00004755 if (bp->port.pmf)
4756 for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
4757 REG_WR(bp, BAR_XSTRORM_INTMEM +
4758 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
4759 ((u32 *)(&bp->cmng))[i]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004760}
4761
Eilon Greenstein471de712008-08-13 15:49:35 -07004762static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
4763{
4764 switch (load_code) {
4765 case FW_MSG_CODE_DRV_LOAD_COMMON:
4766 bnx2x_init_internal_common(bp);
4767 /* no break */
4768
4769 case FW_MSG_CODE_DRV_LOAD_PORT:
4770 bnx2x_init_internal_port(bp);
4771 /* no break */
4772
4773 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
4774 bnx2x_init_internal_func(bp);
4775 break;
4776
4777 default:
4778 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
4779 break;
4780 }
4781}
4782
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004783void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004784{
4785 int i;
4786
4787 for_each_queue(bp, i) {
4788 struct bnx2x_fastpath *fp = &bp->fp[i];
4789
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004790 fp->bp = bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004791 fp->state = BNX2X_FP_STATE_CLOSED;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004792 fp->index = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004793 fp->cl_id = BP_L_ID(bp) + i;
Michael Chan37b091b2009-10-10 13:46:55 +00004794#ifdef BCM_CNIC
4795 fp->sb_id = fp->cl_id + 1;
4796#else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004797 fp->sb_id = fp->cl_id;
Michael Chan37b091b2009-10-10 13:46:55 +00004798#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004799 DP(NETIF_MSG_IFUP,
Eilon Greensteinf5372252009-02-12 08:38:30 +00004800 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
4801 i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004802 bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
Eilon Greenstein0626b892009-02-12 08:38:14 +00004803 fp->sb_id);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004804 bnx2x_update_fpsb_idx(fp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004805 }
4806
Eilon Greenstein16119782009-03-02 07:59:27 +00004807 /* ensure status block indices were read */
4808 rmb();
4809
4810
Eilon Greenstein5c862842008-08-13 15:51:48 -07004811 bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
4812 DEF_SB_ID);
4813 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004814 bnx2x_update_coalesce(bp);
4815 bnx2x_init_rx_rings(bp);
4816 bnx2x_init_tx_ring(bp);
4817 bnx2x_init_sp_ring(bp);
4818 bnx2x_init_context(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07004819 bnx2x_init_internal(bp, load_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004820 bnx2x_init_ind_table(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08004821 bnx2x_stats_init(bp);
4822
4823 /* At this point, we are ready for interrupts */
4824 atomic_set(&bp->intr_sem, 0);
4825
4826 /* flush all before enabling interrupts */
4827 mb();
4828 mmiowb();
4829
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08004830 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00004831
4832 /* Check for SPIO5 */
4833 bnx2x_attn_int_deasserted0(bp,
4834 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
4835 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004836}
4837
4838/* end of nic init */
4839
4840/*
4841 * gzip service functions
4842 */
4843
4844static int bnx2x_gunzip_init(struct bnx2x *bp)
4845{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00004846 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
4847 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004848 if (bp->gunzip_buf == NULL)
4849 goto gunzip_nomem1;
4850
4851 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
4852 if (bp->strm == NULL)
4853 goto gunzip_nomem2;
4854
4855 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
4856 GFP_KERNEL);
4857 if (bp->strm->workspace == NULL)
4858 goto gunzip_nomem3;
4859
4860 return 0;
4861
4862gunzip_nomem3:
4863 kfree(bp->strm);
4864 bp->strm = NULL;
4865
4866gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00004867 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
4868 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004869 bp->gunzip_buf = NULL;
4870
4871gunzip_nomem1:
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004872 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
4873 " un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004874 return -ENOMEM;
4875}
4876
4877static void bnx2x_gunzip_end(struct bnx2x *bp)
4878{
4879 kfree(bp->strm->workspace);
4880
4881 kfree(bp->strm);
4882 bp->strm = NULL;
4883
4884 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00004885 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
4886 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004887 bp->gunzip_buf = NULL;
4888 }
4889}
4890
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07004891static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004892{
4893 int n, rc;
4894
4895 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07004896 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
4897 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004898 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07004899 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004900
4901 n = 10;
4902
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004903#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004904
4905 if (zbuf[3] & FNAME)
4906 while ((zbuf[n++] != 0) && (n < len));
4907
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07004908 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004909 bp->strm->avail_in = len - n;
4910 bp->strm->next_out = bp->gunzip_buf;
4911 bp->strm->avail_out = FW_BUF_SIZE;
4912
4913 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
4914 if (rc != Z_OK)
4915 return rc;
4916
4917 rc = zlib_inflate(bp->strm, Z_FINISH);
4918 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00004919 netdev_err(bp->dev, "Firmware decompression error: %s\n",
4920 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004921
4922 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
4923 if (bp->gunzip_outlen & 0x3)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004924 netdev_err(bp->dev, "Firmware decompression error:"
4925 " gunzip_outlen (%d) not aligned\n",
4926 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004927 bp->gunzip_outlen >>= 2;
4928
4929 zlib_inflateEnd(bp->strm);
4930
4931 if (rc == Z_STREAM_END)
4932 return 0;
4933
4934 return rc;
4935}
4936
4937/* nic load/unload */
4938
4939/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004940 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004941 */
4942
4943/* send a NIG loopback debug packet */
4944static void bnx2x_lb_pckt(struct bnx2x *bp)
4945{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004946 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004947
4948 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004949 wb_write[0] = 0x55555555;
4950 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004951 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004952 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004953
4954 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004955 wb_write[0] = 0x09000000;
4956 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004957 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004958 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004959}
4960
4961/* some of the internal memories
4962 * are not directly readable from the driver
4963 * to test them we send debug packets
4964 */
4965static int bnx2x_int_mem_test(struct bnx2x *bp)
4966{
4967 int factor;
4968 int count, i;
4969 u32 val = 0;
4970
Eilon Greensteinad8d3942008-06-23 20:29:02 -07004971 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004972 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07004973 else if (CHIP_REV_IS_EMUL(bp))
4974 factor = 200;
4975 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004976 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004977
4978 DP(NETIF_MSG_HW, "start part1\n");
4979
4980 /* Disable inputs of parser neighbor blocks */
4981 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
4982 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
4983 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07004984 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004985
4986 /* Write 0 to parser credits for CFC search request */
4987 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
4988
4989 /* send Ethernet packet */
4990 bnx2x_lb_pckt(bp);
4991
4992 /* TODO do i reset NIG statistic? */
4993 /* Wait until NIG register shows 1 packet of size 0x10 */
4994 count = 1000 * factor;
4995 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004996
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004997 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
4998 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004999 if (val == 0x10)
5000 break;
5001
5002 msleep(10);
5003 count--;
5004 }
5005 if (val != 0x10) {
5006 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5007 return -1;
5008 }
5009
5010 /* Wait until PRS register shows 1 packet */
5011 count = 1000 * factor;
5012 while (count) {
5013 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005014 if (val == 1)
5015 break;
5016
5017 msleep(10);
5018 count--;
5019 }
5020 if (val != 0x1) {
5021 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5022 return -2;
5023 }
5024
5025 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005026 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005027 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005028 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005029 msleep(50);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005030 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
5031 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005032
5033 DP(NETIF_MSG_HW, "part2\n");
5034
5035 /* Disable inputs of parser neighbor blocks */
5036 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5037 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5038 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005039 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005040
5041 /* Write 0 to parser credits for CFC search request */
5042 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5043
5044 /* send 10 Ethernet packets */
5045 for (i = 0; i < 10; i++)
5046 bnx2x_lb_pckt(bp);
5047
5048 /* Wait until NIG register shows 10 + 1
5049 packets of size 11*0x10 = 0xb0 */
5050 count = 1000 * factor;
5051 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005052
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005053 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5054 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005055 if (val == 0xb0)
5056 break;
5057
5058 msleep(10);
5059 count--;
5060 }
5061 if (val != 0xb0) {
5062 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5063 return -3;
5064 }
5065
5066 /* Wait until PRS register shows 2 packets */
5067 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5068 if (val != 2)
5069 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5070
5071 /* Write 1 to parser credits for CFC search request */
5072 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5073
5074 /* Wait until PRS register shows 3 packets */
5075 msleep(10 * factor);
5076 /* Wait until NIG register shows 1 packet of size 0x10 */
5077 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5078 if (val != 3)
5079 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5080
5081 /* clear NIG EOP FIFO */
5082 for (i = 0; i < 11; i++)
5083 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5084 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5085 if (val != 1) {
5086 BNX2X_ERR("clear of NIG failed\n");
5087 return -4;
5088 }
5089
5090 /* Reset and init BRB, PRS, NIG */
5091 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5092 msleep(50);
5093 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5094 msleep(50);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005095 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
5096 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00005097#ifndef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005098 /* set NIC mode */
5099 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5100#endif
5101
5102 /* Enable inputs of parser neighbor blocks */
5103 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5104 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5105 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005106 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005107
5108 DP(NETIF_MSG_HW, "done\n");
5109
5110 return 0; /* OK */
5111}
5112
5113static void enable_blocks_attention(struct bnx2x *bp)
5114{
5115 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5116 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5117 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5118 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5119 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5120 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5121 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5122 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5123 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005124/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5125/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005126 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5127 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5128 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005129/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5130/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005131 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5132 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5133 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5134 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005135/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5136/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5137 if (CHIP_REV_IS_FPGA(bp))
5138 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5139 else
5140 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005141 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5142 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5143 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005144/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5145/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005146 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5147 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005148/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5149 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005150}
5151
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005152static const struct {
5153 u32 addr;
5154 u32 mask;
5155} bnx2x_parity_mask[] = {
5156 {PXP_REG_PXP_PRTY_MASK, 0xffffffff},
5157 {PXP2_REG_PXP2_PRTY_MASK_0, 0xffffffff},
5158 {PXP2_REG_PXP2_PRTY_MASK_1, 0xffffffff},
5159 {HC_REG_HC_PRTY_MASK, 0xffffffff},
5160 {MISC_REG_MISC_PRTY_MASK, 0xffffffff},
5161 {QM_REG_QM_PRTY_MASK, 0x0},
5162 {DORQ_REG_DORQ_PRTY_MASK, 0x0},
5163 {GRCBASE_UPB + PB_REG_PB_PRTY_MASK, 0x0},
5164 {GRCBASE_XPB + PB_REG_PB_PRTY_MASK, 0x0},
5165 {SRC_REG_SRC_PRTY_MASK, 0x4}, /* bit 2 */
5166 {CDU_REG_CDU_PRTY_MASK, 0x0},
5167 {CFC_REG_CFC_PRTY_MASK, 0x0},
5168 {DBG_REG_DBG_PRTY_MASK, 0x0},
5169 {DMAE_REG_DMAE_PRTY_MASK, 0x0},
5170 {BRB1_REG_BRB1_PRTY_MASK, 0x0},
5171 {PRS_REG_PRS_PRTY_MASK, (1<<6)},/* bit 6 */
5172 {TSDM_REG_TSDM_PRTY_MASK, 0x18},/* bit 3,4 */
5173 {CSDM_REG_CSDM_PRTY_MASK, 0x8}, /* bit 3 */
5174 {USDM_REG_USDM_PRTY_MASK, 0x38},/* bit 3,4,5 */
5175 {XSDM_REG_XSDM_PRTY_MASK, 0x8}, /* bit 3 */
5176 {TSEM_REG_TSEM_PRTY_MASK_0, 0x0},
5177 {TSEM_REG_TSEM_PRTY_MASK_1, 0x0},
5178 {USEM_REG_USEM_PRTY_MASK_0, 0x0},
5179 {USEM_REG_USEM_PRTY_MASK_1, 0x0},
5180 {CSEM_REG_CSEM_PRTY_MASK_0, 0x0},
5181 {CSEM_REG_CSEM_PRTY_MASK_1, 0x0},
5182 {XSEM_REG_XSEM_PRTY_MASK_0, 0x0},
5183 {XSEM_REG_XSEM_PRTY_MASK_1, 0x0}
5184};
5185
5186static void enable_blocks_parity(struct bnx2x *bp)
5187{
5188 int i, mask_arr_len =
5189 sizeof(bnx2x_parity_mask)/(sizeof(bnx2x_parity_mask[0]));
5190
5191 for (i = 0; i < mask_arr_len; i++)
5192 REG_WR(bp, bnx2x_parity_mask[i].addr,
5193 bnx2x_parity_mask[i].mask);
5194}
5195
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005196
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005197static void bnx2x_reset_common(struct bnx2x *bp)
5198{
5199 /* reset_common */
5200 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5201 0xd3ffff7f);
5202 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
5203}
5204
Eilon Greenstein573f2032009-08-12 08:24:14 +00005205static void bnx2x_init_pxp(struct bnx2x *bp)
5206{
5207 u16 devctl;
5208 int r_order, w_order;
5209
5210 pci_read_config_word(bp->pdev,
5211 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5212 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5213 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5214 if (bp->mrrs == -1)
5215 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5216 else {
5217 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5218 r_order = bp->mrrs;
5219 }
5220
5221 bnx2x_init_pxp_arb(bp, r_order, w_order);
5222}
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005223
5224static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5225{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005226 int is_required;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005227 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005228 int port;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005229
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005230 if (BP_NOMCP(bp))
5231 return;
5232
5233 is_required = 0;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005234 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5235 SHARED_HW_CFG_FAN_FAILURE_MASK;
5236
5237 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5238 is_required = 1;
5239
5240 /*
5241 * The fan failure mechanism is usually related to the PHY type since
5242 * the power consumption of the board is affected by the PHY. Currently,
5243 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5244 */
5245 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5246 for (port = PORT_0; port < PORT_MAX; port++) {
5247 u32 phy_type =
5248 SHMEM_RD(bp, dev_info.port_hw_config[port].
5249 external_phy_config) &
5250 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
5251 is_required |=
5252 ((phy_type ==
5253 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) ||
5254 (phy_type ==
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005255 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
5256 (phy_type ==
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005257 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481));
5258 }
5259
5260 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5261
5262 if (is_required == 0)
5263 return;
5264
5265 /* Fan failure is indicated by SPIO 5 */
5266 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5267 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5268
5269 /* set to active low mode */
5270 val = REG_RD(bp, MISC_REG_SPIO_INT);
5271 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005272 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005273 REG_WR(bp, MISC_REG_SPIO_INT, val);
5274
5275 /* enable interrupt to signal the IGU */
5276 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5277 val |= (1 << MISC_REGISTERS_SPIO_5);
5278 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5279}
5280
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005281static int bnx2x_init_common(struct bnx2x *bp)
5282{
5283 u32 val, i;
Michael Chan37b091b2009-10-10 13:46:55 +00005284#ifdef BCM_CNIC
5285 u32 wb_write[2];
5286#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005287
5288 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
5289
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005290 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005291 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5292 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
5293
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005294 bnx2x_init_block(bp, MISC_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005295 if (CHIP_IS_E1H(bp))
5296 REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
5297
5298 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
5299 msleep(30);
5300 REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
5301
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005302 bnx2x_init_block(bp, PXP_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005303 if (CHIP_IS_E1(bp)) {
5304 /* enable HW interrupt from PXP on USDM overflow
5305 bit 16 on INT_MASK_0 */
5306 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005307 }
5308
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005309 bnx2x_init_block(bp, PXP2_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005310 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005311
5312#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005313 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5314 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5315 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5316 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5317 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005318 /* make sure this value is 0 */
5319 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005320
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005321/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5322 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5323 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5324 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5325 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005326#endif
5327
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005328 REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
Michael Chan37b091b2009-10-10 13:46:55 +00005329#ifdef BCM_CNIC
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005330 REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
5331 REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
5332 REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005333#endif
5334
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005335 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5336 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005337
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005338 /* let the HW do it's magic ... */
5339 msleep(100);
5340 /* finish PXP init */
5341 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5342 if (val != 1) {
5343 BNX2X_ERR("PXP2 CFG failed\n");
5344 return -EBUSY;
5345 }
5346 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5347 if (val != 1) {
5348 BNX2X_ERR("PXP2 RD_INIT failed\n");
5349 return -EBUSY;
5350 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005351
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005352 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5353 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005354
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005355 bnx2x_init_block(bp, DMAE_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005356
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005357 /* clean the DMAE memory */
5358 bp->dmae_ready = 1;
5359 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005360
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005361 bnx2x_init_block(bp, TCM_BLOCK, COMMON_STAGE);
5362 bnx2x_init_block(bp, UCM_BLOCK, COMMON_STAGE);
5363 bnx2x_init_block(bp, CCM_BLOCK, COMMON_STAGE);
5364 bnx2x_init_block(bp, XCM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005365
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005366 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5367 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5368 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5369 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5370
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005371 bnx2x_init_block(bp, QM_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00005372
5373#ifdef BCM_CNIC
5374 wb_write[0] = 0;
5375 wb_write[1] = 0;
5376 for (i = 0; i < 64; i++) {
5377 REG_WR(bp, QM_REG_BASEADDR + i*4, 1024 * 4 * (i%16));
5378 bnx2x_init_ind_wr(bp, QM_REG_PTRTBL + i*8, wb_write, 2);
5379
5380 if (CHIP_IS_E1H(bp)) {
5381 REG_WR(bp, QM_REG_BASEADDR_EXT_A + i*4, 1024*4*(i%16));
5382 bnx2x_init_ind_wr(bp, QM_REG_PTRTBL_EXT_A + i*8,
5383 wb_write, 2);
5384 }
5385 }
5386#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005387 /* soft reset pulse */
5388 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5389 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005390
Michael Chan37b091b2009-10-10 13:46:55 +00005391#ifdef BCM_CNIC
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005392 bnx2x_init_block(bp, TIMERS_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005393#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005394
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005395 bnx2x_init_block(bp, DQ_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005396 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
5397 if (!CHIP_REV_IS_SLOW(bp)) {
5398 /* enable hw interrupt from doorbell Q */
5399 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5400 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005401
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005402 bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
5403 bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005404 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Michael Chan37b091b2009-10-10 13:46:55 +00005405#ifndef BCM_CNIC
Eilon Greenstein3196a882008-08-13 15:58:49 -07005406 /* set NIC mode */
5407 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Michael Chan37b091b2009-10-10 13:46:55 +00005408#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005409 if (CHIP_IS_E1H(bp))
5410 REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005411
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005412 bnx2x_init_block(bp, TSDM_BLOCK, COMMON_STAGE);
5413 bnx2x_init_block(bp, CSDM_BLOCK, COMMON_STAGE);
5414 bnx2x_init_block(bp, USDM_BLOCK, COMMON_STAGE);
5415 bnx2x_init_block(bp, XSDM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005416
Eilon Greensteinca003922009-08-12 22:53:28 -07005417 bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
5418 bnx2x_init_fill(bp, USEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
5419 bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
5420 bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005421
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005422 bnx2x_init_block(bp, TSEM_BLOCK, COMMON_STAGE);
5423 bnx2x_init_block(bp, USEM_BLOCK, COMMON_STAGE);
5424 bnx2x_init_block(bp, CSEM_BLOCK, COMMON_STAGE);
5425 bnx2x_init_block(bp, XSEM_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005426
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005427 /* sync semi rtc */
5428 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5429 0x80000000);
5430 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5431 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005432
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005433 bnx2x_init_block(bp, UPB_BLOCK, COMMON_STAGE);
5434 bnx2x_init_block(bp, XPB_BLOCK, COMMON_STAGE);
5435 bnx2x_init_block(bp, PBF_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005436
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005437 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Tom Herbertc68ed252010-04-23 00:10:52 -07005438 for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4)
5439 REG_WR(bp, i, random32());
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005440 bnx2x_init_block(bp, SRCH_BLOCK, COMMON_STAGE);
Michael Chan37b091b2009-10-10 13:46:55 +00005441#ifdef BCM_CNIC
5442 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
5443 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
5444 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
5445 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
5446 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
5447 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
5448 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
5449 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
5450 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
5451 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
5452#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005453 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005454
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005455 if (sizeof(union cdu_context) != 1024)
5456 /* we currently assume that a context is 1024 bytes */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005457 dev_alert(&bp->pdev->dev, "please adjust the size "
5458 "of cdu_context(%ld)\n",
Joe Perches7995c642010-02-17 15:01:52 +00005459 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005460
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005461 bnx2x_init_block(bp, CDU_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005462 val = (4 << 24) + (0 << 12) + 1024;
5463 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005464
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005465 bnx2x_init_block(bp, CFC_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005466 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005467 /* enable context validation interrupt from CFC */
5468 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5469
5470 /* set the thresholds to prevent CFC/CDU race */
5471 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005472
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005473 bnx2x_init_block(bp, HC_BLOCK, COMMON_STAGE);
5474 bnx2x_init_block(bp, MISC_AEU_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005475
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005476 bnx2x_init_block(bp, PXPCS_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005477 /* Reset PCIE errors for debug */
5478 REG_WR(bp, 0x2814, 0xffffffff);
5479 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005480
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005481 bnx2x_init_block(bp, EMAC0_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005482 bnx2x_init_block(bp, EMAC1_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005483 bnx2x_init_block(bp, DBU_BLOCK, COMMON_STAGE);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005484 bnx2x_init_block(bp, DBG_BLOCK, COMMON_STAGE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005485
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005486 bnx2x_init_block(bp, NIG_BLOCK, COMMON_STAGE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005487 if (CHIP_IS_E1H(bp)) {
5488 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
5489 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
5490 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005491
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005492 if (CHIP_REV_IS_SLOW(bp))
5493 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005494
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005495 /* finish CFC init */
5496 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5497 if (val != 1) {
5498 BNX2X_ERR("CFC LL_INIT failed\n");
5499 return -EBUSY;
5500 }
5501 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5502 if (val != 1) {
5503 BNX2X_ERR("CFC AC_INIT failed\n");
5504 return -EBUSY;
5505 }
5506 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5507 if (val != 1) {
5508 BNX2X_ERR("CFC CAM_INIT failed\n");
5509 return -EBUSY;
5510 }
5511 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005512
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005513 /* read NIG statistic
5514 to see if this is our first up since powerup */
5515 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5516 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005517
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005518 /* do internal memory self test */
5519 if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
5520 BNX2X_ERR("internal mem self test failed\n");
5521 return -EBUSY;
5522 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005523
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005524 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein46c6a672009-02-12 08:36:58 +00005525 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
5526 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
5527 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005528 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eilon Greenstein46c6a672009-02-12 08:36:58 +00005529 bp->port.need_hw_lock = 1;
5530 break;
5531
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005532 default:
5533 break;
5534 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08005535
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00005536 bnx2x_setup_fan_failure_detection(bp);
5537
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005538 /* clear PXP2 attentions */
5539 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005540
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005541 enable_blocks_attention(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005542 if (CHIP_PARITY_SUPPORTED(bp))
5543 enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005544
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005545 if (!BP_NOMCP(bp)) {
5546 bnx2x_acquire_phy_lock(bp);
5547 bnx2x_common_init_phy(bp, bp->common.shmem_base);
5548 bnx2x_release_phy_lock(bp);
5549 } else
5550 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5551
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005552 return 0;
5553}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005554
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005555static int bnx2x_init_port(struct bnx2x *bp)
5556{
5557 int port = BP_PORT(bp);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005558 int init_stage = port ? PORT1_STAGE : PORT0_STAGE;
Eilon Greenstein1c063282009-02-12 08:36:43 +00005559 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005560 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005561
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005562 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005563
5564 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005565
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005566 bnx2x_init_block(bp, PXP_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005567 bnx2x_init_block(bp, PXP2_BLOCK, init_stage);
Eilon Greensteinca003922009-08-12 22:53:28 -07005568
5569 bnx2x_init_block(bp, TCM_BLOCK, init_stage);
5570 bnx2x_init_block(bp, UCM_BLOCK, init_stage);
5571 bnx2x_init_block(bp, CCM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005572 bnx2x_init_block(bp, XCM_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005573
Michael Chan37b091b2009-10-10 13:46:55 +00005574#ifdef BCM_CNIC
5575 REG_WR(bp, QM_REG_CONNNUM_0 + port*4, 1024/16 - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005576
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005577 bnx2x_init_block(bp, TIMERS_BLOCK, init_stage);
Michael Chan37b091b2009-10-10 13:46:55 +00005578 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
5579 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005580#endif
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005581
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005582 bnx2x_init_block(bp, DQ_BLOCK, init_stage);
Eilon Greenstein1c063282009-02-12 08:36:43 +00005583
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005584 bnx2x_init_block(bp, BRB1_BLOCK, init_stage);
Eilon Greenstein1c063282009-02-12 08:36:43 +00005585 if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
5586 /* no pause for emulation and FPGA */
5587 low = 0;
5588 high = 513;
5589 } else {
5590 if (IS_E1HMF(bp))
5591 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
5592 else if (bp->dev->mtu > 4096) {
5593 if (bp->flags & ONE_PORT_FLAG)
5594 low = 160;
5595 else {
5596 val = bp->dev->mtu;
5597 /* (24*1024 + val*4)/256 */
5598 low = 96 + (val/64) + ((val % 64) ? 1 : 0);
5599 }
5600 } else
5601 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
5602 high = low + 56; /* 14*1024/256 */
5603 }
5604 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
5605 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
5606
5607
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005608 bnx2x_init_block(bp, PRS_BLOCK, init_stage);
Eilon Greensteinca003922009-08-12 22:53:28 -07005609
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005610 bnx2x_init_block(bp, TSDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005611 bnx2x_init_block(bp, CSDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005612 bnx2x_init_block(bp, USDM_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005613 bnx2x_init_block(bp, XSDM_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00005614
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005615 bnx2x_init_block(bp, TSEM_BLOCK, init_stage);
5616 bnx2x_init_block(bp, USEM_BLOCK, init_stage);
5617 bnx2x_init_block(bp, CSEM_BLOCK, init_stage);
5618 bnx2x_init_block(bp, XSEM_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00005619
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005620 bnx2x_init_block(bp, UPB_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005621 bnx2x_init_block(bp, XPB_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005622
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005623 bnx2x_init_block(bp, PBF_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005624
5625 /* configure PBF to work without PAUSE mtu 9000 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005626 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005627
5628 /* update threshold */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005629 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005630 /* update init credit */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005631 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005632
5633 /* probe changes */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005634 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005635 msleep(5);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005636 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005637
Michael Chan37b091b2009-10-10 13:46:55 +00005638#ifdef BCM_CNIC
5639 bnx2x_init_block(bp, SRCH_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005640#endif
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005641 bnx2x_init_block(bp, CDU_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005642 bnx2x_init_block(bp, CFC_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005643
5644 if (CHIP_IS_E1(bp)) {
5645 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
5646 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
5647 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005648 bnx2x_init_block(bp, HC_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005649
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005650 bnx2x_init_block(bp, MISC_AEU_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005651 /* init aeu_mask_attn_func_0/1:
5652 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
5653 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
5654 * bits 4-7 are used for "per vn group attention" */
5655 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
5656 (IS_E1HMF(bp) ? 0xF7 : 0x7));
5657
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005658 bnx2x_init_block(bp, PXPCS_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005659 bnx2x_init_block(bp, EMAC0_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005660 bnx2x_init_block(bp, EMAC1_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005661 bnx2x_init_block(bp, DBU_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005662 bnx2x_init_block(bp, DBG_BLOCK, init_stage);
Eilon Greenstein356e2382009-02-12 08:38:32 +00005663
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005664 bnx2x_init_block(bp, NIG_BLOCK, init_stage);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005665
5666 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
5667
5668 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005669 /* 0x2 disable e1hov, 0x1 enable */
5670 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
5671 (IS_E1HMF(bp) ? 0x1 : 0x2));
5672
Eilon Greenstein1c063282009-02-12 08:36:43 +00005673 {
5674 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
5675 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
5676 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
5677 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005678 }
5679
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005680 bnx2x_init_block(bp, MCP_BLOCK, init_stage);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005681 bnx2x_init_block(bp, DMAE_BLOCK, init_stage);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005682
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005683 switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00005684 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5685 {
5686 u32 swap_val, swap_override, aeu_gpio_mask, offset;
5687
5688 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
5689 MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
5690
5691 /* The GPIO should be swapped if the swap register is
5692 set and active */
5693 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5694 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5695
5696 /* Select function upon port-swap configuration */
5697 if (port == 0) {
5698 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5699 aeu_gpio_mask = (swap_val && swap_override) ?
5700 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
5701 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
5702 } else {
5703 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
5704 aeu_gpio_mask = (swap_val && swap_override) ?
5705 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
5706 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
5707 }
5708 val = REG_RD(bp, offset);
5709 /* add GPIO3 to group */
5710 val |= aeu_gpio_mask;
5711 REG_WR(bp, offset, val);
5712 }
5713 break;
5714
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00005715 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005716 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eliezer Tamirf1410642008-02-28 11:51:50 -08005717 /* add SPIO 5 to group 0 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005718 {
5719 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5720 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5721 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08005722 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005723 REG_WR(bp, reg_addr, val);
5724 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08005725 break;
5726
5727 default:
5728 break;
5729 }
5730
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07005731 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005732
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005733 return 0;
5734}
5735
5736#define ILT_PER_FUNC (768/2)
5737#define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
5738/* the phys address is shifted right 12 bits and has an added
5739 1=valid bit added to the 53rd bit
5740 then since this is a wide register(TM)
5741 we split it into two 32 bit writes
5742 */
5743#define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
5744#define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
5745#define PXP_ONE_ILT(x) (((x) << 10) | x)
5746#define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
5747
Michael Chan37b091b2009-10-10 13:46:55 +00005748#ifdef BCM_CNIC
5749#define CNIC_ILT_LINES 127
5750#define CNIC_CTX_PER_ILT 16
5751#else
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005752#define CNIC_ILT_LINES 0
Michael Chan37b091b2009-10-10 13:46:55 +00005753#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005754
5755static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
5756{
5757 int reg;
5758
5759 if (CHIP_IS_E1H(bp))
5760 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
5761 else /* E1 */
5762 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
5763
5764 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
5765}
5766
5767static int bnx2x_init_func(struct bnx2x *bp)
5768{
5769 int port = BP_PORT(bp);
5770 int func = BP_FUNC(bp);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005771 u32 addr, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005772 int i;
5773
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005774 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005775
Eilon Greenstein8badd272009-02-12 08:36:15 +00005776 /* set MSI reconfigure capability */
5777 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
5778 val = REG_RD(bp, addr);
5779 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
5780 REG_WR(bp, addr, val);
5781
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005782 i = FUNC_ILT_BASE(func);
5783
5784 bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
5785 if (CHIP_IS_E1H(bp)) {
5786 REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
5787 REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
5788 } else /* E1 */
5789 REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
5790 PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
5791
Michael Chan37b091b2009-10-10 13:46:55 +00005792#ifdef BCM_CNIC
5793 i += 1 + CNIC_ILT_LINES;
5794 bnx2x_ilt_wr(bp, i, bp->timers_mapping);
5795 if (CHIP_IS_E1(bp))
5796 REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
5797 else {
5798 REG_WR(bp, PXP2_REG_RQ_TM_FIRST_ILT, i);
5799 REG_WR(bp, PXP2_REG_RQ_TM_LAST_ILT, i);
5800 }
5801
5802 i++;
5803 bnx2x_ilt_wr(bp, i, bp->qm_mapping);
5804 if (CHIP_IS_E1(bp))
5805 REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
5806 else {
5807 REG_WR(bp, PXP2_REG_RQ_QM_FIRST_ILT, i);
5808 REG_WR(bp, PXP2_REG_RQ_QM_LAST_ILT, i);
5809 }
5810
5811 i++;
5812 bnx2x_ilt_wr(bp, i, bp->t1_mapping);
5813 if (CHIP_IS_E1(bp))
5814 REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
5815 else {
5816 REG_WR(bp, PXP2_REG_RQ_SRC_FIRST_ILT, i);
5817 REG_WR(bp, PXP2_REG_RQ_SRC_LAST_ILT, i);
5818 }
5819
5820 /* tell the searcher where the T2 table is */
5821 REG_WR(bp, SRC_REG_COUNTFREE0 + port*4, 16*1024/64);
5822
5823 bnx2x_wb_wr(bp, SRC_REG_FIRSTFREE0 + port*16,
5824 U64_LO(bp->t2_mapping), U64_HI(bp->t2_mapping));
5825
5826 bnx2x_wb_wr(bp, SRC_REG_LASTFREE0 + port*16,
5827 U64_LO((u64)bp->t2_mapping + 16*1024 - 64),
5828 U64_HI((u64)bp->t2_mapping + 16*1024 - 64));
5829
5830 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, 10);
5831#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005832
5833 if (CHIP_IS_E1H(bp)) {
Eilon Greenstein573f2032009-08-12 08:24:14 +00005834 bnx2x_init_block(bp, MISC_BLOCK, FUNC0_STAGE + func);
5835 bnx2x_init_block(bp, TCM_BLOCK, FUNC0_STAGE + func);
5836 bnx2x_init_block(bp, UCM_BLOCK, FUNC0_STAGE + func);
5837 bnx2x_init_block(bp, CCM_BLOCK, FUNC0_STAGE + func);
5838 bnx2x_init_block(bp, XCM_BLOCK, FUNC0_STAGE + func);
5839 bnx2x_init_block(bp, TSEM_BLOCK, FUNC0_STAGE + func);
5840 bnx2x_init_block(bp, USEM_BLOCK, FUNC0_STAGE + func);
5841 bnx2x_init_block(bp, CSEM_BLOCK, FUNC0_STAGE + func);
5842 bnx2x_init_block(bp, XSEM_BLOCK, FUNC0_STAGE + func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005843
5844 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
5845 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
5846 }
5847
5848 /* HC init per function */
5849 if (CHIP_IS_E1H(bp)) {
5850 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
5851
5852 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
5853 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
5854 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005855 bnx2x_init_block(bp, HC_BLOCK, FUNC0_STAGE + func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005856
Eliezer Tamirc14423f2008-02-28 11:49:42 -08005857 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005858 REG_WR(bp, 0x2114, 0xffffffff);
5859 REG_WR(bp, 0x2120, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005860
5861 return 0;
5862}
5863
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005864int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005865{
5866 int i, rc = 0;
5867
5868 DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
5869 BP_FUNC(bp), load_code);
5870
5871 bp->dmae_ready = 0;
5872 mutex_init(&bp->dmae_mutex);
Eilon Greenstein54016b22009-08-12 08:23:48 +00005873 rc = bnx2x_gunzip_init(bp);
5874 if (rc)
5875 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005876
5877 switch (load_code) {
5878 case FW_MSG_CODE_DRV_LOAD_COMMON:
5879 rc = bnx2x_init_common(bp);
5880 if (rc)
5881 goto init_hw_err;
5882 /* no break */
5883
5884 case FW_MSG_CODE_DRV_LOAD_PORT:
5885 bp->dmae_ready = 1;
5886 rc = bnx2x_init_port(bp);
5887 if (rc)
5888 goto init_hw_err;
5889 /* no break */
5890
5891 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5892 bp->dmae_ready = 1;
5893 rc = bnx2x_init_func(bp);
5894 if (rc)
5895 goto init_hw_err;
5896 break;
5897
5898 default:
5899 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5900 break;
5901 }
5902
5903 if (!BP_NOMCP(bp)) {
5904 int func = BP_FUNC(bp);
5905
5906 bp->fw_drv_pulse_wr_seq =
5907 (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
5908 DRV_PULSE_SEQ_MASK);
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +00005909 DP(BNX2X_MSG_MCP, "drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
5910 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005911
5912 /* this needs to be done before gunzip end */
5913 bnx2x_zero_def_sb(bp);
5914 for_each_queue(bp, i)
5915 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
Michael Chan37b091b2009-10-10 13:46:55 +00005916#ifdef BCM_CNIC
5917 bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
5918#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005919
5920init_hw_err:
5921 bnx2x_gunzip_end(bp);
5922
5923 return rc;
5924}
5925
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005926void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005927{
5928
5929#define BNX2X_PCI_FREE(x, y, size) \
5930 do { \
5931 if (x) { \
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005932 dma_free_coherent(&bp->pdev->dev, size, x, y); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005933 x = NULL; \
5934 y = 0; \
5935 } \
5936 } while (0)
5937
5938#define BNX2X_FREE(x) \
5939 do { \
5940 if (x) { \
5941 vfree(x); \
5942 x = NULL; \
5943 } \
5944 } while (0)
5945
5946 int i;
5947
5948 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005949 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005950 for_each_queue(bp, i) {
5951
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005952 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005953 BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
5954 bnx2x_fp(bp, i, status_blk_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07005955 sizeof(struct host_status_block));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005956 }
5957 /* Rx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00005958 for_each_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005959
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005960 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005961 BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
5962 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
5963 bnx2x_fp(bp, i, rx_desc_mapping),
5964 sizeof(struct eth_rx_bd) * NUM_RX_BD);
5965
5966 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
5967 bnx2x_fp(bp, i, rx_comp_mapping),
5968 sizeof(struct eth_fast_path_rx_cqe) *
5969 NUM_RCQ_BD);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005970
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005971 /* SGE ring */
Eilon Greenstein32626232008-08-13 15:51:07 -07005972 BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07005973 BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
5974 bnx2x_fp(bp, i, rx_sge_mapping),
5975 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
5976 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005977 /* Tx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00005978 for_each_queue(bp, i) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005979
5980 /* fastpath tx rings: tx_buf tx_desc */
5981 BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
5982 BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
5983 bnx2x_fp(bp, i, tx_desc_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07005984 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00005985 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005986 /* end of fastpath */
5987
5988 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005989 sizeof(struct host_def_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005990
5991 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005992 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005993
Michael Chan37b091b2009-10-10 13:46:55 +00005994#ifdef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005995 BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
5996 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
5997 BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
5998 BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
Michael Chan37b091b2009-10-10 13:46:55 +00005999 BNX2X_PCI_FREE(bp->cnic_sb, bp->cnic_sb_mapping,
6000 sizeof(struct host_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006001#endif
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006002 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006003
6004#undef BNX2X_PCI_FREE
6005#undef BNX2X_KFREE
6006}
6007
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006008int bnx2x_alloc_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006009{
6010
6011#define BNX2X_PCI_ALLOC(x, y, size) \
6012 do { \
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006013 x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006014 if (x == NULL) \
6015 goto alloc_mem_err; \
6016 memset(x, 0, size); \
6017 } while (0)
6018
6019#define BNX2X_ALLOC(x, size) \
6020 do { \
6021 x = vmalloc(size); \
6022 if (x == NULL) \
6023 goto alloc_mem_err; \
6024 memset(x, 0, size); \
6025 } while (0)
6026
6027 int i;
6028
6029 /* fastpath */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006030 /* Common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006031 for_each_queue(bp, i) {
6032 bnx2x_fp(bp, i, bp) = bp;
6033
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006034 /* status blocks */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006035 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
6036 &bnx2x_fp(bp, i, status_blk_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006037 sizeof(struct host_status_block));
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006038 }
6039 /* Rx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006040 for_each_queue(bp, i) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006041
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006042 /* fastpath rx rings: rx_buf rx_desc rx_comp */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006043 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
6044 sizeof(struct sw_rx_bd) * NUM_RX_BD);
6045 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
6046 &bnx2x_fp(bp, i, rx_desc_mapping),
6047 sizeof(struct eth_rx_bd) * NUM_RX_BD);
6048
6049 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
6050 &bnx2x_fp(bp, i, rx_comp_mapping),
6051 sizeof(struct eth_fast_path_rx_cqe) *
6052 NUM_RCQ_BD);
6053
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006054 /* SGE ring */
6055 BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
6056 sizeof(struct sw_rx_page) * NUM_RX_SGE);
6057 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
6058 &bnx2x_fp(bp, i, rx_sge_mapping),
6059 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006060 }
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006061 /* Tx */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006062 for_each_queue(bp, i) {
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006063
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006064 /* fastpath tx rings: tx_buf tx_desc */
6065 BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
6066 sizeof(struct sw_tx_bd) * NUM_TX_BD);
6067 BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
6068 &bnx2x_fp(bp, i, tx_desc_mapping),
Eilon Greensteinca003922009-08-12 22:53:28 -07006069 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006070 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006071 /* end of fastpath */
6072
6073 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6074 sizeof(struct host_def_status_block));
6075
6076 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6077 sizeof(struct bnx2x_slowpath));
6078
Michael Chan37b091b2009-10-10 13:46:55 +00006079#ifdef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006080 BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
6081
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006082 /* allocate searcher T2 table
6083 we allocate 1/4 of alloc num for T2
6084 (which is not entered into the ILT) */
6085 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
6086
Michael Chan37b091b2009-10-10 13:46:55 +00006087 /* Initialize T2 (for 1024 connections) */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006088 for (i = 0; i < 16*1024; i += 64)
Michael Chan37b091b2009-10-10 13:46:55 +00006089 *(u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006090
Michael Chan37b091b2009-10-10 13:46:55 +00006091 /* Timer block array (8*MAX_CONN) phys uncached for now 1024 conns */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006092 BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
6093
6094 /* QM queues (128*MAX_CONN) */
6095 BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
Michael Chan37b091b2009-10-10 13:46:55 +00006096
6097 BNX2X_PCI_ALLOC(bp->cnic_sb, &bp->cnic_sb_mapping,
6098 sizeof(struct host_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006099#endif
6100
6101 /* Slow path ring */
6102 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6103
6104 return 0;
6105
6106alloc_mem_err:
6107 bnx2x_free_mem(bp);
6108 return -ENOMEM;
6109
6110#undef BNX2X_PCI_ALLOC
6111#undef BNX2X_ALLOC
6112}
6113
Yitchak Gertner65abd742008-08-25 15:26:24 -07006114
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006115/*
6116 * Init service functions
6117 */
6118
Michael Chane665bfd2009-10-10 13:46:54 +00006119/**
6120 * Sets a MAC in a CAM for a few L2 Clients for E1 chip
6121 *
6122 * @param bp driver descriptor
6123 * @param set set or clear an entry (1 or 0)
6124 * @param mac pointer to a buffer containing a MAC
6125 * @param cl_bit_vec bit vector of clients to register a MAC for
6126 * @param cam_offset offset in a CAM to use
6127 * @param with_bcast set broadcast MAC as well
6128 */
6129static void bnx2x_set_mac_addr_e1_gen(struct bnx2x *bp, int set, u8 *mac,
6130 u32 cl_bit_vec, u8 cam_offset,
6131 u8 with_bcast)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006132{
6133 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006134 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006135
6136 /* CAM allocation
6137 * unicasts 0-31:port0 32-63:port1
6138 * multicast 64-127:port0 128-191:port1
6139 */
Michael Chane665bfd2009-10-10 13:46:54 +00006140 config->hdr.length = 1 + (with_bcast ? 1 : 0);
6141 config->hdr.offset = cam_offset;
6142 config->hdr.client_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006143 config->hdr.reserved1 = 0;
6144
6145 /* primary MAC */
6146 config->config_table[0].cam_entry.msb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006147 swab16(*(u16 *)&mac[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006148 config->config_table[0].cam_entry.middle_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006149 swab16(*(u16 *)&mac[2]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006150 config->config_table[0].cam_entry.lsb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006151 swab16(*(u16 *)&mac[4]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006152 config->config_table[0].cam_entry.flags = cpu_to_le16(port);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006153 if (set)
6154 config->config_table[0].target_table_entry.flags = 0;
6155 else
6156 CAM_INVALIDATE(config->config_table[0]);
Eilon Greensteinca003922009-08-12 22:53:28 -07006157 config->config_table[0].target_table_entry.clients_bit_vector =
Michael Chane665bfd2009-10-10 13:46:54 +00006158 cpu_to_le32(cl_bit_vec);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006159 config->config_table[0].target_table_entry.vlan_id = 0;
6160
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006161 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
6162 (set ? "setting" : "clearing"),
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006163 config->config_table[0].cam_entry.msb_mac_addr,
6164 config->config_table[0].cam_entry.middle_mac_addr,
6165 config->config_table[0].cam_entry.lsb_mac_addr);
6166
6167 /* broadcast */
Michael Chane665bfd2009-10-10 13:46:54 +00006168 if (with_bcast) {
6169 config->config_table[1].cam_entry.msb_mac_addr =
6170 cpu_to_le16(0xffff);
6171 config->config_table[1].cam_entry.middle_mac_addr =
6172 cpu_to_le16(0xffff);
6173 config->config_table[1].cam_entry.lsb_mac_addr =
6174 cpu_to_le16(0xffff);
6175 config->config_table[1].cam_entry.flags = cpu_to_le16(port);
6176 if (set)
6177 config->config_table[1].target_table_entry.flags =
6178 TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
6179 else
6180 CAM_INVALIDATE(config->config_table[1]);
6181 config->config_table[1].target_table_entry.clients_bit_vector =
6182 cpu_to_le32(cl_bit_vec);
6183 config->config_table[1].target_table_entry.vlan_id = 0;
6184 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006185
6186 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6187 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6188 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6189}
6190
Michael Chane665bfd2009-10-10 13:46:54 +00006191/**
6192 * Sets a MAC in a CAM for a few L2 Clients for E1H chip
6193 *
6194 * @param bp driver descriptor
6195 * @param set set or clear an entry (1 or 0)
6196 * @param mac pointer to a buffer containing a MAC
6197 * @param cl_bit_vec bit vector of clients to register a MAC for
6198 * @param cam_offset offset in a CAM to use
6199 */
6200static void bnx2x_set_mac_addr_e1h_gen(struct bnx2x *bp, int set, u8 *mac,
6201 u32 cl_bit_vec, u8 cam_offset)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006202{
6203 struct mac_configuration_cmd_e1h *config =
6204 (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
6205
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006206 config->hdr.length = 1;
Michael Chane665bfd2009-10-10 13:46:54 +00006207 config->hdr.offset = cam_offset;
6208 config->hdr.client_id = 0xff;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006209 config->hdr.reserved1 = 0;
6210
6211 /* primary MAC */
6212 config->config_table[0].msb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006213 swab16(*(u16 *)&mac[0]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006214 config->config_table[0].middle_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006215 swab16(*(u16 *)&mac[2]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006216 config->config_table[0].lsb_mac_addr =
Michael Chane665bfd2009-10-10 13:46:54 +00006217 swab16(*(u16 *)&mac[4]);
Eilon Greensteinca003922009-08-12 22:53:28 -07006218 config->config_table[0].clients_bit_vector =
Michael Chane665bfd2009-10-10 13:46:54 +00006219 cpu_to_le32(cl_bit_vec);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006220 config->config_table[0].vlan_id = 0;
6221 config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006222 if (set)
6223 config->config_table[0].flags = BP_PORT(bp);
6224 else
6225 config->config_table[0].flags =
6226 MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006227
Michael Chane665bfd2009-10-10 13:46:54 +00006228 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID mask %d\n",
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006229 (set ? "setting" : "clearing"),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006230 config->config_table[0].msb_mac_addr,
6231 config->config_table[0].middle_mac_addr,
Michael Chane665bfd2009-10-10 13:46:54 +00006232 config->config_table[0].lsb_mac_addr, bp->e1hov, cl_bit_vec);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006233
6234 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6235 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
6236 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
6237}
6238
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006239static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6240 int *state_p, int poll)
6241{
6242 /* can take a while if any port is running */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006243 int cnt = 5000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006244
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006245 DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
6246 poll ? "polling" : "waiting", state, idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006247
6248 might_sleep();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006249 while (cnt--) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006250 if (poll) {
6251 bnx2x_rx_int(bp->fp, 10);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006252 /* if index is different from 0
6253 * the reply for some commands will
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006254 * be on the non default queue
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006255 */
6256 if (idx)
6257 bnx2x_rx_int(&bp->fp[idx], 10);
6258 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006259
Yitchak Gertner3101c2b2008-08-13 15:52:28 -07006260 mb(); /* state is changed by bnx2x_sp_event() */
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006261 if (*state_p == state) {
6262#ifdef BNX2X_STOP_ON_ERROR
6263 DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
6264#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006265 return 0;
Eilon Greenstein8b3a0f02009-02-12 08:37:23 +00006266 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006267
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006268 msleep(1);
Eilon Greensteine3553b22009-08-12 08:23:31 +00006269
6270 if (bp->panic)
6271 return -EIO;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006272 }
6273
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006274 /* timeout! */
Eliezer Tamir49d66772008-02-28 11:53:13 -08006275 BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
6276 poll ? "polling" : "waiting", state, idx);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006277#ifdef BNX2X_STOP_ON_ERROR
6278 bnx2x_panic();
6279#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006280
Eliezer Tamir49d66772008-02-28 11:53:13 -08006281 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006282}
6283
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006284void bnx2x_set_eth_mac_addr_e1h(struct bnx2x *bp, int set)
Michael Chane665bfd2009-10-10 13:46:54 +00006285{
6286 bp->set_mac_pending++;
6287 smp_wmb();
6288
6289 bnx2x_set_mac_addr_e1h_gen(bp, set, bp->dev->dev_addr,
6290 (1 << bp->fp->cl_id), BP_FUNC(bp));
6291
6292 /* Wait for a completion */
6293 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
6294}
6295
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006296void bnx2x_set_eth_mac_addr_e1(struct bnx2x *bp, int set)
Michael Chane665bfd2009-10-10 13:46:54 +00006297{
6298 bp->set_mac_pending++;
6299 smp_wmb();
6300
6301 bnx2x_set_mac_addr_e1_gen(bp, set, bp->dev->dev_addr,
6302 (1 << bp->fp->cl_id), (BP_PORT(bp) ? 32 : 0),
6303 1);
6304
6305 /* Wait for a completion */
6306 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
6307}
6308
Michael Chan993ac7b2009-10-10 13:46:56 +00006309#ifdef BCM_CNIC
6310/**
6311 * Set iSCSI MAC(s) at the next enties in the CAM after the ETH
6312 * MAC(s). This function will wait until the ramdord completion
6313 * returns.
6314 *
6315 * @param bp driver handle
6316 * @param set set or clear the CAM entry
6317 *
6318 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
6319 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006320int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set)
Michael Chan993ac7b2009-10-10 13:46:56 +00006321{
6322 u32 cl_bit_vec = (1 << BCM_ISCSI_ETH_CL_ID);
6323
6324 bp->set_mac_pending++;
6325 smp_wmb();
6326
6327 /* Send a SET_MAC ramrod */
6328 if (CHIP_IS_E1(bp))
6329 bnx2x_set_mac_addr_e1_gen(bp, set, bp->iscsi_mac,
6330 cl_bit_vec, (BP_PORT(bp) ? 32 : 0) + 2,
6331 1);
6332 else
6333 /* CAM allocation for E1H
6334 * unicasts: by func number
6335 * multicast: 20+FUNC*20, 20 each
6336 */
6337 bnx2x_set_mac_addr_e1h_gen(bp, set, bp->iscsi_mac,
6338 cl_bit_vec, E1H_FUNC_MAX + BP_FUNC(bp));
6339
6340 /* Wait for a completion when setting */
6341 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
6342
6343 return 0;
6344}
6345#endif
6346
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006347int bnx2x_setup_leading(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006348{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006349 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006350
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006351 /* reset IGU state */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006352 bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006353
6354 /* SETUP ramrod */
6355 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
6356
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006357 /* Wait for completion */
6358 rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006359
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006360 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006361}
6362
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006363int bnx2x_setup_multi(struct bnx2x *bp, int index)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006364{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006365 struct bnx2x_fastpath *fp = &bp->fp[index];
6366
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006367 /* reset IGU state */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006368 bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006369
Eliezer Tamir228241e2008-02-28 11:56:57 -08006370 /* SETUP ramrod */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006371 fp->state = BNX2X_FP_STATE_OPENING;
6372 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
6373 fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006374
6375 /* Wait for completion */
6376 return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006377 &(fp->state), 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006378}
6379
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006380
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006381void bnx2x_set_num_queues_msix(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006382{
Eilon Greensteinca003922009-08-12 22:53:28 -07006383
6384 switch (bp->multi_mode) {
6385 case ETH_RSS_MODE_DISABLED:
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006386 bp->num_queues = 1;
Eilon Greensteinca003922009-08-12 22:53:28 -07006387 break;
6388
6389 case ETH_RSS_MODE_REGULAR:
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006390 if (num_queues)
6391 bp->num_queues = min_t(u32, num_queues,
6392 BNX2X_MAX_QUEUES(bp));
Eilon Greensteinca003922009-08-12 22:53:28 -07006393 else
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006394 bp->num_queues = min_t(u32, num_online_cpus(),
6395 BNX2X_MAX_QUEUES(bp));
Eilon Greensteinca003922009-08-12 22:53:28 -07006396 break;
6397
6398
6399 default:
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006400 bp->num_queues = 1;
Eilon Greensteinca003922009-08-12 22:53:28 -07006401 break;
6402 }
Eilon Greensteinca003922009-08-12 22:53:28 -07006403}
6404
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006405
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006406
6407static int bnx2x_stop_multi(struct bnx2x *bp, int index)
6408{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006409 struct bnx2x_fastpath *fp = &bp->fp[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006410 int rc;
6411
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006412 /* halt the connection */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006413 fp->state = BNX2X_FP_STATE_HALTING;
6414 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006415
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006416 /* Wait for completion */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006417 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006418 &(fp->state), 1);
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006419 if (rc) /* timeout */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006420 return rc;
6421
6422 /* delete cfc entry */
6423 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
6424
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006425 /* Wait for completion */
6426 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006427 &(fp->state), 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006428 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006429}
6430
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006431static int bnx2x_stop_leading(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006432{
Eilon Greenstein4781bfa2009-02-12 08:38:17 +00006433 __le16 dsb_sp_prod_idx;
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006434 /* if the other port is handling traffic,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006435 this can take a lot of time */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006436 int cnt = 500;
6437 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006438
6439 might_sleep();
6440
6441 /* Send HALT ramrod */
6442 bp->fp[0].state = BNX2X_FP_STATE_HALTING;
Eilon Greenstein0626b892009-02-12 08:38:14 +00006443 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006444
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006445 /* Wait for completion */
6446 rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
6447 &(bp->fp[0].state), 1);
6448 if (rc) /* timeout */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006449 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006450
Eliezer Tamir49d66772008-02-28 11:53:13 -08006451 dsb_sp_prod_idx = *bp->dsb_sp_prod;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006452
Eliezer Tamir228241e2008-02-28 11:56:57 -08006453 /* Send PORT_DELETE ramrod */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006454 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
6455
Eliezer Tamir49d66772008-02-28 11:53:13 -08006456 /* Wait for completion to arrive on default status block
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006457 we are going to reset the chip anyway
6458 so there is not much to do if this times out
6459 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006460 while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006461 if (!cnt) {
6462 DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
6463 "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
6464 *bp->dsb_sp_prod, dsb_sp_prod_idx);
6465#ifdef BNX2X_STOP_ON_ERROR
6466 bnx2x_panic();
6467#endif
Eilon Greenstein36e552a2009-02-12 08:37:21 +00006468 rc = -EBUSY;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006469 break;
6470 }
6471 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006472 msleep(1);
Eilon Greenstein5650d9d2009-01-22 06:01:29 +00006473 rmb(); /* Refresh the dsb_sp_prod */
Eliezer Tamir49d66772008-02-28 11:53:13 -08006474 }
6475 bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
6476 bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006477
6478 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006479}
6480
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006481static void bnx2x_reset_func(struct bnx2x *bp)
6482{
6483 int port = BP_PORT(bp);
6484 int func = BP_FUNC(bp);
6485 int base, i;
Eliezer Tamir49d66772008-02-28 11:53:13 -08006486
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006487 /* Configure IGU */
6488 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6489 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6490
Michael Chan37b091b2009-10-10 13:46:55 +00006491#ifdef BCM_CNIC
6492 /* Disable Timer scan */
6493 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
6494 /*
6495 * Wait for at least 10ms and up to 2 second for the timers scan to
6496 * complete
6497 */
6498 for (i = 0; i < 200; i++) {
6499 msleep(10);
6500 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
6501 break;
6502 }
6503#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006504 /* Clear ILT */
6505 base = FUNC_ILT_BASE(func);
6506 for (i = base; i < base + ILT_PER_FUNC; i++)
6507 bnx2x_ilt_wr(bp, i, 0);
6508}
6509
6510static void bnx2x_reset_port(struct bnx2x *bp)
6511{
6512 int port = BP_PORT(bp);
6513 u32 val;
6514
6515 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6516
6517 /* Do not rcv packets to BRB */
6518 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
6519 /* Do not direct rcv packets that are not for MCP to the BRB */
6520 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
6521 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
6522
6523 /* Configure AEU */
6524 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
6525
6526 msleep(100);
6527 /* Check for BRB port occupancy */
6528 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
6529 if (val)
6530 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07006531 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006532
6533 /* TODO: Close Doorbell port? */
6534}
6535
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006536static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
6537{
6538 DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
6539 BP_FUNC(bp), reset_code);
6540
6541 switch (reset_code) {
6542 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
6543 bnx2x_reset_port(bp);
6544 bnx2x_reset_func(bp);
6545 bnx2x_reset_common(bp);
6546 break;
6547
6548 case FW_MSG_CODE_DRV_UNLOAD_PORT:
6549 bnx2x_reset_port(bp);
6550 bnx2x_reset_func(bp);
6551 break;
6552
6553 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
6554 bnx2x_reset_func(bp);
6555 break;
6556
6557 default:
6558 BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
6559 break;
6560 }
6561}
6562
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006563void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006564{
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006565 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006566 u32 reset_code = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006567 int i, cnt, rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006568
Eilon Greenstein555f6c72009-02-12 08:36:11 +00006569 /* Wait until tx fastpath tasks complete */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00006570 for_each_queue(bp, i) {
Eliezer Tamir228241e2008-02-28 11:56:57 -08006571 struct bnx2x_fastpath *fp = &bp->fp[i];
6572
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006573 cnt = 1000;
Vladislav Zolotarove8b5fc52009-01-26 12:36:42 -08006574 while (bnx2x_has_tx_work_unload(fp)) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006575
Eilon Greenstein7961f792009-03-02 07:59:31 +00006576 bnx2x_tx_int(fp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006577 if (!cnt) {
6578 BNX2X_ERR("timeout waiting for queue[%d]\n",
6579 i);
6580#ifdef BNX2X_STOP_ON_ERROR
6581 bnx2x_panic();
6582 return -EBUSY;
6583#else
6584 break;
6585#endif
6586 }
6587 cnt--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006588 msleep(1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006589 }
Eliezer Tamir228241e2008-02-28 11:56:57 -08006590 }
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006591 /* Give HW time to discard old tx messages */
6592 msleep(1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006593
Yitchak Gertner65abd742008-08-25 15:26:24 -07006594 if (CHIP_IS_E1(bp)) {
6595 struct mac_configuration_cmd *config =
6596 bnx2x_sp(bp, mcast_config);
6597
Michael Chane665bfd2009-10-10 13:46:54 +00006598 bnx2x_set_eth_mac_addr_e1(bp, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006599
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006600 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertner65abd742008-08-25 15:26:24 -07006601 CAM_INVALIDATE(config->config_table[i]);
6602
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006603 config->hdr.length = i;
Yitchak Gertner65abd742008-08-25 15:26:24 -07006604 if (CHIP_REV_IS_SLOW(bp))
6605 config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
6606 else
6607 config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
Eilon Greenstein0626b892009-02-12 08:38:14 +00006608 config->hdr.client_id = bp->fp->cl_id;
Yitchak Gertner65abd742008-08-25 15:26:24 -07006609 config->hdr.reserved1 = 0;
6610
Michael Chane665bfd2009-10-10 13:46:54 +00006611 bp->set_mac_pending++;
6612 smp_wmb();
6613
Yitchak Gertner65abd742008-08-25 15:26:24 -07006614 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
6615 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
6616 U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
6617
6618 } else { /* E1H */
6619 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
6620
Michael Chane665bfd2009-10-10 13:46:54 +00006621 bnx2x_set_eth_mac_addr_e1h(bp, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006622
6623 for (i = 0; i < MC_HASH_SIZE; i++)
6624 REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00006625
6626 REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
Yitchak Gertner65abd742008-08-25 15:26:24 -07006627 }
Michael Chan993ac7b2009-10-10 13:46:56 +00006628#ifdef BCM_CNIC
6629 /* Clear iSCSI L2 MAC */
6630 mutex_lock(&bp->cnic_mutex);
6631 if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
6632 bnx2x_set_iscsi_eth_mac_addr(bp, 0);
6633 bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
6634 }
6635 mutex_unlock(&bp->cnic_mutex);
6636#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07006637
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006638 if (unload_mode == UNLOAD_NORMAL)
6639 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08006640
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00006641 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006642 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006643
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00006644 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006645 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006646 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006647 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006648 /* The mac address is written to entries 1-4 to
6649 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006650 u8 entry = (BP_E1HVN(bp) + 1)*8;
6651
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006652 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07006653 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006654
6655 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
6656 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07006657 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006658
6659 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08006660
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006661 } else
6662 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
6663
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006664 /* Close multi and leading connections
6665 Completions for ramrods are collected in a synchronous way */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006666 for_each_nondefault_queue(bp, i)
6667 if (bnx2x_stop_multi(bp, i))
Eliezer Tamir228241e2008-02-28 11:56:57 -08006668 goto unload_error;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006669
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006670 rc = bnx2x_stop_leading(bp);
6671 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006672 BNX2X_ERR("Stop leading failed!\n");
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006673#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006674 return -EBUSY;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006675#else
6676 goto unload_error;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006677#endif
Eliezer Tamir228241e2008-02-28 11:56:57 -08006678 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006679
Eliezer Tamir228241e2008-02-28 11:56:57 -08006680unload_error:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006681 if (!BP_NOMCP(bp))
Eliezer Tamir228241e2008-02-28 11:56:57 -08006682 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006683 else {
Eilon Greensteinf5372252009-02-12 08:38:30 +00006684 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006685 load_count[0], load_count[1], load_count[2]);
6686 load_count[0]--;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006687 load_count[1 + port]--;
Eilon Greensteinf5372252009-02-12 08:38:30 +00006688 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006689 load_count[0], load_count[1], load_count[2]);
6690 if (load_count[0] == 0)
6691 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07006692 else if (load_count[1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006693 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
6694 else
6695 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
6696 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006697
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006698 if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
6699 (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
6700 bnx2x__link_reset(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006701
6702 /* Reset the chip */
Eliezer Tamir228241e2008-02-28 11:56:57 -08006703 bnx2x_reset_chip(bp, reset_code);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006704
6705 /* Report UNLOAD_DONE to MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006706 if (!BP_NOMCP(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006707 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006708
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00006709}
6710
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006711void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00006712{
6713 u32 val;
6714
6715 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
6716
6717 if (CHIP_IS_E1(bp)) {
6718 int port = BP_PORT(bp);
6719 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
6720 MISC_REG_AEU_MASK_ATTN_FUNC_0;
6721
6722 val = REG_RD(bp, addr);
6723 val &= ~(0x300);
6724 REG_WR(bp, addr, val);
6725 } else if (CHIP_IS_E1H(bp)) {
6726 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
6727 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
6728 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
6729 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
6730 }
6731}
6732
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006733
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00006734/* Close gates #2, #3 and #4: */
6735static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
6736{
6737 u32 val, addr;
6738
6739 /* Gates #2 and #4a are closed/opened for "not E1" only */
6740 if (!CHIP_IS_E1(bp)) {
6741 /* #4 */
6742 val = REG_RD(bp, PXP_REG_HST_DISCARD_DOORBELLS);
6743 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS,
6744 close ? (val | 0x1) : (val & (~(u32)1)));
6745 /* #2 */
6746 val = REG_RD(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES);
6747 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES,
6748 close ? (val | 0x1) : (val & (~(u32)1)));
6749 }
6750
6751 /* #3 */
6752 addr = BP_PORT(bp) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
6753 val = REG_RD(bp, addr);
6754 REG_WR(bp, addr, (!close) ? (val | 0x1) : (val & (~(u32)1)));
6755
6756 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
6757 close ? "closing" : "opening");
6758 mmiowb();
6759}
6760
6761#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
6762
6763static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
6764{
6765 /* Do some magic... */
6766 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
6767 *magic_val = val & SHARED_MF_CLP_MAGIC;
6768 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
6769}
6770
6771/* Restore the value of the `magic' bit.
6772 *
6773 * @param pdev Device handle.
6774 * @param magic_val Old value of the `magic' bit.
6775 */
6776static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
6777{
6778 /* Restore the `magic' bit value... */
6779 /* u32 val = SHMEM_RD(bp, mf_cfg.shared_mf_config.clp_mb);
6780 SHMEM_WR(bp, mf_cfg.shared_mf_config.clp_mb,
6781 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); */
6782 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
6783 MF_CFG_WR(bp, shared_mf_config.clp_mb,
6784 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
6785}
6786
6787/* Prepares for MCP reset: takes care of CLP configurations.
6788 *
6789 * @param bp
6790 * @param magic_val Old value of 'magic' bit.
6791 */
6792static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
6793{
6794 u32 shmem;
6795 u32 validity_offset;
6796
6797 DP(NETIF_MSG_HW, "Starting\n");
6798
6799 /* Set `magic' bit in order to save MF config */
6800 if (!CHIP_IS_E1(bp))
6801 bnx2x_clp_reset_prep(bp, magic_val);
6802
6803 /* Get shmem offset */
6804 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
6805 validity_offset = offsetof(struct shmem_region, validity_map[0]);
6806
6807 /* Clear validity map flags */
6808 if (shmem > 0)
6809 REG_WR(bp, shmem + validity_offset, 0);
6810}
6811
6812#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
6813#define MCP_ONE_TIMEOUT 100 /* 100 ms */
6814
6815/* Waits for MCP_ONE_TIMEOUT or MCP_ONE_TIMEOUT*10,
6816 * depending on the HW type.
6817 *
6818 * @param bp
6819 */
6820static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
6821{
6822 /* special handling for emulation and FPGA,
6823 wait 10 times longer */
6824 if (CHIP_REV_IS_SLOW(bp))
6825 msleep(MCP_ONE_TIMEOUT*10);
6826 else
6827 msleep(MCP_ONE_TIMEOUT);
6828}
6829
6830static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
6831{
6832 u32 shmem, cnt, validity_offset, val;
6833 int rc = 0;
6834
6835 msleep(100);
6836
6837 /* Get shmem offset */
6838 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
6839 if (shmem == 0) {
6840 BNX2X_ERR("Shmem 0 return failure\n");
6841 rc = -ENOTTY;
6842 goto exit_lbl;
6843 }
6844
6845 validity_offset = offsetof(struct shmem_region, validity_map[0]);
6846
6847 /* Wait for MCP to come up */
6848 for (cnt = 0; cnt < (MCP_TIMEOUT / MCP_ONE_TIMEOUT); cnt++) {
6849 /* TBD: its best to check validity map of last port.
6850 * currently checks on port 0.
6851 */
6852 val = REG_RD(bp, shmem + validity_offset);
6853 DP(NETIF_MSG_HW, "shmem 0x%x validity map(0x%x)=0x%x\n", shmem,
6854 shmem + validity_offset, val);
6855
6856 /* check that shared memory is valid. */
6857 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
6858 == (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
6859 break;
6860
6861 bnx2x_mcp_wait_one(bp);
6862 }
6863
6864 DP(NETIF_MSG_HW, "Cnt=%d Shmem validity map 0x%x\n", cnt, val);
6865
6866 /* Check that shared memory is valid. This indicates that MCP is up. */
6867 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
6868 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
6869 BNX2X_ERR("Shmem signature not present. MCP is not up !!\n");
6870 rc = -ENOTTY;
6871 goto exit_lbl;
6872 }
6873
6874exit_lbl:
6875 /* Restore the `magic' bit value */
6876 if (!CHIP_IS_E1(bp))
6877 bnx2x_clp_reset_done(bp, magic_val);
6878
6879 return rc;
6880}
6881
6882static void bnx2x_pxp_prep(struct bnx2x *bp)
6883{
6884 if (!CHIP_IS_E1(bp)) {
6885 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
6886 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
6887 REG_WR(bp, PXP2_REG_RQ_CFG_DONE, 0);
6888 mmiowb();
6889 }
6890}
6891
6892/*
6893 * Reset the whole chip except for:
6894 * - PCIE core
6895 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
6896 * one reset bit)
6897 * - IGU
6898 * - MISC (including AEU)
6899 * - GRC
6900 * - RBCN, RBCP
6901 */
6902static void bnx2x_process_kill_chip_reset(struct bnx2x *bp)
6903{
6904 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
6905
6906 not_reset_mask1 =
6907 MISC_REGISTERS_RESET_REG_1_RST_HC |
6908 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
6909 MISC_REGISTERS_RESET_REG_1_RST_PXP;
6910
6911 not_reset_mask2 =
6912 MISC_REGISTERS_RESET_REG_2_RST_MDIO |
6913 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
6914 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
6915 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
6916 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
6917 MISC_REGISTERS_RESET_REG_2_RST_GRC |
6918 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
6919 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
6920
6921 reset_mask1 = 0xffffffff;
6922
6923 if (CHIP_IS_E1(bp))
6924 reset_mask2 = 0xffff;
6925 else
6926 reset_mask2 = 0x1ffff;
6927
6928 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6929 reset_mask1 & (~not_reset_mask1));
6930 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
6931 reset_mask2 & (~not_reset_mask2));
6932
6933 barrier();
6934 mmiowb();
6935
6936 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
6937 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
6938 mmiowb();
6939}
6940
6941static int bnx2x_process_kill(struct bnx2x *bp)
6942{
6943 int cnt = 1000;
6944 u32 val = 0;
6945 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
6946
6947
6948 /* Empty the Tetris buffer, wait for 1s */
6949 do {
6950 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
6951 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
6952 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
6953 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
6954 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
6955 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
6956 ((port_is_idle_0 & 0x1) == 0x1) &&
6957 ((port_is_idle_1 & 0x1) == 0x1) &&
6958 (pgl_exp_rom2 == 0xffffffff))
6959 break;
6960 msleep(1);
6961 } while (cnt-- > 0);
6962
6963 if (cnt <= 0) {
6964 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
6965 " are still"
6966 " outstanding read requests after 1s!\n");
6967 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
6968 " port_is_idle_0=0x%08x,"
6969 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
6970 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
6971 pgl_exp_rom2);
6972 return -EAGAIN;
6973 }
6974
6975 barrier();
6976
6977 /* Close gates #2, #3 and #4 */
6978 bnx2x_set_234_gates(bp, true);
6979
6980 /* TBD: Indicate that "process kill" is in progress to MCP */
6981
6982 /* Clear "unprepared" bit */
6983 REG_WR(bp, MISC_REG_UNPREPARED, 0);
6984 barrier();
6985
6986 /* Make sure all is written to the chip before the reset */
6987 mmiowb();
6988
6989 /* Wait for 1ms to empty GLUE and PCI-E core queues,
6990 * PSWHST, GRC and PSWRD Tetris buffer.
6991 */
6992 msleep(1);
6993
6994 /* Prepare to chip reset: */
6995 /* MCP */
6996 bnx2x_reset_mcp_prep(bp, &val);
6997
6998 /* PXP */
6999 bnx2x_pxp_prep(bp);
7000 barrier();
7001
7002 /* reset the chip */
7003 bnx2x_process_kill_chip_reset(bp);
7004 barrier();
7005
7006 /* Recover after reset: */
7007 /* MCP */
7008 if (bnx2x_reset_mcp_comp(bp, val))
7009 return -EAGAIN;
7010
7011 /* PXP */
7012 bnx2x_pxp_prep(bp);
7013
7014 /* Open the gates #2, #3 and #4 */
7015 bnx2x_set_234_gates(bp, false);
7016
7017 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
7018 * reset state, re-enable attentions. */
7019
7020 return 0;
7021}
7022
7023static int bnx2x_leader_reset(struct bnx2x *bp)
7024{
7025 int rc = 0;
7026 /* Try to recover after the failure */
7027 if (bnx2x_process_kill(bp)) {
7028 printk(KERN_ERR "%s: Something bad had happen! Aii!\n",
7029 bp->dev->name);
7030 rc = -EAGAIN;
7031 goto exit_leader_reset;
7032 }
7033
7034 /* Clear "reset is in progress" bit and update the driver state */
7035 bnx2x_set_reset_done(bp);
7036 bp->recovery_state = BNX2X_RECOVERY_DONE;
7037
7038exit_leader_reset:
7039 bp->is_leader = 0;
7040 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESERVED_08);
7041 smp_wmb();
7042 return rc;
7043}
7044
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007045/* Assumption: runs under rtnl lock. This together with the fact
7046 * that it's called only from bnx2x_reset_task() ensure that it
7047 * will never be called when netif_running(bp->dev) is false.
7048 */
7049static void bnx2x_parity_recover(struct bnx2x *bp)
7050{
7051 DP(NETIF_MSG_HW, "Handling parity\n");
7052 while (1) {
7053 switch (bp->recovery_state) {
7054 case BNX2X_RECOVERY_INIT:
7055 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
7056 /* Try to get a LEADER_LOCK HW lock */
7057 if (bnx2x_trylock_hw_lock(bp,
7058 HW_LOCK_RESOURCE_RESERVED_08))
7059 bp->is_leader = 1;
7060
7061 /* Stop the driver */
7062 /* If interface has been removed - break */
7063 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
7064 return;
7065
7066 bp->recovery_state = BNX2X_RECOVERY_WAIT;
7067 /* Ensure "is_leader" and "recovery_state"
7068 * update values are seen on other CPUs
7069 */
7070 smp_wmb();
7071 break;
7072
7073 case BNX2X_RECOVERY_WAIT:
7074 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
7075 if (bp->is_leader) {
7076 u32 load_counter = bnx2x_get_load_cnt(bp);
7077 if (load_counter) {
7078 /* Wait until all other functions get
7079 * down.
7080 */
7081 schedule_delayed_work(&bp->reset_task,
7082 HZ/10);
7083 return;
7084 } else {
7085 /* If all other functions got down -
7086 * try to bring the chip back to
7087 * normal. In any case it's an exit
7088 * point for a leader.
7089 */
7090 if (bnx2x_leader_reset(bp) ||
7091 bnx2x_nic_load(bp, LOAD_NORMAL)) {
7092 printk(KERN_ERR"%s: Recovery "
7093 "has failed. Power cycle is "
7094 "needed.\n", bp->dev->name);
7095 /* Disconnect this device */
7096 netif_device_detach(bp->dev);
7097 /* Block ifup for all function
7098 * of this ASIC until
7099 * "process kill" or power
7100 * cycle.
7101 */
7102 bnx2x_set_reset_in_progress(bp);
7103 /* Shut down the power */
7104 bnx2x_set_power_state(bp,
7105 PCI_D3hot);
7106 return;
7107 }
7108
7109 return;
7110 }
7111 } else { /* non-leader */
7112 if (!bnx2x_reset_is_done(bp)) {
7113 /* Try to get a LEADER_LOCK HW lock as
7114 * long as a former leader may have
7115 * been unloaded by the user or
7116 * released a leadership by another
7117 * reason.
7118 */
7119 if (bnx2x_trylock_hw_lock(bp,
7120 HW_LOCK_RESOURCE_RESERVED_08)) {
7121 /* I'm a leader now! Restart a
7122 * switch case.
7123 */
7124 bp->is_leader = 1;
7125 break;
7126 }
7127
7128 schedule_delayed_work(&bp->reset_task,
7129 HZ/10);
7130 return;
7131
7132 } else { /* A leader has completed
7133 * the "process kill". It's an exit
7134 * point for a non-leader.
7135 */
7136 bnx2x_nic_load(bp, LOAD_NORMAL);
7137 bp->recovery_state =
7138 BNX2X_RECOVERY_DONE;
7139 smp_wmb();
7140 return;
7141 }
7142 }
7143 default:
7144 return;
7145 }
7146 }
7147}
7148
7149/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
7150 * scheduled on a general queue in order to prevent a dead lock.
7151 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007152static void bnx2x_reset_task(struct work_struct *work)
7153{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007154 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007155
7156#ifdef BNX2X_STOP_ON_ERROR
7157 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7158 " so reset not done to allow debug dump,\n"
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007159 KERN_ERR " you will need to reboot when done\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007160 return;
7161#endif
7162
7163 rtnl_lock();
7164
7165 if (!netif_running(bp->dev))
7166 goto reset_task_exit;
7167
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007168 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
7169 bnx2x_parity_recover(bp);
7170 else {
7171 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7172 bnx2x_nic_load(bp, LOAD_NORMAL);
7173 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007174
7175reset_task_exit:
7176 rtnl_unlock();
7177}
7178
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007179/* end of nic load/unload */
7180
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007181/*
7182 * Init service functions
7183 */
7184
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007185static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
7186{
7187 switch (func) {
7188 case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
7189 case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
7190 case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
7191 case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
7192 case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
7193 case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
7194 case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
7195 case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
7196 default:
7197 BNX2X_ERR("Unsupported function index: %d\n", func);
7198 return (u32)(-1);
7199 }
7200}
7201
7202static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
7203{
7204 u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
7205
7206 /* Flush all outstanding writes */
7207 mmiowb();
7208
7209 /* Pretend to be function 0 */
7210 REG_WR(bp, reg, 0);
7211 /* Flush the GRC transaction (in the chip) */
7212 new_val = REG_RD(bp, reg);
7213 if (new_val != 0) {
7214 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
7215 new_val);
7216 BUG();
7217 }
7218
7219 /* From now we are in the "like-E1" mode */
7220 bnx2x_int_disable(bp);
7221
7222 /* Flush all outstanding writes */
7223 mmiowb();
7224
7225 /* Restore the original funtion settings */
7226 REG_WR(bp, reg, orig_func);
7227 new_val = REG_RD(bp, reg);
7228 if (new_val != orig_func) {
7229 BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
7230 orig_func, new_val);
7231 BUG();
7232 }
7233}
7234
7235static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
7236{
7237 if (CHIP_IS_E1H(bp))
7238 bnx2x_undi_int_disable_e1h(bp, func);
7239 else
7240 bnx2x_int_disable(bp);
7241}
7242
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007243static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007244{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007245 u32 val;
7246
7247 /* Check if there is any driver already loaded */
7248 val = REG_RD(bp, MISC_REG_UNPREPARED);
7249 if (val == 0x1) {
7250 /* Check if it is the UNDI driver
7251 * UNDI driver initializes CID offset for normal bell to 0x7
7252 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07007253 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007254 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
7255 if (val == 0x7) {
7256 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007257 /* save our func */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007258 int func = BP_FUNC(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007259 u32 swap_en;
7260 u32 swap_val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007261
Eilon Greensteinb4661732009-01-14 06:43:56 +00007262 /* clear the UNDI indication */
7263 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
7264
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007265 BNX2X_DEV_INFO("UNDI is active! reset device\n");
7266
7267 /* try unload UNDI on port 0 */
7268 bp->func = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007269 bp->fw_seq =
7270 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7271 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007272 reset_code = bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007273
7274 /* if UNDI is loaded on the other port */
7275 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
7276
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007277 /* send "DONE" for previous unload */
7278 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7279
7280 /* unload UNDI on port 1 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007281 bp->func = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007282 bp->fw_seq =
7283 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7284 DRV_MSG_SEQ_NUMBER_MASK);
7285 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007286
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007287 bnx2x_fw_command(bp, reset_code);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007288 }
7289
Eilon Greensteinb4661732009-01-14 06:43:56 +00007290 /* now it's safe to release the lock */
7291 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
7292
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00007293 bnx2x_undi_int_disable(bp, func);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007294
7295 /* close input traffic and wait for it */
7296 /* Do not rcv packets to BRB */
7297 REG_WR(bp,
7298 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
7299 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
7300 /* Do not direct rcv packets that are not for MCP to
7301 * the BRB */
7302 REG_WR(bp,
7303 (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
7304 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7305 /* clear AEU */
7306 REG_WR(bp,
7307 (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7308 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
7309 msleep(10);
7310
7311 /* save NIG port swap info */
7312 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7313 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007314 /* reset device */
7315 REG_WR(bp,
7316 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007317 0xd3ffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007318 REG_WR(bp,
7319 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7320 0x1403);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007321 /* take the NIG out of reset and restore swap values */
7322 REG_WR(bp,
7323 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7324 MISC_REGISTERS_RESET_REG_1_RST_NIG);
7325 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
7326 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
7327
7328 /* send unload done to the MCP */
7329 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
7330
7331 /* restore our func and fw_seq */
7332 bp->func = func;
7333 bp->fw_seq =
7334 (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
7335 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00007336
7337 } else
7338 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007339 }
7340}
7341
7342static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
7343{
7344 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007345 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007346
7347 /* Get the chip revision id and number. */
7348 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
7349 val = REG_RD(bp, MISC_REG_CHIP_NUM);
7350 id = ((val & 0xffff) << 16);
7351 val = REG_RD(bp, MISC_REG_CHIP_REV);
7352 id |= ((val & 0xf) << 12);
7353 val = REG_RD(bp, MISC_REG_CHIP_METAL);
7354 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00007355 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007356 id |= (val & 0xf);
7357 bp->common.chip_id = id;
7358 bp->link_params.chip_id = bp->common.chip_id;
7359 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
7360
Eilon Greenstein1c063282009-02-12 08:36:43 +00007361 val = (REG_RD(bp, 0x2874) & 0x55);
7362 if ((bp->common.chip_id & 0x1) ||
7363 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
7364 bp->flags |= ONE_PORT_FLAG;
7365 BNX2X_DEV_INFO("single port device\n");
7366 }
7367
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007368 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
7369 bp->common.flash_size = (NVRAM_1MB_SIZE <<
7370 (val & MCPR_NVM_CFG4_FLASH_SIZE));
7371 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
7372 bp->common.flash_size, bp->common.flash_size);
7373
7374 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
Eilon Greenstein2691d512009-08-12 08:22:08 +00007375 bp->common.shmem2_base = REG_RD(bp, MISC_REG_GENERIC_CR_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007376 bp->link_params.shmem_base = bp->common.shmem_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +00007377 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
7378 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007379
7380 if (!bp->common.shmem_base ||
7381 (bp->common.shmem_base < 0xA0000) ||
7382 (bp->common.shmem_base >= 0xC0000)) {
7383 BNX2X_DEV_INFO("MCP not active\n");
7384 bp->flags |= NO_MCP_FLAG;
7385 return;
7386 }
7387
7388 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7389 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
7390 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007391 BNX2X_ERROR("BAD MCP validity signature\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007392
7393 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00007394 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007395
7396 bp->link_params.hw_led_mode = ((bp->common.hw_config &
7397 SHARED_HW_CFG_LED_MODE_MASK) >>
7398 SHARED_HW_CFG_LED_MODE_SHIFT);
7399
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007400 bp->link_params.feature_config_flags = 0;
7401 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
7402 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
7403 bp->link_params.feature_config_flags |=
7404 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7405 else
7406 bp->link_params.feature_config_flags &=
7407 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
7408
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007409 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
7410 bp->common.bc_ver = val;
7411 BNX2X_DEV_INFO("bc_ver %X\n", val);
7412 if (val < BNX2X_BC_VER) {
7413 /* for now only warn
7414 * later we might need to enforce this */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007415 BNX2X_ERROR("This driver needs bc_ver %X but found %X, "
7416 "please upgrade BC\n", BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007417 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007418 bp->link_params.feature_config_flags |=
7419 (val >= REQ_BC_VER_4_VRFY_OPT_MDL) ?
7420 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07007421
7422 if (BP_E1HVN(bp) == 0) {
7423 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
7424 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
7425 } else {
7426 /* no WOL capability for E1HVN != 0 */
7427 bp->flags |= NO_WOL_FLAG;
7428 }
7429 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +00007430 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007431
7432 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
7433 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
7434 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
7435 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
7436
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007437 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
7438 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007439}
7440
7441static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
7442 u32 switch_cfg)
7443{
7444 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007445 u32 ext_phy_type;
7446
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007447 switch (switch_cfg) {
7448 case SWITCH_CFG_1G:
7449 BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
7450
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007451 ext_phy_type =
7452 SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007453 switch (ext_phy_type) {
7454 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
7455 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7456 ext_phy_type);
7457
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007458 bp->port.supported |= (SUPPORTED_10baseT_Half |
7459 SUPPORTED_10baseT_Full |
7460 SUPPORTED_100baseT_Half |
7461 SUPPORTED_100baseT_Full |
7462 SUPPORTED_1000baseT_Full |
7463 SUPPORTED_2500baseX_Full |
7464 SUPPORTED_TP |
7465 SUPPORTED_FIBRE |
7466 SUPPORTED_Autoneg |
7467 SUPPORTED_Pause |
7468 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007469 break;
7470
7471 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
7472 BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
7473 ext_phy_type);
7474
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007475 bp->port.supported |= (SUPPORTED_10baseT_Half |
7476 SUPPORTED_10baseT_Full |
7477 SUPPORTED_100baseT_Half |
7478 SUPPORTED_100baseT_Full |
7479 SUPPORTED_1000baseT_Full |
7480 SUPPORTED_TP |
7481 SUPPORTED_FIBRE |
7482 SUPPORTED_Autoneg |
7483 SUPPORTED_Pause |
7484 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007485 break;
7486
7487 default:
7488 BNX2X_ERR("NVRAM config error. "
7489 "BAD SerDes ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007490 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007491 return;
7492 }
7493
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007494 bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
7495 port*0x10);
7496 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007497 break;
7498
7499 case SWITCH_CFG_10G:
7500 BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
7501
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007502 ext_phy_type =
7503 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007504 switch (ext_phy_type) {
7505 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7506 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
7507 ext_phy_type);
7508
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007509 bp->port.supported |= (SUPPORTED_10baseT_Half |
7510 SUPPORTED_10baseT_Full |
7511 SUPPORTED_100baseT_Half |
7512 SUPPORTED_100baseT_Full |
7513 SUPPORTED_1000baseT_Full |
7514 SUPPORTED_2500baseX_Full |
7515 SUPPORTED_10000baseT_Full |
7516 SUPPORTED_TP |
7517 SUPPORTED_FIBRE |
7518 SUPPORTED_Autoneg |
7519 SUPPORTED_Pause |
7520 SUPPORTED_Asym_Pause);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007521 break;
7522
Eliezer Tamirf1410642008-02-28 11:51:50 -08007523 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
7524 BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
7525 ext_phy_type);
7526
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007527 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7528 SUPPORTED_1000baseT_Full |
7529 SUPPORTED_FIBRE |
7530 SUPPORTED_Autoneg |
7531 SUPPORTED_Pause |
7532 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007533 break;
7534
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007535 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
7536 BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
7537 ext_phy_type);
7538
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007539 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7540 SUPPORTED_2500baseX_Full |
7541 SUPPORTED_1000baseT_Full |
7542 SUPPORTED_FIBRE |
7543 SUPPORTED_Autoneg |
7544 SUPPORTED_Pause |
7545 SUPPORTED_Asym_Pause);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007546 break;
7547
Eilon Greenstein589abe32009-02-12 08:36:55 +00007548 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7549 BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
7550 ext_phy_type);
7551
7552 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7553 SUPPORTED_FIBRE |
7554 SUPPORTED_Pause |
7555 SUPPORTED_Asym_Pause);
7556 break;
7557
7558 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7559 BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
7560 ext_phy_type);
7561
7562 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7563 SUPPORTED_1000baseT_Full |
7564 SUPPORTED_FIBRE |
7565 SUPPORTED_Pause |
7566 SUPPORTED_Asym_Pause);
7567 break;
7568
7569 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7570 BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
7571 ext_phy_type);
7572
7573 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7574 SUPPORTED_1000baseT_Full |
7575 SUPPORTED_Autoneg |
7576 SUPPORTED_FIBRE |
7577 SUPPORTED_Pause |
7578 SUPPORTED_Asym_Pause);
7579 break;
7580
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007581 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
7582 BNX2X_DEV_INFO("ext_phy_type 0x%x (8727)\n",
7583 ext_phy_type);
7584
7585 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7586 SUPPORTED_1000baseT_Full |
7587 SUPPORTED_Autoneg |
7588 SUPPORTED_FIBRE |
7589 SUPPORTED_Pause |
7590 SUPPORTED_Asym_Pause);
7591 break;
7592
Eliezer Tamirf1410642008-02-28 11:51:50 -08007593 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7594 BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
7595 ext_phy_type);
7596
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007597 bp->port.supported |= (SUPPORTED_10000baseT_Full |
7598 SUPPORTED_TP |
7599 SUPPORTED_Autoneg |
7600 SUPPORTED_Pause |
7601 SUPPORTED_Asym_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007602 break;
7603
Eilon Greenstein28577182009-02-12 08:37:00 +00007604 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7605 BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
7606 ext_phy_type);
7607
7608 bp->port.supported |= (SUPPORTED_10baseT_Half |
7609 SUPPORTED_10baseT_Full |
7610 SUPPORTED_100baseT_Half |
7611 SUPPORTED_100baseT_Full |
7612 SUPPORTED_1000baseT_Full |
7613 SUPPORTED_10000baseT_Full |
7614 SUPPORTED_TP |
7615 SUPPORTED_Autoneg |
7616 SUPPORTED_Pause |
7617 SUPPORTED_Asym_Pause);
7618 break;
7619
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007620 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7621 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
7622 bp->link_params.ext_phy_config);
7623 break;
7624
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007625 default:
7626 BNX2X_ERR("NVRAM config error. "
7627 "BAD XGXS ext_phy_config 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007628 bp->link_params.ext_phy_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007629 return;
7630 }
7631
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007632 bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
7633 port*0x18);
7634 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007635
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007636 break;
7637
7638 default:
7639 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007640 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007641 return;
7642 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007643 bp->link_params.phy_addr = bp->port.phy_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007644
7645 /* mask what we support according to speed_cap_mask */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007646 if (!(bp->link_params.speed_cap_mask &
7647 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007648 bp->port.supported &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007649
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007650 if (!(bp->link_params.speed_cap_mask &
7651 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007652 bp->port.supported &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007653
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007654 if (!(bp->link_params.speed_cap_mask &
7655 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007656 bp->port.supported &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007657
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007658 if (!(bp->link_params.speed_cap_mask &
7659 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007660 bp->port.supported &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007661
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007662 if (!(bp->link_params.speed_cap_mask &
7663 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007664 bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
7665 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007666
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007667 if (!(bp->link_params.speed_cap_mask &
7668 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007669 bp->port.supported &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007670
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007671 if (!(bp->link_params.speed_cap_mask &
7672 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007673 bp->port.supported &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007674
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007675 BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007676}
7677
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007678static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007679{
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007680 bp->link_params.req_duplex = DUPLEX_FULL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007681
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007682 switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007683 case PORT_FEATURE_LINK_SPEED_AUTO:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007684 if (bp->port.supported & SUPPORTED_Autoneg) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007685 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007686 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007687 } else {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007688 u32 ext_phy_type =
7689 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
7690
7691 if ((ext_phy_type ==
7692 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
7693 (ext_phy_type ==
7694 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007695 /* force 10G, no AN */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007696 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007697 bp->port.advertising =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007698 (ADVERTISED_10000baseT_Full |
7699 ADVERTISED_FIBRE);
7700 break;
7701 }
7702 BNX2X_ERR("NVRAM config error. "
7703 "Invalid link_config 0x%x"
7704 " Autoneg not supported\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007705 bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007706 return;
7707 }
7708 break;
7709
7710 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007711 if (bp->port.supported & SUPPORTED_10baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007712 bp->link_params.req_line_speed = SPEED_10;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007713 bp->port.advertising = (ADVERTISED_10baseT_Full |
7714 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007715 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007716 BNX2X_ERROR("NVRAM config error. "
7717 "Invalid link_config 0x%x"
7718 " speed_cap_mask 0x%x\n",
7719 bp->port.link_config,
7720 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007721 return;
7722 }
7723 break;
7724
7725 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007726 if (bp->port.supported & SUPPORTED_10baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007727 bp->link_params.req_line_speed = SPEED_10;
7728 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007729 bp->port.advertising = (ADVERTISED_10baseT_Half |
7730 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007731 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007732 BNX2X_ERROR("NVRAM config error. "
7733 "Invalid link_config 0x%x"
7734 " speed_cap_mask 0x%x\n",
7735 bp->port.link_config,
7736 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007737 return;
7738 }
7739 break;
7740
7741 case PORT_FEATURE_LINK_SPEED_100M_FULL:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007742 if (bp->port.supported & SUPPORTED_100baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007743 bp->link_params.req_line_speed = SPEED_100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007744 bp->port.advertising = (ADVERTISED_100baseT_Full |
7745 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007746 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007747 BNX2X_ERROR("NVRAM config error. "
7748 "Invalid link_config 0x%x"
7749 " speed_cap_mask 0x%x\n",
7750 bp->port.link_config,
7751 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007752 return;
7753 }
7754 break;
7755
7756 case PORT_FEATURE_LINK_SPEED_100M_HALF:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007757 if (bp->port.supported & SUPPORTED_100baseT_Half) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007758 bp->link_params.req_line_speed = SPEED_100;
7759 bp->link_params.req_duplex = DUPLEX_HALF;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007760 bp->port.advertising = (ADVERTISED_100baseT_Half |
7761 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007762 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007763 BNX2X_ERROR("NVRAM config error. "
7764 "Invalid link_config 0x%x"
7765 " speed_cap_mask 0x%x\n",
7766 bp->port.link_config,
7767 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007768 return;
7769 }
7770 break;
7771
7772 case PORT_FEATURE_LINK_SPEED_1G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007773 if (bp->port.supported & SUPPORTED_1000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007774 bp->link_params.req_line_speed = SPEED_1000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007775 bp->port.advertising = (ADVERTISED_1000baseT_Full |
7776 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007777 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007778 BNX2X_ERROR("NVRAM config error. "
7779 "Invalid link_config 0x%x"
7780 " speed_cap_mask 0x%x\n",
7781 bp->port.link_config,
7782 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007783 return;
7784 }
7785 break;
7786
7787 case PORT_FEATURE_LINK_SPEED_2_5G:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007788 if (bp->port.supported & SUPPORTED_2500baseX_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007789 bp->link_params.req_line_speed = SPEED_2500;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007790 bp->port.advertising = (ADVERTISED_2500baseX_Full |
7791 ADVERTISED_TP);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007792 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007793 BNX2X_ERROR("NVRAM config error. "
7794 "Invalid link_config 0x%x"
7795 " speed_cap_mask 0x%x\n",
7796 bp->port.link_config,
7797 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007798 return;
7799 }
7800 break;
7801
7802 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7803 case PORT_FEATURE_LINK_SPEED_10G_KX4:
7804 case PORT_FEATURE_LINK_SPEED_10G_KR:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007805 if (bp->port.supported & SUPPORTED_10000baseT_Full) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007806 bp->link_params.req_line_speed = SPEED_10000;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007807 bp->port.advertising = (ADVERTISED_10000baseT_Full |
7808 ADVERTISED_FIBRE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007809 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007810 BNX2X_ERROR("NVRAM config error. "
7811 "Invalid link_config 0x%x"
7812 " speed_cap_mask 0x%x\n",
7813 bp->port.link_config,
7814 bp->link_params.speed_cap_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007815 return;
7816 }
7817 break;
7818
7819 default:
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007820 BNX2X_ERROR("NVRAM config error. "
7821 "BAD link speed link_config 0x%x\n",
7822 bp->port.link_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007823 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007824 bp->port.advertising = bp->port.supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007825 break;
7826 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007827
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007828 bp->link_params.req_flow_ctrl = (bp->port.link_config &
7829 PORT_FEATURE_FLOW_CONTROL_MASK);
David S. Millerc0700f92008-12-16 23:53:20 -08007830 if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Randy Dunlap4ab84d42008-08-07 20:33:19 -07007831 !(bp->port.supported & SUPPORTED_Autoneg))
David S. Millerc0700f92008-12-16 23:53:20 -08007832 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007833
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007834 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
Eliezer Tamirf1410642008-02-28 11:51:50 -08007835 " advertising 0x%x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007836 bp->link_params.req_line_speed,
7837 bp->link_params.req_duplex,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007838 bp->link_params.req_flow_ctrl, bp->port.advertising);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007839}
7840
Michael Chane665bfd2009-10-10 13:46:54 +00007841static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
7842{
7843 mac_hi = cpu_to_be16(mac_hi);
7844 mac_lo = cpu_to_be32(mac_lo);
7845 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
7846 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
7847}
7848
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007849static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007850{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007851 int port = BP_PORT(bp);
7852 u32 val, val2;
Eilon Greenstein589abe32009-02-12 08:36:55 +00007853 u32 config;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007854 u16 i;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00007855 u32 ext_phy_type;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007856
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007857 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007858 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007859
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007860 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007861 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007862 bp->link_params.ext_phy_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007863 SHMEM_RD(bp,
7864 dev_info.port_hw_config[port].external_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007865 /* BCM8727_NOC => BCM8727 no over current */
7866 if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
7867 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC) {
7868 bp->link_params.ext_phy_config &=
7869 ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
7870 bp->link_params.ext_phy_config |=
7871 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727;
7872 bp->link_params.feature_config_flags |=
7873 FEATURE_CONFIG_BCM8727_NOC;
7874 }
7875
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007876 bp->link_params.speed_cap_mask =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007877 SHMEM_RD(bp,
7878 dev_info.port_hw_config[port].speed_capability_mask);
7879
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007880 bp->port.link_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007881 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
7882
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007883 /* Get the 4 lanes xgxs config rx and tx */
7884 for (i = 0; i < 2; i++) {
7885 val = SHMEM_RD(bp,
7886 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
7887 bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
7888 bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
7889
7890 val = SHMEM_RD(bp,
7891 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
7892 bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
7893 bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
7894 }
7895
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00007896 /* If the device is capable of WoL, set the default state according
7897 * to the HW
7898 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007899 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00007900 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
7901 (config & PORT_FEATURE_WOL_ENABLED));
7902
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00007903 BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
7904 " speed_cap_mask 0x%08x link_config 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007905 bp->link_params.lane_config,
7906 bp->link_params.ext_phy_config,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007907 bp->link_params.speed_cap_mask, bp->port.link_config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007908
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007909 bp->link_params.switch_cfg |= (bp->port.link_config &
7910 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007911 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007912
7913 bnx2x_link_settings_requested(bp);
7914
Eilon Greenstein01cd4522009-08-12 08:23:08 +00007915 /*
7916 * If connected directly, work with the internal PHY, otherwise, work
7917 * with the external PHY
7918 */
7919 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
7920 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
7921 bp->mdio.prtad = bp->link_params.phy_addr;
7922
7923 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
7924 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
7925 bp->mdio.prtad =
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00007926 XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00007927
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007928 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
7929 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
Michael Chane665bfd2009-10-10 13:46:54 +00007930 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07007931 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
7932 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +00007933
7934#ifdef BCM_CNIC
7935 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_upper);
7936 val = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_lower);
7937 bnx2x_set_mac_buf(bp->iscsi_mac, val, val2);
7938#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007939}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007940
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007941static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
7942{
7943 int func = BP_FUNC(bp);
7944 u32 val, val2;
7945 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007946
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007947 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007948
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007949 bp->e1hov = 0;
7950 bp->e1hmf = 0;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00007951 if (CHIP_IS_E1H(bp) && !BP_NOMCP(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007952 bp->mf_config =
7953 SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007954
Eilon Greenstein2691d512009-08-12 08:22:08 +00007955 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[FUNC_0].e1hov_tag) &
Eilon Greenstein3196a882008-08-13 15:58:49 -07007956 FUNC_MF_CFG_E1HOV_TAG_MASK);
Eilon Greenstein2691d512009-08-12 08:22:08 +00007957 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007958 bp->e1hmf = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00007959 BNX2X_DEV_INFO("%s function mode\n",
7960 IS_E1HMF(bp) ? "multi" : "single");
7961
7962 if (IS_E1HMF(bp)) {
7963 val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].
7964 e1hov_tag) &
7965 FUNC_MF_CFG_E1HOV_TAG_MASK);
7966 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
7967 bp->e1hov = val;
7968 BNX2X_DEV_INFO("E1HOV for func %d is %d "
7969 "(0x%04x)\n",
7970 func, bp->e1hov, bp->e1hov);
7971 } else {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007972 BNX2X_ERROR("No valid E1HOV for func %d,"
7973 " aborting\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007974 rc = -EPERM;
7975 }
Eilon Greenstein2691d512009-08-12 08:22:08 +00007976 } else {
7977 if (BP_E1HVN(bp)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007978 BNX2X_ERROR("VN %d in single function mode,"
7979 " aborting\n", BP_E1HVN(bp));
Eilon Greenstein2691d512009-08-12 08:22:08 +00007980 rc = -EPERM;
7981 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007982 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007983 }
7984
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007985 if (!BP_NOMCP(bp)) {
7986 bnx2x_get_port_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007987
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007988 bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
7989 DRV_MSG_SEQ_NUMBER_MASK);
7990 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
7991 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007992
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007993 if (IS_E1HMF(bp)) {
7994 val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
7995 val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
7996 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
7997 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
7998 bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
7999 bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
8000 bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
8001 bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
8002 bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
8003 bp->dev->dev_addr[5] = (u8)(val & 0xff);
8004 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
8005 ETH_ALEN);
8006 memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
8007 ETH_ALEN);
8008 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008009
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008010 return rc;
8011 }
8012
8013 if (BP_NOMCP(bp)) {
8014 /* only supposed to happen on emulation/FPGA */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008015 BNX2X_ERROR("warning: random MAC workaround active\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008016 random_ether_addr(bp->dev->dev_addr);
8017 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8018 }
8019
8020 return rc;
8021}
8022
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00008023static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
8024{
8025 int cnt, i, block_end, rodi;
8026 char vpd_data[BNX2X_VPD_LEN+1];
8027 char str_id_reg[VENDOR_ID_LEN+1];
8028 char str_id_cap[VENDOR_ID_LEN+1];
8029 u8 len;
8030
8031 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
8032 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
8033
8034 if (cnt < BNX2X_VPD_LEN)
8035 goto out_not_found;
8036
8037 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
8038 PCI_VPD_LRDT_RO_DATA);
8039 if (i < 0)
8040 goto out_not_found;
8041
8042
8043 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
8044 pci_vpd_lrdt_size(&vpd_data[i]);
8045
8046 i += PCI_VPD_LRDT_TAG_SIZE;
8047
8048 if (block_end > BNX2X_VPD_LEN)
8049 goto out_not_found;
8050
8051 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
8052 PCI_VPD_RO_KEYWORD_MFR_ID);
8053 if (rodi < 0)
8054 goto out_not_found;
8055
8056 len = pci_vpd_info_field_size(&vpd_data[rodi]);
8057
8058 if (len != VENDOR_ID_LEN)
8059 goto out_not_found;
8060
8061 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
8062
8063 /* vendor specific info */
8064 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
8065 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
8066 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
8067 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
8068
8069 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
8070 PCI_VPD_RO_KEYWORD_VENDOR0);
8071 if (rodi >= 0) {
8072 len = pci_vpd_info_field_size(&vpd_data[rodi]);
8073
8074 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
8075
8076 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
8077 memcpy(bp->fw_ver, &vpd_data[rodi], len);
8078 bp->fw_ver[len] = ' ';
8079 }
8080 }
8081 return;
8082 }
8083out_not_found:
8084 return;
8085}
8086
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008087static int __devinit bnx2x_init_bp(struct bnx2x *bp)
8088{
8089 int func = BP_FUNC(bp);
Eilon Greenstein87942b42009-02-12 08:36:49 +00008090 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008091 int rc;
8092
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008093 /* Disable interrupt handling until HW is initialized */
8094 atomic_set(&bp->intr_sem, 1);
Eilon Greensteine1510702009-07-21 05:47:41 +00008095 smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008096
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008097 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07008098 mutex_init(&bp->fw_mb_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +00008099#ifdef BCM_CNIC
8100 mutex_init(&bp->cnic_mutex);
8101#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008102
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08008103 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008104 INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008105
8106 rc = bnx2x_get_hwinfo(bp);
8107
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00008108 bnx2x_read_fwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008109 /* need to reset chip if undi was active */
8110 if (!BP_NOMCP(bp))
8111 bnx2x_undi_unload(bp);
8112
8113 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008114 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008115
8116 if (BP_NOMCP(bp) && (func == 0))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008117 dev_err(&bp->pdev->dev, "MCP disabled, "
8118 "must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008119
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008120 /* Set multi queue mode */
Eilon Greenstein8badd272009-02-12 08:36:15 +00008121 if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
8122 ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008123 dev_err(&bp->pdev->dev, "Multi disabled since int_mode "
8124 "requested is not MSI-X\n");
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008125 multi_mode = ETH_RSS_MODE_DISABLED;
8126 }
8127 bp->multi_mode = multi_mode;
Dmitry Kravkov5d7cd492010-07-27 12:32:19 +00008128 bp->int_mode = int_mode;
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008129
Dmitry Kravkov4fd89b7a2010-04-01 19:45:34 -07008130 bp->dev->features |= NETIF_F_GRO;
8131
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008132 /* Set TPA flags */
8133 if (disable_tpa) {
8134 bp->flags &= ~TPA_ENABLE_FLAG;
8135 bp->dev->features &= ~NETIF_F_LRO;
8136 } else {
8137 bp->flags |= TPA_ENABLE_FLAG;
8138 bp->dev->features |= NETIF_F_LRO;
8139 }
Dmitry Kravkov5d7cd492010-07-27 12:32:19 +00008140 bp->disable_tpa = disable_tpa;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008141
Eilon Greensteina18f5122009-08-12 08:23:26 +00008142 if (CHIP_IS_E1(bp))
8143 bp->dropless_fc = 0;
8144 else
8145 bp->dropless_fc = dropless_fc;
8146
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00008147 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008148
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008149 bp->tx_ring_size = MAX_TX_AVAIL;
8150 bp->rx_ring_size = MAX_RX_AVAIL;
8151
8152 bp->rx_csum = 1;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008153
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00008154 /* make sure that the numbers are in the right granularity */
8155 bp->tx_ticks = (50 / (4 * BNX2X_BTR)) * (4 * BNX2X_BTR);
8156 bp->rx_ticks = (25 / (4 * BNX2X_BTR)) * (4 * BNX2X_BTR);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008157
Eilon Greenstein87942b42009-02-12 08:36:49 +00008158 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
8159 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008160
8161 init_timer(&bp->timer);
8162 bp->timer.expires = jiffies + bp->current_interval;
8163 bp->timer.data = (unsigned long) bp;
8164 bp->timer.function = bnx2x_timer;
8165
8166 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008167}
8168
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008169
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00008170/****************************************************************************
8171* General service functions
8172****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008173
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008174/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008175static int bnx2x_open(struct net_device *dev)
8176{
8177 struct bnx2x *bp = netdev_priv(dev);
8178
Eilon Greenstein6eccabb2009-01-22 03:37:48 +00008179 netif_carrier_off(dev);
8180
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008181 bnx2x_set_power_state(bp, PCI_D0);
8182
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008183 if (!bnx2x_reset_is_done(bp)) {
8184 do {
8185 /* Reset MCP mail box sequence if there is on going
8186 * recovery
8187 */
8188 bp->fw_seq = 0;
8189
8190 /* If it's the first function to load and reset done
8191 * is still not cleared it may mean that. We don't
8192 * check the attention state here because it may have
8193 * already been cleared by a "common" reset but we
8194 * shell proceed with "process kill" anyway.
8195 */
8196 if ((bnx2x_get_load_cnt(bp) == 0) &&
8197 bnx2x_trylock_hw_lock(bp,
8198 HW_LOCK_RESOURCE_RESERVED_08) &&
8199 (!bnx2x_leader_reset(bp))) {
8200 DP(NETIF_MSG_HW, "Recovered in open\n");
8201 break;
8202 }
8203
8204 bnx2x_set_power_state(bp, PCI_D3hot);
8205
8206 printk(KERN_ERR"%s: Recovery flow hasn't been properly"
8207 " completed yet. Try again later. If u still see this"
8208 " message after a few retries then power cycle is"
8209 " required.\n", bp->dev->name);
8210
8211 return -EAGAIN;
8212 } while (0);
8213 }
8214
8215 bp->recovery_state = BNX2X_RECOVERY_DONE;
8216
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008217 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008218}
8219
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008220/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008221static int bnx2x_close(struct net_device *dev)
8222{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008223 struct bnx2x *bp = netdev_priv(dev);
8224
8225 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07008226 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Vladislav Zolotarovd3dbfee2010-04-19 01:14:49 +00008227 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008228
8229 return 0;
8230}
8231
Eilon Greensteinf5372252009-02-12 08:38:30 +00008232/* called with netif_tx_lock from dev_mcast.c */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00008233void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008234{
8235 struct bnx2x *bp = netdev_priv(dev);
8236 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
8237 int port = BP_PORT(bp);
8238
8239 if (bp->state != BNX2X_STATE_OPEN) {
8240 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
8241 return;
8242 }
8243
8244 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
8245
8246 if (dev->flags & IFF_PROMISC)
8247 rx_mode = BNX2X_RX_MODE_PROMISC;
8248
8249 else if ((dev->flags & IFF_ALLMULTI) ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00008250 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
8251 CHIP_IS_E1(bp)))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008252 rx_mode = BNX2X_RX_MODE_ALLMULTI;
8253
8254 else { /* some multicasts */
8255 if (CHIP_IS_E1(bp)) {
8256 int i, old, offset;
Jiri Pirko22bedad32010-04-01 21:22:57 +00008257 struct netdev_hw_addr *ha;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008258 struct mac_configuration_cmd *config =
8259 bnx2x_sp(bp, mcast_config);
8260
Jiri Pirko0ddf4772010-02-20 00:13:58 +00008261 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00008262 netdev_for_each_mc_addr(ha, dev) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008263 config->config_table[i].
8264 cam_entry.msb_mac_addr =
Jiri Pirko22bedad32010-04-01 21:22:57 +00008265 swab16(*(u16 *)&ha->addr[0]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008266 config->config_table[i].
8267 cam_entry.middle_mac_addr =
Jiri Pirko22bedad32010-04-01 21:22:57 +00008268 swab16(*(u16 *)&ha->addr[2]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008269 config->config_table[i].
8270 cam_entry.lsb_mac_addr =
Jiri Pirko22bedad32010-04-01 21:22:57 +00008271 swab16(*(u16 *)&ha->addr[4]);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008272 config->config_table[i].cam_entry.flags =
8273 cpu_to_le16(port);
8274 config->config_table[i].
8275 target_table_entry.flags = 0;
Eilon Greensteinca003922009-08-12 22:53:28 -07008276 config->config_table[i].target_table_entry.
8277 clients_bit_vector =
8278 cpu_to_le32(1 << BP_L_ID(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008279 config->config_table[i].
8280 target_table_entry.vlan_id = 0;
8281
8282 DP(NETIF_MSG_IFUP,
8283 "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
8284 config->config_table[i].
8285 cam_entry.msb_mac_addr,
8286 config->config_table[i].
8287 cam_entry.middle_mac_addr,
8288 config->config_table[i].
8289 cam_entry.lsb_mac_addr);
Jiri Pirko0ddf4772010-02-20 00:13:58 +00008290 i++;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008291 }
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08008292 old = config->hdr.length;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008293 if (old > i) {
8294 for (; i < old; i++) {
8295 if (CAM_IS_INVALID(config->
8296 config_table[i])) {
Eilon Greensteinaf246402009-01-14 06:43:59 +00008297 /* already invalidated */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008298 break;
8299 }
8300 /* invalidate */
8301 CAM_INVALIDATE(config->
8302 config_table[i]);
8303 }
8304 }
8305
8306 if (CHIP_REV_IS_SLOW(bp))
8307 offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
8308 else
8309 offset = BNX2X_MAX_MULTICAST*(1 + port);
8310
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08008311 config->hdr.length = i;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008312 config->hdr.offset = offset;
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08008313 config->hdr.client_id = bp->fp->cl_id;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008314 config->hdr.reserved1 = 0;
8315
Michael Chane665bfd2009-10-10 13:46:54 +00008316 bp->set_mac_pending++;
8317 smp_wmb();
8318
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008319 bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
8320 U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
8321 U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
8322 0);
8323 } else { /* E1H */
8324 /* Accept one or more multicasts */
Jiri Pirko22bedad32010-04-01 21:22:57 +00008325 struct netdev_hw_addr *ha;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008326 u32 mc_filter[MC_HASH_SIZE];
8327 u32 crc, bit, regidx;
8328 int i;
8329
8330 memset(mc_filter, 0, 4 * MC_HASH_SIZE);
8331
Jiri Pirko22bedad32010-04-01 21:22:57 +00008332 netdev_for_each_mc_addr(ha, dev) {
Johannes Berg7c510e42008-10-27 17:47:26 -07008333 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00008334 ha->addr);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008335
Jiri Pirko22bedad32010-04-01 21:22:57 +00008336 crc = crc32c_le(0, ha->addr, ETH_ALEN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008337 bit = (crc >> 24) & 0xff;
8338 regidx = bit >> 5;
8339 bit &= 0x1f;
8340 mc_filter[regidx] |= (1 << bit);
8341 }
8342
8343 for (i = 0; i < MC_HASH_SIZE; i++)
8344 REG_WR(bp, MC_HASH_OFFSET(bp, i),
8345 mc_filter[i]);
8346 }
8347 }
8348
8349 bp->rx_mode = rx_mode;
8350 bnx2x_set_storm_rx_mode(bp);
8351}
8352
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008353
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008354/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008355static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
8356 int devad, u16 addr)
8357{
8358 struct bnx2x *bp = netdev_priv(netdev);
8359 u16 value;
8360 int rc;
8361 u32 phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
8362
8363 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
8364 prtad, devad, addr);
8365
8366 if (prtad != bp->mdio.prtad) {
8367 DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
8368 prtad, bp->mdio.prtad);
8369 return -EINVAL;
8370 }
8371
8372 /* The HW expects different devad if CL22 is used */
8373 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
8374
8375 bnx2x_acquire_phy_lock(bp);
8376 rc = bnx2x_cl45_read(bp, BP_PORT(bp), phy_type, prtad,
8377 devad, addr, &value);
8378 bnx2x_release_phy_lock(bp);
8379 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
8380
8381 if (!rc)
8382 rc = value;
8383 return rc;
8384}
8385
8386/* called with rtnl_lock */
8387static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
8388 u16 addr, u16 value)
8389{
8390 struct bnx2x *bp = netdev_priv(netdev);
8391 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
8392 int rc;
8393
8394 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
8395 " value 0x%x\n", prtad, devad, addr, value);
8396
8397 if (prtad != bp->mdio.prtad) {
8398 DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
8399 prtad, bp->mdio.prtad);
8400 return -EINVAL;
8401 }
8402
8403 /* The HW expects different devad if CL22 is used */
8404 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
8405
8406 bnx2x_acquire_phy_lock(bp);
8407 rc = bnx2x_cl45_write(bp, BP_PORT(bp), ext_phy_type, prtad,
8408 devad, addr, value);
8409 bnx2x_release_phy_lock(bp);
8410 return rc;
8411}
8412
8413/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008414static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
8415{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008416 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008417 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008418
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008419 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
8420 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008421
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008422 if (!netif_running(dev))
8423 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008424
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008425 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008426}
8427
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00008428#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008429static void poll_bnx2x(struct net_device *dev)
8430{
8431 struct bnx2x *bp = netdev_priv(dev);
8432
8433 disable_irq(bp->pdev->irq);
8434 bnx2x_interrupt(bp->pdev->irq, dev);
8435 enable_irq(bp->pdev->irq);
8436}
8437#endif
8438
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08008439static const struct net_device_ops bnx2x_netdev_ops = {
8440 .ndo_open = bnx2x_open,
8441 .ndo_stop = bnx2x_close,
8442 .ndo_start_xmit = bnx2x_start_xmit,
Eilon Greenstein356e2382009-02-12 08:38:32 +00008443 .ndo_set_multicast_list = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08008444 .ndo_set_mac_address = bnx2x_change_mac_addr,
8445 .ndo_validate_addr = eth_validate_addr,
8446 .ndo_do_ioctl = bnx2x_ioctl,
8447 .ndo_change_mtu = bnx2x_change_mtu,
8448 .ndo_tx_timeout = bnx2x_tx_timeout,
8449#ifdef BCM_VLAN
8450 .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
8451#endif
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00008452#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08008453 .ndo_poll_controller = poll_bnx2x,
8454#endif
8455};
8456
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008457static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
8458 struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008459{
8460 struct bnx2x *bp;
8461 int rc;
8462
8463 SET_NETDEV_DEV(dev, &pdev->dev);
8464 bp = netdev_priv(dev);
8465
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008466 bp->dev = dev;
8467 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008468 bp->flags = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008469 bp->func = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008470
8471 rc = pci_enable_device(pdev);
8472 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008473 dev_err(&bp->pdev->dev,
8474 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008475 goto err_out;
8476 }
8477
8478 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008479 dev_err(&bp->pdev->dev,
8480 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008481 rc = -ENODEV;
8482 goto err_out_disable;
8483 }
8484
8485 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008486 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
8487 " base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008488 rc = -ENODEV;
8489 goto err_out_disable;
8490 }
8491
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008492 if (atomic_read(&pdev->enable_cnt) == 1) {
8493 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
8494 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008495 dev_err(&bp->pdev->dev,
8496 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008497 goto err_out_disable;
8498 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008499
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008500 pci_set_master(pdev);
8501 pci_save_state(pdev);
8502 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008503
8504 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
8505 if (bp->pm_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008506 dev_err(&bp->pdev->dev,
8507 "Cannot find power management capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008508 rc = -EIO;
8509 goto err_out_release;
8510 }
8511
8512 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
8513 if (bp->pcie_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008514 dev_err(&bp->pdev->dev,
8515 "Cannot find PCI Express capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008516 rc = -EIO;
8517 goto err_out_release;
8518 }
8519
FUJITA Tomonori1a983142010-04-04 01:51:03 +00008520 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) == 0) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008521 bp->flags |= USING_DAC_FLAG;
FUJITA Tomonori1a983142010-04-04 01:51:03 +00008522 if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)) != 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008523 dev_err(&bp->pdev->dev, "dma_set_coherent_mask"
8524 " failed, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008525 rc = -EIO;
8526 goto err_out_release;
8527 }
8528
FUJITA Tomonori1a983142010-04-04 01:51:03 +00008529 } else if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008530 dev_err(&bp->pdev->dev,
8531 "System does not support DMA, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008532 rc = -EIO;
8533 goto err_out_release;
8534 }
8535
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008536 dev->mem_start = pci_resource_start(pdev, 0);
8537 dev->base_addr = dev->mem_start;
8538 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008539
8540 dev->irq = pdev->irq;
8541
Arjan van de Ven275f1652008-10-20 21:42:39 -07008542 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008543 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008544 dev_err(&bp->pdev->dev,
8545 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008546 rc = -ENOMEM;
8547 goto err_out_release;
8548 }
8549
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008550 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
8551 min_t(u64, BNX2X_DB_SIZE,
8552 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008553 if (!bp->doorbells) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008554 dev_err(&bp->pdev->dev,
8555 "Cannot map doorbell space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008556 rc = -ENOMEM;
8557 goto err_out_unmap;
8558 }
8559
8560 bnx2x_set_power_state(bp, PCI_D0);
8561
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008562 /* clean indirect addresses */
8563 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
8564 PCICFG_VENDOR_ID_OFFSET);
8565 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
8566 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
8567 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
8568 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008569
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008570 /* Reset the load counter */
8571 bnx2x_clear_load_cnt(bp);
8572
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008573 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008574
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08008575 dev->netdev_ops = &bnx2x_netdev_ops;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00008576 bnx2x_set_ethtool_ops(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008577 dev->features |= NETIF_F_SG;
8578 dev->features |= NETIF_F_HW_CSUM;
8579 if (bp->flags & USING_DAC_FLAG)
8580 dev->features |= NETIF_F_HIGHDMA;
Eilon Greenstein5316bc02009-07-21 05:47:43 +00008581 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
8582 dev->features |= NETIF_F_TSO6;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008583#ifdef BCM_VLAN
8584 dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
Eilon Greenstein0c6671b2009-01-14 21:26:51 -08008585 bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
Eilon Greenstein5316bc02009-07-21 05:47:43 +00008586
8587 dev->vlan_features |= NETIF_F_SG;
8588 dev->vlan_features |= NETIF_F_HW_CSUM;
8589 if (bp->flags & USING_DAC_FLAG)
8590 dev->vlan_features |= NETIF_F_HIGHDMA;
8591 dev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
8592 dev->vlan_features |= NETIF_F_TSO6;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008593#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008594
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008595 /* get_port_hwinfo() will set prtad and mmds properly */
8596 bp->mdio.prtad = MDIO_PRTAD_NONE;
8597 bp->mdio.mmds = 0;
8598 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8599 bp->mdio.dev = dev;
8600 bp->mdio.mdio_read = bnx2x_mdio_read;
8601 bp->mdio.mdio_write = bnx2x_mdio_write;
8602
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008603 return 0;
8604
8605err_out_unmap:
8606 if (bp->regview) {
8607 iounmap(bp->regview);
8608 bp->regview = NULL;
8609 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008610 if (bp->doorbells) {
8611 iounmap(bp->doorbells);
8612 bp->doorbells = NULL;
8613 }
8614
8615err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008616 if (atomic_read(&pdev->enable_cnt) == 1)
8617 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008618
8619err_out_disable:
8620 pci_disable_device(pdev);
8621 pci_set_drvdata(pdev, NULL);
8622
8623err_out:
8624 return rc;
8625}
8626
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008627static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
8628 int *width, int *speed)
Eliezer Tamir25047952008-02-28 11:50:16 -08008629{
8630 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
8631
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008632 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
8633
8634 /* return value of 1=2.5GHz 2=5GHz */
8635 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
Eliezer Tamir25047952008-02-28 11:50:16 -08008636}
8637
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008638static int __devinit bnx2x_check_firmware(struct bnx2x *bp)
8639{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008640 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008641 struct bnx2x_fw_file_hdr *fw_hdr;
8642 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008643 u32 offset, len, num_ops;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008644 u16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008645 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008646 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008647
8648 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
8649 return -EINVAL;
8650
8651 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
8652 sections = (struct bnx2x_fw_file_section *)fw_hdr;
8653
8654 /* Make sure none of the offsets and sizes make us read beyond
8655 * the end of the firmware data */
8656 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
8657 offset = be32_to_cpu(sections[i].offset);
8658 len = be32_to_cpu(sections[i].len);
8659 if (offset + len > firmware->size) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008660 dev_err(&bp->pdev->dev,
8661 "Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008662 return -EINVAL;
8663 }
8664 }
8665
8666 /* Likewise for the init_ops offsets */
8667 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
8668 ops_offsets = (u16 *)(firmware->data + offset);
8669 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
8670
8671 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
8672 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008673 dev_err(&bp->pdev->dev,
8674 "Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008675 return -EINVAL;
8676 }
8677 }
8678
8679 /* Check FW version */
8680 offset = be32_to_cpu(fw_hdr->fw_version.offset);
8681 fw_ver = firmware->data + offset;
8682 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
8683 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
8684 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
8685 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008686 dev_err(&bp->pdev->dev,
8687 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008688 fw_ver[0], fw_ver[1], fw_ver[2],
8689 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
8690 BCM_5710_FW_MINOR_VERSION,
8691 BCM_5710_FW_REVISION_VERSION,
8692 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008693 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008694 }
8695
8696 return 0;
8697}
8698
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008699static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008700{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008701 const __be32 *source = (const __be32 *)_source;
8702 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008703 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008704
8705 for (i = 0; i < n/4; i++)
8706 target[i] = be32_to_cpu(source[i]);
8707}
8708
8709/*
8710 Ops array is stored in the following format:
8711 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
8712 */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008713static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008714{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008715 const __be32 *source = (const __be32 *)_source;
8716 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008717 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008718
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008719 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008720 tmp = be32_to_cpu(source[j]);
8721 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008722 target[i].offset = tmp & 0xffffff;
8723 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008724 }
8725}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008726
8727static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008728{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008729 const __be16 *source = (const __be16 *)_source;
8730 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008731 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008732
8733 for (i = 0; i < n/2; i++)
8734 target[i] = be16_to_cpu(source[i]);
8735}
8736
Joe Perches7995c642010-02-17 15:01:52 +00008737#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
8738do { \
8739 u32 len = be32_to_cpu(fw_hdr->arr.len); \
8740 bp->arr = kmalloc(len, GFP_KERNEL); \
8741 if (!bp->arr) { \
8742 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
8743 goto lbl; \
8744 } \
8745 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
8746 (u8 *)bp->arr, len); \
8747} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008748
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008749static int __devinit bnx2x_init_firmware(struct bnx2x *bp, struct device *dev)
8750{
Ben Hutchings45229b42009-11-07 11:53:39 +00008751 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008752 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +00008753 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008754
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008755 if (CHIP_IS_E1(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00008756 fw_file_name = FW_FILE_NAME_E1;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008757 else if (CHIP_IS_E1H(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00008758 fw_file_name = FW_FILE_NAME_E1H;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008759 else {
8760 dev_err(dev, "Unsupported chip revision\n");
8761 return -EINVAL;
8762 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008763
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008764 dev_info(dev, "Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008765
8766 rc = request_firmware(&bp->firmware, fw_file_name, dev);
8767 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008768 dev_err(dev, "Can't load firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008769 goto request_firmware_exit;
8770 }
8771
8772 rc = bnx2x_check_firmware(bp);
8773 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008774 dev_err(dev, "Corrupt firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008775 goto request_firmware_exit;
8776 }
8777
8778 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
8779
8780 /* Initialize the pointers to the init arrays */
8781 /* Blob */
8782 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
8783
8784 /* Opcodes */
8785 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
8786
8787 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008788 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
8789 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008790
8791 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +00008792 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
8793 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
8794 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
8795 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
8796 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
8797 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
8798 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
8799 be32_to_cpu(fw_hdr->usem_pram_data.offset);
8800 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
8801 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
8802 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
8803 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
8804 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
8805 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
8806 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
8807 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008808
8809 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00008810
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008811init_offsets_alloc_err:
8812 kfree(bp->init_ops);
8813init_ops_alloc_err:
8814 kfree(bp->init_data);
8815request_firmware_exit:
8816 release_firmware(bp->firmware);
8817
8818 return rc;
8819}
8820
8821
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008822static int __devinit bnx2x_init_one(struct pci_dev *pdev,
8823 const struct pci_device_id *ent)
8824{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008825 struct net_device *dev = NULL;
8826 struct bnx2x *bp;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008827 int pcie_width, pcie_speed;
Eliezer Tamir25047952008-02-28 11:50:16 -08008828 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008829
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008830 /* dev zeroed in init_etherdev */
Eilon Greenstein555f6c72009-02-12 08:36:11 +00008831 dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008832 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008833 dev_err(&pdev->dev, "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008834 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008835 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008836
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008837 bp = netdev_priv(dev);
Joe Perches7995c642010-02-17 15:01:52 +00008838 bp->msg_enable = debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008839
Eilon Greensteindf4770de2009-08-12 08:23:28 +00008840 pci_set_drvdata(pdev, dev);
8841
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008842 rc = bnx2x_init_dev(pdev, dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008843 if (rc < 0) {
8844 free_netdev(dev);
8845 return rc;
8846 }
8847
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008848 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +00008849 if (rc)
8850 goto init_one_exit;
8851
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008852 /* Set init arrays */
8853 rc = bnx2x_init_firmware(bp, &pdev->dev);
8854 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008855 dev_err(&pdev->dev, "Error loading firmware\n");
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008856 goto init_one_exit;
8857 }
8858
Eilon Greenstein693fc0d2009-01-14 06:43:52 +00008859 rc = register_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008860 if (rc) {
Eilon Greenstein693fc0d2009-01-14 06:43:52 +00008861 dev_err(&pdev->dev, "Cannot register net device\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008862 goto init_one_exit;
8863 }
8864
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00008865 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008866 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
8867 " IRQ %d, ", board_info[ent->driver_data].name,
8868 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
8869 pcie_width, (pcie_speed == 2) ? "5GHz (Gen2)" : "2.5GHz",
8870 dev->base_addr, bp->pdev->irq);
8871 pr_cont("node addr %pM\n", dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +00008872
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008873 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008874
8875init_one_exit:
8876 if (bp->regview)
8877 iounmap(bp->regview);
8878
8879 if (bp->doorbells)
8880 iounmap(bp->doorbells);
8881
8882 free_netdev(dev);
8883
8884 if (atomic_read(&pdev->enable_cnt) == 1)
8885 pci_release_regions(pdev);
8886
8887 pci_disable_device(pdev);
8888 pci_set_drvdata(pdev, NULL);
8889
8890 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008891}
8892
8893static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
8894{
8895 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -08008896 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008897
Eliezer Tamir228241e2008-02-28 11:56:57 -08008898 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008899 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
Eliezer Tamir228241e2008-02-28 11:56:57 -08008900 return;
8901 }
Eliezer Tamir228241e2008-02-28 11:56:57 -08008902 bp = netdev_priv(dev);
8903
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008904 unregister_netdev(dev);
8905
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008906 /* Make sure RESET task is not scheduled before continuing */
8907 cancel_delayed_work_sync(&bp->reset_task);
8908
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07008909 kfree(bp->init_ops_offsets);
8910 kfree(bp->init_ops);
8911 kfree(bp->init_data);
8912 release_firmware(bp->firmware);
8913
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008914 if (bp->regview)
8915 iounmap(bp->regview);
8916
8917 if (bp->doorbells)
8918 iounmap(bp->doorbells);
8919
8920 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008921
8922 if (atomic_read(&pdev->enable_cnt) == 1)
8923 pci_release_regions(pdev);
8924
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008925 pci_disable_device(pdev);
8926 pci_set_drvdata(pdev, NULL);
8927}
8928
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008929static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
8930{
8931 int i;
8932
8933 bp->state = BNX2X_STATE_ERROR;
8934
8935 bp->rx_mode = BNX2X_RX_MODE_NONE;
8936
8937 bnx2x_netif_stop(bp, 0);
Stanislaw Gruszkac89af1a2010-05-17 17:35:38 -07008938 netif_carrier_off(bp->dev);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008939
8940 del_timer_sync(&bp->timer);
8941 bp->stats_state = STATS_STATE_DISABLED;
8942 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
8943
8944 /* Release IRQs */
Vladislav Zolotarov6cbe5062010-02-17 02:03:27 +00008945 bnx2x_free_irq(bp, false);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008946
8947 if (CHIP_IS_E1(bp)) {
8948 struct mac_configuration_cmd *config =
8949 bnx2x_sp(bp, mcast_config);
8950
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08008951 for (i = 0; i < config->hdr.length; i++)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008952 CAM_INVALIDATE(config->config_table[i]);
8953 }
8954
8955 /* Free SKBs, SGEs, TPA pool and driver internals */
8956 bnx2x_free_skbs(bp);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00008957 for_each_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008958 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00008959 for_each_queue(bp, i)
Eilon Greenstein7cde1c82009-01-22 06:01:25 +00008960 netif_napi_del(&bnx2x_fp(bp, i, napi));
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008961 bnx2x_free_mem(bp);
8962
8963 bp->state = BNX2X_STATE_CLOSED;
8964
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07008965 return 0;
8966}
8967
8968static void bnx2x_eeh_recover(struct bnx2x *bp)
8969{
8970 u32 val;
8971
8972 mutex_init(&bp->port.phy_mutex);
8973
8974 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8975 bp->link_params.shmem_base = bp->common.shmem_base;
8976 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
8977
8978 if (!bp->common.shmem_base ||
8979 (bp->common.shmem_base < 0xA0000) ||
8980 (bp->common.shmem_base >= 0xC0000)) {
8981 BNX2X_DEV_INFO("MCP not active\n");
8982 bp->flags |= NO_MCP_FLAG;
8983 return;
8984 }
8985
8986 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8987 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
8988 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
8989 BNX2X_ERR("BAD MCP validity signature\n");
8990
8991 if (!BP_NOMCP(bp)) {
8992 bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
8993 & DRV_MSG_SEQ_NUMBER_MASK);
8994 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
8995 }
8996}
8997
Wendy Xiong493adb12008-06-23 20:36:22 -07008998/**
8999 * bnx2x_io_error_detected - called when PCI error is detected
9000 * @pdev: Pointer to PCI device
9001 * @state: The current pci connection state
9002 *
9003 * This function is called after a PCI bus error affecting
9004 * this device has been detected.
9005 */
9006static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
9007 pci_channel_state_t state)
9008{
9009 struct net_device *dev = pci_get_drvdata(pdev);
9010 struct bnx2x *bp = netdev_priv(dev);
9011
9012 rtnl_lock();
9013
9014 netif_device_detach(dev);
9015
Dean Nelson07ce50e2009-07-31 09:13:25 +00009016 if (state == pci_channel_io_perm_failure) {
9017 rtnl_unlock();
9018 return PCI_ERS_RESULT_DISCONNECT;
9019 }
9020
Wendy Xiong493adb12008-06-23 20:36:22 -07009021 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07009022 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -07009023
9024 pci_disable_device(pdev);
9025
9026 rtnl_unlock();
9027
9028 /* Request a slot reset */
9029 return PCI_ERS_RESULT_NEED_RESET;
9030}
9031
9032/**
9033 * bnx2x_io_slot_reset - called after the PCI bus has been reset
9034 * @pdev: Pointer to PCI device
9035 *
9036 * Restart the card from scratch, as if from a cold-boot.
9037 */
9038static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
9039{
9040 struct net_device *dev = pci_get_drvdata(pdev);
9041 struct bnx2x *bp = netdev_priv(dev);
9042
9043 rtnl_lock();
9044
9045 if (pci_enable_device(pdev)) {
9046 dev_err(&pdev->dev,
9047 "Cannot re-enable PCI device after reset\n");
9048 rtnl_unlock();
9049 return PCI_ERS_RESULT_DISCONNECT;
9050 }
9051
9052 pci_set_master(pdev);
9053 pci_restore_state(pdev);
9054
9055 if (netif_running(dev))
9056 bnx2x_set_power_state(bp, PCI_D0);
9057
9058 rtnl_unlock();
9059
9060 return PCI_ERS_RESULT_RECOVERED;
9061}
9062
9063/**
9064 * bnx2x_io_resume - called when traffic can start flowing again
9065 * @pdev: Pointer to PCI device
9066 *
9067 * This callback is called when the error recovery driver tells us that
9068 * its OK to resume normal operation.
9069 */
9070static void bnx2x_io_resume(struct pci_dev *pdev)
9071{
9072 struct net_device *dev = pci_get_drvdata(pdev);
9073 struct bnx2x *bp = netdev_priv(dev);
9074
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009075 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
9076 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
9077 return;
9078 }
9079
Wendy Xiong493adb12008-06-23 20:36:22 -07009080 rtnl_lock();
9081
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07009082 bnx2x_eeh_recover(bp);
9083
Wendy Xiong493adb12008-06-23 20:36:22 -07009084 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07009085 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -07009086
9087 netif_device_attach(dev);
9088
9089 rtnl_unlock();
9090}
9091
9092static struct pci_error_handlers bnx2x_err_handler = {
9093 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +00009094 .slot_reset = bnx2x_io_slot_reset,
9095 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -07009096};
9097
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009098static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -07009099 .name = DRV_MODULE_NAME,
9100 .id_table = bnx2x_pci_tbl,
9101 .probe = bnx2x_init_one,
9102 .remove = __devexit_p(bnx2x_remove_one),
9103 .suspend = bnx2x_suspend,
9104 .resume = bnx2x_resume,
9105 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009106};
9107
9108static int __init bnx2x_init(void)
9109{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +00009110 int ret;
9111
Joe Perches7995c642010-02-17 15:01:52 +00009112 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +00009113
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08009114 bnx2x_wq = create_singlethread_workqueue("bnx2x");
9115 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +00009116 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08009117 return -ENOMEM;
9118 }
9119
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +00009120 ret = pci_register_driver(&bnx2x_pci_driver);
9121 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +00009122 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +00009123 destroy_workqueue(bnx2x_wq);
9124 }
9125 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009126}
9127
9128static void __exit bnx2x_cleanup(void)
9129{
9130 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08009131
9132 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009133}
9134
9135module_init(bnx2x_init);
9136module_exit(bnx2x_cleanup);
9137
Michael Chan993ac7b2009-10-10 13:46:56 +00009138#ifdef BCM_CNIC
9139
9140/* count denotes the number of new completions we have seen */
9141static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
9142{
9143 struct eth_spe *spe;
9144
9145#ifdef BNX2X_STOP_ON_ERROR
9146 if (unlikely(bp->panic))
9147 return;
9148#endif
9149
9150 spin_lock_bh(&bp->spq_lock);
9151 bp->cnic_spq_pending -= count;
9152
9153 for (; bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending;
9154 bp->cnic_spq_pending++) {
9155
9156 if (!bp->cnic_kwq_pending)
9157 break;
9158
9159 spe = bnx2x_sp_get_next(bp);
9160 *spe = *bp->cnic_kwq_cons;
9161
9162 bp->cnic_kwq_pending--;
9163
9164 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
9165 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
9166
9167 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
9168 bp->cnic_kwq_cons = bp->cnic_kwq;
9169 else
9170 bp->cnic_kwq_cons++;
9171 }
9172 bnx2x_sp_prod_update(bp);
9173 spin_unlock_bh(&bp->spq_lock);
9174}
9175
9176static int bnx2x_cnic_sp_queue(struct net_device *dev,
9177 struct kwqe_16 *kwqes[], u32 count)
9178{
9179 struct bnx2x *bp = netdev_priv(dev);
9180 int i;
9181
9182#ifdef BNX2X_STOP_ON_ERROR
9183 if (unlikely(bp->panic))
9184 return -EIO;
9185#endif
9186
9187 spin_lock_bh(&bp->spq_lock);
9188
9189 for (i = 0; i < count; i++) {
9190 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
9191
9192 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
9193 break;
9194
9195 *bp->cnic_kwq_prod = *spe;
9196
9197 bp->cnic_kwq_pending++;
9198
9199 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
9200 spe->hdr.conn_and_cmd_data, spe->hdr.type,
9201 spe->data.mac_config_addr.hi,
9202 spe->data.mac_config_addr.lo,
9203 bp->cnic_kwq_pending);
9204
9205 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
9206 bp->cnic_kwq_prod = bp->cnic_kwq;
9207 else
9208 bp->cnic_kwq_prod++;
9209 }
9210
9211 spin_unlock_bh(&bp->spq_lock);
9212
9213 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
9214 bnx2x_cnic_sp_post(bp, 0);
9215
9216 return i;
9217}
9218
9219static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
9220{
9221 struct cnic_ops *c_ops;
9222 int rc = 0;
9223
9224 mutex_lock(&bp->cnic_mutex);
9225 c_ops = bp->cnic_ops;
9226 if (c_ops)
9227 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
9228 mutex_unlock(&bp->cnic_mutex);
9229
9230 return rc;
9231}
9232
9233static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
9234{
9235 struct cnic_ops *c_ops;
9236 int rc = 0;
9237
9238 rcu_read_lock();
9239 c_ops = rcu_dereference(bp->cnic_ops);
9240 if (c_ops)
9241 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
9242 rcu_read_unlock();
9243
9244 return rc;
9245}
9246
9247/*
9248 * for commands that have no data
9249 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009250int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +00009251{
9252 struct cnic_ctl_info ctl = {0};
9253
9254 ctl.cmd = cmd;
9255
9256 return bnx2x_cnic_ctl_send(bp, &ctl);
9257}
9258
9259static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid)
9260{
9261 struct cnic_ctl_info ctl;
9262
9263 /* first we tell CNIC and only then we count this as a completion */
9264 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
9265 ctl.data.comp.cid = cid;
9266
9267 bnx2x_cnic_ctl_send_bh(bp, &ctl);
9268 bnx2x_cnic_sp_post(bp, 1);
9269}
9270
9271static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
9272{
9273 struct bnx2x *bp = netdev_priv(dev);
9274 int rc = 0;
9275
9276 switch (ctl->cmd) {
9277 case DRV_CTL_CTXTBL_WR_CMD: {
9278 u32 index = ctl->data.io.offset;
9279 dma_addr_t addr = ctl->data.io.dma_addr;
9280
9281 bnx2x_ilt_wr(bp, index, addr);
9282 break;
9283 }
9284
9285 case DRV_CTL_COMPLETION_CMD: {
9286 int count = ctl->data.comp.comp_count;
9287
9288 bnx2x_cnic_sp_post(bp, count);
9289 break;
9290 }
9291
9292 /* rtnl_lock is held. */
9293 case DRV_CTL_START_L2_CMD: {
9294 u32 cli = ctl->data.ring.client_id;
9295
9296 bp->rx_mode_cl_mask |= (1 << cli);
9297 bnx2x_set_storm_rx_mode(bp);
9298 break;
9299 }
9300
9301 /* rtnl_lock is held. */
9302 case DRV_CTL_STOP_L2_CMD: {
9303 u32 cli = ctl->data.ring.client_id;
9304
9305 bp->rx_mode_cl_mask &= ~(1 << cli);
9306 bnx2x_set_storm_rx_mode(bp);
9307 break;
9308 }
9309
9310 default:
9311 BNX2X_ERR("unknown command %x\n", ctl->cmd);
9312 rc = -EINVAL;
9313 }
9314
9315 return rc;
9316}
9317
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009318void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +00009319{
9320 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
9321
9322 if (bp->flags & USING_MSIX_FLAG) {
9323 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
9324 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
9325 cp->irq_arr[0].vector = bp->msix_table[1].vector;
9326 } else {
9327 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
9328 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
9329 }
9330 cp->irq_arr[0].status_blk = bp->cnic_sb;
9331 cp->irq_arr[0].status_blk_num = CNIC_SB_ID(bp);
9332 cp->irq_arr[1].status_blk = bp->def_status_blk;
9333 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
9334
9335 cp->num_irq = 2;
9336}
9337
9338static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
9339 void *data)
9340{
9341 struct bnx2x *bp = netdev_priv(dev);
9342 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
9343
9344 if (ops == NULL)
9345 return -EINVAL;
9346
9347 if (atomic_read(&bp->intr_sem) != 0)
9348 return -EBUSY;
9349
9350 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
9351 if (!bp->cnic_kwq)
9352 return -ENOMEM;
9353
9354 bp->cnic_kwq_cons = bp->cnic_kwq;
9355 bp->cnic_kwq_prod = bp->cnic_kwq;
9356 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
9357
9358 bp->cnic_spq_pending = 0;
9359 bp->cnic_kwq_pending = 0;
9360
9361 bp->cnic_data = data;
9362
9363 cp->num_irq = 0;
9364 cp->drv_state = CNIC_DRV_STATE_REGD;
9365
9366 bnx2x_init_sb(bp, bp->cnic_sb, bp->cnic_sb_mapping, CNIC_SB_ID(bp));
9367
9368 bnx2x_setup_cnic_irq_info(bp);
9369 bnx2x_set_iscsi_eth_mac_addr(bp, 1);
9370 bp->cnic_flags |= BNX2X_CNIC_FLAG_MAC_SET;
9371 rcu_assign_pointer(bp->cnic_ops, ops);
9372
9373 return 0;
9374}
9375
9376static int bnx2x_unregister_cnic(struct net_device *dev)
9377{
9378 struct bnx2x *bp = netdev_priv(dev);
9379 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
9380
9381 mutex_lock(&bp->cnic_mutex);
9382 if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
9383 bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
9384 bnx2x_set_iscsi_eth_mac_addr(bp, 0);
9385 }
9386 cp->drv_state = 0;
9387 rcu_assign_pointer(bp->cnic_ops, NULL);
9388 mutex_unlock(&bp->cnic_mutex);
9389 synchronize_rcu();
9390 kfree(bp->cnic_kwq);
9391 bp->cnic_kwq = NULL;
9392
9393 return 0;
9394}
9395
9396struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
9397{
9398 struct bnx2x *bp = netdev_priv(dev);
9399 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
9400
9401 cp->drv_owner = THIS_MODULE;
9402 cp->chip_id = CHIP_ID(bp);
9403 cp->pdev = bp->pdev;
9404 cp->io_base = bp->regview;
9405 cp->io_base2 = bp->doorbells;
9406 cp->max_kwqe_pending = 8;
9407 cp->ctx_blk_size = CNIC_CTX_PER_ILT * sizeof(union cdu_context);
9408 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + 1;
9409 cp->ctx_tbl_len = CNIC_ILT_LINES;
9410 cp->starting_cid = BCM_CNIC_CID_START;
9411 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
9412 cp->drv_ctl = bnx2x_drv_ctl;
9413 cp->drv_register_cnic = bnx2x_register_cnic;
9414 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
9415
9416 return cp;
9417}
9418EXPORT_SYMBOL(bnx2x_cnic_probe);
9419
9420#endif /* BCM_CNIC */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009421