]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
bnx2x: enable inta on the pci bus when used
[mirror_ubuntu-eoan-kernel.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_main.c
CommitLineData
34f80b04 1/* bnx2x_main.c: Broadcom Everest network driver.
a2fbb9ea 2 *
85b26ea1 3 * Copyright (c) 2007-2012 Broadcom Corporation
a2fbb9ea
ET
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
24e3fcef
EG
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
a2fbb9ea
ET
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
ca00392c 13 * Slowpath and fastpath rework by Vladislav Zolotarov
c14423fe 14 * Statistics and Link management by Yitchak Gertner
a2fbb9ea
ET
15 *
16 */
17
f1deab50
JP
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
a2fbb9ea
ET
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/kernel.h>
23#include <linux/device.h> /* for dev_info() */
24#include <linux/timer.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
a2fbb9ea
ET
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/dma-mapping.h>
35#include <linux/bitops.h>
36#include <linux/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
0c6671b0 42#include <linux/if_vlan.h>
a2fbb9ea 43#include <net/ip.h>
619c5cb6 44#include <net/ipv6.h>
a2fbb9ea
ET
45#include <net/tcp.h>
46#include <net/checksum.h>
34f80b04 47#include <net/ip6_checksum.h>
a2fbb9ea
ET
48#include <linux/workqueue.h>
49#include <linux/crc32.h>
34f80b04 50#include <linux/crc32c.h>
a2fbb9ea
ET
51#include <linux/prefetch.h>
52#include <linux/zlib.h>
a2fbb9ea 53#include <linux/io.h>
452427b0 54#include <linux/semaphore.h>
45229b42 55#include <linux/stringify.h>
7ab24bfd 56#include <linux/vmalloc.h>
a2fbb9ea 57
a2fbb9ea
ET
58#include "bnx2x.h"
59#include "bnx2x_init.h"
94a78b79 60#include "bnx2x_init_ops.h"
9f6c9258 61#include "bnx2x_cmn.h"
e4901dde 62#include "bnx2x_dcb.h"
042181f5 63#include "bnx2x_sp.h"
a2fbb9ea 64
94a78b79
VZ
65#include <linux/firmware.h>
66#include "bnx2x_fw_file_hdr.h"
67/* FW files */
45229b42
BH
68#define FW_FILE_VERSION \
69 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
70 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
71 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
72 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
560131f3
DK
73#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
74#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
f2e0899f 75#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
94a78b79 76
34f80b04
EG
77/* Time in jiffies before concluding the transmitter is hung */
78#define TX_TIMEOUT (5*HZ)
a2fbb9ea 79
53a10565 80static char version[] __devinitdata =
619c5cb6 81 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
82 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
83
24e3fcef 84MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 85MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
86 "BCM57710/57711/57711E/"
87 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
88 "57840/57840_MF Driver");
a2fbb9ea
ET
89MODULE_LICENSE("GPL");
90MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
91MODULE_FIRMWARE(FW_FILE_NAME_E1);
92MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 93MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 94
555f6c78
EG
95static int multi_mode = 1;
96module_param(multi_mode, int, 0);
ca00392c
EG
97MODULE_PARM_DESC(multi_mode, " Multi queue mode "
98 "(0 Disable; 1 Enable (default))");
99
d6214d7a 100int num_queues;
54b9ddaa
VZ
101module_param(num_queues, int, 0);
102MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
103 " (default is as a number of CPUs)");
555f6c78 104
19680c48 105static int disable_tpa;
19680c48 106module_param(disable_tpa, int, 0);
9898f86d 107MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 108
9ee3d37b
DK
109#define INT_MODE_INTx 1
110#define INT_MODE_MSI 2
8badd27a
EG
111static int int_mode;
112module_param(int_mode, int, 0);
619c5cb6 113MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 114 "(1 INT#x; 2 MSI)");
8badd27a 115
a18f5128
EG
116static int dropless_fc;
117module_param(dropless_fc, int, 0);
118MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
119
8d5726c4
EG
120static int mrrs = -1;
121module_param(mrrs, int, 0);
122MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
123
9898f86d 124static int debug;
a2fbb9ea 125module_param(debug, int, 0);
9898f86d
EG
126MODULE_PARM_DESC(debug, " Default debug msglevel");
127
a2fbb9ea 128
619c5cb6
VZ
129
130struct workqueue_struct *bnx2x_wq;
ec6ba945 131
a2fbb9ea
ET
132enum bnx2x_board_type {
133 BCM57710 = 0,
619c5cb6
VZ
134 BCM57711,
135 BCM57711E,
136 BCM57712,
137 BCM57712_MF,
138 BCM57800,
139 BCM57800_MF,
140 BCM57810,
141 BCM57810_MF,
142 BCM57840,
143 BCM57840_MF
a2fbb9ea
ET
144};
145
34f80b04 146/* indexed by board_type, above */
53a10565 147static struct {
a2fbb9ea
ET
148 char *name;
149} board_info[] __devinitdata = {
619c5cb6
VZ
150 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
151 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
152 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
153 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
154 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
155 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
156 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
157 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
158 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
159 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
160 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
161 "Ethernet Multi Function"}
a2fbb9ea
ET
162};
163
619c5cb6
VZ
164#ifndef PCI_DEVICE_ID_NX2_57710
165#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
166#endif
167#ifndef PCI_DEVICE_ID_NX2_57711
168#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
169#endif
170#ifndef PCI_DEVICE_ID_NX2_57711E
171#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
172#endif
173#ifndef PCI_DEVICE_ID_NX2_57712
174#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
175#endif
176#ifndef PCI_DEVICE_ID_NX2_57712_MF
177#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
178#endif
179#ifndef PCI_DEVICE_ID_NX2_57800
180#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
181#endif
182#ifndef PCI_DEVICE_ID_NX2_57800_MF
183#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
184#endif
185#ifndef PCI_DEVICE_ID_NX2_57810
186#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
187#endif
188#ifndef PCI_DEVICE_ID_NX2_57810_MF
189#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
190#endif
191#ifndef PCI_DEVICE_ID_NX2_57840
192#define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
193#endif
194#ifndef PCI_DEVICE_ID_NX2_57840_MF
195#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
196#endif
a3aa1884 197static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
198 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
199 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
200 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 201 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6
VZ
202 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
203 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
204 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
205 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
206 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
207 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
208 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
a2fbb9ea
ET
209 { 0 }
210};
211
212MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
213
452427b0
YM
214/* Global resources for unloading a previously loaded device */
215#define BNX2X_PREV_WAIT_NEEDED 1
216static DEFINE_SEMAPHORE(bnx2x_prev_sem);
217static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
218/****************************************************************************
219* General service functions
220****************************************************************************/
221
619c5cb6
VZ
222static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
223 u32 addr, dma_addr_t mapping)
224{
225 REG_WR(bp, addr, U64_LO(mapping));
226 REG_WR(bp, addr + 4, U64_HI(mapping));
227}
228
229static inline void storm_memset_spq_addr(struct bnx2x *bp,
230 dma_addr_t mapping, u16 abs_fid)
231{
232 u32 addr = XSEM_REG_FAST_MEMORY +
233 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
234
235 __storm_memset_dma_mapping(bp, addr, mapping);
236}
237
238static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
239 u16 pf_id)
523224a3 240{
619c5cb6
VZ
241 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
242 pf_id);
243 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
244 pf_id);
245 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
246 pf_id);
247 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
248 pf_id);
523224a3
DK
249}
250
619c5cb6
VZ
251static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
252 u8 enable)
253{
254 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
255 enable);
256 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
257 enable);
258 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
259 enable);
260 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
261 enable);
262}
523224a3
DK
263
264static inline void storm_memset_eq_data(struct bnx2x *bp,
265 struct event_ring_data *eq_data,
266 u16 pfid)
267{
268 size_t size = sizeof(struct event_ring_data);
269
270 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
271
272 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
273}
274
275static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
276 u16 pfid)
277{
278 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
279 REG_WR16(bp, addr, eq_prod);
280}
281
a2fbb9ea
ET
282/* used only at init
283 * locking is done by mcp
284 */
8d96286a 285static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
286{
287 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
288 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
289 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
290 PCICFG_VENDOR_ID_OFFSET);
291}
292
a2fbb9ea
ET
293static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
294{
295 u32 val;
296
297 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
298 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
299 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
300 PCICFG_VENDOR_ID_OFFSET);
301
302 return val;
303}
a2fbb9ea 304
f2e0899f
DK
305#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
306#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
307#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
308#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
309#define DMAE_DP_DST_NONE "dst_addr [none]"
310
f2e0899f 311
a2fbb9ea 312/* copy command into DMAE command memory and set DMAE command go */
6c719d00 313void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
314{
315 u32 cmd_offset;
316 int i;
317
318 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
319 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
320 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
321 }
322 REG_WR(bp, dmae_reg_go_c[idx], 1);
323}
324
f2e0899f 325u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 326{
f2e0899f
DK
327 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
328 DMAE_CMD_C_ENABLE);
329}
ad8d3948 330
f2e0899f
DK
331u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
332{
333 return opcode & ~DMAE_CMD_SRC_RESET;
334}
ad8d3948 335
f2e0899f
DK
336u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
337 bool with_comp, u8 comp_type)
338{
339 u32 opcode = 0;
340
341 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
342 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 343
f2e0899f
DK
344 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
345
346 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
347 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
348 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 349 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 350
a2fbb9ea 351#ifdef __BIG_ENDIAN
f2e0899f 352 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 353#else
f2e0899f 354 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 355#endif
f2e0899f
DK
356 if (with_comp)
357 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
358 return opcode;
359}
360
8d96286a 361static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
362 struct dmae_command *dmae,
363 u8 src_type, u8 dst_type)
f2e0899f
DK
364{
365 memset(dmae, 0, sizeof(struct dmae_command));
366
367 /* set the opcode */
368 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
369 true, DMAE_COMP_PCI);
370
371 /* fill in the completion parameters */
372 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
373 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
374 dmae->comp_val = DMAE_COMP_VAL;
375}
376
377/* issue a dmae command over the init-channel and wailt for completion */
8d96286a 378static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
379 struct dmae_command *dmae)
f2e0899f
DK
380{
381 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
5e374b5a 382 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
383 int rc = 0;
384
619c5cb6
VZ
385 /*
386 * Lock the dmae channel. Disable BHs to prevent a dead-lock
387 * as long as this code is called both from syscall context and
388 * from ndo_set_rx_mode() flow that may be called from BH.
389 */
6e30dd4e 390 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 391
f2e0899f 392 /* reset completion */
a2fbb9ea
ET
393 *wb_comp = 0;
394
f2e0899f
DK
395 /* post the command on the channel used for initializations */
396 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 397
f2e0899f 398 /* wait for completion */
a2fbb9ea 399 udelay(5);
f2e0899f 400 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 401
95c6c616
AE
402 if (!cnt ||
403 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
404 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 405 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
406 rc = DMAE_TIMEOUT;
407 goto unlock;
a2fbb9ea 408 }
ad8d3948 409 cnt--;
f2e0899f 410 udelay(50);
a2fbb9ea 411 }
f2e0899f
DK
412 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
413 BNX2X_ERR("DMAE PCI error!\n");
414 rc = DMAE_PCI_ERROR;
415 }
416
f2e0899f 417unlock:
6e30dd4e 418 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
419 return rc;
420}
421
422void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
423 u32 len32)
424{
425 struct dmae_command dmae;
426
427 if (!bp->dmae_ready) {
428 u32 *data = bnx2x_sp(bp, wb_data[0]);
429
127a425e
AE
430 if (CHIP_IS_E1(bp))
431 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
432 else
433 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
434 return;
435 }
436
437 /* set opcode and fixed command fields */
438 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
439
440 /* fill in addresses and len */
441 dmae.src_addr_lo = U64_LO(dma_addr);
442 dmae.src_addr_hi = U64_HI(dma_addr);
443 dmae.dst_addr_lo = dst_addr >> 2;
444 dmae.dst_addr_hi = 0;
445 dmae.len = len32;
446
f2e0899f
DK
447 /* issue the command and wait for completion */
448 bnx2x_issue_dmae_with_comp(bp, &dmae);
a2fbb9ea
ET
449}
450
c18487ee 451void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 452{
5ff7b6d4 453 struct dmae_command dmae;
ad8d3948
EG
454
455 if (!bp->dmae_ready) {
456 u32 *data = bnx2x_sp(bp, wb_data[0]);
457 int i;
458
51c1a580 459 if (CHIP_IS_E1(bp))
127a425e
AE
460 for (i = 0; i < len32; i++)
461 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 462 else
127a425e
AE
463 for (i = 0; i < len32; i++)
464 data[i] = REG_RD(bp, src_addr + i*4);
465
ad8d3948
EG
466 return;
467 }
468
f2e0899f
DK
469 /* set opcode and fixed command fields */
470 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 471
f2e0899f 472 /* fill in addresses and len */
5ff7b6d4
EG
473 dmae.src_addr_lo = src_addr >> 2;
474 dmae.src_addr_hi = 0;
475 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
476 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
477 dmae.len = len32;
ad8d3948 478
f2e0899f
DK
479 /* issue the command and wait for completion */
480 bnx2x_issue_dmae_with_comp(bp, &dmae);
ad8d3948
EG
481}
482
8d96286a 483static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
484 u32 addr, u32 len)
573f2035 485{
02e3c6cb 486 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
487 int offset = 0;
488
02e3c6cb 489 while (len > dmae_wr_max) {
573f2035 490 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
491 addr + offset, dmae_wr_max);
492 offset += dmae_wr_max * 4;
493 len -= dmae_wr_max;
573f2035
EG
494 }
495
496 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
497}
498
a2fbb9ea
ET
499static int bnx2x_mc_assert(struct bnx2x *bp)
500{
a2fbb9ea 501 char last_idx;
34f80b04
EG
502 int i, rc = 0;
503 u32 row0, row1, row2, row3;
504
505 /* XSTORM */
506 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
507 XSTORM_ASSERT_LIST_INDEX_OFFSET);
508 if (last_idx)
509 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
510
511 /* print the asserts */
512 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
513
514 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
515 XSTORM_ASSERT_LIST_OFFSET(i));
516 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
517 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
518 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
519 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
520 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
521 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
522
523 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 524 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
525 i, row3, row2, row1, row0);
526 rc++;
527 } else {
528 break;
529 }
530 }
531
532 /* TSTORM */
533 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
534 TSTORM_ASSERT_LIST_INDEX_OFFSET);
535 if (last_idx)
536 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
537
538 /* print the asserts */
539 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
540
541 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
542 TSTORM_ASSERT_LIST_OFFSET(i));
543 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
544 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
545 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
546 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
547 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
548 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
549
550 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 551 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
552 i, row3, row2, row1, row0);
553 rc++;
554 } else {
555 break;
556 }
557 }
558
559 /* CSTORM */
560 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
561 CSTORM_ASSERT_LIST_INDEX_OFFSET);
562 if (last_idx)
563 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
564
565 /* print the asserts */
566 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
567
568 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
569 CSTORM_ASSERT_LIST_OFFSET(i));
570 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
571 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
572 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
573 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
574 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
575 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
576
577 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 578 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
579 i, row3, row2, row1, row0);
580 rc++;
581 } else {
582 break;
583 }
584 }
585
586 /* USTORM */
587 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
588 USTORM_ASSERT_LIST_INDEX_OFFSET);
589 if (last_idx)
590 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
591
592 /* print the asserts */
593 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
594
595 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
596 USTORM_ASSERT_LIST_OFFSET(i));
597 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
598 USTORM_ASSERT_LIST_OFFSET(i) + 4);
599 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
600 USTORM_ASSERT_LIST_OFFSET(i) + 8);
601 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
602 USTORM_ASSERT_LIST_OFFSET(i) + 12);
603
604 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 605 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
606 i, row3, row2, row1, row0);
607 rc++;
608 } else {
609 break;
a2fbb9ea
ET
610 }
611 }
34f80b04 612
a2fbb9ea
ET
613 return rc;
614}
c14423fe 615
7a25cc73 616void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 617{
7a25cc73 618 u32 addr, val;
a2fbb9ea 619 u32 mark, offset;
4781bfad 620 __be32 data[9];
a2fbb9ea 621 int word;
f2e0899f 622 u32 trace_shmem_base;
2145a920
VZ
623 if (BP_NOMCP(bp)) {
624 BNX2X_ERR("NO MCP - can not dump\n");
625 return;
626 }
7a25cc73
DK
627 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
628 (bp->common.bc_ver & 0xff0000) >> 16,
629 (bp->common.bc_ver & 0xff00) >> 8,
630 (bp->common.bc_ver & 0xff));
631
632 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
633 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 634 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 635
f2e0899f
DK
636 if (BP_PATH(bp) == 0)
637 trace_shmem_base = bp->common.shmem_base;
638 else
639 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
de128804
DK
640 addr = trace_shmem_base - 0x800;
641
642 /* validate TRCB signature */
643 mark = REG_RD(bp, addr);
644 if (mark != MFW_TRACE_SIGNATURE) {
645 BNX2X_ERR("Trace buffer signature is missing.");
646 return ;
647 }
648
649 /* read cyclic buffer pointer */
650 addr += 4;
cdaa7cb8 651 mark = REG_RD(bp, addr);
f2e0899f
DK
652 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
653 + ((mark + 0x3) & ~0x3) - 0x08000000;
7a25cc73 654 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 655
7a25cc73 656 printk("%s", lvl);
f2e0899f 657 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 658 for (word = 0; word < 8; word++)
cdaa7cb8 659 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 660 data[8] = 0x0;
7995c64e 661 pr_cont("%s", (char *)data);
a2fbb9ea 662 }
cdaa7cb8 663 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 664 for (word = 0; word < 8; word++)
cdaa7cb8 665 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 666 data[8] = 0x0;
7995c64e 667 pr_cont("%s", (char *)data);
a2fbb9ea 668 }
7a25cc73
DK
669 printk("%s" "end of fw dump\n", lvl);
670}
671
672static inline void bnx2x_fw_dump(struct bnx2x *bp)
673{
674 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
675}
676
6c719d00 677void bnx2x_panic_dump(struct bnx2x *bp)
a2fbb9ea
ET
678{
679 int i;
523224a3
DK
680 u16 j;
681 struct hc_sp_status_block_data sp_sb_data;
682 int func = BP_FUNC(bp);
683#ifdef BNX2X_STOP_ON_ERROR
684 u16 start = 0, end = 0;
6383c0b3 685 u8 cos;
523224a3 686#endif
a2fbb9ea 687
66e855f3 688 bp->stats_state = STATS_STATE_DISABLED;
7a752993 689 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
690 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
691
a2fbb9ea
ET
692 BNX2X_ERR("begin crash dump -----------------\n");
693
8440d2b6
EG
694 /* Indices */
695 /* Common */
51c1a580 696 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
619c5cb6
VZ
697 bp->def_idx, bp->def_att_idx, bp->attn_state,
698 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
699 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
700 bp->def_status_blk->atten_status_block.attn_bits,
701 bp->def_status_blk->atten_status_block.attn_bits_ack,
702 bp->def_status_blk->atten_status_block.status_block_id,
703 bp->def_status_blk->atten_status_block.attn_bits_index);
704 BNX2X_ERR(" def (");
705 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
706 pr_cont("0x%x%s",
f1deab50
JP
707 bp->def_status_blk->sp_sb.index_values[i],
708 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
709
710 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
711 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
712 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
713 i*sizeof(u32));
714
f1deab50 715 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
523224a3
DK
716 sp_sb_data.igu_sb_id,
717 sp_sb_data.igu_seg_id,
718 sp_sb_data.p_func.pf_id,
719 sp_sb_data.p_func.vnic_id,
720 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
721 sp_sb_data.p_func.vf_valid,
722 sp_sb_data.state);
523224a3 723
8440d2b6 724
ec6ba945 725 for_each_eth_queue(bp, i) {
a2fbb9ea 726 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 727 int loop;
f2e0899f 728 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
729 struct hc_status_block_data_e1x sb_data_e1x;
730 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
731 CHIP_IS_E1x(bp) ?
732 sb_data_e1x.common.state_machine :
733 sb_data_e2.common.state_machine;
523224a3 734 struct hc_index_data *hc_index_p =
619c5cb6
VZ
735 CHIP_IS_E1x(bp) ?
736 sb_data_e1x.index_data :
737 sb_data_e2.index_data;
6383c0b3 738 u8 data_size, cos;
523224a3 739 u32 *sb_data_p;
6383c0b3 740 struct bnx2x_fp_txdata txdata;
523224a3
DK
741
742 /* Rx */
51c1a580 743 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
8440d2b6 744 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 745 fp->rx_comp_prod,
66e855f3 746 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 747 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 748 fp->rx_sge_prod, fp->last_max_sge,
523224a3 749 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 750
523224a3 751 /* Tx */
6383c0b3
AE
752 for_each_cos_in_tx_queue(fp, cos)
753 {
754 txdata = fp->txdata[cos];
51c1a580 755 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
6383c0b3
AE
756 i, txdata.tx_pkt_prod,
757 txdata.tx_pkt_cons, txdata.tx_bd_prod,
758 txdata.tx_bd_cons,
759 le16_to_cpu(*txdata.tx_cons_sb));
760 }
523224a3 761
619c5cb6
VZ
762 loop = CHIP_IS_E1x(bp) ?
763 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
764
765 /* host sb data */
766
ec6ba945
VZ
767#ifdef BCM_CNIC
768 if (IS_FCOE_FP(fp))
769 continue;
770#endif
523224a3
DK
771 BNX2X_ERR(" run indexes (");
772 for (j = 0; j < HC_SB_MAX_SM; j++)
773 pr_cont("0x%x%s",
774 fp->sb_running_index[j],
775 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
776
777 BNX2X_ERR(" indexes (");
778 for (j = 0; j < loop; j++)
779 pr_cont("0x%x%s",
780 fp->sb_index_values[j],
781 (j == loop - 1) ? ")" : " ");
782 /* fw sb data */
619c5cb6
VZ
783 data_size = CHIP_IS_E1x(bp) ?
784 sizeof(struct hc_status_block_data_e1x) :
785 sizeof(struct hc_status_block_data_e2);
523224a3 786 data_size /= sizeof(u32);
619c5cb6
VZ
787 sb_data_p = CHIP_IS_E1x(bp) ?
788 (u32 *)&sb_data_e1x :
789 (u32 *)&sb_data_e2;
523224a3
DK
790 /* copy sb data in here */
791 for (j = 0; j < data_size; j++)
792 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
793 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
794 j * sizeof(u32));
795
619c5cb6 796 if (!CHIP_IS_E1x(bp)) {
51c1a580 797 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
f2e0899f
DK
798 sb_data_e2.common.p_func.pf_id,
799 sb_data_e2.common.p_func.vf_id,
800 sb_data_e2.common.p_func.vf_valid,
801 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
802 sb_data_e2.common.same_igu_sb_1b,
803 sb_data_e2.common.state);
f2e0899f 804 } else {
51c1a580 805 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
f2e0899f
DK
806 sb_data_e1x.common.p_func.pf_id,
807 sb_data_e1x.common.p_func.vf_id,
808 sb_data_e1x.common.p_func.vf_valid,
809 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
810 sb_data_e1x.common.same_igu_sb_1b,
811 sb_data_e1x.common.state);
f2e0899f 812 }
523224a3
DK
813
814 /* SB_SMs data */
815 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
816 pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
817 j, hc_sm_p[j].__flags,
818 hc_sm_p[j].igu_sb_id,
819 hc_sm_p[j].igu_seg_id,
820 hc_sm_p[j].time_to_expire,
821 hc_sm_p[j].timer_value);
523224a3
DK
822 }
823
824 /* Indecies data */
825 for (j = 0; j < loop; j++) {
51c1a580 826 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
827 hc_index_p[j].flags,
828 hc_index_p[j].timeout);
829 }
8440d2b6 830 }
a2fbb9ea 831
523224a3 832#ifdef BNX2X_STOP_ON_ERROR
8440d2b6
EG
833 /* Rings */
834 /* Rx */
ec6ba945 835 for_each_rx_queue(bp, i) {
8440d2b6 836 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
837
838 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
839 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 840 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
841 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
842 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
843
c3eefaf6 844 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 845 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
846 }
847
3196a88a
EG
848 start = RX_SGE(fp->rx_sge_prod);
849 end = RX_SGE(fp->last_max_sge);
8440d2b6 850 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
851 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
852 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
853
c3eefaf6
EG
854 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
855 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
856 }
857
a2fbb9ea
ET
858 start = RCQ_BD(fp->rx_comp_cons - 10);
859 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 860 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
861 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
862
c3eefaf6
EG
863 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
864 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
865 }
866 }
867
8440d2b6 868 /* Tx */
ec6ba945 869 for_each_tx_queue(bp, i) {
8440d2b6 870 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3
AE
871 for_each_cos_in_tx_queue(fp, cos) {
872 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
873
874 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
875 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
876 for (j = start; j != end; j = TX_BD(j + 1)) {
877 struct sw_tx_bd *sw_bd =
878 &txdata->tx_buf_ring[j];
879
51c1a580 880 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
881 i, cos, j, sw_bd->skb,
882 sw_bd->first_bd);
883 }
8440d2b6 884
6383c0b3
AE
885 start = TX_BD(txdata->tx_bd_cons - 10);
886 end = TX_BD(txdata->tx_bd_cons + 254);
887 for (j = start; j != end; j = TX_BD(j + 1)) {
888 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 889
51c1a580 890 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
891 i, cos, j, tx_bd[0], tx_bd[1],
892 tx_bd[2], tx_bd[3]);
893 }
8440d2b6
EG
894 }
895 }
523224a3 896#endif
34f80b04 897 bnx2x_fw_dump(bp);
a2fbb9ea
ET
898 bnx2x_mc_assert(bp);
899 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
900}
901
619c5cb6
VZ
902/*
903 * FLR Support for E2
904 *
905 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
906 * initialization.
907 */
908#define FLR_WAIT_USEC 10000 /* 10 miliseconds */
89db4ad8
AE
909#define FLR_WAIT_INTERVAL 50 /* usec */
910#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
911
912struct pbf_pN_buf_regs {
913 int pN;
914 u32 init_crd;
915 u32 crd;
916 u32 crd_freed;
917};
918
919struct pbf_pN_cmd_regs {
920 int pN;
921 u32 lines_occup;
922 u32 lines_freed;
923};
924
925static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
926 struct pbf_pN_buf_regs *regs,
927 u32 poll_count)
928{
929 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
930 u32 cur_cnt = poll_count;
931
932 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
933 crd = crd_start = REG_RD(bp, regs->crd);
934 init_crd = REG_RD(bp, regs->init_crd);
935
936 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
937 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
938 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
939
940 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
941 (init_crd - crd_start))) {
942 if (cur_cnt--) {
89db4ad8 943 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
944 crd = REG_RD(bp, regs->crd);
945 crd_freed = REG_RD(bp, regs->crd_freed);
946 } else {
947 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
948 regs->pN);
949 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
950 regs->pN, crd);
951 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
952 regs->pN, crd_freed);
953 break;
954 }
955 }
956 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 957 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
958}
959
960static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
961 struct pbf_pN_cmd_regs *regs,
962 u32 poll_count)
963{
964 u32 occup, to_free, freed, freed_start;
965 u32 cur_cnt = poll_count;
966
967 occup = to_free = REG_RD(bp, regs->lines_occup);
968 freed = freed_start = REG_RD(bp, regs->lines_freed);
969
970 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
971 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
972
973 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
974 if (cur_cnt--) {
89db4ad8 975 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
976 occup = REG_RD(bp, regs->lines_occup);
977 freed = REG_RD(bp, regs->lines_freed);
978 } else {
979 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
980 regs->pN);
981 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
982 regs->pN, occup);
983 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
984 regs->pN, freed);
985 break;
986 }
987 }
988 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 989 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
990}
991
992static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
993 u32 expected, u32 poll_count)
994{
995 u32 cur_cnt = poll_count;
996 u32 val;
997
998 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 999 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1000
1001 return val;
1002}
1003
1004static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1005 char *msg, u32 poll_cnt)
1006{
1007 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1008 if (val != 0) {
1009 BNX2X_ERR("%s usage count=%d\n", msg, val);
1010 return 1;
1011 }
1012 return 0;
1013}
1014
1015static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1016{
1017 /* adjust polling timeout */
1018 if (CHIP_REV_IS_EMUL(bp))
1019 return FLR_POLL_CNT * 2000;
1020
1021 if (CHIP_REV_IS_FPGA(bp))
1022 return FLR_POLL_CNT * 120;
1023
1024 return FLR_POLL_CNT;
1025}
1026
1027static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1028{
1029 struct pbf_pN_cmd_regs cmd_regs[] = {
1030 {0, (CHIP_IS_E3B0(bp)) ?
1031 PBF_REG_TQ_OCCUPANCY_Q0 :
1032 PBF_REG_P0_TQ_OCCUPANCY,
1033 (CHIP_IS_E3B0(bp)) ?
1034 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1035 PBF_REG_P0_TQ_LINES_FREED_CNT},
1036 {1, (CHIP_IS_E3B0(bp)) ?
1037 PBF_REG_TQ_OCCUPANCY_Q1 :
1038 PBF_REG_P1_TQ_OCCUPANCY,
1039 (CHIP_IS_E3B0(bp)) ?
1040 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1041 PBF_REG_P1_TQ_LINES_FREED_CNT},
1042 {4, (CHIP_IS_E3B0(bp)) ?
1043 PBF_REG_TQ_OCCUPANCY_LB_Q :
1044 PBF_REG_P4_TQ_OCCUPANCY,
1045 (CHIP_IS_E3B0(bp)) ?
1046 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1047 PBF_REG_P4_TQ_LINES_FREED_CNT}
1048 };
1049
1050 struct pbf_pN_buf_regs buf_regs[] = {
1051 {0, (CHIP_IS_E3B0(bp)) ?
1052 PBF_REG_INIT_CRD_Q0 :
1053 PBF_REG_P0_INIT_CRD ,
1054 (CHIP_IS_E3B0(bp)) ?
1055 PBF_REG_CREDIT_Q0 :
1056 PBF_REG_P0_CREDIT,
1057 (CHIP_IS_E3B0(bp)) ?
1058 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1059 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1060 {1, (CHIP_IS_E3B0(bp)) ?
1061 PBF_REG_INIT_CRD_Q1 :
1062 PBF_REG_P1_INIT_CRD,
1063 (CHIP_IS_E3B0(bp)) ?
1064 PBF_REG_CREDIT_Q1 :
1065 PBF_REG_P1_CREDIT,
1066 (CHIP_IS_E3B0(bp)) ?
1067 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1068 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1069 {4, (CHIP_IS_E3B0(bp)) ?
1070 PBF_REG_INIT_CRD_LB_Q :
1071 PBF_REG_P4_INIT_CRD,
1072 (CHIP_IS_E3B0(bp)) ?
1073 PBF_REG_CREDIT_LB_Q :
1074 PBF_REG_P4_CREDIT,
1075 (CHIP_IS_E3B0(bp)) ?
1076 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1077 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1078 };
1079
1080 int i;
1081
1082 /* Verify the command queues are flushed P0, P1, P4 */
1083 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1084 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1085
1086
1087 /* Verify the transmission buffers are flushed P0, P1, P4 */
1088 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1089 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1090}
1091
1092#define OP_GEN_PARAM(param) \
1093 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1094
1095#define OP_GEN_TYPE(type) \
1096 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1097
1098#define OP_GEN_AGG_VECT(index) \
1099 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1100
1101
1102static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1103 u32 poll_cnt)
1104{
1105 struct sdm_op_gen op_gen = {0};
1106
1107 u32 comp_addr = BAR_CSTRORM_INTMEM +
1108 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1109 int ret = 0;
1110
1111 if (REG_RD(bp, comp_addr)) {
89db4ad8 1112 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1113 return 1;
1114 }
1115
1116 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1117 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1118 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1119 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1120
89db4ad8 1121 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
619c5cb6
VZ
1122 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1123
1124 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1125 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1126 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1127 (REG_RD(bp, comp_addr)));
619c5cb6
VZ
1128 ret = 1;
1129 }
1130 /* Zero completion for nxt FLR */
1131 REG_WR(bp, comp_addr, 0);
1132
1133 return ret;
1134}
1135
1136static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1137{
1138 int pos;
1139 u16 status;
1140
77c98e6a 1141 pos = pci_pcie_cap(dev);
619c5cb6
VZ
1142 if (!pos)
1143 return false;
1144
1145 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1146 return status & PCI_EXP_DEVSTA_TRPND;
1147}
1148
1149/* PF FLR specific routines
1150*/
1151static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1152{
1153
1154 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1155 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1156 CFC_REG_NUM_LCIDS_INSIDE_PF,
1157 "CFC PF usage counter timed out",
1158 poll_cnt))
1159 return 1;
1160
1161
1162 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1163 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1164 DORQ_REG_PF_USAGE_CNT,
1165 "DQ PF usage counter timed out",
1166 poll_cnt))
1167 return 1;
1168
1169 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1170 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1171 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1172 "QM PF usage counter timed out",
1173 poll_cnt))
1174 return 1;
1175
1176 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1177 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1178 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1179 "Timers VNIC usage counter timed out",
1180 poll_cnt))
1181 return 1;
1182 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1183 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1184 "Timers NUM_SCANS usage counter timed out",
1185 poll_cnt))
1186 return 1;
1187
1188 /* Wait DMAE PF usage counter to zero */
1189 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1190 dmae_reg_go_c[INIT_DMAE_C(bp)],
1191 "DMAE dommand register timed out",
1192 poll_cnt))
1193 return 1;
1194
1195 return 0;
1196}
1197
1198static void bnx2x_hw_enable_status(struct bnx2x *bp)
1199{
1200 u32 val;
1201
1202 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1203 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1204
1205 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1206 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1207
1208 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1209 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1210
1211 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1212 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1213
1214 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1215 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1216
1217 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1218 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1219
1220 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1221 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1222
1223 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1224 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1225 val);
1226}
1227
1228static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1229{
1230 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1231
1232 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1233
1234 /* Re-enable PF target read access */
1235 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1236
1237 /* Poll HW usage counters */
89db4ad8 1238 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1239 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1240 return -EBUSY;
1241
1242 /* Zero the igu 'trailing edge' and 'leading edge' */
1243
1244 /* Send the FW cleanup command */
1245 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1246 return -EBUSY;
1247
1248 /* ATC cleanup */
1249
1250 /* Verify TX hw is flushed */
1251 bnx2x_tx_hw_flushed(bp, poll_cnt);
1252
1253 /* Wait 100ms (not adjusted according to platform) */
1254 msleep(100);
1255
1256 /* Verify no pending pci transactions */
1257 if (bnx2x_is_pcie_pending(bp->pdev))
1258 BNX2X_ERR("PCIE Transactions still pending\n");
1259
1260 /* Debug */
1261 bnx2x_hw_enable_status(bp);
1262
1263 /*
1264 * Master enable - Due to WB DMAE writes performed before this
1265 * register is re-initialized as part of the regular function init
1266 */
1267 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1268
1269 return 0;
1270}
1271
f2e0899f 1272static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1273{
34f80b04 1274 int port = BP_PORT(bp);
a2fbb9ea
ET
1275 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1276 u32 val = REG_RD(bp, addr);
1277 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1278 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
a2fbb9ea
ET
1279
1280 if (msix) {
8badd27a
EG
1281 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1282 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1283 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1284 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
8badd27a
EG
1285 } else if (msi) {
1286 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1287 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1288 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1289 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea
ET
1290 } else {
1291 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1292 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1293 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1294 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1295
a0fd065c 1296 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1297 DP(NETIF_MSG_IFUP,
1298 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1299
a0fd065c 1300 REG_WR(bp, addr, val);
615f8fd9 1301
a0fd065c
DK
1302 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1303 }
a2fbb9ea
ET
1304 }
1305
a0fd065c
DK
1306 if (CHIP_IS_E1(bp))
1307 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1308
51c1a580
MS
1309 DP(NETIF_MSG_IFUP,
1310 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1311 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1312
1313 REG_WR(bp, addr, val);
37dbbf32
EG
1314 /*
1315 * Ensure that HC_CONFIG is written before leading/trailing edge config
1316 */
1317 mmiowb();
1318 barrier();
34f80b04 1319
f2e0899f 1320 if (!CHIP_IS_E1(bp)) {
34f80b04 1321 /* init leading/trailing edge */
fb3bff17 1322 if (IS_MF(bp)) {
3395a033 1323 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1324 if (bp->port.pmf)
4acac6a5
EG
1325 /* enable nig and gpio3 attention */
1326 val |= 0x1100;
34f80b04
EG
1327 } else
1328 val = 0xffff;
1329
1330 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1331 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1332 }
37dbbf32
EG
1333
1334 /* Make sure that interrupts are indeed enabled from here on */
1335 mmiowb();
a2fbb9ea
ET
1336}
1337
f2e0899f
DK
1338static void bnx2x_igu_int_enable(struct bnx2x *bp)
1339{
1340 u32 val;
1341 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1342 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1343
1344 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1345
1346 if (msix) {
1347 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1348 IGU_PF_CONF_SINGLE_ISR_EN);
1349 val |= (IGU_PF_CONF_FUNC_EN |
1350 IGU_PF_CONF_MSI_MSIX_EN |
1351 IGU_PF_CONF_ATTN_BIT_EN);
1352 } else if (msi) {
1353 val &= ~IGU_PF_CONF_INT_LINE_EN;
1354 val |= (IGU_PF_CONF_FUNC_EN |
1355 IGU_PF_CONF_MSI_MSIX_EN |
1356 IGU_PF_CONF_ATTN_BIT_EN |
1357 IGU_PF_CONF_SINGLE_ISR_EN);
1358 } else {
1359 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1360 val |= (IGU_PF_CONF_FUNC_EN |
1361 IGU_PF_CONF_INT_LINE_EN |
1362 IGU_PF_CONF_ATTN_BIT_EN |
1363 IGU_PF_CONF_SINGLE_ISR_EN);
1364 }
1365
51c1a580 1366 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1367 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1368
1369 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1370
79a8557a
YM
1371 if (val & IGU_PF_CONF_INT_LINE_EN)
1372 pci_intx(bp->pdev, true);
1373
f2e0899f
DK
1374 barrier();
1375
1376 /* init leading/trailing edge */
1377 if (IS_MF(bp)) {
3395a033 1378 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1379 if (bp->port.pmf)
1380 /* enable nig and gpio3 attention */
1381 val |= 0x1100;
1382 } else
1383 val = 0xffff;
1384
1385 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1386 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1387
1388 /* Make sure that interrupts are indeed enabled from here on */
1389 mmiowb();
1390}
1391
1392void bnx2x_int_enable(struct bnx2x *bp)
1393{
1394 if (bp->common.int_block == INT_BLOCK_HC)
1395 bnx2x_hc_int_enable(bp);
1396 else
1397 bnx2x_igu_int_enable(bp);
1398}
1399
1400static void bnx2x_hc_int_disable(struct bnx2x *bp)
a2fbb9ea 1401{
34f80b04 1402 int port = BP_PORT(bp);
a2fbb9ea
ET
1403 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1404 u32 val = REG_RD(bp, addr);
1405
a0fd065c
DK
1406 /*
1407 * in E1 we must use only PCI configuration space to disable
1408 * MSI/MSIX capablility
1409 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1410 */
1411 if (CHIP_IS_E1(bp)) {
1412 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1413 * Use mask register to prevent from HC sending interrupts
1414 * after we exit the function
1415 */
1416 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1417
1418 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1419 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1420 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1421 } else
1422 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1423 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1424 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1425 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea 1426
51c1a580
MS
1427 DP(NETIF_MSG_IFDOWN,
1428 "write %x to HC %d (addr 0x%x)\n",
a2fbb9ea
ET
1429 val, port, addr);
1430
8badd27a
EG
1431 /* flush all outstanding writes */
1432 mmiowb();
1433
a2fbb9ea
ET
1434 REG_WR(bp, addr, val);
1435 if (REG_RD(bp, addr) != val)
1436 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1437}
1438
f2e0899f
DK
1439static void bnx2x_igu_int_disable(struct bnx2x *bp)
1440{
1441 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1442
1443 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1444 IGU_PF_CONF_INT_LINE_EN |
1445 IGU_PF_CONF_ATTN_BIT_EN);
1446
51c1a580 1447 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
f2e0899f
DK
1448
1449 /* flush all outstanding writes */
1450 mmiowb();
1451
1452 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1453 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1454 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1455}
1456
6383c0b3 1457void bnx2x_int_disable(struct bnx2x *bp)
f2e0899f
DK
1458{
1459 if (bp->common.int_block == INT_BLOCK_HC)
1460 bnx2x_hc_int_disable(bp);
1461 else
1462 bnx2x_igu_int_disable(bp);
1463}
1464
9f6c9258 1465void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1466{
a2fbb9ea 1467 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1468 int i, offset;
a2fbb9ea 1469
f8ef6e44
YG
1470 if (disable_hw)
1471 /* prevent the HW from sending interrupts */
1472 bnx2x_int_disable(bp);
a2fbb9ea
ET
1473
1474 /* make sure all ISRs are done */
1475 if (msix) {
8badd27a
EG
1476 synchronize_irq(bp->msix_table[0].vector);
1477 offset = 1;
37b091ba
MC
1478#ifdef BCM_CNIC
1479 offset++;
1480#endif
ec6ba945 1481 for_each_eth_queue(bp, i)
754a2f52 1482 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1483 } else
1484 synchronize_irq(bp->pdev->irq);
1485
1486 /* make sure sp_task is not running */
1cf167f2 1487 cancel_delayed_work(&bp->sp_task);
3deb8167 1488 cancel_delayed_work(&bp->period_task);
1cf167f2 1489 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1490}
1491
34f80b04 1492/* fast path */
a2fbb9ea
ET
1493
1494/*
34f80b04 1495 * General service functions
a2fbb9ea
ET
1496 */
1497
72fd0718
VZ
1498/* Return true if succeeded to acquire the lock */
1499static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1500{
1501 u32 lock_status;
1502 u32 resource_bit = (1 << resource);
1503 int func = BP_FUNC(bp);
1504 u32 hw_lock_control_reg;
1505
51c1a580
MS
1506 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1507 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1508
1509 /* Validating that the resource is within range */
1510 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1511 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1512 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1513 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1514 return false;
72fd0718
VZ
1515 }
1516
1517 if (func <= 5)
1518 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1519 else
1520 hw_lock_control_reg =
1521 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1522
1523 /* Try to acquire the lock */
1524 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1525 lock_status = REG_RD(bp, hw_lock_control_reg);
1526 if (lock_status & resource_bit)
1527 return true;
1528
51c1a580
MS
1529 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1530 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1531 return false;
1532}
1533
c9ee9206
VZ
1534/**
1535 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1536 *
1537 * @bp: driver handle
1538 *
1539 * Returns the recovery leader resource id according to the engine this function
1540 * belongs to. Currently only only 2 engines is supported.
1541 */
1542static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1543{
1544 if (BP_PATH(bp))
1545 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1546 else
1547 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1548}
1549
1550/**
1551 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1552 *
1553 * @bp: driver handle
1554 *
1555 * Tries to aquire a leader lock for cuurent engine.
1556 */
1557static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1558{
1559 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1560}
1561
993ac7b5 1562#ifdef BCM_CNIC
619c5cb6 1563static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
993ac7b5 1564#endif
3196a88a 1565
619c5cb6 1566void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1567{
1568 struct bnx2x *bp = fp->bp;
1569 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1570 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6
VZ
1571 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1572 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
a2fbb9ea 1573
34f80b04 1574 DP(BNX2X_MSG_SP,
a2fbb9ea 1575 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1576 fp->index, cid, command, bp->state,
34f80b04 1577 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1578
619c5cb6
VZ
1579 switch (command) {
1580 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1581 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1582 drv_cmd = BNX2X_Q_CMD_UPDATE;
1583 break;
d6cae238 1584
619c5cb6 1585 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1586 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1587 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1588 break;
1589
6383c0b3 1590 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1591 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1592 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1593 break;
1594
619c5cb6 1595 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1596 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1597 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1598 break;
1599
619c5cb6 1600 case (RAMROD_CMD_ID_ETH_TERMINATE):
d6cae238 1601 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
619c5cb6 1602 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1603 break;
1604
619c5cb6 1605 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1606 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1607 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1608 break;
619c5cb6
VZ
1609
1610 default:
1611 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1612 command, fp->index);
1613 return;
523224a3 1614 }
3196a88a 1615
619c5cb6
VZ
1616 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1617 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1618 /* q_obj->complete_cmd() failure means that this was
1619 * an unexpected completion.
1620 *
1621 * In this case we don't want to increase the bp->spq_left
1622 * because apparently we haven't sent this command the first
1623 * place.
1624 */
1625#ifdef BNX2X_STOP_ON_ERROR
1626 bnx2x_panic();
1627#else
1628 return;
1629#endif
1630
8fe23fbd 1631 smp_mb__before_atomic_inc();
6e30dd4e 1632 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1633 /* push the change in bp->spq_left and towards the memory */
1634 smp_mb__after_atomic_inc();
49d66772 1635
d6cae238
VZ
1636 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1637
523224a3 1638 return;
a2fbb9ea
ET
1639}
1640
619c5cb6
VZ
1641void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1642 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1643{
1644 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1645
1646 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1647 start);
1648}
1649
9f6c9258 1650irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1651{
555f6c78 1652 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1653 u16 status = bnx2x_ack_int(bp);
34f80b04 1654 u16 mask;
ca00392c 1655 int i;
6383c0b3 1656 u8 cos;
a2fbb9ea 1657
34f80b04 1658 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1659 if (unlikely(status == 0)) {
1660 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1661 return IRQ_NONE;
1662 }
f5372251 1663 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1664
3196a88a
EG
1665#ifdef BNX2X_STOP_ON_ERROR
1666 if (unlikely(bp->panic))
1667 return IRQ_HANDLED;
1668#endif
1669
ec6ba945 1670 for_each_eth_queue(bp, i) {
ca00392c 1671 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1672
6383c0b3 1673 mask = 0x2 << (fp->index + CNIC_PRESENT);
ca00392c 1674 if (status & mask) {
619c5cb6 1675 /* Handle Rx or Tx according to SB id */
54b9ddaa 1676 prefetch(fp->rx_cons_sb);
6383c0b3
AE
1677 for_each_cos_in_tx_queue(fp, cos)
1678 prefetch(fp->txdata[cos].tx_cons_sb);
523224a3 1679 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1680 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1681 status &= ~mask;
1682 }
a2fbb9ea
ET
1683 }
1684
993ac7b5 1685#ifdef BCM_CNIC
523224a3 1686 mask = 0x2;
993ac7b5
MC
1687 if (status & (mask | 0x1)) {
1688 struct cnic_ops *c_ops = NULL;
1689
619c5cb6
VZ
1690 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1691 rcu_read_lock();
1692 c_ops = rcu_dereference(bp->cnic_ops);
1693 if (c_ops)
1694 c_ops->cnic_handler(bp->cnic_data, NULL);
1695 rcu_read_unlock();
1696 }
993ac7b5
MC
1697
1698 status &= ~mask;
1699 }
1700#endif
a2fbb9ea 1701
34f80b04 1702 if (unlikely(status & 0x1)) {
1cf167f2 1703 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
a2fbb9ea
ET
1704
1705 status &= ~0x1;
1706 if (!status)
1707 return IRQ_HANDLED;
1708 }
1709
cdaa7cb8
VZ
1710 if (unlikely(status))
1711 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1712 status);
a2fbb9ea 1713
c18487ee 1714 return IRQ_HANDLED;
a2fbb9ea
ET
1715}
1716
c18487ee
YR
1717/* Link */
1718
1719/*
1720 * General service functions
1721 */
a2fbb9ea 1722
9f6c9258 1723int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1724{
1725 u32 lock_status;
1726 u32 resource_bit = (1 << resource);
4a37fb66
YG
1727 int func = BP_FUNC(bp);
1728 u32 hw_lock_control_reg;
c18487ee 1729 int cnt;
a2fbb9ea 1730
c18487ee
YR
1731 /* Validating that the resource is within range */
1732 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1733 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1734 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1735 return -EINVAL;
1736 }
a2fbb9ea 1737
4a37fb66
YG
1738 if (func <= 5) {
1739 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1740 } else {
1741 hw_lock_control_reg =
1742 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1743 }
1744
c18487ee 1745 /* Validating that the resource is not already taken */
4a37fb66 1746 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1747 if (lock_status & resource_bit) {
51c1a580 1748 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
c18487ee
YR
1749 lock_status, resource_bit);
1750 return -EEXIST;
1751 }
a2fbb9ea 1752
46230476
EG
1753 /* Try for 5 second every 5ms */
1754 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1755 /* Try to acquire the lock */
4a37fb66
YG
1756 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1757 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1758 if (lock_status & resource_bit)
1759 return 0;
a2fbb9ea 1760
c18487ee 1761 msleep(5);
a2fbb9ea 1762 }
51c1a580 1763 BNX2X_ERR("Timeout\n");
c18487ee
YR
1764 return -EAGAIN;
1765}
a2fbb9ea 1766
c9ee9206
VZ
1767int bnx2x_release_leader_lock(struct bnx2x *bp)
1768{
1769 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1770}
1771
9f6c9258 1772int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1773{
1774 u32 lock_status;
1775 u32 resource_bit = (1 << resource);
4a37fb66
YG
1776 int func = BP_FUNC(bp);
1777 u32 hw_lock_control_reg;
a2fbb9ea 1778
c18487ee
YR
1779 /* Validating that the resource is within range */
1780 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1781 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1782 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1783 return -EINVAL;
1784 }
1785
4a37fb66
YG
1786 if (func <= 5) {
1787 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1788 } else {
1789 hw_lock_control_reg =
1790 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1791 }
1792
c18487ee 1793 /* Validating that the resource is currently taken */
4a37fb66 1794 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1795 if (!(lock_status & resource_bit)) {
51c1a580 1796 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
c18487ee
YR
1797 lock_status, resource_bit);
1798 return -EFAULT;
a2fbb9ea
ET
1799 }
1800
9f6c9258
DK
1801 REG_WR(bp, hw_lock_control_reg, resource_bit);
1802 return 0;
c18487ee 1803}
a2fbb9ea 1804
9f6c9258 1805
4acac6a5
EG
1806int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1807{
1808 /* The GPIO should be swapped if swap register is set and active */
1809 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1810 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1811 int gpio_shift = gpio_num +
1812 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1813 u32 gpio_mask = (1 << gpio_shift);
1814 u32 gpio_reg;
1815 int value;
1816
1817 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1818 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1819 return -EINVAL;
1820 }
1821
1822 /* read GPIO value */
1823 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1824
1825 /* get the requested pin value */
1826 if ((gpio_reg & gpio_mask) == gpio_mask)
1827 value = 1;
1828 else
1829 value = 0;
1830
1831 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1832
1833 return value;
1834}
1835
17de50b7 1836int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
1837{
1838 /* The GPIO should be swapped if swap register is set and active */
1839 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 1840 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
1841 int gpio_shift = gpio_num +
1842 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1843 u32 gpio_mask = (1 << gpio_shift);
1844 u32 gpio_reg;
a2fbb9ea 1845
c18487ee
YR
1846 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1847 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1848 return -EINVAL;
1849 }
a2fbb9ea 1850
4a37fb66 1851 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
1852 /* read GPIO and mask except the float bits */
1853 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 1854
c18487ee
YR
1855 switch (mode) {
1856 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
1857 DP(NETIF_MSG_LINK,
1858 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
1859 gpio_num, gpio_shift);
1860 /* clear FLOAT and set CLR */
1861 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1862 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1863 break;
a2fbb9ea 1864
c18487ee 1865 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
1866 DP(NETIF_MSG_LINK,
1867 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
1868 gpio_num, gpio_shift);
1869 /* clear FLOAT and set SET */
1870 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1871 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1872 break;
a2fbb9ea 1873
17de50b7 1874 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
1875 DP(NETIF_MSG_LINK,
1876 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
1877 gpio_num, gpio_shift);
1878 /* set FLOAT */
1879 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1880 break;
a2fbb9ea 1881
c18487ee
YR
1882 default:
1883 break;
a2fbb9ea
ET
1884 }
1885
c18487ee 1886 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 1887 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 1888
c18487ee 1889 return 0;
a2fbb9ea
ET
1890}
1891
0d40f0d4
YR
1892int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1893{
1894 u32 gpio_reg = 0;
1895 int rc = 0;
1896
1897 /* Any port swapping should be handled by caller. */
1898
1899 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1900 /* read GPIO and mask except the float bits */
1901 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1902 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1903 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1904 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1905
1906 switch (mode) {
1907 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1908 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1909 /* set CLR */
1910 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1911 break;
1912
1913 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1914 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1915 /* set SET */
1916 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1917 break;
1918
1919 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1920 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
1921 /* set FLOAT */
1922 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1923 break;
1924
1925 default:
1926 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
1927 rc = -EINVAL;
1928 break;
1929 }
1930
1931 if (rc == 0)
1932 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1933
1934 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1935
1936 return rc;
1937}
1938
4acac6a5
EG
1939int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1940{
1941 /* The GPIO should be swapped if swap register is set and active */
1942 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1943 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1944 int gpio_shift = gpio_num +
1945 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1946 u32 gpio_mask = (1 << gpio_shift);
1947 u32 gpio_reg;
1948
1949 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1950 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1951 return -EINVAL;
1952 }
1953
1954 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1955 /* read GPIO int */
1956 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1957
1958 switch (mode) {
1959 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
1960 DP(NETIF_MSG_LINK,
1961 "Clear GPIO INT %d (shift %d) -> output low\n",
1962 gpio_num, gpio_shift);
4acac6a5
EG
1963 /* clear SET and set CLR */
1964 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1965 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1966 break;
1967
1968 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
1969 DP(NETIF_MSG_LINK,
1970 "Set GPIO INT %d (shift %d) -> output high\n",
1971 gpio_num, gpio_shift);
4acac6a5
EG
1972 /* clear CLR and set SET */
1973 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1974 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1975 break;
1976
1977 default:
1978 break;
1979 }
1980
1981 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1982 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1983
1984 return 0;
1985}
1986
c18487ee 1987static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
a2fbb9ea 1988{
c18487ee
YR
1989 u32 spio_mask = (1 << spio_num);
1990 u32 spio_reg;
a2fbb9ea 1991
c18487ee
YR
1992 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
1993 (spio_num > MISC_REGISTERS_SPIO_7)) {
1994 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
1995 return -EINVAL;
a2fbb9ea
ET
1996 }
1997
4a37fb66 1998 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee
YR
1999 /* read SPIO and mask except the float bits */
2000 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
a2fbb9ea 2001
c18487ee 2002 switch (mode) {
6378c025 2003 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
51c1a580 2004 DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
c18487ee
YR
2005 /* clear FLOAT and set CLR */
2006 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2007 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2008 break;
a2fbb9ea 2009
6378c025 2010 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
51c1a580 2011 DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
c18487ee
YR
2012 /* clear FLOAT and set SET */
2013 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2014 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2015 break;
a2fbb9ea 2016
c18487ee 2017 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
51c1a580 2018 DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
c18487ee
YR
2019 /* set FLOAT */
2020 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2021 break;
a2fbb9ea 2022
c18487ee
YR
2023 default:
2024 break;
a2fbb9ea
ET
2025 }
2026
c18487ee 2027 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2028 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2029
a2fbb9ea
ET
2030 return 0;
2031}
2032
9f6c9258 2033void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2034{
a22f0788 2035 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2036 switch (bp->link_vars.ieee_fc &
2037 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2038 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2039 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2040 ADVERTISED_Pause);
c18487ee 2041 break;
356e2385 2042
c18487ee 2043 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2044 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2045 ADVERTISED_Pause);
c18487ee 2046 break;
356e2385 2047
c18487ee 2048 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2049 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2050 break;
356e2385 2051
c18487ee 2052 default:
a22f0788 2053 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2054 ADVERTISED_Pause);
c18487ee
YR
2055 break;
2056 }
2057}
f1410647 2058
9f6c9258 2059u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
c18487ee 2060{
19680c48
EG
2061 if (!BP_NOMCP(bp)) {
2062 u8 rc;
a22f0788
YR
2063 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2064 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
1cb0c788
YR
2065 /*
2066 * Initialize link parameters structure variables
2067 * It is recommended to turn off RX FC for jumbo frames
2068 * for better performance
2069 */
2070 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
c0700f90 2071 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
8c99e7b0 2072 else
c0700f90 2073 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
a2fbb9ea 2074
4a37fb66 2075 bnx2x_acquire_phy_lock(bp);
b5bf9068 2076
a22f0788 2077 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2078 struct link_params *lp = &bp->link_params;
2079 lp->loopback_mode = LOOPBACK_XGXS;
2080 /* do PHY loopback at 10G speed, if possible */
2081 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2082 if (lp->speed_cap_mask[cfx_idx] &
2083 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2084 lp->req_line_speed[cfx_idx] =
2085 SPEED_10000;
2086 else
2087 lp->req_line_speed[cfx_idx] =
2088 SPEED_1000;
2089 }
a22f0788 2090 }
b5bf9068 2091
19680c48 2092 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2093
4a37fb66 2094 bnx2x_release_phy_lock(bp);
a2fbb9ea 2095
3c96c68b
EG
2096 bnx2x_calc_fc_adv(bp);
2097
b5bf9068
EG
2098 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2099 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2100 bnx2x_link_report(bp);
3deb8167
YR
2101 } else
2102 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2103 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2104 return rc;
2105 }
f5372251 2106 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2107 return -EINVAL;
a2fbb9ea
ET
2108}
2109
9f6c9258 2110void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2111{
19680c48 2112 if (!BP_NOMCP(bp)) {
4a37fb66 2113 bnx2x_acquire_phy_lock(bp);
54c2fb78 2114 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
19680c48 2115 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2116 bnx2x_release_phy_lock(bp);
a2fbb9ea 2117
19680c48
EG
2118 bnx2x_calc_fc_adv(bp);
2119 } else
f5372251 2120 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2121}
a2fbb9ea 2122
c18487ee
YR
2123static void bnx2x__link_reset(struct bnx2x *bp)
2124{
19680c48 2125 if (!BP_NOMCP(bp)) {
4a37fb66 2126 bnx2x_acquire_phy_lock(bp);
589abe3a 2127 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
4a37fb66 2128 bnx2x_release_phy_lock(bp);
19680c48 2129 } else
f5372251 2130 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2131}
a2fbb9ea 2132
a22f0788 2133u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2134{
2145a920 2135 u8 rc = 0;
a2fbb9ea 2136
2145a920
VZ
2137 if (!BP_NOMCP(bp)) {
2138 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2139 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2140 is_serdes);
2145a920
VZ
2141 bnx2x_release_phy_lock(bp);
2142 } else
2143 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2144
c18487ee
YR
2145 return rc;
2146}
a2fbb9ea 2147
8a1c38d1 2148static void bnx2x_init_port_minmax(struct bnx2x *bp)
34f80b04 2149{
8a1c38d1
EG
2150 u32 r_param = bp->link_vars.line_speed / 8;
2151 u32 fair_periodic_timeout_usec;
2152 u32 t_fair;
34f80b04 2153
8a1c38d1
EG
2154 memset(&(bp->cmng.rs_vars), 0,
2155 sizeof(struct rate_shaping_vars_per_port));
2156 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
34f80b04 2157
8a1c38d1
EG
2158 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2159 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
34f80b04 2160
8a1c38d1
EG
2161 /* this is the threshold below which no timer arming will occur
2162 1.25 coefficient is for the threshold to be a little bigger
2163 than the real time, to compensate for timer in-accuracy */
2164 bp->cmng.rs_vars.rs_threshold =
34f80b04
EG
2165 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2166
8a1c38d1
EG
2167 /* resolution of fairness timer */
2168 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2169 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2170 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
34f80b04 2171
8a1c38d1
EG
2172 /* this is the threshold below which we won't arm the timer anymore */
2173 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
34f80b04 2174
8a1c38d1
EG
2175 /* we multiply by 1e3/8 to get bytes/msec.
2176 We don't want the credits to pass a credit
2177 of the t_fair*FAIR_MEM (algorithm resolution) */
2178 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2179 /* since each tick is 4 usec */
2180 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
34f80b04
EG
2181}
2182
2691d51d
EG
2183/* Calculates the sum of vn_min_rates.
2184 It's needed for further normalizing of the min_rates.
2185 Returns:
2186 sum of vn_min_rates.
2187 or
2188 0 - if all the min_rates are 0.
2189 In the later case fainess algorithm should be deactivated.
2190 If not all min_rates are zero then those that are zeroes will be set to 1.
2191 */
2192static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2193{
2194 int all_zero = 1;
2691d51d
EG
2195 int vn;
2196
2197 bp->vn_weight_sum = 0;
3395a033 2198 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2199 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2200 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2201 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2202
2203 /* Skip hidden vns */
2204 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2205 continue;
2206
2207 /* If min rate is zero - set it to 1 */
2208 if (!vn_min_rate)
2209 vn_min_rate = DEF_MIN_RATE;
2210 else
2211 all_zero = 0;
2212
2213 bp->vn_weight_sum += vn_min_rate;
2214 }
2215
30ae438b
DK
2216 /* if ETS or all min rates are zeros - disable fairness */
2217 if (BNX2X_IS_ETS_ENABLED(bp)) {
2218 bp->cmng.flags.cmng_enables &=
2219 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2220 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2221 } else if (all_zero) {
b015e3d1
EG
2222 bp->cmng.flags.cmng_enables &=
2223 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2224 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2225 " fairness will be disabled\n");
2226 } else
2227 bp->cmng.flags.cmng_enables |=
2228 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2229}
2230
f2e0899f 2231static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
34f80b04
EG
2232{
2233 struct rate_shaping_vars_per_vn m_rs_vn;
2234 struct fairness_vars_per_vn m_fair_vn;
f2e0899f 2235 u32 vn_cfg = bp->mf_config[vn];
3395a033 2236 int func = func_by_vn(bp, vn);
34f80b04
EG
2237 u16 vn_min_rate, vn_max_rate;
2238 int i;
2239
2240 /* If function is hidden - set min and max to zeroes */
2241 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2242 vn_min_rate = 0;
2243 vn_max_rate = 0;
2244
2245 } else {
faa6fcbb
DK
2246 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2247
34f80b04
EG
2248 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2249 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
faa6fcbb
DK
2250 /* If fairness is enabled (not all min rates are zeroes) and
2251 if current min rate is zero - set it to 1.
2252 This is a requirement of the algorithm. */
f2e0899f 2253 if (bp->vn_weight_sum && (vn_min_rate == 0))
34f80b04 2254 vn_min_rate = DEF_MIN_RATE;
faa6fcbb
DK
2255
2256 if (IS_MF_SI(bp))
2257 /* maxCfg in percents of linkspeed */
2258 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2259 else
2260 /* maxCfg is absolute in 100Mb units */
2261 vn_max_rate = maxCfg * 100;
34f80b04 2262 }
f85582f8 2263
8a1c38d1 2264 DP(NETIF_MSG_IFUP,
b015e3d1 2265 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
8a1c38d1 2266 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
34f80b04
EG
2267
2268 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2269 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2270
2271 /* global vn counter - maximal Mbps for this vn */
2272 m_rs_vn.vn_counter.rate = vn_max_rate;
2273
2274 /* quota - number of bytes transmitted in this period */
2275 m_rs_vn.vn_counter.quota =
2276 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2277
8a1c38d1 2278 if (bp->vn_weight_sum) {
34f80b04
EG
2279 /* credit for each period of the fairness algorithm:
2280 number of bytes in T_FAIR (the vn share the port rate).
8a1c38d1
EG
2281 vn_weight_sum should not be larger than 10000, thus
2282 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2283 than zero */
34f80b04 2284 m_fair_vn.vn_credit_delta =
cdaa7cb8
VZ
2285 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2286 (8 * bp->vn_weight_sum))),
ff80ee02
DK
2287 (bp->cmng.fair_vars.fair_threshold +
2288 MIN_ABOVE_THRESH));
cdaa7cb8 2289 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
34f80b04
EG
2290 m_fair_vn.vn_credit_delta);
2291 }
2292
34f80b04
EG
2293 /* Store it to internal memory */
2294 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2295 REG_WR(bp, BAR_XSTRORM_INTMEM +
2296 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2297 ((u32 *)(&m_rs_vn))[i]);
2298
2299 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2300 REG_WR(bp, BAR_XSTRORM_INTMEM +
2301 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2302 ((u32 *)(&m_fair_vn))[i]);
2303}
f85582f8 2304
523224a3
DK
2305static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2306{
2307 if (CHIP_REV_IS_SLOW(bp))
2308 return CMNG_FNS_NONE;
fb3bff17 2309 if (IS_MF(bp))
523224a3
DK
2310 return CMNG_FNS_MINMAX;
2311
2312 return CMNG_FNS_NONE;
2313}
2314
2ae17f66 2315void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2316{
0793f83f 2317 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2318
2319 if (BP_NOMCP(bp))
2320 return; /* what should be the default bvalue in this case */
2321
0793f83f
DK
2322 /* For 2 port configuration the absolute function number formula
2323 * is:
2324 * abs_func = 2 * vn + BP_PORT + BP_PATH
2325 *
2326 * and there are 4 functions per port
2327 *
2328 * For 4 port configuration it is
2329 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2330 *
2331 * and there are 2 functions per port
2332 */
3395a033 2333 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2334 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2335
2336 if (func >= E1H_FUNC_MAX)
2337 break;
2338
f2e0899f 2339 bp->mf_config[vn] =
523224a3
DK
2340 MF_CFG_RD(bp, func_mf_config[func].config);
2341 }
2342}
2343
2344static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2345{
2346
2347 if (cmng_type == CMNG_FNS_MINMAX) {
2348 int vn;
2349
2350 /* clear cmng_enables */
2351 bp->cmng.flags.cmng_enables = 0;
2352
2353 /* read mf conf from shmem */
2354 if (read_cfg)
2355 bnx2x_read_mf_cfg(bp);
2356
2357 /* Init rate shaping and fairness contexts */
2358 bnx2x_init_port_minmax(bp);
2359
2360 /* vn_weight_sum and enable fairness if not 0 */
2361 bnx2x_calc_vn_weight_sum(bp);
2362
2363 /* calculate and set min-max rate for each vn */
c4154f25 2364 if (bp->port.pmf)
3395a033 2365 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
c4154f25 2366 bnx2x_init_vn_minmax(bp, vn);
523224a3
DK
2367
2368 /* always enable rate shaping and fairness */
2369 bp->cmng.flags.cmng_enables |=
2370 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2371 if (!bp->vn_weight_sum)
2372 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2373 " fairness will be disabled\n");
2374 return;
2375 }
2376
2377 /* rate shaping and fairness are disabled */
2378 DP(NETIF_MSG_IFUP,
2379 "rate shaping and fairness are disabled\n");
2380}
34f80b04 2381
c18487ee
YR
2382/* This function is called upon link interrupt */
2383static void bnx2x_link_attn(struct bnx2x *bp)
2384{
bb2a0f7a
YG
2385 /* Make sure that we are synced with the current statistics */
2386 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2387
c18487ee 2388 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2389
bb2a0f7a
YG
2390 if (bp->link_vars.link_up) {
2391
1c06328c 2392 /* dropless flow control */
f2e0899f 2393 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2394 int port = BP_PORT(bp);
2395 u32 pause_enabled = 0;
2396
2397 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2398 pause_enabled = 1;
2399
2400 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2401 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2402 pause_enabled);
2403 }
2404
619c5cb6 2405 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2406 struct host_port_stats *pstats;
2407
2408 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2409 /* reset old mac stats */
bb2a0f7a
YG
2410 memset(&(pstats->mac_stx[0]), 0,
2411 sizeof(struct mac_stx));
2412 }
f34d28ea 2413 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2414 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2415 }
2416
f2e0899f
DK
2417 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2418 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2419
f2e0899f
DK
2420 if (cmng_fns != CMNG_FNS_NONE) {
2421 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2422 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2423 } else
2424 /* rate shaping and fairness are disabled */
2425 DP(NETIF_MSG_IFUP,
2426 "single function mode without fairness\n");
34f80b04 2427 }
9fdc3e95 2428
2ae17f66
VZ
2429 __bnx2x_link_report(bp);
2430
9fdc3e95
DK
2431 if (IS_MF(bp))
2432 bnx2x_link_sync_notify(bp);
c18487ee 2433}
a2fbb9ea 2434
9f6c9258 2435void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2436{
2ae17f66 2437 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2438 return;
a2fbb9ea 2439
00253a8c
DK
2440 /* read updated dcb configuration */
2441 bnx2x_dcbx_pmf_update(bp);
2442
c18487ee 2443 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2444
bb2a0f7a
YG
2445 if (bp->link_vars.link_up)
2446 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2447 else
2448 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2449
c18487ee
YR
2450 /* indicate link status */
2451 bnx2x_link_report(bp);
a2fbb9ea 2452}
a2fbb9ea 2453
34f80b04
EG
2454static void bnx2x_pmf_update(struct bnx2x *bp)
2455{
2456 int port = BP_PORT(bp);
2457 u32 val;
2458
2459 bp->port.pmf = 1;
51c1a580 2460 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2461
3deb8167
YR
2462 /*
2463 * We need the mb() to ensure the ordering between the writing to
2464 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2465 */
2466 smp_mb();
2467
2468 /* queue a periodic task */
2469 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2470
ef01854e
DK
2471 bnx2x_dcbx_pmf_update(bp);
2472
34f80b04 2473 /* enable nig attention */
3395a033 2474 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2475 if (bp->common.int_block == INT_BLOCK_HC) {
2476 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2477 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2478 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2479 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2480 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2481 }
bb2a0f7a
YG
2482
2483 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2484}
2485
c18487ee 2486/* end of Link */
a2fbb9ea
ET
2487
2488/* slow path */
2489
2490/*
2491 * General service functions
2492 */
2493
2691d51d 2494/* send the MCP a request, block until there is a reply */
a22f0788 2495u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2496{
f2e0899f 2497 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2498 u32 seq;
2691d51d
EG
2499 u32 rc = 0;
2500 u32 cnt = 1;
2501 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2502
c4ff7cbf 2503 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2504 seq = ++bp->fw_seq;
f2e0899f
DK
2505 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2506 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2507
754a2f52
DK
2508 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2509 (command | seq), param);
2691d51d
EG
2510
2511 do {
2512 /* let the FW do it's magic ... */
2513 msleep(delay);
2514
f2e0899f 2515 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2516
c4ff7cbf
EG
2517 /* Give the FW up to 5 second (500*10ms) */
2518 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2519
2520 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2521 cnt*delay, rc, seq);
2522
2523 /* is this a reply to our command? */
2524 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2525 rc &= FW_MSG_CODE_MASK;
2526 else {
2527 /* FW BUG! */
2528 BNX2X_ERR("FW failed to respond!\n");
2529 bnx2x_fw_dump(bp);
2530 rc = 0;
2531 }
c4ff7cbf 2532 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2533
2534 return rc;
2535}
2536
ec6ba945 2537
619c5cb6
VZ
2538void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2539{
2540 if (CHIP_IS_E1x(bp)) {
2541 struct tstorm_eth_function_common_config tcfg = {0};
2542
2543 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2544 }
2545
2546 /* Enable the function in the FW */
2547 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2548 storm_memset_func_en(bp, p->func_id, 1);
2549
2550 /* spq */
2551 if (p->func_flgs & FUNC_FLG_SPQ) {
2552 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2553 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2554 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2555 }
2556}
2557
6383c0b3
AE
2558/**
2559 * bnx2x_get_tx_only_flags - Return common flags
2560 *
2561 * @bp device handle
2562 * @fp queue handle
2563 * @zero_stats TRUE if statistics zeroing is needed
2564 *
2565 * Return the flags that are common for the Tx-only and not normal connections.
2566 */
2567static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2568 struct bnx2x_fastpath *fp,
2569 bool zero_stats)
28912902 2570{
619c5cb6
VZ
2571 unsigned long flags = 0;
2572
2573 /* PF driver will always initialize the Queue to an ACTIVE state */
2574 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2575
6383c0b3
AE
2576 /* tx only connections collect statistics (on the same index as the
2577 * parent connection). The statistics are zeroed when the parent
2578 * connection is initialized.
2579 */
50f0a562
BW
2580
2581 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2582 if (zero_stats)
2583 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2584
6383c0b3
AE
2585
2586 return flags;
2587}
2588
2589static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2590 struct bnx2x_fastpath *fp,
2591 bool leading)
2592{
2593 unsigned long flags = 0;
2594
619c5cb6
VZ
2595 /* calculate other queue flags */
2596 if (IS_MF_SD(bp))
2597 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2598
619c5cb6
VZ
2599 if (IS_FCOE_FP(fp))
2600 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
523224a3 2601
f5219d8e 2602 if (!fp->disable_tpa) {
619c5cb6 2603 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2604 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2605 if (fp->mode == TPA_MODE_GRO)
2606 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2607 }
619c5cb6 2608
619c5cb6
VZ
2609 if (leading) {
2610 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2611 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2612 }
523224a3 2613
619c5cb6
VZ
2614 /* Always set HW VLAN stripping */
2615 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 2616
6383c0b3
AE
2617
2618 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
2619}
2620
619c5cb6 2621static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
2622 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2623 u8 cos)
619c5cb6
VZ
2624{
2625 gen_init->stat_id = bnx2x_stats_id(fp);
2626 gen_init->spcl_id = fp->cl_id;
2627
2628 /* Always use mini-jumbo MTU for FCoE L2 ring */
2629 if (IS_FCOE_FP(fp))
2630 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2631 else
2632 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
2633
2634 gen_init->cos = cos;
619c5cb6
VZ
2635}
2636
2637static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 2638 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 2639 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 2640{
619c5cb6 2641 u8 max_sge = 0;
523224a3
DK
2642 u16 sge_sz = 0;
2643 u16 tpa_agg_size = 0;
2644
523224a3 2645 if (!fp->disable_tpa) {
dfacf138
DK
2646 pause->sge_th_lo = SGE_TH_LO(bp);
2647 pause->sge_th_hi = SGE_TH_HI(bp);
2648
2649 /* validate SGE ring has enough to cross high threshold */
2650 WARN_ON(bp->dropless_fc &&
2651 pause->sge_th_hi + FW_PREFETCH_CNT >
2652 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2653
523224a3
DK
2654 tpa_agg_size = min_t(u32,
2655 (min_t(u32, 8, MAX_SKB_FRAGS) *
2656 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2657 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2658 SGE_PAGE_SHIFT;
2659 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2660 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2661 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2662 0xffff);
2663 }
2664
2665 /* pause - not for e1 */
2666 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
2667 pause->bd_th_lo = BD_TH_LO(bp);
2668 pause->bd_th_hi = BD_TH_HI(bp);
2669
2670 pause->rcq_th_lo = RCQ_TH_LO(bp);
2671 pause->rcq_th_hi = RCQ_TH_HI(bp);
2672 /*
2673 * validate that rings have enough entries to cross
2674 * high thresholds
2675 */
2676 WARN_ON(bp->dropless_fc &&
2677 pause->bd_th_hi + FW_PREFETCH_CNT >
2678 bp->rx_ring_size);
2679 WARN_ON(bp->dropless_fc &&
2680 pause->rcq_th_hi + FW_PREFETCH_CNT >
2681 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 2682
523224a3
DK
2683 pause->pri_map = 1;
2684 }
2685
2686 /* rxq setup */
523224a3
DK
2687 rxq_init->dscr_map = fp->rx_desc_mapping;
2688 rxq_init->sge_map = fp->rx_sge_mapping;
2689 rxq_init->rcq_map = fp->rx_comp_mapping;
2690 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 2691
619c5cb6
VZ
2692 /* This should be a maximum number of data bytes that may be
2693 * placed on the BD (not including paddings).
2694 */
e52fcb24
ED
2695 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2696 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 2697
523224a3 2698 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
2699 rxq_init->tpa_agg_sz = tpa_agg_size;
2700 rxq_init->sge_buf_sz = sge_sz;
2701 rxq_init->max_sges_pkt = max_sge;
619c5cb6 2702 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 2703 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
2704
2705 /* Maximum number or simultaneous TPA aggregation for this Queue.
2706 *
2707 * For PF Clients it should be the maximum avaliable number.
2708 * VF driver(s) may want to define it to a smaller value.
2709 */
dfacf138 2710 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 2711
523224a3
DK
2712 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2713 rxq_init->fw_sb_id = fp->fw_sb_id;
2714
ec6ba945
VZ
2715 if (IS_FCOE_FP(fp))
2716 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2717 else
6383c0b3 2718 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
523224a3
DK
2719}
2720
619c5cb6 2721static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
2722 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2723 u8 cos)
523224a3 2724{
6383c0b3
AE
2725 txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
2726 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
2727 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2728 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 2729
619c5cb6
VZ
2730 /*
2731 * set the tss leading client id for TX classfication ==
2732 * leading RSS client id
2733 */
2734 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2735
ec6ba945
VZ
2736 if (IS_FCOE_FP(fp)) {
2737 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2738 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2739 }
523224a3
DK
2740}
2741
8d96286a 2742static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
2743{
2744 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
2745 struct event_ring_data eq_data = { {0} };
2746 u16 flags;
2747
619c5cb6 2748 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2749 /* reset IGU PF statistics: MSIX + ATTN */
2750 /* PF */
2751 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2752 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2753 (CHIP_MODE_IS_4_PORT(bp) ?
2754 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2755 /* ATTN */
2756 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2757 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2758 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2759 (CHIP_MODE_IS_4_PORT(bp) ?
2760 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2761 }
2762
523224a3
DK
2763 /* function setup flags */
2764 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2765
619c5cb6
VZ
2766 /* This flag is relevant for E1x only.
2767 * E2 doesn't have a TPA configuration in a function level.
523224a3 2768 */
619c5cb6 2769 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
2770
2771 func_init.func_flgs = flags;
2772 func_init.pf_id = BP_FUNC(bp);
2773 func_init.func_id = BP_FUNC(bp);
523224a3
DK
2774 func_init.spq_map = bp->spq_mapping;
2775 func_init.spq_prod = bp->spq_prod_idx;
2776
2777 bnx2x_func_init(bp, &func_init);
2778
2779 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2780
2781 /*
619c5cb6
VZ
2782 * Congestion management values depend on the link rate
2783 * There is no active link so initial link rate is set to 10 Gbps.
2784 * When the link comes up The congestion management values are
2785 * re-calculated according to the actual link rate.
2786 */
523224a3
DK
2787 bp->link_vars.line_speed = SPEED_10000;
2788 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2789
2790 /* Only the PMF sets the HW */
2791 if (bp->port.pmf)
2792 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2793
523224a3
DK
2794 /* init Event Queue */
2795 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2796 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2797 eq_data.producer = bp->eq_prod;
2798 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2799 eq_data.sb_id = DEF_SB_ID;
2800 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2801}
2802
2803
2804static void bnx2x_e1h_disable(struct bnx2x *bp)
2805{
2806 int port = BP_PORT(bp);
2807
619c5cb6 2808 bnx2x_tx_disable(bp);
523224a3
DK
2809
2810 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
2811}
2812
2813static void bnx2x_e1h_enable(struct bnx2x *bp)
2814{
2815 int port = BP_PORT(bp);
2816
2817 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2818
2819 /* Tx queue should be only reenabled */
2820 netif_tx_wake_all_queues(bp->dev);
2821
2822 /*
2823 * Should not call netif_carrier_on since it will be called if the link
2824 * is up when checking for link state
2825 */
2826}
2827
1d187b34
BW
2828#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
2829
2830static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
2831{
2832 struct eth_stats_info *ether_stat =
2833 &bp->slowpath->drv_info_to_mcp.ether_stat;
2834
2835 /* leave last char as NULL */
2836 memcpy(ether_stat->version, DRV_MODULE_VERSION,
2837 ETH_STAT_INFO_VERSION_LEN - 1);
2838
2839 bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
2840 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
2841 ether_stat->mac_local);
2842
2843 ether_stat->mtu_size = bp->dev->mtu;
2844
2845 if (bp->dev->features & NETIF_F_RXCSUM)
2846 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
2847 if (bp->dev->features & NETIF_F_TSO)
2848 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
2849 ether_stat->feature_flags |= bp->common.boot_mode;
2850
2851 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
2852
2853 ether_stat->txq_size = bp->tx_ring_size;
2854 ether_stat->rxq_size = bp->rx_ring_size;
2855}
2856
2857static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
2858{
f2fd5c34 2859#ifdef BCM_CNIC
1d187b34
BW
2860 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
2861 struct fcoe_stats_info *fcoe_stat =
2862 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
2863
2864 memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
2865
2866 fcoe_stat->qos_priority =
2867 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
2868
2869 /* insert FCoE stats from ramrod response */
2870 if (!NO_FCOE(bp)) {
2871 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
2872 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2873 tstorm_queue_statistics;
2874
2875 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
2876 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2877 xstorm_queue_statistics;
2878
2879 struct fcoe_statistics_params *fw_fcoe_stat =
2880 &bp->fw_stats_data->fcoe;
2881
2882 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
2883 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
2884
2885 ADD_64(fcoe_stat->rx_bytes_hi,
2886 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
2887 fcoe_stat->rx_bytes_lo,
2888 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
2889
2890 ADD_64(fcoe_stat->rx_bytes_hi,
2891 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
2892 fcoe_stat->rx_bytes_lo,
2893 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
2894
2895 ADD_64(fcoe_stat->rx_bytes_hi,
2896 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
2897 fcoe_stat->rx_bytes_lo,
2898 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
2899
2900 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2901 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
2902
2903 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2904 fcoe_q_tstorm_stats->rcv_ucast_pkts);
2905
2906 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2907 fcoe_q_tstorm_stats->rcv_bcast_pkts);
2908
2909 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
f33f1fcc 2910 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34
BW
2911
2912 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
2913 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
2914
2915 ADD_64(fcoe_stat->tx_bytes_hi,
2916 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
2917 fcoe_stat->tx_bytes_lo,
2918 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
2919
2920 ADD_64(fcoe_stat->tx_bytes_hi,
2921 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
2922 fcoe_stat->tx_bytes_lo,
2923 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
2924
2925 ADD_64(fcoe_stat->tx_bytes_hi,
2926 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
2927 fcoe_stat->tx_bytes_lo,
2928 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
2929
2930 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2931 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
2932
2933 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2934 fcoe_q_xstorm_stats->ucast_pkts_sent);
2935
2936 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2937 fcoe_q_xstorm_stats->bcast_pkts_sent);
2938
2939 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2940 fcoe_q_xstorm_stats->mcast_pkts_sent);
2941 }
2942
1d187b34
BW
2943 /* ask L5 driver to add data to the struct */
2944 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
2945#endif
2946}
2947
2948static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
2949{
f2fd5c34 2950#ifdef BCM_CNIC
1d187b34
BW
2951 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
2952 struct iscsi_stats_info *iscsi_stat =
2953 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
2954
2955 memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
2956
2957 iscsi_stat->qos_priority =
2958 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
2959
1d187b34
BW
2960 /* ask L5 driver to add data to the struct */
2961 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
2962#endif
2963}
2964
0793f83f
DK
2965/* called due to MCP event (on pmf):
2966 * reread new bandwidth configuration
2967 * configure FW
2968 * notify others function about the change
2969 */
2970static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2971{
2972 if (bp->link_vars.link_up) {
2973 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2974 bnx2x_link_sync_notify(bp);
2975 }
2976 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2977}
2978
2979static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2980{
2981 bnx2x_config_mf_bw(bp);
2982 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2983}
2984
1d187b34
BW
2985static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
2986{
2987 enum drv_info_opcode op_code;
2988 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
2989
2990 /* if drv_info version supported by MFW doesn't match - send NACK */
2991 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
2992 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
2993 return;
2994 }
2995
2996 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
2997 DRV_INFO_CONTROL_OP_CODE_SHIFT;
2998
2999 memset(&bp->slowpath->drv_info_to_mcp, 0,
3000 sizeof(union drv_info_to_mcp));
3001
3002 switch (op_code) {
3003 case ETH_STATS_OPCODE:
3004 bnx2x_drv_info_ether_stat(bp);
3005 break;
3006 case FCOE_STATS_OPCODE:
3007 bnx2x_drv_info_fcoe_stat(bp);
3008 break;
3009 case ISCSI_STATS_OPCODE:
3010 bnx2x_drv_info_iscsi_stat(bp);
3011 break;
3012 default:
3013 /* if op code isn't supported - send NACK */
3014 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3015 return;
3016 }
3017
3018 /* if we got drv_info attn from MFW then these fields are defined in
3019 * shmem2 for sure
3020 */
3021 SHMEM2_WR(bp, drv_info_host_addr_lo,
3022 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3023 SHMEM2_WR(bp, drv_info_host_addr_hi,
3024 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3025
3026 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3027}
3028
523224a3
DK
3029static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3030{
3031 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3032
3033 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3034
3035 /*
3036 * This is the only place besides the function initialization
3037 * where the bp->flags can change so it is done without any
3038 * locks
3039 */
f2e0899f 3040 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3041 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3042 bp->flags |= MF_FUNC_DIS;
3043
3044 bnx2x_e1h_disable(bp);
3045 } else {
51c1a580 3046 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3047 bp->flags &= ~MF_FUNC_DIS;
3048
3049 bnx2x_e1h_enable(bp);
3050 }
3051 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3052 }
3053 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3054 bnx2x_config_mf_bw(bp);
523224a3
DK
3055 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3056 }
3057
3058 /* Report results to MCP */
3059 if (dcc_event)
3060 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3061 else
3062 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3063}
3064
3065/* must be called under the spq lock */
3066static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
3067{
3068 struct eth_spe *next_spe = bp->spq_prod_bd;
3069
3070 if (bp->spq_prod_bd == bp->spq_last_bd) {
3071 bp->spq_prod_bd = bp->spq;
3072 bp->spq_prod_idx = 0;
51c1a580 3073 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3074 } else {
3075 bp->spq_prod_bd++;
3076 bp->spq_prod_idx++;
3077 }
3078 return next_spe;
3079}
3080
3081/* must be called under the spq lock */
28912902
MC
3082static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
3083{
3084 int func = BP_FUNC(bp);
3085
53e51e2f
VZ
3086 /*
3087 * Make sure that BD data is updated before writing the producer:
3088 * BD data is written to the memory, the producer is read from the
3089 * memory, thus we need a full memory barrier to ensure the ordering.
3090 */
3091 mb();
28912902 3092
523224a3 3093 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3094 bp->spq_prod_idx);
28912902
MC
3095 mmiowb();
3096}
3097
619c5cb6
VZ
3098/**
3099 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3100 *
3101 * @cmd: command to check
3102 * @cmd_type: command type
3103 */
3104static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3105{
3106 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3107 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3108 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3109 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3110 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3111 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3112 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3113 return true;
3114 else
3115 return false;
3116
3117}
3118
3119
3120/**
3121 * bnx2x_sp_post - place a single command on an SP ring
3122 *
3123 * @bp: driver handle
3124 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3125 * @cid: SW CID the command is related to
3126 * @data_hi: command private data address (high 32 bits)
3127 * @data_lo: command private data address (low 32 bits)
3128 * @cmd_type: command type (e.g. NONE, ETH)
3129 *
3130 * SP data is handled as if it's always an address pair, thus data fields are
3131 * not swapped to little endian in upper functions. Instead this function swaps
3132 * data as if it's two u32 fields.
3133 */
9f6c9258 3134int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3135 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3136{
28912902 3137 struct eth_spe *spe;
523224a3 3138 u16 type;
619c5cb6 3139 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3140
a2fbb9ea 3141#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3142 if (unlikely(bp->panic)) {
3143 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3144 return -EIO;
51c1a580 3145 }
a2fbb9ea
ET
3146#endif
3147
34f80b04 3148 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3149
6e30dd4e
VZ
3150 if (common) {
3151 if (!atomic_read(&bp->eq_spq_left)) {
3152 BNX2X_ERR("BUG! EQ ring full!\n");
3153 spin_unlock_bh(&bp->spq_lock);
3154 bnx2x_panic();
3155 return -EBUSY;
3156 }
3157 } else if (!atomic_read(&bp->cq_spq_left)) {
3158 BNX2X_ERR("BUG! SPQ ring full!\n");
3159 spin_unlock_bh(&bp->spq_lock);
3160 bnx2x_panic();
3161 return -EBUSY;
a2fbb9ea 3162 }
f1410647 3163
28912902
MC
3164 spe = bnx2x_sp_get_next(bp);
3165
a2fbb9ea 3166 /* CID needs port number to be encoded int it */
28912902 3167 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3168 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3169 HW_CID(bp, cid));
523224a3 3170
619c5cb6 3171 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3172
523224a3
DK
3173 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3174 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3175
523224a3
DK
3176 spe->hdr.type = cpu_to_le16(type);
3177
3178 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3179 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3180
d6cae238
VZ
3181 /*
3182 * It's ok if the actual decrement is issued towards the memory
3183 * somewhere between the spin_lock and spin_unlock. Thus no
3184 * more explict memory barrier is needed.
3185 */
3186 if (common)
3187 atomic_dec(&bp->eq_spq_left);
3188 else
3189 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3190
a2fbb9ea 3191
51c1a580
MS
3192 DP(BNX2X_MSG_SP,
3193 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
cdaa7cb8
VZ
3194 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3195 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3196 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3197 HW_CID(bp, cid), data_hi, data_lo, type,
3198 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3199
28912902 3200 bnx2x_sp_prod_update(bp);
34f80b04 3201 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3202 return 0;
3203}
3204
3205/* acquire split MCP access lock register */
4a37fb66 3206static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3207{
72fd0718 3208 u32 j, val;
34f80b04 3209 int rc = 0;
a2fbb9ea
ET
3210
3211 might_sleep();
72fd0718 3212 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3213 val = (1UL << 31);
3214 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3215 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3216 if (val & (1L << 31))
3217 break;
3218
3219 msleep(5);
3220 }
a2fbb9ea 3221 if (!(val & (1L << 31))) {
19680c48 3222 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3223 rc = -EBUSY;
3224 }
3225
3226 return rc;
3227}
3228
4a37fb66
YG
3229/* release split MCP access lock register */
3230static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3231{
72fd0718 3232 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3233}
3234
523224a3
DK
3235#define BNX2X_DEF_SB_ATT_IDX 0x0001
3236#define BNX2X_DEF_SB_IDX 0x0002
3237
a2fbb9ea
ET
3238static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3239{
523224a3 3240 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3241 u16 rc = 0;
3242
3243 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3244 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3245 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3246 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3247 }
523224a3
DK
3248
3249 if (bp->def_idx != def_sb->sp_sb.running_index) {
3250 bp->def_idx = def_sb->sp_sb.running_index;
3251 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3252 }
523224a3
DK
3253
3254 /* Do not reorder: indecies reading should complete before handling */
3255 barrier();
a2fbb9ea
ET
3256 return rc;
3257}
3258
3259/*
3260 * slow path service functions
3261 */
3262
3263static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3264{
34f80b04 3265 int port = BP_PORT(bp);
a2fbb9ea
ET
3266 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3267 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3268 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3269 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3270 u32 aeu_mask;
87942b46 3271 u32 nig_mask = 0;
f2e0899f 3272 u32 reg_addr;
a2fbb9ea 3273
a2fbb9ea
ET
3274 if (bp->attn_state & asserted)
3275 BNX2X_ERR("IGU ERROR\n");
3276
3fcaf2e5
EG
3277 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3278 aeu_mask = REG_RD(bp, aeu_addr);
3279
a2fbb9ea 3280 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3281 aeu_mask, asserted);
72fd0718 3282 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3283 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3284
3fcaf2e5
EG
3285 REG_WR(bp, aeu_addr, aeu_mask);
3286 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3287
3fcaf2e5 3288 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3289 bp->attn_state |= asserted;
3fcaf2e5 3290 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3291
3292 if (asserted & ATTN_HARD_WIRED_MASK) {
3293 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3294
a5e9a7cf
EG
3295 bnx2x_acquire_phy_lock(bp);
3296
877e9aa4 3297 /* save nig interrupt mask */
87942b46 3298 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3299
361c391e
YR
3300 /* If nig_mask is not set, no need to call the update
3301 * function.
3302 */
3303 if (nig_mask) {
3304 REG_WR(bp, nig_int_mask_addr, 0);
3305
3306 bnx2x_link_attn(bp);
3307 }
a2fbb9ea
ET
3308
3309 /* handle unicore attn? */
3310 }
3311 if (asserted & ATTN_SW_TIMER_4_FUNC)
3312 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3313
3314 if (asserted & GPIO_2_FUNC)
3315 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3316
3317 if (asserted & GPIO_3_FUNC)
3318 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3319
3320 if (asserted & GPIO_4_FUNC)
3321 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3322
3323 if (port == 0) {
3324 if (asserted & ATTN_GENERAL_ATTN_1) {
3325 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3326 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3327 }
3328 if (asserted & ATTN_GENERAL_ATTN_2) {
3329 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3330 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3331 }
3332 if (asserted & ATTN_GENERAL_ATTN_3) {
3333 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3334 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3335 }
3336 } else {
3337 if (asserted & ATTN_GENERAL_ATTN_4) {
3338 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3339 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3340 }
3341 if (asserted & ATTN_GENERAL_ATTN_5) {
3342 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3343 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3344 }
3345 if (asserted & ATTN_GENERAL_ATTN_6) {
3346 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3347 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3348 }
3349 }
3350
3351 } /* if hardwired */
3352
f2e0899f
DK
3353 if (bp->common.int_block == INT_BLOCK_HC)
3354 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3355 COMMAND_REG_ATTN_BITS_SET);
3356 else
3357 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3358
3359 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3360 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3361 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3362
3363 /* now set back the mask */
a5e9a7cf 3364 if (asserted & ATTN_NIG_FOR_FUNC) {
87942b46 3365 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3366 bnx2x_release_phy_lock(bp);
3367 }
a2fbb9ea
ET
3368}
3369
fd4ef40d
EG
3370static inline void bnx2x_fan_failure(struct bnx2x *bp)
3371{
3372 int port = BP_PORT(bp);
b7737c9b 3373 u32 ext_phy_config;
fd4ef40d 3374 /* mark the failure */
b7737c9b
YR
3375 ext_phy_config =
3376 SHMEM_RD(bp,
3377 dev_info.port_hw_config[port].external_phy_config);
3378
3379 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3380 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3381 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3382 ext_phy_config);
fd4ef40d
EG
3383
3384 /* log the failure */
51c1a580
MS
3385 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3386 "Please contact OEM Support for assistance\n");
8304859a
AE
3387
3388 /*
3389 * Scheudle device reset (unload)
3390 * This is due to some boards consuming sufficient power when driver is
3391 * up to overheat if fan fails.
3392 */
3393 smp_mb__before_clear_bit();
3394 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3395 smp_mb__after_clear_bit();
3396 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3397
fd4ef40d 3398}
ab6ad5a4 3399
877e9aa4 3400static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3401{
34f80b04 3402 int port = BP_PORT(bp);
877e9aa4 3403 int reg_offset;
d90d96ba 3404 u32 val;
877e9aa4 3405
34f80b04
EG
3406 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3407 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3408
34f80b04 3409 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3410
3411 val = REG_RD(bp, reg_offset);
3412 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3413 REG_WR(bp, reg_offset, val);
3414
3415 BNX2X_ERR("SPIO5 hw attention\n");
3416
fd4ef40d 3417 /* Fan failure attention */
d90d96ba 3418 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3419 bnx2x_fan_failure(bp);
877e9aa4 3420 }
34f80b04 3421
3deb8167 3422 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3423 bnx2x_acquire_phy_lock(bp);
3424 bnx2x_handle_module_detect_int(&bp->link_params);
3425 bnx2x_release_phy_lock(bp);
3426 }
3427
34f80b04
EG
3428 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3429
3430 val = REG_RD(bp, reg_offset);
3431 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3432 REG_WR(bp, reg_offset, val);
3433
3434 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3435 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3436 bnx2x_panic();
3437 }
877e9aa4
ET
3438}
3439
3440static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3441{
3442 u32 val;
3443
0626b899 3444 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3445
3446 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3447 BNX2X_ERR("DB hw attention 0x%x\n", val);
3448 /* DORQ discard attention */
3449 if (val & 0x2)
3450 BNX2X_ERR("FATAL error from DORQ\n");
3451 }
34f80b04
EG
3452
3453 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3454
3455 int port = BP_PORT(bp);
3456 int reg_offset;
3457
3458 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3459 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3460
3461 val = REG_RD(bp, reg_offset);
3462 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3463 REG_WR(bp, reg_offset, val);
3464
3465 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3466 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3467 bnx2x_panic();
3468 }
877e9aa4
ET
3469}
3470
3471static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3472{
3473 u32 val;
3474
3475 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3476
3477 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3478 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3479 /* CFC error attention */
3480 if (val & 0x2)
3481 BNX2X_ERR("FATAL error from CFC\n");
3482 }
3483
3484 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3485 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3486 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3487 /* RQ_USDMDP_FIFO_OVERFLOW */
3488 if (val & 0x18000)
3489 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3490
3491 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3492 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3493 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3494 }
877e9aa4 3495 }
34f80b04
EG
3496
3497 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3498
3499 int port = BP_PORT(bp);
3500 int reg_offset;
3501
3502 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3503 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3504
3505 val = REG_RD(bp, reg_offset);
3506 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3507 REG_WR(bp, reg_offset, val);
3508
3509 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3510 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3511 bnx2x_panic();
3512 }
877e9aa4
ET
3513}
3514
3515static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3516{
34f80b04
EG
3517 u32 val;
3518
877e9aa4
ET
3519 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3520
34f80b04
EG
3521 if (attn & BNX2X_PMF_LINK_ASSERT) {
3522 int func = BP_FUNC(bp);
3523
3524 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
f2e0899f
DK
3525 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3526 func_mf_config[BP_ABS_FUNC(bp)].config);
3527 val = SHMEM_RD(bp,
3528 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3529 if (val & DRV_STATUS_DCC_EVENT_MASK)
3530 bnx2x_dcc_event(bp,
3531 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3532
3533 if (val & DRV_STATUS_SET_MF_BW)
3534 bnx2x_set_mf_bw(bp);
3535
1d187b34
BW
3536 if (val & DRV_STATUS_DRV_INFO_REQ)
3537 bnx2x_handle_drv_info_req(bp);
2691d51d 3538 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3539 bnx2x_pmf_update(bp);
3540
e4901dde 3541 if (bp->port.pmf &&
785b9b1a
SR
3542 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3543 bp->dcbx_enabled > 0)
e4901dde
VZ
3544 /* start dcbx state machine */
3545 bnx2x_dcbx_set_params(bp,
3546 BNX2X_DCBX_STATE_NEG_RECEIVED);
3deb8167
YR
3547 if (bp->link_vars.periodic_flags &
3548 PERIODIC_FLAGS_LINK_EVENT) {
3549 /* sync with link */
3550 bnx2x_acquire_phy_lock(bp);
3551 bp->link_vars.periodic_flags &=
3552 ~PERIODIC_FLAGS_LINK_EVENT;
3553 bnx2x_release_phy_lock(bp);
3554 if (IS_MF(bp))
3555 bnx2x_link_sync_notify(bp);
3556 bnx2x_link_report(bp);
3557 }
3558 /* Always call it here: bnx2x_link_report() will
3559 * prevent the link indication duplication.
3560 */
3561 bnx2x__link_status_update(bp);
34f80b04 3562 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
3563
3564 BNX2X_ERR("MC assert!\n");
d6cae238 3565 bnx2x_mc_assert(bp);
877e9aa4
ET
3566 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3567 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3568 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3569 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3570 bnx2x_panic();
3571
3572 } else if (attn & BNX2X_MCP_ASSERT) {
3573
3574 BNX2X_ERR("MCP assert!\n");
3575 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 3576 bnx2x_fw_dump(bp);
877e9aa4
ET
3577
3578 } else
3579 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3580 }
3581
3582 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
3583 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3584 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
3585 val = CHIP_IS_E1(bp) ? 0 :
3586 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
3587 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3588 }
3589 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
3590 val = CHIP_IS_E1(bp) ? 0 :
3591 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
3592 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3593 }
877e9aa4 3594 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
3595 }
3596}
3597
c9ee9206
VZ
3598/*
3599 * Bits map:
3600 * 0-7 - Engine0 load counter.
3601 * 8-15 - Engine1 load counter.
3602 * 16 - Engine0 RESET_IN_PROGRESS bit.
3603 * 17 - Engine1 RESET_IN_PROGRESS bit.
3604 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3605 * on the engine
3606 * 19 - Engine1 ONE_IS_LOADED.
3607 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3608 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3609 * just the one belonging to its engine).
3610 *
3611 */
3612#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3613
3614#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3615#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3616#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3617#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3618#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3619#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3620#define BNX2X_GLOBAL_RESET_BIT 0x00040000
3621
3622/*
3623 * Set the GLOBAL_RESET bit.
3624 *
3625 * Should be run under rtnl lock
3626 */
3627void bnx2x_set_reset_global(struct bnx2x *bp)
3628{
f16da43b
AE
3629 u32 val;
3630 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3631 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3632 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 3633 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
3634}
3635
3636/*
3637 * Clear the GLOBAL_RESET bit.
3638 *
3639 * Should be run under rtnl lock
3640 */
3641static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3642{
f16da43b
AE
3643 u32 val;
3644 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3645 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3646 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 3647 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 3648}
f85582f8 3649
72fd0718 3650/*
c9ee9206
VZ
3651 * Checks the GLOBAL_RESET bit.
3652 *
72fd0718
VZ
3653 * should be run under rtnl lock
3654 */
c9ee9206
VZ
3655static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3656{
3657 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3658
3659 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3660 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3661}
3662
3663/*
3664 * Clear RESET_IN_PROGRESS bit for the current engine.
3665 *
3666 * Should be run under rtnl lock
3667 */
72fd0718
VZ
3668static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3669{
f16da43b 3670 u32 val;
c9ee9206
VZ
3671 u32 bit = BP_PATH(bp) ?
3672 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3673 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3674 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3675
3676 /* Clear the bit */
3677 val &= ~bit;
3678 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
3679
3680 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3681}
3682
3683/*
c9ee9206
VZ
3684 * Set RESET_IN_PROGRESS for the current engine.
3685 *
72fd0718
VZ
3686 * should be run under rtnl lock
3687 */
c9ee9206 3688void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 3689{
f16da43b 3690 u32 val;
c9ee9206
VZ
3691 u32 bit = BP_PATH(bp) ?
3692 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3693 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3694 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3695
3696 /* Set the bit */
3697 val |= bit;
3698 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3699 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3700}
3701
3702/*
c9ee9206 3703 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
3704 * should be run under rtnl lock
3705 */
c9ee9206 3706bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 3707{
c9ee9206
VZ
3708 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3709 u32 bit = engine ?
3710 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3711
3712 /* return false if bit is set */
3713 return (val & bit) ? false : true;
72fd0718
VZ
3714}
3715
3716/*
889b9af3 3717 * set pf load for the current pf.
c9ee9206 3718 *
72fd0718
VZ
3719 * should be run under rtnl lock
3720 */
889b9af3 3721void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 3722{
f16da43b 3723 u32 val1, val;
c9ee9206
VZ
3724 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3725 BNX2X_PATH0_LOAD_CNT_MASK;
3726 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3727 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3728
f16da43b
AE
3729 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3730 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3731
51c1a580 3732 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 3733
c9ee9206
VZ
3734 /* get the current counter value */
3735 val1 = (val & mask) >> shift;
3736
889b9af3
AE
3737 /* set bit of that PF */
3738 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
3739
3740 /* clear the old value */
3741 val &= ~mask;
3742
3743 /* set the new one */
3744 val |= ((val1 << shift) & mask);
3745
3746 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3747 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3748}
3749
c9ee9206 3750/**
889b9af3 3751 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
3752 *
3753 * @bp: driver handle
3754 *
3755 * Should be run under rtnl lock.
3756 * Decrements the load counter for the current engine. Returns
889b9af3 3757 * whether other functions are still loaded
72fd0718 3758 */
889b9af3 3759bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 3760{
f16da43b 3761 u32 val1, val;
c9ee9206
VZ
3762 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3763 BNX2X_PATH0_LOAD_CNT_MASK;
3764 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3765 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3766
f16da43b
AE
3767 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3768 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 3769 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 3770
c9ee9206
VZ
3771 /* get the current counter value */
3772 val1 = (val & mask) >> shift;
3773
889b9af3
AE
3774 /* clear bit of that PF */
3775 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
3776
3777 /* clear the old value */
3778 val &= ~mask;
3779
3780 /* set the new one */
3781 val |= ((val1 << shift) & mask);
3782
3783 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
3784 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3785 return val1 != 0;
72fd0718
VZ
3786}
3787
3788/*
889b9af3 3789 * Read the load status for the current engine.
c9ee9206 3790 *
72fd0718
VZ
3791 * should be run under rtnl lock
3792 */
889b9af3 3793static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 3794{
c9ee9206
VZ
3795 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3796 BNX2X_PATH0_LOAD_CNT_MASK);
3797 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3798 BNX2X_PATH0_LOAD_CNT_SHIFT);
3799 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3800
51c1a580 3801 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
3802
3803 val = (val & mask) >> shift;
3804
51c1a580
MS
3805 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
3806 engine, val);
c9ee9206 3807
889b9af3 3808 return val != 0;
72fd0718
VZ
3809}
3810
c9ee9206 3811/*
889b9af3 3812 * Reset the load status for the current engine.
c9ee9206 3813 */
889b9af3 3814static inline void bnx2x_clear_load_status(struct bnx2x *bp)
72fd0718 3815{
f16da43b 3816 u32 val;
c9ee9206 3817 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
f16da43b
AE
3818 BNX2X_PATH0_LOAD_CNT_MASK);
3819 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3820 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3821 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
f16da43b 3822 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3823}
3824
3825static inline void _print_next_block(int idx, const char *blk)
3826{
f1deab50 3827 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
3828}
3829
c9ee9206
VZ
3830static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3831 bool print)
72fd0718
VZ
3832{
3833 int i = 0;
3834 u32 cur_bit = 0;
3835 for (i = 0; sig; i++) {
3836 cur_bit = ((u32)0x1 << i);
3837 if (sig & cur_bit) {
3838 switch (cur_bit) {
3839 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
3840 if (print)
3841 _print_next_block(par_num++, "BRB");
72fd0718
VZ
3842 break;
3843 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
3844 if (print)
3845 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
3846 break;
3847 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
3848 if (print)
3849 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
3850 break;
3851 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
3852 if (print)
3853 _print_next_block(par_num++,
3854 "SEARCHER");
3855 break;
3856 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3857 if (print)
3858 _print_next_block(par_num++, "TCM");
72fd0718
VZ
3859 break;
3860 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
3861 if (print)
3862 _print_next_block(par_num++, "TSEMI");
3863 break;
3864 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3865 if (print)
3866 _print_next_block(par_num++, "XPB");
72fd0718
VZ
3867 break;
3868 }
3869
3870 /* Clear the bit */
3871 sig &= ~cur_bit;
3872 }
3873 }
3874
3875 return par_num;
3876}
3877
c9ee9206
VZ
3878static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3879 bool *global, bool print)
72fd0718
VZ
3880{
3881 int i = 0;
3882 u32 cur_bit = 0;
3883 for (i = 0; sig; i++) {
3884 cur_bit = ((u32)0x1 << i);
3885 if (sig & cur_bit) {
3886 switch (cur_bit) {
c9ee9206
VZ
3887 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3888 if (print)
3889 _print_next_block(par_num++, "PBF");
72fd0718
VZ
3890 break;
3891 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
3892 if (print)
3893 _print_next_block(par_num++, "QM");
3894 break;
3895 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3896 if (print)
3897 _print_next_block(par_num++, "TM");
72fd0718
VZ
3898 break;
3899 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
3900 if (print)
3901 _print_next_block(par_num++, "XSDM");
3902 break;
3903 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3904 if (print)
3905 _print_next_block(par_num++, "XCM");
72fd0718
VZ
3906 break;
3907 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
3908 if (print)
3909 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
3910 break;
3911 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
3912 if (print)
3913 _print_next_block(par_num++,
3914 "DOORBELLQ");
3915 break;
3916 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3917 if (print)
3918 _print_next_block(par_num++, "NIG");
72fd0718
VZ
3919 break;
3920 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
3921 if (print)
3922 _print_next_block(par_num++,
3923 "VAUX PCI CORE");
3924 *global = true;
72fd0718
VZ
3925 break;
3926 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
3927 if (print)
3928 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
3929 break;
3930 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
3931 if (print)
3932 _print_next_block(par_num++, "USDM");
72fd0718 3933 break;
8736c826
VZ
3934 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
3935 if (print)
3936 _print_next_block(par_num++, "UCM");
3937 break;
72fd0718 3938 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
3939 if (print)
3940 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
3941 break;
3942 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
3943 if (print)
3944 _print_next_block(par_num++, "UPB");
72fd0718
VZ
3945 break;
3946 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
3947 if (print)
3948 _print_next_block(par_num++, "CSDM");
72fd0718 3949 break;
8736c826
VZ
3950 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
3951 if (print)
3952 _print_next_block(par_num++, "CCM");
3953 break;
72fd0718
VZ
3954 }
3955
3956 /* Clear the bit */
3957 sig &= ~cur_bit;
3958 }
3959 }
3960
3961 return par_num;
3962}
3963
c9ee9206
VZ
3964static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3965 bool print)
72fd0718
VZ
3966{
3967 int i = 0;
3968 u32 cur_bit = 0;
3969 for (i = 0; sig; i++) {
3970 cur_bit = ((u32)0x1 << i);
3971 if (sig & cur_bit) {
3972 switch (cur_bit) {
3973 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
3974 if (print)
3975 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
3976 break;
3977 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
3978 if (print)
3979 _print_next_block(par_num++, "PXP");
72fd0718
VZ
3980 break;
3981 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
3982 if (print)
3983 _print_next_block(par_num++,
72fd0718
VZ
3984 "PXPPCICLOCKCLIENT");
3985 break;
3986 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
3987 if (print)
3988 _print_next_block(par_num++, "CFC");
72fd0718
VZ
3989 break;
3990 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
3991 if (print)
3992 _print_next_block(par_num++, "CDU");
3993 break;
3994 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3995 if (print)
3996 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
3997 break;
3998 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
3999 if (print)
4000 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4001 break;
4002 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4003 if (print)
4004 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4005 break;
4006 }
4007
4008 /* Clear the bit */
4009 sig &= ~cur_bit;
4010 }
4011 }
4012
4013 return par_num;
4014}
4015
c9ee9206
VZ
4016static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4017 bool *global, bool print)
72fd0718
VZ
4018{
4019 int i = 0;
4020 u32 cur_bit = 0;
4021 for (i = 0; sig; i++) {
4022 cur_bit = ((u32)0x1 << i);
4023 if (sig & cur_bit) {
4024 switch (cur_bit) {
4025 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4026 if (print)
4027 _print_next_block(par_num++, "MCP ROM");
4028 *global = true;
72fd0718
VZ
4029 break;
4030 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4031 if (print)
4032 _print_next_block(par_num++,
4033 "MCP UMP RX");
4034 *global = true;
72fd0718
VZ
4035 break;
4036 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4037 if (print)
4038 _print_next_block(par_num++,
4039 "MCP UMP TX");
4040 *global = true;
72fd0718
VZ
4041 break;
4042 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4043 if (print)
4044 _print_next_block(par_num++,
4045 "MCP SCPAD");
4046 *global = true;
72fd0718
VZ
4047 break;
4048 }
4049
4050 /* Clear the bit */
4051 sig &= ~cur_bit;
4052 }
4053 }
4054
4055 return par_num;
4056}
4057
8736c826
VZ
4058static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4059 bool print)
4060{
4061 int i = 0;
4062 u32 cur_bit = 0;
4063 for (i = 0; sig; i++) {
4064 cur_bit = ((u32)0x1 << i);
4065 if (sig & cur_bit) {
4066 switch (cur_bit) {
4067 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4068 if (print)
4069 _print_next_block(par_num++, "PGLUE_B");
4070 break;
4071 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4072 if (print)
4073 _print_next_block(par_num++, "ATC");
4074 break;
4075 }
4076
4077 /* Clear the bit */
4078 sig &= ~cur_bit;
4079 }
4080 }
4081
4082 return par_num;
4083}
4084
c9ee9206 4085static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
8736c826 4086 u32 *sig)
72fd0718 4087{
8736c826
VZ
4088 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4089 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4090 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4091 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4092 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4093 int par_num = 0;
51c1a580
MS
4094 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4095 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4096 sig[0] & HW_PRTY_ASSERT_SET_0,
4097 sig[1] & HW_PRTY_ASSERT_SET_1,
4098 sig[2] & HW_PRTY_ASSERT_SET_2,
4099 sig[3] & HW_PRTY_ASSERT_SET_3,
4100 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4101 if (print)
4102 netdev_err(bp->dev,
4103 "Parity errors detected in blocks: ");
4104 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4105 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4106 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4107 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4108 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4109 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4110 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4111 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4112 par_num = bnx2x_check_blocks_with_parity4(
4113 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4114
c9ee9206
VZ
4115 if (print)
4116 pr_cont("\n");
8736c826 4117
72fd0718
VZ
4118 return true;
4119 } else
4120 return false;
4121}
4122
c9ee9206
VZ
4123/**
4124 * bnx2x_chk_parity_attn - checks for parity attentions.
4125 *
4126 * @bp: driver handle
4127 * @global: true if there was a global attention
4128 * @print: show parity attention in syslog
4129 */
4130bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4131{
8736c826 4132 struct attn_route attn = { {0} };
72fd0718
VZ
4133 int port = BP_PORT(bp);
4134
4135 attn.sig[0] = REG_RD(bp,
4136 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4137 port*4);
4138 attn.sig[1] = REG_RD(bp,
4139 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4140 port*4);
4141 attn.sig[2] = REG_RD(bp,
4142 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4143 port*4);
4144 attn.sig[3] = REG_RD(bp,
4145 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4146 port*4);
4147
8736c826
VZ
4148 if (!CHIP_IS_E1x(bp))
4149 attn.sig[4] = REG_RD(bp,
4150 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4151 port*4);
4152
4153 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4154}
4155
f2e0899f
DK
4156
4157static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
4158{
4159 u32 val;
4160 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4161
4162 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4163 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4164 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4165 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4166 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4167 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4168 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4169 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4170 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4171 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4172 if (val &
4173 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4174 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4175 if (val &
4176 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4177 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4178 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4179 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4180 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4181 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4182 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4183 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4184 }
4185 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4186 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4187 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4188 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4189 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4190 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4191 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4192 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4193 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4194 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4195 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4196 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4197 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4198 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4199 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4200 }
4201
4202 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4203 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4204 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4205 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4206 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4207 }
4208
4209}
4210
72fd0718
VZ
4211static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4212{
4213 struct attn_route attn, *group_mask;
34f80b04 4214 int port = BP_PORT(bp);
877e9aa4 4215 int index;
a2fbb9ea
ET
4216 u32 reg_addr;
4217 u32 val;
3fcaf2e5 4218 u32 aeu_mask;
c9ee9206 4219 bool global = false;
a2fbb9ea
ET
4220
4221 /* need to take HW lock because MCP or other port might also
4222 try to handle this event */
4a37fb66 4223 bnx2x_acquire_alr(bp);
a2fbb9ea 4224
c9ee9206
VZ
4225 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4226#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4227 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4228 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4229 /* Disable HW interrupts */
4230 bnx2x_int_disable(bp);
72fd0718
VZ
4231 /* In case of parity errors don't handle attentions so that
4232 * other function would "see" parity errors.
4233 */
c9ee9206
VZ
4234#else
4235 bnx2x_panic();
4236#endif
4237 bnx2x_release_alr(bp);
72fd0718
VZ
4238 return;
4239 }
4240
a2fbb9ea
ET
4241 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4242 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4243 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4244 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4245 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4246 attn.sig[4] =
4247 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4248 else
4249 attn.sig[4] = 0;
4250
4251 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4252 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4253
4254 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4255 if (deasserted & (1 << index)) {
72fd0718 4256 group_mask = &bp->attn_group[index];
a2fbb9ea 4257
51c1a580 4258 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4259 index,
4260 group_mask->sig[0], group_mask->sig[1],
4261 group_mask->sig[2], group_mask->sig[3],
4262 group_mask->sig[4]);
a2fbb9ea 4263
f2e0899f
DK
4264 bnx2x_attn_int_deasserted4(bp,
4265 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4266 bnx2x_attn_int_deasserted3(bp,
72fd0718 4267 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4268 bnx2x_attn_int_deasserted1(bp,
72fd0718 4269 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4270 bnx2x_attn_int_deasserted2(bp,
72fd0718 4271 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4272 bnx2x_attn_int_deasserted0(bp,
72fd0718 4273 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4274 }
4275 }
4276
4a37fb66 4277 bnx2x_release_alr(bp);
a2fbb9ea 4278
f2e0899f
DK
4279 if (bp->common.int_block == INT_BLOCK_HC)
4280 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4281 COMMAND_REG_ATTN_BITS_CLR);
4282 else
4283 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4284
4285 val = ~deasserted;
f2e0899f
DK
4286 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4287 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4288 REG_WR(bp, reg_addr, val);
a2fbb9ea 4289
a2fbb9ea 4290 if (~bp->attn_state & deasserted)
3fcaf2e5 4291 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4292
4293 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4294 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4295
3fcaf2e5
EG
4296 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4297 aeu_mask = REG_RD(bp, reg_addr);
4298
4299 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4300 aeu_mask, deasserted);
72fd0718 4301 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4302 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4303
3fcaf2e5
EG
4304 REG_WR(bp, reg_addr, aeu_mask);
4305 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4306
4307 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4308 bp->attn_state &= ~deasserted;
4309 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4310}
4311
4312static void bnx2x_attn_int(struct bnx2x *bp)
4313{
4314 /* read local copy of bits */
68d59484
EG
4315 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4316 attn_bits);
4317 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4318 attn_bits_ack);
a2fbb9ea
ET
4319 u32 attn_state = bp->attn_state;
4320
4321 /* look for changed bits */
4322 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4323 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4324
4325 DP(NETIF_MSG_HW,
4326 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4327 attn_bits, attn_ack, asserted, deasserted);
4328
4329 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4330 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4331
4332 /* handle bits that were raised */
4333 if (asserted)
4334 bnx2x_attn_int_asserted(bp, asserted);
4335
4336 if (deasserted)
4337 bnx2x_attn_int_deasserted(bp, deasserted);
4338}
4339
619c5cb6
VZ
4340void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4341 u16 index, u8 op, u8 update)
4342{
4343 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4344
4345 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4346 igu_addr);
4347}
4348
523224a3
DK
4349static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4350{
4351 /* No memory barriers */
4352 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4353 mmiowb(); /* keep prod updates ordered */
4354}
4355
4356#ifdef BCM_CNIC
4357static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4358 union event_ring_elem *elem)
4359{
619c5cb6
VZ
4360 u8 err = elem->message.error;
4361
523224a3 4362 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4363 (cid < bp->cnic_eth_dev.starting_cid &&
4364 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4365 return 1;
4366
4367 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4368
619c5cb6
VZ
4369 if (unlikely(err)) {
4370
523224a3
DK
4371 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4372 cid);
4373 bnx2x_panic_dump(bp);
4374 }
619c5cb6 4375 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4376 return 0;
4377}
4378#endif
4379
619c5cb6
VZ
4380static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4381{
4382 struct bnx2x_mcast_ramrod_params rparam;
4383 int rc;
4384
4385 memset(&rparam, 0, sizeof(rparam));
4386
4387 rparam.mcast_obj = &bp->mcast_obj;
4388
4389 netif_addr_lock_bh(bp->dev);
4390
4391 /* Clear pending state for the last command */
4392 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4393
4394 /* If there are pending mcast commands - send them */
4395 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4396 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4397 if (rc < 0)
4398 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4399 rc);
4400 }
4401
4402 netif_addr_unlock_bh(bp->dev);
4403}
4404
4405static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4406 union event_ring_elem *elem)
4407{
4408 unsigned long ramrod_flags = 0;
4409 int rc = 0;
4410 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4411 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4412
4413 /* Always push next commands out, don't wait here */
4414 __set_bit(RAMROD_CONT, &ramrod_flags);
4415
4416 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4417 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4418 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
619c5cb6
VZ
4419#ifdef BCM_CNIC
4420 if (cid == BNX2X_ISCSI_ETH_CID)
4421 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4422 else
4423#endif
4424 vlan_mac_obj = &bp->fp[cid].mac_obj;
4425
4426 break;
619c5cb6 4427 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4428 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4429 /* This is only relevant for 57710 where multicast MACs are
4430 * configured as unicast MACs using the same ramrod.
4431 */
4432 bnx2x_handle_mcast_eqe(bp);
4433 return;
4434 default:
4435 BNX2X_ERR("Unsupported classification command: %d\n",
4436 elem->message.data.eth_event.echo);
4437 return;
4438 }
4439
4440 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4441
4442 if (rc < 0)
4443 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4444 else if (rc > 0)
4445 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4446
4447}
4448
4449#ifdef BCM_CNIC
4450static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4451#endif
4452
4453static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4454{
4455 netif_addr_lock_bh(bp->dev);
4456
4457 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4458
4459 /* Send rx_mode command again if was requested */
4460 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4461 bnx2x_set_storm_rx_mode(bp);
4462#ifdef BCM_CNIC
4463 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4464 &bp->sp_state))
4465 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4466 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4467 &bp->sp_state))
4468 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4469#endif
4470
4471 netif_addr_unlock_bh(bp->dev);
4472}
4473
4474static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4475 struct bnx2x *bp, u32 cid)
4476{
94f05b0f 4477 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
619c5cb6
VZ
4478#ifdef BCM_CNIC
4479 if (cid == BNX2X_FCOE_ETH_CID)
4480 return &bnx2x_fcoe(bp, q_obj);
4481 else
4482#endif
6383c0b3 4483 return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
619c5cb6
VZ
4484}
4485
523224a3
DK
4486static void bnx2x_eq_int(struct bnx2x *bp)
4487{
4488 u16 hw_cons, sw_cons, sw_prod;
4489 union event_ring_elem *elem;
4490 u32 cid;
4491 u8 opcode;
4492 int spqe_cnt = 0;
619c5cb6
VZ
4493 struct bnx2x_queue_sp_obj *q_obj;
4494 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4495 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4496
4497 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4498
4499 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4500 * when we get the the next-page we nned to adjust so the loop
4501 * condition below will be met. The next element is the size of a
4502 * regular element and hence incrementing by 1
4503 */
4504 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4505 hw_cons++;
4506
25985edc 4507 /* This function may never run in parallel with itself for a
523224a3
DK
4508 * specific bp, thus there is no need in "paired" read memory
4509 * barrier here.
4510 */
4511 sw_cons = bp->eq_cons;
4512 sw_prod = bp->eq_prod;
4513
d6cae238 4514 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 4515 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
4516
4517 for (; sw_cons != hw_cons;
4518 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4519
4520
4521 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4522
4523 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4524 opcode = elem->message.opcode;
4525
4526
4527 /* handle eq element */
4528 switch (opcode) {
4529 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
4530 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4531 "got statistics comp event %d\n",
619c5cb6 4532 bp->stats_comp++);
523224a3 4533 /* nothing to do with stats comp */
d6cae238 4534 goto next_spqe;
523224a3
DK
4535
4536 case EVENT_RING_OPCODE_CFC_DEL:
4537 /* handle according to cid range */
4538 /*
4539 * we may want to verify here that the bp state is
4540 * HALTING
4541 */
d6cae238 4542 DP(BNX2X_MSG_SP,
523224a3
DK
4543 "got delete ramrod for MULTI[%d]\n", cid);
4544#ifdef BCM_CNIC
4545 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4546 goto next_spqe;
4547#endif
619c5cb6
VZ
4548 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4549
4550 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4551 break;
4552
4553
523224a3
DK
4554
4555 goto next_spqe;
e4901dde
VZ
4556
4557 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 4558 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
4559 if (f_obj->complete_cmd(bp, f_obj,
4560 BNX2X_F_CMD_TX_STOP))
4561 break;
e4901dde
VZ
4562 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4563 goto next_spqe;
619c5cb6 4564
e4901dde 4565 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 4566 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
4567 if (f_obj->complete_cmd(bp, f_obj,
4568 BNX2X_F_CMD_TX_START))
4569 break;
e4901dde
VZ
4570 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4571 goto next_spqe;
619c5cb6 4572 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
4573 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4574 "got FUNC_START ramrod\n");
619c5cb6
VZ
4575 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4576 break;
4577
4578 goto next_spqe;
4579
4580 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
4581 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4582 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
4583 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4584 break;
4585
4586 goto next_spqe;
523224a3
DK
4587 }
4588
4589 switch (opcode | bp->state) {
619c5cb6
VZ
4590 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4591 BNX2X_STATE_OPEN):
4592 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 4593 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
4594 cid = elem->message.data.eth_event.echo &
4595 BNX2X_SWCID_MASK;
d6cae238 4596 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
4597 cid);
4598 rss_raw->clear_pending(rss_raw);
523224a3
DK
4599 break;
4600
619c5cb6
VZ
4601 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4602 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4603 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 4604 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
4605 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4606 BNX2X_STATE_OPEN):
4607 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4608 BNX2X_STATE_DIAG):
4609 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4610 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4611 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 4612 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
4613 break;
4614
619c5cb6
VZ
4615 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4616 BNX2X_STATE_OPEN):
4617 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4618 BNX2X_STATE_DIAG):
4619 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4620 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4621 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 4622 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
4623 break;
4624
619c5cb6
VZ
4625 case (EVENT_RING_OPCODE_FILTERS_RULES |
4626 BNX2X_STATE_OPEN):
4627 case (EVENT_RING_OPCODE_FILTERS_RULES |
4628 BNX2X_STATE_DIAG):
4629 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 4630 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4631 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 4632 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
4633 break;
4634 default:
4635 /* unknown event log error and continue */
619c5cb6
VZ
4636 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4637 elem->message.opcode, bp->state);
523224a3
DK
4638 }
4639next_spqe:
4640 spqe_cnt++;
4641 } /* for */
4642
8fe23fbd 4643 smp_mb__before_atomic_inc();
6e30dd4e 4644 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
4645
4646 bp->eq_cons = sw_cons;
4647 bp->eq_prod = sw_prod;
4648 /* Make sure that above mem writes were issued towards the memory */
4649 smp_wmb();
4650
4651 /* update producer */
4652 bnx2x_update_eq_prod(bp, bp->eq_prod);
4653}
4654
a2fbb9ea
ET
4655static void bnx2x_sp_task(struct work_struct *work)
4656{
1cf167f2 4657 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea
ET
4658 u16 status;
4659
a2fbb9ea 4660 status = bnx2x_update_dsb_idx(bp);
34f80b04
EG
4661/* if (status == 0) */
4662/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
a2fbb9ea 4663
51c1a580 4664 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
a2fbb9ea 4665
877e9aa4 4666 /* HW attentions */
523224a3 4667 if (status & BNX2X_DEF_SB_ATT_IDX) {
a2fbb9ea 4668 bnx2x_attn_int(bp);
523224a3 4669 status &= ~BNX2X_DEF_SB_ATT_IDX;
cdaa7cb8
VZ
4670 }
4671
523224a3
DK
4672 /* SP events: STAT_QUERY and others */
4673 if (status & BNX2X_DEF_SB_IDX) {
ec6ba945
VZ
4674#ifdef BCM_CNIC
4675 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 4676
ec6ba945 4677 if ((!NO_FCOE(bp)) &&
019dbb4c
VZ
4678 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
4679 /*
4680 * Prevent local bottom-halves from running as
4681 * we are going to change the local NAPI list.
4682 */
4683 local_bh_disable();
ec6ba945 4684 napi_schedule(&bnx2x_fcoe(bp, napi));
019dbb4c
VZ
4685 local_bh_enable();
4686 }
ec6ba945 4687#endif
523224a3
DK
4688 /* Handle EQ completions */
4689 bnx2x_eq_int(bp);
4690
4691 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4692 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4693
4694 status &= ~BNX2X_DEF_SB_IDX;
cdaa7cb8
VZ
4695 }
4696
4697 if (unlikely(status))
51c1a580 4698 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
cdaa7cb8 4699 status);
a2fbb9ea 4700
523224a3
DK
4701 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4702 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
a2fbb9ea
ET
4703}
4704
9f6c9258 4705irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
4706{
4707 struct net_device *dev = dev_instance;
4708 struct bnx2x *bp = netdev_priv(dev);
4709
523224a3
DK
4710 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4711 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
4712
4713#ifdef BNX2X_STOP_ON_ERROR
4714 if (unlikely(bp->panic))
4715 return IRQ_HANDLED;
4716#endif
4717
993ac7b5
MC
4718#ifdef BCM_CNIC
4719 {
4720 struct cnic_ops *c_ops;
4721
4722 rcu_read_lock();
4723 c_ops = rcu_dereference(bp->cnic_ops);
4724 if (c_ops)
4725 c_ops->cnic_handler(bp->cnic_data, NULL);
4726 rcu_read_unlock();
4727 }
4728#endif
1cf167f2 4729 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
a2fbb9ea
ET
4730
4731 return IRQ_HANDLED;
4732}
4733
4734/* end of slow path */
4735
619c5cb6
VZ
4736
4737void bnx2x_drv_pulse(struct bnx2x *bp)
4738{
4739 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4740 bp->fw_drv_pulse_wr_seq);
4741}
4742
4743
a2fbb9ea
ET
4744static void bnx2x_timer(unsigned long data)
4745{
4746 struct bnx2x *bp = (struct bnx2x *) data;
4747
4748 if (!netif_running(bp->dev))
4749 return;
4750
34f80b04 4751 if (!BP_NOMCP(bp)) {
f2e0899f 4752 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
4753 u32 drv_pulse;
4754 u32 mcp_pulse;
4755
4756 ++bp->fw_drv_pulse_wr_seq;
4757 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4758 /* TBD - add SYSTEM_TIME */
4759 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 4760 bnx2x_drv_pulse(bp);
a2fbb9ea 4761
f2e0899f 4762 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
4763 MCP_PULSE_SEQ_MASK);
4764 /* The delta between driver pulse and mcp response
4765 * should be 1 (before mcp response) or 0 (after mcp response)
4766 */
4767 if ((drv_pulse != mcp_pulse) &&
4768 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4769 /* someone lost a heartbeat... */
4770 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4771 drv_pulse, mcp_pulse);
4772 }
4773 }
4774
f34d28ea 4775 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 4776 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 4777
a2fbb9ea
ET
4778 mod_timer(&bp->timer, jiffies + bp->current_interval);
4779}
4780
4781/* end of Statistics */
4782
4783/* nic init */
4784
4785/*
4786 * nic init service functions
4787 */
4788
523224a3 4789static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 4790{
523224a3
DK
4791 u32 i;
4792 if (!(len%4) && !(addr%4))
4793 for (i = 0; i < len; i += 4)
4794 REG_WR(bp, addr + i, fill);
4795 else
4796 for (i = 0; i < len; i++)
4797 REG_WR8(bp, addr + i, fill);
34f80b04 4798
34f80b04
EG
4799}
4800
523224a3
DK
4801/* helper: writes FP SP data to FW - data_size in dwords */
4802static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4803 int fw_sb_id,
4804 u32 *sb_data_p,
4805 u32 data_size)
34f80b04 4806{
a2fbb9ea 4807 int index;
523224a3
DK
4808 for (index = 0; index < data_size; index++)
4809 REG_WR(bp, BAR_CSTRORM_INTMEM +
4810 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4811 sizeof(u32)*index,
4812 *(sb_data_p + index));
4813}
a2fbb9ea 4814
523224a3
DK
4815static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4816{
4817 u32 *sb_data_p;
4818 u32 data_size = 0;
f2e0899f 4819 struct hc_status_block_data_e2 sb_data_e2;
523224a3 4820 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 4821
523224a3 4822 /* disable the function first */
619c5cb6 4823 if (!CHIP_IS_E1x(bp)) {
f2e0899f 4824 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 4825 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
4826 sb_data_e2.common.p_func.vf_valid = false;
4827 sb_data_p = (u32 *)&sb_data_e2;
4828 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4829 } else {
4830 memset(&sb_data_e1x, 0,
4831 sizeof(struct hc_status_block_data_e1x));
619c5cb6 4832 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
4833 sb_data_e1x.common.p_func.vf_valid = false;
4834 sb_data_p = (u32 *)&sb_data_e1x;
4835 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4836 }
523224a3 4837 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 4838
523224a3
DK
4839 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4840 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4841 CSTORM_STATUS_BLOCK_SIZE);
4842 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4843 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4844 CSTORM_SYNC_BLOCK_SIZE);
4845}
34f80b04 4846
523224a3
DK
4847/* helper: writes SP SB data to FW */
4848static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4849 struct hc_sp_status_block_data *sp_sb_data)
4850{
4851 int func = BP_FUNC(bp);
4852 int i;
4853 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4854 REG_WR(bp, BAR_CSTRORM_INTMEM +
4855 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4856 i*sizeof(u32),
4857 *((u32 *)sp_sb_data + i));
34f80b04
EG
4858}
4859
523224a3 4860static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
4861{
4862 int func = BP_FUNC(bp);
523224a3
DK
4863 struct hc_sp_status_block_data sp_sb_data;
4864 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 4865
619c5cb6 4866 sp_sb_data.state = SB_DISABLED;
523224a3
DK
4867 sp_sb_data.p_func.vf_valid = false;
4868
4869 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4870
4871 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4872 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4873 CSTORM_SP_STATUS_BLOCK_SIZE);
4874 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4875 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4876 CSTORM_SP_SYNC_BLOCK_SIZE);
4877
4878}
4879
4880
4881static inline
4882void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4883 int igu_sb_id, int igu_seg_id)
4884{
4885 hc_sm->igu_sb_id = igu_sb_id;
4886 hc_sm->igu_seg_id = igu_seg_id;
4887 hc_sm->timer_value = 0xFF;
4888 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
4889}
4890
150966ad
AE
4891
4892/* allocates state machine ids. */
4893static inline
4894void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
4895{
4896 /* zero out state machine indices */
4897 /* rx indices */
4898 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4899
4900 /* tx indices */
4901 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4902 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
4903 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
4904 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
4905
4906 /* map indices */
4907 /* rx indices */
4908 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
4909 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4910
4911 /* tx indices */
4912 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
4913 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4914 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
4915 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4916 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
4917 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4918 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
4919 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4920}
4921
8d96286a 4922static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 4923 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 4924{
523224a3
DK
4925 int igu_seg_id;
4926
f2e0899f 4927 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
4928 struct hc_status_block_data_e1x sb_data_e1x;
4929 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
4930 int data_size;
4931 u32 *sb_data_p;
4932
f2e0899f
DK
4933 if (CHIP_INT_MODE_IS_BC(bp))
4934 igu_seg_id = HC_SEG_ACCESS_NORM;
4935 else
4936 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
4937
4938 bnx2x_zero_fp_sb(bp, fw_sb_id);
4939
619c5cb6 4940 if (!CHIP_IS_E1x(bp)) {
f2e0899f 4941 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 4942 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
4943 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4944 sb_data_e2.common.p_func.vf_id = vfid;
4945 sb_data_e2.common.p_func.vf_valid = vf_valid;
4946 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4947 sb_data_e2.common.same_igu_sb_1b = true;
4948 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4949 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4950 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
4951 sb_data_p = (u32 *)&sb_data_e2;
4952 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 4953 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
4954 } else {
4955 memset(&sb_data_e1x, 0,
4956 sizeof(struct hc_status_block_data_e1x));
619c5cb6 4957 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
4958 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4959 sb_data_e1x.common.p_func.vf_id = 0xff;
4960 sb_data_e1x.common.p_func.vf_valid = false;
4961 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4962 sb_data_e1x.common.same_igu_sb_1b = true;
4963 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4964 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4965 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
4966 sb_data_p = (u32 *)&sb_data_e1x;
4967 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 4968 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 4969 }
523224a3
DK
4970
4971 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4972 igu_sb_id, igu_seg_id);
4973 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4974 igu_sb_id, igu_seg_id);
4975
51c1a580 4976 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3
DK
4977
4978 /* write indecies to HW */
4979 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4980}
4981
619c5cb6 4982static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
4983 u16 tx_usec, u16 rx_usec)
4984{
6383c0b3 4985 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 4986 false, rx_usec);
6383c0b3
AE
4987 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4988 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
4989 tx_usec);
4990 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4991 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
4992 tx_usec);
4993 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4994 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
4995 tx_usec);
523224a3 4996}
f2e0899f 4997
523224a3
DK
4998static void bnx2x_init_def_sb(struct bnx2x *bp)
4999{
5000 struct host_sp_status_block *def_sb = bp->def_status_blk;
5001 dma_addr_t mapping = bp->def_status_blk_mapping;
5002 int igu_sp_sb_index;
5003 int igu_seg_id;
34f80b04
EG
5004 int port = BP_PORT(bp);
5005 int func = BP_FUNC(bp);
f2eaeb58 5006 int reg_offset, reg_offset_en5;
a2fbb9ea 5007 u64 section;
523224a3
DK
5008 int index;
5009 struct hc_sp_status_block_data sp_sb_data;
5010 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5011
f2e0899f
DK
5012 if (CHIP_INT_MODE_IS_BC(bp)) {
5013 igu_sp_sb_index = DEF_SB_IGU_ID;
5014 igu_seg_id = HC_SEG_ACCESS_DEF;
5015 } else {
5016 igu_sp_sb_index = bp->igu_dsb_id;
5017 igu_seg_id = IGU_SEG_ACCESS_DEF;
5018 }
a2fbb9ea
ET
5019
5020 /* ATTN */
523224a3 5021 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5022 atten_status_block);
523224a3 5023 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5024
49d66772
ET
5025 bp->attn_state = 0;
5026
a2fbb9ea
ET
5027 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5028 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5029 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5030 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5031 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5032 int sindex;
5033 /* take care of sig[0]..sig[4] */
5034 for (sindex = 0; sindex < 4; sindex++)
5035 bp->attn_group[index].sig[sindex] =
5036 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5037
619c5cb6 5038 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5039 /*
5040 * enable5 is separate from the rest of the registers,
5041 * and therefore the address skip is 4
5042 * and not 16 between the different groups
5043 */
5044 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5045 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5046 else
5047 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5048 }
5049
f2e0899f
DK
5050 if (bp->common.int_block == INT_BLOCK_HC) {
5051 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5052 HC_REG_ATTN_MSG0_ADDR_L);
5053
5054 REG_WR(bp, reg_offset, U64_LO(section));
5055 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5056 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5057 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5058 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5059 }
a2fbb9ea 5060
523224a3
DK
5061 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5062 sp_sb);
a2fbb9ea 5063
523224a3 5064 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5065
619c5cb6 5066 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5067 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5068 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5069 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5070 sp_sb_data.igu_seg_id = igu_seg_id;
5071 sp_sb_data.p_func.pf_id = func;
f2e0899f 5072 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5073 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5074
523224a3 5075 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5076
523224a3 5077 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5078}
5079
9f6c9258 5080void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5081{
a2fbb9ea
ET
5082 int i;
5083
ec6ba945 5084 for_each_eth_queue(bp, i)
523224a3 5085 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5086 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5087}
5088
a2fbb9ea
ET
5089static void bnx2x_init_sp_ring(struct bnx2x *bp)
5090{
a2fbb9ea 5091 spin_lock_init(&bp->spq_lock);
6e30dd4e 5092 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5093
a2fbb9ea 5094 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5095 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5096 bp->spq_prod_bd = bp->spq;
5097 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5098}
5099
523224a3 5100static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5101{
5102 int i;
523224a3
DK
5103 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5104 union event_ring_elem *elem =
5105 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5106
523224a3
DK
5107 elem->next_page.addr.hi =
5108 cpu_to_le32(U64_HI(bp->eq_mapping +
5109 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5110 elem->next_page.addr.lo =
5111 cpu_to_le32(U64_LO(bp->eq_mapping +
5112 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5113 }
523224a3
DK
5114 bp->eq_cons = 0;
5115 bp->eq_prod = NUM_EQ_DESC;
5116 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6e30dd4e
VZ
5117 /* we want a warning message before it gets rought... */
5118 atomic_set(&bp->eq_spq_left,
5119 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5120}
5121
619c5cb6
VZ
5122
5123/* called with netif_addr_lock_bh() */
5124void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5125 unsigned long rx_mode_flags,
5126 unsigned long rx_accept_flags,
5127 unsigned long tx_accept_flags,
5128 unsigned long ramrod_flags)
ab532cf3 5129{
619c5cb6
VZ
5130 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5131 int rc;
5132
5133 memset(&ramrod_param, 0, sizeof(ramrod_param));
5134
5135 /* Prepare ramrod parameters */
5136 ramrod_param.cid = 0;
5137 ramrod_param.cl_id = cl_id;
5138 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5139 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5140
619c5cb6
VZ
5141 ramrod_param.pstate = &bp->sp_state;
5142 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5143
619c5cb6
VZ
5144 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5145 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5146
5147 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5148
5149 ramrod_param.ramrod_flags = ramrod_flags;
5150 ramrod_param.rx_mode_flags = rx_mode_flags;
5151
5152 ramrod_param.rx_accept_flags = rx_accept_flags;
5153 ramrod_param.tx_accept_flags = tx_accept_flags;
5154
5155 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5156 if (rc < 0) {
5157 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5158 return;
5159 }
a2fbb9ea
ET
5160}
5161
619c5cb6
VZ
5162/* called with netif_addr_lock_bh() */
5163void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
471de716 5164{
619c5cb6
VZ
5165 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5166 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
471de716 5167
619c5cb6
VZ
5168#ifdef BCM_CNIC
5169 if (!NO_FCOE(bp))
5170
5171 /* Configure rx_mode of FCoE Queue */
5172 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5173#endif
5174
5175 switch (bp->rx_mode) {
5176 case BNX2X_RX_MODE_NONE:
5177 /*
5178 * 'drop all' supersedes any accept flags that may have been
5179 * passed to the function.
5180 */
5181 break;
5182 case BNX2X_RX_MODE_NORMAL:
5183 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5184 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5185 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5186
5187 /* internal switching mode */
5188 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5189 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5190 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5191
5192 break;
5193 case BNX2X_RX_MODE_ALLMULTI:
5194 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5195 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5196 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5197
5198 /* internal switching mode */
5199 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5200 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5201 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5202
5203 break;
5204 case BNX2X_RX_MODE_PROMISC:
5205 /* According to deffinition of SI mode, iface in promisc mode
5206 * should receive matched and unmatched (in resolution of port)
5207 * unicast packets.
5208 */
5209 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5210 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5211 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5212 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5213
5214 /* internal switching mode */
5215 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5216 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5217
5218 if (IS_MF_SI(bp))
5219 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5220 else
5221 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5222
5223 break;
5224 default:
5225 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5226 return;
5227 }
de832a55 5228
619c5cb6
VZ
5229 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5230 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5231 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
34f80b04
EG
5232 }
5233
619c5cb6
VZ
5234 __set_bit(RAMROD_RX, &ramrod_flags);
5235 __set_bit(RAMROD_TX, &ramrod_flags);
5236
5237 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5238 tx_accept_flags, ramrod_flags);
5239}
5240
5241static void bnx2x_init_internal_common(struct bnx2x *bp)
5242{
5243 int i;
5244
0793f83f
DK
5245 if (IS_MF_SI(bp))
5246 /*
5247 * In switch independent mode, the TSTORM needs to accept
5248 * packets that failed classification, since approximate match
5249 * mac addresses aren't written to NIG LLH
5250 */
5251 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5252 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5253 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5254 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5255 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5256
523224a3
DK
5257 /* Zero this manually as its initialization is
5258 currently missing in the initTool */
5259 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5260 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5261 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5262 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5263 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5264 CHIP_INT_MODE_IS_BC(bp) ?
5265 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5266 }
523224a3 5267}
8a1c38d1 5268
471de716
EG
5269static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5270{
5271 switch (load_code) {
5272 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5273 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5274 bnx2x_init_internal_common(bp);
5275 /* no break */
5276
5277 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5278 /* nothing to do */
471de716
EG
5279 /* no break */
5280
5281 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5282 /* internal memory per function is
5283 initialized inside bnx2x_pf_init */
471de716
EG
5284 break;
5285
5286 default:
5287 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5288 break;
5289 }
5290}
5291
619c5cb6 5292static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5293{
6383c0b3 5294 return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
619c5cb6 5295}
523224a3 5296
619c5cb6
VZ
5297static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5298{
6383c0b3 5299 return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
619c5cb6
VZ
5300}
5301
5302static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5303{
5304 if (CHIP_IS_E1x(fp->bp))
5305 return BP_L_ID(fp->bp) + fp->index;
5306 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5307 return bnx2x_fp_igu_sb_id(fp);
5308}
5309
6383c0b3 5310static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5311{
5312 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5313 u8 cos;
619c5cb6 5314 unsigned long q_type = 0;
6383c0b3 5315 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5316 fp->rx_queue = fp_idx;
b3b83c3f 5317 fp->cid = fp_idx;
619c5cb6
VZ
5318 fp->cl_id = bnx2x_fp_cl_id(fp);
5319 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5320 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5321 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5322 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5323
523224a3 5324 /* init shortcut */
619c5cb6 5325 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5326
523224a3
DK
5327 /* Setup SB indicies */
5328 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5329
619c5cb6
VZ
5330 /* Configure Queue State object */
5331 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5332 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5333
5334 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5335
5336 /* init tx data */
5337 for_each_cos_in_tx_queue(fp, cos) {
5338 bnx2x_init_txdata(bp, &fp->txdata[cos],
5339 CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
5340 FP_COS_TO_TXQ(fp, cos),
5341 BNX2X_TX_SB_INDEX_BASE + cos);
5342 cids[cos] = fp->txdata[cos].cid;
5343 }
5344
5345 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
5346 BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
5347 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5348
5349 /**
5350 * Configure classification DBs: Always enable Tx switching
5351 */
5352 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5353
51c1a580 5354 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
619c5cb6 5355 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
523224a3
DK
5356 fp->igu_sb_id);
5357 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5358 fp->fw_sb_id, fp->igu_sb_id);
5359
5360 bnx2x_update_fpsb_idx(fp);
5361}
5362
9f6c9258 5363void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
a2fbb9ea
ET
5364{
5365 int i;
5366
ec6ba945 5367 for_each_eth_queue(bp, i)
6383c0b3 5368 bnx2x_init_eth_fp(bp, i);
37b091ba 5369#ifdef BCM_CNIC
ec6ba945
VZ
5370 if (!NO_FCOE(bp))
5371 bnx2x_init_fcoe_fp(bp);
523224a3
DK
5372
5373 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5374 BNX2X_VF_ID_INVALID, false,
619c5cb6 5375 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 5376
37b091ba 5377#endif
a2fbb9ea 5378
020c7e3f
YR
5379 /* Initialize MOD_ABS interrupts */
5380 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5381 bp->common.shmem_base, bp->common.shmem2_base,
5382 BP_PORT(bp));
16119785
EG
5383 /* ensure status block indices were read */
5384 rmb();
5385
523224a3 5386 bnx2x_init_def_sb(bp);
5c862848 5387 bnx2x_update_dsb_idx(bp);
a2fbb9ea 5388 bnx2x_init_rx_rings(bp);
523224a3 5389 bnx2x_init_tx_rings(bp);
a2fbb9ea 5390 bnx2x_init_sp_ring(bp);
523224a3 5391 bnx2x_init_eq_ring(bp);
471de716 5392 bnx2x_init_internal(bp, load_code);
523224a3 5393 bnx2x_pf_init(bp);
0ef00459
EG
5394 bnx2x_stats_init(bp);
5395
0ef00459
EG
5396 /* flush all before enabling interrupts */
5397 mb();
5398 mmiowb();
5399
615f8fd9 5400 bnx2x_int_enable(bp);
eb8da205
EG
5401
5402 /* Check for SPIO5 */
5403 bnx2x_attn_int_deasserted0(bp,
5404 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5405 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
5406}
5407
5408/* end of nic init */
5409
5410/*
5411 * gzip service functions
5412 */
5413
5414static int bnx2x_gunzip_init(struct bnx2x *bp)
5415{
1a983142
FT
5416 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5417 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
5418 if (bp->gunzip_buf == NULL)
5419 goto gunzip_nomem1;
5420
5421 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5422 if (bp->strm == NULL)
5423 goto gunzip_nomem2;
5424
7ab24bfd 5425 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
5426 if (bp->strm->workspace == NULL)
5427 goto gunzip_nomem3;
5428
5429 return 0;
5430
5431gunzip_nomem3:
5432 kfree(bp->strm);
5433 bp->strm = NULL;
5434
5435gunzip_nomem2:
1a983142
FT
5436 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5437 bp->gunzip_mapping);
a2fbb9ea
ET
5438 bp->gunzip_buf = NULL;
5439
5440gunzip_nomem1:
51c1a580 5441 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
5442 return -ENOMEM;
5443}
5444
5445static void bnx2x_gunzip_end(struct bnx2x *bp)
5446{
b3b83c3f 5447 if (bp->strm) {
7ab24bfd 5448 vfree(bp->strm->workspace);
b3b83c3f
DK
5449 kfree(bp->strm);
5450 bp->strm = NULL;
5451 }
a2fbb9ea
ET
5452
5453 if (bp->gunzip_buf) {
1a983142
FT
5454 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5455 bp->gunzip_mapping);
a2fbb9ea
ET
5456 bp->gunzip_buf = NULL;
5457 }
5458}
5459
94a78b79 5460static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
5461{
5462 int n, rc;
5463
5464 /* check gzip header */
94a78b79
VZ
5465 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5466 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 5467 return -EINVAL;
94a78b79 5468 }
a2fbb9ea
ET
5469
5470 n = 10;
5471
34f80b04 5472#define FNAME 0x8
a2fbb9ea
ET
5473
5474 if (zbuf[3] & FNAME)
5475 while ((zbuf[n++] != 0) && (n < len));
5476
94a78b79 5477 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
5478 bp->strm->avail_in = len - n;
5479 bp->strm->next_out = bp->gunzip_buf;
5480 bp->strm->avail_out = FW_BUF_SIZE;
5481
5482 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5483 if (rc != Z_OK)
5484 return rc;
5485
5486 rc = zlib_inflate(bp->strm, Z_FINISH);
5487 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
5488 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5489 bp->strm->msg);
a2fbb9ea
ET
5490
5491 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5492 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
5493 netdev_err(bp->dev,
5494 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 5495 bp->gunzip_outlen);
a2fbb9ea
ET
5496 bp->gunzip_outlen >>= 2;
5497
5498 zlib_inflateEnd(bp->strm);
5499
5500 if (rc == Z_STREAM_END)
5501 return 0;
5502
5503 return rc;
5504}
5505
5506/* nic load/unload */
5507
5508/*
34f80b04 5509 * General service functions
a2fbb9ea
ET
5510 */
5511
5512/* send a NIG loopback debug packet */
5513static void bnx2x_lb_pckt(struct bnx2x *bp)
5514{
a2fbb9ea 5515 u32 wb_write[3];
a2fbb9ea
ET
5516
5517 /* Ethernet source and destination addresses */
a2fbb9ea
ET
5518 wb_write[0] = 0x55555555;
5519 wb_write[1] = 0x55555555;
34f80b04 5520 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 5521 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5522
5523 /* NON-IP protocol */
a2fbb9ea
ET
5524 wb_write[0] = 0x09000000;
5525 wb_write[1] = 0x55555555;
34f80b04 5526 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 5527 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5528}
5529
5530/* some of the internal memories
5531 * are not directly readable from the driver
5532 * to test them we send debug packets
5533 */
5534static int bnx2x_int_mem_test(struct bnx2x *bp)
5535{
5536 int factor;
5537 int count, i;
5538 u32 val = 0;
5539
ad8d3948 5540 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 5541 factor = 120;
ad8d3948
EG
5542 else if (CHIP_REV_IS_EMUL(bp))
5543 factor = 200;
5544 else
a2fbb9ea 5545 factor = 1;
a2fbb9ea 5546
a2fbb9ea
ET
5547 /* Disable inputs of parser neighbor blocks */
5548 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5549 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5550 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5551 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5552
5553 /* Write 0 to parser credits for CFC search request */
5554 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5555
5556 /* send Ethernet packet */
5557 bnx2x_lb_pckt(bp);
5558
5559 /* TODO do i reset NIG statistic? */
5560 /* Wait until NIG register shows 1 packet of size 0x10 */
5561 count = 1000 * factor;
5562 while (count) {
34f80b04 5563
a2fbb9ea
ET
5564 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5565 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
5566 if (val == 0x10)
5567 break;
5568
5569 msleep(10);
5570 count--;
5571 }
5572 if (val != 0x10) {
5573 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5574 return -1;
5575 }
5576
5577 /* Wait until PRS register shows 1 packet */
5578 count = 1000 * factor;
5579 while (count) {
5580 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
5581 if (val == 1)
5582 break;
5583
5584 msleep(10);
5585 count--;
5586 }
5587 if (val != 0x1) {
5588 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5589 return -2;
5590 }
5591
5592 /* Reset and init BRB, PRS */
34f80b04 5593 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 5594 msleep(50);
34f80b04 5595 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 5596 msleep(50);
619c5cb6
VZ
5597 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5598 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
5599
5600 DP(NETIF_MSG_HW, "part2\n");
5601
5602 /* Disable inputs of parser neighbor blocks */
5603 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5604 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5605 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5606 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5607
5608 /* Write 0 to parser credits for CFC search request */
5609 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5610
5611 /* send 10 Ethernet packets */
5612 for (i = 0; i < 10; i++)
5613 bnx2x_lb_pckt(bp);
5614
5615 /* Wait until NIG register shows 10 + 1
5616 packets of size 11*0x10 = 0xb0 */
5617 count = 1000 * factor;
5618 while (count) {
34f80b04 5619
a2fbb9ea
ET
5620 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5621 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
5622 if (val == 0xb0)
5623 break;
5624
5625 msleep(10);
5626 count--;
5627 }
5628 if (val != 0xb0) {
5629 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5630 return -3;
5631 }
5632
5633 /* Wait until PRS register shows 2 packets */
5634 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5635 if (val != 2)
5636 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5637
5638 /* Write 1 to parser credits for CFC search request */
5639 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5640
5641 /* Wait until PRS register shows 3 packets */
5642 msleep(10 * factor);
5643 /* Wait until NIG register shows 1 packet of size 0x10 */
5644 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5645 if (val != 3)
5646 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5647
5648 /* clear NIG EOP FIFO */
5649 for (i = 0; i < 11; i++)
5650 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5651 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5652 if (val != 1) {
5653 BNX2X_ERR("clear of NIG failed\n");
5654 return -4;
5655 }
5656
5657 /* Reset and init BRB, PRS, NIG */
5658 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5659 msleep(50);
5660 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5661 msleep(50);
619c5cb6
VZ
5662 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5663 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
37b091ba 5664#ifndef BCM_CNIC
a2fbb9ea
ET
5665 /* set NIC mode */
5666 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5667#endif
5668
5669 /* Enable inputs of parser neighbor blocks */
5670 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5671 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5672 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 5673 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
5674
5675 DP(NETIF_MSG_HW, "done\n");
5676
5677 return 0; /* OK */
5678}
5679
4a33bc03 5680static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea
ET
5681{
5682 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 5683 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5684 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5685 else
5686 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
5687 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5688 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
5689 /*
5690 * mask read length error interrupts in brb for parser
5691 * (parsing unit and 'checksum and crc' unit)
5692 * these errors are legal (PU reads fixed length and CAC can cause
5693 * read length error on truncated packets)
5694 */
5695 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
5696 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5697 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5698 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5699 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5700 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
5701/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5702/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
5703 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5704 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5705 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
5706/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5707/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
5708 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5709 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5710 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5711 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
5712/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5713/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 5714
34f80b04
EG
5715 if (CHIP_REV_IS_FPGA(bp))
5716 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
619c5cb6 5717 else if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5718 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5719 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5720 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5721 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5722 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5723 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
34f80b04
EG
5724 else
5725 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
a2fbb9ea
ET
5726 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5727 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5728 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 5729/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
5730
5731 if (!CHIP_IS_E1x(bp))
5732 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5733 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5734
a2fbb9ea
ET
5735 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5736 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 5737/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 5738 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
5739}
5740
81f75bbf
EG
5741static void bnx2x_reset_common(struct bnx2x *bp)
5742{
619c5cb6
VZ
5743 u32 val = 0x1400;
5744
81f75bbf
EG
5745 /* reset_common */
5746 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5747 0xd3ffff7f);
619c5cb6
VZ
5748
5749 if (CHIP_IS_E3(bp)) {
5750 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5751 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5752 }
5753
5754 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5755}
5756
5757static void bnx2x_setup_dmae(struct bnx2x *bp)
5758{
5759 bp->dmae_ready = 0;
5760 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
5761}
5762
573f2035
EG
5763static void bnx2x_init_pxp(struct bnx2x *bp)
5764{
5765 u16 devctl;
5766 int r_order, w_order;
5767
5768 pci_read_config_word(bp->pdev,
b6c2f86e 5769 pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
573f2035
EG
5770 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5771 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5772 if (bp->mrrs == -1)
5773 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5774 else {
5775 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5776 r_order = bp->mrrs;
5777 }
5778
5779 bnx2x_init_pxp_arb(bp, r_order, w_order);
5780}
fd4ef40d
EG
5781
5782static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5783{
2145a920 5784 int is_required;
fd4ef40d 5785 u32 val;
2145a920 5786 int port;
fd4ef40d 5787
2145a920
VZ
5788 if (BP_NOMCP(bp))
5789 return;
5790
5791 is_required = 0;
fd4ef40d
EG
5792 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5793 SHARED_HW_CFG_FAN_FAILURE_MASK;
5794
5795 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5796 is_required = 1;
5797
5798 /*
5799 * The fan failure mechanism is usually related to the PHY type since
5800 * the power consumption of the board is affected by the PHY. Currently,
5801 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5802 */
5803 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5804 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 5805 is_required |=
d90d96ba
YR
5806 bnx2x_fan_failure_det_req(
5807 bp,
5808 bp->common.shmem_base,
a22f0788 5809 bp->common.shmem2_base,
d90d96ba 5810 port);
fd4ef40d
EG
5811 }
5812
5813 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5814
5815 if (is_required == 0)
5816 return;
5817
5818 /* Fan failure is indicated by SPIO 5 */
5819 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5820 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5821
5822 /* set to active low mode */
5823 val = REG_RD(bp, MISC_REG_SPIO_INT);
5824 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
cdaa7cb8 5825 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
5826 REG_WR(bp, MISC_REG_SPIO_INT, val);
5827
5828 /* enable interrupt to signal the IGU */
5829 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5830 val |= (1 << MISC_REGISTERS_SPIO_5);
5831 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5832}
5833
f2e0899f
DK
5834static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5835{
5836 u32 offset = 0;
5837
5838 if (CHIP_IS_E1(bp))
5839 return;
5840 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5841 return;
5842
5843 switch (BP_ABS_FUNC(bp)) {
5844 case 0:
5845 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5846 break;
5847 case 1:
5848 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5849 break;
5850 case 2:
5851 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5852 break;
5853 case 3:
5854 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5855 break;
5856 case 4:
5857 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5858 break;
5859 case 5:
5860 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5861 break;
5862 case 6:
5863 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5864 break;
5865 case 7:
5866 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5867 break;
5868 default:
5869 return;
5870 }
5871
5872 REG_WR(bp, offset, pretend_func_num);
5873 REG_RD(bp, offset);
5874 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5875}
5876
c9ee9206 5877void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
5878{
5879 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5880 val &= ~IGU_PF_CONF_FUNC_EN;
5881
5882 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5883 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5884 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5885}
5886
619c5cb6
VZ
5887static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5888{
5889 u32 shmem_base[2], shmem2_base[2];
5890 shmem_base[0] = bp->common.shmem_base;
5891 shmem2_base[0] = bp->common.shmem2_base;
5892 if (!CHIP_IS_E1x(bp)) {
5893 shmem_base[1] =
5894 SHMEM2_RD(bp, other_shmem_base_addr);
5895 shmem2_base[1] =
5896 SHMEM2_RD(bp, other_shmem2_base_addr);
5897 }
5898 bnx2x_acquire_phy_lock(bp);
5899 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5900 bp->common.chip_id);
5901 bnx2x_release_phy_lock(bp);
5902}
5903
5904/**
5905 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5906 *
5907 * @bp: driver handle
5908 */
5909static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 5910{
619c5cb6 5911 u32 val;
a2fbb9ea 5912
51c1a580 5913 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 5914
2031bd3a
DK
5915 /*
5916 * take the UNDI lock to protect undi_unload flow from accessing
5917 * registers while we're resetting the chip
5918 */
7a06a122 5919 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 5920
81f75bbf 5921 bnx2x_reset_common(bp);
34f80b04 5922 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 5923
619c5cb6
VZ
5924 val = 0xfffc;
5925 if (CHIP_IS_E3(bp)) {
5926 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5927 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5928 }
5929 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
5930
7a06a122 5931 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 5932
619c5cb6 5933 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 5934
619c5cb6
VZ
5935 if (!CHIP_IS_E1x(bp)) {
5936 u8 abs_func_id;
f2e0899f
DK
5937
5938 /**
5939 * 4-port mode or 2-port mode we need to turn of master-enable
5940 * for everyone, after that, turn it back on for self.
5941 * so, we disregard multi-function or not, and always disable
5942 * for all functions on the given path, this means 0,2,4,6 for
5943 * path 0 and 1,3,5,7 for path 1
5944 */
619c5cb6
VZ
5945 for (abs_func_id = BP_PATH(bp);
5946 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5947 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
5948 REG_WR(bp,
5949 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5950 1);
5951 continue;
5952 }
5953
619c5cb6 5954 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
5955 /* clear pf enable */
5956 bnx2x_pf_disable(bp);
5957 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5958 }
5959 }
a2fbb9ea 5960
619c5cb6 5961 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
5962 if (CHIP_IS_E1(bp)) {
5963 /* enable HW interrupt from PXP on USDM overflow
5964 bit 16 on INT_MASK_0 */
5965 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5966 }
a2fbb9ea 5967
619c5cb6 5968 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 5969 bnx2x_init_pxp(bp);
a2fbb9ea
ET
5970
5971#ifdef __BIG_ENDIAN
34f80b04
EG
5972 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5973 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5974 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5975 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5976 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
5977 /* make sure this value is 0 */
5978 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
5979
5980/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5981 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5982 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5983 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5984 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
5985#endif
5986
523224a3
DK
5987 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5988
34f80b04
EG
5989 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5990 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 5991
34f80b04
EG
5992 /* let the HW do it's magic ... */
5993 msleep(100);
5994 /* finish PXP init */
5995 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5996 if (val != 1) {
5997 BNX2X_ERR("PXP2 CFG failed\n");
5998 return -EBUSY;
5999 }
6000 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6001 if (val != 1) {
6002 BNX2X_ERR("PXP2 RD_INIT failed\n");
6003 return -EBUSY;
6004 }
a2fbb9ea 6005
f2e0899f
DK
6006 /* Timers bug workaround E2 only. We need to set the entire ILT to
6007 * have entries with value "0" and valid bit on.
6008 * This needs to be done by the first PF that is loaded in a path
6009 * (i.e. common phase)
6010 */
619c5cb6
VZ
6011 if (!CHIP_IS_E1x(bp)) {
6012/* In E2 there is a bug in the timers block that can cause function 6 / 7
6013 * (i.e. vnic3) to start even if it is marked as "scan-off".
6014 * This occurs when a different function (func2,3) is being marked
6015 * as "scan-off". Real-life scenario for example: if a driver is being
6016 * load-unloaded while func6,7 are down. This will cause the timer to access
6017 * the ilt, translate to a logical address and send a request to read/write.
6018 * Since the ilt for the function that is down is not valid, this will cause
6019 * a translation error which is unrecoverable.
6020 * The Workaround is intended to make sure that when this happens nothing fatal
6021 * will occur. The workaround:
6022 * 1. First PF driver which loads on a path will:
6023 * a. After taking the chip out of reset, by using pretend,
6024 * it will write "0" to the following registers of
6025 * the other vnics.
6026 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6027 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6028 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6029 * And for itself it will write '1' to
6030 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6031 * dmae-operations (writing to pram for example.)
6032 * note: can be done for only function 6,7 but cleaner this
6033 * way.
6034 * b. Write zero+valid to the entire ILT.
6035 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6036 * VNIC3 (of that port). The range allocated will be the
6037 * entire ILT. This is needed to prevent ILT range error.
6038 * 2. Any PF driver load flow:
6039 * a. ILT update with the physical addresses of the allocated
6040 * logical pages.
6041 * b. Wait 20msec. - note that this timeout is needed to make
6042 * sure there are no requests in one of the PXP internal
6043 * queues with "old" ILT addresses.
6044 * c. PF enable in the PGLC.
6045 * d. Clear the was_error of the PF in the PGLC. (could have
6046 * occured while driver was down)
6047 * e. PF enable in the CFC (WEAK + STRONG)
6048 * f. Timers scan enable
6049 * 3. PF driver unload flow:
6050 * a. Clear the Timers scan_en.
6051 * b. Polling for scan_on=0 for that PF.
6052 * c. Clear the PF enable bit in the PXP.
6053 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6054 * e. Write zero+valid to all ILT entries (The valid bit must
6055 * stay set)
6056 * f. If this is VNIC 3 of a port then also init
6057 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6058 * to the last enrty in the ILT.
6059 *
6060 * Notes:
6061 * Currently the PF error in the PGLC is non recoverable.
6062 * In the future the there will be a recovery routine for this error.
6063 * Currently attention is masked.
6064 * Having an MCP lock on the load/unload process does not guarantee that
6065 * there is no Timer disable during Func6/7 enable. This is because the
6066 * Timers scan is currently being cleared by the MCP on FLR.
6067 * Step 2.d can be done only for PF6/7 and the driver can also check if
6068 * there is error before clearing it. But the flow above is simpler and
6069 * more general.
6070 * All ILT entries are written by zero+valid and not just PF6/7
6071 * ILT entries since in the future the ILT entries allocation for
6072 * PF-s might be dynamic.
6073 */
f2e0899f
DK
6074 struct ilt_client_info ilt_cli;
6075 struct bnx2x_ilt ilt;
6076 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6077 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6078
b595076a 6079 /* initialize dummy TM client */
f2e0899f
DK
6080 ilt_cli.start = 0;
6081 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6082 ilt_cli.client_num = ILT_CLIENT_TM;
6083
6084 /* Step 1: set zeroes to all ilt page entries with valid bit on
6085 * Step 2: set the timers first/last ilt entry to point
6086 * to the entire range to prevent ILT range error for 3rd/4th
619c5cb6 6087 * vnic (this code assumes existance of the vnic)
f2e0899f
DK
6088 *
6089 * both steps performed by call to bnx2x_ilt_client_init_op()
6090 * with dummy TM client
6091 *
6092 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6093 * and his brother are split registers
6094 */
6095 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6096 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6097 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6098
6099 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6100 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6101 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6102 }
6103
6104
34f80b04
EG
6105 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6106 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6107
619c5cb6 6108 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6109 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6110 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6111 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6112
619c5cb6 6113 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6114
6115 /* let the HW do it's magic ... */
6116 do {
6117 msleep(200);
6118 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6119 } while (factor-- && (val != 1));
6120
6121 if (val != 1) {
6122 BNX2X_ERR("ATC_INIT failed\n");
6123 return -EBUSY;
6124 }
6125 }
6126
619c5cb6 6127 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6128
34f80b04
EG
6129 /* clean the DMAE memory */
6130 bp->dmae_ready = 1;
619c5cb6
VZ
6131 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6132
6133 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6134
6135 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6136
6137 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6138
619c5cb6 6139 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6140
34f80b04
EG
6141 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6142 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6143 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6144 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6145
619c5cb6 6146 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6147
f85582f8 6148
523224a3
DK
6149 /* QM queues pointers table */
6150 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6151
34f80b04
EG
6152 /* soft reset pulse */
6153 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6154 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6155
37b091ba 6156#ifdef BCM_CNIC
619c5cb6 6157 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6158#endif
a2fbb9ea 6159
619c5cb6 6160 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6161 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6162 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6163 /* enable hw interrupt from doorbell Q */
6164 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6165
619c5cb6 6166 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6167
619c5cb6 6168 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6169 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6170
f2e0899f 6171 if (!CHIP_IS_E1(bp))
619c5cb6 6172 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6173
619c5cb6
VZ
6174 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
6175 /* Bit-map indicating which L2 hdrs may appear
6176 * after the basic Ethernet header
6177 */
6178 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6179 bp->path_has_ovlan ? 7 : 6);
a2fbb9ea 6180
619c5cb6
VZ
6181 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6182 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6183 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6184 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6185
619c5cb6
VZ
6186 if (!CHIP_IS_E1x(bp)) {
6187 /* reset VFC memories */
6188 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6189 VFC_MEMORIES_RST_REG_CAM_RST |
6190 VFC_MEMORIES_RST_REG_RAM_RST);
6191 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6192 VFC_MEMORIES_RST_REG_CAM_RST |
6193 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6194
619c5cb6
VZ
6195 msleep(20);
6196 }
a2fbb9ea 6197
619c5cb6
VZ
6198 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6199 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6200 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6201 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6202
34f80b04
EG
6203 /* sync semi rtc */
6204 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6205 0x80000000);
6206 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6207 0x80000000);
a2fbb9ea 6208
619c5cb6
VZ
6209 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6210 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6211 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6212
619c5cb6
VZ
6213 if (!CHIP_IS_E1x(bp))
6214 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6215 bp->path_has_ovlan ? 7 : 6);
f2e0899f 6216
34f80b04 6217 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6218
619c5cb6
VZ
6219 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6220
37b091ba
MC
6221#ifdef BCM_CNIC
6222 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6223 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6224 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6225 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6226 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6227 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6228 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6229 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6230 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6231 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6232#endif
34f80b04 6233 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6234
34f80b04
EG
6235 if (sizeof(union cdu_context) != 1024)
6236 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6237 dev_alert(&bp->pdev->dev,
6238 "please adjust the size of cdu_context(%ld)\n",
6239 (long)sizeof(union cdu_context));
a2fbb9ea 6240
619c5cb6 6241 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6242 val = (4 << 24) + (0 << 12) + 1024;
6243 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6244
619c5cb6 6245 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6246 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6247 /* enable context validation interrupt from CFC */
6248 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6249
6250 /* set the thresholds to prevent CFC/CDU race */
6251 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6252
619c5cb6 6253 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6254
619c5cb6 6255 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6256 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6257
619c5cb6
VZ
6258 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6259 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6260
34f80b04
EG
6261 /* Reset PCIE errors for debug */
6262 REG_WR(bp, 0x2814, 0xffffffff);
6263 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6264
619c5cb6 6265 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6266 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6267 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6268 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6269 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6270 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6271 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6272 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6273 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6274 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6275 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6276 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6277 }
6278
619c5cb6 6279 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6280 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6281 /* in E3 this done in per-port section */
6282 if (!CHIP_IS_E3(bp))
6283 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6284 }
619c5cb6
VZ
6285 if (CHIP_IS_E1H(bp))
6286 /* not applicable for E2 (and above ...) */
6287 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6288
6289 if (CHIP_REV_IS_SLOW(bp))
6290 msleep(200);
6291
6292 /* finish CFC init */
6293 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6294 if (val != 1) {
6295 BNX2X_ERR("CFC LL_INIT failed\n");
6296 return -EBUSY;
6297 }
6298 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6299 if (val != 1) {
6300 BNX2X_ERR("CFC AC_INIT failed\n");
6301 return -EBUSY;
6302 }
6303 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6304 if (val != 1) {
6305 BNX2X_ERR("CFC CAM_INIT failed\n");
6306 return -EBUSY;
6307 }
6308 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6309
f2e0899f
DK
6310 if (CHIP_IS_E1(bp)) {
6311 /* read NIG statistic
6312 to see if this is our first up since powerup */
6313 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6314 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6315
f2e0899f
DK
6316 /* do internal memory self test */
6317 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6318 BNX2X_ERR("internal mem self test failed\n");
6319 return -EBUSY;
6320 }
34f80b04
EG
6321 }
6322
fd4ef40d
EG
6323 bnx2x_setup_fan_failure_detection(bp);
6324
34f80b04
EG
6325 /* clear PXP2 attentions */
6326 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6327
4a33bc03 6328 bnx2x_enable_blocks_attention(bp);
c9ee9206 6329 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6330
6bbca910 6331 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6332 if (CHIP_IS_E1x(bp))
6333 bnx2x__common_init_phy(bp);
6bbca910
YR
6334 } else
6335 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6336
34f80b04
EG
6337 return 0;
6338}
a2fbb9ea 6339
619c5cb6
VZ
6340/**
6341 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6342 *
6343 * @bp: driver handle
6344 */
6345static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6346{
6347 int rc = bnx2x_init_hw_common(bp);
6348
6349 if (rc)
6350 return rc;
6351
6352 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6353 if (!BP_NOMCP(bp))
6354 bnx2x__common_init_phy(bp);
6355
6356 return 0;
6357}
6358
523224a3 6359static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6360{
6361 int port = BP_PORT(bp);
619c5cb6 6362 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6363 u32 low, high;
34f80b04 6364 u32 val;
a2fbb9ea 6365
619c5cb6
VZ
6366 bnx2x__link_reset(bp);
6367
51c1a580 6368 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
6369
6370 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 6371
619c5cb6
VZ
6372 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6373 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6374 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 6375
f2e0899f
DK
6376 /* Timers bug workaround: disables the pf_master bit in pglue at
6377 * common phase, we need to enable it here before any dmae access are
6378 * attempted. Therefore we manually added the enable-master to the
6379 * port phase (it also happens in the function phase)
6380 */
619c5cb6 6381 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6382 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6383
619c5cb6
VZ
6384 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6385 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6386 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6387 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6388
6389 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6390 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6391 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6392 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 6393
523224a3
DK
6394 /* QM cid (connection) count */
6395 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 6396
523224a3 6397#ifdef BCM_CNIC
619c5cb6 6398 bnx2x_init_block(bp, BLOCK_TM, init_phase);
37b091ba
MC
6399 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6400 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
a2fbb9ea 6401#endif
cdaa7cb8 6402
619c5cb6 6403 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f
DK
6404
6405 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
6406 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6407
6408 if (IS_MF(bp))
6409 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6410 else if (bp->dev->mtu > 4096) {
6411 if (bp->flags & ONE_PORT_FLAG)
6412 low = 160;
6413 else {
6414 val = bp->dev->mtu;
6415 /* (24*1024 + val*4)/256 */
6416 low = 96 + (val/64) +
6417 ((val % 64) ? 1 : 0);
6418 }
6419 } else
6420 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6421 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
6422 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6423 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 6424 }
1c06328c 6425
619c5cb6
VZ
6426 if (CHIP_MODE_IS_4_PORT(bp))
6427 REG_WR(bp, (BP_PORT(bp) ?
6428 BRB1_REG_MAC_GUARANTIED_1 :
6429 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 6430
ca00392c 6431
619c5cb6
VZ
6432 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6433 if (CHIP_IS_E3B0(bp))
6434 /* Ovlan exists only if we are in multi-function +
6435 * switch-dependent mode, in switch-independent there
6436 * is no ovlan headers
6437 */
6438 REG_WR(bp, BP_PORT(bp) ?
6439 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6440 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6441 (bp->path_has_ovlan ? 7 : 6));
356e2385 6442
619c5cb6
VZ
6443 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6444 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6445 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6446 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 6447
619c5cb6
VZ
6448 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6449 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6450 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6451 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 6452
619c5cb6
VZ
6453 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6454 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 6455
619c5cb6
VZ
6456 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6457
6458 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
6459 /* configure PBF to work without PAUSE mtu 9000 */
6460 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 6461
f2e0899f
DK
6462 /* update threshold */
6463 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6464 /* update init credit */
6465 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 6466
f2e0899f
DK
6467 /* probe changes */
6468 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6469 udelay(50);
6470 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6471 }
a2fbb9ea 6472
37b091ba 6473#ifdef BCM_CNIC
619c5cb6 6474 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
a2fbb9ea 6475#endif
619c5cb6
VZ
6476 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6477 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
6478
6479 if (CHIP_IS_E1(bp)) {
6480 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6481 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6482 }
619c5cb6 6483 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 6484
619c5cb6 6485 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 6486
619c5cb6 6487 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04
EG
6488 /* init aeu_mask_attn_func_0/1:
6489 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6490 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6491 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
6492 val = IS_MF(bp) ? 0xF7 : 0x7;
6493 /* Enable DCBX attention for all but E1 */
6494 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6495 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 6496
619c5cb6
VZ
6497 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6498
6499 if (!CHIP_IS_E1x(bp)) {
6500 /* Bit-map indicating which L2 hdrs may appear after the
6501 * basic Ethernet header
6502 */
6503 REG_WR(bp, BP_PORT(bp) ?
6504 NIG_REG_P1_HDRS_AFTER_BASIC :
6505 NIG_REG_P0_HDRS_AFTER_BASIC,
6506 IS_MF_SD(bp) ? 7 : 6);
6507
6508 if (CHIP_IS_E3(bp))
6509 REG_WR(bp, BP_PORT(bp) ?
6510 NIG_REG_LLH1_MF_MODE :
6511 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6512 }
6513 if (!CHIP_IS_E3(bp))
6514 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 6515
f2e0899f 6516 if (!CHIP_IS_E1(bp)) {
fb3bff17 6517 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 6518 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 6519 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 6520
619c5cb6 6521 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6522 val = 0;
6523 switch (bp->mf_mode) {
6524 case MULTI_FUNCTION_SD:
6525 val = 1;
6526 break;
6527 case MULTI_FUNCTION_SI:
6528 val = 2;
6529 break;
6530 }
6531
6532 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6533 NIG_REG_LLH0_CLS_TYPE), val);
6534 }
1c06328c
EG
6535 {
6536 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6537 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6538 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6539 }
34f80b04
EG
6540 }
6541
619c5cb6
VZ
6542
6543 /* If SPIO5 is set to generate interrupts, enable it for this port */
6544 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6545 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
4d295db0
EG
6546 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6547 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6548 val = REG_RD(bp, reg_addr);
f1410647 6549 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 6550 REG_WR(bp, reg_addr, val);
f1410647 6551 }
a2fbb9ea 6552
34f80b04
EG
6553 return 0;
6554}
6555
34f80b04
EG
6556static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6557{
6558 int reg;
32d68de1 6559 u32 wb_write[2];
34f80b04 6560
f2e0899f 6561 if (CHIP_IS_E1(bp))
34f80b04 6562 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
6563 else
6564 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 6565
32d68de1
YM
6566 wb_write[0] = ONCHIP_ADDR1(addr);
6567 wb_write[1] = ONCHIP_ADDR2(addr);
6568 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
6569}
6570
f2e0899f
DK
6571static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6572{
619c5cb6 6573 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
6574}
6575
6576static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6577{
6578 u32 i, base = FUNC_ILT_BASE(func);
6579 for (i = base; i < base + ILT_PER_FUNC; i++)
6580 bnx2x_ilt_wr(bp, i, 0);
6581}
6582
523224a3 6583static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
6584{
6585 int port = BP_PORT(bp);
6586 int func = BP_FUNC(bp);
619c5cb6 6587 int init_phase = PHASE_PF0 + func;
523224a3
DK
6588 struct bnx2x_ilt *ilt = BP_ILT(bp);
6589 u16 cdu_ilt_start;
8badd27a 6590 u32 addr, val;
f4a66897 6591 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 6592 int i, main_mem_width, rc;
34f80b04 6593
51c1a580 6594 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 6595
619c5cb6 6596 /* FLR cleanup - hmmm */
89db4ad8
AE
6597 if (!CHIP_IS_E1x(bp)) {
6598 rc = bnx2x_pf_flr_clnup(bp);
6599 if (rc)
6600 return rc;
6601 }
619c5cb6 6602
8badd27a 6603 /* set MSI reconfigure capability */
f2e0899f
DK
6604 if (bp->common.int_block == INT_BLOCK_HC) {
6605 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6606 val = REG_RD(bp, addr);
6607 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6608 REG_WR(bp, addr, val);
6609 }
8badd27a 6610
619c5cb6
VZ
6611 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6612 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6613
523224a3
DK
6614 ilt = BP_ILT(bp);
6615 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 6616
523224a3
DK
6617 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6618 ilt->lines[cdu_ilt_start + i].page =
6619 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6620 ilt->lines[cdu_ilt_start + i].page_mapping =
6621 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6622 /* cdu ilt pages are allocated manually so there's no need to
6623 set the size */
37b091ba 6624 }
523224a3 6625 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 6626
523224a3
DK
6627#ifdef BCM_CNIC
6628 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
37b091ba 6629
523224a3
DK
6630 /* T1 hash bits value determines the T1 number of entries */
6631 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6632#endif
37b091ba 6633
523224a3
DK
6634#ifndef BCM_CNIC
6635 /* set NIC mode */
6636 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6637#endif /* BCM_CNIC */
37b091ba 6638
619c5cb6 6639 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6640 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6641
6642 /* Turn on a single ISR mode in IGU if driver is going to use
6643 * INT#x or MSI
6644 */
6645 if (!(bp->flags & USING_MSIX_FLAG))
6646 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6647 /*
6648 * Timers workaround bug: function init part.
6649 * Need to wait 20msec after initializing ILT,
6650 * needed to make sure there are no requests in
6651 * one of the PXP internal queues with "old" ILT addresses
6652 */
6653 msleep(20);
6654 /*
6655 * Master enable - Due to WB DMAE writes performed before this
6656 * register is re-initialized as part of the regular function
6657 * init
6658 */
6659 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6660 /* Enable the function in IGU */
6661 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6662 }
6663
523224a3 6664 bp->dmae_ready = 1;
34f80b04 6665
619c5cb6 6666 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 6667
619c5cb6 6668 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6669 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6670
619c5cb6
VZ
6671 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6672 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6673 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6674 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6675 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6676 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6677 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6678 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6679 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6680 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6681 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6682 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6683 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6684
6685 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6686 REG_WR(bp, QM_REG_PF_EN, 1);
6687
619c5cb6
VZ
6688 if (!CHIP_IS_E1x(bp)) {
6689 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6690 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6691 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6692 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6693 }
6694 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6695
6696 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6697 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6698 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6699 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6700 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6701 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6702 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6703 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6704 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6705 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6706 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6707 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6708 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6709
619c5cb6 6710 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 6711
619c5cb6 6712 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 6713
619c5cb6 6714 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6715 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6716
fb3bff17 6717 if (IS_MF(bp)) {
34f80b04 6718 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 6719 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
6720 }
6721
619c5cb6 6722 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 6723
34f80b04 6724 /* HC init per function */
f2e0899f
DK
6725 if (bp->common.int_block == INT_BLOCK_HC) {
6726 if (CHIP_IS_E1H(bp)) {
6727 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6728
6729 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6730 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6731 }
619c5cb6 6732 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
6733
6734 } else {
6735 int num_segs, sb_idx, prod_offset;
6736
34f80b04
EG
6737 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6738
619c5cb6 6739 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6740 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6741 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6742 }
6743
619c5cb6 6744 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 6745
619c5cb6 6746 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6747 int dsb_idx = 0;
6748 /**
6749 * Producer memory:
6750 * E2 mode: address 0-135 match to the mapping memory;
6751 * 136 - PF0 default prod; 137 - PF1 default prod;
6752 * 138 - PF2 default prod; 139 - PF3 default prod;
6753 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6754 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6755 * 144-147 reserved.
6756 *
6757 * E1.5 mode - In backward compatible mode;
6758 * for non default SB; each even line in the memory
6759 * holds the U producer and each odd line hold
6760 * the C producer. The first 128 producers are for
6761 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6762 * producers are for the DSB for each PF.
6763 * Each PF has five segments: (the order inside each
6764 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6765 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6766 * 144-147 attn prods;
6767 */
6768 /* non-default-status-blocks */
6769 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6770 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6771 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6772 prod_offset = (bp->igu_base_sb + sb_idx) *
6773 num_segs;
6774
6775 for (i = 0; i < num_segs; i++) {
6776 addr = IGU_REG_PROD_CONS_MEMORY +
6777 (prod_offset + i) * 4;
6778 REG_WR(bp, addr, 0);
6779 }
6780 /* send consumer update with value 0 */
6781 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6782 USTORM_ID, 0, IGU_INT_NOP, 1);
6783 bnx2x_igu_clear_sb(bp,
6784 bp->igu_base_sb + sb_idx);
6785 }
6786
6787 /* default-status-blocks */
6788 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6789 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6790
6791 if (CHIP_MODE_IS_4_PORT(bp))
6792 dsb_idx = BP_FUNC(bp);
6793 else
3395a033 6794 dsb_idx = BP_VN(bp);
f2e0899f
DK
6795
6796 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6797 IGU_BC_BASE_DSB_PROD + dsb_idx :
6798 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6799
3395a033
DK
6800 /*
6801 * igu prods come in chunks of E1HVN_MAX (4) -
6802 * does not matters what is the current chip mode
6803 */
f2e0899f
DK
6804 for (i = 0; i < (num_segs * E1HVN_MAX);
6805 i += E1HVN_MAX) {
6806 addr = IGU_REG_PROD_CONS_MEMORY +
6807 (prod_offset + i)*4;
6808 REG_WR(bp, addr, 0);
6809 }
6810 /* send consumer update with 0 */
6811 if (CHIP_INT_MODE_IS_BC(bp)) {
6812 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6813 USTORM_ID, 0, IGU_INT_NOP, 1);
6814 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6815 CSTORM_ID, 0, IGU_INT_NOP, 1);
6816 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6817 XSTORM_ID, 0, IGU_INT_NOP, 1);
6818 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6819 TSTORM_ID, 0, IGU_INT_NOP, 1);
6820 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6821 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6822 } else {
6823 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6824 USTORM_ID, 0, IGU_INT_NOP, 1);
6825 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6826 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6827 }
6828 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6829
6830 /* !!! these should become driver const once
6831 rf-tool supports split-68 const */
6832 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6833 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6834 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6835 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6836 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6837 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6838 }
34f80b04 6839 }
34f80b04 6840
c14423fe 6841 /* Reset PCIE errors for debug */
a2fbb9ea
ET
6842 REG_WR(bp, 0x2114, 0xffffffff);
6843 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 6844
f4a66897
VZ
6845 if (CHIP_IS_E1x(bp)) {
6846 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6847 main_mem_base = HC_REG_MAIN_MEMORY +
6848 BP_PORT(bp) * (main_mem_size * 4);
6849 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6850 main_mem_width = 8;
6851
6852 val = REG_RD(bp, main_mem_prty_clr);
6853 if (val)
51c1a580
MS
6854 DP(NETIF_MSG_HW,
6855 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
6856 val);
f4a66897
VZ
6857
6858 /* Clear "false" parity errors in MSI-X table */
6859 for (i = main_mem_base;
6860 i < main_mem_base + main_mem_size * 4;
6861 i += main_mem_width) {
6862 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6863 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6864 i, main_mem_width / 4);
6865 }
6866 /* Clear HC parity attention */
6867 REG_RD(bp, main_mem_prty_clr);
6868 }
6869
619c5cb6
VZ
6870#ifdef BNX2X_STOP_ON_ERROR
6871 /* Enable STORMs SP logging */
6872 REG_WR8(bp, BAR_USTRORM_INTMEM +
6873 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6874 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6875 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6876 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6877 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6878 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6879 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6880#endif
6881
b7737c9b 6882 bnx2x_phy_probe(&bp->link_params);
f85582f8 6883
34f80b04
EG
6884 return 0;
6885}
6886
a2fbb9ea 6887
9f6c9258 6888void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 6889{
a2fbb9ea 6890 /* fastpath */
b3b83c3f 6891 bnx2x_free_fp_mem(bp);
a2fbb9ea
ET
6892 /* end of fastpath */
6893
6894 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 6895 sizeof(struct host_sp_status_block));
a2fbb9ea 6896
619c5cb6
VZ
6897 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6898 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6899
a2fbb9ea 6900 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 6901 sizeof(struct bnx2x_slowpath));
a2fbb9ea 6902
523224a3
DK
6903 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6904 bp->context.size);
6905
6906 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6907
6908 BNX2X_FREE(bp->ilt->lines);
f85582f8 6909
37b091ba 6910#ifdef BCM_CNIC
619c5cb6 6911 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6912 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6913 sizeof(struct host_hc_status_block_e2));
6914 else
6915 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6916 sizeof(struct host_hc_status_block_e1x));
f85582f8 6917
523224a3 6918 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
a2fbb9ea 6919#endif
f85582f8 6920
7a9b2557 6921 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 6922
523224a3
DK
6923 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6924 BCM_PAGE_SIZE * NUM_EQ_PAGES);
619c5cb6
VZ
6925}
6926
6927static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6928{
6929 int num_groups;
50f0a562 6930 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
619c5cb6 6931
50f0a562
BW
6932 /* number of queues for statistics is number of eth queues + FCoE */
6933 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
619c5cb6
VZ
6934
6935 /* Total number of FW statistics requests =
50f0a562
BW
6936 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
6937 * num of queues
6938 */
6939 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
523224a3 6940
619c5cb6
VZ
6941
6942 /* Request is built from stats_query_header and an array of
6943 * stats_query_cmd_group each of which contains
6944 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6945 * configured in the stats_query_header.
6946 */
50f0a562
BW
6947 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
6948 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
619c5cb6
VZ
6949
6950 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6951 num_groups * sizeof(struct stats_query_cmd_group);
6952
6953 /* Data for statistics requests + stats_conter
6954 *
6955 * stats_counter holds per-STORM counters that are incremented
6956 * when STORM has finished with the current request.
50f0a562
BW
6957 *
6958 * memory for FCoE offloaded statistics are counted anyway,
6959 * even if they will not be sent.
619c5cb6
VZ
6960 */
6961 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6962 sizeof(struct per_pf_stats) +
50f0a562 6963 sizeof(struct fcoe_statistics_params) +
619c5cb6
VZ
6964 sizeof(struct per_queue_stats) * num_queue_stats +
6965 sizeof(struct stats_counter);
6966
6967 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6968 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6969
6970 /* Set shortcuts */
6971 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6972 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6973
6974 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6975 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6976
6977 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6978 bp->fw_stats_req_sz;
6979 return 0;
6980
6981alloc_mem_err:
6982 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6983 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
51c1a580 6984 BNX2X_ERR("Can't allocate memory\n");
619c5cb6 6985 return -ENOMEM;
a2fbb9ea
ET
6986}
6987
f2e0899f 6988
9f6c9258 6989int bnx2x_alloc_mem(struct bnx2x *bp)
a2fbb9ea 6990{
523224a3 6991#ifdef BCM_CNIC
619c5cb6
VZ
6992 if (!CHIP_IS_E1x(bp))
6993 /* size = the status block + ramrod buffers */
f2e0899f
DK
6994 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6995 sizeof(struct host_hc_status_block_e2));
6996 else
6997 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6998 sizeof(struct host_hc_status_block_e1x));
8badd27a 6999
523224a3
DK
7000 /* allocate searcher T2 table */
7001 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7002#endif
a2fbb9ea 7003
8badd27a 7004
523224a3
DK
7005 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7006 sizeof(struct host_sp_status_block));
a2fbb9ea 7007
523224a3
DK
7008 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7009 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7010
82fa848c
MY
7011#ifdef BCM_CNIC
7012 /* write address to which L5 should insert its values */
7013 bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
7014#endif
7015
619c5cb6
VZ
7016 /* Allocated memory for FW statistics */
7017 if (bnx2x_alloc_fw_stats_mem(bp))
7018 goto alloc_mem_err;
7019
6383c0b3 7020 bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
f85582f8 7021
523224a3
DK
7022 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
7023 bp->context.size);
65abd74d 7024
523224a3 7025 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7026
523224a3
DK
7027 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7028 goto alloc_mem_err;
65abd74d 7029
9f6c9258
DK
7030 /* Slow path ring */
7031 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7032
523224a3
DK
7033 /* EQ */
7034 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7035 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7036
b3b83c3f
DK
7037
7038 /* fastpath */
7039 /* need to be done at the end, since it's self adjusting to amount
7040 * of memory available for RSS queues
7041 */
7042 if (bnx2x_alloc_fp_mem(bp))
7043 goto alloc_mem_err;
9f6c9258 7044 return 0;
e1510706 7045
9f6c9258
DK
7046alloc_mem_err:
7047 bnx2x_free_mem(bp);
51c1a580 7048 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7049 return -ENOMEM;
65abd74d
YG
7050}
7051
a2fbb9ea
ET
7052/*
7053 * Init service functions
7054 */
a2fbb9ea 7055
619c5cb6
VZ
7056int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7057 struct bnx2x_vlan_mac_obj *obj, bool set,
7058 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7059{
619c5cb6
VZ
7060 int rc;
7061 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7062
619c5cb6 7063 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7064
619c5cb6
VZ
7065 /* Fill general parameters */
7066 ramrod_param.vlan_mac_obj = obj;
7067 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7068
619c5cb6
VZ
7069 /* Fill a user request section if needed */
7070 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7071 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7072
619c5cb6 7073 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7074
619c5cb6
VZ
7075 /* Set the command: ADD or DEL */
7076 if (set)
7077 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7078 else
7079 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7080 }
7081
619c5cb6
VZ
7082 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7083 if (rc < 0)
7084 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7085 return rc;
a2fbb9ea
ET
7086}
7087
619c5cb6
VZ
7088int bnx2x_del_all_macs(struct bnx2x *bp,
7089 struct bnx2x_vlan_mac_obj *mac_obj,
7090 int mac_type, bool wait_for_comp)
e665bfda 7091{
619c5cb6
VZ
7092 int rc;
7093 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7094
619c5cb6
VZ
7095 /* Wait for completion of requested */
7096 if (wait_for_comp)
7097 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7098
619c5cb6
VZ
7099 /* Set the mac type of addresses we want to clear */
7100 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7101
619c5cb6
VZ
7102 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7103 if (rc < 0)
7104 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7105
619c5cb6 7106 return rc;
0793f83f
DK
7107}
7108
619c5cb6 7109int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7110{
619c5cb6 7111 unsigned long ramrod_flags = 0;
e665bfda 7112
614c76df 7113#ifdef BCM_CNIC
9e62e912 7114 if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) {
51c1a580
MS
7115 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7116 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7117 return 0;
7118 }
7119#endif
7120
619c5cb6 7121 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7122
619c5cb6
VZ
7123 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7124 /* Eth MAC is set on RSS leading client (fp[0]) */
7125 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
7126 BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7127}
6e30dd4e 7128
619c5cb6 7129int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7130{
619c5cb6 7131 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7132}
a2fbb9ea 7133
d6214d7a 7134/**
e8920674 7135 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7136 *
e8920674 7137 * @bp: driver handle
d6214d7a 7138 *
e8920674 7139 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7140 */
9ee3d37b 7141static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7142{
9ee3d37b 7143 switch (int_mode) {
d6214d7a
DK
7144 case INT_MODE_MSI:
7145 bnx2x_enable_msi(bp);
7146 /* falling through... */
7147 case INT_MODE_INTx:
6383c0b3 7148 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
51c1a580 7149 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7150 break;
d6214d7a
DK
7151 default:
7152 /* Set number of queues according to bp->multi_mode value */
7153 bnx2x_set_num_queues(bp);
ca00392c 7154
51c1a580 7155 BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
ca00392c 7156
d6214d7a
DK
7157 /* if we can't use MSI-X we only need one fp,
7158 * so try to enable MSI-X with the requested number of fp's
7159 * and fallback to MSI or legacy INTx with one fp
7160 */
9ee3d37b 7161 if (bnx2x_enable_msix(bp)) {
d6214d7a 7162 /* failed to enable MSI-X */
51c1a580
MS
7163 BNX2X_DEV_INFO("Failed to enable MSI-X (%d), set number of queues to %d\n",
7164 bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
7165
6383c0b3 7166 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
d6214d7a 7167
9ee3d37b 7168 /* Try to enable MSI */
d6214d7a
DK
7169 if (!(bp->flags & DISABLE_MSI_FLAG))
7170 bnx2x_enable_msi(bp);
7171 }
9f6c9258
DK
7172 break;
7173 }
a2fbb9ea
ET
7174}
7175
c2bff63f
DK
7176/* must be called prioir to any HW initializations */
7177static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7178{
7179 return L2_ILT_LINES(bp);
7180}
7181
523224a3
DK
7182void bnx2x_ilt_set_info(struct bnx2x *bp)
7183{
7184 struct ilt_client_info *ilt_client;
7185 struct bnx2x_ilt *ilt = BP_ILT(bp);
7186 u16 line = 0;
7187
7188 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7189 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7190
7191 /* CDU */
7192 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7193 ilt_client->client_num = ILT_CLIENT_CDU;
7194 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7195 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7196 ilt_client->start = line;
619c5cb6 7197 line += bnx2x_cid_ilt_lines(bp);
523224a3
DK
7198#ifdef BCM_CNIC
7199 line += CNIC_ILT_LINES;
7200#endif
7201 ilt_client->end = line - 1;
7202
51c1a580 7203 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7204 ilt_client->start,
7205 ilt_client->end,
7206 ilt_client->page_size,
7207 ilt_client->flags,
7208 ilog2(ilt_client->page_size >> 12));
7209
7210 /* QM */
7211 if (QM_INIT(bp->qm_cid_count)) {
7212 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7213 ilt_client->client_num = ILT_CLIENT_QM;
7214 ilt_client->page_size = QM_ILT_PAGE_SZ;
7215 ilt_client->flags = 0;
7216 ilt_client->start = line;
7217
7218 /* 4 bytes for each cid */
7219 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7220 QM_ILT_PAGE_SZ);
7221
7222 ilt_client->end = line - 1;
7223
51c1a580
MS
7224 DP(NETIF_MSG_IFUP,
7225 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7226 ilt_client->start,
7227 ilt_client->end,
7228 ilt_client->page_size,
7229 ilt_client->flags,
7230 ilog2(ilt_client->page_size >> 12));
7231
7232 }
7233 /* SRC */
7234 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7235#ifdef BCM_CNIC
7236 ilt_client->client_num = ILT_CLIENT_SRC;
7237 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7238 ilt_client->flags = 0;
7239 ilt_client->start = line;
7240 line += SRC_ILT_LINES;
7241 ilt_client->end = line - 1;
7242
51c1a580
MS
7243 DP(NETIF_MSG_IFUP,
7244 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7245 ilt_client->start,
7246 ilt_client->end,
7247 ilt_client->page_size,
7248 ilt_client->flags,
7249 ilog2(ilt_client->page_size >> 12));
7250
7251#else
7252 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7253#endif
9f6c9258 7254
523224a3
DK
7255 /* TM */
7256 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7257#ifdef BCM_CNIC
7258 ilt_client->client_num = ILT_CLIENT_TM;
7259 ilt_client->page_size = TM_ILT_PAGE_SZ;
7260 ilt_client->flags = 0;
7261 ilt_client->start = line;
7262 line += TM_ILT_LINES;
7263 ilt_client->end = line - 1;
7264
51c1a580
MS
7265 DP(NETIF_MSG_IFUP,
7266 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7267 ilt_client->start,
7268 ilt_client->end,
7269 ilt_client->page_size,
7270 ilt_client->flags,
7271 ilog2(ilt_client->page_size >> 12));
9f6c9258 7272
523224a3
DK
7273#else
7274 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7275#endif
619c5cb6 7276 BUG_ON(line > ILT_MAX_LINES);
523224a3 7277}
f85582f8 7278
619c5cb6
VZ
7279/**
7280 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7281 *
7282 * @bp: driver handle
7283 * @fp: pointer to fastpath
7284 * @init_params: pointer to parameters structure
7285 *
7286 * parameters configured:
7287 * - HC configuration
7288 * - Queue's CDU context
7289 */
7290static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
7291 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 7292{
6383c0b3
AE
7293
7294 u8 cos;
619c5cb6
VZ
7295 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7296 if (!IS_FCOE_FP(fp)) {
7297 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7298 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7299
7300 /* If HC is supporterd, enable host coalescing in the transition
7301 * to INIT state.
7302 */
7303 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7304 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7305
7306 /* HC rate */
7307 init_params->rx.hc_rate = bp->rx_ticks ?
7308 (1000000 / bp->rx_ticks) : 0;
7309 init_params->tx.hc_rate = bp->tx_ticks ?
7310 (1000000 / bp->tx_ticks) : 0;
7311
7312 /* FW SB ID */
7313 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7314 fp->fw_sb_id;
7315
7316 /*
7317 * CQ index among the SB indices: FCoE clients uses the default
7318 * SB, therefore it's different.
7319 */
6383c0b3
AE
7320 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7321 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
7322 }
7323
6383c0b3
AE
7324 /* set maximum number of COSs supported by this queue */
7325 init_params->max_cos = fp->max_cos;
7326
51c1a580 7327 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
7328 fp->index, init_params->max_cos);
7329
7330 /* set the context pointers queue object */
7331 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
7332 init_params->cxts[cos] =
7333 &bp->context.vcxt[fp->txdata[cos].cid].eth;
619c5cb6
VZ
7334}
7335
6383c0b3
AE
7336int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7337 struct bnx2x_queue_state_params *q_params,
7338 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7339 int tx_index, bool leading)
7340{
7341 memset(tx_only_params, 0, sizeof(*tx_only_params));
7342
7343 /* Set the command */
7344 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7345
7346 /* Set tx-only QUEUE flags: don't zero statistics */
7347 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7348
7349 /* choose the index of the cid to send the slow path on */
7350 tx_only_params->cid_index = tx_index;
7351
7352 /* Set general TX_ONLY_SETUP parameters */
7353 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7354
7355 /* Set Tx TX_ONLY_SETUP parameters */
7356 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7357
51c1a580
MS
7358 DP(NETIF_MSG_IFUP,
7359 "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
6383c0b3
AE
7360 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7361 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7362 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7363
7364 /* send the ramrod */
7365 return bnx2x_queue_state_change(bp, q_params);
7366}
7367
7368
619c5cb6
VZ
7369/**
7370 * bnx2x_setup_queue - setup queue
7371 *
7372 * @bp: driver handle
7373 * @fp: pointer to fastpath
7374 * @leading: is leading
7375 *
7376 * This function performs 2 steps in a Queue state machine
7377 * actually: 1) RESET->INIT 2) INIT->SETUP
7378 */
7379
7380int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7381 bool leading)
7382{
3b603066 7383 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
7384 struct bnx2x_queue_setup_params *setup_params =
7385 &q_params.params.setup;
6383c0b3
AE
7386 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
7387 &q_params.params.tx_only;
a2fbb9ea 7388 int rc;
6383c0b3
AE
7389 u8 tx_index;
7390
51c1a580 7391 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 7392
ec6ba945
VZ
7393 /* reset IGU state skip FCoE L2 queue */
7394 if (!IS_FCOE_FP(fp))
7395 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 7396 IGU_INT_ENABLE, 0);
a2fbb9ea 7397
619c5cb6
VZ
7398 q_params.q_obj = &fp->q_obj;
7399 /* We want to wait for completion in this context */
7400 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 7401
619c5cb6
VZ
7402 /* Prepare the INIT parameters */
7403 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 7404
619c5cb6
VZ
7405 /* Set the command */
7406 q_params.cmd = BNX2X_Q_CMD_INIT;
7407
7408 /* Change the state to INIT */
7409 rc = bnx2x_queue_state_change(bp, &q_params);
7410 if (rc) {
6383c0b3 7411 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
7412 return rc;
7413 }
ec6ba945 7414
51c1a580 7415 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
7416
7417
619c5cb6
VZ
7418 /* Now move the Queue to the SETUP state... */
7419 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 7420
619c5cb6
VZ
7421 /* Set QUEUE flags */
7422 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 7423
619c5cb6 7424 /* Set general SETUP parameters */
6383c0b3
AE
7425 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
7426 FIRST_TX_COS_INDEX);
619c5cb6 7427
6383c0b3 7428 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
7429 &setup_params->rxq_params);
7430
6383c0b3
AE
7431 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
7432 FIRST_TX_COS_INDEX);
619c5cb6
VZ
7433
7434 /* Set the command */
7435 q_params.cmd = BNX2X_Q_CMD_SETUP;
7436
7437 /* Change the state to SETUP */
7438 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
7439 if (rc) {
7440 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
7441 return rc;
7442 }
7443
7444 /* loop through the relevant tx-only indices */
7445 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7446 tx_index < fp->max_cos;
7447 tx_index++) {
7448
7449 /* prepare and send tx-only ramrod*/
7450 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
7451 tx_only_params, tx_index, leading);
7452 if (rc) {
7453 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
7454 fp->index, tx_index);
7455 return rc;
7456 }
7457 }
523224a3 7458
34f80b04 7459 return rc;
a2fbb9ea
ET
7460}
7461
619c5cb6 7462static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 7463{
619c5cb6 7464 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 7465 struct bnx2x_fp_txdata *txdata;
3b603066 7466 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
7467 int rc, tx_index;
7468
51c1a580 7469 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 7470
619c5cb6
VZ
7471 q_params.q_obj = &fp->q_obj;
7472 /* We want to wait for completion in this context */
7473 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 7474
6383c0b3
AE
7475
7476 /* close tx-only connections */
7477 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7478 tx_index < fp->max_cos;
7479 tx_index++){
7480
7481 /* ascertain this is a normal queue*/
7482 txdata = &fp->txdata[tx_index];
7483
51c1a580 7484 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
7485 txdata->txq_index);
7486
7487 /* send halt terminate on tx-only connection */
7488 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7489 memset(&q_params.params.terminate, 0,
7490 sizeof(q_params.params.terminate));
7491 q_params.params.terminate.cid_index = tx_index;
7492
7493 rc = bnx2x_queue_state_change(bp, &q_params);
7494 if (rc)
7495 return rc;
7496
7497 /* send halt terminate on tx-only connection */
7498 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7499 memset(&q_params.params.cfc_del, 0,
7500 sizeof(q_params.params.cfc_del));
7501 q_params.params.cfc_del.cid_index = tx_index;
7502 rc = bnx2x_queue_state_change(bp, &q_params);
7503 if (rc)
7504 return rc;
7505 }
7506 /* Stop the primary connection: */
7507 /* ...halt the connection */
619c5cb6
VZ
7508 q_params.cmd = BNX2X_Q_CMD_HALT;
7509 rc = bnx2x_queue_state_change(bp, &q_params);
7510 if (rc)
da5a662a 7511 return rc;
a2fbb9ea 7512
6383c0b3 7513 /* ...terminate the connection */
619c5cb6 7514 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
7515 memset(&q_params.params.terminate, 0,
7516 sizeof(q_params.params.terminate));
7517 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
7518 rc = bnx2x_queue_state_change(bp, &q_params);
7519 if (rc)
523224a3 7520 return rc;
6383c0b3 7521 /* ...delete cfc entry */
619c5cb6 7522 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
7523 memset(&q_params.params.cfc_del, 0,
7524 sizeof(q_params.params.cfc_del));
7525 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 7526 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
7527}
7528
7529
34f80b04
EG
7530static void bnx2x_reset_func(struct bnx2x *bp)
7531{
7532 int port = BP_PORT(bp);
7533 int func = BP_FUNC(bp);
f2e0899f 7534 int i;
523224a3
DK
7535
7536 /* Disable the function in the FW */
7537 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7538 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7539 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7540 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7541
7542 /* FP SBs */
ec6ba945 7543 for_each_eth_queue(bp, i) {
523224a3 7544 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 7545 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
7546 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7547 SB_DISABLED);
523224a3
DK
7548 }
7549
619c5cb6
VZ
7550#ifdef BCM_CNIC
7551 /* CNIC SB */
7552 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7553 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7554 SB_DISABLED);
7555#endif
523224a3 7556 /* SP SB */
619c5cb6 7557 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
7558 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7559 SB_DISABLED);
523224a3
DK
7560
7561 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7562 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7563 0);
34f80b04
EG
7564
7565 /* Configure IGU */
f2e0899f
DK
7566 if (bp->common.int_block == INT_BLOCK_HC) {
7567 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7568 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7569 } else {
7570 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7571 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7572 }
34f80b04 7573
37b091ba
MC
7574#ifdef BCM_CNIC
7575 /* Disable Timer scan */
7576 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7577 /*
7578 * Wait for at least 10ms and up to 2 second for the timers scan to
7579 * complete
7580 */
7581 for (i = 0; i < 200; i++) {
7582 msleep(10);
7583 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7584 break;
7585 }
7586#endif
34f80b04 7587 /* Clear ILT */
f2e0899f
DK
7588 bnx2x_clear_func_ilt(bp, func);
7589
7590 /* Timers workaround bug for E2: if this is vnic-3,
7591 * we need to set the entire ilt range for this timers.
7592 */
619c5cb6 7593 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
7594 struct ilt_client_info ilt_cli;
7595 /* use dummy TM client */
7596 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7597 ilt_cli.start = 0;
7598 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7599 ilt_cli.client_num = ILT_CLIENT_TM;
7600
7601 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7602 }
7603
7604 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 7605 if (!CHIP_IS_E1x(bp))
f2e0899f 7606 bnx2x_pf_disable(bp);
523224a3
DK
7607
7608 bp->dmae_ready = 0;
34f80b04
EG
7609}
7610
7611static void bnx2x_reset_port(struct bnx2x *bp)
7612{
7613 int port = BP_PORT(bp);
7614 u32 val;
7615
619c5cb6
VZ
7616 /* Reset physical Link */
7617 bnx2x__link_reset(bp);
7618
34f80b04
EG
7619 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7620
7621 /* Do not rcv packets to BRB */
7622 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7623 /* Do not direct rcv packets that are not for MCP to the BRB */
7624 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7625 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7626
7627 /* Configure AEU */
7628 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7629
7630 msleep(100);
7631 /* Check for BRB port occupancy */
7632 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7633 if (val)
7634 DP(NETIF_MSG_IFDOWN,
33471629 7635 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
7636
7637 /* TODO: Close Doorbell port? */
7638}
7639
619c5cb6 7640static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 7641{
3b603066 7642 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 7643
619c5cb6
VZ
7644 /* Prepare parameters for function state transitions */
7645 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 7646
619c5cb6
VZ
7647 func_params.f_obj = &bp->func_obj;
7648 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 7649
619c5cb6 7650 func_params.params.hw_init.load_phase = load_code;
49d66772 7651
619c5cb6 7652 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
7653}
7654
619c5cb6 7655static inline int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 7656{
3b603066 7657 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 7658 int rc;
228241eb 7659
619c5cb6
VZ
7660 /* Prepare parameters for function state transitions */
7661 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7662 func_params.f_obj = &bp->func_obj;
7663 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 7664
619c5cb6
VZ
7665 /*
7666 * Try to stop the function the 'good way'. If fails (in case
7667 * of a parity error during bnx2x_chip_cleanup()) and we are
7668 * not in a debug mode, perform a state transaction in order to
7669 * enable further HW_RESET transaction.
7670 */
7671 rc = bnx2x_func_state_change(bp, &func_params);
7672 if (rc) {
34f80b04 7673#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 7674 return rc;
34f80b04 7675#else
51c1a580 7676 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
7677 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7678 return bnx2x_func_state_change(bp, &func_params);
34f80b04 7679#endif
228241eb 7680 }
a2fbb9ea 7681
619c5cb6
VZ
7682 return 0;
7683}
523224a3 7684
619c5cb6
VZ
7685/**
7686 * bnx2x_send_unload_req - request unload mode from the MCP.
7687 *
7688 * @bp: driver handle
7689 * @unload_mode: requested function's unload mode
7690 *
7691 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7692 */
7693u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7694{
7695 u32 reset_code = 0;
7696 int port = BP_PORT(bp);
3101c2bc 7697
619c5cb6 7698 /* Select the UNLOAD request mode */
65abd74d
YG
7699 if (unload_mode == UNLOAD_NORMAL)
7700 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7701
7d0446c2 7702 else if (bp->flags & NO_WOL_FLAG)
65abd74d 7703 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 7704
7d0446c2 7705 else if (bp->wol) {
65abd74d
YG
7706 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7707 u8 *mac_addr = bp->dev->dev_addr;
7708 u32 val;
f9977903
DK
7709 u16 pmc;
7710
65abd74d 7711 /* The mac address is written to entries 1-4 to
f9977903
DK
7712 * preserve entry 0 which is used by the PMF
7713 */
3395a033 7714 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
7715
7716 val = (mac_addr[0] << 8) | mac_addr[1];
7717 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7718
7719 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7720 (mac_addr[4] << 8) | mac_addr[5];
7721 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7722
f9977903
DK
7723 /* Enable the PME and clear the status */
7724 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
7725 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
7726 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
7727
65abd74d
YG
7728 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7729
7730 } else
7731 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 7732
619c5cb6
VZ
7733 /* Send the request to the MCP */
7734 if (!BP_NOMCP(bp))
7735 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7736 else {
7737 int path = BP_PATH(bp);
7738
51c1a580 7739 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
7740 path, load_count[path][0], load_count[path][1],
7741 load_count[path][2]);
7742 load_count[path][0]--;
7743 load_count[path][1 + port]--;
51c1a580 7744 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
7745 path, load_count[path][0], load_count[path][1],
7746 load_count[path][2]);
7747 if (load_count[path][0] == 0)
7748 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7749 else if (load_count[path][1 + port] == 0)
7750 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7751 else
7752 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7753 }
7754
7755 return reset_code;
7756}
7757
7758/**
7759 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7760 *
7761 * @bp: driver handle
7762 */
7763void bnx2x_send_unload_done(struct bnx2x *bp)
7764{
7765 /* Report UNLOAD_DONE to MCP */
7766 if (!BP_NOMCP(bp))
7767 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7768}
7769
6debea87
DK
7770static inline int bnx2x_func_wait_started(struct bnx2x *bp)
7771{
7772 int tout = 50;
7773 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
7774
7775 if (!bp->port.pmf)
7776 return 0;
7777
7778 /*
7779 * (assumption: No Attention from MCP at this stage)
7780 * PMF probably in the middle of TXdisable/enable transaction
7781 * 1. Sync IRS for default SB
7782 * 2. Sync SP queue - this guarantes us that attention handling started
7783 * 3. Wait, that TXdisable/enable transaction completes
7784 *
7785 * 1+2 guranty that if DCBx attention was scheduled it already changed
7786 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
7787 * received complettion for the transaction the state is TX_STOPPED.
7788 * State will return to STARTED after completion of TX_STOPPED-->STARTED
7789 * transaction.
7790 */
7791
7792 /* make sure default SB ISR is done */
7793 if (msix)
7794 synchronize_irq(bp->msix_table[0].vector);
7795 else
7796 synchronize_irq(bp->pdev->irq);
7797
7798 flush_workqueue(bnx2x_wq);
7799
7800 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
7801 BNX2X_F_STATE_STARTED && tout--)
7802 msleep(20);
7803
7804 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
7805 BNX2X_F_STATE_STARTED) {
7806#ifdef BNX2X_STOP_ON_ERROR
51c1a580 7807 BNX2X_ERR("Wrong function state\n");
6debea87
DK
7808 return -EBUSY;
7809#else
7810 /*
7811 * Failed to complete the transaction in a "good way"
7812 * Force both transactions with CLR bit
7813 */
3b603066 7814 struct bnx2x_func_state_params func_params = {NULL};
6debea87 7815
51c1a580
MS
7816 DP(NETIF_MSG_IFDOWN,
7817 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
7818
7819 func_params.f_obj = &bp->func_obj;
7820 __set_bit(RAMROD_DRV_CLR_ONLY,
7821 &func_params.ramrod_flags);
7822
7823 /* STARTED-->TX_ST0PPED */
7824 func_params.cmd = BNX2X_F_CMD_TX_STOP;
7825 bnx2x_func_state_change(bp, &func_params);
7826
7827 /* TX_ST0PPED-->STARTED */
7828 func_params.cmd = BNX2X_F_CMD_TX_START;
7829 return bnx2x_func_state_change(bp, &func_params);
7830#endif
7831 }
7832
7833 return 0;
7834}
7835
619c5cb6
VZ
7836void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7837{
7838 int port = BP_PORT(bp);
6383c0b3
AE
7839 int i, rc = 0;
7840 u8 cos;
3b603066 7841 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
7842 u32 reset_code;
7843
7844 /* Wait until tx fastpath tasks complete */
7845 for_each_tx_queue(bp, i) {
7846 struct bnx2x_fastpath *fp = &bp->fp[i];
7847
6383c0b3
AE
7848 for_each_cos_in_tx_queue(fp, cos)
7849 rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
619c5cb6
VZ
7850#ifdef BNX2X_STOP_ON_ERROR
7851 if (rc)
7852 return;
7853#endif
7854 }
7855
7856 /* Give HW time to discard old tx messages */
7857 usleep_range(1000, 1000);
7858
7859 /* Clean all ETH MACs */
7860 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7861 if (rc < 0)
7862 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7863
7864 /* Clean up UC list */
7865 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7866 true);
7867 if (rc < 0)
51c1a580
MS
7868 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
7869 rc);
619c5cb6
VZ
7870
7871 /* Disable LLH */
7872 if (!CHIP_IS_E1(bp))
7873 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7874
7875 /* Set "drop all" (stop Rx).
7876 * We need to take a netif_addr_lock() here in order to prevent
7877 * a race between the completion code and this code.
7878 */
7879 netif_addr_lock_bh(bp->dev);
7880 /* Schedule the rx_mode command */
7881 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7882 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7883 else
7884 bnx2x_set_storm_rx_mode(bp);
7885
7886 /* Cleanup multicast configuration */
7887 rparam.mcast_obj = &bp->mcast_obj;
7888 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7889 if (rc < 0)
7890 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7891
7892 netif_addr_unlock_bh(bp->dev);
7893
7894
6debea87
DK
7895
7896 /*
7897 * Send the UNLOAD_REQUEST to the MCP. This will return if
7898 * this function should perform FUNC, PORT or COMMON HW
7899 * reset.
7900 */
7901 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7902
7903 /*
7904 * (assumption: No Attention from MCP at this stage)
7905 * PMF probably in the middle of TXdisable/enable transaction
7906 */
7907 rc = bnx2x_func_wait_started(bp);
7908 if (rc) {
7909 BNX2X_ERR("bnx2x_func_wait_started failed\n");
7910#ifdef BNX2X_STOP_ON_ERROR
7911 return;
7912#endif
7913 }
7914
34f80b04 7915 /* Close multi and leading connections
619c5cb6
VZ
7916 * Completions for ramrods are collected in a synchronous way
7917 */
523224a3 7918 for_each_queue(bp, i)
619c5cb6 7919 if (bnx2x_stop_queue(bp, i))
523224a3
DK
7920#ifdef BNX2X_STOP_ON_ERROR
7921 return;
7922#else
228241eb 7923 goto unload_error;
523224a3 7924#endif
619c5cb6
VZ
7925 /* If SP settings didn't get completed so far - something
7926 * very wrong has happen.
7927 */
7928 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7929 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 7930
619c5cb6
VZ
7931#ifndef BNX2X_STOP_ON_ERROR
7932unload_error:
7933#endif
523224a3 7934 rc = bnx2x_func_stop(bp);
da5a662a 7935 if (rc) {
523224a3 7936 BNX2X_ERR("Function stop failed!\n");
da5a662a 7937#ifdef BNX2X_STOP_ON_ERROR
523224a3 7938 return;
523224a3 7939#endif
34f80b04 7940 }
a2fbb9ea 7941
523224a3
DK
7942 /* Disable HW interrupts, NAPI */
7943 bnx2x_netif_stop(bp, 1);
7944
7945 /* Release IRQs */
d6214d7a 7946 bnx2x_free_irq(bp);
523224a3 7947
a2fbb9ea 7948 /* Reset the chip */
619c5cb6
VZ
7949 rc = bnx2x_reset_hw(bp, reset_code);
7950 if (rc)
7951 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 7952
356e2385 7953
619c5cb6
VZ
7954 /* Report UNLOAD_DONE to MCP */
7955 bnx2x_send_unload_done(bp);
72fd0718
VZ
7956}
7957
9f6c9258 7958void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
7959{
7960 u32 val;
7961
51c1a580 7962 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
7963
7964 if (CHIP_IS_E1(bp)) {
7965 int port = BP_PORT(bp);
7966 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7967 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7968
7969 val = REG_RD(bp, addr);
7970 val &= ~(0x300);
7971 REG_WR(bp, addr, val);
619c5cb6 7972 } else {
72fd0718
VZ
7973 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7974 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7975 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7976 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7977 }
7978}
7979
72fd0718
VZ
7980/* Close gates #2, #3 and #4: */
7981static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7982{
c9ee9206 7983 u32 val;
72fd0718
VZ
7984
7985 /* Gates #2 and #4a are closed/opened for "not E1" only */
7986 if (!CHIP_IS_E1(bp)) {
7987 /* #4 */
c9ee9206 7988 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 7989 /* #2 */
c9ee9206 7990 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
7991 }
7992
7993 /* #3 */
c9ee9206
VZ
7994 if (CHIP_IS_E1x(bp)) {
7995 /* Prevent interrupts from HC on both ports */
7996 val = REG_RD(bp, HC_REG_CONFIG_1);
7997 REG_WR(bp, HC_REG_CONFIG_1,
7998 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7999 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8000
8001 val = REG_RD(bp, HC_REG_CONFIG_0);
8002 REG_WR(bp, HC_REG_CONFIG_0,
8003 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8004 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8005 } else {
8006 /* Prevent incomming interrupts in IGU */
8007 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8008
8009 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8010 (!close) ?
8011 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8012 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8013 }
72fd0718 8014
51c1a580 8015 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8016 close ? "closing" : "opening");
8017 mmiowb();
8018}
8019
8020#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8021
8022static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8023{
8024 /* Do some magic... */
8025 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8026 *magic_val = val & SHARED_MF_CLP_MAGIC;
8027 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8028}
8029
e8920674
DK
8030/**
8031 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8032 *
e8920674
DK
8033 * @bp: driver handle
8034 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8035 */
8036static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8037{
8038 /* Restore the `magic' bit value... */
72fd0718
VZ
8039 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8040 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8041 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8042}
8043
f85582f8 8044/**
e8920674 8045 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8046 *
e8920674
DK
8047 * @bp: driver handle
8048 * @magic_val: old value of 'magic' bit.
8049 *
8050 * Takes care of CLP configurations.
72fd0718
VZ
8051 */
8052static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8053{
8054 u32 shmem;
8055 u32 validity_offset;
8056
51c1a580 8057 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8058
8059 /* Set `magic' bit in order to save MF config */
8060 if (!CHIP_IS_E1(bp))
8061 bnx2x_clp_reset_prep(bp, magic_val);
8062
8063 /* Get shmem offset */
8064 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8065 validity_offset = offsetof(struct shmem_region, validity_map[0]);
8066
8067 /* Clear validity map flags */
8068 if (shmem > 0)
8069 REG_WR(bp, shmem + validity_offset, 0);
8070}
8071
8072#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8073#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8074
e8920674
DK
8075/**
8076 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8077 *
e8920674 8078 * @bp: driver handle
72fd0718
VZ
8079 */
8080static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
8081{
8082 /* special handling for emulation and FPGA,
8083 wait 10 times longer */
8084 if (CHIP_REV_IS_SLOW(bp))
8085 msleep(MCP_ONE_TIMEOUT*10);
8086 else
8087 msleep(MCP_ONE_TIMEOUT);
8088}
8089
1b6e2ceb
DK
8090/*
8091 * initializes bp->common.shmem_base and waits for validity signature to appear
8092 */
8093static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8094{
1b6e2ceb
DK
8095 int cnt = 0;
8096 u32 val = 0;
72fd0718 8097
1b6e2ceb
DK
8098 do {
8099 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8100 if (bp->common.shmem_base) {
8101 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8102 if (val & SHR_MEM_VALIDITY_MB)
8103 return 0;
8104 }
72fd0718 8105
1b6e2ceb 8106 bnx2x_mcp_wait_one(bp);
72fd0718 8107
1b6e2ceb 8108 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8109
1b6e2ceb 8110 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8111
1b6e2ceb
DK
8112 return -ENODEV;
8113}
72fd0718 8114
1b6e2ceb
DK
8115static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8116{
8117 int rc = bnx2x_init_shmem(bp);
72fd0718 8118
72fd0718
VZ
8119 /* Restore the `magic' bit value */
8120 if (!CHIP_IS_E1(bp))
8121 bnx2x_clp_reset_done(bp, magic_val);
8122
8123 return rc;
8124}
8125
8126static void bnx2x_pxp_prep(struct bnx2x *bp)
8127{
8128 if (!CHIP_IS_E1(bp)) {
8129 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8130 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8131 mmiowb();
8132 }
8133}
8134
8135/*
8136 * Reset the whole chip except for:
8137 * - PCIE core
8138 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8139 * one reset bit)
8140 * - IGU
8141 * - MISC (including AEU)
8142 * - GRC
8143 * - RBCN, RBCP
8144 */
c9ee9206 8145static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8146{
8147 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8148 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8149
8150 /*
8151 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8152 * (per chip) blocks.
8153 */
8154 global_bits2 =
8155 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8156 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 8157
8736c826 8158 /* Don't reset the following blocks */
72fd0718
VZ
8159 not_reset_mask1 =
8160 MISC_REGISTERS_RESET_REG_1_RST_HC |
8161 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8162 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8163
8164 not_reset_mask2 =
c9ee9206 8165 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
8166 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8167 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8168 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8169 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8170 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8171 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
8172 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8173 MISC_REGISTERS_RESET_REG_2_RST_ATC |
8174 MISC_REGISTERS_RESET_REG_2_PGLC;
72fd0718 8175
8736c826
VZ
8176 /*
8177 * Keep the following blocks in reset:
8178 * - all xxMACs are handled by the bnx2x_link code.
8179 */
8180 stay_reset2 =
8181 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8182 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8183 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8184 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8185 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8186 MISC_REGISTERS_RESET_REG_2_UMAC1 |
8187 MISC_REGISTERS_RESET_REG_2_XMAC |
8188 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8189
8190 /* Full reset masks according to the chip */
72fd0718
VZ
8191 reset_mask1 = 0xffffffff;
8192
8193 if (CHIP_IS_E1(bp))
8194 reset_mask2 = 0xffff;
8736c826 8195 else if (CHIP_IS_E1H(bp))
72fd0718 8196 reset_mask2 = 0x1ffff;
8736c826
VZ
8197 else if (CHIP_IS_E2(bp))
8198 reset_mask2 = 0xfffff;
8199 else /* CHIP_IS_E3 */
8200 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
8201
8202 /* Don't reset global blocks unless we need to */
8203 if (!global)
8204 reset_mask2 &= ~global_bits2;
8205
8206 /*
8207 * In case of attention in the QM, we need to reset PXP
8208 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8209 * because otherwise QM reset would release 'close the gates' shortly
8210 * before resetting the PXP, then the PSWRQ would send a write
8211 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8212 * read the payload data from PSWWR, but PSWWR would not
8213 * respond. The write queue in PGLUE would stuck, dmae commands
8214 * would not return. Therefore it's important to reset the second
8215 * reset register (containing the
8216 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8217 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8218 * bit).
8219 */
72fd0718
VZ
8220 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8221 reset_mask2 & (~not_reset_mask2));
8222
c9ee9206
VZ
8223 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8224 reset_mask1 & (~not_reset_mask1));
8225
72fd0718
VZ
8226 barrier();
8227 mmiowb();
8228
8736c826
VZ
8229 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8230 reset_mask2 & (~stay_reset2));
8231
8232 barrier();
8233 mmiowb();
8234
c9ee9206 8235 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
8236 mmiowb();
8237}
8238
c9ee9206
VZ
8239/**
8240 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8241 * It should get cleared in no more than 1s.
8242 *
8243 * @bp: driver handle
8244 *
8245 * It should get cleared in no more than 1s. Returns 0 if
8246 * pending writes bit gets cleared.
8247 */
8248static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8249{
8250 u32 cnt = 1000;
8251 u32 pend_bits = 0;
8252
8253 do {
8254 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8255
8256 if (pend_bits == 0)
8257 break;
8258
8259 usleep_range(1000, 1000);
8260 } while (cnt-- > 0);
8261
8262 if (cnt <= 0) {
8263 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8264 pend_bits);
8265 return -EBUSY;
8266 }
8267
8268 return 0;
8269}
8270
8271static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
8272{
8273 int cnt = 1000;
8274 u32 val = 0;
8275 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8276
8277
8278 /* Empty the Tetris buffer, wait for 1s */
8279 do {
8280 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8281 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8282 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8283 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8284 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8285 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8286 ((port_is_idle_0 & 0x1) == 0x1) &&
8287 ((port_is_idle_1 & 0x1) == 0x1) &&
8288 (pgl_exp_rom2 == 0xffffffff))
8289 break;
c9ee9206 8290 usleep_range(1000, 1000);
72fd0718
VZ
8291 } while (cnt-- > 0);
8292
8293 if (cnt <= 0) {
51c1a580
MS
8294 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8295 BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
72fd0718
VZ
8296 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8297 pgl_exp_rom2);
8298 return -EAGAIN;
8299 }
8300
8301 barrier();
8302
8303 /* Close gates #2, #3 and #4 */
8304 bnx2x_set_234_gates(bp, true);
8305
c9ee9206
VZ
8306 /* Poll for IGU VQs for 57712 and newer chips */
8307 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8308 return -EAGAIN;
8309
8310
72fd0718
VZ
8311 /* TBD: Indicate that "process kill" is in progress to MCP */
8312
8313 /* Clear "unprepared" bit */
8314 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8315 barrier();
8316
8317 /* Make sure all is written to the chip before the reset */
8318 mmiowb();
8319
8320 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8321 * PSWHST, GRC and PSWRD Tetris buffer.
8322 */
c9ee9206 8323 usleep_range(1000, 1000);
72fd0718
VZ
8324
8325 /* Prepare to chip reset: */
8326 /* MCP */
c9ee9206
VZ
8327 if (global)
8328 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
8329
8330 /* PXP */
8331 bnx2x_pxp_prep(bp);
8332 barrier();
8333
8334 /* reset the chip */
c9ee9206 8335 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
8336 barrier();
8337
8338 /* Recover after reset: */
8339 /* MCP */
c9ee9206 8340 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
8341 return -EAGAIN;
8342
c9ee9206
VZ
8343 /* TBD: Add resetting the NO_MCP mode DB here */
8344
72fd0718
VZ
8345 /* PXP */
8346 bnx2x_pxp_prep(bp);
8347
8348 /* Open the gates #2, #3 and #4 */
8349 bnx2x_set_234_gates(bp, false);
8350
8351 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
8352 * reset state, re-enable attentions. */
8353
a2fbb9ea
ET
8354 return 0;
8355}
8356
c9ee9206 8357int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
8358{
8359 int rc = 0;
c9ee9206 8360 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
8361 u32 load_code;
8362
8363 /* if not going to reset MCP - load "fake" driver to reset HW while
8364 * driver is owner of the HW
8365 */
8366 if (!global && !BP_NOMCP(bp)) {
8367 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
8368 if (!load_code) {
8369 BNX2X_ERR("MCP response failure, aborting\n");
8370 rc = -EAGAIN;
8371 goto exit_leader_reset;
8372 }
8373 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
8374 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
8375 BNX2X_ERR("MCP unexpected resp, aborting\n");
8376 rc = -EAGAIN;
8377 goto exit_leader_reset2;
8378 }
8379 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
8380 if (!load_code) {
8381 BNX2X_ERR("MCP response failure, aborting\n");
8382 rc = -EAGAIN;
8383 goto exit_leader_reset2;
8384 }
8385 }
c9ee9206 8386
72fd0718 8387 /* Try to recover after the failure */
c9ee9206 8388 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
8389 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
8390 BP_PATH(bp));
72fd0718 8391 rc = -EAGAIN;
95c6c616 8392 goto exit_leader_reset2;
72fd0718
VZ
8393 }
8394
c9ee9206
VZ
8395 /*
8396 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
8397 * state.
8398 */
72fd0718 8399 bnx2x_set_reset_done(bp);
c9ee9206
VZ
8400 if (global)
8401 bnx2x_clear_reset_global(bp);
72fd0718 8402
95c6c616
AE
8403exit_leader_reset2:
8404 /* unload "fake driver" if it was loaded */
8405 if (!global && !BP_NOMCP(bp)) {
8406 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
8407 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8408 }
72fd0718
VZ
8409exit_leader_reset:
8410 bp->is_leader = 0;
c9ee9206
VZ
8411 bnx2x_release_leader_lock(bp);
8412 smp_mb();
72fd0718
VZ
8413 return rc;
8414}
8415
c9ee9206
VZ
8416static inline void bnx2x_recovery_failed(struct bnx2x *bp)
8417{
8418 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
8419
8420 /* Disconnect this device */
8421 netif_device_detach(bp->dev);
8422
8423 /*
8424 * Block ifup for all function on this engine until "process kill"
8425 * or power cycle.
8426 */
8427 bnx2x_set_reset_in_progress(bp);
8428
8429 /* Shut down the power */
8430 bnx2x_set_power_state(bp, PCI_D3hot);
8431
8432 bp->recovery_state = BNX2X_RECOVERY_FAILED;
8433
8434 smp_mb();
8435}
8436
8437/*
8438 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 8439 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
8440 * will never be called when netif_running(bp->dev) is false.
8441 */
8442static void bnx2x_parity_recover(struct bnx2x *bp)
8443{
c9ee9206 8444 bool global = false;
7a752993 8445 u32 error_recovered, error_unrecovered;
95c6c616 8446 bool is_parity;
c9ee9206 8447
72fd0718
VZ
8448 DP(NETIF_MSG_HW, "Handling parity\n");
8449 while (1) {
8450 switch (bp->recovery_state) {
8451 case BNX2X_RECOVERY_INIT:
8452 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
8453 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
8454 WARN_ON(!is_parity);
c9ee9206 8455
72fd0718 8456 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
8457 if (bnx2x_trylock_leader_lock(bp)) {
8458 bnx2x_set_reset_in_progress(bp);
8459 /*
8460 * Check if there is a global attention and if
8461 * there was a global attention, set the global
8462 * reset bit.
8463 */
8464
8465 if (global)
8466 bnx2x_set_reset_global(bp);
8467
72fd0718 8468 bp->is_leader = 1;
c9ee9206 8469 }
72fd0718
VZ
8470
8471 /* Stop the driver */
8472 /* If interface has been removed - break */
8473 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
8474 return;
8475
8476 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 8477
c9ee9206
VZ
8478 /* Ensure "is_leader", MCP command sequence and
8479 * "recovery_state" update values are seen on other
8480 * CPUs.
72fd0718 8481 */
c9ee9206 8482 smp_mb();
72fd0718
VZ
8483 break;
8484
8485 case BNX2X_RECOVERY_WAIT:
8486 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
8487 if (bp->is_leader) {
c9ee9206 8488 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
8489 bool other_load_status =
8490 bnx2x_get_load_status(bp, other_engine);
8491 bool load_status =
8492 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
8493 global = bnx2x_reset_is_global(bp);
8494
8495 /*
8496 * In case of a parity in a global block, let
8497 * the first leader that performs a
8498 * leader_reset() reset the global blocks in
8499 * order to clear global attentions. Otherwise
8500 * the the gates will remain closed for that
8501 * engine.
8502 */
889b9af3
AE
8503 if (load_status ||
8504 (global && other_load_status)) {
72fd0718
VZ
8505 /* Wait until all other functions get
8506 * down.
8507 */
7be08a72 8508 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
8509 HZ/10);
8510 return;
8511 } else {
8512 /* If all other functions got down -
8513 * try to bring the chip back to
8514 * normal. In any case it's an exit
8515 * point for a leader.
8516 */
c9ee9206
VZ
8517 if (bnx2x_leader_reset(bp)) {
8518 bnx2x_recovery_failed(bp);
72fd0718
VZ
8519 return;
8520 }
8521
c9ee9206
VZ
8522 /* If we are here, means that the
8523 * leader has succeeded and doesn't
8524 * want to be a leader any more. Try
8525 * to continue as a none-leader.
8526 */
8527 break;
72fd0718
VZ
8528 }
8529 } else { /* non-leader */
c9ee9206 8530 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
8531 /* Try to get a LEADER_LOCK HW lock as
8532 * long as a former leader may have
8533 * been unloaded by the user or
8534 * released a leadership by another
8535 * reason.
8536 */
c9ee9206 8537 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
8538 /* I'm a leader now! Restart a
8539 * switch case.
8540 */
8541 bp->is_leader = 1;
8542 break;
8543 }
8544
7be08a72 8545 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
8546 HZ/10);
8547 return;
8548
c9ee9206
VZ
8549 } else {
8550 /*
8551 * If there was a global attention, wait
8552 * for it to be cleared.
8553 */
8554 if (bnx2x_reset_is_global(bp)) {
8555 schedule_delayed_work(
7be08a72
AE
8556 &bp->sp_rtnl_task,
8557 HZ/10);
c9ee9206
VZ
8558 return;
8559 }
8560
7a752993
AE
8561 error_recovered =
8562 bp->eth_stats.recoverable_error;
8563 error_unrecovered =
8564 bp->eth_stats.unrecoverable_error;
95c6c616
AE
8565 bp->recovery_state =
8566 BNX2X_RECOVERY_NIC_LOADING;
8567 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 8568 error_unrecovered++;
95c6c616 8569 netdev_err(bp->dev,
51c1a580 8570 "Recovery failed. Power cycle needed\n");
95c6c616
AE
8571 /* Disconnect this device */
8572 netif_device_detach(bp->dev);
8573 /* Shut down the power */
8574 bnx2x_set_power_state(
8575 bp, PCI_D3hot);
8576 smp_mb();
8577 } else {
c9ee9206
VZ
8578 bp->recovery_state =
8579 BNX2X_RECOVERY_DONE;
7a752993 8580 error_recovered++;
c9ee9206
VZ
8581 smp_mb();
8582 }
7a752993
AE
8583 bp->eth_stats.recoverable_error =
8584 error_recovered;
8585 bp->eth_stats.unrecoverable_error =
8586 error_unrecovered;
c9ee9206 8587
72fd0718
VZ
8588 return;
8589 }
8590 }
8591 default:
8592 return;
8593 }
8594 }
8595}
8596
56ad3152
MS
8597static int bnx2x_close(struct net_device *dev);
8598
72fd0718
VZ
8599/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
8600 * scheduled on a general queue in order to prevent a dead lock.
8601 */
7be08a72 8602static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 8603{
7be08a72 8604 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
8605
8606 rtnl_lock();
8607
8608 if (!netif_running(bp->dev))
7be08a72
AE
8609 goto sp_rtnl_exit;
8610
8611 /* if stop on error is defined no recovery flows should be executed */
8612#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8613 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 8614 "you will need to reboot when done\n");
b1fb8740 8615 goto sp_rtnl_not_reset;
7be08a72 8616#endif
34f80b04 8617
7be08a72
AE
8618 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
8619 /*
b1fb8740
VZ
8620 * Clear all pending SP commands as we are going to reset the
8621 * function anyway.
7be08a72 8622 */
b1fb8740
VZ
8623 bp->sp_rtnl_state = 0;
8624 smp_mb();
8625
72fd0718 8626 bnx2x_parity_recover(bp);
b1fb8740
VZ
8627
8628 goto sp_rtnl_exit;
8629 }
8630
8631 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
8632 /*
8633 * Clear all pending SP commands as we are going to reset the
8634 * function anyway.
8635 */
8636 bp->sp_rtnl_state = 0;
8637 smp_mb();
8638
72fd0718
VZ
8639 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8640 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740
VZ
8641
8642 goto sp_rtnl_exit;
72fd0718 8643 }
b1fb8740
VZ
8644#ifdef BNX2X_STOP_ON_ERROR
8645sp_rtnl_not_reset:
8646#endif
8647 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
8648 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
34f80b04 8649
8304859a
AE
8650 /*
8651 * in case of fan failure we need to reset id if the "stop on error"
8652 * debug flag is set, since we trying to prevent permanent overheating
8653 * damage
8654 */
8655 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 8656 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
8657 netif_device_detach(bp->dev);
8658 bnx2x_close(bp->dev);
8659 }
8660
7be08a72 8661sp_rtnl_exit:
34f80b04
EG
8662 rtnl_unlock();
8663}
8664
a2fbb9ea
ET
8665/* end of nic load/unload */
8666
3deb8167
YR
8667static void bnx2x_period_task(struct work_struct *work)
8668{
8669 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
8670
8671 if (!netif_running(bp->dev))
8672 goto period_task_exit;
8673
8674 if (CHIP_REV_IS_SLOW(bp)) {
8675 BNX2X_ERR("period task called on emulation, ignoring\n");
8676 goto period_task_exit;
8677 }
8678
8679 bnx2x_acquire_phy_lock(bp);
8680 /*
8681 * The barrier is needed to ensure the ordering between the writing to
8682 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
8683 * the reading here.
8684 */
8685 smp_mb();
8686 if (bp->port.pmf) {
8687 bnx2x_period_func(&bp->link_params, &bp->link_vars);
8688
8689 /* Re-queue task in 1 sec */
8690 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
8691 }
8692
8693 bnx2x_release_phy_lock(bp);
8694period_task_exit:
8695 return;
8696}
8697
a2fbb9ea
ET
8698/*
8699 * Init service functions
8700 */
8701
8d96286a 8702static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
8703{
8704 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8705 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8706 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
8707}
8708
f2e0899f 8709static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
f1ef27ef 8710{
f2e0899f 8711 u32 reg = bnx2x_get_pretend_reg(bp);
f1ef27ef
EG
8712
8713 /* Flush all outstanding writes */
8714 mmiowb();
8715
8716 /* Pretend to be function 0 */
8717 REG_WR(bp, reg, 0);
f2e0899f 8718 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
f1ef27ef
EG
8719
8720 /* From now we are in the "like-E1" mode */
8721 bnx2x_int_disable(bp);
8722
8723 /* Flush all outstanding writes */
8724 mmiowb();
8725
f2e0899f
DK
8726 /* Restore the original function */
8727 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8728 REG_RD(bp, reg);
f1ef27ef
EG
8729}
8730
f2e0899f 8731static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
f1ef27ef 8732{
f2e0899f 8733 if (CHIP_IS_E1(bp))
f1ef27ef 8734 bnx2x_int_disable(bp);
f2e0899f
DK
8735 else
8736 bnx2x_undi_int_disable_e1h(bp);
f1ef27ef
EG
8737}
8738
452427b0 8739static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
34f80b04 8740{
452427b0
YM
8741 u32 val, base_addr, offset, mask, reset_reg;
8742 bool mac_stopped = false;
8743 u8 port = BP_PORT(bp);
34f80b04 8744
452427b0 8745 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 8746
452427b0
YM
8747 if (!CHIP_IS_E3(bp)) {
8748 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
8749 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
8750 if ((mask & reset_reg) && val) {
8751 u32 wb_data[2];
8752 BNX2X_DEV_INFO("Disable bmac Rx\n");
8753 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
8754 : NIG_REG_INGRESS_BMAC0_MEM;
8755 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
8756 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 8757
452427b0
YM
8758 /*
8759 * use rd/wr since we cannot use dmae. This is safe
8760 * since MCP won't access the bus due to the request
8761 * to unload, and no function on the path can be
8762 * loaded at this time.
8763 */
8764 wb_data[0] = REG_RD(bp, base_addr + offset);
8765 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
8766 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
8767 REG_WR(bp, base_addr + offset, wb_data[0]);
8768 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
8769
8770 }
8771 BNX2X_DEV_INFO("Disable emac Rx\n");
8772 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
8773
8774 mac_stopped = true;
8775 } else {
8776 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
8777 BNX2X_DEV_INFO("Disable xmac Rx\n");
8778 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
8779 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
8780 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8781 val & ~(1 << 1));
8782 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8783 val | (1 << 1));
8784 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
8785 mac_stopped = true;
8786 }
8787 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
8788 if (mask & reset_reg) {
8789 BNX2X_DEV_INFO("Disable umac Rx\n");
8790 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
8791 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
8792 mac_stopped = true;
8793 }
8794 }
8795
8796 if (mac_stopped)
8797 msleep(20);
8798
8799}
8800
8801#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
8802#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
8803#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
8804#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
8805
8806static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
8807 u8 inc)
8808{
8809 u16 rcq, bd;
8810 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
8811
8812 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
8813 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
8814
8815 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
8816 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
8817
8818 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
8819 port, bd, rcq);
8820}
8821
8822static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
8823{
8824 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8825 if (!rc) {
8826 BNX2X_ERR("MCP response failure, aborting\n");
8827 return -EBUSY;
8828 }
8829
8830 return 0;
8831}
8832
8833static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
8834{
8835 struct bnx2x_prev_path_list *tmp_list;
8836 int rc = false;
8837
8838 if (down_trylock(&bnx2x_prev_sem))
8839 return false;
8840
8841 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
8842 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
8843 bp->pdev->bus->number == tmp_list->bus &&
8844 BP_PATH(bp) == tmp_list->path) {
8845 rc = true;
8846 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
8847 BP_PATH(bp));
8848 break;
8849 }
8850 }
8851
8852 up(&bnx2x_prev_sem);
8853
8854 return rc;
8855}
8856
8857static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
8858{
8859 struct bnx2x_prev_path_list *tmp_list;
8860 int rc;
8861
8862 tmp_list = (struct bnx2x_prev_path_list *)
8863 kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
8864 if (!tmp_list) {
8865 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
8866 return -ENOMEM;
8867 }
8868
8869 tmp_list->bus = bp->pdev->bus->number;
8870 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
8871 tmp_list->path = BP_PATH(bp);
8872
8873 rc = down_interruptible(&bnx2x_prev_sem);
8874 if (rc) {
8875 BNX2X_ERR("Received %d when tried to take lock\n", rc);
8876 kfree(tmp_list);
8877 } else {
8878 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
8879 BP_PATH(bp));
8880 list_add(&tmp_list->list, &bnx2x_prev_list);
8881 up(&bnx2x_prev_sem);
8882 }
8883
8884 return rc;
8885}
8886
8887static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
8888{
8889 int pos;
8890 u32 cap;
8891 struct pci_dev *dev = bp->pdev;
8892
8893 pos = pci_pcie_cap(dev);
8894 if (!pos)
8895 return false;
8896
8897 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
8898 if (!(cap & PCI_EXP_DEVCAP_FLR))
8899 return false;
8900
8901 return true;
8902}
8903
8904static int __devinit bnx2x_do_flr(struct bnx2x *bp)
8905{
8906 int i, pos;
8907 u16 status;
8908 struct pci_dev *dev = bp->pdev;
8909
8910 /* probe the capability first */
8911 if (bnx2x_can_flr(bp))
8912 return -ENOTTY;
8913
8914 pos = pci_pcie_cap(dev);
8915 if (!pos)
8916 return -ENOTTY;
8917
8918 /* Wait for Transaction Pending bit clean */
8919 for (i = 0; i < 4; i++) {
8920 if (i)
8921 msleep((1 << (i - 1)) * 100);
8922
8923 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
8924 if (!(status & PCI_EXP_DEVSTA_TRPND))
8925 goto clear;
8926 }
8927
8928 dev_err(&dev->dev,
8929 "transaction is not cleared; proceeding with reset anyway\n");
8930
8931clear:
8932 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
8933 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
8934 bp->common.bc_ver);
8935 return -EINVAL;
8936 }
8937
8938 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
8939
8940 return 0;
8941}
8942
8943static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
8944{
8945 int rc;
8946
8947 BNX2X_DEV_INFO("Uncommon unload Flow\n");
8948
8949 /* Test if previous unload process was already finished for this path */
8950 if (bnx2x_prev_is_path_marked(bp))
8951 return bnx2x_prev_mcp_done(bp);
8952
8953 /* If function has FLR capabilities, and existing FW version matches
8954 * the one required, then FLR will be sufficient to clean any residue
8955 * left by previous driver
8956 */
8957 if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
8958 return bnx2x_do_flr(bp);
8959
8960 /* Close the MCP request, return failure*/
8961 rc = bnx2x_prev_mcp_done(bp);
8962 if (!rc)
8963 rc = BNX2X_PREV_WAIT_NEEDED;
8964
8965 return rc;
8966}
8967
8968static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
8969{
8970 u32 reset_reg, tmp_reg = 0, rc;
8971 /* It is possible a previous function received 'common' answer,
8972 * but hasn't loaded yet, therefore creating a scenario of
8973 * multiple functions receiving 'common' on the same path.
8974 */
8975 BNX2X_DEV_INFO("Common unload Flow\n");
8976
8977 if (bnx2x_prev_is_path_marked(bp))
8978 return bnx2x_prev_mcp_done(bp);
8979
8980 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
8981
8982 /* Reset should be performed after BRB is emptied */
8983 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
8984 u32 timer_count = 1000;
8985 bool prev_undi = false;
8986
8987 /* Close the MAC Rx to prevent BRB from filling up */
8988 bnx2x_prev_unload_close_mac(bp);
8989
8990 /* Check if the UNDI driver was previously loaded
34f80b04
EG
8991 * UNDI driver initializes CID offset for normal bell to 0x7
8992 */
452427b0
YM
8993 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
8994 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
8995 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8996 if (tmp_reg == 0x7) {
8997 BNX2X_DEV_INFO("UNDI previously loaded\n");
8998 prev_undi = true;
8999 /* clear the UNDI indication */
9000 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
34f80b04 9001 }
452427b0
YM
9002 }
9003 /* wait until BRB is empty */
9004 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9005 while (timer_count) {
9006 u32 prev_brb = tmp_reg;
34f80b04 9007
452427b0
YM
9008 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9009 if (!tmp_reg)
9010 break;
619c5cb6 9011
452427b0 9012 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9013
452427b0
YM
9014 /* reset timer as long as BRB actually gets emptied */
9015 if (prev_brb > tmp_reg)
9016 timer_count = 1000;
9017 else
9018 timer_count--;
da5a662a 9019
452427b0
YM
9020 /* If UNDI resides in memory, manually increment it */
9021 if (prev_undi)
9022 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9023
452427b0 9024 udelay(10);
7a06a122 9025 }
452427b0
YM
9026
9027 if (!timer_count)
9028 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9029
34f80b04 9030 }
f16da43b 9031
452427b0
YM
9032 /* No packets are in the pipeline, path is ready for reset */
9033 bnx2x_reset_common(bp);
9034
9035 rc = bnx2x_prev_mark_path(bp);
9036 if (rc) {
9037 bnx2x_prev_mcp_done(bp);
9038 return rc;
9039 }
9040
9041 return bnx2x_prev_mcp_done(bp);
9042}
9043
9044static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9045{
9046 int time_counter = 10;
9047 u32 rc, fw, hw_lock_reg, hw_lock_val;
9048 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9049
9050 /* Release previously held locks */
9051 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9052 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9053 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9054
9055 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9056 if (hw_lock_val) {
9057 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9058 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9059 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9060 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9061 }
9062
9063 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9064 REG_WR(bp, hw_lock_reg, 0xffffffff);
9065 } else
9066 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9067
9068 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9069 BNX2X_DEV_INFO("Release previously held alr\n");
9070 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9071 }
9072
9073
9074 do {
9075 /* Lock MCP using an unload request */
9076 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9077 if (!fw) {
9078 BNX2X_ERR("MCP response failure, aborting\n");
9079 rc = -EBUSY;
9080 break;
9081 }
9082
9083 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9084 rc = bnx2x_prev_unload_common(bp);
9085 break;
9086 }
9087
9088 /* non-common reply from MCP night require looping */
9089 rc = bnx2x_prev_unload_uncommon(bp);
9090 if (rc != BNX2X_PREV_WAIT_NEEDED)
9091 break;
9092
9093 msleep(20);
9094 } while (--time_counter);
9095
9096 if (!time_counter || rc) {
9097 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9098 rc = -EBUSY;
9099 }
9100
9101 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9102
9103 return rc;
34f80b04
EG
9104}
9105
9106static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9107{
1d187b34 9108 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 9109 u16 pmc;
34f80b04
EG
9110
9111 /* Get the chip revision id and number. */
9112 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9113 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9114 id = ((val & 0xffff) << 16);
9115 val = REG_RD(bp, MISC_REG_CHIP_REV);
9116 id |= ((val & 0xf) << 12);
9117 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9118 id |= ((val & 0xff) << 4);
5a40e08e 9119 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
9120 id |= (val & 0xf);
9121 bp->common.chip_id = id;
523224a3
DK
9122
9123 /* Set doorbell size */
9124 bp->db_size = (1 << BNX2X_DB_SHIFT);
9125
619c5cb6 9126 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
9127 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9128 if ((val & 1) == 0)
9129 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9130 else
9131 val = (val >> 1) & 1;
9132 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9133 "2_PORT_MODE");
9134 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9135 CHIP_2_PORT_MODE;
9136
9137 if (CHIP_MODE_IS_4_PORT(bp))
9138 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9139 else
9140 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9141 } else {
9142 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9143 bp->pfid = bp->pf_num; /* 0..7 */
9144 }
9145
51c1a580
MS
9146 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9147
f2e0899f
DK
9148 bp->link_params.chip_id = bp->common.chip_id;
9149 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 9150
1c06328c
EG
9151 val = (REG_RD(bp, 0x2874) & 0x55);
9152 if ((bp->common.chip_id & 0x1) ||
9153 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9154 bp->flags |= ONE_PORT_FLAG;
9155 BNX2X_DEV_INFO("single port device\n");
9156 }
9157
34f80b04 9158 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 9159 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
9160 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9161 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9162 bp->common.flash_size, bp->common.flash_size);
9163
1b6e2ceb
DK
9164 bnx2x_init_shmem(bp);
9165
619c5cb6
VZ
9166
9167
f2e0899f
DK
9168 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9169 MISC_REG_GENERIC_CR_1 :
9170 MISC_REG_GENERIC_CR_0));
1b6e2ceb 9171
34f80b04 9172 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 9173 bp->link_params.shmem2_base = bp->common.shmem2_base;
2691d51d
EG
9174 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9175 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 9176
f2e0899f 9177 if (!bp->common.shmem_base) {
34f80b04
EG
9178 BNX2X_DEV_INFO("MCP not active\n");
9179 bp->flags |= NO_MCP_FLAG;
9180 return;
9181 }
9182
34f80b04 9183 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 9184 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
9185
9186 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9187 SHARED_HW_CFG_LED_MODE_MASK) >>
9188 SHARED_HW_CFG_LED_MODE_SHIFT);
9189
c2c8b03e
EG
9190 bp->link_params.feature_config_flags = 0;
9191 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9192 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9193 bp->link_params.feature_config_flags |=
9194 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9195 else
9196 bp->link_params.feature_config_flags &=
9197 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9198
34f80b04
EG
9199 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9200 bp->common.bc_ver = val;
9201 BNX2X_DEV_INFO("bc_ver %X\n", val);
9202 if (val < BNX2X_BC_VER) {
9203 /* for now only warn
9204 * later we might need to enforce this */
51c1a580
MS
9205 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9206 BNX2X_BC_VER, val);
34f80b04 9207 }
4d295db0 9208 bp->link_params.feature_config_flags |=
a22f0788 9209 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
9210 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9211
a22f0788
YR
9212 bp->link_params.feature_config_flags |=
9213 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9214 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
72ce58c3 9215
85242eea
YR
9216 bp->link_params.feature_config_flags |=
9217 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9218 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
0e898dd7
BW
9219 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9220 BC_SUPPORTS_PFC_STATS : 0;
85242eea 9221
1d187b34
BW
9222 boot_mode = SHMEM_RD(bp,
9223 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9224 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9225 switch (boot_mode) {
9226 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9227 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9228 break;
9229 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9230 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9231 break;
9232 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9233 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9234 break;
9235 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9236 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9237 break;
9238 }
9239
f9a3ebbe
DK
9240 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9241 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9242
72ce58c3 9243 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 9244 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
9245
9246 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9247 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9248 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9249 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9250
cdaa7cb8
VZ
9251 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9252 val, val2, val3, val4);
34f80b04
EG
9253}
9254
f2e0899f
DK
9255#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9256#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9257
9258static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9259{
9260 int pfid = BP_FUNC(bp);
f2e0899f
DK
9261 int igu_sb_id;
9262 u32 val;
6383c0b3 9263 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
9264
9265 bp->igu_base_sb = 0xff;
f2e0899f 9266 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 9267 int vn = BP_VN(bp);
6383c0b3 9268 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
9269 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9270 FP_SB_MAX_E1x;
9271
9272 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9273 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9274
9275 return;
9276 }
9277
9278 /* IGU in normal mode - read CAM */
9279 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9280 igu_sb_id++) {
9281 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
9282 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
9283 continue;
9284 fid = IGU_FID(val);
9285 if ((fid & IGU_FID_ENCODE_IS_PF)) {
9286 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
9287 continue;
9288 if (IGU_VEC(val) == 0)
9289 /* default status block */
9290 bp->igu_dsb_id = igu_sb_id;
9291 else {
9292 if (bp->igu_base_sb == 0xff)
9293 bp->igu_base_sb = igu_sb_id;
6383c0b3 9294 igu_sb_cnt++;
f2e0899f
DK
9295 }
9296 }
9297 }
619c5cb6 9298
6383c0b3
AE
9299#ifdef CONFIG_PCI_MSI
9300 /*
9301 * It's expected that number of CAM entries for this functions is equal
9302 * to the number evaluated based on the MSI-X table size. We want a
9303 * harsh warning if these values are different!
619c5cb6 9304 */
6383c0b3
AE
9305 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
9306#endif
619c5cb6 9307
6383c0b3 9308 if (igu_sb_cnt == 0)
f2e0899f
DK
9309 BNX2X_ERR("CAM configuration error\n");
9310}
9311
34f80b04
EG
9312static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
9313 u32 switch_cfg)
a2fbb9ea 9314{
a22f0788
YR
9315 int cfg_size = 0, idx, port = BP_PORT(bp);
9316
9317 /* Aggregation of supported attributes of all external phys */
9318 bp->port.supported[0] = 0;
9319 bp->port.supported[1] = 0;
b7737c9b
YR
9320 switch (bp->link_params.num_phys) {
9321 case 1:
a22f0788
YR
9322 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
9323 cfg_size = 1;
9324 break;
b7737c9b 9325 case 2:
a22f0788
YR
9326 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
9327 cfg_size = 1;
9328 break;
9329 case 3:
9330 if (bp->link_params.multi_phy_config &
9331 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
9332 bp->port.supported[1] =
9333 bp->link_params.phy[EXT_PHY1].supported;
9334 bp->port.supported[0] =
9335 bp->link_params.phy[EXT_PHY2].supported;
9336 } else {
9337 bp->port.supported[0] =
9338 bp->link_params.phy[EXT_PHY1].supported;
9339 bp->port.supported[1] =
9340 bp->link_params.phy[EXT_PHY2].supported;
9341 }
9342 cfg_size = 2;
9343 break;
b7737c9b 9344 }
a2fbb9ea 9345
a22f0788 9346 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 9347 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 9348 SHMEM_RD(bp,
a22f0788
YR
9349 dev_info.port_hw_config[port].external_phy_config),
9350 SHMEM_RD(bp,
9351 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 9352 return;
f85582f8 9353 }
a2fbb9ea 9354
619c5cb6
VZ
9355 if (CHIP_IS_E3(bp))
9356 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
9357 else {
9358 switch (switch_cfg) {
9359 case SWITCH_CFG_1G:
9360 bp->port.phy_addr = REG_RD(
9361 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
9362 break;
9363 case SWITCH_CFG_10G:
9364 bp->port.phy_addr = REG_RD(
9365 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
9366 break;
9367 default:
9368 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
9369 bp->port.link_config[0]);
9370 return;
9371 }
a2fbb9ea 9372 }
619c5cb6 9373 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
9374 /* mask what we support according to speed_cap_mask per configuration */
9375 for (idx = 0; idx < cfg_size; idx++) {
9376 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9377 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 9378 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 9379
a22f0788 9380 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9381 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 9382 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 9383
a22f0788 9384 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9385 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 9386 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 9387
a22f0788 9388 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9389 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 9390 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 9391
a22f0788 9392 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9393 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 9394 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 9395 SUPPORTED_1000baseT_Full);
a2fbb9ea 9396
a22f0788 9397 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9398 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 9399 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 9400
a22f0788 9401 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 9402 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
9403 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
9404
9405 }
a2fbb9ea 9406
a22f0788
YR
9407 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
9408 bp->port.supported[1]);
a2fbb9ea
ET
9409}
9410
34f80b04 9411static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 9412{
a22f0788
YR
9413 u32 link_config, idx, cfg_size = 0;
9414 bp->port.advertising[0] = 0;
9415 bp->port.advertising[1] = 0;
9416 switch (bp->link_params.num_phys) {
9417 case 1:
9418 case 2:
9419 cfg_size = 1;
9420 break;
9421 case 3:
9422 cfg_size = 2;
9423 break;
9424 }
9425 for (idx = 0; idx < cfg_size; idx++) {
9426 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
9427 link_config = bp->port.link_config[idx];
9428 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 9429 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
9430 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
9431 bp->link_params.req_line_speed[idx] =
9432 SPEED_AUTO_NEG;
9433 bp->port.advertising[idx] |=
9434 bp->port.supported[idx];
10bd1f24
MY
9435 if (bp->link_params.phy[EXT_PHY1].type ==
9436 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9437 bp->port.advertising[idx] |=
9438 (SUPPORTED_100baseT_Half |
9439 SUPPORTED_100baseT_Full);
f85582f8
DK
9440 } else {
9441 /* force 10G, no AN */
a22f0788
YR
9442 bp->link_params.req_line_speed[idx] =
9443 SPEED_10000;
9444 bp->port.advertising[idx] |=
9445 (ADVERTISED_10000baseT_Full |
f85582f8 9446 ADVERTISED_FIBRE);
a22f0788 9447 continue;
f85582f8
DK
9448 }
9449 break;
a2fbb9ea 9450
f85582f8 9451 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
9452 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
9453 bp->link_params.req_line_speed[idx] =
9454 SPEED_10;
9455 bp->port.advertising[idx] |=
9456 (ADVERTISED_10baseT_Full |
f85582f8
DK
9457 ADVERTISED_TP);
9458 } else {
51c1a580 9459 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 9460 link_config,
a22f0788 9461 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
9462 return;
9463 }
9464 break;
a2fbb9ea 9465
f85582f8 9466 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
9467 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
9468 bp->link_params.req_line_speed[idx] =
9469 SPEED_10;
9470 bp->link_params.req_duplex[idx] =
9471 DUPLEX_HALF;
9472 bp->port.advertising[idx] |=
9473 (ADVERTISED_10baseT_Half |
f85582f8
DK
9474 ADVERTISED_TP);
9475 } else {
51c1a580 9476 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
9477 link_config,
9478 bp->link_params.speed_cap_mask[idx]);
9479 return;
9480 }
9481 break;
a2fbb9ea 9482
f85582f8
DK
9483 case PORT_FEATURE_LINK_SPEED_100M_FULL:
9484 if (bp->port.supported[idx] &
9485 SUPPORTED_100baseT_Full) {
a22f0788
YR
9486 bp->link_params.req_line_speed[idx] =
9487 SPEED_100;
9488 bp->port.advertising[idx] |=
9489 (ADVERTISED_100baseT_Full |
f85582f8
DK
9490 ADVERTISED_TP);
9491 } else {
51c1a580 9492 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
9493 link_config,
9494 bp->link_params.speed_cap_mask[idx]);
9495 return;
9496 }
9497 break;
a2fbb9ea 9498
f85582f8
DK
9499 case PORT_FEATURE_LINK_SPEED_100M_HALF:
9500 if (bp->port.supported[idx] &
9501 SUPPORTED_100baseT_Half) {
9502 bp->link_params.req_line_speed[idx] =
9503 SPEED_100;
9504 bp->link_params.req_duplex[idx] =
9505 DUPLEX_HALF;
a22f0788
YR
9506 bp->port.advertising[idx] |=
9507 (ADVERTISED_100baseT_Half |
f85582f8
DK
9508 ADVERTISED_TP);
9509 } else {
51c1a580 9510 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
9511 link_config,
9512 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
9513 return;
9514 }
9515 break;
a2fbb9ea 9516
f85582f8 9517 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
9518 if (bp->port.supported[idx] &
9519 SUPPORTED_1000baseT_Full) {
9520 bp->link_params.req_line_speed[idx] =
9521 SPEED_1000;
9522 bp->port.advertising[idx] |=
9523 (ADVERTISED_1000baseT_Full |
f85582f8
DK
9524 ADVERTISED_TP);
9525 } else {
51c1a580 9526 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
9527 link_config,
9528 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
9529 return;
9530 }
9531 break;
a2fbb9ea 9532
f85582f8 9533 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
9534 if (bp->port.supported[idx] &
9535 SUPPORTED_2500baseX_Full) {
9536 bp->link_params.req_line_speed[idx] =
9537 SPEED_2500;
9538 bp->port.advertising[idx] |=
9539 (ADVERTISED_2500baseX_Full |
34f80b04 9540 ADVERTISED_TP);
f85582f8 9541 } else {
51c1a580 9542 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 9543 link_config,
f85582f8
DK
9544 bp->link_params.speed_cap_mask[idx]);
9545 return;
9546 }
9547 break;
a2fbb9ea 9548
f85582f8 9549 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
9550 if (bp->port.supported[idx] &
9551 SUPPORTED_10000baseT_Full) {
9552 bp->link_params.req_line_speed[idx] =
9553 SPEED_10000;
9554 bp->port.advertising[idx] |=
9555 (ADVERTISED_10000baseT_Full |
34f80b04 9556 ADVERTISED_FIBRE);
f85582f8 9557 } else {
51c1a580 9558 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 9559 link_config,
f85582f8
DK
9560 bp->link_params.speed_cap_mask[idx]);
9561 return;
9562 }
9563 break;
3c9ada22
YR
9564 case PORT_FEATURE_LINK_SPEED_20G:
9565 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 9566
3c9ada22 9567 break;
f85582f8 9568 default:
51c1a580 9569 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 9570 link_config);
f85582f8
DK
9571 bp->link_params.req_line_speed[idx] =
9572 SPEED_AUTO_NEG;
9573 bp->port.advertising[idx] =
9574 bp->port.supported[idx];
9575 break;
9576 }
a2fbb9ea 9577
a22f0788 9578 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 9579 PORT_FEATURE_FLOW_CONTROL_MASK);
a22f0788
YR
9580 if ((bp->link_params.req_flow_ctrl[idx] ==
9581 BNX2X_FLOW_CTRL_AUTO) &&
9582 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
9583 bp->link_params.req_flow_ctrl[idx] =
9584 BNX2X_FLOW_CTRL_NONE;
9585 }
a2fbb9ea 9586
51c1a580 9587 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
9588 bp->link_params.req_line_speed[idx],
9589 bp->link_params.req_duplex[idx],
9590 bp->link_params.req_flow_ctrl[idx],
9591 bp->port.advertising[idx]);
9592 }
a2fbb9ea
ET
9593}
9594
e665bfda
MC
9595static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
9596{
9597 mac_hi = cpu_to_be16(mac_hi);
9598 mac_lo = cpu_to_be32(mac_lo);
9599 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
9600 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
9601}
9602
34f80b04 9603static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 9604{
34f80b04 9605 int port = BP_PORT(bp);
589abe3a 9606 u32 config;
6f38ad93 9607 u32 ext_phy_type, ext_phy_config;
a2fbb9ea 9608
c18487ee 9609 bp->link_params.bp = bp;
34f80b04 9610 bp->link_params.port = port;
c18487ee 9611
c18487ee 9612 bp->link_params.lane_config =
a2fbb9ea 9613 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 9614
a22f0788 9615 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
9616 SHMEM_RD(bp,
9617 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
9618 bp->link_params.speed_cap_mask[1] =
9619 SHMEM_RD(bp,
9620 dev_info.port_hw_config[port].speed_capability_mask2);
9621 bp->port.link_config[0] =
a2fbb9ea
ET
9622 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
9623
a22f0788
YR
9624 bp->port.link_config[1] =
9625 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 9626
a22f0788
YR
9627 bp->link_params.multi_phy_config =
9628 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
9629 /* If the device is capable of WoL, set the default state according
9630 * to the HW
9631 */
4d295db0 9632 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
9633 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
9634 (config & PORT_FEATURE_WOL_ENABLED));
9635
51c1a580 9636 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 9637 bp->link_params.lane_config,
a22f0788
YR
9638 bp->link_params.speed_cap_mask[0],
9639 bp->port.link_config[0]);
a2fbb9ea 9640
a22f0788 9641 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 9642 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 9643 bnx2x_phy_probe(&bp->link_params);
c18487ee 9644 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
9645
9646 bnx2x_link_settings_requested(bp);
9647
01cd4528
EG
9648 /*
9649 * If connected directly, work with the internal PHY, otherwise, work
9650 * with the external PHY
9651 */
b7737c9b
YR
9652 ext_phy_config =
9653 SHMEM_RD(bp,
9654 dev_info.port_hw_config[port].external_phy_config);
9655 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 9656 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 9657 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
9658
9659 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
9660 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
9661 bp->mdio.prtad =
b7737c9b 9662 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d
YR
9663
9664 /*
9665 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
9666 * In MF mode, it is set to cover self test cases
9667 */
9668 if (IS_MF(bp))
9669 bp->port.need_hw_lock = 1;
9670 else
9671 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
9672 bp->common.shmem_base,
9673 bp->common.shmem2_base);
0793f83f 9674}
01cd4528 9675
b306f5ed 9676void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 9677{
9e62e912 9678 u32 no_flags = NO_ISCSI_FLAG;
7185bb33 9679#ifdef BCM_CNIC
bf61ee14 9680 int port = BP_PORT(bp);
bf61ee14 9681
2ba45142 9682 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 9683 drv_lic_key[port].max_iscsi_conn);
2ba45142 9684
b306f5ed 9685 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
9686 bp->cnic_eth_dev.max_iscsi_conn =
9687 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
9688 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
9689
b306f5ed
DK
9690 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
9691 bp->cnic_eth_dev.max_iscsi_conn);
9692
9693 /*
9694 * If maximum allowed number of connections is zero -
9695 * disable the feature.
9696 */
9697 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 9698 bp->flags |= no_flags;
7185bb33 9699#else
9e62e912 9700 bp->flags |= no_flags;
7185bb33 9701#endif
b306f5ed
DK
9702}
9703
9e62e912
DK
9704#ifdef BCM_CNIC
9705static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9706{
9707 /* Port info */
9708 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9709 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
9710 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9711 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
9712
9713 /* Node info */
9714 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9715 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
9716 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9717 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
9718}
9719#endif
b306f5ed
DK
9720static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
9721{
7185bb33 9722#ifdef BCM_CNIC
b306f5ed
DK
9723 int port = BP_PORT(bp);
9724 int func = BP_ABS_FUNC(bp);
9725
9726 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9727 drv_lic_key[port].max_fcoe_conn);
9728
9729 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
9730 bp->cnic_eth_dev.max_fcoe_conn =
9731 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
9732 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
9733
bf61ee14
VZ
9734 /* Read the WWN: */
9735 if (!IS_MF(bp)) {
9736 /* Port info */
9737 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9738 SHMEM_RD(bp,
9739 dev_info.port_hw_config[port].
9740 fcoe_wwn_port_name_upper);
9741 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9742 SHMEM_RD(bp,
9743 dev_info.port_hw_config[port].
9744 fcoe_wwn_port_name_lower);
9745
9746 /* Node info */
9747 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9748 SHMEM_RD(bp,
9749 dev_info.port_hw_config[port].
9750 fcoe_wwn_node_name_upper);
9751 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9752 SHMEM_RD(bp,
9753 dev_info.port_hw_config[port].
9754 fcoe_wwn_node_name_lower);
9755 } else if (!IS_MF_SD(bp)) {
9756 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9757
9758 /*
9759 * Read the WWN info only if the FCoE feature is enabled for
9760 * this function.
9761 */
9e62e912
DK
9762 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
9763 bnx2x_get_ext_wwn_info(bp, func);
9764
9765 } else if (IS_MF_FCOE_SD(bp))
9766 bnx2x_get_ext_wwn_info(bp, func);
bf61ee14 9767
b306f5ed 9768 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 9769
bf61ee14
VZ
9770 /*
9771 * If maximum allowed number of connections is zero -
2ba45142
VZ
9772 * disable the feature.
9773 */
2ba45142
VZ
9774 if (!bp->cnic_eth_dev.max_fcoe_conn)
9775 bp->flags |= NO_FCOE_FLAG;
7185bb33
DK
9776#else
9777 bp->flags |= NO_FCOE_FLAG;
9778#endif
2ba45142 9779}
b306f5ed
DK
9780
9781static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
9782{
9783 /*
9784 * iSCSI may be dynamically disabled but reading
9785 * info here we will decrease memory usage by driver
9786 * if the feature is disabled for good
9787 */
9788 bnx2x_get_iscsi_info(bp);
9789 bnx2x_get_fcoe_info(bp);
9790}
2ba45142 9791
0793f83f
DK
9792static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
9793{
9794 u32 val, val2;
9795 int func = BP_ABS_FUNC(bp);
9796 int port = BP_PORT(bp);
2ba45142
VZ
9797#ifdef BCM_CNIC
9798 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
9799 u8 *fip_mac = bp->fip_mac;
9800#endif
0793f83f 9801
619c5cb6
VZ
9802 /* Zero primary MAC configuration */
9803 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9804
0793f83f
DK
9805 if (BP_NOMCP(bp)) {
9806 BNX2X_ERROR("warning: random MAC workaround active\n");
7ce5d222 9807 eth_hw_addr_random(bp->dev);
0793f83f
DK
9808 } else if (IS_MF(bp)) {
9809 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
9810 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
9811 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
9812 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
9813 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
37b091ba
MC
9814
9815#ifdef BCM_CNIC
614c76df
DK
9816 /*
9817 * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 9818 * FCoE MAC then the appropriate feature should be disabled.
9e62e912
DK
9819 *
9820 * In non SD mode features configuration comes from
9821 * struct func_ext_config.
2ba45142 9822 */
9e62e912 9823 if (!IS_MF_SD(bp)) {
0793f83f
DK
9824 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9825 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
9826 val2 = MF_CFG_RD(bp, func_ext_config[func].
9827 iscsi_mac_addr_upper);
9828 val = MF_CFG_RD(bp, func_ext_config[func].
9829 iscsi_mac_addr_lower);
2ba45142 9830 bnx2x_set_mac_buf(iscsi_mac, val, val2);
0f9dad10
JP
9831 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9832 iscsi_mac);
2ba45142
VZ
9833 } else
9834 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
9835
9836 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
9837 val2 = MF_CFG_RD(bp, func_ext_config[func].
9838 fcoe_mac_addr_upper);
9839 val = MF_CFG_RD(bp, func_ext_config[func].
9840 fcoe_mac_addr_lower);
2ba45142 9841 bnx2x_set_mac_buf(fip_mac, val, val2);
614c76df 9842 BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
0f9dad10 9843 fip_mac);
2ba45142 9844
2ba45142
VZ
9845 } else
9846 bp->flags |= NO_FCOE_FLAG;
9e62e912
DK
9847 } else { /* SD MODE */
9848 if (IS_MF_STORAGE_SD(bp)) {
9849 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
9850 /* use primary mac as iscsi mac */
9851 memcpy(iscsi_mac, bp->dev->dev_addr,
9852 ETH_ALEN);
9853
9854 BNX2X_DEV_INFO("SD ISCSI MODE\n");
9855 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9856 iscsi_mac);
9857 } else { /* FCoE */
9858 memcpy(fip_mac, bp->dev->dev_addr,
9859 ETH_ALEN);
9860 BNX2X_DEV_INFO("SD FCoE MODE\n");
9861 BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
9862 fip_mac);
9863 }
614c76df
DK
9864 /* Zero primary MAC configuration */
9865 memset(bp->dev->dev_addr, 0, ETH_ALEN);
614c76df 9866 }
0793f83f 9867 }
37b091ba 9868#endif
0793f83f
DK
9869 } else {
9870 /* in SF read MACs from port configuration */
9871 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
9872 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
9873 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9874
9875#ifdef BCM_CNIC
9876 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9877 iscsi_mac_upper);
9878 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9879 iscsi_mac_lower);
2ba45142 9880 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
9881
9882 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9883 fcoe_fip_mac_upper);
9884 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9885 fcoe_fip_mac_lower);
9886 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
9887#endif
9888 }
9889
9890 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
9891 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
9892
ec6ba945 9893#ifdef BCM_CNIC
426b9241
DK
9894 /* Disable iSCSI if MAC configuration is
9895 * invalid.
9896 */
9897 if (!is_valid_ether_addr(iscsi_mac)) {
9898 bp->flags |= NO_ISCSI_FLAG;
9899 memset(iscsi_mac, 0, ETH_ALEN);
9900 }
9901
9902 /* Disable FCoE if MAC configuration is
9903 * invalid.
9904 */
9905 if (!is_valid_ether_addr(fip_mac)) {
9906 bp->flags |= NO_FCOE_FLAG;
9907 memset(bp->fip_mac, 0, ETH_ALEN);
9908 }
ec6ba945 9909#endif
619c5cb6 9910
614c76df 9911 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 9912 dev_err(&bp->pdev->dev,
51c1a580
MS
9913 "bad Ethernet MAC address configuration: %pM\n"
9914 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 9915 bp->dev->dev_addr);
51c1a580
MS
9916
9917
34f80b04
EG
9918}
9919
9920static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
9921{
0793f83f 9922 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 9923 int vn;
0793f83f 9924 u32 val = 0;
34f80b04 9925 int rc = 0;
a2fbb9ea 9926
34f80b04 9927 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 9928
6383c0b3
AE
9929 /*
9930 * initialize IGU parameters
9931 */
f2e0899f
DK
9932 if (CHIP_IS_E1x(bp)) {
9933 bp->common.int_block = INT_BLOCK_HC;
9934
9935 bp->igu_dsb_id = DEF_SB_IGU_ID;
9936 bp->igu_base_sb = 0;
f2e0899f
DK
9937 } else {
9938 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
9939
9940 /* do not allow device reset during IGU info preocessing */
9941 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9942
f2e0899f 9943 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
9944
9945 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
9946 int tout = 5000;
9947
9948 BNX2X_DEV_INFO("FORCING Normal Mode\n");
9949
9950 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
9951 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
9952 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
9953
9954 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9955 tout--;
9956 usleep_range(1000, 1000);
9957 }
9958
9959 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9960 dev_err(&bp->pdev->dev,
9961 "FORCING Normal Mode failed!!!\n");
9962 return -EPERM;
9963 }
9964 }
9965
f2e0899f 9966 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 9967 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
9968 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
9969 } else
619c5cb6 9970 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 9971
f2e0899f
DK
9972 bnx2x_get_igu_cam_info(bp);
9973
7a06a122 9974 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
f2e0899f 9975 }
619c5cb6
VZ
9976
9977 /*
9978 * set base FW non-default (fast path) status block id, this value is
9979 * used to initialize the fw_sb_id saved on the fp/queue structure to
9980 * determine the id used by the FW.
9981 */
9982 if (CHIP_IS_E1x(bp))
9983 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
9984 else /*
9985 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
9986 * the same queue are indicated on the same IGU SB). So we prefer
9987 * FW and IGU SBs to be the same value.
9988 */
9989 bp->base_fw_ndsb = bp->igu_base_sb;
9990
9991 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
9992 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
9993 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
9994
9995 /*
9996 * Initialize MF configuration
9997 */
523224a3 9998
fb3bff17
DK
9999 bp->mf_ov = 0;
10000 bp->mf_mode = 0;
3395a033 10001 vn = BP_VN(bp);
0793f83f 10002
f2e0899f 10003 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
10004 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10005 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10006 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10007
f2e0899f
DK
10008 if (SHMEM2_HAS(bp, mf_cfg_addr))
10009 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10010 else
10011 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
10012 offsetof(struct shmem_region, func_mb) +
10013 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
10014 /*
10015 * get mf configuration:
25985edc 10016 * 1. existence of MF configuration
0793f83f
DK
10017 * 2. MAC address must be legal (check only upper bytes)
10018 * for Switch-Independent mode;
10019 * OVLAN must be legal for Switch-Dependent mode
10020 * 3. SF_MODE configures specific MF mode
10021 */
10022 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10023 /* get mf configuration */
10024 val = SHMEM_RD(bp,
10025 dev_info.shared_feature_config.config);
10026 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10027
10028 switch (val) {
10029 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10030 val = MF_CFG_RD(bp, func_mf_config[func].
10031 mac_upper);
10032 /* check for legal mac (upper bytes)*/
10033 if (val != 0xffff) {
10034 bp->mf_mode = MULTI_FUNCTION_SI;
10035 bp->mf_config[vn] = MF_CFG_RD(bp,
10036 func_mf_config[func].config);
10037 } else
51c1a580 10038 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f
DK
10039 break;
10040 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10041 /* get OV configuration */
10042 val = MF_CFG_RD(bp,
10043 func_mf_config[FUNC_0].e1hov_tag);
10044 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10045
10046 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10047 bp->mf_mode = MULTI_FUNCTION_SD;
10048 bp->mf_config[vn] = MF_CFG_RD(bp,
10049 func_mf_config[func].config);
10050 } else
754a2f52 10051 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
10052 break;
10053 default:
10054 /* Unknown configuration: reset mf_config */
10055 bp->mf_config[vn] = 0;
51c1a580 10056 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
10057 }
10058 }
a2fbb9ea 10059
2691d51d 10060 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 10061 IS_MF(bp) ? "multi" : "single");
2691d51d 10062
0793f83f
DK
10063 switch (bp->mf_mode) {
10064 case MULTI_FUNCTION_SD:
10065 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10066 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 10067 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 10068 bp->mf_ov = val;
619c5cb6
VZ
10069 bp->path_has_ovlan = true;
10070
51c1a580
MS
10071 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10072 func, bp->mf_ov, bp->mf_ov);
2691d51d 10073 } else {
619c5cb6 10074 dev_err(&bp->pdev->dev,
51c1a580
MS
10075 "No valid MF OV for func %d, aborting\n",
10076 func);
619c5cb6 10077 return -EPERM;
34f80b04 10078 }
0793f83f
DK
10079 break;
10080 case MULTI_FUNCTION_SI:
51c1a580
MS
10081 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10082 func);
0793f83f
DK
10083 break;
10084 default:
10085 if (vn) {
619c5cb6 10086 dev_err(&bp->pdev->dev,
51c1a580
MS
10087 "VN %d is in a single function mode, aborting\n",
10088 vn);
619c5cb6 10089 return -EPERM;
2691d51d 10090 }
0793f83f 10091 break;
34f80b04 10092 }
0793f83f 10093
619c5cb6
VZ
10094 /* check if other port on the path needs ovlan:
10095 * Since MF configuration is shared between ports
10096 * Possible mixed modes are only
10097 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10098 */
10099 if (CHIP_MODE_IS_4_PORT(bp) &&
10100 !bp->path_has_ovlan &&
10101 !IS_MF(bp) &&
10102 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10103 u8 other_port = !BP_PORT(bp);
10104 u8 other_func = BP_PATH(bp) + 2*other_port;
10105 val = MF_CFG_RD(bp,
10106 func_mf_config[other_func].e1hov_tag);
10107 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10108 bp->path_has_ovlan = true;
10109 }
34f80b04 10110 }
a2fbb9ea 10111
f2e0899f
DK
10112 /* adjust igu_sb_cnt to MF for E1x */
10113 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
10114 bp->igu_sb_cnt /= E1HVN_MAX;
10115
619c5cb6
VZ
10116 /* port info */
10117 bnx2x_get_port_hwinfo(bp);
f2e0899f 10118
0793f83f
DK
10119 /* Get MAC addresses */
10120 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 10121
2ba45142 10122 bnx2x_get_cnic_info(bp);
2ba45142 10123
34f80b04
EG
10124 return rc;
10125}
10126
34f24c7f
VZ
10127static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10128{
10129 int cnt, i, block_end, rodi;
fcdf95cb 10130 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
10131 char str_id_reg[VENDOR_ID_LEN+1];
10132 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
10133 char *vpd_data;
10134 char *vpd_extended_data = NULL;
34f24c7f
VZ
10135 u8 len;
10136
fcdf95cb 10137 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
10138 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10139
10140 if (cnt < BNX2X_VPD_LEN)
10141 goto out_not_found;
10142
fcdf95cb
BW
10143 /* VPD RO tag should be first tag after identifier string, hence
10144 * we should be able to find it in first BNX2X_VPD_LEN chars
10145 */
10146 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
10147 PCI_VPD_LRDT_RO_DATA);
10148 if (i < 0)
10149 goto out_not_found;
10150
34f24c7f 10151 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 10152 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
10153
10154 i += PCI_VPD_LRDT_TAG_SIZE;
10155
fcdf95cb
BW
10156 if (block_end > BNX2X_VPD_LEN) {
10157 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10158 if (vpd_extended_data == NULL)
10159 goto out_not_found;
10160
10161 /* read rest of vpd image into vpd_extended_data */
10162 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10163 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10164 block_end - BNX2X_VPD_LEN,
10165 vpd_extended_data + BNX2X_VPD_LEN);
10166 if (cnt < (block_end - BNX2X_VPD_LEN))
10167 goto out_not_found;
10168 vpd_data = vpd_extended_data;
10169 } else
10170 vpd_data = vpd_start;
10171
10172 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
10173
10174 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10175 PCI_VPD_RO_KEYWORD_MFR_ID);
10176 if (rodi < 0)
10177 goto out_not_found;
10178
10179 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10180
10181 if (len != VENDOR_ID_LEN)
10182 goto out_not_found;
10183
10184 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10185
10186 /* vendor specific info */
10187 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10188 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10189 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10190 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10191
10192 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10193 PCI_VPD_RO_KEYWORD_VENDOR0);
10194 if (rodi >= 0) {
10195 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10196
10197 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10198
10199 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10200 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10201 bp->fw_ver[len] = ' ';
10202 }
10203 }
fcdf95cb 10204 kfree(vpd_extended_data);
34f24c7f
VZ
10205 return;
10206 }
10207out_not_found:
fcdf95cb 10208 kfree(vpd_extended_data);
34f24c7f
VZ
10209 return;
10210}
10211
619c5cb6
VZ
10212static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10213{
10214 u32 flags = 0;
10215
10216 if (CHIP_REV_IS_FPGA(bp))
10217 SET_FLAGS(flags, MODE_FPGA);
10218 else if (CHIP_REV_IS_EMUL(bp))
10219 SET_FLAGS(flags, MODE_EMUL);
10220 else
10221 SET_FLAGS(flags, MODE_ASIC);
10222
10223 if (CHIP_MODE_IS_4_PORT(bp))
10224 SET_FLAGS(flags, MODE_PORT4);
10225 else
10226 SET_FLAGS(flags, MODE_PORT2);
10227
10228 if (CHIP_IS_E2(bp))
10229 SET_FLAGS(flags, MODE_E2);
10230 else if (CHIP_IS_E3(bp)) {
10231 SET_FLAGS(flags, MODE_E3);
10232 if (CHIP_REV(bp) == CHIP_REV_Ax)
10233 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
10234 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
10235 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
10236 }
10237
10238 if (IS_MF(bp)) {
10239 SET_FLAGS(flags, MODE_MF);
10240 switch (bp->mf_mode) {
10241 case MULTI_FUNCTION_SD:
10242 SET_FLAGS(flags, MODE_MF_SD);
10243 break;
10244 case MULTI_FUNCTION_SI:
10245 SET_FLAGS(flags, MODE_MF_SI);
10246 break;
10247 }
10248 } else
10249 SET_FLAGS(flags, MODE_SF);
10250
10251#if defined(__LITTLE_ENDIAN)
10252 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
10253#else /*(__BIG_ENDIAN)*/
10254 SET_FLAGS(flags, MODE_BIG_ENDIAN);
10255#endif
10256 INIT_MODE_FLAGS(bp) = flags;
10257}
10258
34f80b04
EG
10259static int __devinit bnx2x_init_bp(struct bnx2x *bp)
10260{
f2e0899f 10261 int func;
34f80b04
EG
10262 int rc;
10263
34f80b04 10264 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 10265 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 10266 spin_lock_init(&bp->stats_lock);
993ac7b5
MC
10267#ifdef BCM_CNIC
10268 mutex_init(&bp->cnic_mutex);
10269#endif
a2fbb9ea 10270
1cf167f2 10271 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 10272 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 10273 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
34f80b04 10274 rc = bnx2x_get_hwinfo(bp);
619c5cb6
VZ
10275 if (rc)
10276 return rc;
34f80b04 10277
619c5cb6
VZ
10278 bnx2x_set_modes_bitmap(bp);
10279
10280 rc = bnx2x_alloc_mem_bp(bp);
10281 if (rc)
10282 return rc;
523224a3 10283
34f24c7f 10284 bnx2x_read_fwinfo(bp);
f2e0899f
DK
10285
10286 func = BP_FUNC(bp);
10287
34f80b04 10288 /* need to reset chip if undi was active */
452427b0
YM
10289 if (!BP_NOMCP(bp)) {
10290 /* init fw_seq */
10291 bp->fw_seq =
10292 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10293 DRV_MSG_SEQ_NUMBER_MASK;
10294 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10295
10296 bnx2x_prev_unload(bp);
10297 }
10298
34f80b04
EG
10299
10300 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 10301 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
10302
10303 if (BP_NOMCP(bp) && (func == 0))
51c1a580 10304 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 10305
555f6c78 10306 bp->multi_mode = multi_mode;
555f6c78 10307
614c76df
DK
10308 bp->disable_tpa = disable_tpa;
10309
10310#ifdef BCM_CNIC
9e62e912 10311 bp->disable_tpa |= IS_MF_STORAGE_SD(bp);
614c76df
DK
10312#endif
10313
7a9b2557 10314 /* Set TPA flags */
614c76df 10315 if (bp->disable_tpa) {
621b4d66 10316 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
10317 bp->dev->features &= ~NETIF_F_LRO;
10318 } else {
621b4d66 10319 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
10320 bp->dev->features |= NETIF_F_LRO;
10321 }
10322
a18f5128
EG
10323 if (CHIP_IS_E1(bp))
10324 bp->dropless_fc = 0;
10325 else
10326 bp->dropless_fc = dropless_fc;
10327
8d5726c4 10328 bp->mrrs = mrrs;
7a9b2557 10329
34f80b04 10330 bp->tx_ring_size = MAX_TX_AVAIL;
34f80b04 10331
7d323bfd 10332 /* make sure that the numbers are in the right granularity */
523224a3
DK
10333 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
10334 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 10335
fc543637 10336 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
10337
10338 init_timer(&bp->timer);
10339 bp->timer.expires = jiffies + bp->current_interval;
10340 bp->timer.data = (unsigned long) bp;
10341 bp->timer.function = bnx2x_timer;
10342
785b9b1a 10343 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
e4901dde
VZ
10344 bnx2x_dcbx_init_params(bp);
10345
619c5cb6
VZ
10346#ifdef BCM_CNIC
10347 if (CHIP_IS_E1x(bp))
10348 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
10349 else
10350 bp->cnic_base_cl_id = FP_SB_MAX_E2;
10351#endif
10352
6383c0b3
AE
10353 /* multiple tx priority */
10354 if (CHIP_IS_E1x(bp))
10355 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
10356 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
10357 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
10358 if (CHIP_IS_E3B0(bp))
10359 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
10360
fe603b4d
DK
10361 bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu);
10362
34f80b04 10363 return rc;
a2fbb9ea
ET
10364}
10365
a2fbb9ea 10366
de0c62db
DK
10367/****************************************************************************
10368* General service functions
10369****************************************************************************/
a2fbb9ea 10370
619c5cb6
VZ
10371/*
10372 * net_device service functions
10373 */
10374
bb2a0f7a 10375/* called with rtnl_lock */
a2fbb9ea
ET
10376static int bnx2x_open(struct net_device *dev)
10377{
10378 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
10379 bool global = false;
10380 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 10381 bool other_load_status, load_status;
a2fbb9ea 10382
1355b704
MY
10383 bp->stats_init = true;
10384
6eccabb3
EG
10385 netif_carrier_off(dev);
10386
a2fbb9ea
ET
10387 bnx2x_set_power_state(bp, PCI_D0);
10388
889b9af3
AE
10389 other_load_status = bnx2x_get_load_status(bp, other_engine);
10390 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
10391
10392 /*
10393 * If parity had happen during the unload, then attentions
10394 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
10395 * want the first function loaded on the current engine to
10396 * complete the recovery.
10397 */
10398 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
10399 bnx2x_chk_parity_attn(bp, &global, true))
72fd0718 10400 do {
c9ee9206
VZ
10401 /*
10402 * If there are attentions and they are in a global
10403 * blocks, set the GLOBAL_RESET bit regardless whether
10404 * it will be this function that will complete the
10405 * recovery or not.
72fd0718 10406 */
c9ee9206
VZ
10407 if (global)
10408 bnx2x_set_reset_global(bp);
72fd0718 10409
c9ee9206
VZ
10410 /*
10411 * Only the first function on the current engine should
10412 * try to recover in open. In case of attentions in
10413 * global blocks only the first in the chip should try
10414 * to recover.
72fd0718 10415 */
889b9af3
AE
10416 if ((!load_status &&
10417 (!global || !other_load_status)) &&
c9ee9206
VZ
10418 bnx2x_trylock_leader_lock(bp) &&
10419 !bnx2x_leader_reset(bp)) {
10420 netdev_info(bp->dev, "Recovered in open\n");
72fd0718
VZ
10421 break;
10422 }
10423
c9ee9206 10424 /* recovery has failed... */
72fd0718 10425 bnx2x_set_power_state(bp, PCI_D3hot);
c9ee9206 10426 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 10427
51c1a580
MS
10428 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
10429 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718
VZ
10430
10431 return -EAGAIN;
10432 } while (0);
72fd0718
VZ
10433
10434 bp->recovery_state = BNX2X_RECOVERY_DONE;
bb2a0f7a 10435 return bnx2x_nic_load(bp, LOAD_OPEN);
a2fbb9ea
ET
10436}
10437
bb2a0f7a 10438/* called with rtnl_lock */
56ad3152 10439static int bnx2x_close(struct net_device *dev)
a2fbb9ea 10440{
a2fbb9ea
ET
10441 struct bnx2x *bp = netdev_priv(dev);
10442
10443 /* Unload the driver, release IRQs */
bb2a0f7a 10444 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
c9ee9206
VZ
10445
10446 /* Power off */
d3dbfee0 10447 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
10448
10449 return 0;
10450}
10451
619c5cb6
VZ
10452static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
10453 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 10454{
619c5cb6
VZ
10455 int mc_count = netdev_mc_count(bp->dev);
10456 struct bnx2x_mcast_list_elem *mc_mac =
10457 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
10458 struct netdev_hw_addr *ha;
6e30dd4e 10459
619c5cb6
VZ
10460 if (!mc_mac)
10461 return -ENOMEM;
6e30dd4e 10462
619c5cb6 10463 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 10464
619c5cb6
VZ
10465 netdev_for_each_mc_addr(ha, bp->dev) {
10466 mc_mac->mac = bnx2x_mc_addr(ha);
10467 list_add_tail(&mc_mac->link, &p->mcast_list);
10468 mc_mac++;
6e30dd4e 10469 }
619c5cb6
VZ
10470
10471 p->mcast_list_len = mc_count;
10472
10473 return 0;
6e30dd4e
VZ
10474}
10475
619c5cb6
VZ
10476static inline void bnx2x_free_mcast_macs_list(
10477 struct bnx2x_mcast_ramrod_params *p)
10478{
10479 struct bnx2x_mcast_list_elem *mc_mac =
10480 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
10481 link);
10482
10483 WARN_ON(!mc_mac);
10484 kfree(mc_mac);
10485}
10486
10487/**
10488 * bnx2x_set_uc_list - configure a new unicast MACs list.
10489 *
10490 * @bp: driver handle
6e30dd4e 10491 *
619c5cb6 10492 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 10493 */
619c5cb6 10494static inline int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 10495{
619c5cb6 10496 int rc;
6e30dd4e 10497 struct net_device *dev = bp->dev;
6e30dd4e 10498 struct netdev_hw_addr *ha;
619c5cb6
VZ
10499 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
10500 unsigned long ramrod_flags = 0;
6e30dd4e 10501
619c5cb6
VZ
10502 /* First schedule a cleanup up of old configuration */
10503 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
10504 if (rc < 0) {
10505 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
10506 return rc;
10507 }
6e30dd4e
VZ
10508
10509 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
10510 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
10511 BNX2X_UC_LIST_MAC, &ramrod_flags);
10512 if (rc < 0) {
10513 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
10514 rc);
10515 return rc;
6e30dd4e
VZ
10516 }
10517 }
10518
619c5cb6
VZ
10519 /* Execute the pending commands */
10520 __set_bit(RAMROD_CONT, &ramrod_flags);
10521 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
10522 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
10523}
10524
619c5cb6 10525static inline int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 10526{
619c5cb6 10527 struct net_device *dev = bp->dev;
3b603066 10528 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 10529 int rc = 0;
6e30dd4e 10530
619c5cb6 10531 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 10532
619c5cb6
VZ
10533 /* first, clear all configured multicast MACs */
10534 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
10535 if (rc < 0) {
51c1a580 10536 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
10537 return rc;
10538 }
6e30dd4e 10539
619c5cb6
VZ
10540 /* then, configure a new MACs list */
10541 if (netdev_mc_count(dev)) {
10542 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
10543 if (rc) {
51c1a580
MS
10544 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
10545 rc);
619c5cb6
VZ
10546 return rc;
10547 }
6e30dd4e 10548
619c5cb6
VZ
10549 /* Now add the new MACs */
10550 rc = bnx2x_config_mcast(bp, &rparam,
10551 BNX2X_MCAST_CMD_ADD);
10552 if (rc < 0)
51c1a580
MS
10553 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
10554 rc);
6e30dd4e 10555
619c5cb6
VZ
10556 bnx2x_free_mcast_macs_list(&rparam);
10557 }
6e30dd4e 10558
619c5cb6 10559 return rc;
6e30dd4e
VZ
10560}
10561
6e30dd4e 10562
619c5cb6 10563/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 10564void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
10565{
10566 struct bnx2x *bp = netdev_priv(dev);
10567 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
10568
10569 if (bp->state != BNX2X_STATE_OPEN) {
10570 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
10571 return;
10572 }
10573
619c5cb6 10574 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
10575
10576 if (dev->flags & IFF_PROMISC)
10577 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
10578 else if ((dev->flags & IFF_ALLMULTI) ||
10579 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
10580 CHIP_IS_E1(bp)))
34f80b04 10581 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e
VZ
10582 else {
10583 /* some multicasts */
619c5cb6 10584 if (bnx2x_set_mc_list(bp) < 0)
6e30dd4e 10585 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 10586
619c5cb6 10587 if (bnx2x_set_uc_list(bp) < 0)
6e30dd4e 10588 rx_mode = BNX2X_RX_MODE_PROMISC;
34f80b04
EG
10589 }
10590
10591 bp->rx_mode = rx_mode;
614c76df
DK
10592#ifdef BCM_CNIC
10593 /* handle ISCSI SD mode */
10594 if (IS_MF_ISCSI_SD(bp))
10595 bp->rx_mode = BNX2X_RX_MODE_NONE;
10596#endif
619c5cb6
VZ
10597
10598 /* Schedule the rx_mode command */
10599 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
10600 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
10601 return;
10602 }
10603
34f80b04
EG
10604 bnx2x_set_storm_rx_mode(bp);
10605}
10606
c18487ee 10607/* called with rtnl_lock */
01cd4528
EG
10608static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
10609 int devad, u16 addr)
a2fbb9ea 10610{
01cd4528
EG
10611 struct bnx2x *bp = netdev_priv(netdev);
10612 u16 value;
10613 int rc;
a2fbb9ea 10614
01cd4528
EG
10615 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
10616 prtad, devad, addr);
a2fbb9ea 10617
01cd4528
EG
10618 /* The HW expects different devad if CL22 is used */
10619 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 10620
01cd4528 10621 bnx2x_acquire_phy_lock(bp);
e10bc84d 10622 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
10623 bnx2x_release_phy_lock(bp);
10624 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 10625
01cd4528
EG
10626 if (!rc)
10627 rc = value;
10628 return rc;
10629}
a2fbb9ea 10630
01cd4528
EG
10631/* called with rtnl_lock */
10632static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
10633 u16 addr, u16 value)
10634{
10635 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
10636 int rc;
10637
51c1a580
MS
10638 DP(NETIF_MSG_LINK,
10639 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
10640 prtad, devad, addr, value);
01cd4528 10641
01cd4528
EG
10642 /* The HW expects different devad if CL22 is used */
10643 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 10644
01cd4528 10645 bnx2x_acquire_phy_lock(bp);
e10bc84d 10646 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
10647 bnx2x_release_phy_lock(bp);
10648 return rc;
10649}
c18487ee 10650
01cd4528
EG
10651/* called with rtnl_lock */
10652static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10653{
10654 struct bnx2x *bp = netdev_priv(dev);
10655 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 10656
01cd4528
EG
10657 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
10658 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 10659
01cd4528
EG
10660 if (!netif_running(dev))
10661 return -EAGAIN;
10662
10663 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
10664}
10665
257ddbda 10666#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
10667static void poll_bnx2x(struct net_device *dev)
10668{
10669 struct bnx2x *bp = netdev_priv(dev);
10670
10671 disable_irq(bp->pdev->irq);
10672 bnx2x_interrupt(bp->pdev->irq, dev);
10673 enable_irq(bp->pdev->irq);
10674}
10675#endif
10676
614c76df
DK
10677static int bnx2x_validate_addr(struct net_device *dev)
10678{
10679 struct bnx2x *bp = netdev_priv(dev);
10680
51c1a580
MS
10681 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
10682 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 10683 return -EADDRNOTAVAIL;
51c1a580 10684 }
614c76df
DK
10685 return 0;
10686}
10687
c64213cd
SH
10688static const struct net_device_ops bnx2x_netdev_ops = {
10689 .ndo_open = bnx2x_open,
10690 .ndo_stop = bnx2x_close,
10691 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 10692 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 10693 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 10694 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 10695 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
10696 .ndo_do_ioctl = bnx2x_ioctl,
10697 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
10698 .ndo_fix_features = bnx2x_fix_features,
10699 .ndo_set_features = bnx2x_set_features,
c64213cd 10700 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 10701#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
10702 .ndo_poll_controller = poll_bnx2x,
10703#endif
6383c0b3
AE
10704 .ndo_setup_tc = bnx2x_setup_tc,
10705
bf61ee14
VZ
10706#if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
10707 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
10708#endif
c64213cd
SH
10709};
10710
619c5cb6
VZ
10711static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
10712{
10713 struct device *dev = &bp->pdev->dev;
10714
10715 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
10716 bp->flags |= USING_DAC_FLAG;
10717 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 10718 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
10719 return -EIO;
10720 }
10721 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
10722 dev_err(dev, "System does not support DMA, aborting\n");
10723 return -EIO;
10724 }
10725
10726 return 0;
10727}
10728
34f80b04 10729static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
619c5cb6
VZ
10730 struct net_device *dev,
10731 unsigned long board_type)
a2fbb9ea
ET
10732{
10733 struct bnx2x *bp;
10734 int rc;
c22610d0 10735 u32 pci_cfg_dword;
65087cfe
AE
10736 bool chip_is_e1x = (board_type == BCM57710 ||
10737 board_type == BCM57711 ||
10738 board_type == BCM57711E);
a2fbb9ea
ET
10739
10740 SET_NETDEV_DEV(dev, &pdev->dev);
10741 bp = netdev_priv(dev);
10742
34f80b04
EG
10743 bp->dev = dev;
10744 bp->pdev = pdev;
a2fbb9ea 10745 bp->flags = 0;
a2fbb9ea
ET
10746
10747 rc = pci_enable_device(pdev);
10748 if (rc) {
cdaa7cb8
VZ
10749 dev_err(&bp->pdev->dev,
10750 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
10751 goto err_out;
10752 }
10753
10754 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
10755 dev_err(&bp->pdev->dev,
10756 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
10757 rc = -ENODEV;
10758 goto err_out_disable;
10759 }
10760
10761 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
10762 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
10763 " base address, aborting\n");
a2fbb9ea
ET
10764 rc = -ENODEV;
10765 goto err_out_disable;
10766 }
10767
34f80b04
EG
10768 if (atomic_read(&pdev->enable_cnt) == 1) {
10769 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10770 if (rc) {
cdaa7cb8
VZ
10771 dev_err(&bp->pdev->dev,
10772 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
10773 goto err_out_disable;
10774 }
a2fbb9ea 10775
34f80b04
EG
10776 pci_set_master(pdev);
10777 pci_save_state(pdev);
10778 }
a2fbb9ea
ET
10779
10780 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10781 if (bp->pm_cap == 0) {
cdaa7cb8
VZ
10782 dev_err(&bp->pdev->dev,
10783 "Cannot find power management capability, aborting\n");
a2fbb9ea
ET
10784 rc = -EIO;
10785 goto err_out_release;
10786 }
10787
77c98e6a 10788 if (!pci_is_pcie(pdev)) {
51c1a580 10789 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
10790 rc = -EIO;
10791 goto err_out_release;
10792 }
10793
619c5cb6
VZ
10794 rc = bnx2x_set_coherency_mask(bp);
10795 if (rc)
a2fbb9ea 10796 goto err_out_release;
a2fbb9ea 10797
34f80b04
EG
10798 dev->mem_start = pci_resource_start(pdev, 0);
10799 dev->base_addr = dev->mem_start;
10800 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
10801
10802 dev->irq = pdev->irq;
10803
275f165f 10804 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 10805 if (!bp->regview) {
cdaa7cb8
VZ
10806 dev_err(&bp->pdev->dev,
10807 "Cannot map register space, aborting\n");
a2fbb9ea
ET
10808 rc = -ENOMEM;
10809 goto err_out_release;
10810 }
10811
c22610d0
AE
10812 /* In E1/E1H use pci device function given by kernel.
10813 * In E2/E3 read physical function from ME register since these chips
10814 * support Physical Device Assignment where kernel BDF maybe arbitrary
10815 * (depending on hypervisor).
10816 */
10817 if (chip_is_e1x)
10818 bp->pf_num = PCI_FUNC(pdev->devfn);
10819 else {/* chip is E2/3*/
10820 pci_read_config_dword(bp->pdev,
10821 PCICFG_ME_REGISTER, &pci_cfg_dword);
10822 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
10823 ME_REG_ABS_PF_NUM_SHIFT);
10824 }
51c1a580 10825 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 10826
a2fbb9ea
ET
10827 bnx2x_set_power_state(bp, PCI_D0);
10828
34f80b04
EG
10829 /* clean indirect addresses */
10830 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10831 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
10832 /*
10833 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
10834 * is not used by the driver.
10835 */
10836 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
10837 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
10838 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
10839 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
a5c53dbc 10840
65087cfe 10841 if (chip_is_e1x) {
a5c53dbc
DK
10842 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
10843 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
10844 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
10845 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
10846 }
a2fbb9ea 10847
2189400b 10848 /*
619c5cb6 10849 * Enable internal target-read (in case we are probed after PF FLR).
2189400b 10850 * Must be done prior to any BAR read access. Only for 57712 and up
619c5cb6 10851 */
65087cfe 10852 if (!chip_is_e1x)
2189400b 10853 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
619c5cb6 10854
72fd0718 10855 /* Reset the load counter */
889b9af3 10856 bnx2x_clear_load_status(bp);
72fd0718 10857
34f80b04 10858 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 10859
c64213cd 10860 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 10861 bnx2x_set_ethtool_ops(dev);
5316bc0b 10862
01789349
JP
10863 dev->priv_flags |= IFF_UNICAST_FLT;
10864
66371c44 10865 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
10866 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
10867 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
10868 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
10869
10870 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10871 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
10872
10873 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 10874 if (bp->flags & USING_DAC_FLAG)
66371c44 10875 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 10876
538dd2e3
MB
10877 /* Add Loopback capability to the device */
10878 dev->hw_features |= NETIF_F_LOOPBACK;
10879
98507672 10880#ifdef BCM_DCBNL
785b9b1a
SR
10881 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
10882#endif
10883
01cd4528
EG
10884 /* get_port_hwinfo() will set prtad and mmds properly */
10885 bp->mdio.prtad = MDIO_PRTAD_NONE;
10886 bp->mdio.mmds = 0;
10887 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10888 bp->mdio.dev = dev;
10889 bp->mdio.mdio_read = bnx2x_mdio_read;
10890 bp->mdio.mdio_write = bnx2x_mdio_write;
10891
a2fbb9ea
ET
10892 return 0;
10893
a2fbb9ea 10894err_out_release:
34f80b04
EG
10895 if (atomic_read(&pdev->enable_cnt) == 1)
10896 pci_release_regions(pdev);
a2fbb9ea
ET
10897
10898err_out_disable:
10899 pci_disable_device(pdev);
10900 pci_set_drvdata(pdev, NULL);
10901
10902err_out:
10903 return rc;
10904}
10905
37f9ce62
EG
10906static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
10907 int *width, int *speed)
25047950
ET
10908{
10909 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10910
37f9ce62 10911 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 10912
37f9ce62
EG
10913 /* return value of 1=2.5GHz 2=5GHz */
10914 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 10915}
37f9ce62 10916
6891dd25 10917static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 10918{
37f9ce62 10919 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
10920 struct bnx2x_fw_file_hdr *fw_hdr;
10921 struct bnx2x_fw_file_section *sections;
94a78b79 10922 u32 offset, len, num_ops;
37f9ce62 10923 u16 *ops_offsets;
94a78b79 10924 int i;
37f9ce62 10925 const u8 *fw_ver;
94a78b79 10926
51c1a580
MS
10927 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
10928 BNX2X_ERR("Wrong FW size\n");
94a78b79 10929 return -EINVAL;
51c1a580 10930 }
94a78b79
VZ
10931
10932 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
10933 sections = (struct bnx2x_fw_file_section *)fw_hdr;
10934
10935 /* Make sure none of the offsets and sizes make us read beyond
10936 * the end of the firmware data */
10937 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
10938 offset = be32_to_cpu(sections[i].offset);
10939 len = be32_to_cpu(sections[i].len);
10940 if (offset + len > firmware->size) {
51c1a580 10941 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
10942 return -EINVAL;
10943 }
10944 }
10945
10946 /* Likewise for the init_ops offsets */
10947 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
10948 ops_offsets = (u16 *)(firmware->data + offset);
10949 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
10950
10951 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
10952 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 10953 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
10954 return -EINVAL;
10955 }
10956 }
10957
10958 /* Check FW version */
10959 offset = be32_to_cpu(fw_hdr->fw_version.offset);
10960 fw_ver = firmware->data + offset;
10961 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
10962 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
10963 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
10964 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
10965 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
10966 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
10967 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
10968 BCM_5710_FW_MINOR_VERSION,
10969 BCM_5710_FW_REVISION_VERSION,
10970 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 10971 return -EINVAL;
94a78b79
VZ
10972 }
10973
10974 return 0;
10975}
10976
ab6ad5a4 10977static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 10978{
ab6ad5a4
EG
10979 const __be32 *source = (const __be32 *)_source;
10980 u32 *target = (u32 *)_target;
94a78b79 10981 u32 i;
94a78b79
VZ
10982
10983 for (i = 0; i < n/4; i++)
10984 target[i] = be32_to_cpu(source[i]);
10985}
10986
10987/*
10988 Ops array is stored in the following format:
10989 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
10990 */
ab6ad5a4 10991static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 10992{
ab6ad5a4
EG
10993 const __be32 *source = (const __be32 *)_source;
10994 struct raw_op *target = (struct raw_op *)_target;
94a78b79 10995 u32 i, j, tmp;
94a78b79 10996
ab6ad5a4 10997 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
10998 tmp = be32_to_cpu(source[j]);
10999 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
11000 target[i].offset = tmp & 0xffffff;
11001 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
11002 }
11003}
ab6ad5a4 11004
523224a3
DK
11005/**
11006 * IRO array is stored in the following format:
11007 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11008 */
11009static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
11010{
11011 const __be32 *source = (const __be32 *)_source;
11012 struct iro *target = (struct iro *)_target;
11013 u32 i, j, tmp;
11014
11015 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11016 target[i].base = be32_to_cpu(source[j]);
11017 j++;
11018 tmp = be32_to_cpu(source[j]);
11019 target[i].m1 = (tmp >> 16) & 0xffff;
11020 target[i].m2 = tmp & 0xffff;
11021 j++;
11022 tmp = be32_to_cpu(source[j]);
11023 target[i].m3 = (tmp >> 16) & 0xffff;
11024 target[i].size = tmp & 0xffff;
11025 j++;
11026 }
11027}
11028
ab6ad5a4 11029static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11030{
ab6ad5a4
EG
11031 const __be16 *source = (const __be16 *)_source;
11032 u16 *target = (u16 *)_target;
94a78b79 11033 u32 i;
94a78b79
VZ
11034
11035 for (i = 0; i < n/2; i++)
11036 target[i] = be16_to_cpu(source[i]);
11037}
11038
7995c64e
JP
11039#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11040do { \
11041 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11042 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 11043 if (!bp->arr) \
7995c64e 11044 goto lbl; \
7995c64e
JP
11045 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11046 (u8 *)bp->arr, len); \
11047} while (0)
94a78b79 11048
3b603066 11049static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 11050{
c0ea452e 11051 const char *fw_file_name;
94a78b79 11052 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 11053 int rc;
94a78b79 11054
c0ea452e
MS
11055 if (bp->firmware)
11056 return 0;
94a78b79 11057
c0ea452e
MS
11058 if (CHIP_IS_E1(bp))
11059 fw_file_name = FW_FILE_NAME_E1;
11060 else if (CHIP_IS_E1H(bp))
11061 fw_file_name = FW_FILE_NAME_E1H;
11062 else if (!CHIP_IS_E1x(bp))
11063 fw_file_name = FW_FILE_NAME_E2;
11064 else {
11065 BNX2X_ERR("Unsupported chip revision\n");
11066 return -EINVAL;
11067 }
11068 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 11069
c0ea452e
MS
11070 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11071 if (rc) {
11072 BNX2X_ERR("Can't load firmware file %s\n",
11073 fw_file_name);
11074 goto request_firmware_exit;
11075 }
eb2afd4a 11076
c0ea452e
MS
11077 rc = bnx2x_check_firmware(bp);
11078 if (rc) {
11079 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11080 goto request_firmware_exit;
94a78b79
VZ
11081 }
11082
11083 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11084
11085 /* Initialize the pointers to the init arrays */
11086 /* Blob */
11087 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11088
11089 /* Opcodes */
11090 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11091
11092 /* Offsets */
ab6ad5a4
EG
11093 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11094 be16_to_cpu_n);
94a78b79
VZ
11095
11096 /* STORMs firmware */
573f2035
EG
11097 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11098 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11099 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11100 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11101 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11102 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11103 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11104 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11105 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11106 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11107 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11108 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11109 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11110 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11111 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11112 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
11113 /* IRO */
11114 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
11115
11116 return 0;
ab6ad5a4 11117
523224a3
DK
11118iro_alloc_err:
11119 kfree(bp->init_ops_offsets);
94a78b79
VZ
11120init_offsets_alloc_err:
11121 kfree(bp->init_ops);
11122init_ops_alloc_err:
11123 kfree(bp->init_data);
11124request_firmware_exit:
11125 release_firmware(bp->firmware);
127d0a19 11126 bp->firmware = NULL;
94a78b79
VZ
11127
11128 return rc;
11129}
11130
619c5cb6
VZ
11131static void bnx2x_release_firmware(struct bnx2x *bp)
11132{
11133 kfree(bp->init_ops_offsets);
11134 kfree(bp->init_ops);
11135 kfree(bp->init_data);
11136 release_firmware(bp->firmware);
eb2afd4a 11137 bp->firmware = NULL;
619c5cb6
VZ
11138}
11139
11140
11141static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11142 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11143 .init_hw_cmn = bnx2x_init_hw_common,
11144 .init_hw_port = bnx2x_init_hw_port,
11145 .init_hw_func = bnx2x_init_hw_func,
11146
11147 .reset_hw_cmn = bnx2x_reset_common,
11148 .reset_hw_port = bnx2x_reset_port,
11149 .reset_hw_func = bnx2x_reset_func,
11150
11151 .gunzip_init = bnx2x_gunzip_init,
11152 .gunzip_end = bnx2x_gunzip_end,
11153
11154 .init_fw = bnx2x_init_firmware,
11155 .release_fw = bnx2x_release_firmware,
11156};
11157
11158void bnx2x__init_func_obj(struct bnx2x *bp)
11159{
11160 /* Prepare DMAE related driver resources */
11161 bnx2x_setup_dmae(bp);
11162
11163 bnx2x_init_func_obj(bp, &bp->func_obj,
11164 bnx2x_sp(bp, func_rdata),
11165 bnx2x_sp_mapping(bp, func_rdata),
11166 &bnx2x_func_sp_drv);
11167}
11168
11169/* must be called after sriov-enable */
6383c0b3 11170static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 11171{
6383c0b3 11172 int cid_count = BNX2X_L2_CID_COUNT(bp);
94a78b79 11173
523224a3
DK
11174#ifdef BCM_CNIC
11175 cid_count += CNIC_CID_MAX;
11176#endif
11177 return roundup(cid_count, QM_CID_ROUND);
11178}
f85582f8 11179
619c5cb6 11180/**
6383c0b3 11181 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
11182 *
11183 * @dev: pci device
11184 *
11185 */
6383c0b3 11186static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
619c5cb6
VZ
11187{
11188 int pos;
11189 u16 control;
11190
11191 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
11192
11193 /*
11194 * If MSI-X is not supported - return number of SBs needed to support
11195 * one fast path queue: one FP queue + SB for CNIC
11196 */
619c5cb6 11197 if (!pos)
6383c0b3 11198 return 1 + CNIC_PRESENT;
619c5cb6 11199
6383c0b3
AE
11200 /*
11201 * The value in the PCI configuration space is the index of the last
11202 * entry, namely one less than the actual size of the table, which is
11203 * exactly what we want to return from this function: number of all SBs
11204 * without the default SB.
11205 */
619c5cb6 11206 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
6383c0b3 11207 return control & PCI_MSIX_FLAGS_QSIZE;
619c5cb6
VZ
11208}
11209
a2fbb9ea
ET
11210static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11211 const struct pci_device_id *ent)
11212{
a2fbb9ea
ET
11213 struct net_device *dev = NULL;
11214 struct bnx2x *bp;
37f9ce62 11215 int pcie_width, pcie_speed;
6383c0b3
AE
11216 int rc, max_non_def_sbs;
11217 int rx_count, tx_count, rss_count;
11218 /*
11219 * An estimated maximum supported CoS number according to the chip
11220 * version.
11221 * We will try to roughly estimate the maximum number of CoSes this chip
11222 * may support in order to minimize the memory allocated for Tx
11223 * netdev_queue's. This number will be accurately calculated during the
11224 * initialization of bp->max_cos based on the chip versions AND chip
11225 * revision in the bnx2x_init_bp().
11226 */
11227 u8 max_cos_est = 0;
523224a3 11228
f2e0899f
DK
11229 switch (ent->driver_data) {
11230 case BCM57710:
11231 case BCM57711:
11232 case BCM57711E:
6383c0b3
AE
11233 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
11234 break;
11235
f2e0899f 11236 case BCM57712:
619c5cb6 11237 case BCM57712_MF:
6383c0b3
AE
11238 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
11239 break;
11240
619c5cb6
VZ
11241 case BCM57800:
11242 case BCM57800_MF:
11243 case BCM57810:
11244 case BCM57810_MF:
11245 case BCM57840:
11246 case BCM57840_MF:
6383c0b3 11247 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
f2e0899f 11248 break;
a2fbb9ea 11249
f2e0899f
DK
11250 default:
11251 pr_err("Unknown board_type (%ld), aborting\n",
11252 ent->driver_data);
870634b0 11253 return -ENODEV;
f2e0899f
DK
11254 }
11255
6383c0b3
AE
11256 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
11257
11258 /* !!! FIXME !!!
11259 * Do not allow the maximum SB count to grow above 16
11260 * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
11261 * We will use the FP_SB_MAX_E1x macro for this matter.
11262 */
11263 max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
11264
11265 WARN_ON(!max_non_def_sbs);
11266
11267 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
11268 rss_count = max_non_def_sbs - CNIC_PRESENT;
11269
11270 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
11271 rx_count = rss_count + FCOE_PRESENT;
11272
11273 /*
11274 * Maximum number of netdev Tx queues:
11275 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
11276 */
11277 tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
f85582f8 11278
a2fbb9ea 11279 /* dev zeroed in init_etherdev */
6383c0b3 11280 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 11281 if (!dev)
a2fbb9ea
ET
11282 return -ENOMEM;
11283
a2fbb9ea 11284 bp = netdev_priv(dev);
a2fbb9ea 11285
51c1a580 11286 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
6383c0b3 11287 tx_count, rx_count);
df4770de 11288
6383c0b3
AE
11289 bp->igu_sb_cnt = max_non_def_sbs;
11290 bp->msg_enable = debug;
11291 pci_set_drvdata(pdev, dev);
523224a3 11292
619c5cb6 11293 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
a2fbb9ea
ET
11294 if (rc < 0) {
11295 free_netdev(dev);
11296 return rc;
11297 }
11298
51c1a580 11299 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
619c5cb6 11300
34f80b04 11301 rc = bnx2x_init_bp(bp);
693fc0d1
EG
11302 if (rc)
11303 goto init_one_exit;
11304
6383c0b3
AE
11305 /*
11306 * Map doorbels here as we need the real value of bp->max_cos which
11307 * is initialized in bnx2x_init_bp().
11308 */
11309 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
11310 min_t(u64, BNX2X_DB_SIZE(bp),
11311 pci_resource_len(pdev, 2)));
11312 if (!bp->doorbells) {
11313 dev_err(&bp->pdev->dev,
11314 "Cannot map doorbell space, aborting\n");
11315 rc = -ENOMEM;
11316 goto init_one_exit;
11317 }
11318
523224a3 11319 /* calc qm_cid_count */
6383c0b3 11320 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
523224a3 11321
ec6ba945 11322#ifdef BCM_CNIC
62ac0dc9
DK
11323 /* disable FCOE L2 queue for E1x */
11324 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
11325 bp->flags |= NO_FCOE_FLAG;
11326
11327#endif
11328
25985edc 11329 /* Configure interrupt mode: try to enable MSI-X/MSI if
d6214d7a
DK
11330 * needed, set bp->num_queues appropriately.
11331 */
11332 bnx2x_set_int_mode(bp);
11333
11334 /* Add all NAPI objects */
11335 bnx2x_add_all_napi(bp);
11336
b340007f
VZ
11337 rc = register_netdev(dev);
11338 if (rc) {
11339 dev_err(&pdev->dev, "Cannot register net device\n");
11340 goto init_one_exit;
11341 }
11342
ec6ba945
VZ
11343#ifdef BCM_CNIC
11344 if (!NO_FCOE(bp)) {
11345 /* Add storage MAC address */
11346 rtnl_lock();
11347 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11348 rtnl_unlock();
11349 }
11350#endif
11351
37f9ce62 11352 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
d6214d7a 11353
51c1a580
MS
11354 BNX2X_DEV_INFO(
11355 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
11356 board_info[ent->driver_data].name,
11357 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
11358 pcie_width,
11359 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
11360 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
11361 "5GHz (Gen2)" : "2.5GHz",
11362 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 11363
a2fbb9ea 11364 return 0;
34f80b04
EG
11365
11366init_one_exit:
11367 if (bp->regview)
11368 iounmap(bp->regview);
11369
11370 if (bp->doorbells)
11371 iounmap(bp->doorbells);
11372
11373 free_netdev(dev);
11374
11375 if (atomic_read(&pdev->enable_cnt) == 1)
11376 pci_release_regions(pdev);
11377
11378 pci_disable_device(pdev);
11379 pci_set_drvdata(pdev, NULL);
11380
11381 return rc;
a2fbb9ea
ET
11382}
11383
11384static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11385{
11386 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
11387 struct bnx2x *bp;
11388
11389 if (!dev) {
cdaa7cb8 11390 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
11391 return;
11392 }
228241eb 11393 bp = netdev_priv(dev);
a2fbb9ea 11394
ec6ba945
VZ
11395#ifdef BCM_CNIC
11396 /* Delete storage MAC address */
11397 if (!NO_FCOE(bp)) {
11398 rtnl_lock();
11399 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11400 rtnl_unlock();
11401 }
11402#endif
11403
98507672
SR
11404#ifdef BCM_DCBNL
11405 /* Delete app tlvs from dcbnl */
11406 bnx2x_dcbnl_update_applist(bp, true);
11407#endif
11408
a2fbb9ea
ET
11409 unregister_netdev(dev);
11410
d6214d7a
DK
11411 /* Delete all NAPI objects */
11412 bnx2x_del_all_napi(bp);
11413
084d6cbb
VZ
11414 /* Power on: we can't let PCI layer write to us while we are in D3 */
11415 bnx2x_set_power_state(bp, PCI_D0);
11416
d6214d7a
DK
11417 /* Disable MSI/MSI-X */
11418 bnx2x_disable_msi(bp);
f85582f8 11419
084d6cbb
VZ
11420 /* Power off */
11421 bnx2x_set_power_state(bp, PCI_D3hot);
11422
72fd0718 11423 /* Make sure RESET task is not scheduled before continuing */
7be08a72 11424 cancel_delayed_work_sync(&bp->sp_rtnl_task);
72fd0718 11425
a2fbb9ea
ET
11426 if (bp->regview)
11427 iounmap(bp->regview);
11428
11429 if (bp->doorbells)
11430 iounmap(bp->doorbells);
11431
eb2afd4a
DK
11432 bnx2x_release_firmware(bp);
11433
523224a3
DK
11434 bnx2x_free_mem_bp(bp);
11435
a2fbb9ea 11436 free_netdev(dev);
34f80b04
EG
11437
11438 if (atomic_read(&pdev->enable_cnt) == 1)
11439 pci_release_regions(pdev);
11440
a2fbb9ea
ET
11441 pci_disable_device(pdev);
11442 pci_set_drvdata(pdev, NULL);
11443}
11444
f8ef6e44
YG
11445static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
11446{
11447 int i;
11448
11449 bp->state = BNX2X_STATE_ERROR;
11450
11451 bp->rx_mode = BNX2X_RX_MODE_NONE;
11452
619c5cb6
VZ
11453#ifdef BCM_CNIC
11454 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
11455#endif
11456 /* Stop Tx */
11457 bnx2x_tx_disable(bp);
11458
f8ef6e44
YG
11459 bnx2x_netif_stop(bp, 0);
11460
11461 del_timer_sync(&bp->timer);
619c5cb6
VZ
11462
11463 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
11464
11465 /* Release IRQs */
d6214d7a 11466 bnx2x_free_irq(bp);
f8ef6e44 11467
f8ef6e44
YG
11468 /* Free SKBs, SGEs, TPA pool and driver internals */
11469 bnx2x_free_skbs(bp);
523224a3 11470
ec6ba945 11471 for_each_rx_queue(bp, i)
f8ef6e44 11472 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 11473
f8ef6e44
YG
11474 bnx2x_free_mem(bp);
11475
11476 bp->state = BNX2X_STATE_CLOSED;
11477
619c5cb6
VZ
11478 netif_carrier_off(bp->dev);
11479
f8ef6e44
YG
11480 return 0;
11481}
11482
11483static void bnx2x_eeh_recover(struct bnx2x *bp)
11484{
11485 u32 val;
11486
11487 mutex_init(&bp->port.phy_mutex);
11488
f8ef6e44
YG
11489
11490 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
11491 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11492 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11493 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
11494}
11495
493adb1f
WX
11496/**
11497 * bnx2x_io_error_detected - called when PCI error is detected
11498 * @pdev: Pointer to PCI device
11499 * @state: The current pci connection state
11500 *
11501 * This function is called after a PCI bus error affecting
11502 * this device has been detected.
11503 */
11504static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
11505 pci_channel_state_t state)
11506{
11507 struct net_device *dev = pci_get_drvdata(pdev);
11508 struct bnx2x *bp = netdev_priv(dev);
11509
11510 rtnl_lock();
11511
11512 netif_device_detach(dev);
11513
07ce50e4
DN
11514 if (state == pci_channel_io_perm_failure) {
11515 rtnl_unlock();
11516 return PCI_ERS_RESULT_DISCONNECT;
11517 }
11518
493adb1f 11519 if (netif_running(dev))
f8ef6e44 11520 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
11521
11522 pci_disable_device(pdev);
11523
11524 rtnl_unlock();
11525
11526 /* Request a slot reset */
11527 return PCI_ERS_RESULT_NEED_RESET;
11528}
11529
11530/**
11531 * bnx2x_io_slot_reset - called after the PCI bus has been reset
11532 * @pdev: Pointer to PCI device
11533 *
11534 * Restart the card from scratch, as if from a cold-boot.
11535 */
11536static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
11537{
11538 struct net_device *dev = pci_get_drvdata(pdev);
11539 struct bnx2x *bp = netdev_priv(dev);
11540
11541 rtnl_lock();
11542
11543 if (pci_enable_device(pdev)) {
11544 dev_err(&pdev->dev,
11545 "Cannot re-enable PCI device after reset\n");
11546 rtnl_unlock();
11547 return PCI_ERS_RESULT_DISCONNECT;
11548 }
11549
11550 pci_set_master(pdev);
11551 pci_restore_state(pdev);
11552
11553 if (netif_running(dev))
11554 bnx2x_set_power_state(bp, PCI_D0);
11555
11556 rtnl_unlock();
11557
11558 return PCI_ERS_RESULT_RECOVERED;
11559}
11560
11561/**
11562 * bnx2x_io_resume - called when traffic can start flowing again
11563 * @pdev: Pointer to PCI device
11564 *
11565 * This callback is called when the error recovery driver tells us that
11566 * its OK to resume normal operation.
11567 */
11568static void bnx2x_io_resume(struct pci_dev *pdev)
11569{
11570 struct net_device *dev = pci_get_drvdata(pdev);
11571 struct bnx2x *bp = netdev_priv(dev);
11572
72fd0718 11573 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 11574 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
11575 return;
11576 }
11577
493adb1f
WX
11578 rtnl_lock();
11579
f8ef6e44
YG
11580 bnx2x_eeh_recover(bp);
11581
493adb1f 11582 if (netif_running(dev))
f8ef6e44 11583 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
11584
11585 netif_device_attach(dev);
11586
11587 rtnl_unlock();
11588}
11589
11590static struct pci_error_handlers bnx2x_err_handler = {
11591 .error_detected = bnx2x_io_error_detected,
356e2385
EG
11592 .slot_reset = bnx2x_io_slot_reset,
11593 .resume = bnx2x_io_resume,
493adb1f
WX
11594};
11595
a2fbb9ea 11596static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
11597 .name = DRV_MODULE_NAME,
11598 .id_table = bnx2x_pci_tbl,
11599 .probe = bnx2x_init_one,
11600 .remove = __devexit_p(bnx2x_remove_one),
11601 .suspend = bnx2x_suspend,
11602 .resume = bnx2x_resume,
11603 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
11604};
11605
11606static int __init bnx2x_init(void)
11607{
dd21ca6d
SG
11608 int ret;
11609
7995c64e 11610 pr_info("%s", version);
938cf541 11611
1cf167f2
EG
11612 bnx2x_wq = create_singlethread_workqueue("bnx2x");
11613 if (bnx2x_wq == NULL) {
7995c64e 11614 pr_err("Cannot create workqueue\n");
1cf167f2
EG
11615 return -ENOMEM;
11616 }
11617
dd21ca6d
SG
11618 ret = pci_register_driver(&bnx2x_pci_driver);
11619 if (ret) {
7995c64e 11620 pr_err("Cannot register driver\n");
dd21ca6d
SG
11621 destroy_workqueue(bnx2x_wq);
11622 }
11623 return ret;
a2fbb9ea
ET
11624}
11625
11626static void __exit bnx2x_cleanup(void)
11627{
452427b0 11628 struct list_head *pos, *q;
a2fbb9ea 11629 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
11630
11631 destroy_workqueue(bnx2x_wq);
452427b0
YM
11632
11633 /* Free globablly allocated resources */
11634 list_for_each_safe(pos, q, &bnx2x_prev_list) {
11635 struct bnx2x_prev_path_list *tmp =
11636 list_entry(pos, struct bnx2x_prev_path_list, list);
11637 list_del(pos);
11638 kfree(tmp);
11639 }
a2fbb9ea
ET
11640}
11641
3deb8167
YR
11642void bnx2x_notify_link_changed(struct bnx2x *bp)
11643{
11644 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
11645}
11646
a2fbb9ea
ET
11647module_init(bnx2x_init);
11648module_exit(bnx2x_cleanup);
11649
993ac7b5 11650#ifdef BCM_CNIC
619c5cb6
VZ
11651/**
11652 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
11653 *
11654 * @bp: driver handle
11655 * @set: set or clear the CAM entry
11656 *
11657 * This function will wait until the ramdord completion returns.
11658 * Return 0 if success, -ENODEV if ramrod doesn't return.
11659 */
11660static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
11661{
11662 unsigned long ramrod_flags = 0;
11663
11664 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11665 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
11666 &bp->iscsi_l2_mac_obj, true,
11667 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
11668}
993ac7b5
MC
11669
11670/* count denotes the number of new completions we have seen */
11671static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
11672{
11673 struct eth_spe *spe;
11674
11675#ifdef BNX2X_STOP_ON_ERROR
11676 if (unlikely(bp->panic))
11677 return;
11678#endif
11679
11680 spin_lock_bh(&bp->spq_lock);
c2bff63f 11681 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
11682 bp->cnic_spq_pending -= count;
11683
993ac7b5 11684
c2bff63f
DK
11685 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
11686 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
11687 & SPE_HDR_CONN_TYPE) >>
11688 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
11689 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
11690 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
11691
11692 /* Set validation for iSCSI L2 client before sending SETUP
11693 * ramrod
11694 */
11695 if (type == ETH_CONNECTION_TYPE) {
c2bff63f 11696 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
619c5cb6
VZ
11697 bnx2x_set_ctx_validation(bp, &bp->context.
11698 vcxt[BNX2X_ISCSI_ETH_CID].eth,
11699 BNX2X_ISCSI_ETH_CID);
c2bff63f
DK
11700 }
11701
619c5cb6
VZ
11702 /*
11703 * There may be not more than 8 L2, not more than 8 L5 SPEs
11704 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
11705 * COMMON ramrods is not more than the EQ and SPQ can
11706 * accommodate.
c2bff63f 11707 */
6e30dd4e
VZ
11708 if (type == ETH_CONNECTION_TYPE) {
11709 if (!atomic_read(&bp->cq_spq_left))
11710 break;
11711 else
11712 atomic_dec(&bp->cq_spq_left);
11713 } else if (type == NONE_CONNECTION_TYPE) {
11714 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
11715 break;
11716 else
6e30dd4e 11717 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
11718 } else if ((type == ISCSI_CONNECTION_TYPE) ||
11719 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
11720 if (bp->cnic_spq_pending >=
11721 bp->cnic_eth_dev.max_kwqe_pending)
11722 break;
11723 else
11724 bp->cnic_spq_pending++;
11725 } else {
11726 BNX2X_ERR("Unknown SPE type: %d\n", type);
11727 bnx2x_panic();
993ac7b5 11728 break;
c2bff63f 11729 }
993ac7b5
MC
11730
11731 spe = bnx2x_sp_get_next(bp);
11732 *spe = *bp->cnic_kwq_cons;
11733
51c1a580 11734 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
11735 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
11736
11737 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
11738 bp->cnic_kwq_cons = bp->cnic_kwq;
11739 else
11740 bp->cnic_kwq_cons++;
11741 }
11742 bnx2x_sp_prod_update(bp);
11743 spin_unlock_bh(&bp->spq_lock);
11744}
11745
11746static int bnx2x_cnic_sp_queue(struct net_device *dev,
11747 struct kwqe_16 *kwqes[], u32 count)
11748{
11749 struct bnx2x *bp = netdev_priv(dev);
11750 int i;
11751
11752#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
11753 if (unlikely(bp->panic)) {
11754 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 11755 return -EIO;
51c1a580 11756 }
993ac7b5
MC
11757#endif
11758
95c6c616
AE
11759 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
11760 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 11761 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
11762 return -EAGAIN;
11763 }
11764
993ac7b5
MC
11765 spin_lock_bh(&bp->spq_lock);
11766
11767 for (i = 0; i < count; i++) {
11768 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
11769
11770 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
11771 break;
11772
11773 *bp->cnic_kwq_prod = *spe;
11774
11775 bp->cnic_kwq_pending++;
11776
51c1a580 11777 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 11778 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
11779 spe->data.update_data_addr.hi,
11780 spe->data.update_data_addr.lo,
993ac7b5
MC
11781 bp->cnic_kwq_pending);
11782
11783 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
11784 bp->cnic_kwq_prod = bp->cnic_kwq;
11785 else
11786 bp->cnic_kwq_prod++;
11787 }
11788
11789 spin_unlock_bh(&bp->spq_lock);
11790
11791 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
11792 bnx2x_cnic_sp_post(bp, 0);
11793
11794 return i;
11795}
11796
11797static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11798{
11799 struct cnic_ops *c_ops;
11800 int rc = 0;
11801
11802 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
11803 c_ops = rcu_dereference_protected(bp->cnic_ops,
11804 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
11805 if (c_ops)
11806 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11807 mutex_unlock(&bp->cnic_mutex);
11808
11809 return rc;
11810}
11811
11812static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11813{
11814 struct cnic_ops *c_ops;
11815 int rc = 0;
11816
11817 rcu_read_lock();
11818 c_ops = rcu_dereference(bp->cnic_ops);
11819 if (c_ops)
11820 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11821 rcu_read_unlock();
11822
11823 return rc;
11824}
11825
11826/*
11827 * for commands that have no data
11828 */
9f6c9258 11829int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
11830{
11831 struct cnic_ctl_info ctl = {0};
11832
11833 ctl.cmd = cmd;
11834
11835 return bnx2x_cnic_ctl_send(bp, &ctl);
11836}
11837
619c5cb6 11838static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 11839{
619c5cb6 11840 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
11841
11842 /* first we tell CNIC and only then we count this as a completion */
11843 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
11844 ctl.data.comp.cid = cid;
619c5cb6 11845 ctl.data.comp.error = err;
993ac7b5
MC
11846
11847 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 11848 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
11849}
11850
619c5cb6
VZ
11851
11852/* Called with netif_addr_lock_bh() taken.
11853 * Sets an rx_mode config for an iSCSI ETH client.
11854 * Doesn't block.
11855 * Completion should be checked outside.
11856 */
11857static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
11858{
11859 unsigned long accept_flags = 0, ramrod_flags = 0;
11860 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11861 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
11862
11863 if (start) {
11864 /* Start accepting on iSCSI L2 ring. Accept all multicasts
11865 * because it's the only way for UIO Queue to accept
11866 * multicasts (in non-promiscuous mode only one Queue per
11867 * function will receive multicast packets (leading in our
11868 * case).
11869 */
11870 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
11871 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
11872 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
11873 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
11874
11875 /* Clear STOP_PENDING bit if START is requested */
11876 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
11877
11878 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
11879 } else
11880 /* Clear START_PENDING bit if STOP is requested */
11881 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
11882
11883 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
11884 set_bit(sched_state, &bp->sp_state);
11885 else {
11886 __set_bit(RAMROD_RX, &ramrod_flags);
11887 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
11888 ramrod_flags);
11889 }
11890}
11891
11892
993ac7b5
MC
11893static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
11894{
11895 struct bnx2x *bp = netdev_priv(dev);
11896 int rc = 0;
11897
11898 switch (ctl->cmd) {
11899 case DRV_CTL_CTXTBL_WR_CMD: {
11900 u32 index = ctl->data.io.offset;
11901 dma_addr_t addr = ctl->data.io.dma_addr;
11902
11903 bnx2x_ilt_wr(bp, index, addr);
11904 break;
11905 }
11906
c2bff63f
DK
11907 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
11908 int count = ctl->data.credit.credit_count;
993ac7b5
MC
11909
11910 bnx2x_cnic_sp_post(bp, count);
11911 break;
11912 }
11913
11914 /* rtnl_lock is held. */
11915 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
11916 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11917 unsigned long sp_bits = 0;
11918
11919 /* Configure the iSCSI classification object */
11920 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
11921 cp->iscsi_l2_client_id,
11922 cp->iscsi_l2_cid, BP_FUNC(bp),
11923 bnx2x_sp(bp, mac_rdata),
11924 bnx2x_sp_mapping(bp, mac_rdata),
11925 BNX2X_FILTER_MAC_PENDING,
11926 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
11927 &bp->macs_pool);
ec6ba945 11928
523224a3 11929 /* Set iSCSI MAC address */
619c5cb6
VZ
11930 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
11931 if (rc)
11932 break;
523224a3
DK
11933
11934 mmiowb();
11935 barrier();
11936
619c5cb6
VZ
11937 /* Start accepting on iSCSI L2 ring */
11938
11939 netif_addr_lock_bh(dev);
11940 bnx2x_set_iscsi_eth_rx_mode(bp, true);
11941 netif_addr_unlock_bh(dev);
11942
11943 /* bits to wait on */
11944 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11945 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
11946
11947 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11948 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 11949
993ac7b5
MC
11950 break;
11951 }
11952
11953 /* rtnl_lock is held. */
11954 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 11955 unsigned long sp_bits = 0;
993ac7b5 11956
523224a3 11957 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
11958 netif_addr_lock_bh(dev);
11959 bnx2x_set_iscsi_eth_rx_mode(bp, false);
11960 netif_addr_unlock_bh(dev);
11961
11962 /* bits to wait on */
11963 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11964 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
11965
11966 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11967 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
11968
11969 mmiowb();
11970 barrier();
11971
11972 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
11973 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
11974 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
11975 break;
11976 }
c2bff63f
DK
11977 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
11978 int count = ctl->data.credit.credit_count;
11979
11980 smp_mb__before_atomic_inc();
6e30dd4e 11981 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
11982 smp_mb__after_atomic_inc();
11983 break;
11984 }
1d187b34
BW
11985 case DRV_CTL_ULP_REGISTER_CMD: {
11986 int ulp_type = ctl->data.ulp_type;
11987
11988 if (CHIP_IS_E3(bp)) {
11989 int idx = BP_FW_MB_IDX(bp);
11990 u32 cap;
11991
11992 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
11993 if (ulp_type == CNIC_ULP_ISCSI)
11994 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
11995 else if (ulp_type == CNIC_ULP_FCOE)
11996 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
11997 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
11998 }
11999 break;
12000 }
12001 case DRV_CTL_ULP_UNREGISTER_CMD: {
12002 int ulp_type = ctl->data.ulp_type;
12003
12004 if (CHIP_IS_E3(bp)) {
12005 int idx = BP_FW_MB_IDX(bp);
12006 u32 cap;
12007
12008 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12009 if (ulp_type == CNIC_ULP_ISCSI)
12010 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12011 else if (ulp_type == CNIC_ULP_FCOE)
12012 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12013 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12014 }
12015 break;
12016 }
993ac7b5
MC
12017
12018 default:
12019 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12020 rc = -EINVAL;
12021 }
12022
12023 return rc;
12024}
12025
9f6c9258 12026void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
12027{
12028 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12029
12030 if (bp->flags & USING_MSIX_FLAG) {
12031 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12032 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12033 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12034 } else {
12035 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12036 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12037 }
619c5cb6 12038 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
12039 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12040 else
12041 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12042
619c5cb6
VZ
12043 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12044 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
12045 cp->irq_arr[1].status_blk = bp->def_status_blk;
12046 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 12047 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
12048
12049 cp->num_irq = 2;
12050}
12051
12052static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12053 void *data)
12054{
12055 struct bnx2x *bp = netdev_priv(dev);
12056 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12057
51c1a580
MS
12058 if (ops == NULL) {
12059 BNX2X_ERR("NULL ops received\n");
993ac7b5 12060 return -EINVAL;
51c1a580 12061 }
993ac7b5 12062
993ac7b5
MC
12063 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12064 if (!bp->cnic_kwq)
12065 return -ENOMEM;
12066
12067 bp->cnic_kwq_cons = bp->cnic_kwq;
12068 bp->cnic_kwq_prod = bp->cnic_kwq;
12069 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12070
12071 bp->cnic_spq_pending = 0;
12072 bp->cnic_kwq_pending = 0;
12073
12074 bp->cnic_data = data;
12075
12076 cp->num_irq = 0;
619c5cb6 12077 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 12078 cp->iro_arr = bp->iro_arr;
993ac7b5 12079
993ac7b5 12080 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 12081
993ac7b5
MC
12082 rcu_assign_pointer(bp->cnic_ops, ops);
12083
12084 return 0;
12085}
12086
12087static int bnx2x_unregister_cnic(struct net_device *dev)
12088{
12089 struct bnx2x *bp = netdev_priv(dev);
12090 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12091
12092 mutex_lock(&bp->cnic_mutex);
993ac7b5 12093 cp->drv_state = 0;
2cfa5a04 12094 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
12095 mutex_unlock(&bp->cnic_mutex);
12096 synchronize_rcu();
12097 kfree(bp->cnic_kwq);
12098 bp->cnic_kwq = NULL;
12099
12100 return 0;
12101}
12102
12103struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12104{
12105 struct bnx2x *bp = netdev_priv(dev);
12106 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12107
2ba45142
VZ
12108 /* If both iSCSI and FCoE are disabled - return NULL in
12109 * order to indicate CNIC that it should not try to work
12110 * with this device.
12111 */
12112 if (NO_ISCSI(bp) && NO_FCOE(bp))
12113 return NULL;
12114
993ac7b5
MC
12115 cp->drv_owner = THIS_MODULE;
12116 cp->chip_id = CHIP_ID(bp);
12117 cp->pdev = bp->pdev;
12118 cp->io_base = bp->regview;
12119 cp->io_base2 = bp->doorbells;
12120 cp->max_kwqe_pending = 8;
523224a3 12121 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
12122 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12123 bnx2x_cid_ilt_lines(bp);
993ac7b5 12124 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 12125 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
12126 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12127 cp->drv_ctl = bnx2x_drv_ctl;
12128 cp->drv_register_cnic = bnx2x_register_cnic;
12129 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
ec6ba945 12130 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
619c5cb6
VZ
12131 cp->iscsi_l2_client_id =
12132 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
c2bff63f
DK
12133 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
12134
2ba45142
VZ
12135 if (NO_ISCSI_OOO(bp))
12136 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12137
12138 if (NO_ISCSI(bp))
12139 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12140
12141 if (NO_FCOE(bp))
12142 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12143
51c1a580
MS
12144 BNX2X_DEV_INFO(
12145 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
12146 cp->ctx_blk_size,
12147 cp->ctx_tbl_offset,
12148 cp->ctx_tbl_len,
12149 cp->starting_cid);
993ac7b5
MC
12150 return cp;
12151}
12152EXPORT_SYMBOL(bnx2x_cnic_probe);
12153
12154#endif /* BCM_CNIC */
94a78b79 12155