bnx2x: mask CPL_OF interrupt
[linux-2.6-block.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
2e499d3c
BW
77#define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
78
34f80b04
EG
79/* Time in jiffies before concluding the transmitter is hung */
80#define TX_TIMEOUT (5*HZ)
a2fbb9ea 81
53a10565 82static char version[] __devinitdata =
619c5cb6 83 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
84 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
85
24e3fcef 86MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 87MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
88 "BCM57710/57711/57711E/"
89 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
90 "57840/57840_MF Driver");
a2fbb9ea
ET
91MODULE_LICENSE("GPL");
92MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
93MODULE_FIRMWARE(FW_FILE_NAME_E1);
94MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 95MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 96
ca00392c 97
d6214d7a 98int num_queues;
54b9ddaa 99module_param(num_queues, int, 0);
96305234
DK
100MODULE_PARM_DESC(num_queues,
101 " Set number of queues (default is as a number of CPUs)");
555f6c78 102
19680c48 103static int disable_tpa;
19680c48 104module_param(disable_tpa, int, 0);
9898f86d 105MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 106
9ee3d37b
DK
107#define INT_MODE_INTx 1
108#define INT_MODE_MSI 2
0e8d2ec5 109int int_mode;
8badd27a 110module_param(int_mode, int, 0);
619c5cb6 111MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 112 "(1 INT#x; 2 MSI)");
8badd27a 113
a18f5128
EG
114static int dropless_fc;
115module_param(dropless_fc, int, 0);
116MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
117
8d5726c4
EG
118static int mrrs = -1;
119module_param(mrrs, int, 0);
120MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
121
9898f86d 122static int debug;
a2fbb9ea 123module_param(debug, int, 0);
9898f86d
EG
124MODULE_PARM_DESC(debug, " Default debug msglevel");
125
a2fbb9ea 126
619c5cb6
VZ
127
128struct workqueue_struct *bnx2x_wq;
ec6ba945 129
a2fbb9ea
ET
130enum bnx2x_board_type {
131 BCM57710 = 0,
619c5cb6
VZ
132 BCM57711,
133 BCM57711E,
134 BCM57712,
135 BCM57712_MF,
136 BCM57800,
137 BCM57800_MF,
138 BCM57810,
139 BCM57810_MF,
c3def943
YM
140 BCM57840_O,
141 BCM57840_4_10,
142 BCM57840_2_20,
143 BCM57840_MFO,
7e8e02df
BW
144 BCM57840_MF,
145 BCM57811,
146 BCM57811_MF
a2fbb9ea
ET
147};
148
34f80b04 149/* indexed by board_type, above */
53a10565 150static struct {
a2fbb9ea
ET
151 char *name;
152} board_info[] __devinitdata = {
619c5cb6
VZ
153 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
154 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
155 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
156 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
157 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
158 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
159 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
160 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
161 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
162 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
c3def943
YM
163 { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
164 { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
165 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
7e8e02df
BW
166 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
167 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
168 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
a2fbb9ea
ET
169};
170
619c5cb6
VZ
171#ifndef PCI_DEVICE_ID_NX2_57710
172#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
173#endif
174#ifndef PCI_DEVICE_ID_NX2_57711
175#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
176#endif
177#ifndef PCI_DEVICE_ID_NX2_57711E
178#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
179#endif
180#ifndef PCI_DEVICE_ID_NX2_57712
181#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
182#endif
183#ifndef PCI_DEVICE_ID_NX2_57712_MF
184#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
185#endif
186#ifndef PCI_DEVICE_ID_NX2_57800
187#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
188#endif
189#ifndef PCI_DEVICE_ID_NX2_57800_MF
190#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
191#endif
192#ifndef PCI_DEVICE_ID_NX2_57810
193#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
194#endif
195#ifndef PCI_DEVICE_ID_NX2_57810_MF
196#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
197#endif
c3def943
YM
198#ifndef PCI_DEVICE_ID_NX2_57840_O
199#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
200#endif
201#ifndef PCI_DEVICE_ID_NX2_57840_4_10
202#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
203#endif
204#ifndef PCI_DEVICE_ID_NX2_57840_2_20
205#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
206#endif
207#ifndef PCI_DEVICE_ID_NX2_57840_MFO
208#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
619c5cb6
VZ
209#endif
210#ifndef PCI_DEVICE_ID_NX2_57840_MF
211#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
212#endif
7e8e02df
BW
213#ifndef PCI_DEVICE_ID_NX2_57811
214#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
215#endif
216#ifndef PCI_DEVICE_ID_NX2_57811_MF
217#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
218#endif
a3aa1884 219static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
220 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
221 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
222 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 223 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6
VZ
224 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
225 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
226 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
227 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
228 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
c3def943
YM
229 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
230 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
231 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
232 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
619c5cb6 233 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
7e8e02df
BW
234 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
235 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
a2fbb9ea
ET
236 { 0 }
237};
238
239MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
240
452427b0
YM
241/* Global resources for unloading a previously loaded device */
242#define BNX2X_PREV_WAIT_NEEDED 1
243static DEFINE_SEMAPHORE(bnx2x_prev_sem);
244static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
245/****************************************************************************
246* General service functions
247****************************************************************************/
248
1191cb83 249static void __storm_memset_dma_mapping(struct bnx2x *bp,
619c5cb6
VZ
250 u32 addr, dma_addr_t mapping)
251{
252 REG_WR(bp, addr, U64_LO(mapping));
253 REG_WR(bp, addr + 4, U64_HI(mapping));
254}
255
1191cb83
ED
256static void storm_memset_spq_addr(struct bnx2x *bp,
257 dma_addr_t mapping, u16 abs_fid)
619c5cb6
VZ
258{
259 u32 addr = XSEM_REG_FAST_MEMORY +
260 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
261
262 __storm_memset_dma_mapping(bp, addr, mapping);
263}
264
1191cb83
ED
265static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
266 u16 pf_id)
523224a3 267{
619c5cb6
VZ
268 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
269 pf_id);
270 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
271 pf_id);
272 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
273 pf_id);
274 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
275 pf_id);
523224a3
DK
276}
277
1191cb83
ED
278static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
279 u8 enable)
619c5cb6
VZ
280{
281 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
282 enable);
283 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
284 enable);
285 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
286 enable);
287 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
288 enable);
289}
523224a3 290
1191cb83
ED
291static void storm_memset_eq_data(struct bnx2x *bp,
292 struct event_ring_data *eq_data,
523224a3
DK
293 u16 pfid)
294{
295 size_t size = sizeof(struct event_ring_data);
296
297 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
298
299 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
300}
301
1191cb83
ED
302static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
303 u16 pfid)
523224a3
DK
304{
305 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
306 REG_WR16(bp, addr, eq_prod);
307}
308
a2fbb9ea
ET
309/* used only at init
310 * locking is done by mcp
311 */
8d96286a 312static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
313{
314 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
315 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
316 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
317 PCICFG_VENDOR_ID_OFFSET);
318}
319
a2fbb9ea
ET
320static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
321{
322 u32 val;
323
324 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
325 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
326 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
327 PCICFG_VENDOR_ID_OFFSET);
328
329 return val;
330}
a2fbb9ea 331
f2e0899f
DK
332#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
333#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
334#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
335#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
336#define DMAE_DP_DST_NONE "dst_addr [none]"
337
f2e0899f 338
a2fbb9ea 339/* copy command into DMAE command memory and set DMAE command go */
6c719d00 340void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
341{
342 u32 cmd_offset;
343 int i;
344
345 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
346 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
347 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
348 }
349 REG_WR(bp, dmae_reg_go_c[idx], 1);
350}
351
f2e0899f 352u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 353{
f2e0899f
DK
354 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
355 DMAE_CMD_C_ENABLE);
356}
ad8d3948 357
f2e0899f
DK
358u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
359{
360 return opcode & ~DMAE_CMD_SRC_RESET;
361}
ad8d3948 362
f2e0899f
DK
363u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
364 bool with_comp, u8 comp_type)
365{
366 u32 opcode = 0;
367
368 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
369 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 370
f2e0899f
DK
371 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
372
373 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
374 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
375 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 376 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 377
a2fbb9ea 378#ifdef __BIG_ENDIAN
f2e0899f 379 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 380#else
f2e0899f 381 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 382#endif
f2e0899f
DK
383 if (with_comp)
384 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
385 return opcode;
386}
387
8d96286a 388static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
389 struct dmae_command *dmae,
390 u8 src_type, u8 dst_type)
f2e0899f
DK
391{
392 memset(dmae, 0, sizeof(struct dmae_command));
393
394 /* set the opcode */
395 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
396 true, DMAE_COMP_PCI);
397
398 /* fill in the completion parameters */
399 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
400 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
401 dmae->comp_val = DMAE_COMP_VAL;
402}
403
404/* issue a dmae command over the init-channel and wailt for completion */
8d96286a 405static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
406 struct dmae_command *dmae)
f2e0899f
DK
407{
408 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
5e374b5a 409 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
410 int rc = 0;
411
619c5cb6
VZ
412 /*
413 * Lock the dmae channel. Disable BHs to prevent a dead-lock
414 * as long as this code is called both from syscall context and
415 * from ndo_set_rx_mode() flow that may be called from BH.
416 */
6e30dd4e 417 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 418
f2e0899f 419 /* reset completion */
a2fbb9ea
ET
420 *wb_comp = 0;
421
f2e0899f
DK
422 /* post the command on the channel used for initializations */
423 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 424
f2e0899f 425 /* wait for completion */
a2fbb9ea 426 udelay(5);
f2e0899f 427 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 428
95c6c616
AE
429 if (!cnt ||
430 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
431 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 432 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
433 rc = DMAE_TIMEOUT;
434 goto unlock;
a2fbb9ea 435 }
ad8d3948 436 cnt--;
f2e0899f 437 udelay(50);
a2fbb9ea 438 }
f2e0899f
DK
439 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
440 BNX2X_ERR("DMAE PCI error!\n");
441 rc = DMAE_PCI_ERROR;
442 }
443
f2e0899f 444unlock:
6e30dd4e 445 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
446 return rc;
447}
448
449void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
450 u32 len32)
451{
452 struct dmae_command dmae;
453
454 if (!bp->dmae_ready) {
455 u32 *data = bnx2x_sp(bp, wb_data[0]);
456
127a425e
AE
457 if (CHIP_IS_E1(bp))
458 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
459 else
460 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
461 return;
462 }
463
464 /* set opcode and fixed command fields */
465 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
466
467 /* fill in addresses and len */
468 dmae.src_addr_lo = U64_LO(dma_addr);
469 dmae.src_addr_hi = U64_HI(dma_addr);
470 dmae.dst_addr_lo = dst_addr >> 2;
471 dmae.dst_addr_hi = 0;
472 dmae.len = len32;
473
f2e0899f
DK
474 /* issue the command and wait for completion */
475 bnx2x_issue_dmae_with_comp(bp, &dmae);
a2fbb9ea
ET
476}
477
c18487ee 478void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 479{
5ff7b6d4 480 struct dmae_command dmae;
ad8d3948
EG
481
482 if (!bp->dmae_ready) {
483 u32 *data = bnx2x_sp(bp, wb_data[0]);
484 int i;
485
51c1a580 486 if (CHIP_IS_E1(bp))
127a425e
AE
487 for (i = 0; i < len32; i++)
488 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 489 else
127a425e
AE
490 for (i = 0; i < len32; i++)
491 data[i] = REG_RD(bp, src_addr + i*4);
492
ad8d3948
EG
493 return;
494 }
495
f2e0899f
DK
496 /* set opcode and fixed command fields */
497 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 498
f2e0899f 499 /* fill in addresses and len */
5ff7b6d4
EG
500 dmae.src_addr_lo = src_addr >> 2;
501 dmae.src_addr_hi = 0;
502 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
503 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
504 dmae.len = len32;
ad8d3948 505
f2e0899f
DK
506 /* issue the command and wait for completion */
507 bnx2x_issue_dmae_with_comp(bp, &dmae);
ad8d3948
EG
508}
509
8d96286a 510static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
511 u32 addr, u32 len)
573f2035 512{
02e3c6cb 513 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
514 int offset = 0;
515
02e3c6cb 516 while (len > dmae_wr_max) {
573f2035 517 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
518 addr + offset, dmae_wr_max);
519 offset += dmae_wr_max * 4;
520 len -= dmae_wr_max;
573f2035
EG
521 }
522
523 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
524}
525
a2fbb9ea
ET
526static int bnx2x_mc_assert(struct bnx2x *bp)
527{
a2fbb9ea 528 char last_idx;
34f80b04
EG
529 int i, rc = 0;
530 u32 row0, row1, row2, row3;
531
532 /* XSTORM */
533 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
534 XSTORM_ASSERT_LIST_INDEX_OFFSET);
535 if (last_idx)
536 BNX2X_ERR("XSTORM_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_XSTRORM_INTMEM +
542 XSTORM_ASSERT_LIST_OFFSET(i));
543 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
544 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
545 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
546 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
547 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
548 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
549
550 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 551 BNX2X_ERR("XSTORM_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 /* TSTORM */
560 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
561 TSTORM_ASSERT_LIST_INDEX_OFFSET);
562 if (last_idx)
563 BNX2X_ERR("TSTORM_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_TSTRORM_INTMEM +
569 TSTORM_ASSERT_LIST_OFFSET(i));
570 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
571 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
572 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
573 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
574 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
575 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
576
577 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 578 BNX2X_ERR("TSTORM_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 /* CSTORM */
587 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
588 CSTORM_ASSERT_LIST_INDEX_OFFSET);
589 if (last_idx)
590 BNX2X_ERR("CSTORM_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_CSTRORM_INTMEM +
596 CSTORM_ASSERT_LIST_OFFSET(i));
597 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
598 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
599 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
600 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
601 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
602 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
603
604 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 605 BNX2X_ERR("CSTORM_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;
610 }
611 }
612
613 /* USTORM */
614 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
615 USTORM_ASSERT_LIST_INDEX_OFFSET);
616 if (last_idx)
617 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
618
619 /* print the asserts */
620 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
621
622 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
623 USTORM_ASSERT_LIST_OFFSET(i));
624 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
625 USTORM_ASSERT_LIST_OFFSET(i) + 4);
626 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
627 USTORM_ASSERT_LIST_OFFSET(i) + 8);
628 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
629 USTORM_ASSERT_LIST_OFFSET(i) + 12);
630
631 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 632 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
633 i, row3, row2, row1, row0);
634 rc++;
635 } else {
636 break;
a2fbb9ea
ET
637 }
638 }
34f80b04 639
a2fbb9ea
ET
640 return rc;
641}
c14423fe 642
7a25cc73 643void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 644{
7a25cc73 645 u32 addr, val;
a2fbb9ea 646 u32 mark, offset;
4781bfad 647 __be32 data[9];
a2fbb9ea 648 int word;
f2e0899f 649 u32 trace_shmem_base;
2145a920
VZ
650 if (BP_NOMCP(bp)) {
651 BNX2X_ERR("NO MCP - can not dump\n");
652 return;
653 }
7a25cc73
DK
654 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
655 (bp->common.bc_ver & 0xff0000) >> 16,
656 (bp->common.bc_ver & 0xff00) >> 8,
657 (bp->common.bc_ver & 0xff));
658
659 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
660 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 661 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 662
f2e0899f
DK
663 if (BP_PATH(bp) == 0)
664 trace_shmem_base = bp->common.shmem_base;
665 else
666 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
de128804
DK
667 addr = trace_shmem_base - 0x800;
668
669 /* validate TRCB signature */
670 mark = REG_RD(bp, addr);
671 if (mark != MFW_TRACE_SIGNATURE) {
672 BNX2X_ERR("Trace buffer signature is missing.");
673 return ;
674 }
675
676 /* read cyclic buffer pointer */
677 addr += 4;
cdaa7cb8 678 mark = REG_RD(bp, addr);
f2e0899f
DK
679 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
680 + ((mark + 0x3) & ~0x3) - 0x08000000;
7a25cc73 681 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 682
7a25cc73 683 printk("%s", lvl);
f2e0899f 684 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 685 for (word = 0; word < 8; word++)
cdaa7cb8 686 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 687 data[8] = 0x0;
7995c64e 688 pr_cont("%s", (char *)data);
a2fbb9ea 689 }
cdaa7cb8 690 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 691 for (word = 0; word < 8; word++)
cdaa7cb8 692 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 693 data[8] = 0x0;
7995c64e 694 pr_cont("%s", (char *)data);
a2fbb9ea 695 }
7a25cc73
DK
696 printk("%s" "end of fw dump\n", lvl);
697}
698
1191cb83 699static void bnx2x_fw_dump(struct bnx2x *bp)
7a25cc73
DK
700{
701 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
702}
703
6c719d00 704void bnx2x_panic_dump(struct bnx2x *bp)
a2fbb9ea
ET
705{
706 int i;
523224a3
DK
707 u16 j;
708 struct hc_sp_status_block_data sp_sb_data;
709 int func = BP_FUNC(bp);
710#ifdef BNX2X_STOP_ON_ERROR
711 u16 start = 0, end = 0;
6383c0b3 712 u8 cos;
523224a3 713#endif
a2fbb9ea 714
66e855f3 715 bp->stats_state = STATS_STATE_DISABLED;
7a752993 716 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
717 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
718
a2fbb9ea
ET
719 BNX2X_ERR("begin crash dump -----------------\n");
720
8440d2b6
EG
721 /* Indices */
722 /* Common */
51c1a580 723 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
724 bp->def_idx, bp->def_att_idx, bp->attn_state,
725 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
726 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
727 bp->def_status_blk->atten_status_block.attn_bits,
728 bp->def_status_blk->atten_status_block.attn_bits_ack,
729 bp->def_status_blk->atten_status_block.status_block_id,
730 bp->def_status_blk->atten_status_block.attn_bits_index);
731 BNX2X_ERR(" def (");
732 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
733 pr_cont("0x%x%s",
f1deab50
JP
734 bp->def_status_blk->sp_sb.index_values[i],
735 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
736
737 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
738 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
739 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
740 i*sizeof(u32));
741
f1deab50 742 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
743 sp_sb_data.igu_sb_id,
744 sp_sb_data.igu_seg_id,
745 sp_sb_data.p_func.pf_id,
746 sp_sb_data.p_func.vnic_id,
747 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
748 sp_sb_data.p_func.vf_valid,
749 sp_sb_data.state);
523224a3 750
8440d2b6 751
ec6ba945 752 for_each_eth_queue(bp, i) {
a2fbb9ea 753 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 754 int loop;
f2e0899f 755 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
756 struct hc_status_block_data_e1x sb_data_e1x;
757 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
758 CHIP_IS_E1x(bp) ?
759 sb_data_e1x.common.state_machine :
760 sb_data_e2.common.state_machine;
523224a3 761 struct hc_index_data *hc_index_p =
619c5cb6
VZ
762 CHIP_IS_E1x(bp) ?
763 sb_data_e1x.index_data :
764 sb_data_e2.index_data;
6383c0b3 765 u8 data_size, cos;
523224a3 766 u32 *sb_data_p;
6383c0b3 767 struct bnx2x_fp_txdata txdata;
523224a3
DK
768
769 /* Rx */
51c1a580 770 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 771 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 772 fp->rx_comp_prod,
66e855f3 773 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 774 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 775 fp->rx_sge_prod, fp->last_max_sge,
523224a3 776 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 777
523224a3 778 /* Tx */
6383c0b3
AE
779 for_each_cos_in_tx_queue(fp, cos)
780 {
65565884 781 txdata = *fp->txdata_ptr[cos];
51c1a580 782 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
783 i, txdata.tx_pkt_prod,
784 txdata.tx_pkt_cons, txdata.tx_bd_prod,
785 txdata.tx_bd_cons,
786 le16_to_cpu(*txdata.tx_cons_sb));
787 }
523224a3 788
619c5cb6
VZ
789 loop = CHIP_IS_E1x(bp) ?
790 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
791
792 /* host sb data */
793
ec6ba945
VZ
794 if (IS_FCOE_FP(fp))
795 continue;
55c11941 796
523224a3
DK
797 BNX2X_ERR(" run indexes (");
798 for (j = 0; j < HC_SB_MAX_SM; j++)
799 pr_cont("0x%x%s",
800 fp->sb_running_index[j],
801 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
802
803 BNX2X_ERR(" indexes (");
804 for (j = 0; j < loop; j++)
805 pr_cont("0x%x%s",
806 fp->sb_index_values[j],
807 (j == loop - 1) ? ")" : " ");
808 /* fw sb data */
619c5cb6
VZ
809 data_size = CHIP_IS_E1x(bp) ?
810 sizeof(struct hc_status_block_data_e1x) :
811 sizeof(struct hc_status_block_data_e2);
523224a3 812 data_size /= sizeof(u32);
619c5cb6
VZ
813 sb_data_p = CHIP_IS_E1x(bp) ?
814 (u32 *)&sb_data_e1x :
815 (u32 *)&sb_data_e2;
523224a3
DK
816 /* copy sb data in here */
817 for (j = 0; j < data_size; j++)
818 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
819 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
820 j * sizeof(u32));
821
619c5cb6 822 if (!CHIP_IS_E1x(bp)) {
51c1a580 823 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
824 sb_data_e2.common.p_func.pf_id,
825 sb_data_e2.common.p_func.vf_id,
826 sb_data_e2.common.p_func.vf_valid,
827 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
828 sb_data_e2.common.same_igu_sb_1b,
829 sb_data_e2.common.state);
f2e0899f 830 } else {
51c1a580 831 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
832 sb_data_e1x.common.p_func.pf_id,
833 sb_data_e1x.common.p_func.vf_id,
834 sb_data_e1x.common.p_func.vf_valid,
835 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
836 sb_data_e1x.common.same_igu_sb_1b,
837 sb_data_e1x.common.state);
f2e0899f 838 }
523224a3
DK
839
840 /* SB_SMs data */
841 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
842 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",
843 j, hc_sm_p[j].__flags,
844 hc_sm_p[j].igu_sb_id,
845 hc_sm_p[j].igu_seg_id,
846 hc_sm_p[j].time_to_expire,
847 hc_sm_p[j].timer_value);
523224a3
DK
848 }
849
850 /* Indecies data */
851 for (j = 0; j < loop; j++) {
51c1a580 852 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
853 hc_index_p[j].flags,
854 hc_index_p[j].timeout);
855 }
8440d2b6 856 }
a2fbb9ea 857
523224a3 858#ifdef BNX2X_STOP_ON_ERROR
8440d2b6
EG
859 /* Rings */
860 /* Rx */
55c11941 861 for_each_valid_rx_queue(bp, i) {
8440d2b6 862 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
863
864 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
865 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 866 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
867 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
868 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
869
c3eefaf6 870 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 871 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
872 }
873
3196a88a
EG
874 start = RX_SGE(fp->rx_sge_prod);
875 end = RX_SGE(fp->last_max_sge);
8440d2b6 876 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
877 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
878 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
879
c3eefaf6
EG
880 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
881 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
882 }
883
a2fbb9ea
ET
884 start = RCQ_BD(fp->rx_comp_cons - 10);
885 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 886 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
887 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
888
c3eefaf6
EG
889 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
890 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
891 }
892 }
893
8440d2b6 894 /* Tx */
55c11941 895 for_each_valid_tx_queue(bp, i) {
8440d2b6 896 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3 897 for_each_cos_in_tx_queue(fp, cos) {
65565884 898 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
6383c0b3
AE
899
900 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
901 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
902 for (j = start; j != end; j = TX_BD(j + 1)) {
903 struct sw_tx_bd *sw_bd =
904 &txdata->tx_buf_ring[j];
905
51c1a580 906 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
907 i, cos, j, sw_bd->skb,
908 sw_bd->first_bd);
909 }
8440d2b6 910
6383c0b3
AE
911 start = TX_BD(txdata->tx_bd_cons - 10);
912 end = TX_BD(txdata->tx_bd_cons + 254);
913 for (j = start; j != end; j = TX_BD(j + 1)) {
914 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 915
51c1a580 916 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
917 i, cos, j, tx_bd[0], tx_bd[1],
918 tx_bd[2], tx_bd[3]);
919 }
8440d2b6
EG
920 }
921 }
523224a3 922#endif
34f80b04 923 bnx2x_fw_dump(bp);
a2fbb9ea
ET
924 bnx2x_mc_assert(bp);
925 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
926}
927
619c5cb6
VZ
928/*
929 * FLR Support for E2
930 *
931 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
932 * initialization.
933 */
934#define FLR_WAIT_USEC 10000 /* 10 miliseconds */
89db4ad8
AE
935#define FLR_WAIT_INTERVAL 50 /* usec */
936#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
937
938struct pbf_pN_buf_regs {
939 int pN;
940 u32 init_crd;
941 u32 crd;
942 u32 crd_freed;
943};
944
945struct pbf_pN_cmd_regs {
946 int pN;
947 u32 lines_occup;
948 u32 lines_freed;
949};
950
951static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
952 struct pbf_pN_buf_regs *regs,
953 u32 poll_count)
954{
955 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
956 u32 cur_cnt = poll_count;
957
958 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
959 crd = crd_start = REG_RD(bp, regs->crd);
960 init_crd = REG_RD(bp, regs->init_crd);
961
962 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
963 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
964 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
965
966 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
967 (init_crd - crd_start))) {
968 if (cur_cnt--) {
89db4ad8 969 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
970 crd = REG_RD(bp, regs->crd);
971 crd_freed = REG_RD(bp, regs->crd_freed);
972 } else {
973 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
974 regs->pN);
975 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
976 regs->pN, crd);
977 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
978 regs->pN, crd_freed);
979 break;
980 }
981 }
982 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 983 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
984}
985
986static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
987 struct pbf_pN_cmd_regs *regs,
988 u32 poll_count)
989{
990 u32 occup, to_free, freed, freed_start;
991 u32 cur_cnt = poll_count;
992
993 occup = to_free = REG_RD(bp, regs->lines_occup);
994 freed = freed_start = REG_RD(bp, regs->lines_freed);
995
996 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
997 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
998
999 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1000 if (cur_cnt--) {
89db4ad8 1001 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1002 occup = REG_RD(bp, regs->lines_occup);
1003 freed = REG_RD(bp, regs->lines_freed);
1004 } else {
1005 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1006 regs->pN);
1007 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1008 regs->pN, occup);
1009 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1010 regs->pN, freed);
1011 break;
1012 }
1013 }
1014 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 1015 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1016}
1017
1191cb83
ED
1018static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1019 u32 expected, u32 poll_count)
619c5cb6
VZ
1020{
1021 u32 cur_cnt = poll_count;
1022 u32 val;
1023
1024 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 1025 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1026
1027 return val;
1028}
1029
1191cb83
ED
1030static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1031 char *msg, u32 poll_cnt)
619c5cb6
VZ
1032{
1033 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1034 if (val != 0) {
1035 BNX2X_ERR("%s usage count=%d\n", msg, val);
1036 return 1;
1037 }
1038 return 0;
1039}
1040
1041static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1042{
1043 /* adjust polling timeout */
1044 if (CHIP_REV_IS_EMUL(bp))
1045 return FLR_POLL_CNT * 2000;
1046
1047 if (CHIP_REV_IS_FPGA(bp))
1048 return FLR_POLL_CNT * 120;
1049
1050 return FLR_POLL_CNT;
1051}
1052
1053static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1054{
1055 struct pbf_pN_cmd_regs cmd_regs[] = {
1056 {0, (CHIP_IS_E3B0(bp)) ?
1057 PBF_REG_TQ_OCCUPANCY_Q0 :
1058 PBF_REG_P0_TQ_OCCUPANCY,
1059 (CHIP_IS_E3B0(bp)) ?
1060 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1061 PBF_REG_P0_TQ_LINES_FREED_CNT},
1062 {1, (CHIP_IS_E3B0(bp)) ?
1063 PBF_REG_TQ_OCCUPANCY_Q1 :
1064 PBF_REG_P1_TQ_OCCUPANCY,
1065 (CHIP_IS_E3B0(bp)) ?
1066 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1067 PBF_REG_P1_TQ_LINES_FREED_CNT},
1068 {4, (CHIP_IS_E3B0(bp)) ?
1069 PBF_REG_TQ_OCCUPANCY_LB_Q :
1070 PBF_REG_P4_TQ_OCCUPANCY,
1071 (CHIP_IS_E3B0(bp)) ?
1072 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1073 PBF_REG_P4_TQ_LINES_FREED_CNT}
1074 };
1075
1076 struct pbf_pN_buf_regs buf_regs[] = {
1077 {0, (CHIP_IS_E3B0(bp)) ?
1078 PBF_REG_INIT_CRD_Q0 :
1079 PBF_REG_P0_INIT_CRD ,
1080 (CHIP_IS_E3B0(bp)) ?
1081 PBF_REG_CREDIT_Q0 :
1082 PBF_REG_P0_CREDIT,
1083 (CHIP_IS_E3B0(bp)) ?
1084 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1085 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1086 {1, (CHIP_IS_E3B0(bp)) ?
1087 PBF_REG_INIT_CRD_Q1 :
1088 PBF_REG_P1_INIT_CRD,
1089 (CHIP_IS_E3B0(bp)) ?
1090 PBF_REG_CREDIT_Q1 :
1091 PBF_REG_P1_CREDIT,
1092 (CHIP_IS_E3B0(bp)) ?
1093 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1094 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1095 {4, (CHIP_IS_E3B0(bp)) ?
1096 PBF_REG_INIT_CRD_LB_Q :
1097 PBF_REG_P4_INIT_CRD,
1098 (CHIP_IS_E3B0(bp)) ?
1099 PBF_REG_CREDIT_LB_Q :
1100 PBF_REG_P4_CREDIT,
1101 (CHIP_IS_E3B0(bp)) ?
1102 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1103 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1104 };
1105
1106 int i;
1107
1108 /* Verify the command queues are flushed P0, P1, P4 */
1109 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1110 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1111
1112
1113 /* Verify the transmission buffers are flushed P0, P1, P4 */
1114 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1115 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1116}
1117
1118#define OP_GEN_PARAM(param) \
1119 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1120
1121#define OP_GEN_TYPE(type) \
1122 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1123
1124#define OP_GEN_AGG_VECT(index) \
1125 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1126
1127
1191cb83 1128static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
619c5cb6
VZ
1129 u32 poll_cnt)
1130{
1131 struct sdm_op_gen op_gen = {0};
1132
1133 u32 comp_addr = BAR_CSTRORM_INTMEM +
1134 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1135 int ret = 0;
1136
1137 if (REG_RD(bp, comp_addr)) {
89db4ad8 1138 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1139 return 1;
1140 }
1141
1142 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1143 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1144 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1145 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1146
89db4ad8 1147 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
619c5cb6
VZ
1148 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1149
1150 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1151 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1152 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1153 (REG_RD(bp, comp_addr)));
619c5cb6
VZ
1154 ret = 1;
1155 }
1156 /* Zero completion for nxt FLR */
1157 REG_WR(bp, comp_addr, 0);
1158
1159 return ret;
1160}
1161
1191cb83 1162static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
619c5cb6 1163{
619c5cb6
VZ
1164 u16 status;
1165
2a80eebc 1166 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
619c5cb6
VZ
1167 return status & PCI_EXP_DEVSTA_TRPND;
1168}
1169
1170/* PF FLR specific routines
1171*/
1172static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1173{
1174
1175 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1176 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1177 CFC_REG_NUM_LCIDS_INSIDE_PF,
1178 "CFC PF usage counter timed out",
1179 poll_cnt))
1180 return 1;
1181
1182
1183 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1184 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1185 DORQ_REG_PF_USAGE_CNT,
1186 "DQ PF usage counter timed out",
1187 poll_cnt))
1188 return 1;
1189
1190 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1191 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1192 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1193 "QM PF usage counter timed out",
1194 poll_cnt))
1195 return 1;
1196
1197 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1198 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1199 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1200 "Timers VNIC usage counter timed out",
1201 poll_cnt))
1202 return 1;
1203 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1204 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1205 "Timers NUM_SCANS usage counter timed out",
1206 poll_cnt))
1207 return 1;
1208
1209 /* Wait DMAE PF usage counter to zero */
1210 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1211 dmae_reg_go_c[INIT_DMAE_C(bp)],
1212 "DMAE dommand register timed out",
1213 poll_cnt))
1214 return 1;
1215
1216 return 0;
1217}
1218
1219static void bnx2x_hw_enable_status(struct bnx2x *bp)
1220{
1221 u32 val;
1222
1223 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1224 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1225
1226 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1227 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1228
1229 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1230 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1231
1232 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1233 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1234
1235 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1236 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1237
1238 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1239 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1240
1241 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1242 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1243
1244 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1245 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1246 val);
1247}
1248
1249static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1250{
1251 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1252
1253 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1254
1255 /* Re-enable PF target read access */
1256 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1257
1258 /* Poll HW usage counters */
89db4ad8 1259 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1260 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1261 return -EBUSY;
1262
1263 /* Zero the igu 'trailing edge' and 'leading edge' */
1264
1265 /* Send the FW cleanup command */
1266 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1267 return -EBUSY;
1268
1269 /* ATC cleanup */
1270
1271 /* Verify TX hw is flushed */
1272 bnx2x_tx_hw_flushed(bp, poll_cnt);
1273
1274 /* Wait 100ms (not adjusted according to platform) */
1275 msleep(100);
1276
1277 /* Verify no pending pci transactions */
1278 if (bnx2x_is_pcie_pending(bp->pdev))
1279 BNX2X_ERR("PCIE Transactions still pending\n");
1280
1281 /* Debug */
1282 bnx2x_hw_enable_status(bp);
1283
1284 /*
1285 * Master enable - Due to WB DMAE writes performed before this
1286 * register is re-initialized as part of the regular function init
1287 */
1288 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1289
1290 return 0;
1291}
1292
f2e0899f 1293static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1294{
34f80b04 1295 int port = BP_PORT(bp);
a2fbb9ea
ET
1296 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1297 u32 val = REG_RD(bp, addr);
69c326b3
DK
1298 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1299 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1300 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
a2fbb9ea
ET
1301
1302 if (msix) {
8badd27a
EG
1303 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1304 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1305 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1306 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
69c326b3
DK
1307 if (single_msix)
1308 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
8badd27a
EG
1309 } else if (msi) {
1310 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1311 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1312 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1313 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea
ET
1314 } else {
1315 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1316 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1317 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1318 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1319
a0fd065c 1320 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1321 DP(NETIF_MSG_IFUP,
1322 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1323
a0fd065c 1324 REG_WR(bp, addr, val);
615f8fd9 1325
a0fd065c
DK
1326 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1327 }
a2fbb9ea
ET
1328 }
1329
a0fd065c
DK
1330 if (CHIP_IS_E1(bp))
1331 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1332
51c1a580
MS
1333 DP(NETIF_MSG_IFUP,
1334 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1335 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1336
1337 REG_WR(bp, addr, val);
37dbbf32
EG
1338 /*
1339 * Ensure that HC_CONFIG is written before leading/trailing edge config
1340 */
1341 mmiowb();
1342 barrier();
34f80b04 1343
f2e0899f 1344 if (!CHIP_IS_E1(bp)) {
34f80b04 1345 /* init leading/trailing edge */
fb3bff17 1346 if (IS_MF(bp)) {
3395a033 1347 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1348 if (bp->port.pmf)
4acac6a5
EG
1349 /* enable nig and gpio3 attention */
1350 val |= 0x1100;
34f80b04
EG
1351 } else
1352 val = 0xffff;
1353
1354 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1355 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1356 }
37dbbf32
EG
1357
1358 /* Make sure that interrupts are indeed enabled from here on */
1359 mmiowb();
a2fbb9ea
ET
1360}
1361
f2e0899f
DK
1362static void bnx2x_igu_int_enable(struct bnx2x *bp)
1363{
1364 u32 val;
30a5de77
DK
1365 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1366 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1367 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
f2e0899f
DK
1368
1369 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1370
1371 if (msix) {
1372 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1373 IGU_PF_CONF_SINGLE_ISR_EN);
1374 val |= (IGU_PF_CONF_FUNC_EN |
1375 IGU_PF_CONF_MSI_MSIX_EN |
1376 IGU_PF_CONF_ATTN_BIT_EN);
30a5de77
DK
1377
1378 if (single_msix)
1379 val |= IGU_PF_CONF_SINGLE_ISR_EN;
f2e0899f
DK
1380 } else if (msi) {
1381 val &= ~IGU_PF_CONF_INT_LINE_EN;
1382 val |= (IGU_PF_CONF_FUNC_EN |
1383 IGU_PF_CONF_MSI_MSIX_EN |
1384 IGU_PF_CONF_ATTN_BIT_EN |
1385 IGU_PF_CONF_SINGLE_ISR_EN);
1386 } else {
1387 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1388 val |= (IGU_PF_CONF_FUNC_EN |
1389 IGU_PF_CONF_INT_LINE_EN |
1390 IGU_PF_CONF_ATTN_BIT_EN |
1391 IGU_PF_CONF_SINGLE_ISR_EN);
1392 }
1393
51c1a580 1394 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1395 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1396
1397 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1398
79a8557a
YM
1399 if (val & IGU_PF_CONF_INT_LINE_EN)
1400 pci_intx(bp->pdev, true);
1401
f2e0899f
DK
1402 barrier();
1403
1404 /* init leading/trailing edge */
1405 if (IS_MF(bp)) {
3395a033 1406 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1407 if (bp->port.pmf)
1408 /* enable nig and gpio3 attention */
1409 val |= 0x1100;
1410 } else
1411 val = 0xffff;
1412
1413 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1414 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1415
1416 /* Make sure that interrupts are indeed enabled from here on */
1417 mmiowb();
1418}
1419
1420void bnx2x_int_enable(struct bnx2x *bp)
1421{
1422 if (bp->common.int_block == INT_BLOCK_HC)
1423 bnx2x_hc_int_enable(bp);
1424 else
1425 bnx2x_igu_int_enable(bp);
1426}
1427
1428static void bnx2x_hc_int_disable(struct bnx2x *bp)
a2fbb9ea 1429{
34f80b04 1430 int port = BP_PORT(bp);
a2fbb9ea
ET
1431 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1432 u32 val = REG_RD(bp, addr);
1433
a0fd065c
DK
1434 /*
1435 * in E1 we must use only PCI configuration space to disable
1436 * MSI/MSIX capablility
1437 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1438 */
1439 if (CHIP_IS_E1(bp)) {
1440 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1441 * Use mask register to prevent from HC sending interrupts
1442 * after we exit the function
1443 */
1444 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1445
1446 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1447 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1448 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1449 } else
1450 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1451 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1452 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1453 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea 1454
51c1a580
MS
1455 DP(NETIF_MSG_IFDOWN,
1456 "write %x to HC %d (addr 0x%x)\n",
a2fbb9ea
ET
1457 val, port, addr);
1458
8badd27a
EG
1459 /* flush all outstanding writes */
1460 mmiowb();
1461
a2fbb9ea
ET
1462 REG_WR(bp, addr, val);
1463 if (REG_RD(bp, addr) != val)
1464 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1465}
1466
f2e0899f
DK
1467static void bnx2x_igu_int_disable(struct bnx2x *bp)
1468{
1469 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1470
1471 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1472 IGU_PF_CONF_INT_LINE_EN |
1473 IGU_PF_CONF_ATTN_BIT_EN);
1474
51c1a580 1475 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
f2e0899f
DK
1476
1477 /* flush all outstanding writes */
1478 mmiowb();
1479
1480 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1481 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1482 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1483}
1484
910cc727 1485static void bnx2x_int_disable(struct bnx2x *bp)
f2e0899f
DK
1486{
1487 if (bp->common.int_block == INT_BLOCK_HC)
1488 bnx2x_hc_int_disable(bp);
1489 else
1490 bnx2x_igu_int_disable(bp);
1491}
1492
9f6c9258 1493void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1494{
a2fbb9ea 1495 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1496 int i, offset;
a2fbb9ea 1497
f8ef6e44
YG
1498 if (disable_hw)
1499 /* prevent the HW from sending interrupts */
1500 bnx2x_int_disable(bp);
a2fbb9ea
ET
1501
1502 /* make sure all ISRs are done */
1503 if (msix) {
8badd27a
EG
1504 synchronize_irq(bp->msix_table[0].vector);
1505 offset = 1;
55c11941
MS
1506 if (CNIC_SUPPORT(bp))
1507 offset++;
ec6ba945 1508 for_each_eth_queue(bp, i)
754a2f52 1509 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1510 } else
1511 synchronize_irq(bp->pdev->irq);
1512
1513 /* make sure sp_task is not running */
1cf167f2 1514 cancel_delayed_work(&bp->sp_task);
3deb8167 1515 cancel_delayed_work(&bp->period_task);
1cf167f2 1516 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1517}
1518
34f80b04 1519/* fast path */
a2fbb9ea
ET
1520
1521/*
34f80b04 1522 * General service functions
a2fbb9ea
ET
1523 */
1524
72fd0718
VZ
1525/* Return true if succeeded to acquire the lock */
1526static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1527{
1528 u32 lock_status;
1529 u32 resource_bit = (1 << resource);
1530 int func = BP_FUNC(bp);
1531 u32 hw_lock_control_reg;
1532
51c1a580
MS
1533 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1534 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1535
1536 /* Validating that the resource is within range */
1537 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1538 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1539 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1540 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1541 return false;
72fd0718
VZ
1542 }
1543
1544 if (func <= 5)
1545 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1546 else
1547 hw_lock_control_reg =
1548 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1549
1550 /* Try to acquire the lock */
1551 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1552 lock_status = REG_RD(bp, hw_lock_control_reg);
1553 if (lock_status & resource_bit)
1554 return true;
1555
51c1a580
MS
1556 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1557 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1558 return false;
1559}
1560
c9ee9206
VZ
1561/**
1562 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1563 *
1564 * @bp: driver handle
1565 *
1566 * Returns the recovery leader resource id according to the engine this function
1567 * belongs to. Currently only only 2 engines is supported.
1568 */
1191cb83 1569static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
c9ee9206
VZ
1570{
1571 if (BP_PATH(bp))
1572 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1573 else
1574 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1575}
1576
1577/**
1578 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1579 *
1580 * @bp: driver handle
1581 *
1191cb83 1582 * Tries to aquire a leader lock for current engine.
c9ee9206 1583 */
1191cb83 1584static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
c9ee9206
VZ
1585{
1586 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1587}
1588
619c5cb6 1589static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
55c11941 1590
3196a88a 1591
619c5cb6 1592void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1593{
1594 struct bnx2x *bp = fp->bp;
1595 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1596 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6 1597 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
15192a8c 1598 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a2fbb9ea 1599
34f80b04 1600 DP(BNX2X_MSG_SP,
a2fbb9ea 1601 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1602 fp->index, cid, command, bp->state,
34f80b04 1603 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1604
619c5cb6
VZ
1605 switch (command) {
1606 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1607 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1608 drv_cmd = BNX2X_Q_CMD_UPDATE;
1609 break;
d6cae238 1610
619c5cb6 1611 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1612 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1613 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1614 break;
1615
6383c0b3 1616 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1617 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1618 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1619 break;
1620
619c5cb6 1621 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1622 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1623 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1624 break;
1625
619c5cb6 1626 case (RAMROD_CMD_ID_ETH_TERMINATE):
d6cae238 1627 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
619c5cb6 1628 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1629 break;
1630
619c5cb6 1631 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1632 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1633 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1634 break;
619c5cb6
VZ
1635
1636 default:
1637 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1638 command, fp->index);
1639 return;
523224a3 1640 }
3196a88a 1641
619c5cb6
VZ
1642 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1643 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1644 /* q_obj->complete_cmd() failure means that this was
1645 * an unexpected completion.
1646 *
1647 * In this case we don't want to increase the bp->spq_left
1648 * because apparently we haven't sent this command the first
1649 * place.
1650 */
1651#ifdef BNX2X_STOP_ON_ERROR
1652 bnx2x_panic();
1653#else
1654 return;
1655#endif
1656
8fe23fbd 1657 smp_mb__before_atomic_inc();
6e30dd4e 1658 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1659 /* push the change in bp->spq_left and towards the memory */
1660 smp_mb__after_atomic_inc();
49d66772 1661
d6cae238
VZ
1662 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1663
a3348722
BW
1664 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1665 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1666 /* if Q update ramrod is completed for last Q in AFEX vif set
1667 * flow, then ACK MCP at the end
1668 *
1669 * mark pending ACK to MCP bit.
1670 * prevent case that both bits are cleared.
1671 * At the end of load/unload driver checks that
1672 * sp_state is cleaerd, and this order prevents
1673 * races
1674 */
1675 smp_mb__before_clear_bit();
1676 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1677 wmb();
1678 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1679 smp_mb__after_clear_bit();
1680
1681 /* schedule workqueue to send ack to MCP */
1682 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1683 }
1684
523224a3 1685 return;
a2fbb9ea
ET
1686}
1687
619c5cb6
VZ
1688void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1689 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1690{
1691 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1692
1693 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1694 start);
1695}
1696
9f6c9258 1697irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1698{
555f6c78 1699 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1700 u16 status = bnx2x_ack_int(bp);
34f80b04 1701 u16 mask;
ca00392c 1702 int i;
6383c0b3 1703 u8 cos;
a2fbb9ea 1704
34f80b04 1705 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1706 if (unlikely(status == 0)) {
1707 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1708 return IRQ_NONE;
1709 }
f5372251 1710 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1711
3196a88a
EG
1712#ifdef BNX2X_STOP_ON_ERROR
1713 if (unlikely(bp->panic))
1714 return IRQ_HANDLED;
1715#endif
1716
ec6ba945 1717 for_each_eth_queue(bp, i) {
ca00392c 1718 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1719
55c11941 1720 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
ca00392c 1721 if (status & mask) {
619c5cb6 1722 /* Handle Rx or Tx according to SB id */
54b9ddaa 1723 prefetch(fp->rx_cons_sb);
6383c0b3 1724 for_each_cos_in_tx_queue(fp, cos)
65565884 1725 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
523224a3 1726 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1727 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1728 status &= ~mask;
1729 }
a2fbb9ea
ET
1730 }
1731
55c11941
MS
1732 if (CNIC_SUPPORT(bp)) {
1733 mask = 0x2;
1734 if (status & (mask | 0x1)) {
1735 struct cnic_ops *c_ops = NULL;
993ac7b5 1736
55c11941
MS
1737 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1738 rcu_read_lock();
1739 c_ops = rcu_dereference(bp->cnic_ops);
1740 if (c_ops)
1741 c_ops->cnic_handler(bp->cnic_data,
1742 NULL);
1743 rcu_read_unlock();
1744 }
993ac7b5 1745
55c11941
MS
1746 status &= ~mask;
1747 }
993ac7b5 1748 }
a2fbb9ea 1749
34f80b04 1750 if (unlikely(status & 0x1)) {
1cf167f2 1751 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
a2fbb9ea
ET
1752
1753 status &= ~0x1;
1754 if (!status)
1755 return IRQ_HANDLED;
1756 }
1757
cdaa7cb8
VZ
1758 if (unlikely(status))
1759 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1760 status);
a2fbb9ea 1761
c18487ee 1762 return IRQ_HANDLED;
a2fbb9ea
ET
1763}
1764
c18487ee
YR
1765/* Link */
1766
1767/*
1768 * General service functions
1769 */
a2fbb9ea 1770
9f6c9258 1771int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1772{
1773 u32 lock_status;
1774 u32 resource_bit = (1 << resource);
4a37fb66
YG
1775 int func = BP_FUNC(bp);
1776 u32 hw_lock_control_reg;
c18487ee 1777 int cnt;
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 }
a2fbb9ea 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 not already 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\n",
c18487ee
YR
1797 lock_status, resource_bit);
1798 return -EEXIST;
1799 }
a2fbb9ea 1800
46230476
EG
1801 /* Try for 5 second every 5ms */
1802 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1803 /* Try to acquire the lock */
4a37fb66
YG
1804 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1805 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1806 if (lock_status & resource_bit)
1807 return 0;
a2fbb9ea 1808
c18487ee 1809 msleep(5);
a2fbb9ea 1810 }
51c1a580 1811 BNX2X_ERR("Timeout\n");
c18487ee
YR
1812 return -EAGAIN;
1813}
a2fbb9ea 1814
c9ee9206
VZ
1815int bnx2x_release_leader_lock(struct bnx2x *bp)
1816{
1817 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1818}
1819
9f6c9258 1820int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1821{
1822 u32 lock_status;
1823 u32 resource_bit = (1 << resource);
4a37fb66
YG
1824 int func = BP_FUNC(bp);
1825 u32 hw_lock_control_reg;
a2fbb9ea 1826
c18487ee
YR
1827 /* Validating that the resource is within range */
1828 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1829 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1830 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1831 return -EINVAL;
1832 }
1833
4a37fb66
YG
1834 if (func <= 5) {
1835 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1836 } else {
1837 hw_lock_control_reg =
1838 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1839 }
1840
c18487ee 1841 /* Validating that the resource is currently taken */
4a37fb66 1842 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1843 if (!(lock_status & resource_bit)) {
51c1a580 1844 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
c18487ee
YR
1845 lock_status, resource_bit);
1846 return -EFAULT;
a2fbb9ea
ET
1847 }
1848
9f6c9258
DK
1849 REG_WR(bp, hw_lock_control_reg, resource_bit);
1850 return 0;
c18487ee 1851}
a2fbb9ea 1852
9f6c9258 1853
4acac6a5
EG
1854int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1855{
1856 /* The GPIO should be swapped if swap register is set and active */
1857 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1858 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1859 int gpio_shift = gpio_num +
1860 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1861 u32 gpio_mask = (1 << gpio_shift);
1862 u32 gpio_reg;
1863 int value;
1864
1865 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1866 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1867 return -EINVAL;
1868 }
1869
1870 /* read GPIO value */
1871 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1872
1873 /* get the requested pin value */
1874 if ((gpio_reg & gpio_mask) == gpio_mask)
1875 value = 1;
1876 else
1877 value = 0;
1878
1879 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1880
1881 return value;
1882}
1883
17de50b7 1884int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
1885{
1886 /* The GPIO should be swapped if swap register is set and active */
1887 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 1888 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
1889 int gpio_shift = gpio_num +
1890 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1891 u32 gpio_mask = (1 << gpio_shift);
1892 u32 gpio_reg;
a2fbb9ea 1893
c18487ee
YR
1894 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1895 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1896 return -EINVAL;
1897 }
a2fbb9ea 1898
4a37fb66 1899 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
1900 /* read GPIO and mask except the float bits */
1901 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 1902
c18487ee
YR
1903 switch (mode) {
1904 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
1905 DP(NETIF_MSG_LINK,
1906 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
1907 gpio_num, gpio_shift);
1908 /* clear FLOAT and set CLR */
1909 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1910 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1911 break;
a2fbb9ea 1912
c18487ee 1913 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
1914 DP(NETIF_MSG_LINK,
1915 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
1916 gpio_num, gpio_shift);
1917 /* clear FLOAT and set SET */
1918 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1919 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1920 break;
a2fbb9ea 1921
17de50b7 1922 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
1923 DP(NETIF_MSG_LINK,
1924 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
1925 gpio_num, gpio_shift);
1926 /* set FLOAT */
1927 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1928 break;
a2fbb9ea 1929
c18487ee
YR
1930 default:
1931 break;
a2fbb9ea
ET
1932 }
1933
c18487ee 1934 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 1935 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 1936
c18487ee 1937 return 0;
a2fbb9ea
ET
1938}
1939
0d40f0d4
YR
1940int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1941{
1942 u32 gpio_reg = 0;
1943 int rc = 0;
1944
1945 /* Any port swapping should be handled by caller. */
1946
1947 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1948 /* read GPIO and mask except the float bits */
1949 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1950 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1951 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1952 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1953
1954 switch (mode) {
1955 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1956 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1957 /* set CLR */
1958 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1959 break;
1960
1961 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1962 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1963 /* set SET */
1964 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1965 break;
1966
1967 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1968 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
1969 /* set FLOAT */
1970 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1971 break;
1972
1973 default:
1974 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
1975 rc = -EINVAL;
1976 break;
1977 }
1978
1979 if (rc == 0)
1980 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1981
1982 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1983
1984 return rc;
1985}
1986
4acac6a5
EG
1987int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1988{
1989 /* The GPIO should be swapped if swap register is set and active */
1990 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1991 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1992 int gpio_shift = gpio_num +
1993 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1994 u32 gpio_mask = (1 << gpio_shift);
1995 u32 gpio_reg;
1996
1997 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1998 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1999 return -EINVAL;
2000 }
2001
2002 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2003 /* read GPIO int */
2004 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2005
2006 switch (mode) {
2007 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
2008 DP(NETIF_MSG_LINK,
2009 "Clear GPIO INT %d (shift %d) -> output low\n",
2010 gpio_num, gpio_shift);
4acac6a5
EG
2011 /* clear SET and set CLR */
2012 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2013 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2014 break;
2015
2016 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
2017 DP(NETIF_MSG_LINK,
2018 "Set GPIO INT %d (shift %d) -> output high\n",
2019 gpio_num, gpio_shift);
4acac6a5
EG
2020 /* clear CLR and set SET */
2021 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2022 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2023 break;
2024
2025 default:
2026 break;
2027 }
2028
2029 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2030 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2031
2032 return 0;
2033}
2034
d6d99a3f 2035static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
a2fbb9ea 2036{
c18487ee 2037 u32 spio_reg;
a2fbb9ea 2038
d6d99a3f
YM
2039 /* Only 2 SPIOs are configurable */
2040 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2041 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
c18487ee 2042 return -EINVAL;
a2fbb9ea
ET
2043 }
2044
4a37fb66 2045 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2046 /* read SPIO and mask except the float bits */
d6d99a3f 2047 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
a2fbb9ea 2048
c18487ee 2049 switch (mode) {
d6d99a3f
YM
2050 case MISC_SPIO_OUTPUT_LOW:
2051 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
c18487ee 2052 /* clear FLOAT and set CLR */
d6d99a3f
YM
2053 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2054 spio_reg |= (spio << MISC_SPIO_CLR_POS);
c18487ee 2055 break;
a2fbb9ea 2056
d6d99a3f
YM
2057 case MISC_SPIO_OUTPUT_HIGH:
2058 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
c18487ee 2059 /* clear FLOAT and set SET */
d6d99a3f
YM
2060 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2061 spio_reg |= (spio << MISC_SPIO_SET_POS);
c18487ee 2062 break;
a2fbb9ea 2063
d6d99a3f
YM
2064 case MISC_SPIO_INPUT_HI_Z:
2065 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
c18487ee 2066 /* set FLOAT */
d6d99a3f 2067 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
c18487ee 2068 break;
a2fbb9ea 2069
c18487ee
YR
2070 default:
2071 break;
a2fbb9ea
ET
2072 }
2073
c18487ee 2074 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2075 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2076
a2fbb9ea
ET
2077 return 0;
2078}
2079
9f6c9258 2080void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2081{
a22f0788 2082 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2083 switch (bp->link_vars.ieee_fc &
2084 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2085 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2086 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2087 ADVERTISED_Pause);
c18487ee 2088 break;
356e2385 2089
c18487ee 2090 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2091 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2092 ADVERTISED_Pause);
c18487ee 2093 break;
356e2385 2094
c18487ee 2095 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2096 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2097 break;
356e2385 2098
c18487ee 2099 default:
a22f0788 2100 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2101 ADVERTISED_Pause);
c18487ee
YR
2102 break;
2103 }
2104}
f1410647 2105
9f6c9258 2106u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
c18487ee 2107{
19680c48
EG
2108 if (!BP_NOMCP(bp)) {
2109 u8 rc;
a22f0788
YR
2110 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2111 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
1cb0c788
YR
2112 /*
2113 * Initialize link parameters structure variables
2114 * It is recommended to turn off RX FC for jumbo frames
2115 * for better performance
2116 */
2117 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
c0700f90 2118 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
8c99e7b0 2119 else
c0700f90 2120 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
a2fbb9ea 2121
4a37fb66 2122 bnx2x_acquire_phy_lock(bp);
b5bf9068 2123
a22f0788 2124 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2125 struct link_params *lp = &bp->link_params;
2126 lp->loopback_mode = LOOPBACK_XGXS;
2127 /* do PHY loopback at 10G speed, if possible */
2128 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2129 if (lp->speed_cap_mask[cfx_idx] &
2130 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2131 lp->req_line_speed[cfx_idx] =
2132 SPEED_10000;
2133 else
2134 lp->req_line_speed[cfx_idx] =
2135 SPEED_1000;
2136 }
a22f0788 2137 }
b5bf9068 2138
8970b2e4
MS
2139 if (load_mode == LOAD_LOOPBACK_EXT) {
2140 struct link_params *lp = &bp->link_params;
2141 lp->loopback_mode = LOOPBACK_EXT;
2142 }
2143
19680c48 2144 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2145
4a37fb66 2146 bnx2x_release_phy_lock(bp);
a2fbb9ea 2147
3c96c68b
EG
2148 bnx2x_calc_fc_adv(bp);
2149
b5bf9068
EG
2150 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2151 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2152 bnx2x_link_report(bp);
3deb8167
YR
2153 } else
2154 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2155 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2156 return rc;
2157 }
f5372251 2158 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2159 return -EINVAL;
a2fbb9ea
ET
2160}
2161
9f6c9258 2162void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2163{
19680c48 2164 if (!BP_NOMCP(bp)) {
4a37fb66 2165 bnx2x_acquire_phy_lock(bp);
19680c48 2166 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2167 bnx2x_release_phy_lock(bp);
a2fbb9ea 2168
19680c48
EG
2169 bnx2x_calc_fc_adv(bp);
2170 } else
f5372251 2171 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2172}
a2fbb9ea 2173
c18487ee
YR
2174static void bnx2x__link_reset(struct bnx2x *bp)
2175{
19680c48 2176 if (!BP_NOMCP(bp)) {
4a37fb66 2177 bnx2x_acquire_phy_lock(bp);
5d07d868 2178 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2179 bnx2x_release_phy_lock(bp);
19680c48 2180 } else
f5372251 2181 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2182}
a2fbb9ea 2183
5d07d868
YM
2184void bnx2x_force_link_reset(struct bnx2x *bp)
2185{
2186 bnx2x_acquire_phy_lock(bp);
2187 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2188 bnx2x_release_phy_lock(bp);
2189}
2190
a22f0788 2191u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2192{
2145a920 2193 u8 rc = 0;
a2fbb9ea 2194
2145a920
VZ
2195 if (!BP_NOMCP(bp)) {
2196 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2197 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2198 is_serdes);
2145a920
VZ
2199 bnx2x_release_phy_lock(bp);
2200 } else
2201 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2202
c18487ee
YR
2203 return rc;
2204}
a2fbb9ea 2205
34f80b04 2206
2691d51d
EG
2207/* Calculates the sum of vn_min_rates.
2208 It's needed for further normalizing of the min_rates.
2209 Returns:
2210 sum of vn_min_rates.
2211 or
2212 0 - if all the min_rates are 0.
2213 In the later case fainess algorithm should be deactivated.
2214 If not all min_rates are zero then those that are zeroes will be set to 1.
2215 */
b475d78f
YM
2216static void bnx2x_calc_vn_min(struct bnx2x *bp,
2217 struct cmng_init_input *input)
2691d51d
EG
2218{
2219 int all_zero = 1;
2691d51d
EG
2220 int vn;
2221
3395a033 2222 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2223 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2224 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2225 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2226
2227 /* Skip hidden vns */
2228 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2229 vn_min_rate = 0;
2691d51d 2230 /* If min rate is zero - set it to 1 */
b475d78f 2231 else if (!vn_min_rate)
2691d51d
EG
2232 vn_min_rate = DEF_MIN_RATE;
2233 else
2234 all_zero = 0;
2235
b475d78f 2236 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2237 }
2238
30ae438b
DK
2239 /* if ETS or all min rates are zeros - disable fairness */
2240 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2241 input->flags.cmng_enables &=
30ae438b
DK
2242 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2243 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2244 } else if (all_zero) {
b475d78f 2245 input->flags.cmng_enables &=
b015e3d1 2246 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2247 DP(NETIF_MSG_IFUP,
2248 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2249 } else
b475d78f 2250 input->flags.cmng_enables |=
b015e3d1 2251 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2252}
2253
b475d78f
YM
2254static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2255 struct cmng_init_input *input)
34f80b04 2256{
b475d78f 2257 u16 vn_max_rate;
f2e0899f 2258 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2259
b475d78f 2260 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2261 vn_max_rate = 0;
b475d78f 2262 else {
faa6fcbb
DK
2263 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2264
b475d78f 2265 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2266 /* maxCfg in percents of linkspeed */
2267 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2268 } else /* SD modes */
faa6fcbb
DK
2269 /* maxCfg is absolute in 100Mb units */
2270 vn_max_rate = maxCfg * 100;
34f80b04 2271 }
f85582f8 2272
b475d78f 2273 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2274
b475d78f 2275 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2276}
f85582f8 2277
b475d78f 2278
523224a3
DK
2279static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2280{
2281 if (CHIP_REV_IS_SLOW(bp))
2282 return CMNG_FNS_NONE;
fb3bff17 2283 if (IS_MF(bp))
523224a3
DK
2284 return CMNG_FNS_MINMAX;
2285
2286 return CMNG_FNS_NONE;
2287}
2288
2ae17f66 2289void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2290{
0793f83f 2291 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2292
2293 if (BP_NOMCP(bp))
2294 return; /* what should be the default bvalue in this case */
2295
0793f83f
DK
2296 /* For 2 port configuration the absolute function number formula
2297 * is:
2298 * abs_func = 2 * vn + BP_PORT + BP_PATH
2299 *
2300 * and there are 4 functions per port
2301 *
2302 * For 4 port configuration it is
2303 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2304 *
2305 * and there are 2 functions per port
2306 */
3395a033 2307 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2308 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2309
2310 if (func >= E1H_FUNC_MAX)
2311 break;
2312
f2e0899f 2313 bp->mf_config[vn] =
523224a3
DK
2314 MF_CFG_RD(bp, func_mf_config[func].config);
2315 }
a3348722
BW
2316 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2317 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2318 bp->flags |= MF_FUNC_DIS;
2319 } else {
2320 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2321 bp->flags &= ~MF_FUNC_DIS;
2322 }
523224a3
DK
2323}
2324
2325static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2326{
b475d78f
YM
2327 struct cmng_init_input input;
2328 memset(&input, 0, sizeof(struct cmng_init_input));
2329
2330 input.port_rate = bp->link_vars.line_speed;
523224a3
DK
2331
2332 if (cmng_type == CMNG_FNS_MINMAX) {
2333 int vn;
2334
523224a3
DK
2335 /* read mf conf from shmem */
2336 if (read_cfg)
2337 bnx2x_read_mf_cfg(bp);
2338
523224a3 2339 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2340 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2341
2342 /* calculate and set min-max rate for each vn */
c4154f25 2343 if (bp->port.pmf)
3395a033 2344 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2345 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2346
2347 /* always enable rate shaping and fairness */
b475d78f 2348 input.flags.cmng_enables |=
523224a3 2349 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2350
2351 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2352 return;
2353 }
2354
2355 /* rate shaping and fairness are disabled */
2356 DP(NETIF_MSG_IFUP,
2357 "rate shaping and fairness are disabled\n");
2358}
34f80b04 2359
1191cb83
ED
2360static void storm_memset_cmng(struct bnx2x *bp,
2361 struct cmng_init *cmng,
2362 u8 port)
2363{
2364 int vn;
2365 size_t size = sizeof(struct cmng_struct_per_port);
2366
2367 u32 addr = BAR_XSTRORM_INTMEM +
2368 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2369
2370 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2371
2372 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2373 int func = func_by_vn(bp, vn);
2374
2375 addr = BAR_XSTRORM_INTMEM +
2376 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2377 size = sizeof(struct rate_shaping_vars_per_vn);
2378 __storm_memset_struct(bp, addr, size,
2379 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2380
2381 addr = BAR_XSTRORM_INTMEM +
2382 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2383 size = sizeof(struct fairness_vars_per_vn);
2384 __storm_memset_struct(bp, addr, size,
2385 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2386 }
2387}
2388
c18487ee
YR
2389/* This function is called upon link interrupt */
2390static void bnx2x_link_attn(struct bnx2x *bp)
2391{
bb2a0f7a
YG
2392 /* Make sure that we are synced with the current statistics */
2393 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2394
c18487ee 2395 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2396
bb2a0f7a
YG
2397 if (bp->link_vars.link_up) {
2398
1c06328c 2399 /* dropless flow control */
f2e0899f 2400 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2401 int port = BP_PORT(bp);
2402 u32 pause_enabled = 0;
2403
2404 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2405 pause_enabled = 1;
2406
2407 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2408 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2409 pause_enabled);
2410 }
2411
619c5cb6 2412 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2413 struct host_port_stats *pstats;
2414
2415 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2416 /* reset old mac stats */
bb2a0f7a
YG
2417 memset(&(pstats->mac_stx[0]), 0,
2418 sizeof(struct mac_stx));
2419 }
f34d28ea 2420 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2421 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2422 }
2423
f2e0899f
DK
2424 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2425 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2426
f2e0899f
DK
2427 if (cmng_fns != CMNG_FNS_NONE) {
2428 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2429 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2430 } else
2431 /* rate shaping and fairness are disabled */
2432 DP(NETIF_MSG_IFUP,
2433 "single function mode without fairness\n");
34f80b04 2434 }
9fdc3e95 2435
2ae17f66
VZ
2436 __bnx2x_link_report(bp);
2437
9fdc3e95
DK
2438 if (IS_MF(bp))
2439 bnx2x_link_sync_notify(bp);
c18487ee 2440}
a2fbb9ea 2441
9f6c9258 2442void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2443{
2ae17f66 2444 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2445 return;
a2fbb9ea 2446
00253a8c
DK
2447 /* read updated dcb configuration */
2448 bnx2x_dcbx_pmf_update(bp);
2449
c18487ee 2450 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2451
bb2a0f7a
YG
2452 if (bp->link_vars.link_up)
2453 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2454 else
2455 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2456
c18487ee
YR
2457 /* indicate link status */
2458 bnx2x_link_report(bp);
a2fbb9ea 2459}
a2fbb9ea 2460
a3348722
BW
2461static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2462 u16 vlan_val, u8 allowed_prio)
2463{
2464 struct bnx2x_func_state_params func_params = {0};
2465 struct bnx2x_func_afex_update_params *f_update_params =
2466 &func_params.params.afex_update;
2467
2468 func_params.f_obj = &bp->func_obj;
2469 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2470
2471 /* no need to wait for RAMROD completion, so don't
2472 * set RAMROD_COMP_WAIT flag
2473 */
2474
2475 f_update_params->vif_id = vifid;
2476 f_update_params->afex_default_vlan = vlan_val;
2477 f_update_params->allowed_priorities = allowed_prio;
2478
2479 /* if ramrod can not be sent, response to MCP immediately */
2480 if (bnx2x_func_state_change(bp, &func_params) < 0)
2481 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2482
2483 return 0;
2484}
2485
2486static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2487 u16 vif_index, u8 func_bit_map)
2488{
2489 struct bnx2x_func_state_params func_params = {0};
2490 struct bnx2x_func_afex_viflists_params *update_params =
2491 &func_params.params.afex_viflists;
2492 int rc;
2493 u32 drv_msg_code;
2494
2495 /* validate only LIST_SET and LIST_GET are received from switch */
2496 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2497 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2498 cmd_type);
2499
2500 func_params.f_obj = &bp->func_obj;
2501 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2502
2503 /* set parameters according to cmd_type */
2504 update_params->afex_vif_list_command = cmd_type;
2505 update_params->vif_list_index = cpu_to_le16(vif_index);
2506 update_params->func_bit_map =
2507 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2508 update_params->func_to_clear = 0;
2509 drv_msg_code =
2510 (cmd_type == VIF_LIST_RULE_GET) ?
2511 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2512 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2513
2514 /* if ramrod can not be sent, respond to MCP immediately for
2515 * SET and GET requests (other are not triggered from MCP)
2516 */
2517 rc = bnx2x_func_state_change(bp, &func_params);
2518 if (rc < 0)
2519 bnx2x_fw_command(bp, drv_msg_code, 0);
2520
2521 return 0;
2522}
2523
2524static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2525{
2526 struct afex_stats afex_stats;
2527 u32 func = BP_ABS_FUNC(bp);
2528 u32 mf_config;
2529 u16 vlan_val;
2530 u32 vlan_prio;
2531 u16 vif_id;
2532 u8 allowed_prio;
2533 u8 vlan_mode;
2534 u32 addr_to_write, vifid, addrs, stats_type, i;
2535
2536 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2537 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2538 DP(BNX2X_MSG_MCP,
2539 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2540 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2541 }
2542
2543 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2544 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2545 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2546 DP(BNX2X_MSG_MCP,
2547 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2548 vifid, addrs);
2549 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2550 addrs);
2551 }
2552
2553 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2554 addr_to_write = SHMEM2_RD(bp,
2555 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2556 stats_type = SHMEM2_RD(bp,
2557 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2558
2559 DP(BNX2X_MSG_MCP,
2560 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2561 addr_to_write);
2562
2563 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2564
2565 /* write response to scratchpad, for MCP */
2566 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2567 REG_WR(bp, addr_to_write + i*sizeof(u32),
2568 *(((u32 *)(&afex_stats))+i));
2569
2570 /* send ack message to MCP */
2571 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2572 }
2573
2574 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2575 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2576 bp->mf_config[BP_VN(bp)] = mf_config;
2577 DP(BNX2X_MSG_MCP,
2578 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2579 mf_config);
2580
2581 /* if VIF_SET is "enabled" */
2582 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2583 /* set rate limit directly to internal RAM */
2584 struct cmng_init_input cmng_input;
2585 struct rate_shaping_vars_per_vn m_rs_vn;
2586 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2587 u32 addr = BAR_XSTRORM_INTMEM +
2588 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2589
2590 bp->mf_config[BP_VN(bp)] = mf_config;
2591
2592 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2593 m_rs_vn.vn_counter.rate =
2594 cmng_input.vnic_max_rate[BP_VN(bp)];
2595 m_rs_vn.vn_counter.quota =
2596 (m_rs_vn.vn_counter.rate *
2597 RS_PERIODIC_TIMEOUT_USEC) / 8;
2598
2599 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2600
2601 /* read relevant values from mf_cfg struct in shmem */
2602 vif_id =
2603 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2604 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2605 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2606 vlan_val =
2607 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2608 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2609 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2610 vlan_prio = (mf_config &
2611 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2612 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2613 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2614 vlan_mode =
2615 (MF_CFG_RD(bp,
2616 func_mf_config[func].afex_config) &
2617 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2618 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2619 allowed_prio =
2620 (MF_CFG_RD(bp,
2621 func_mf_config[func].afex_config) &
2622 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2623 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2624
2625 /* send ramrod to FW, return in case of failure */
2626 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2627 allowed_prio))
2628 return;
2629
2630 bp->afex_def_vlan_tag = vlan_val;
2631 bp->afex_vlan_mode = vlan_mode;
2632 } else {
2633 /* notify link down because BP->flags is disabled */
2634 bnx2x_link_report(bp);
2635
2636 /* send INVALID VIF ramrod to FW */
2637 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2638
2639 /* Reset the default afex VLAN */
2640 bp->afex_def_vlan_tag = -1;
2641 }
2642 }
2643}
2644
34f80b04
EG
2645static void bnx2x_pmf_update(struct bnx2x *bp)
2646{
2647 int port = BP_PORT(bp);
2648 u32 val;
2649
2650 bp->port.pmf = 1;
51c1a580 2651 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2652
3deb8167
YR
2653 /*
2654 * We need the mb() to ensure the ordering between the writing to
2655 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2656 */
2657 smp_mb();
2658
2659 /* queue a periodic task */
2660 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2661
ef01854e
DK
2662 bnx2x_dcbx_pmf_update(bp);
2663
34f80b04 2664 /* enable nig attention */
3395a033 2665 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2666 if (bp->common.int_block == INT_BLOCK_HC) {
2667 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2668 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2669 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2670 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2671 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2672 }
bb2a0f7a
YG
2673
2674 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2675}
2676
c18487ee 2677/* end of Link */
a2fbb9ea
ET
2678
2679/* slow path */
2680
2681/*
2682 * General service functions
2683 */
2684
2691d51d 2685/* send the MCP a request, block until there is a reply */
a22f0788 2686u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2687{
f2e0899f 2688 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2689 u32 seq;
2691d51d
EG
2690 u32 rc = 0;
2691 u32 cnt = 1;
2692 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2693
c4ff7cbf 2694 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2695 seq = ++bp->fw_seq;
f2e0899f
DK
2696 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2697 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2698
754a2f52
DK
2699 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2700 (command | seq), param);
2691d51d
EG
2701
2702 do {
2703 /* let the FW do it's magic ... */
2704 msleep(delay);
2705
f2e0899f 2706 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2707
c4ff7cbf
EG
2708 /* Give the FW up to 5 second (500*10ms) */
2709 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2710
2711 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2712 cnt*delay, rc, seq);
2713
2714 /* is this a reply to our command? */
2715 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2716 rc &= FW_MSG_CODE_MASK;
2717 else {
2718 /* FW BUG! */
2719 BNX2X_ERR("FW failed to respond!\n");
2720 bnx2x_fw_dump(bp);
2721 rc = 0;
2722 }
c4ff7cbf 2723 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2724
2725 return rc;
2726}
2727
ec6ba945 2728
1191cb83
ED
2729static void storm_memset_func_cfg(struct bnx2x *bp,
2730 struct tstorm_eth_function_common_config *tcfg,
2731 u16 abs_fid)
2732{
2733 size_t size = sizeof(struct tstorm_eth_function_common_config);
2734
2735 u32 addr = BAR_TSTRORM_INTMEM +
2736 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2737
2738 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2739}
2740
619c5cb6
VZ
2741void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2742{
2743 if (CHIP_IS_E1x(bp)) {
2744 struct tstorm_eth_function_common_config tcfg = {0};
2745
2746 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2747 }
2748
2749 /* Enable the function in the FW */
2750 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2751 storm_memset_func_en(bp, p->func_id, 1);
2752
2753 /* spq */
2754 if (p->func_flgs & FUNC_FLG_SPQ) {
2755 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2756 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2757 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2758 }
2759}
2760
6383c0b3
AE
2761/**
2762 * bnx2x_get_tx_only_flags - Return common flags
2763 *
2764 * @bp device handle
2765 * @fp queue handle
2766 * @zero_stats TRUE if statistics zeroing is needed
2767 *
2768 * Return the flags that are common for the Tx-only and not normal connections.
2769 */
1191cb83
ED
2770static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2771 struct bnx2x_fastpath *fp,
2772 bool zero_stats)
28912902 2773{
619c5cb6
VZ
2774 unsigned long flags = 0;
2775
2776 /* PF driver will always initialize the Queue to an ACTIVE state */
2777 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2778
6383c0b3
AE
2779 /* tx only connections collect statistics (on the same index as the
2780 * parent connection). The statistics are zeroed when the parent
2781 * connection is initialized.
2782 */
50f0a562
BW
2783
2784 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2785 if (zero_stats)
2786 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2787
6383c0b3
AE
2788
2789 return flags;
2790}
2791
1191cb83
ED
2792static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2793 struct bnx2x_fastpath *fp,
2794 bool leading)
6383c0b3
AE
2795{
2796 unsigned long flags = 0;
2797
619c5cb6
VZ
2798 /* calculate other queue flags */
2799 if (IS_MF_SD(bp))
2800 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2801
a3348722 2802 if (IS_FCOE_FP(fp)) {
619c5cb6 2803 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
2804 /* For FCoE - force usage of default priority (for afex) */
2805 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2806 }
523224a3 2807
f5219d8e 2808 if (!fp->disable_tpa) {
619c5cb6 2809 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2810 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2811 if (fp->mode == TPA_MODE_GRO)
2812 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2813 }
619c5cb6 2814
619c5cb6
VZ
2815 if (leading) {
2816 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2817 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2818 }
523224a3 2819
619c5cb6
VZ
2820 /* Always set HW VLAN stripping */
2821 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 2822
a3348722
BW
2823 /* configure silent vlan removal */
2824 if (IS_MF_AFEX(bp))
2825 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
2826
6383c0b3
AE
2827
2828 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
2829}
2830
619c5cb6 2831static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
2832 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2833 u8 cos)
619c5cb6
VZ
2834{
2835 gen_init->stat_id = bnx2x_stats_id(fp);
2836 gen_init->spcl_id = fp->cl_id;
2837
2838 /* Always use mini-jumbo MTU for FCoE L2 ring */
2839 if (IS_FCOE_FP(fp))
2840 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2841 else
2842 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
2843
2844 gen_init->cos = cos;
619c5cb6
VZ
2845}
2846
2847static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 2848 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 2849 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 2850{
619c5cb6 2851 u8 max_sge = 0;
523224a3
DK
2852 u16 sge_sz = 0;
2853 u16 tpa_agg_size = 0;
2854
523224a3 2855 if (!fp->disable_tpa) {
dfacf138
DK
2856 pause->sge_th_lo = SGE_TH_LO(bp);
2857 pause->sge_th_hi = SGE_TH_HI(bp);
2858
2859 /* validate SGE ring has enough to cross high threshold */
2860 WARN_ON(bp->dropless_fc &&
2861 pause->sge_th_hi + FW_PREFETCH_CNT >
2862 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2863
523224a3
DK
2864 tpa_agg_size = min_t(u32,
2865 (min_t(u32, 8, MAX_SKB_FRAGS) *
2866 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2867 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2868 SGE_PAGE_SHIFT;
2869 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2870 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2871 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2872 0xffff);
2873 }
2874
2875 /* pause - not for e1 */
2876 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
2877 pause->bd_th_lo = BD_TH_LO(bp);
2878 pause->bd_th_hi = BD_TH_HI(bp);
2879
2880 pause->rcq_th_lo = RCQ_TH_LO(bp);
2881 pause->rcq_th_hi = RCQ_TH_HI(bp);
2882 /*
2883 * validate that rings have enough entries to cross
2884 * high thresholds
2885 */
2886 WARN_ON(bp->dropless_fc &&
2887 pause->bd_th_hi + FW_PREFETCH_CNT >
2888 bp->rx_ring_size);
2889 WARN_ON(bp->dropless_fc &&
2890 pause->rcq_th_hi + FW_PREFETCH_CNT >
2891 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 2892
523224a3
DK
2893 pause->pri_map = 1;
2894 }
2895
2896 /* rxq setup */
523224a3
DK
2897 rxq_init->dscr_map = fp->rx_desc_mapping;
2898 rxq_init->sge_map = fp->rx_sge_mapping;
2899 rxq_init->rcq_map = fp->rx_comp_mapping;
2900 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 2901
619c5cb6
VZ
2902 /* This should be a maximum number of data bytes that may be
2903 * placed on the BD (not including paddings).
2904 */
e52fcb24
ED
2905 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2906 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 2907
523224a3 2908 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
2909 rxq_init->tpa_agg_sz = tpa_agg_size;
2910 rxq_init->sge_buf_sz = sge_sz;
2911 rxq_init->max_sges_pkt = max_sge;
619c5cb6 2912 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 2913 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
2914
2915 /* Maximum number or simultaneous TPA aggregation for this Queue.
2916 *
2917 * For PF Clients it should be the maximum avaliable number.
2918 * VF driver(s) may want to define it to a smaller value.
2919 */
dfacf138 2920 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 2921
523224a3
DK
2922 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2923 rxq_init->fw_sb_id = fp->fw_sb_id;
2924
ec6ba945
VZ
2925 if (IS_FCOE_FP(fp))
2926 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2927 else
6383c0b3 2928 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
2929 /* configure silent vlan removal
2930 * if multi function mode is afex, then mask default vlan
2931 */
2932 if (IS_MF_AFEX(bp)) {
2933 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
2934 rxq_init->silent_removal_mask = VLAN_VID_MASK;
2935 }
523224a3
DK
2936}
2937
619c5cb6 2938static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
2939 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2940 u8 cos)
523224a3 2941{
65565884 2942 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 2943 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
2944 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2945 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 2946
619c5cb6
VZ
2947 /*
2948 * set the tss leading client id for TX classfication ==
2949 * leading RSS client id
2950 */
2951 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2952
ec6ba945
VZ
2953 if (IS_FCOE_FP(fp)) {
2954 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2955 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2956 }
523224a3
DK
2957}
2958
8d96286a 2959static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
2960{
2961 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
2962 struct event_ring_data eq_data = { {0} };
2963 u16 flags;
2964
619c5cb6 2965 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2966 /* reset IGU PF statistics: MSIX + ATTN */
2967 /* PF */
2968 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2969 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2970 (CHIP_MODE_IS_4_PORT(bp) ?
2971 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2972 /* ATTN */
2973 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2974 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2975 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2976 (CHIP_MODE_IS_4_PORT(bp) ?
2977 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2978 }
2979
523224a3
DK
2980 /* function setup flags */
2981 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2982
619c5cb6
VZ
2983 /* This flag is relevant for E1x only.
2984 * E2 doesn't have a TPA configuration in a function level.
523224a3 2985 */
619c5cb6 2986 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
2987
2988 func_init.func_flgs = flags;
2989 func_init.pf_id = BP_FUNC(bp);
2990 func_init.func_id = BP_FUNC(bp);
523224a3
DK
2991 func_init.spq_map = bp->spq_mapping;
2992 func_init.spq_prod = bp->spq_prod_idx;
2993
2994 bnx2x_func_init(bp, &func_init);
2995
2996 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2997
2998 /*
619c5cb6
VZ
2999 * Congestion management values depend on the link rate
3000 * There is no active link so initial link rate is set to 10 Gbps.
3001 * When the link comes up The congestion management values are
3002 * re-calculated according to the actual link rate.
3003 */
523224a3
DK
3004 bp->link_vars.line_speed = SPEED_10000;
3005 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3006
3007 /* Only the PMF sets the HW */
3008 if (bp->port.pmf)
3009 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3010
523224a3
DK
3011 /* init Event Queue */
3012 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3013 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3014 eq_data.producer = bp->eq_prod;
3015 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3016 eq_data.sb_id = DEF_SB_ID;
3017 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3018}
3019
3020
3021static void bnx2x_e1h_disable(struct bnx2x *bp)
3022{
3023 int port = BP_PORT(bp);
3024
619c5cb6 3025 bnx2x_tx_disable(bp);
523224a3
DK
3026
3027 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3028}
3029
3030static void bnx2x_e1h_enable(struct bnx2x *bp)
3031{
3032 int port = BP_PORT(bp);
3033
3034 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3035
3036 /* Tx queue should be only reenabled */
3037 netif_tx_wake_all_queues(bp->dev);
3038
3039 /*
3040 * Should not call netif_carrier_on since it will be called if the link
3041 * is up when checking for link state
3042 */
3043}
3044
1d187b34
BW
3045#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3046
3047static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3048{
3049 struct eth_stats_info *ether_stat =
3050 &bp->slowpath->drv_info_to_mcp.ether_stat;
3051
786fdf0b
DC
3052 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3053 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3054
15192a8c
BW
3055 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3056 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3057 ether_stat->mac_local);
1d187b34
BW
3058
3059 ether_stat->mtu_size = bp->dev->mtu;
3060
3061 if (bp->dev->features & NETIF_F_RXCSUM)
3062 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3063 if (bp->dev->features & NETIF_F_TSO)
3064 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3065 ether_stat->feature_flags |= bp->common.boot_mode;
3066
3067 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3068
3069 ether_stat->txq_size = bp->tx_ring_size;
3070 ether_stat->rxq_size = bp->rx_ring_size;
3071}
3072
3073static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3074{
3075 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3076 struct fcoe_stats_info *fcoe_stat =
3077 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3078
55c11941
MS
3079 if (!CNIC_LOADED(bp))
3080 return;
3081
2e499d3c
BW
3082 memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
3083 bp->fip_mac, ETH_ALEN);
1d187b34
BW
3084
3085 fcoe_stat->qos_priority =
3086 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3087
3088 /* insert FCoE stats from ramrod response */
3089 if (!NO_FCOE(bp)) {
3090 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3091 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3092 tstorm_queue_statistics;
3093
3094 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3095 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3096 xstorm_queue_statistics;
3097
3098 struct fcoe_statistics_params *fw_fcoe_stat =
3099 &bp->fw_stats_data->fcoe;
3100
3101 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
3102 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
3103
3104 ADD_64(fcoe_stat->rx_bytes_hi,
3105 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3106 fcoe_stat->rx_bytes_lo,
3107 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
3108
3109 ADD_64(fcoe_stat->rx_bytes_hi,
3110 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3111 fcoe_stat->rx_bytes_lo,
3112 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
3113
3114 ADD_64(fcoe_stat->rx_bytes_hi,
3115 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3116 fcoe_stat->rx_bytes_lo,
3117 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
3118
3119 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3120 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
3121
3122 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3123 fcoe_q_tstorm_stats->rcv_ucast_pkts);
3124
3125 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3126 fcoe_q_tstorm_stats->rcv_bcast_pkts);
3127
3128 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
f33f1fcc 3129 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34
BW
3130
3131 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
3132 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
3133
3134 ADD_64(fcoe_stat->tx_bytes_hi,
3135 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3136 fcoe_stat->tx_bytes_lo,
3137 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3138
3139 ADD_64(fcoe_stat->tx_bytes_hi,
3140 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3141 fcoe_stat->tx_bytes_lo,
3142 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3143
3144 ADD_64(fcoe_stat->tx_bytes_hi,
3145 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3146 fcoe_stat->tx_bytes_lo,
3147 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3148
3149 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3150 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3151
3152 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3153 fcoe_q_xstorm_stats->ucast_pkts_sent);
3154
3155 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3156 fcoe_q_xstorm_stats->bcast_pkts_sent);
3157
3158 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3159 fcoe_q_xstorm_stats->mcast_pkts_sent);
3160 }
3161
1d187b34
BW
3162 /* ask L5 driver to add data to the struct */
3163 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3164}
3165
3166static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3167{
3168 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3169 struct iscsi_stats_info *iscsi_stat =
3170 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3171
55c11941
MS
3172 if (!CNIC_LOADED(bp))
3173 return;
3174
2e499d3c
BW
3175 memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
3176 bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
1d187b34
BW
3177
3178 iscsi_stat->qos_priority =
3179 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3180
1d187b34
BW
3181 /* ask L5 driver to add data to the struct */
3182 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3183}
3184
0793f83f
DK
3185/* called due to MCP event (on pmf):
3186 * reread new bandwidth configuration
3187 * configure FW
3188 * notify others function about the change
3189 */
1191cb83 3190static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3191{
3192 if (bp->link_vars.link_up) {
3193 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3194 bnx2x_link_sync_notify(bp);
3195 }
3196 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3197}
3198
1191cb83 3199static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3200{
3201 bnx2x_config_mf_bw(bp);
3202 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3203}
3204
c8c60d88
YM
3205static void bnx2x_handle_eee_event(struct bnx2x *bp)
3206{
3207 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3208 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3209}
3210
1d187b34
BW
3211static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3212{
3213 enum drv_info_opcode op_code;
3214 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3215
3216 /* if drv_info version supported by MFW doesn't match - send NACK */
3217 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3218 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3219 return;
3220 }
3221
3222 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3223 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3224
3225 memset(&bp->slowpath->drv_info_to_mcp, 0,
3226 sizeof(union drv_info_to_mcp));
3227
3228 switch (op_code) {
3229 case ETH_STATS_OPCODE:
3230 bnx2x_drv_info_ether_stat(bp);
3231 break;
3232 case FCOE_STATS_OPCODE:
3233 bnx2x_drv_info_fcoe_stat(bp);
3234 break;
3235 case ISCSI_STATS_OPCODE:
3236 bnx2x_drv_info_iscsi_stat(bp);
3237 break;
3238 default:
3239 /* if op code isn't supported - send NACK */
3240 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3241 return;
3242 }
3243
3244 /* if we got drv_info attn from MFW then these fields are defined in
3245 * shmem2 for sure
3246 */
3247 SHMEM2_WR(bp, drv_info_host_addr_lo,
3248 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3249 SHMEM2_WR(bp, drv_info_host_addr_hi,
3250 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3251
3252 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3253}
3254
523224a3
DK
3255static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3256{
3257 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3258
3259 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3260
3261 /*
3262 * This is the only place besides the function initialization
3263 * where the bp->flags can change so it is done without any
3264 * locks
3265 */
f2e0899f 3266 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3267 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3268 bp->flags |= MF_FUNC_DIS;
3269
3270 bnx2x_e1h_disable(bp);
3271 } else {
51c1a580 3272 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3273 bp->flags &= ~MF_FUNC_DIS;
3274
3275 bnx2x_e1h_enable(bp);
3276 }
3277 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3278 }
3279 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3280 bnx2x_config_mf_bw(bp);
523224a3
DK
3281 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3282 }
3283
3284 /* Report results to MCP */
3285 if (dcc_event)
3286 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3287 else
3288 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3289}
3290
3291/* must be called under the spq lock */
1191cb83 3292static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3293{
3294 struct eth_spe *next_spe = bp->spq_prod_bd;
3295
3296 if (bp->spq_prod_bd == bp->spq_last_bd) {
3297 bp->spq_prod_bd = bp->spq;
3298 bp->spq_prod_idx = 0;
51c1a580 3299 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3300 } else {
3301 bp->spq_prod_bd++;
3302 bp->spq_prod_idx++;
3303 }
3304 return next_spe;
3305}
3306
3307/* must be called under the spq lock */
1191cb83 3308static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3309{
3310 int func = BP_FUNC(bp);
3311
53e51e2f
VZ
3312 /*
3313 * Make sure that BD data is updated before writing the producer:
3314 * BD data is written to the memory, the producer is read from the
3315 * memory, thus we need a full memory barrier to ensure the ordering.
3316 */
3317 mb();
28912902 3318
523224a3 3319 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3320 bp->spq_prod_idx);
28912902
MC
3321 mmiowb();
3322}
3323
619c5cb6
VZ
3324/**
3325 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3326 *
3327 * @cmd: command to check
3328 * @cmd_type: command type
3329 */
1191cb83 3330static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3331{
3332 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3333 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3334 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3335 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3336 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3337 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3338 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3339 return true;
3340 else
3341 return false;
3342
3343}
3344
3345
3346/**
3347 * bnx2x_sp_post - place a single command on an SP ring
3348 *
3349 * @bp: driver handle
3350 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3351 * @cid: SW CID the command is related to
3352 * @data_hi: command private data address (high 32 bits)
3353 * @data_lo: command private data address (low 32 bits)
3354 * @cmd_type: command type (e.g. NONE, ETH)
3355 *
3356 * SP data is handled as if it's always an address pair, thus data fields are
3357 * not swapped to little endian in upper functions. Instead this function swaps
3358 * data as if it's two u32 fields.
3359 */
9f6c9258 3360int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3361 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3362{
28912902 3363 struct eth_spe *spe;
523224a3 3364 u16 type;
619c5cb6 3365 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3366
a2fbb9ea 3367#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3368 if (unlikely(bp->panic)) {
3369 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3370 return -EIO;
51c1a580 3371 }
a2fbb9ea
ET
3372#endif
3373
34f80b04 3374 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3375
6e30dd4e
VZ
3376 if (common) {
3377 if (!atomic_read(&bp->eq_spq_left)) {
3378 BNX2X_ERR("BUG! EQ ring full!\n");
3379 spin_unlock_bh(&bp->spq_lock);
3380 bnx2x_panic();
3381 return -EBUSY;
3382 }
3383 } else if (!atomic_read(&bp->cq_spq_left)) {
3384 BNX2X_ERR("BUG! SPQ ring full!\n");
3385 spin_unlock_bh(&bp->spq_lock);
3386 bnx2x_panic();
3387 return -EBUSY;
a2fbb9ea 3388 }
f1410647 3389
28912902
MC
3390 spe = bnx2x_sp_get_next(bp);
3391
a2fbb9ea 3392 /* CID needs port number to be encoded int it */
28912902 3393 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3394 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3395 HW_CID(bp, cid));
523224a3 3396
619c5cb6 3397 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3398
523224a3
DK
3399 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3400 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3401
523224a3
DK
3402 spe->hdr.type = cpu_to_le16(type);
3403
3404 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3405 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3406
d6cae238
VZ
3407 /*
3408 * It's ok if the actual decrement is issued towards the memory
3409 * somewhere between the spin_lock and spin_unlock. Thus no
3410 * more explict memory barrier is needed.
3411 */
3412 if (common)
3413 atomic_dec(&bp->eq_spq_left);
3414 else
3415 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3416
a2fbb9ea 3417
51c1a580
MS
3418 DP(BNX2X_MSG_SP,
3419 "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
3420 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3421 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3422 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3423 HW_CID(bp, cid), data_hi, data_lo, type,
3424 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3425
28912902 3426 bnx2x_sp_prod_update(bp);
34f80b04 3427 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3428 return 0;
3429}
3430
3431/* acquire split MCP access lock register */
4a37fb66 3432static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3433{
72fd0718 3434 u32 j, val;
34f80b04 3435 int rc = 0;
a2fbb9ea
ET
3436
3437 might_sleep();
72fd0718 3438 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3439 val = (1UL << 31);
3440 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3441 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3442 if (val & (1L << 31))
3443 break;
3444
3445 msleep(5);
3446 }
a2fbb9ea 3447 if (!(val & (1L << 31))) {
19680c48 3448 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3449 rc = -EBUSY;
3450 }
3451
3452 return rc;
3453}
3454
4a37fb66
YG
3455/* release split MCP access lock register */
3456static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3457{
72fd0718 3458 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3459}
3460
523224a3
DK
3461#define BNX2X_DEF_SB_ATT_IDX 0x0001
3462#define BNX2X_DEF_SB_IDX 0x0002
3463
1191cb83 3464static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3465{
523224a3 3466 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3467 u16 rc = 0;
3468
3469 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3470 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3471 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3472 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3473 }
523224a3
DK
3474
3475 if (bp->def_idx != def_sb->sp_sb.running_index) {
3476 bp->def_idx = def_sb->sp_sb.running_index;
3477 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3478 }
523224a3
DK
3479
3480 /* Do not reorder: indecies reading should complete before handling */
3481 barrier();
a2fbb9ea
ET
3482 return rc;
3483}
3484
3485/*
3486 * slow path service functions
3487 */
3488
3489static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3490{
34f80b04 3491 int port = BP_PORT(bp);
a2fbb9ea
ET
3492 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3493 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3494 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3495 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3496 u32 aeu_mask;
87942b46 3497 u32 nig_mask = 0;
f2e0899f 3498 u32 reg_addr;
a2fbb9ea 3499
a2fbb9ea
ET
3500 if (bp->attn_state & asserted)
3501 BNX2X_ERR("IGU ERROR\n");
3502
3fcaf2e5
EG
3503 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3504 aeu_mask = REG_RD(bp, aeu_addr);
3505
a2fbb9ea 3506 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3507 aeu_mask, asserted);
72fd0718 3508 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3509 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3510
3fcaf2e5
EG
3511 REG_WR(bp, aeu_addr, aeu_mask);
3512 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3513
3fcaf2e5 3514 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3515 bp->attn_state |= asserted;
3fcaf2e5 3516 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3517
3518 if (asserted & ATTN_HARD_WIRED_MASK) {
3519 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3520
a5e9a7cf
EG
3521 bnx2x_acquire_phy_lock(bp);
3522
877e9aa4 3523 /* save nig interrupt mask */
87942b46 3524 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3525
361c391e
YR
3526 /* If nig_mask is not set, no need to call the update
3527 * function.
3528 */
3529 if (nig_mask) {
3530 REG_WR(bp, nig_int_mask_addr, 0);
3531
3532 bnx2x_link_attn(bp);
3533 }
a2fbb9ea
ET
3534
3535 /* handle unicore attn? */
3536 }
3537 if (asserted & ATTN_SW_TIMER_4_FUNC)
3538 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3539
3540 if (asserted & GPIO_2_FUNC)
3541 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3542
3543 if (asserted & GPIO_3_FUNC)
3544 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3545
3546 if (asserted & GPIO_4_FUNC)
3547 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3548
3549 if (port == 0) {
3550 if (asserted & ATTN_GENERAL_ATTN_1) {
3551 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3552 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3553 }
3554 if (asserted & ATTN_GENERAL_ATTN_2) {
3555 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3556 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3557 }
3558 if (asserted & ATTN_GENERAL_ATTN_3) {
3559 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3560 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3561 }
3562 } else {
3563 if (asserted & ATTN_GENERAL_ATTN_4) {
3564 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3565 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3566 }
3567 if (asserted & ATTN_GENERAL_ATTN_5) {
3568 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3569 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3570 }
3571 if (asserted & ATTN_GENERAL_ATTN_6) {
3572 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3573 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3574 }
3575 }
3576
3577 } /* if hardwired */
3578
f2e0899f
DK
3579 if (bp->common.int_block == INT_BLOCK_HC)
3580 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3581 COMMAND_REG_ATTN_BITS_SET);
3582 else
3583 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3584
3585 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3586 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3587 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3588
3589 /* now set back the mask */
a5e9a7cf 3590 if (asserted & ATTN_NIG_FOR_FUNC) {
87942b46 3591 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3592 bnx2x_release_phy_lock(bp);
3593 }
a2fbb9ea
ET
3594}
3595
1191cb83 3596static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3597{
3598 int port = BP_PORT(bp);
b7737c9b 3599 u32 ext_phy_config;
fd4ef40d 3600 /* mark the failure */
b7737c9b
YR
3601 ext_phy_config =
3602 SHMEM_RD(bp,
3603 dev_info.port_hw_config[port].external_phy_config);
3604
3605 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3606 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3607 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3608 ext_phy_config);
fd4ef40d
EG
3609
3610 /* log the failure */
51c1a580
MS
3611 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3612 "Please contact OEM Support for assistance\n");
8304859a
AE
3613
3614 /*
3615 * Scheudle device reset (unload)
3616 * This is due to some boards consuming sufficient power when driver is
3617 * up to overheat if fan fails.
3618 */
3619 smp_mb__before_clear_bit();
3620 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3621 smp_mb__after_clear_bit();
3622 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3623
fd4ef40d 3624}
ab6ad5a4 3625
1191cb83 3626static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3627{
34f80b04 3628 int port = BP_PORT(bp);
877e9aa4 3629 int reg_offset;
d90d96ba 3630 u32 val;
877e9aa4 3631
34f80b04
EG
3632 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3633 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3634
34f80b04 3635 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3636
3637 val = REG_RD(bp, reg_offset);
3638 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3639 REG_WR(bp, reg_offset, val);
3640
3641 BNX2X_ERR("SPIO5 hw attention\n");
3642
fd4ef40d 3643 /* Fan failure attention */
d90d96ba 3644 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3645 bnx2x_fan_failure(bp);
877e9aa4 3646 }
34f80b04 3647
3deb8167 3648 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3649 bnx2x_acquire_phy_lock(bp);
3650 bnx2x_handle_module_detect_int(&bp->link_params);
3651 bnx2x_release_phy_lock(bp);
3652 }
3653
34f80b04
EG
3654 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3655
3656 val = REG_RD(bp, reg_offset);
3657 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3658 REG_WR(bp, reg_offset, val);
3659
3660 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3661 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3662 bnx2x_panic();
3663 }
877e9aa4
ET
3664}
3665
1191cb83 3666static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3667{
3668 u32 val;
3669
0626b899 3670 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3671
3672 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3673 BNX2X_ERR("DB hw attention 0x%x\n", val);
3674 /* DORQ discard attention */
3675 if (val & 0x2)
3676 BNX2X_ERR("FATAL error from DORQ\n");
3677 }
34f80b04
EG
3678
3679 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3680
3681 int port = BP_PORT(bp);
3682 int reg_offset;
3683
3684 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3685 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3686
3687 val = REG_RD(bp, reg_offset);
3688 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3689 REG_WR(bp, reg_offset, val);
3690
3691 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3692 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3693 bnx2x_panic();
3694 }
877e9aa4
ET
3695}
3696
1191cb83 3697static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3698{
3699 u32 val;
3700
3701 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3702
3703 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3704 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3705 /* CFC error attention */
3706 if (val & 0x2)
3707 BNX2X_ERR("FATAL error from CFC\n");
3708 }
3709
3710 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3711 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3712 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3713 /* RQ_USDMDP_FIFO_OVERFLOW */
3714 if (val & 0x18000)
3715 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3716
3717 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3718 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3719 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3720 }
877e9aa4 3721 }
34f80b04
EG
3722
3723 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3724
3725 int port = BP_PORT(bp);
3726 int reg_offset;
3727
3728 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3729 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3730
3731 val = REG_RD(bp, reg_offset);
3732 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3733 REG_WR(bp, reg_offset, val);
3734
3735 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3736 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3737 bnx2x_panic();
3738 }
877e9aa4
ET
3739}
3740
1191cb83 3741static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3742{
34f80b04
EG
3743 u32 val;
3744
877e9aa4
ET
3745 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3746
34f80b04
EG
3747 if (attn & BNX2X_PMF_LINK_ASSERT) {
3748 int func = BP_FUNC(bp);
3749
3750 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 3751 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
3752 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3753 func_mf_config[BP_ABS_FUNC(bp)].config);
3754 val = SHMEM_RD(bp,
3755 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3756 if (val & DRV_STATUS_DCC_EVENT_MASK)
3757 bnx2x_dcc_event(bp,
3758 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3759
3760 if (val & DRV_STATUS_SET_MF_BW)
3761 bnx2x_set_mf_bw(bp);
3762
1d187b34
BW
3763 if (val & DRV_STATUS_DRV_INFO_REQ)
3764 bnx2x_handle_drv_info_req(bp);
2691d51d 3765 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3766 bnx2x_pmf_update(bp);
3767
e4901dde 3768 if (bp->port.pmf &&
785b9b1a
SR
3769 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3770 bp->dcbx_enabled > 0)
e4901dde
VZ
3771 /* start dcbx state machine */
3772 bnx2x_dcbx_set_params(bp,
3773 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
3774 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3775 bnx2x_handle_afex_cmd(bp,
3776 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
3777 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3778 bnx2x_handle_eee_event(bp);
3deb8167
YR
3779 if (bp->link_vars.periodic_flags &
3780 PERIODIC_FLAGS_LINK_EVENT) {
3781 /* sync with link */
3782 bnx2x_acquire_phy_lock(bp);
3783 bp->link_vars.periodic_flags &=
3784 ~PERIODIC_FLAGS_LINK_EVENT;
3785 bnx2x_release_phy_lock(bp);
3786 if (IS_MF(bp))
3787 bnx2x_link_sync_notify(bp);
3788 bnx2x_link_report(bp);
3789 }
3790 /* Always call it here: bnx2x_link_report() will
3791 * prevent the link indication duplication.
3792 */
3793 bnx2x__link_status_update(bp);
34f80b04 3794 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
3795
3796 BNX2X_ERR("MC assert!\n");
d6cae238 3797 bnx2x_mc_assert(bp);
877e9aa4
ET
3798 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3799 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3800 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3801 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3802 bnx2x_panic();
3803
3804 } else if (attn & BNX2X_MCP_ASSERT) {
3805
3806 BNX2X_ERR("MCP assert!\n");
3807 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 3808 bnx2x_fw_dump(bp);
877e9aa4
ET
3809
3810 } else
3811 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3812 }
3813
3814 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
3815 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3816 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
3817 val = CHIP_IS_E1(bp) ? 0 :
3818 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
3819 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3820 }
3821 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
3822 val = CHIP_IS_E1(bp) ? 0 :
3823 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
3824 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3825 }
877e9aa4 3826 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
3827 }
3828}
3829
c9ee9206
VZ
3830/*
3831 * Bits map:
3832 * 0-7 - Engine0 load counter.
3833 * 8-15 - Engine1 load counter.
3834 * 16 - Engine0 RESET_IN_PROGRESS bit.
3835 * 17 - Engine1 RESET_IN_PROGRESS bit.
3836 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3837 * on the engine
3838 * 19 - Engine1 ONE_IS_LOADED.
3839 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3840 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3841 * just the one belonging to its engine).
3842 *
3843 */
3844#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3845
3846#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3847#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3848#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3849#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3850#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3851#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3852#define BNX2X_GLOBAL_RESET_BIT 0x00040000
3853
3854/*
3855 * Set the GLOBAL_RESET bit.
3856 *
3857 * Should be run under rtnl lock
3858 */
3859void bnx2x_set_reset_global(struct bnx2x *bp)
3860{
f16da43b
AE
3861 u32 val;
3862 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3863 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3864 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 3865 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
3866}
3867
3868/*
3869 * Clear the GLOBAL_RESET bit.
3870 *
3871 * Should be run under rtnl lock
3872 */
1191cb83 3873static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 3874{
f16da43b
AE
3875 u32 val;
3876 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3877 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3878 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 3879 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 3880}
f85582f8 3881
72fd0718 3882/*
c9ee9206
VZ
3883 * Checks the GLOBAL_RESET bit.
3884 *
72fd0718
VZ
3885 * should be run under rtnl lock
3886 */
1191cb83 3887static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206
VZ
3888{
3889 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3890
3891 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3892 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3893}
3894
3895/*
3896 * Clear RESET_IN_PROGRESS bit for the current engine.
3897 *
3898 * Should be run under rtnl lock
3899 */
1191cb83 3900static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 3901{
f16da43b 3902 u32 val;
c9ee9206
VZ
3903 u32 bit = BP_PATH(bp) ?
3904 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3905 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3906 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3907
3908 /* Clear the bit */
3909 val &= ~bit;
3910 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
3911
3912 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3913}
3914
3915/*
c9ee9206
VZ
3916 * Set RESET_IN_PROGRESS for the current engine.
3917 *
72fd0718
VZ
3918 * should be run under rtnl lock
3919 */
c9ee9206 3920void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 3921{
f16da43b 3922 u32 val;
c9ee9206
VZ
3923 u32 bit = BP_PATH(bp) ?
3924 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3925 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3926 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3927
3928 /* Set the bit */
3929 val |= bit;
3930 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3931 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3932}
3933
3934/*
c9ee9206 3935 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
3936 * should be run under rtnl lock
3937 */
c9ee9206 3938bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 3939{
c9ee9206
VZ
3940 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3941 u32 bit = engine ?
3942 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3943
3944 /* return false if bit is set */
3945 return (val & bit) ? false : true;
72fd0718
VZ
3946}
3947
3948/*
889b9af3 3949 * set pf load for the current pf.
c9ee9206 3950 *
72fd0718
VZ
3951 * should be run under rtnl lock
3952 */
889b9af3 3953void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 3954{
f16da43b 3955 u32 val1, val;
c9ee9206
VZ
3956 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3957 BNX2X_PATH0_LOAD_CNT_MASK;
3958 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3959 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3960
f16da43b
AE
3961 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3962 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3963
51c1a580 3964 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 3965
c9ee9206
VZ
3966 /* get the current counter value */
3967 val1 = (val & mask) >> shift;
3968
889b9af3
AE
3969 /* set bit of that PF */
3970 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
3971
3972 /* clear the old value */
3973 val &= ~mask;
3974
3975 /* set the new one */
3976 val |= ((val1 << shift) & mask);
3977
3978 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3979 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3980}
3981
c9ee9206 3982/**
889b9af3 3983 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
3984 *
3985 * @bp: driver handle
3986 *
3987 * Should be run under rtnl lock.
3988 * Decrements the load counter for the current engine. Returns
889b9af3 3989 * whether other functions are still loaded
72fd0718 3990 */
889b9af3 3991bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 3992{
f16da43b 3993 u32 val1, val;
c9ee9206
VZ
3994 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3995 BNX2X_PATH0_LOAD_CNT_MASK;
3996 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3997 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3998
f16da43b
AE
3999 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4000 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4001 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4002
c9ee9206
VZ
4003 /* get the current counter value */
4004 val1 = (val & mask) >> shift;
4005
889b9af3
AE
4006 /* clear bit of that PF */
4007 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4008
4009 /* clear the old value */
4010 val &= ~mask;
4011
4012 /* set the new one */
4013 val |= ((val1 << shift) & mask);
4014
4015 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4016 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4017 return val1 != 0;
72fd0718
VZ
4018}
4019
4020/*
889b9af3 4021 * Read the load status for the current engine.
c9ee9206 4022 *
72fd0718
VZ
4023 * should be run under rtnl lock
4024 */
1191cb83 4025static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4026{
c9ee9206
VZ
4027 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4028 BNX2X_PATH0_LOAD_CNT_MASK);
4029 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4030 BNX2X_PATH0_LOAD_CNT_SHIFT);
4031 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4032
51c1a580 4033 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4034
4035 val = (val & mask) >> shift;
4036
51c1a580
MS
4037 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4038 engine, val);
c9ee9206 4039
889b9af3 4040 return val != 0;
72fd0718
VZ
4041}
4042
1191cb83 4043static void _print_next_block(int idx, const char *blk)
72fd0718 4044{
f1deab50 4045 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4046}
4047
1191cb83
ED
4048static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4049 bool print)
72fd0718
VZ
4050{
4051 int i = 0;
4052 u32 cur_bit = 0;
4053 for (i = 0; sig; i++) {
4054 cur_bit = ((u32)0x1 << i);
4055 if (sig & cur_bit) {
4056 switch (cur_bit) {
4057 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
4058 if (print)
4059 _print_next_block(par_num++, "BRB");
72fd0718
VZ
4060 break;
4061 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
4062 if (print)
4063 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
4064 break;
4065 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
4066 if (print)
4067 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
4068 break;
4069 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
4070 if (print)
4071 _print_next_block(par_num++,
4072 "SEARCHER");
4073 break;
4074 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4075 if (print)
4076 _print_next_block(par_num++, "TCM");
72fd0718
VZ
4077 break;
4078 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
4079 if (print)
4080 _print_next_block(par_num++, "TSEMI");
4081 break;
4082 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4083 if (print)
4084 _print_next_block(par_num++, "XPB");
72fd0718
VZ
4085 break;
4086 }
4087
4088 /* Clear the bit */
4089 sig &= ~cur_bit;
4090 }
4091 }
4092
4093 return par_num;
4094}
4095
1191cb83
ED
4096static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4097 bool *global, bool print)
72fd0718
VZ
4098{
4099 int i = 0;
4100 u32 cur_bit = 0;
4101 for (i = 0; sig; i++) {
4102 cur_bit = ((u32)0x1 << i);
4103 if (sig & cur_bit) {
4104 switch (cur_bit) {
c9ee9206
VZ
4105 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4106 if (print)
4107 _print_next_block(par_num++, "PBF");
72fd0718
VZ
4108 break;
4109 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
4110 if (print)
4111 _print_next_block(par_num++, "QM");
4112 break;
4113 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4114 if (print)
4115 _print_next_block(par_num++, "TM");
72fd0718
VZ
4116 break;
4117 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
4118 if (print)
4119 _print_next_block(par_num++, "XSDM");
4120 break;
4121 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4122 if (print)
4123 _print_next_block(par_num++, "XCM");
72fd0718
VZ
4124 break;
4125 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
4126 if (print)
4127 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
4128 break;
4129 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
4130 if (print)
4131 _print_next_block(par_num++,
4132 "DOORBELLQ");
4133 break;
4134 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4135 if (print)
4136 _print_next_block(par_num++, "NIG");
72fd0718
VZ
4137 break;
4138 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
4139 if (print)
4140 _print_next_block(par_num++,
4141 "VAUX PCI CORE");
4142 *global = true;
72fd0718
VZ
4143 break;
4144 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
4145 if (print)
4146 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
4147 break;
4148 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
4149 if (print)
4150 _print_next_block(par_num++, "USDM");
72fd0718 4151 break;
8736c826
VZ
4152 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4153 if (print)
4154 _print_next_block(par_num++, "UCM");
4155 break;
72fd0718 4156 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
4157 if (print)
4158 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
4159 break;
4160 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
4161 if (print)
4162 _print_next_block(par_num++, "UPB");
72fd0718
VZ
4163 break;
4164 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
4165 if (print)
4166 _print_next_block(par_num++, "CSDM");
72fd0718 4167 break;
8736c826
VZ
4168 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4169 if (print)
4170 _print_next_block(par_num++, "CCM");
4171 break;
72fd0718
VZ
4172 }
4173
4174 /* Clear the bit */
4175 sig &= ~cur_bit;
4176 }
4177 }
4178
4179 return par_num;
4180}
4181
1191cb83
ED
4182static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4183 bool print)
72fd0718
VZ
4184{
4185 int i = 0;
4186 u32 cur_bit = 0;
4187 for (i = 0; sig; i++) {
4188 cur_bit = ((u32)0x1 << i);
4189 if (sig & cur_bit) {
4190 switch (cur_bit) {
4191 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
4192 if (print)
4193 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
4194 break;
4195 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
4196 if (print)
4197 _print_next_block(par_num++, "PXP");
72fd0718
VZ
4198 break;
4199 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
4200 if (print)
4201 _print_next_block(par_num++,
72fd0718
VZ
4202 "PXPPCICLOCKCLIENT");
4203 break;
4204 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
4205 if (print)
4206 _print_next_block(par_num++, "CFC");
72fd0718
VZ
4207 break;
4208 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
4209 if (print)
4210 _print_next_block(par_num++, "CDU");
4211 break;
4212 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4213 if (print)
4214 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
4215 break;
4216 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
4217 if (print)
4218 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4219 break;
4220 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4221 if (print)
4222 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4223 break;
4224 }
4225
4226 /* Clear the bit */
4227 sig &= ~cur_bit;
4228 }
4229 }
4230
4231 return par_num;
4232}
4233
1191cb83
ED
4234static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4235 bool *global, bool print)
72fd0718
VZ
4236{
4237 int i = 0;
4238 u32 cur_bit = 0;
4239 for (i = 0; sig; i++) {
4240 cur_bit = ((u32)0x1 << i);
4241 if (sig & cur_bit) {
4242 switch (cur_bit) {
4243 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4244 if (print)
4245 _print_next_block(par_num++, "MCP ROM");
4246 *global = true;
72fd0718
VZ
4247 break;
4248 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4249 if (print)
4250 _print_next_block(par_num++,
4251 "MCP UMP RX");
4252 *global = true;
72fd0718
VZ
4253 break;
4254 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4255 if (print)
4256 _print_next_block(par_num++,
4257 "MCP UMP TX");
4258 *global = true;
72fd0718
VZ
4259 break;
4260 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4261 if (print)
4262 _print_next_block(par_num++,
4263 "MCP SCPAD");
4264 *global = true;
72fd0718
VZ
4265 break;
4266 }
4267
4268 /* Clear the bit */
4269 sig &= ~cur_bit;
4270 }
4271 }
4272
4273 return par_num;
4274}
4275
1191cb83
ED
4276static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4277 bool print)
8736c826
VZ
4278{
4279 int i = 0;
4280 u32 cur_bit = 0;
4281 for (i = 0; sig; i++) {
4282 cur_bit = ((u32)0x1 << i);
4283 if (sig & cur_bit) {
4284 switch (cur_bit) {
4285 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4286 if (print)
4287 _print_next_block(par_num++, "PGLUE_B");
4288 break;
4289 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4290 if (print)
4291 _print_next_block(par_num++, "ATC");
4292 break;
4293 }
4294
4295 /* Clear the bit */
4296 sig &= ~cur_bit;
4297 }
4298 }
4299
4300 return par_num;
4301}
4302
1191cb83
ED
4303static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4304 u32 *sig)
72fd0718 4305{
8736c826
VZ
4306 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4307 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4308 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4309 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4310 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4311 int par_num = 0;
51c1a580
MS
4312 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4313 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4314 sig[0] & HW_PRTY_ASSERT_SET_0,
4315 sig[1] & HW_PRTY_ASSERT_SET_1,
4316 sig[2] & HW_PRTY_ASSERT_SET_2,
4317 sig[3] & HW_PRTY_ASSERT_SET_3,
4318 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4319 if (print)
4320 netdev_err(bp->dev,
4321 "Parity errors detected in blocks: ");
4322 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4323 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4324 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4325 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4326 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4327 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4328 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4329 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4330 par_num = bnx2x_check_blocks_with_parity4(
4331 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4332
c9ee9206
VZ
4333 if (print)
4334 pr_cont("\n");
8736c826 4335
72fd0718
VZ
4336 return true;
4337 } else
4338 return false;
4339}
4340
c9ee9206
VZ
4341/**
4342 * bnx2x_chk_parity_attn - checks for parity attentions.
4343 *
4344 * @bp: driver handle
4345 * @global: true if there was a global attention
4346 * @print: show parity attention in syslog
4347 */
4348bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4349{
8736c826 4350 struct attn_route attn = { {0} };
72fd0718
VZ
4351 int port = BP_PORT(bp);
4352
4353 attn.sig[0] = REG_RD(bp,
4354 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4355 port*4);
4356 attn.sig[1] = REG_RD(bp,
4357 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4358 port*4);
4359 attn.sig[2] = REG_RD(bp,
4360 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4361 port*4);
4362 attn.sig[3] = REG_RD(bp,
4363 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4364 port*4);
4365
8736c826
VZ
4366 if (!CHIP_IS_E1x(bp))
4367 attn.sig[4] = REG_RD(bp,
4368 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4369 port*4);
4370
4371 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4372}
4373
f2e0899f 4374
1191cb83 4375static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4376{
4377 u32 val;
4378 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4379
4380 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4381 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4382 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4383 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4384 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4385 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4386 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4387 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4388 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4389 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4390 if (val &
4391 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4392 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4393 if (val &
4394 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4395 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4396 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4397 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4398 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4399 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4400 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4401 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4402 }
4403 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4404 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4405 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4406 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4407 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4408 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4409 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4410 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4411 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4412 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4413 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4414 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4415 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4416 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4417 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4418 }
4419
4420 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4421 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4422 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4423 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4424 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4425 }
4426
4427}
4428
72fd0718
VZ
4429static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4430{
4431 struct attn_route attn, *group_mask;
34f80b04 4432 int port = BP_PORT(bp);
877e9aa4 4433 int index;
a2fbb9ea
ET
4434 u32 reg_addr;
4435 u32 val;
3fcaf2e5 4436 u32 aeu_mask;
c9ee9206 4437 bool global = false;
a2fbb9ea
ET
4438
4439 /* need to take HW lock because MCP or other port might also
4440 try to handle this event */
4a37fb66 4441 bnx2x_acquire_alr(bp);
a2fbb9ea 4442
c9ee9206
VZ
4443 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4444#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4445 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4446 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4447 /* Disable HW interrupts */
4448 bnx2x_int_disable(bp);
72fd0718
VZ
4449 /* In case of parity errors don't handle attentions so that
4450 * other function would "see" parity errors.
4451 */
c9ee9206
VZ
4452#else
4453 bnx2x_panic();
4454#endif
4455 bnx2x_release_alr(bp);
72fd0718
VZ
4456 return;
4457 }
4458
a2fbb9ea
ET
4459 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4460 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4461 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4462 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4463 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4464 attn.sig[4] =
4465 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4466 else
4467 attn.sig[4] = 0;
4468
4469 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4470 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4471
4472 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4473 if (deasserted & (1 << index)) {
72fd0718 4474 group_mask = &bp->attn_group[index];
a2fbb9ea 4475
51c1a580 4476 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4477 index,
4478 group_mask->sig[0], group_mask->sig[1],
4479 group_mask->sig[2], group_mask->sig[3],
4480 group_mask->sig[4]);
a2fbb9ea 4481
f2e0899f
DK
4482 bnx2x_attn_int_deasserted4(bp,
4483 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4484 bnx2x_attn_int_deasserted3(bp,
72fd0718 4485 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4486 bnx2x_attn_int_deasserted1(bp,
72fd0718 4487 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4488 bnx2x_attn_int_deasserted2(bp,
72fd0718 4489 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4490 bnx2x_attn_int_deasserted0(bp,
72fd0718 4491 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4492 }
4493 }
4494
4a37fb66 4495 bnx2x_release_alr(bp);
a2fbb9ea 4496
f2e0899f
DK
4497 if (bp->common.int_block == INT_BLOCK_HC)
4498 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4499 COMMAND_REG_ATTN_BITS_CLR);
4500 else
4501 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4502
4503 val = ~deasserted;
f2e0899f
DK
4504 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4505 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4506 REG_WR(bp, reg_addr, val);
a2fbb9ea 4507
a2fbb9ea 4508 if (~bp->attn_state & deasserted)
3fcaf2e5 4509 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4510
4511 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4512 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4513
3fcaf2e5
EG
4514 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4515 aeu_mask = REG_RD(bp, reg_addr);
4516
4517 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4518 aeu_mask, deasserted);
72fd0718 4519 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4520 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4521
3fcaf2e5
EG
4522 REG_WR(bp, reg_addr, aeu_mask);
4523 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4524
4525 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4526 bp->attn_state &= ~deasserted;
4527 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4528}
4529
4530static void bnx2x_attn_int(struct bnx2x *bp)
4531{
4532 /* read local copy of bits */
68d59484
EG
4533 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4534 attn_bits);
4535 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4536 attn_bits_ack);
a2fbb9ea
ET
4537 u32 attn_state = bp->attn_state;
4538
4539 /* look for changed bits */
4540 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4541 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4542
4543 DP(NETIF_MSG_HW,
4544 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4545 attn_bits, attn_ack, asserted, deasserted);
4546
4547 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4548 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4549
4550 /* handle bits that were raised */
4551 if (asserted)
4552 bnx2x_attn_int_asserted(bp, asserted);
4553
4554 if (deasserted)
4555 bnx2x_attn_int_deasserted(bp, deasserted);
4556}
4557
619c5cb6
VZ
4558void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4559 u16 index, u8 op, u8 update)
4560{
4561 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4562
4563 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4564 igu_addr);
4565}
4566
1191cb83 4567static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4568{
4569 /* No memory barriers */
4570 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4571 mmiowb(); /* keep prod updates ordered */
4572}
4573
523224a3
DK
4574static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4575 union event_ring_elem *elem)
4576{
619c5cb6
VZ
4577 u8 err = elem->message.error;
4578
523224a3 4579 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4580 (cid < bp->cnic_eth_dev.starting_cid &&
4581 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4582 return 1;
4583
4584 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4585
619c5cb6
VZ
4586 if (unlikely(err)) {
4587
523224a3
DK
4588 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4589 cid);
4590 bnx2x_panic_dump(bp);
4591 }
619c5cb6 4592 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4593 return 0;
4594}
523224a3 4595
1191cb83 4596static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4597{
4598 struct bnx2x_mcast_ramrod_params rparam;
4599 int rc;
4600
4601 memset(&rparam, 0, sizeof(rparam));
4602
4603 rparam.mcast_obj = &bp->mcast_obj;
4604
4605 netif_addr_lock_bh(bp->dev);
4606
4607 /* Clear pending state for the last command */
4608 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4609
4610 /* If there are pending mcast commands - send them */
4611 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4612 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4613 if (rc < 0)
4614 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4615 rc);
4616 }
4617
4618 netif_addr_unlock_bh(bp->dev);
4619}
4620
1191cb83
ED
4621static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4622 union event_ring_elem *elem)
619c5cb6
VZ
4623{
4624 unsigned long ramrod_flags = 0;
4625 int rc = 0;
4626 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4627 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4628
4629 /* Always push next commands out, don't wait here */
4630 __set_bit(RAMROD_CONT, &ramrod_flags);
4631
4632 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4633 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4634 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 4635 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
4636 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4637 else
15192a8c 4638 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
4639
4640 break;
619c5cb6 4641 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4642 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4643 /* This is only relevant for 57710 where multicast MACs are
4644 * configured as unicast MACs using the same ramrod.
4645 */
4646 bnx2x_handle_mcast_eqe(bp);
4647 return;
4648 default:
4649 BNX2X_ERR("Unsupported classification command: %d\n",
4650 elem->message.data.eth_event.echo);
4651 return;
4652 }
4653
4654 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4655
4656 if (rc < 0)
4657 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4658 else if (rc > 0)
4659 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4660
4661}
4662
619c5cb6 4663static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 4664
1191cb83 4665static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
4666{
4667 netif_addr_lock_bh(bp->dev);
4668
4669 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4670
4671 /* Send rx_mode command again if was requested */
4672 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4673 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
4674 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4675 &bp->sp_state))
4676 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4677 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4678 &bp->sp_state))
4679 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
4680
4681 netif_addr_unlock_bh(bp->dev);
4682}
4683
1191cb83 4684static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
4685 union event_ring_elem *elem)
4686{
4687 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4688 DP(BNX2X_MSG_SP,
4689 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4690 elem->message.data.vif_list_event.func_bit_map);
4691 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4692 elem->message.data.vif_list_event.func_bit_map);
4693 } else if (elem->message.data.vif_list_event.echo ==
4694 VIF_LIST_RULE_SET) {
4695 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4696 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4697 }
4698}
4699
4700/* called with rtnl_lock */
1191cb83 4701static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
4702{
4703 int q, rc;
4704 struct bnx2x_fastpath *fp;
4705 struct bnx2x_queue_state_params queue_params = {NULL};
4706 struct bnx2x_queue_update_params *q_update_params =
4707 &queue_params.params.update;
4708
4709 /* Send Q update command with afex vlan removal values for all Qs */
4710 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4711
4712 /* set silent vlan removal values according to vlan mode */
4713 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4714 &q_update_params->update_flags);
4715 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4716 &q_update_params->update_flags);
4717 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4718
4719 /* in access mode mark mask and value are 0 to strip all vlans */
4720 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4721 q_update_params->silent_removal_value = 0;
4722 q_update_params->silent_removal_mask = 0;
4723 } else {
4724 q_update_params->silent_removal_value =
4725 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4726 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4727 }
4728
4729 for_each_eth_queue(bp, q) {
4730 /* Set the appropriate Queue object */
4731 fp = &bp->fp[q];
15192a8c 4732 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4733
4734 /* send the ramrod */
4735 rc = bnx2x_queue_state_change(bp, &queue_params);
4736 if (rc < 0)
4737 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4738 q);
4739 }
4740
a3348722 4741 if (!NO_FCOE(bp)) {
65565884 4742 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 4743 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4744
4745 /* clear pending completion bit */
4746 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4747
4748 /* mark latest Q bit */
4749 smp_mb__before_clear_bit();
4750 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4751 smp_mb__after_clear_bit();
4752
4753 /* send Q update ramrod for FCoE Q */
4754 rc = bnx2x_queue_state_change(bp, &queue_params);
4755 if (rc < 0)
4756 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4757 q);
4758 } else {
4759 /* If no FCoE ring - ACK MCP now */
4760 bnx2x_link_report(bp);
4761 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4762 }
a3348722
BW
4763}
4764
1191cb83 4765static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
4766 struct bnx2x *bp, u32 cid)
4767{
94f05b0f 4768 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
4769
4770 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 4771 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 4772 else
15192a8c 4773 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
4774}
4775
523224a3
DK
4776static void bnx2x_eq_int(struct bnx2x *bp)
4777{
4778 u16 hw_cons, sw_cons, sw_prod;
4779 union event_ring_elem *elem;
55c11941 4780 u8 echo;
523224a3
DK
4781 u32 cid;
4782 u8 opcode;
4783 int spqe_cnt = 0;
619c5cb6
VZ
4784 struct bnx2x_queue_sp_obj *q_obj;
4785 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4786 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4787
4788 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4789
4790 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4791 * when we get the the next-page we nned to adjust so the loop
4792 * condition below will be met. The next element is the size of a
4793 * regular element and hence incrementing by 1
4794 */
4795 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4796 hw_cons++;
4797
25985edc 4798 /* This function may never run in parallel with itself for a
523224a3
DK
4799 * specific bp, thus there is no need in "paired" read memory
4800 * barrier here.
4801 */
4802 sw_cons = bp->eq_cons;
4803 sw_prod = bp->eq_prod;
4804
d6cae238 4805 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 4806 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
4807
4808 for (; sw_cons != hw_cons;
4809 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4810
4811
4812 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4813
4814 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4815 opcode = elem->message.opcode;
4816
4817
4818 /* handle eq element */
4819 switch (opcode) {
4820 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
4821 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4822 "got statistics comp event %d\n",
619c5cb6 4823 bp->stats_comp++);
523224a3 4824 /* nothing to do with stats comp */
d6cae238 4825 goto next_spqe;
523224a3
DK
4826
4827 case EVENT_RING_OPCODE_CFC_DEL:
4828 /* handle according to cid range */
4829 /*
4830 * we may want to verify here that the bp state is
4831 * HALTING
4832 */
d6cae238 4833 DP(BNX2X_MSG_SP,
523224a3 4834 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
4835
4836 if (CNIC_LOADED(bp) &&
4837 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 4838 goto next_spqe;
55c11941 4839
619c5cb6
VZ
4840 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4841
4842 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4843 break;
4844
4845
523224a3
DK
4846
4847 goto next_spqe;
e4901dde
VZ
4848
4849 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 4850 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
4851 if (f_obj->complete_cmd(bp, f_obj,
4852 BNX2X_F_CMD_TX_STOP))
4853 break;
e4901dde
VZ
4854 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4855 goto next_spqe;
619c5cb6 4856
e4901dde 4857 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 4858 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
4859 if (f_obj->complete_cmd(bp, f_obj,
4860 BNX2X_F_CMD_TX_START))
4861 break;
e4901dde
VZ
4862 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4863 goto next_spqe;
55c11941 4864
a3348722 4865 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
4866 echo = elem->message.data.function_update_event.echo;
4867 if (echo == SWITCH_UPDATE) {
4868 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4869 "got FUNC_SWITCH_UPDATE ramrod\n");
4870 if (f_obj->complete_cmd(
4871 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
4872 break;
a3348722 4873
55c11941
MS
4874 } else {
4875 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
4876 "AFEX: ramrod completed FUNCTION_UPDATE\n");
4877 f_obj->complete_cmd(bp, f_obj,
4878 BNX2X_F_CMD_AFEX_UPDATE);
4879
4880 /* We will perform the Queues update from
4881 * sp_rtnl task as all Queue SP operations
4882 * should run under rtnl_lock.
4883 */
4884 smp_mb__before_clear_bit();
4885 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
4886 &bp->sp_rtnl_state);
4887 smp_mb__after_clear_bit();
4888
4889 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4890 }
a3348722 4891
a3348722
BW
4892 goto next_spqe;
4893
4894 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
4895 f_obj->complete_cmd(bp, f_obj,
4896 BNX2X_F_CMD_AFEX_VIFLISTS);
4897 bnx2x_after_afex_vif_lists(bp, elem);
4898 goto next_spqe;
619c5cb6 4899 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
4900 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4901 "got FUNC_START ramrod\n");
619c5cb6
VZ
4902 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4903 break;
4904
4905 goto next_spqe;
4906
4907 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
4908 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4909 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
4910 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4911 break;
4912
4913 goto next_spqe;
523224a3
DK
4914 }
4915
4916 switch (opcode | bp->state) {
619c5cb6
VZ
4917 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4918 BNX2X_STATE_OPEN):
4919 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 4920 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
4921 cid = elem->message.data.eth_event.echo &
4922 BNX2X_SWCID_MASK;
d6cae238 4923 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
4924 cid);
4925 rss_raw->clear_pending(rss_raw);
523224a3
DK
4926 break;
4927
619c5cb6
VZ
4928 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4929 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4930 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 4931 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
4932 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4933 BNX2X_STATE_OPEN):
4934 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4935 BNX2X_STATE_DIAG):
4936 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4937 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4938 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 4939 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
4940 break;
4941
619c5cb6
VZ
4942 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4943 BNX2X_STATE_OPEN):
4944 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4945 BNX2X_STATE_DIAG):
4946 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4947 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4948 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 4949 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
4950 break;
4951
619c5cb6
VZ
4952 case (EVENT_RING_OPCODE_FILTERS_RULES |
4953 BNX2X_STATE_OPEN):
4954 case (EVENT_RING_OPCODE_FILTERS_RULES |
4955 BNX2X_STATE_DIAG):
4956 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 4957 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4958 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 4959 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
4960 break;
4961 default:
4962 /* unknown event log error and continue */
619c5cb6
VZ
4963 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4964 elem->message.opcode, bp->state);
523224a3
DK
4965 }
4966next_spqe:
4967 spqe_cnt++;
4968 } /* for */
4969
8fe23fbd 4970 smp_mb__before_atomic_inc();
6e30dd4e 4971 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
4972
4973 bp->eq_cons = sw_cons;
4974 bp->eq_prod = sw_prod;
4975 /* Make sure that above mem writes were issued towards the memory */
4976 smp_wmb();
4977
4978 /* update producer */
4979 bnx2x_update_eq_prod(bp, bp->eq_prod);
4980}
4981
a2fbb9ea
ET
4982static void bnx2x_sp_task(struct work_struct *work)
4983{
1cf167f2 4984 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea
ET
4985 u16 status;
4986
a2fbb9ea 4987 status = bnx2x_update_dsb_idx(bp);
34f80b04
EG
4988/* if (status == 0) */
4989/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
a2fbb9ea 4990
51c1a580 4991 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
a2fbb9ea 4992
877e9aa4 4993 /* HW attentions */
523224a3 4994 if (status & BNX2X_DEF_SB_ATT_IDX) {
a2fbb9ea 4995 bnx2x_attn_int(bp);
523224a3 4996 status &= ~BNX2X_DEF_SB_ATT_IDX;
cdaa7cb8
VZ
4997 }
4998
523224a3
DK
4999 /* SP events: STAT_QUERY and others */
5000 if (status & BNX2X_DEF_SB_IDX) {
ec6ba945 5001 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5002
55c11941
MS
5003 if (FCOE_INIT(bp) &&
5004 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
019dbb4c
VZ
5005 /*
5006 * Prevent local bottom-halves from running as
5007 * we are going to change the local NAPI list.
5008 */
5009 local_bh_disable();
ec6ba945 5010 napi_schedule(&bnx2x_fcoe(bp, napi));
019dbb4c
VZ
5011 local_bh_enable();
5012 }
55c11941 5013
523224a3
DK
5014 /* Handle EQ completions */
5015 bnx2x_eq_int(bp);
5016
5017 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5018 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5019
5020 status &= ~BNX2X_DEF_SB_IDX;
cdaa7cb8
VZ
5021 }
5022
5023 if (unlikely(status))
51c1a580 5024 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
cdaa7cb8 5025 status);
a2fbb9ea 5026
523224a3
DK
5027 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5028 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
a3348722
BW
5029
5030 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5031 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5032 &bp->sp_state)) {
5033 bnx2x_link_report(bp);
5034 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5035 }
a2fbb9ea
ET
5036}
5037
9f6c9258 5038irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5039{
5040 struct net_device *dev = dev_instance;
5041 struct bnx2x *bp = netdev_priv(dev);
5042
523224a3
DK
5043 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5044 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5045
5046#ifdef BNX2X_STOP_ON_ERROR
5047 if (unlikely(bp->panic))
5048 return IRQ_HANDLED;
5049#endif
5050
55c11941 5051 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5052 struct cnic_ops *c_ops;
5053
5054 rcu_read_lock();
5055 c_ops = rcu_dereference(bp->cnic_ops);
5056 if (c_ops)
5057 c_ops->cnic_handler(bp->cnic_data, NULL);
5058 rcu_read_unlock();
5059 }
55c11941 5060
1cf167f2 5061 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
a2fbb9ea
ET
5062
5063 return IRQ_HANDLED;
5064}
5065
5066/* end of slow path */
5067
619c5cb6
VZ
5068
5069void bnx2x_drv_pulse(struct bnx2x *bp)
5070{
5071 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5072 bp->fw_drv_pulse_wr_seq);
5073}
5074
5075
a2fbb9ea
ET
5076static void bnx2x_timer(unsigned long data)
5077{
5078 struct bnx2x *bp = (struct bnx2x *) data;
5079
5080 if (!netif_running(bp->dev))
5081 return;
5082
34f80b04 5083 if (!BP_NOMCP(bp)) {
f2e0899f 5084 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
5085 u32 drv_pulse;
5086 u32 mcp_pulse;
5087
5088 ++bp->fw_drv_pulse_wr_seq;
5089 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5090 /* TBD - add SYSTEM_TIME */
5091 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5092 bnx2x_drv_pulse(bp);
a2fbb9ea 5093
f2e0899f 5094 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5095 MCP_PULSE_SEQ_MASK);
5096 /* The delta between driver pulse and mcp response
5097 * should be 1 (before mcp response) or 0 (after mcp response)
5098 */
5099 if ((drv_pulse != mcp_pulse) &&
5100 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5101 /* someone lost a heartbeat... */
5102 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5103 drv_pulse, mcp_pulse);
5104 }
5105 }
5106
f34d28ea 5107 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5108 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5109
a2fbb9ea
ET
5110 mod_timer(&bp->timer, jiffies + bp->current_interval);
5111}
5112
5113/* end of Statistics */
5114
5115/* nic init */
5116
5117/*
5118 * nic init service functions
5119 */
5120
1191cb83 5121static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5122{
523224a3
DK
5123 u32 i;
5124 if (!(len%4) && !(addr%4))
5125 for (i = 0; i < len; i += 4)
5126 REG_WR(bp, addr + i, fill);
5127 else
5128 for (i = 0; i < len; i++)
5129 REG_WR8(bp, addr + i, fill);
34f80b04 5130
34f80b04
EG
5131}
5132
523224a3 5133/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5134static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5135 int fw_sb_id,
5136 u32 *sb_data_p,
5137 u32 data_size)
34f80b04 5138{
a2fbb9ea 5139 int index;
523224a3
DK
5140 for (index = 0; index < data_size; index++)
5141 REG_WR(bp, BAR_CSTRORM_INTMEM +
5142 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5143 sizeof(u32)*index,
5144 *(sb_data_p + index));
5145}
a2fbb9ea 5146
1191cb83 5147static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5148{
5149 u32 *sb_data_p;
5150 u32 data_size = 0;
f2e0899f 5151 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5152 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5153
523224a3 5154 /* disable the function first */
619c5cb6 5155 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5156 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5157 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5158 sb_data_e2.common.p_func.vf_valid = false;
5159 sb_data_p = (u32 *)&sb_data_e2;
5160 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5161 } else {
5162 memset(&sb_data_e1x, 0,
5163 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5164 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5165 sb_data_e1x.common.p_func.vf_valid = false;
5166 sb_data_p = (u32 *)&sb_data_e1x;
5167 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5168 }
523224a3 5169 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5170
523224a3
DK
5171 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5172 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5173 CSTORM_STATUS_BLOCK_SIZE);
5174 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5175 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5176 CSTORM_SYNC_BLOCK_SIZE);
5177}
34f80b04 5178
523224a3 5179/* helper: writes SP SB data to FW */
1191cb83 5180static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5181 struct hc_sp_status_block_data *sp_sb_data)
5182{
5183 int func = BP_FUNC(bp);
5184 int i;
5185 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5186 REG_WR(bp, BAR_CSTRORM_INTMEM +
5187 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5188 i*sizeof(u32),
5189 *((u32 *)sp_sb_data + i));
34f80b04
EG
5190}
5191
1191cb83 5192static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5193{
5194 int func = BP_FUNC(bp);
523224a3
DK
5195 struct hc_sp_status_block_data sp_sb_data;
5196 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5197
619c5cb6 5198 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5199 sp_sb_data.p_func.vf_valid = false;
5200
5201 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5202
5203 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5204 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5205 CSTORM_SP_STATUS_BLOCK_SIZE);
5206 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5207 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5208 CSTORM_SP_SYNC_BLOCK_SIZE);
5209
5210}
5211
5212
1191cb83 5213static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5214 int igu_sb_id, int igu_seg_id)
5215{
5216 hc_sm->igu_sb_id = igu_sb_id;
5217 hc_sm->igu_seg_id = igu_seg_id;
5218 hc_sm->timer_value = 0xFF;
5219 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5220}
5221
150966ad
AE
5222
5223/* allocates state machine ids. */
1191cb83 5224static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5225{
5226 /* zero out state machine indices */
5227 /* rx indices */
5228 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5229
5230 /* tx indices */
5231 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5232 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5233 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5234 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5235
5236 /* map indices */
5237 /* rx indices */
5238 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5239 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5240
5241 /* tx indices */
5242 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5243 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5244 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5245 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5246 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5247 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5248 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5249 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5250}
5251
8d96286a 5252static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5253 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5254{
523224a3
DK
5255 int igu_seg_id;
5256
f2e0899f 5257 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5258 struct hc_status_block_data_e1x sb_data_e1x;
5259 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5260 int data_size;
5261 u32 *sb_data_p;
5262
f2e0899f
DK
5263 if (CHIP_INT_MODE_IS_BC(bp))
5264 igu_seg_id = HC_SEG_ACCESS_NORM;
5265 else
5266 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5267
5268 bnx2x_zero_fp_sb(bp, fw_sb_id);
5269
619c5cb6 5270 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5271 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5272 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5273 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5274 sb_data_e2.common.p_func.vf_id = vfid;
5275 sb_data_e2.common.p_func.vf_valid = vf_valid;
5276 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5277 sb_data_e2.common.same_igu_sb_1b = true;
5278 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5279 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5280 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5281 sb_data_p = (u32 *)&sb_data_e2;
5282 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5283 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5284 } else {
5285 memset(&sb_data_e1x, 0,
5286 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5287 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5288 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5289 sb_data_e1x.common.p_func.vf_id = 0xff;
5290 sb_data_e1x.common.p_func.vf_valid = false;
5291 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5292 sb_data_e1x.common.same_igu_sb_1b = true;
5293 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5294 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5295 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5296 sb_data_p = (u32 *)&sb_data_e1x;
5297 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5298 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5299 }
523224a3
DK
5300
5301 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5302 igu_sb_id, igu_seg_id);
5303 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5304 igu_sb_id, igu_seg_id);
5305
51c1a580 5306 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3
DK
5307
5308 /* write indecies to HW */
5309 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5310}
5311
619c5cb6 5312static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5313 u16 tx_usec, u16 rx_usec)
5314{
6383c0b3 5315 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5316 false, rx_usec);
6383c0b3
AE
5317 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5318 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5319 tx_usec);
5320 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5321 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5322 tx_usec);
5323 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5324 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5325 tx_usec);
523224a3 5326}
f2e0899f 5327
523224a3
DK
5328static void bnx2x_init_def_sb(struct bnx2x *bp)
5329{
5330 struct host_sp_status_block *def_sb = bp->def_status_blk;
5331 dma_addr_t mapping = bp->def_status_blk_mapping;
5332 int igu_sp_sb_index;
5333 int igu_seg_id;
34f80b04
EG
5334 int port = BP_PORT(bp);
5335 int func = BP_FUNC(bp);
f2eaeb58 5336 int reg_offset, reg_offset_en5;
a2fbb9ea 5337 u64 section;
523224a3
DK
5338 int index;
5339 struct hc_sp_status_block_data sp_sb_data;
5340 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5341
f2e0899f
DK
5342 if (CHIP_INT_MODE_IS_BC(bp)) {
5343 igu_sp_sb_index = DEF_SB_IGU_ID;
5344 igu_seg_id = HC_SEG_ACCESS_DEF;
5345 } else {
5346 igu_sp_sb_index = bp->igu_dsb_id;
5347 igu_seg_id = IGU_SEG_ACCESS_DEF;
5348 }
a2fbb9ea
ET
5349
5350 /* ATTN */
523224a3 5351 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5352 atten_status_block);
523224a3 5353 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5354
49d66772
ET
5355 bp->attn_state = 0;
5356
a2fbb9ea
ET
5357 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5358 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5359 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5360 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5361 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5362 int sindex;
5363 /* take care of sig[0]..sig[4] */
5364 for (sindex = 0; sindex < 4; sindex++)
5365 bp->attn_group[index].sig[sindex] =
5366 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5367
619c5cb6 5368 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5369 /*
5370 * enable5 is separate from the rest of the registers,
5371 * and therefore the address skip is 4
5372 * and not 16 between the different groups
5373 */
5374 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5375 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5376 else
5377 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5378 }
5379
f2e0899f
DK
5380 if (bp->common.int_block == INT_BLOCK_HC) {
5381 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5382 HC_REG_ATTN_MSG0_ADDR_L);
5383
5384 REG_WR(bp, reg_offset, U64_LO(section));
5385 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5386 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5387 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5388 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5389 }
a2fbb9ea 5390
523224a3
DK
5391 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5392 sp_sb);
a2fbb9ea 5393
523224a3 5394 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5395
619c5cb6 5396 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5397 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5398 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5399 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5400 sp_sb_data.igu_seg_id = igu_seg_id;
5401 sp_sb_data.p_func.pf_id = func;
f2e0899f 5402 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5403 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5404
523224a3 5405 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5406
523224a3 5407 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5408}
5409
9f6c9258 5410void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5411{
a2fbb9ea
ET
5412 int i;
5413
ec6ba945 5414 for_each_eth_queue(bp, i)
523224a3 5415 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5416 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5417}
5418
a2fbb9ea
ET
5419static void bnx2x_init_sp_ring(struct bnx2x *bp)
5420{
a2fbb9ea 5421 spin_lock_init(&bp->spq_lock);
6e30dd4e 5422 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5423
a2fbb9ea 5424 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5425 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5426 bp->spq_prod_bd = bp->spq;
5427 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5428}
5429
523224a3 5430static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5431{
5432 int i;
523224a3
DK
5433 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5434 union event_ring_elem *elem =
5435 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5436
523224a3
DK
5437 elem->next_page.addr.hi =
5438 cpu_to_le32(U64_HI(bp->eq_mapping +
5439 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5440 elem->next_page.addr.lo =
5441 cpu_to_le32(U64_LO(bp->eq_mapping +
5442 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5443 }
523224a3
DK
5444 bp->eq_cons = 0;
5445 bp->eq_prod = NUM_EQ_DESC;
5446 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6e30dd4e
VZ
5447 /* we want a warning message before it gets rought... */
5448 atomic_set(&bp->eq_spq_left,
5449 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5450}
5451
619c5cb6
VZ
5452
5453/* called with netif_addr_lock_bh() */
5454void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5455 unsigned long rx_mode_flags,
5456 unsigned long rx_accept_flags,
5457 unsigned long tx_accept_flags,
5458 unsigned long ramrod_flags)
ab532cf3 5459{
619c5cb6
VZ
5460 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5461 int rc;
5462
5463 memset(&ramrod_param, 0, sizeof(ramrod_param));
5464
5465 /* Prepare ramrod parameters */
5466 ramrod_param.cid = 0;
5467 ramrod_param.cl_id = cl_id;
5468 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5469 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5470
619c5cb6
VZ
5471 ramrod_param.pstate = &bp->sp_state;
5472 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5473
619c5cb6
VZ
5474 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5475 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5476
5477 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5478
5479 ramrod_param.ramrod_flags = ramrod_flags;
5480 ramrod_param.rx_mode_flags = rx_mode_flags;
5481
5482 ramrod_param.rx_accept_flags = rx_accept_flags;
5483 ramrod_param.tx_accept_flags = tx_accept_flags;
5484
5485 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5486 if (rc < 0) {
5487 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5488 return;
5489 }
a2fbb9ea
ET
5490}
5491
619c5cb6
VZ
5492/* called with netif_addr_lock_bh() */
5493void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
471de716 5494{
619c5cb6
VZ
5495 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5496 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
471de716 5497
619c5cb6
VZ
5498 if (!NO_FCOE(bp))
5499
5500 /* Configure rx_mode of FCoE Queue */
5501 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
619c5cb6
VZ
5502
5503 switch (bp->rx_mode) {
5504 case BNX2X_RX_MODE_NONE:
5505 /*
5506 * 'drop all' supersedes any accept flags that may have been
5507 * passed to the function.
5508 */
5509 break;
5510 case BNX2X_RX_MODE_NORMAL:
5511 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5512 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5513 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5514
5515 /* internal switching mode */
5516 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5517 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5518 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5519
5520 break;
5521 case BNX2X_RX_MODE_ALLMULTI:
5522 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5523 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5524 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5525
5526 /* internal switching mode */
5527 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5528 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5529 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5530
5531 break;
5532 case BNX2X_RX_MODE_PROMISC:
5533 /* According to deffinition of SI mode, iface in promisc mode
5534 * should receive matched and unmatched (in resolution of port)
5535 * unicast packets.
5536 */
5537 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5538 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5539 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5540 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5541
5542 /* internal switching mode */
5543 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5544 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5545
5546 if (IS_MF_SI(bp))
5547 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5548 else
5549 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5550
5551 break;
5552 default:
5553 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5554 return;
5555 }
de832a55 5556
619c5cb6
VZ
5557 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5558 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5559 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
34f80b04
EG
5560 }
5561
619c5cb6
VZ
5562 __set_bit(RAMROD_RX, &ramrod_flags);
5563 __set_bit(RAMROD_TX, &ramrod_flags);
5564
5565 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5566 tx_accept_flags, ramrod_flags);
5567}
5568
5569static void bnx2x_init_internal_common(struct bnx2x *bp)
5570{
5571 int i;
5572
0793f83f
DK
5573 if (IS_MF_SI(bp))
5574 /*
5575 * In switch independent mode, the TSTORM needs to accept
5576 * packets that failed classification, since approximate match
5577 * mac addresses aren't written to NIG LLH
5578 */
5579 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5580 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5581 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5582 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5583 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5584
523224a3
DK
5585 /* Zero this manually as its initialization is
5586 currently missing in the initTool */
5587 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5588 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5589 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5590 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5591 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5592 CHIP_INT_MODE_IS_BC(bp) ?
5593 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5594 }
523224a3 5595}
8a1c38d1 5596
471de716
EG
5597static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5598{
5599 switch (load_code) {
5600 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5601 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5602 bnx2x_init_internal_common(bp);
5603 /* no break */
5604
5605 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5606 /* nothing to do */
471de716
EG
5607 /* no break */
5608
5609 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5610 /* internal memory per function is
5611 initialized inside bnx2x_pf_init */
471de716
EG
5612 break;
5613
5614 default:
5615 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5616 break;
5617 }
5618}
5619
619c5cb6 5620static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5621{
55c11941 5622 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 5623}
523224a3 5624
619c5cb6
VZ
5625static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5626{
55c11941 5627 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
5628}
5629
1191cb83 5630static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
5631{
5632 if (CHIP_IS_E1x(fp->bp))
5633 return BP_L_ID(fp->bp) + fp->index;
5634 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5635 return bnx2x_fp_igu_sb_id(fp);
5636}
5637
6383c0b3 5638static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5639{
5640 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5641 u8 cos;
619c5cb6 5642 unsigned long q_type = 0;
6383c0b3 5643 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5644 fp->rx_queue = fp_idx;
b3b83c3f 5645 fp->cid = fp_idx;
619c5cb6
VZ
5646 fp->cl_id = bnx2x_fp_cl_id(fp);
5647 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5648 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5649 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5650 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5651
523224a3 5652 /* init shortcut */
619c5cb6 5653 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5654
523224a3
DK
5655 /* Setup SB indicies */
5656 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5657
619c5cb6
VZ
5658 /* Configure Queue State object */
5659 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5660 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5661
5662 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5663
5664 /* init tx data */
5665 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
5666 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5667 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5668 FP_COS_TO_TXQ(fp, cos, bp),
5669 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5670 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
5671 }
5672
15192a8c
BW
5673 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5674 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 5675 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5676
5677 /**
5678 * Configure classification DBs: Always enable Tx switching
5679 */
5680 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5681
51c1a580 5682 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
619c5cb6 5683 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
523224a3
DK
5684 fp->igu_sb_id);
5685 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5686 fp->fw_sb_id, fp->igu_sb_id);
5687
5688 bnx2x_update_fpsb_idx(fp);
5689}
5690
1191cb83
ED
5691static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5692{
5693 int i;
5694
5695 for (i = 1; i <= NUM_TX_RINGS; i++) {
5696 struct eth_tx_next_bd *tx_next_bd =
5697 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5698
5699 tx_next_bd->addr_hi =
5700 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5701 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5702 tx_next_bd->addr_lo =
5703 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5704 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5705 }
5706
5707 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5708 txdata->tx_db.data.zero_fill1 = 0;
5709 txdata->tx_db.data.prod = 0;
5710
5711 txdata->tx_pkt_prod = 0;
5712 txdata->tx_pkt_cons = 0;
5713 txdata->tx_bd_prod = 0;
5714 txdata->tx_bd_cons = 0;
5715 txdata->tx_pkt = 0;
5716}
5717
55c11941
MS
5718static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
5719{
5720 int i;
5721
5722 for_each_tx_queue_cnic(bp, i)
5723 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
5724}
1191cb83
ED
5725static void bnx2x_init_tx_rings(struct bnx2x *bp)
5726{
5727 int i;
5728 u8 cos;
5729
55c11941 5730 for_each_eth_queue(bp, i)
1191cb83 5731 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 5732 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
5733}
5734
55c11941 5735void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 5736{
ec6ba945
VZ
5737 if (!NO_FCOE(bp))
5738 bnx2x_init_fcoe_fp(bp);
523224a3
DK
5739
5740 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5741 BNX2X_VF_ID_INVALID, false,
619c5cb6 5742 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 5743
55c11941
MS
5744 /* ensure status block indices were read */
5745 rmb();
5746 bnx2x_init_rx_rings_cnic(bp);
5747 bnx2x_init_tx_rings_cnic(bp);
5748
5749 /* flush all */
5750 mb();
5751 mmiowb();
5752}
a2fbb9ea 5753
55c11941
MS
5754void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5755{
5756 int i;
5757
5758 for_each_eth_queue(bp, i)
5759 bnx2x_init_eth_fp(bp, i);
020c7e3f
YR
5760 /* Initialize MOD_ABS interrupts */
5761 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5762 bp->common.shmem_base, bp->common.shmem2_base,
5763 BP_PORT(bp));
16119785
EG
5764 /* ensure status block indices were read */
5765 rmb();
5766
523224a3 5767 bnx2x_init_def_sb(bp);
5c862848 5768 bnx2x_update_dsb_idx(bp);
a2fbb9ea 5769 bnx2x_init_rx_rings(bp);
523224a3 5770 bnx2x_init_tx_rings(bp);
a2fbb9ea 5771 bnx2x_init_sp_ring(bp);
523224a3 5772 bnx2x_init_eq_ring(bp);
471de716 5773 bnx2x_init_internal(bp, load_code);
523224a3 5774 bnx2x_pf_init(bp);
0ef00459
EG
5775 bnx2x_stats_init(bp);
5776
0ef00459
EG
5777 /* flush all before enabling interrupts */
5778 mb();
5779 mmiowb();
5780
615f8fd9 5781 bnx2x_int_enable(bp);
eb8da205
EG
5782
5783 /* Check for SPIO5 */
5784 bnx2x_attn_int_deasserted0(bp,
5785 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5786 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
5787}
5788
5789/* end of nic init */
5790
5791/*
5792 * gzip service functions
5793 */
5794
5795static int bnx2x_gunzip_init(struct bnx2x *bp)
5796{
1a983142
FT
5797 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5798 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
5799 if (bp->gunzip_buf == NULL)
5800 goto gunzip_nomem1;
5801
5802 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5803 if (bp->strm == NULL)
5804 goto gunzip_nomem2;
5805
7ab24bfd 5806 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
5807 if (bp->strm->workspace == NULL)
5808 goto gunzip_nomem3;
5809
5810 return 0;
5811
5812gunzip_nomem3:
5813 kfree(bp->strm);
5814 bp->strm = NULL;
5815
5816gunzip_nomem2:
1a983142
FT
5817 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5818 bp->gunzip_mapping);
a2fbb9ea
ET
5819 bp->gunzip_buf = NULL;
5820
5821gunzip_nomem1:
51c1a580 5822 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
5823 return -ENOMEM;
5824}
5825
5826static void bnx2x_gunzip_end(struct bnx2x *bp)
5827{
b3b83c3f 5828 if (bp->strm) {
7ab24bfd 5829 vfree(bp->strm->workspace);
b3b83c3f
DK
5830 kfree(bp->strm);
5831 bp->strm = NULL;
5832 }
a2fbb9ea
ET
5833
5834 if (bp->gunzip_buf) {
1a983142
FT
5835 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5836 bp->gunzip_mapping);
a2fbb9ea
ET
5837 bp->gunzip_buf = NULL;
5838 }
5839}
5840
94a78b79 5841static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
5842{
5843 int n, rc;
5844
5845 /* check gzip header */
94a78b79
VZ
5846 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5847 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 5848 return -EINVAL;
94a78b79 5849 }
a2fbb9ea
ET
5850
5851 n = 10;
5852
34f80b04 5853#define FNAME 0x8
a2fbb9ea
ET
5854
5855 if (zbuf[3] & FNAME)
5856 while ((zbuf[n++] != 0) && (n < len));
5857
94a78b79 5858 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
5859 bp->strm->avail_in = len - n;
5860 bp->strm->next_out = bp->gunzip_buf;
5861 bp->strm->avail_out = FW_BUF_SIZE;
5862
5863 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5864 if (rc != Z_OK)
5865 return rc;
5866
5867 rc = zlib_inflate(bp->strm, Z_FINISH);
5868 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
5869 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5870 bp->strm->msg);
a2fbb9ea
ET
5871
5872 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5873 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
5874 netdev_err(bp->dev,
5875 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 5876 bp->gunzip_outlen);
a2fbb9ea
ET
5877 bp->gunzip_outlen >>= 2;
5878
5879 zlib_inflateEnd(bp->strm);
5880
5881 if (rc == Z_STREAM_END)
5882 return 0;
5883
5884 return rc;
5885}
5886
5887/* nic load/unload */
5888
5889/*
34f80b04 5890 * General service functions
a2fbb9ea
ET
5891 */
5892
5893/* send a NIG loopback debug packet */
5894static void bnx2x_lb_pckt(struct bnx2x *bp)
5895{
a2fbb9ea 5896 u32 wb_write[3];
a2fbb9ea
ET
5897
5898 /* Ethernet source and destination addresses */
a2fbb9ea
ET
5899 wb_write[0] = 0x55555555;
5900 wb_write[1] = 0x55555555;
34f80b04 5901 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 5902 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5903
5904 /* NON-IP protocol */
a2fbb9ea
ET
5905 wb_write[0] = 0x09000000;
5906 wb_write[1] = 0x55555555;
34f80b04 5907 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 5908 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5909}
5910
5911/* some of the internal memories
5912 * are not directly readable from the driver
5913 * to test them we send debug packets
5914 */
5915static int bnx2x_int_mem_test(struct bnx2x *bp)
5916{
5917 int factor;
5918 int count, i;
5919 u32 val = 0;
5920
ad8d3948 5921 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 5922 factor = 120;
ad8d3948
EG
5923 else if (CHIP_REV_IS_EMUL(bp))
5924 factor = 200;
5925 else
a2fbb9ea 5926 factor = 1;
a2fbb9ea 5927
a2fbb9ea
ET
5928 /* Disable inputs of parser neighbor blocks */
5929 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5930 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5931 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5932 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5933
5934 /* Write 0 to parser credits for CFC search request */
5935 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5936
5937 /* send Ethernet packet */
5938 bnx2x_lb_pckt(bp);
5939
5940 /* TODO do i reset NIG statistic? */
5941 /* Wait until NIG register shows 1 packet of size 0x10 */
5942 count = 1000 * factor;
5943 while (count) {
34f80b04 5944
a2fbb9ea
ET
5945 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5946 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
5947 if (val == 0x10)
5948 break;
5949
5950 msleep(10);
5951 count--;
5952 }
5953 if (val != 0x10) {
5954 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5955 return -1;
5956 }
5957
5958 /* Wait until PRS register shows 1 packet */
5959 count = 1000 * factor;
5960 while (count) {
5961 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
5962 if (val == 1)
5963 break;
5964
5965 msleep(10);
5966 count--;
5967 }
5968 if (val != 0x1) {
5969 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5970 return -2;
5971 }
5972
5973 /* Reset and init BRB, PRS */
34f80b04 5974 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 5975 msleep(50);
34f80b04 5976 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 5977 msleep(50);
619c5cb6
VZ
5978 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5979 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
5980
5981 DP(NETIF_MSG_HW, "part2\n");
5982
5983 /* Disable inputs of parser neighbor blocks */
5984 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5985 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5986 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5987 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5988
5989 /* Write 0 to parser credits for CFC search request */
5990 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5991
5992 /* send 10 Ethernet packets */
5993 for (i = 0; i < 10; i++)
5994 bnx2x_lb_pckt(bp);
5995
5996 /* Wait until NIG register shows 10 + 1
5997 packets of size 11*0x10 = 0xb0 */
5998 count = 1000 * factor;
5999 while (count) {
34f80b04 6000
a2fbb9ea
ET
6001 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6002 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6003 if (val == 0xb0)
6004 break;
6005
6006 msleep(10);
6007 count--;
6008 }
6009 if (val != 0xb0) {
6010 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6011 return -3;
6012 }
6013
6014 /* Wait until PRS register shows 2 packets */
6015 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6016 if (val != 2)
6017 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6018
6019 /* Write 1 to parser credits for CFC search request */
6020 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6021
6022 /* Wait until PRS register shows 3 packets */
6023 msleep(10 * factor);
6024 /* Wait until NIG register shows 1 packet of size 0x10 */
6025 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6026 if (val != 3)
6027 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6028
6029 /* clear NIG EOP FIFO */
6030 for (i = 0; i < 11; i++)
6031 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6032 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6033 if (val != 1) {
6034 BNX2X_ERR("clear of NIG failed\n");
6035 return -4;
6036 }
6037
6038 /* Reset and init BRB, PRS, NIG */
6039 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6040 msleep(50);
6041 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6042 msleep(50);
619c5cb6
VZ
6043 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6044 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6045 if (!CNIC_SUPPORT(bp))
6046 /* set NIC mode */
6047 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6048
6049 /* Enable inputs of parser neighbor blocks */
6050 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6051 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6052 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6053 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6054
6055 DP(NETIF_MSG_HW, "done\n");
6056
6057 return 0; /* OK */
6058}
6059
4a33bc03 6060static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea 6061{
b343d002
YM
6062 u32 val;
6063
a2fbb9ea 6064 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6065 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6066 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6067 else
6068 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6069 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6070 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6071 /*
6072 * mask read length error interrupts in brb for parser
6073 * (parsing unit and 'checksum and crc' unit)
6074 * these errors are legal (PU reads fixed length and CAC can cause
6075 * read length error on truncated packets)
6076 */
6077 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6078 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6079 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6080 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6081 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6082 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6083/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6084/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6085 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6086 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6087 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6088/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6089/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6090 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6091 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6092 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6093 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6094/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6095/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6096
b343d002
YM
6097 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6098 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6099 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6100 if (!CHIP_IS_E1x(bp))
6101 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6102 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6103 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6104
a2fbb9ea
ET
6105 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6106 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6107 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6108/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6109
6110 if (!CHIP_IS_E1x(bp))
6111 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6112 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6113
a2fbb9ea
ET
6114 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6115 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6116/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6117 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6118}
6119
81f75bbf
EG
6120static void bnx2x_reset_common(struct bnx2x *bp)
6121{
619c5cb6
VZ
6122 u32 val = 0x1400;
6123
81f75bbf
EG
6124 /* reset_common */
6125 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6126 0xd3ffff7f);
619c5cb6
VZ
6127
6128 if (CHIP_IS_E3(bp)) {
6129 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6130 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6131 }
6132
6133 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6134}
6135
6136static void bnx2x_setup_dmae(struct bnx2x *bp)
6137{
6138 bp->dmae_ready = 0;
6139 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6140}
6141
573f2035
EG
6142static void bnx2x_init_pxp(struct bnx2x *bp)
6143{
6144 u16 devctl;
6145 int r_order, w_order;
6146
2a80eebc 6147 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6148 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6149 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6150 if (bp->mrrs == -1)
6151 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6152 else {
6153 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6154 r_order = bp->mrrs;
6155 }
6156
6157 bnx2x_init_pxp_arb(bp, r_order, w_order);
6158}
fd4ef40d
EG
6159
6160static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6161{
2145a920 6162 int is_required;
fd4ef40d 6163 u32 val;
2145a920 6164 int port;
fd4ef40d 6165
2145a920
VZ
6166 if (BP_NOMCP(bp))
6167 return;
6168
6169 is_required = 0;
fd4ef40d
EG
6170 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6171 SHARED_HW_CFG_FAN_FAILURE_MASK;
6172
6173 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6174 is_required = 1;
6175
6176 /*
6177 * The fan failure mechanism is usually related to the PHY type since
6178 * the power consumption of the board is affected by the PHY. Currently,
6179 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6180 */
6181 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6182 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6183 is_required |=
d90d96ba
YR
6184 bnx2x_fan_failure_det_req(
6185 bp,
6186 bp->common.shmem_base,
a22f0788 6187 bp->common.shmem2_base,
d90d96ba 6188 port);
fd4ef40d
EG
6189 }
6190
6191 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6192
6193 if (is_required == 0)
6194 return;
6195
6196 /* Fan failure is indicated by SPIO 5 */
d6d99a3f 6197 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
fd4ef40d
EG
6198
6199 /* set to active low mode */
6200 val = REG_RD(bp, MISC_REG_SPIO_INT);
d6d99a3f 6201 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6202 REG_WR(bp, MISC_REG_SPIO_INT, val);
6203
6204 /* enable interrupt to signal the IGU */
6205 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6206 val |= MISC_SPIO_SPIO5;
fd4ef40d
EG
6207 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6208}
6209
f2e0899f
DK
6210static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
6211{
6212 u32 offset = 0;
6213
6214 if (CHIP_IS_E1(bp))
6215 return;
6216 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
6217 return;
6218
6219 switch (BP_ABS_FUNC(bp)) {
6220 case 0:
6221 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
6222 break;
6223 case 1:
6224 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
6225 break;
6226 case 2:
6227 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
6228 break;
6229 case 3:
6230 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
6231 break;
6232 case 4:
6233 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
6234 break;
6235 case 5:
6236 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
6237 break;
6238 case 6:
6239 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
6240 break;
6241 case 7:
6242 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
6243 break;
6244 default:
6245 return;
6246 }
6247
6248 REG_WR(bp, offset, pretend_func_num);
6249 REG_RD(bp, offset);
6250 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
6251}
6252
c9ee9206 6253void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6254{
6255 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6256 val &= ~IGU_PF_CONF_FUNC_EN;
6257
6258 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6259 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6260 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6261}
6262
1191cb83 6263static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6264{
6265 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6266 /* Avoid common init in case MFW supports LFA */
6267 if (SHMEM2_RD(bp, size) >
6268 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6269 return;
619c5cb6
VZ
6270 shmem_base[0] = bp->common.shmem_base;
6271 shmem2_base[0] = bp->common.shmem2_base;
6272 if (!CHIP_IS_E1x(bp)) {
6273 shmem_base[1] =
6274 SHMEM2_RD(bp, other_shmem_base_addr);
6275 shmem2_base[1] =
6276 SHMEM2_RD(bp, other_shmem2_base_addr);
6277 }
6278 bnx2x_acquire_phy_lock(bp);
6279 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6280 bp->common.chip_id);
6281 bnx2x_release_phy_lock(bp);
6282}
6283
6284/**
6285 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6286 *
6287 * @bp: driver handle
6288 */
6289static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6290{
619c5cb6 6291 u32 val;
a2fbb9ea 6292
51c1a580 6293 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6294
2031bd3a
DK
6295 /*
6296 * take the UNDI lock to protect undi_unload flow from accessing
6297 * registers while we're resetting the chip
6298 */
7a06a122 6299 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6300
81f75bbf 6301 bnx2x_reset_common(bp);
34f80b04 6302 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6303
619c5cb6
VZ
6304 val = 0xfffc;
6305 if (CHIP_IS_E3(bp)) {
6306 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6307 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6308 }
6309 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6310
7a06a122 6311 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6312
619c5cb6 6313 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6314
619c5cb6
VZ
6315 if (!CHIP_IS_E1x(bp)) {
6316 u8 abs_func_id;
f2e0899f
DK
6317
6318 /**
6319 * 4-port mode or 2-port mode we need to turn of master-enable
6320 * for everyone, after that, turn it back on for self.
6321 * so, we disregard multi-function or not, and always disable
6322 * for all functions on the given path, this means 0,2,4,6 for
6323 * path 0 and 1,3,5,7 for path 1
6324 */
619c5cb6
VZ
6325 for (abs_func_id = BP_PATH(bp);
6326 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6327 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6328 REG_WR(bp,
6329 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6330 1);
6331 continue;
6332 }
6333
619c5cb6 6334 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6335 /* clear pf enable */
6336 bnx2x_pf_disable(bp);
6337 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6338 }
6339 }
a2fbb9ea 6340
619c5cb6 6341 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6342 if (CHIP_IS_E1(bp)) {
6343 /* enable HW interrupt from PXP on USDM overflow
6344 bit 16 on INT_MASK_0 */
6345 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6346 }
a2fbb9ea 6347
619c5cb6 6348 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6349 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6350
6351#ifdef __BIG_ENDIAN
34f80b04
EG
6352 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6353 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6354 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6355 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6356 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6357 /* make sure this value is 0 */
6358 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6359
6360/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6361 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6362 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6363 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6364 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6365#endif
6366
523224a3
DK
6367 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6368
34f80b04
EG
6369 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6370 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6371
34f80b04
EG
6372 /* let the HW do it's magic ... */
6373 msleep(100);
6374 /* finish PXP init */
6375 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6376 if (val != 1) {
6377 BNX2X_ERR("PXP2 CFG failed\n");
6378 return -EBUSY;
6379 }
6380 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6381 if (val != 1) {
6382 BNX2X_ERR("PXP2 RD_INIT failed\n");
6383 return -EBUSY;
6384 }
a2fbb9ea 6385
f2e0899f
DK
6386 /* Timers bug workaround E2 only. We need to set the entire ILT to
6387 * have entries with value "0" and valid bit on.
6388 * This needs to be done by the first PF that is loaded in a path
6389 * (i.e. common phase)
6390 */
619c5cb6
VZ
6391 if (!CHIP_IS_E1x(bp)) {
6392/* In E2 there is a bug in the timers block that can cause function 6 / 7
6393 * (i.e. vnic3) to start even if it is marked as "scan-off".
6394 * This occurs when a different function (func2,3) is being marked
6395 * as "scan-off". Real-life scenario for example: if a driver is being
6396 * load-unloaded while func6,7 are down. This will cause the timer to access
6397 * the ilt, translate to a logical address and send a request to read/write.
6398 * Since the ilt for the function that is down is not valid, this will cause
6399 * a translation error which is unrecoverable.
6400 * The Workaround is intended to make sure that when this happens nothing fatal
6401 * will occur. The workaround:
6402 * 1. First PF driver which loads on a path will:
6403 * a. After taking the chip out of reset, by using pretend,
6404 * it will write "0" to the following registers of
6405 * the other vnics.
6406 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6407 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6408 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6409 * And for itself it will write '1' to
6410 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6411 * dmae-operations (writing to pram for example.)
6412 * note: can be done for only function 6,7 but cleaner this
6413 * way.
6414 * b. Write zero+valid to the entire ILT.
6415 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6416 * VNIC3 (of that port). The range allocated will be the
6417 * entire ILT. This is needed to prevent ILT range error.
6418 * 2. Any PF driver load flow:
6419 * a. ILT update with the physical addresses of the allocated
6420 * logical pages.
6421 * b. Wait 20msec. - note that this timeout is needed to make
6422 * sure there are no requests in one of the PXP internal
6423 * queues with "old" ILT addresses.
6424 * c. PF enable in the PGLC.
6425 * d. Clear the was_error of the PF in the PGLC. (could have
6426 * occured while driver was down)
6427 * e. PF enable in the CFC (WEAK + STRONG)
6428 * f. Timers scan enable
6429 * 3. PF driver unload flow:
6430 * a. Clear the Timers scan_en.
6431 * b. Polling for scan_on=0 for that PF.
6432 * c. Clear the PF enable bit in the PXP.
6433 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6434 * e. Write zero+valid to all ILT entries (The valid bit must
6435 * stay set)
6436 * f. If this is VNIC 3 of a port then also init
6437 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6438 * to the last enrty in the ILT.
6439 *
6440 * Notes:
6441 * Currently the PF error in the PGLC is non recoverable.
6442 * In the future the there will be a recovery routine for this error.
6443 * Currently attention is masked.
6444 * Having an MCP lock on the load/unload process does not guarantee that
6445 * there is no Timer disable during Func6/7 enable. This is because the
6446 * Timers scan is currently being cleared by the MCP on FLR.
6447 * Step 2.d can be done only for PF6/7 and the driver can also check if
6448 * there is error before clearing it. But the flow above is simpler and
6449 * more general.
6450 * All ILT entries are written by zero+valid and not just PF6/7
6451 * ILT entries since in the future the ILT entries allocation for
6452 * PF-s might be dynamic.
6453 */
f2e0899f
DK
6454 struct ilt_client_info ilt_cli;
6455 struct bnx2x_ilt ilt;
6456 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6457 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6458
b595076a 6459 /* initialize dummy TM client */
f2e0899f
DK
6460 ilt_cli.start = 0;
6461 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6462 ilt_cli.client_num = ILT_CLIENT_TM;
6463
6464 /* Step 1: set zeroes to all ilt page entries with valid bit on
6465 * Step 2: set the timers first/last ilt entry to point
6466 * to the entire range to prevent ILT range error for 3rd/4th
619c5cb6 6467 * vnic (this code assumes existance of the vnic)
f2e0899f
DK
6468 *
6469 * both steps performed by call to bnx2x_ilt_client_init_op()
6470 * with dummy TM client
6471 *
6472 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6473 * and his brother are split registers
6474 */
6475 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6476 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6477 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6478
6479 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6480 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6481 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6482 }
6483
6484
34f80b04
EG
6485 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6486 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6487
619c5cb6 6488 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6489 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6490 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6491 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6492
619c5cb6 6493 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6494
6495 /* let the HW do it's magic ... */
6496 do {
6497 msleep(200);
6498 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6499 } while (factor-- && (val != 1));
6500
6501 if (val != 1) {
6502 BNX2X_ERR("ATC_INIT failed\n");
6503 return -EBUSY;
6504 }
6505 }
6506
619c5cb6 6507 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6508
34f80b04
EG
6509 /* clean the DMAE memory */
6510 bp->dmae_ready = 1;
619c5cb6
VZ
6511 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6512
6513 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6514
6515 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6516
6517 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6518
619c5cb6 6519 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6520
34f80b04
EG
6521 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6522 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6523 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6524 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6525
619c5cb6 6526 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6527
f85582f8 6528
523224a3
DK
6529 /* QM queues pointers table */
6530 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6531
34f80b04
EG
6532 /* soft reset pulse */
6533 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6534 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6535
55c11941
MS
6536 if (CNIC_SUPPORT(bp))
6537 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6538
619c5cb6 6539 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6540 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6541 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6542 /* enable hw interrupt from doorbell Q */
6543 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6544
619c5cb6 6545 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6546
619c5cb6 6547 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6548 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6549
f2e0899f 6550 if (!CHIP_IS_E1(bp))
619c5cb6 6551 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6552
a3348722
BW
6553 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6554 if (IS_MF_AFEX(bp)) {
6555 /* configure that VNTag and VLAN headers must be
6556 * received in afex mode
6557 */
6558 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6559 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6560 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6561 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6562 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6563 } else {
6564 /* Bit-map indicating which L2 hdrs may appear
6565 * after the basic Ethernet header
6566 */
6567 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6568 bp->path_has_ovlan ? 7 : 6);
6569 }
6570 }
a2fbb9ea 6571
619c5cb6
VZ
6572 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6573 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6574 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6575 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6576
619c5cb6
VZ
6577 if (!CHIP_IS_E1x(bp)) {
6578 /* reset VFC memories */
6579 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6580 VFC_MEMORIES_RST_REG_CAM_RST |
6581 VFC_MEMORIES_RST_REG_RAM_RST);
6582 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6583 VFC_MEMORIES_RST_REG_CAM_RST |
6584 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6585
619c5cb6
VZ
6586 msleep(20);
6587 }
a2fbb9ea 6588
619c5cb6
VZ
6589 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6590 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6591 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6592 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6593
34f80b04
EG
6594 /* sync semi rtc */
6595 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6596 0x80000000);
6597 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6598 0x80000000);
a2fbb9ea 6599
619c5cb6
VZ
6600 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6601 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6602 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6603
a3348722
BW
6604 if (!CHIP_IS_E1x(bp)) {
6605 if (IS_MF_AFEX(bp)) {
6606 /* configure that VNTag and VLAN headers must be
6607 * sent in afex mode
6608 */
6609 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6610 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6611 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6612 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6613 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6614 } else {
6615 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6616 bp->path_has_ovlan ? 7 : 6);
6617 }
6618 }
f2e0899f 6619
34f80b04 6620 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6621
619c5cb6
VZ
6622 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6623
55c11941
MS
6624 if (CNIC_SUPPORT(bp)) {
6625 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6626 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6627 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6628 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6629 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6630 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6631 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6632 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6633 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6634 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6635 }
34f80b04 6636 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6637
34f80b04
EG
6638 if (sizeof(union cdu_context) != 1024)
6639 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6640 dev_alert(&bp->pdev->dev,
6641 "please adjust the size of cdu_context(%ld)\n",
6642 (long)sizeof(union cdu_context));
a2fbb9ea 6643
619c5cb6 6644 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6645 val = (4 << 24) + (0 << 12) + 1024;
6646 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6647
619c5cb6 6648 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6649 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6650 /* enable context validation interrupt from CFC */
6651 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6652
6653 /* set the thresholds to prevent CFC/CDU race */
6654 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6655
619c5cb6 6656 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6657
619c5cb6 6658 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6659 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6660
619c5cb6
VZ
6661 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6662 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6663
34f80b04
EG
6664 /* Reset PCIE errors for debug */
6665 REG_WR(bp, 0x2814, 0xffffffff);
6666 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6667
619c5cb6 6668 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6669 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6670 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6671 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6672 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6673 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6674 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6675 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6676 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6677 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6678 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6679 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6680 }
6681
619c5cb6 6682 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6683 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6684 /* in E3 this done in per-port section */
6685 if (!CHIP_IS_E3(bp))
6686 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6687 }
619c5cb6
VZ
6688 if (CHIP_IS_E1H(bp))
6689 /* not applicable for E2 (and above ...) */
6690 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6691
6692 if (CHIP_REV_IS_SLOW(bp))
6693 msleep(200);
6694
6695 /* finish CFC init */
6696 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6697 if (val != 1) {
6698 BNX2X_ERR("CFC LL_INIT failed\n");
6699 return -EBUSY;
6700 }
6701 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6702 if (val != 1) {
6703 BNX2X_ERR("CFC AC_INIT failed\n");
6704 return -EBUSY;
6705 }
6706 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6707 if (val != 1) {
6708 BNX2X_ERR("CFC CAM_INIT failed\n");
6709 return -EBUSY;
6710 }
6711 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6712
f2e0899f
DK
6713 if (CHIP_IS_E1(bp)) {
6714 /* read NIG statistic
6715 to see if this is our first up since powerup */
6716 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6717 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6718
f2e0899f
DK
6719 /* do internal memory self test */
6720 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6721 BNX2X_ERR("internal mem self test failed\n");
6722 return -EBUSY;
6723 }
34f80b04
EG
6724 }
6725
fd4ef40d
EG
6726 bnx2x_setup_fan_failure_detection(bp);
6727
34f80b04
EG
6728 /* clear PXP2 attentions */
6729 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6730
4a33bc03 6731 bnx2x_enable_blocks_attention(bp);
c9ee9206 6732 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6733
6bbca910 6734 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6735 if (CHIP_IS_E1x(bp))
6736 bnx2x__common_init_phy(bp);
6bbca910
YR
6737 } else
6738 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6739
34f80b04
EG
6740 return 0;
6741}
a2fbb9ea 6742
619c5cb6
VZ
6743/**
6744 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6745 *
6746 * @bp: driver handle
6747 */
6748static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6749{
6750 int rc = bnx2x_init_hw_common(bp);
6751
6752 if (rc)
6753 return rc;
6754
6755 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6756 if (!BP_NOMCP(bp))
6757 bnx2x__common_init_phy(bp);
6758
6759 return 0;
6760}
6761
523224a3 6762static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6763{
6764 int port = BP_PORT(bp);
619c5cb6 6765 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6766 u32 low, high;
34f80b04 6767 u32 val;
a2fbb9ea 6768
619c5cb6 6769
51c1a580 6770 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
6771
6772 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 6773
619c5cb6
VZ
6774 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6775 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6776 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 6777
f2e0899f
DK
6778 /* Timers bug workaround: disables the pf_master bit in pglue at
6779 * common phase, we need to enable it here before any dmae access are
6780 * attempted. Therefore we manually added the enable-master to the
6781 * port phase (it also happens in the function phase)
6782 */
619c5cb6 6783 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6784 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6785
619c5cb6
VZ
6786 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6787 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6788 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6789 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6790
6791 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6792 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6793 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6794 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 6795
523224a3
DK
6796 /* QM cid (connection) count */
6797 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 6798
55c11941
MS
6799 if (CNIC_SUPPORT(bp)) {
6800 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6801 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6802 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6803 }
cdaa7cb8 6804
619c5cb6 6805 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 6806
2b674047
DK
6807 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6808
f2e0899f 6809 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
6810
6811 if (IS_MF(bp))
6812 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6813 else if (bp->dev->mtu > 4096) {
6814 if (bp->flags & ONE_PORT_FLAG)
6815 low = 160;
6816 else {
6817 val = bp->dev->mtu;
6818 /* (24*1024 + val*4)/256 */
6819 low = 96 + (val/64) +
6820 ((val % 64) ? 1 : 0);
6821 }
6822 } else
6823 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6824 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
6825 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6826 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 6827 }
1c06328c 6828
619c5cb6
VZ
6829 if (CHIP_MODE_IS_4_PORT(bp))
6830 REG_WR(bp, (BP_PORT(bp) ?
6831 BRB1_REG_MAC_GUARANTIED_1 :
6832 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 6833
ca00392c 6834
619c5cb6 6835 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
6836 if (CHIP_IS_E3B0(bp)) {
6837 if (IS_MF_AFEX(bp)) {
6838 /* configure headers for AFEX mode */
6839 REG_WR(bp, BP_PORT(bp) ?
6840 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6841 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
6842 REG_WR(bp, BP_PORT(bp) ?
6843 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
6844 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
6845 REG_WR(bp, BP_PORT(bp) ?
6846 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
6847 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
6848 } else {
6849 /* Ovlan exists only if we are in multi-function +
6850 * switch-dependent mode, in switch-independent there
6851 * is no ovlan headers
6852 */
6853 REG_WR(bp, BP_PORT(bp) ?
6854 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6855 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6856 (bp->path_has_ovlan ? 7 : 6));
6857 }
6858 }
356e2385 6859
619c5cb6
VZ
6860 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6861 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6862 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6863 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 6864
619c5cb6
VZ
6865 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6866 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6867 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6868 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 6869
619c5cb6
VZ
6870 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6871 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 6872
619c5cb6
VZ
6873 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6874
6875 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
6876 /* configure PBF to work without PAUSE mtu 9000 */
6877 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 6878
f2e0899f
DK
6879 /* update threshold */
6880 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6881 /* update init credit */
6882 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 6883
f2e0899f
DK
6884 /* probe changes */
6885 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6886 udelay(50);
6887 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6888 }
a2fbb9ea 6889
55c11941
MS
6890 if (CNIC_SUPPORT(bp))
6891 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6892
619c5cb6
VZ
6893 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6894 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
6895
6896 if (CHIP_IS_E1(bp)) {
6897 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6898 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6899 }
619c5cb6 6900 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 6901
619c5cb6 6902 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 6903
619c5cb6 6904 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04
EG
6905 /* init aeu_mask_attn_func_0/1:
6906 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6907 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6908 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
6909 val = IS_MF(bp) ? 0xF7 : 0x7;
6910 /* Enable DCBX attention for all but E1 */
6911 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6912 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 6913
619c5cb6
VZ
6914 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6915
6916 if (!CHIP_IS_E1x(bp)) {
6917 /* Bit-map indicating which L2 hdrs may appear after the
6918 * basic Ethernet header
6919 */
a3348722
BW
6920 if (IS_MF_AFEX(bp))
6921 REG_WR(bp, BP_PORT(bp) ?
6922 NIG_REG_P1_HDRS_AFTER_BASIC :
6923 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
6924 else
6925 REG_WR(bp, BP_PORT(bp) ?
6926 NIG_REG_P1_HDRS_AFTER_BASIC :
6927 NIG_REG_P0_HDRS_AFTER_BASIC,
6928 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
6929
6930 if (CHIP_IS_E3(bp))
6931 REG_WR(bp, BP_PORT(bp) ?
6932 NIG_REG_LLH1_MF_MODE :
6933 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6934 }
6935 if (!CHIP_IS_E3(bp))
6936 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 6937
f2e0899f 6938 if (!CHIP_IS_E1(bp)) {
fb3bff17 6939 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 6940 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 6941 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 6942
619c5cb6 6943 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6944 val = 0;
6945 switch (bp->mf_mode) {
6946 case MULTI_FUNCTION_SD:
6947 val = 1;
6948 break;
6949 case MULTI_FUNCTION_SI:
a3348722 6950 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
6951 val = 2;
6952 break;
6953 }
6954
6955 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6956 NIG_REG_LLH0_CLS_TYPE), val);
6957 }
1c06328c
EG
6958 {
6959 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6960 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6961 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6962 }
34f80b04
EG
6963 }
6964
619c5cb6
VZ
6965
6966 /* If SPIO5 is set to generate interrupts, enable it for this port */
6967 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6968 if (val & MISC_SPIO_SPIO5) {
4d295db0
EG
6969 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6970 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6971 val = REG_RD(bp, reg_addr);
f1410647 6972 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 6973 REG_WR(bp, reg_addr, val);
f1410647 6974 }
a2fbb9ea 6975
34f80b04
EG
6976 return 0;
6977}
6978
34f80b04
EG
6979static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6980{
6981 int reg;
32d68de1 6982 u32 wb_write[2];
34f80b04 6983
f2e0899f 6984 if (CHIP_IS_E1(bp))
34f80b04 6985 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
6986 else
6987 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 6988
32d68de1
YM
6989 wb_write[0] = ONCHIP_ADDR1(addr);
6990 wb_write[1] = ONCHIP_ADDR2(addr);
6991 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
6992}
6993
1191cb83
ED
6994static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
6995 u8 idu_sb_id, bool is_Pf)
6996{
6997 u32 data, ctl, cnt = 100;
6998 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
6999 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7000 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7001 u32 sb_bit = 1 << (idu_sb_id%32);
7002 u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
7003 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7004
7005 /* Not supported in BC mode */
7006 if (CHIP_INT_MODE_IS_BC(bp))
7007 return;
7008
7009 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7010 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7011 IGU_REGULAR_CLEANUP_SET |
7012 IGU_REGULAR_BCLEANUP;
7013
7014 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7015 func_encode << IGU_CTRL_REG_FID_SHIFT |
7016 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7017
7018 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7019 data, igu_addr_data);
7020 REG_WR(bp, igu_addr_data, data);
7021 mmiowb();
7022 barrier();
7023 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7024 ctl, igu_addr_ctl);
7025 REG_WR(bp, igu_addr_ctl, ctl);
7026 mmiowb();
7027 barrier();
7028
7029 /* wait for clean up to finish */
7030 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7031 msleep(20);
7032
7033
7034 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7035 DP(NETIF_MSG_HW,
7036 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7037 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7038 }
7039}
7040
7041static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7042{
619c5cb6 7043 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7044}
7045
1191cb83 7046static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7047{
7048 u32 i, base = FUNC_ILT_BASE(func);
7049 for (i = base; i < base + ILT_PER_FUNC; i++)
7050 bnx2x_ilt_wr(bp, i, 0);
7051}
7052
55c11941 7053
910cc727 7054static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7055{
7056 int port = BP_PORT(bp);
7057 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7058 /* T1 hash bits value determines the T1 number of entries */
7059 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7060}
7061
7062static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7063{
7064 int rc;
7065 struct bnx2x_func_state_params func_params = {NULL};
7066 struct bnx2x_func_switch_update_params *switch_update_params =
7067 &func_params.params.switch_update;
7068
7069 /* Prepare parameters for function state transitions */
7070 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7071 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7072
7073 func_params.f_obj = &bp->func_obj;
7074 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7075
7076 /* Function parameters */
7077 switch_update_params->suspend = suspend;
7078
7079 rc = bnx2x_func_state_change(bp, &func_params);
7080
7081 return rc;
7082}
7083
910cc727 7084static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7085{
7086 int rc, i, port = BP_PORT(bp);
7087 int vlan_en = 0, mac_en[NUM_MACS];
7088
7089
7090 /* Close input from network */
7091 if (bp->mf_mode == SINGLE_FUNCTION) {
7092 bnx2x_set_rx_filter(&bp->link_params, 0);
7093 } else {
7094 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7095 NIG_REG_LLH0_FUNC_EN);
7096 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7097 NIG_REG_LLH0_FUNC_EN, 0);
7098 for (i = 0; i < NUM_MACS; i++) {
7099 mac_en[i] = REG_RD(bp, port ?
7100 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7101 4 * i) :
7102 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7103 4 * i));
7104 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7105 4 * i) :
7106 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7107 }
7108 }
7109
7110 /* Close BMC to host */
7111 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7112 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7113
7114 /* Suspend Tx switching to the PF. Completion of this ramrod
7115 * further guarantees that all the packets of that PF / child
7116 * VFs in BRB were processed by the Parser, so it is safe to
7117 * change the NIC_MODE register.
7118 */
7119 rc = bnx2x_func_switch_update(bp, 1);
7120 if (rc) {
7121 BNX2X_ERR("Can't suspend tx-switching!\n");
7122 return rc;
7123 }
7124
7125 /* Change NIC_MODE register */
7126 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7127
7128 /* Open input from network */
7129 if (bp->mf_mode == SINGLE_FUNCTION) {
7130 bnx2x_set_rx_filter(&bp->link_params, 1);
7131 } else {
7132 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7133 NIG_REG_LLH0_FUNC_EN, vlan_en);
7134 for (i = 0; i < NUM_MACS; i++) {
7135 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7136 4 * i) :
7137 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7138 mac_en[i]);
7139 }
7140 }
7141
7142 /* Enable BMC to host */
7143 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7144 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7145
7146 /* Resume Tx switching to the PF */
7147 rc = bnx2x_func_switch_update(bp, 0);
7148 if (rc) {
7149 BNX2X_ERR("Can't resume tx-switching!\n");
7150 return rc;
7151 }
7152
7153 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7154 return 0;
7155}
7156
7157int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7158{
7159 int rc;
7160
7161 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7162
7163 if (CONFIGURE_NIC_MODE(bp)) {
7164 /* Configrue searcher as part of function hw init */
7165 bnx2x_init_searcher(bp);
7166
7167 /* Reset NIC mode */
7168 rc = bnx2x_reset_nic_mode(bp);
7169 if (rc)
7170 BNX2X_ERR("Can't change NIC mode!\n");
7171 return rc;
7172 }
7173
7174 return 0;
7175}
7176
523224a3 7177static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7178{
7179 int port = BP_PORT(bp);
7180 int func = BP_FUNC(bp);
619c5cb6 7181 int init_phase = PHASE_PF0 + func;
523224a3
DK
7182 struct bnx2x_ilt *ilt = BP_ILT(bp);
7183 u16 cdu_ilt_start;
8badd27a 7184 u32 addr, val;
f4a66897 7185 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7186 int i, main_mem_width, rc;
34f80b04 7187
51c1a580 7188 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7189
619c5cb6 7190 /* FLR cleanup - hmmm */
89db4ad8
AE
7191 if (!CHIP_IS_E1x(bp)) {
7192 rc = bnx2x_pf_flr_clnup(bp);
7193 if (rc)
7194 return rc;
7195 }
619c5cb6 7196
8badd27a 7197 /* set MSI reconfigure capability */
f2e0899f
DK
7198 if (bp->common.int_block == INT_BLOCK_HC) {
7199 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7200 val = REG_RD(bp, addr);
7201 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7202 REG_WR(bp, addr, val);
7203 }
8badd27a 7204
619c5cb6
VZ
7205 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7206 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7207
523224a3
DK
7208 ilt = BP_ILT(bp);
7209 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7210
523224a3 7211 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7212 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7213 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7214 bp->context[i].cxt_mapping;
7215 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7216 }
523224a3 7217 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7218
55c11941
MS
7219 if (!CONFIGURE_NIC_MODE(bp)) {
7220 bnx2x_init_searcher(bp);
7221 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7222 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7223 } else {
7224 /* Set NIC mode */
7225 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7226 DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
37b091ba 7227
55c11941 7228 }
37b091ba 7229
619c5cb6 7230 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7231 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7232
7233 /* Turn on a single ISR mode in IGU if driver is going to use
7234 * INT#x or MSI
7235 */
7236 if (!(bp->flags & USING_MSIX_FLAG))
7237 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7238 /*
7239 * Timers workaround bug: function init part.
7240 * Need to wait 20msec after initializing ILT,
7241 * needed to make sure there are no requests in
7242 * one of the PXP internal queues with "old" ILT addresses
7243 */
7244 msleep(20);
7245 /*
7246 * Master enable - Due to WB DMAE writes performed before this
7247 * register is re-initialized as part of the regular function
7248 * init
7249 */
7250 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7251 /* Enable the function in IGU */
7252 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7253 }
7254
523224a3 7255 bp->dmae_ready = 1;
34f80b04 7256
619c5cb6 7257 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7258
619c5cb6 7259 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7260 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7261
619c5cb6
VZ
7262 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7263 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7264 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7265 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7266 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7267 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7268 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7269 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7270 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7271 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7272 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7273 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7274 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7275
7276 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7277 REG_WR(bp, QM_REG_PF_EN, 1);
7278
619c5cb6
VZ
7279 if (!CHIP_IS_E1x(bp)) {
7280 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7281 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7282 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7283 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7284 }
7285 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7286
7287 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7288 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
7289 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7290 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7291 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7292 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7293 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7294 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7295 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7296 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7297 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7298 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7299 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7300
619c5cb6 7301 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7302
619c5cb6 7303 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7304
619c5cb6 7305 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7306 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7307
fb3bff17 7308 if (IS_MF(bp)) {
34f80b04 7309 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7310 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7311 }
7312
619c5cb6 7313 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7314
34f80b04 7315 /* HC init per function */
f2e0899f
DK
7316 if (bp->common.int_block == INT_BLOCK_HC) {
7317 if (CHIP_IS_E1H(bp)) {
7318 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7319
7320 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7321 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7322 }
619c5cb6 7323 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7324
7325 } else {
7326 int num_segs, sb_idx, prod_offset;
7327
34f80b04
EG
7328 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7329
619c5cb6 7330 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7331 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7332 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7333 }
7334
619c5cb6 7335 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7336
619c5cb6 7337 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7338 int dsb_idx = 0;
7339 /**
7340 * Producer memory:
7341 * E2 mode: address 0-135 match to the mapping memory;
7342 * 136 - PF0 default prod; 137 - PF1 default prod;
7343 * 138 - PF2 default prod; 139 - PF3 default prod;
7344 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7345 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7346 * 144-147 reserved.
7347 *
7348 * E1.5 mode - In backward compatible mode;
7349 * for non default SB; each even line in the memory
7350 * holds the U producer and each odd line hold
7351 * the C producer. The first 128 producers are for
7352 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7353 * producers are for the DSB for each PF.
7354 * Each PF has five segments: (the order inside each
7355 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7356 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7357 * 144-147 attn prods;
7358 */
7359 /* non-default-status-blocks */
7360 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7361 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7362 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7363 prod_offset = (bp->igu_base_sb + sb_idx) *
7364 num_segs;
7365
7366 for (i = 0; i < num_segs; i++) {
7367 addr = IGU_REG_PROD_CONS_MEMORY +
7368 (prod_offset + i) * 4;
7369 REG_WR(bp, addr, 0);
7370 }
7371 /* send consumer update with value 0 */
7372 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7373 USTORM_ID, 0, IGU_INT_NOP, 1);
7374 bnx2x_igu_clear_sb(bp,
7375 bp->igu_base_sb + sb_idx);
7376 }
7377
7378 /* default-status-blocks */
7379 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7380 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7381
7382 if (CHIP_MODE_IS_4_PORT(bp))
7383 dsb_idx = BP_FUNC(bp);
7384 else
3395a033 7385 dsb_idx = BP_VN(bp);
f2e0899f
DK
7386
7387 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7388 IGU_BC_BASE_DSB_PROD + dsb_idx :
7389 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7390
3395a033
DK
7391 /*
7392 * igu prods come in chunks of E1HVN_MAX (4) -
7393 * does not matters what is the current chip mode
7394 */
f2e0899f
DK
7395 for (i = 0; i < (num_segs * E1HVN_MAX);
7396 i += E1HVN_MAX) {
7397 addr = IGU_REG_PROD_CONS_MEMORY +
7398 (prod_offset + i)*4;
7399 REG_WR(bp, addr, 0);
7400 }
7401 /* send consumer update with 0 */
7402 if (CHIP_INT_MODE_IS_BC(bp)) {
7403 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7404 USTORM_ID, 0, IGU_INT_NOP, 1);
7405 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7406 CSTORM_ID, 0, IGU_INT_NOP, 1);
7407 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7408 XSTORM_ID, 0, IGU_INT_NOP, 1);
7409 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7410 TSTORM_ID, 0, IGU_INT_NOP, 1);
7411 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7412 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7413 } else {
7414 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7415 USTORM_ID, 0, IGU_INT_NOP, 1);
7416 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7417 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7418 }
7419 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7420
7421 /* !!! these should become driver const once
7422 rf-tool supports split-68 const */
7423 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7424 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7425 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7426 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7427 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7428 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7429 }
34f80b04 7430 }
34f80b04 7431
c14423fe 7432 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7433 REG_WR(bp, 0x2114, 0xffffffff);
7434 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7435
f4a66897
VZ
7436 if (CHIP_IS_E1x(bp)) {
7437 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7438 main_mem_base = HC_REG_MAIN_MEMORY +
7439 BP_PORT(bp) * (main_mem_size * 4);
7440 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7441 main_mem_width = 8;
7442
7443 val = REG_RD(bp, main_mem_prty_clr);
7444 if (val)
51c1a580
MS
7445 DP(NETIF_MSG_HW,
7446 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7447 val);
f4a66897
VZ
7448
7449 /* Clear "false" parity errors in MSI-X table */
7450 for (i = main_mem_base;
7451 i < main_mem_base + main_mem_size * 4;
7452 i += main_mem_width) {
7453 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7454 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7455 i, main_mem_width / 4);
7456 }
7457 /* Clear HC parity attention */
7458 REG_RD(bp, main_mem_prty_clr);
7459 }
7460
619c5cb6
VZ
7461#ifdef BNX2X_STOP_ON_ERROR
7462 /* Enable STORMs SP logging */
7463 REG_WR8(bp, BAR_USTRORM_INTMEM +
7464 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7465 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7466 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7467 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7468 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7469 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7470 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7471#endif
7472
b7737c9b 7473 bnx2x_phy_probe(&bp->link_params);
f85582f8 7474
34f80b04
EG
7475 return 0;
7476}
7477
a2fbb9ea 7478
55c11941
MS
7479void bnx2x_free_mem_cnic(struct bnx2x *bp)
7480{
7481 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7482
7483 if (!CHIP_IS_E1x(bp))
7484 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7485 sizeof(struct host_hc_status_block_e2));
7486 else
7487 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7488 sizeof(struct host_hc_status_block_e1x));
7489
7490 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7491}
7492
9f6c9258 7493void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7494{
a052997e
MS
7495 int i;
7496
a2fbb9ea 7497 /* fastpath */
b3b83c3f 7498 bnx2x_free_fp_mem(bp);
a2fbb9ea
ET
7499 /* end of fastpath */
7500
7501 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7502 sizeof(struct host_sp_status_block));
a2fbb9ea 7503
619c5cb6
VZ
7504 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7505 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7506
a2fbb9ea 7507 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7508 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7509
a052997e
MS
7510 for (i = 0; i < L2_ILT_LINES(bp); i++)
7511 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7512 bp->context[i].size);
523224a3
DK
7513 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7514
7515 BNX2X_FREE(bp->ilt->lines);
f85582f8 7516
7a9b2557 7517 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7518
523224a3
DK
7519 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7520 BCM_PAGE_SIZE * NUM_EQ_PAGES);
619c5cb6
VZ
7521}
7522
1191cb83 7523static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
619c5cb6
VZ
7524{
7525 int num_groups;
50f0a562 7526 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
619c5cb6 7527
50f0a562
BW
7528 /* number of queues for statistics is number of eth queues + FCoE */
7529 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
619c5cb6
VZ
7530
7531 /* Total number of FW statistics requests =
50f0a562
BW
7532 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
7533 * num of queues
7534 */
7535 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
523224a3 7536
619c5cb6
VZ
7537
7538 /* Request is built from stats_query_header and an array of
7539 * stats_query_cmd_group each of which contains
7540 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
7541 * configured in the stats_query_header.
7542 */
50f0a562
BW
7543 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
7544 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
619c5cb6
VZ
7545
7546 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
7547 num_groups * sizeof(struct stats_query_cmd_group);
7548
7549 /* Data for statistics requests + stats_conter
7550 *
7551 * stats_counter holds per-STORM counters that are incremented
7552 * when STORM has finished with the current request.
50f0a562
BW
7553 *
7554 * memory for FCoE offloaded statistics are counted anyway,
7555 * even if they will not be sent.
619c5cb6
VZ
7556 */
7557 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
7558 sizeof(struct per_pf_stats) +
50f0a562 7559 sizeof(struct fcoe_statistics_params) +
619c5cb6
VZ
7560 sizeof(struct per_queue_stats) * num_queue_stats +
7561 sizeof(struct stats_counter);
7562
7563 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
7564 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7565
7566 /* Set shortcuts */
7567 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
7568 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
7569
7570 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
7571 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
7572
7573 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
7574 bp->fw_stats_req_sz;
7575 return 0;
7576
7577alloc_mem_err:
7578 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7579 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
51c1a580 7580 BNX2X_ERR("Can't allocate memory\n");
619c5cb6 7581 return -ENOMEM;
a2fbb9ea
ET
7582}
7583
55c11941 7584int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7585{
619c5cb6
VZ
7586 if (!CHIP_IS_E1x(bp))
7587 /* size = the status block + ramrod buffers */
f2e0899f
DK
7588 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7589 sizeof(struct host_hc_status_block_e2));
7590 else
55c11941
MS
7591 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7592 &bp->cnic_sb_mapping,
7593 sizeof(struct
7594 host_hc_status_block_e1x));
8badd27a 7595
55c11941
MS
7596 if (CONFIGURE_NIC_MODE(bp))
7597 /* allocate searcher T2 table, as it wan't allocated before */
7598 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7599
7600 /* write address to which L5 should insert its values */
7601 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7602 &bp->slowpath->drv_info_to_mcp;
7603
7604 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7605 goto alloc_mem_err;
7606
7607 return 0;
7608
7609alloc_mem_err:
7610 bnx2x_free_mem_cnic(bp);
7611 BNX2X_ERR("Can't allocate memory\n");
7612 return -ENOMEM;
7613}
7614
7615int bnx2x_alloc_mem(struct bnx2x *bp)
7616{
7617 int i, allocated, context_size;
a2fbb9ea 7618
55c11941
MS
7619 if (!CONFIGURE_NIC_MODE(bp))
7620 /* allocate searcher T2 table */
7621 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7622
523224a3
DK
7623 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7624 sizeof(struct host_sp_status_block));
a2fbb9ea 7625
523224a3
DK
7626 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7627 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7628
619c5cb6
VZ
7629 /* Allocated memory for FW statistics */
7630 if (bnx2x_alloc_fw_stats_mem(bp))
7631 goto alloc_mem_err;
7632
a052997e
MS
7633 /* Allocate memory for CDU context:
7634 * This memory is allocated separately and not in the generic ILT
7635 * functions because CDU differs in few aspects:
7636 * 1. There are multiple entities allocating memory for context -
7637 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7638 * its own ILT lines.
7639 * 2. Since CDU page-size is not a single 4KB page (which is the case
7640 * for the other ILT clients), to be efficient we want to support
7641 * allocation of sub-page-size in the last entry.
7642 * 3. Context pointers are used by the driver to pass to FW / update
7643 * the context (for the other ILT clients the pointers are used just to
7644 * free the memory during unload).
7645 */
7646 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7647
a052997e
MS
7648 for (i = 0, allocated = 0; allocated < context_size; i++) {
7649 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7650 (context_size - allocated));
7651 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7652 &bp->context[i].cxt_mapping,
7653 bp->context[i].size);
7654 allocated += bp->context[i].size;
7655 }
523224a3 7656 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7657
523224a3
DK
7658 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7659 goto alloc_mem_err;
65abd74d 7660
9f6c9258
DK
7661 /* Slow path ring */
7662 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7663
523224a3
DK
7664 /* EQ */
7665 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7666 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7667
b3b83c3f
DK
7668
7669 /* fastpath */
7670 /* need to be done at the end, since it's self adjusting to amount
7671 * of memory available for RSS queues
7672 */
7673 if (bnx2x_alloc_fp_mem(bp))
7674 goto alloc_mem_err;
9f6c9258 7675 return 0;
e1510706 7676
9f6c9258
DK
7677alloc_mem_err:
7678 bnx2x_free_mem(bp);
51c1a580 7679 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7680 return -ENOMEM;
65abd74d
YG
7681}
7682
a2fbb9ea
ET
7683/*
7684 * Init service functions
7685 */
a2fbb9ea 7686
619c5cb6
VZ
7687int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7688 struct bnx2x_vlan_mac_obj *obj, bool set,
7689 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7690{
619c5cb6
VZ
7691 int rc;
7692 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7693
619c5cb6 7694 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7695
619c5cb6
VZ
7696 /* Fill general parameters */
7697 ramrod_param.vlan_mac_obj = obj;
7698 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7699
619c5cb6
VZ
7700 /* Fill a user request section if needed */
7701 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7702 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7703
619c5cb6 7704 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7705
619c5cb6
VZ
7706 /* Set the command: ADD or DEL */
7707 if (set)
7708 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7709 else
7710 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7711 }
7712
619c5cb6 7713 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7714
7715 if (rc == -EEXIST) {
7716 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7717 /* do not treat adding same MAC as error */
7718 rc = 0;
7719 } else if (rc < 0)
619c5cb6 7720 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7721
619c5cb6 7722 return rc;
a2fbb9ea
ET
7723}
7724
619c5cb6
VZ
7725int bnx2x_del_all_macs(struct bnx2x *bp,
7726 struct bnx2x_vlan_mac_obj *mac_obj,
7727 int mac_type, bool wait_for_comp)
e665bfda 7728{
619c5cb6
VZ
7729 int rc;
7730 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7731
619c5cb6
VZ
7732 /* Wait for completion of requested */
7733 if (wait_for_comp)
7734 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7735
619c5cb6
VZ
7736 /* Set the mac type of addresses we want to clear */
7737 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7738
619c5cb6
VZ
7739 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7740 if (rc < 0)
7741 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7742
619c5cb6 7743 return rc;
0793f83f
DK
7744}
7745
619c5cb6 7746int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7747{
619c5cb6 7748 unsigned long ramrod_flags = 0;
e665bfda 7749
a3348722
BW
7750 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7751 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7752 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7753 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7754 return 0;
7755 }
614c76df 7756
619c5cb6 7757 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7758
619c5cb6
VZ
7759 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7760 /* Eth MAC is set on RSS leading client (fp[0]) */
15192a8c
BW
7761 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7762 set, BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7763}
6e30dd4e 7764
619c5cb6 7765int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7766{
619c5cb6 7767 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7768}
a2fbb9ea 7769
d6214d7a 7770/**
e8920674 7771 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7772 *
e8920674 7773 * @bp: driver handle
d6214d7a 7774 *
e8920674 7775 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7776 */
0e8d2ec5 7777void bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7778{
9ee3d37b 7779 switch (int_mode) {
d6214d7a
DK
7780 case INT_MODE_MSI:
7781 bnx2x_enable_msi(bp);
7782 /* falling through... */
7783 case INT_MODE_INTx:
55c11941
MS
7784 bp->num_ethernet_queues = 1;
7785 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7786 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7787 break;
d6214d7a 7788 default:
d6214d7a
DK
7789 /* if we can't use MSI-X we only need one fp,
7790 * so try to enable MSI-X with the requested number of fp's
7791 * and fallback to MSI or legacy INTx with one fp
7792 */
30a5de77
DK
7793 if (bnx2x_enable_msix(bp) ||
7794 bp->flags & USING_SINGLE_MSIX_FLAG) {
7795 /* failed to enable multiple MSI-X */
7796 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
55c11941
MS
7797 bp->num_queues,
7798 1 + bp->num_cnic_queues);
51c1a580 7799
55c11941 7800 bp->num_queues = 1 + bp->num_cnic_queues;
d6214d7a 7801
9ee3d37b 7802 /* Try to enable MSI */
30a5de77
DK
7803 if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
7804 !(bp->flags & DISABLE_MSI_FLAG))
d6214d7a
DK
7805 bnx2x_enable_msi(bp);
7806 }
9f6c9258
DK
7807 break;
7808 }
a2fbb9ea
ET
7809}
7810
c2bff63f
DK
7811/* must be called prioir to any HW initializations */
7812static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7813{
7814 return L2_ILT_LINES(bp);
7815}
7816
523224a3
DK
7817void bnx2x_ilt_set_info(struct bnx2x *bp)
7818{
7819 struct ilt_client_info *ilt_client;
7820 struct bnx2x_ilt *ilt = BP_ILT(bp);
7821 u16 line = 0;
7822
7823 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7824 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7825
7826 /* CDU */
7827 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7828 ilt_client->client_num = ILT_CLIENT_CDU;
7829 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7830 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7831 ilt_client->start = line;
619c5cb6 7832 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
7833
7834 if (CNIC_SUPPORT(bp))
7835 line += CNIC_ILT_LINES;
523224a3
DK
7836 ilt_client->end = line - 1;
7837
51c1a580 7838 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7839 ilt_client->start,
7840 ilt_client->end,
7841 ilt_client->page_size,
7842 ilt_client->flags,
7843 ilog2(ilt_client->page_size >> 12));
7844
7845 /* QM */
7846 if (QM_INIT(bp->qm_cid_count)) {
7847 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7848 ilt_client->client_num = ILT_CLIENT_QM;
7849 ilt_client->page_size = QM_ILT_PAGE_SZ;
7850 ilt_client->flags = 0;
7851 ilt_client->start = line;
7852
7853 /* 4 bytes for each cid */
7854 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7855 QM_ILT_PAGE_SZ);
7856
7857 ilt_client->end = line - 1;
7858
51c1a580
MS
7859 DP(NETIF_MSG_IFUP,
7860 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7861 ilt_client->start,
7862 ilt_client->end,
7863 ilt_client->page_size,
7864 ilt_client->flags,
7865 ilog2(ilt_client->page_size >> 12));
7866
7867 }
523224a3 7868
55c11941
MS
7869 if (CNIC_SUPPORT(bp)) {
7870 /* SRC */
7871 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7872 ilt_client->client_num = ILT_CLIENT_SRC;
7873 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7874 ilt_client->flags = 0;
7875 ilt_client->start = line;
7876 line += SRC_ILT_LINES;
7877 ilt_client->end = line - 1;
523224a3 7878
55c11941
MS
7879 DP(NETIF_MSG_IFUP,
7880 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7881 ilt_client->start,
7882 ilt_client->end,
7883 ilt_client->page_size,
7884 ilt_client->flags,
7885 ilog2(ilt_client->page_size >> 12));
9f6c9258 7886
55c11941
MS
7887 /* TM */
7888 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7889 ilt_client->client_num = ILT_CLIENT_TM;
7890 ilt_client->page_size = TM_ILT_PAGE_SZ;
7891 ilt_client->flags = 0;
7892 ilt_client->start = line;
7893 line += TM_ILT_LINES;
7894 ilt_client->end = line - 1;
523224a3 7895
55c11941
MS
7896 DP(NETIF_MSG_IFUP,
7897 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7898 ilt_client->start,
7899 ilt_client->end,
7900 ilt_client->page_size,
7901 ilt_client->flags,
7902 ilog2(ilt_client->page_size >> 12));
7903 }
9f6c9258 7904
619c5cb6 7905 BUG_ON(line > ILT_MAX_LINES);
523224a3 7906}
f85582f8 7907
619c5cb6
VZ
7908/**
7909 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7910 *
7911 * @bp: driver handle
7912 * @fp: pointer to fastpath
7913 * @init_params: pointer to parameters structure
7914 *
7915 * parameters configured:
7916 * - HC configuration
7917 * - Queue's CDU context
7918 */
1191cb83 7919static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 7920 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 7921{
6383c0b3
AE
7922
7923 u8 cos;
a052997e
MS
7924 int cxt_index, cxt_offset;
7925
619c5cb6
VZ
7926 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7927 if (!IS_FCOE_FP(fp)) {
7928 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7929 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7930
7931 /* If HC is supporterd, enable host coalescing in the transition
7932 * to INIT state.
7933 */
7934 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7935 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7936
7937 /* HC rate */
7938 init_params->rx.hc_rate = bp->rx_ticks ?
7939 (1000000 / bp->rx_ticks) : 0;
7940 init_params->tx.hc_rate = bp->tx_ticks ?
7941 (1000000 / bp->tx_ticks) : 0;
7942
7943 /* FW SB ID */
7944 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7945 fp->fw_sb_id;
7946
7947 /*
7948 * CQ index among the SB indices: FCoE clients uses the default
7949 * SB, therefore it's different.
7950 */
6383c0b3
AE
7951 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7952 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
7953 }
7954
6383c0b3
AE
7955 /* set maximum number of COSs supported by this queue */
7956 init_params->max_cos = fp->max_cos;
7957
51c1a580 7958 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
7959 fp->index, init_params->max_cos);
7960
7961 /* set the context pointers queue object */
a052997e 7962 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
7963 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
7964 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 7965 ILT_PAGE_CIDS);
6383c0b3 7966 init_params->cxts[cos] =
a052997e
MS
7967 &bp->context[cxt_index].vcxt[cxt_offset].eth;
7968 }
619c5cb6
VZ
7969}
7970
910cc727 7971static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
7972 struct bnx2x_queue_state_params *q_params,
7973 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7974 int tx_index, bool leading)
7975{
7976 memset(tx_only_params, 0, sizeof(*tx_only_params));
7977
7978 /* Set the command */
7979 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7980
7981 /* Set tx-only QUEUE flags: don't zero statistics */
7982 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7983
7984 /* choose the index of the cid to send the slow path on */
7985 tx_only_params->cid_index = tx_index;
7986
7987 /* Set general TX_ONLY_SETUP parameters */
7988 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7989
7990 /* Set Tx TX_ONLY_SETUP parameters */
7991 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7992
51c1a580
MS
7993 DP(NETIF_MSG_IFUP,
7994 "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
7995 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7996 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7997 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7998
7999 /* send the ramrod */
8000 return bnx2x_queue_state_change(bp, q_params);
8001}
8002
8003
619c5cb6
VZ
8004/**
8005 * bnx2x_setup_queue - setup queue
8006 *
8007 * @bp: driver handle
8008 * @fp: pointer to fastpath
8009 * @leading: is leading
8010 *
8011 * This function performs 2 steps in a Queue state machine
8012 * actually: 1) RESET->INIT 2) INIT->SETUP
8013 */
8014
8015int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8016 bool leading)
8017{
3b603066 8018 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8019 struct bnx2x_queue_setup_params *setup_params =
8020 &q_params.params.setup;
6383c0b3
AE
8021 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8022 &q_params.params.tx_only;
a2fbb9ea 8023 int rc;
6383c0b3
AE
8024 u8 tx_index;
8025
51c1a580 8026 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8027
ec6ba945
VZ
8028 /* reset IGU state skip FCoE L2 queue */
8029 if (!IS_FCOE_FP(fp))
8030 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8031 IGU_INT_ENABLE, 0);
a2fbb9ea 8032
15192a8c 8033 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8034 /* We want to wait for completion in this context */
8035 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8036
619c5cb6
VZ
8037 /* Prepare the INIT parameters */
8038 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8039
619c5cb6
VZ
8040 /* Set the command */
8041 q_params.cmd = BNX2X_Q_CMD_INIT;
8042
8043 /* Change the state to INIT */
8044 rc = bnx2x_queue_state_change(bp, &q_params);
8045 if (rc) {
6383c0b3 8046 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8047 return rc;
8048 }
ec6ba945 8049
51c1a580 8050 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
8051
8052
619c5cb6
VZ
8053 /* Now move the Queue to the SETUP state... */
8054 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8055
619c5cb6
VZ
8056 /* Set QUEUE flags */
8057 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8058
619c5cb6 8059 /* Set general SETUP parameters */
6383c0b3
AE
8060 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8061 FIRST_TX_COS_INDEX);
619c5cb6 8062
6383c0b3 8063 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8064 &setup_params->rxq_params);
8065
6383c0b3
AE
8066 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8067 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8068
8069 /* Set the command */
8070 q_params.cmd = BNX2X_Q_CMD_SETUP;
8071
55c11941
MS
8072 if (IS_FCOE_FP(fp))
8073 bp->fcoe_init = true;
8074
619c5cb6
VZ
8075 /* Change the state to SETUP */
8076 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8077 if (rc) {
8078 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8079 return rc;
8080 }
8081
8082 /* loop through the relevant tx-only indices */
8083 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8084 tx_index < fp->max_cos;
8085 tx_index++) {
8086
8087 /* prepare and send tx-only ramrod*/
8088 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8089 tx_only_params, tx_index, leading);
8090 if (rc) {
8091 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8092 fp->index, tx_index);
8093 return rc;
8094 }
8095 }
523224a3 8096
34f80b04 8097 return rc;
a2fbb9ea
ET
8098}
8099
619c5cb6 8100static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8101{
619c5cb6 8102 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8103 struct bnx2x_fp_txdata *txdata;
3b603066 8104 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8105 int rc, tx_index;
8106
51c1a580 8107 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8108
15192a8c 8109 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8110 /* We want to wait for completion in this context */
8111 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8112
6383c0b3
AE
8113
8114 /* close tx-only connections */
8115 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8116 tx_index < fp->max_cos;
8117 tx_index++){
8118
8119 /* ascertain this is a normal queue*/
65565884 8120 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8121
51c1a580 8122 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8123 txdata->txq_index);
8124
8125 /* send halt terminate on tx-only connection */
8126 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8127 memset(&q_params.params.terminate, 0,
8128 sizeof(q_params.params.terminate));
8129 q_params.params.terminate.cid_index = tx_index;
8130
8131 rc = bnx2x_queue_state_change(bp, &q_params);
8132 if (rc)
8133 return rc;
8134
8135 /* send halt terminate on tx-only connection */
8136 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8137 memset(&q_params.params.cfc_del, 0,
8138 sizeof(q_params.params.cfc_del));
8139 q_params.params.cfc_del.cid_index = tx_index;
8140 rc = bnx2x_queue_state_change(bp, &q_params);
8141 if (rc)
8142 return rc;
8143 }
8144 /* Stop the primary connection: */
8145 /* ...halt the connection */
619c5cb6
VZ
8146 q_params.cmd = BNX2X_Q_CMD_HALT;
8147 rc = bnx2x_queue_state_change(bp, &q_params);
8148 if (rc)
da5a662a 8149 return rc;
a2fbb9ea 8150
6383c0b3 8151 /* ...terminate the connection */
619c5cb6 8152 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8153 memset(&q_params.params.terminate, 0,
8154 sizeof(q_params.params.terminate));
8155 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8156 rc = bnx2x_queue_state_change(bp, &q_params);
8157 if (rc)
523224a3 8158 return rc;
6383c0b3 8159 /* ...delete cfc entry */
619c5cb6 8160 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8161 memset(&q_params.params.cfc_del, 0,
8162 sizeof(q_params.params.cfc_del));
8163 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8164 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8165}
8166
8167
34f80b04
EG
8168static void bnx2x_reset_func(struct bnx2x *bp)
8169{
8170 int port = BP_PORT(bp);
8171 int func = BP_FUNC(bp);
f2e0899f 8172 int i;
523224a3
DK
8173
8174 /* Disable the function in the FW */
8175 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8176 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8177 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8178 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8179
8180 /* FP SBs */
ec6ba945 8181 for_each_eth_queue(bp, i) {
523224a3 8182 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8183 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8184 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8185 SB_DISABLED);
523224a3
DK
8186 }
8187
55c11941
MS
8188 if (CNIC_LOADED(bp))
8189 /* CNIC SB */
8190 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8191 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8192 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8193
523224a3 8194 /* SP SB */
619c5cb6 8195 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8196 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8197 SB_DISABLED);
523224a3
DK
8198
8199 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8200 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8201 0);
34f80b04
EG
8202
8203 /* Configure IGU */
f2e0899f
DK
8204 if (bp->common.int_block == INT_BLOCK_HC) {
8205 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8206 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8207 } else {
8208 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8209 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8210 }
34f80b04 8211
55c11941
MS
8212 if (CNIC_LOADED(bp)) {
8213 /* Disable Timer scan */
8214 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8215 /*
8216 * Wait for at least 10ms and up to 2 second for the timers
8217 * scan to complete
8218 */
8219 for (i = 0; i < 200; i++) {
8220 msleep(10);
8221 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8222 break;
8223 }
37b091ba 8224 }
34f80b04 8225 /* Clear ILT */
f2e0899f
DK
8226 bnx2x_clear_func_ilt(bp, func);
8227
8228 /* Timers workaround bug for E2: if this is vnic-3,
8229 * we need to set the entire ilt range for this timers.
8230 */
619c5cb6 8231 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8232 struct ilt_client_info ilt_cli;
8233 /* use dummy TM client */
8234 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8235 ilt_cli.start = 0;
8236 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8237 ilt_cli.client_num = ILT_CLIENT_TM;
8238
8239 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8240 }
8241
8242 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8243 if (!CHIP_IS_E1x(bp))
f2e0899f 8244 bnx2x_pf_disable(bp);
523224a3
DK
8245
8246 bp->dmae_ready = 0;
34f80b04
EG
8247}
8248
8249static void bnx2x_reset_port(struct bnx2x *bp)
8250{
8251 int port = BP_PORT(bp);
8252 u32 val;
8253
619c5cb6
VZ
8254 /* Reset physical Link */
8255 bnx2x__link_reset(bp);
8256
34f80b04
EG
8257 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8258
8259 /* Do not rcv packets to BRB */
8260 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8261 /* Do not direct rcv packets that are not for MCP to the BRB */
8262 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8263 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8264
8265 /* Configure AEU */
8266 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8267
8268 msleep(100);
8269 /* Check for BRB port occupancy */
8270 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8271 if (val)
8272 DP(NETIF_MSG_IFDOWN,
33471629 8273 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8274
8275 /* TODO: Close Doorbell port? */
8276}
8277
1191cb83 8278static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8279{
3b603066 8280 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8281
619c5cb6
VZ
8282 /* Prepare parameters for function state transitions */
8283 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8284
619c5cb6
VZ
8285 func_params.f_obj = &bp->func_obj;
8286 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8287
619c5cb6 8288 func_params.params.hw_init.load_phase = load_code;
49d66772 8289
619c5cb6 8290 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8291}
8292
1191cb83 8293static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8294{
3b603066 8295 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8296 int rc;
228241eb 8297
619c5cb6
VZ
8298 /* Prepare parameters for function state transitions */
8299 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8300 func_params.f_obj = &bp->func_obj;
8301 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8302
619c5cb6
VZ
8303 /*
8304 * Try to stop the function the 'good way'. If fails (in case
8305 * of a parity error during bnx2x_chip_cleanup()) and we are
8306 * not in a debug mode, perform a state transaction in order to
8307 * enable further HW_RESET transaction.
8308 */
8309 rc = bnx2x_func_state_change(bp, &func_params);
8310 if (rc) {
34f80b04 8311#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8312 return rc;
34f80b04 8313#else
51c1a580 8314 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8315 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8316 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8317#endif
228241eb 8318 }
a2fbb9ea 8319
619c5cb6
VZ
8320 return 0;
8321}
523224a3 8322
619c5cb6
VZ
8323/**
8324 * bnx2x_send_unload_req - request unload mode from the MCP.
8325 *
8326 * @bp: driver handle
8327 * @unload_mode: requested function's unload mode
8328 *
8329 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8330 */
8331u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8332{
8333 u32 reset_code = 0;
8334 int port = BP_PORT(bp);
3101c2bc 8335
619c5cb6 8336 /* Select the UNLOAD request mode */
65abd74d
YG
8337 if (unload_mode == UNLOAD_NORMAL)
8338 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8339
7d0446c2 8340 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8341 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8342
7d0446c2 8343 else if (bp->wol) {
65abd74d
YG
8344 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8345 u8 *mac_addr = bp->dev->dev_addr;
8346 u32 val;
f9977903
DK
8347 u16 pmc;
8348
65abd74d 8349 /* The mac address is written to entries 1-4 to
f9977903
DK
8350 * preserve entry 0 which is used by the PMF
8351 */
3395a033 8352 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8353
8354 val = (mac_addr[0] << 8) | mac_addr[1];
8355 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8356
8357 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8358 (mac_addr[4] << 8) | mac_addr[5];
8359 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8360
f9977903
DK
8361 /* Enable the PME and clear the status */
8362 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8363 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8364 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8365
65abd74d
YG
8366 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8367
8368 } else
8369 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8370
619c5cb6
VZ
8371 /* Send the request to the MCP */
8372 if (!BP_NOMCP(bp))
8373 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8374 else {
8375 int path = BP_PATH(bp);
8376
51c1a580 8377 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8378 path, load_count[path][0], load_count[path][1],
8379 load_count[path][2]);
8380 load_count[path][0]--;
8381 load_count[path][1 + port]--;
51c1a580 8382 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8383 path, load_count[path][0], load_count[path][1],
8384 load_count[path][2]);
8385 if (load_count[path][0] == 0)
8386 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8387 else if (load_count[path][1 + port] == 0)
8388 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8389 else
8390 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8391 }
8392
8393 return reset_code;
8394}
8395
8396/**
8397 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8398 *
8399 * @bp: driver handle
5d07d868 8400 * @keep_link: true iff link should be kept up
619c5cb6 8401 */
5d07d868 8402void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8403{
5d07d868
YM
8404 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8405
619c5cb6
VZ
8406 /* Report UNLOAD_DONE to MCP */
8407 if (!BP_NOMCP(bp))
5d07d868 8408 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8409}
8410
1191cb83 8411static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8412{
8413 int tout = 50;
8414 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8415
8416 if (!bp->port.pmf)
8417 return 0;
8418
8419 /*
8420 * (assumption: No Attention from MCP at this stage)
8421 * PMF probably in the middle of TXdisable/enable transaction
8422 * 1. Sync IRS for default SB
8423 * 2. Sync SP queue - this guarantes us that attention handling started
8424 * 3. Wait, that TXdisable/enable transaction completes
8425 *
8426 * 1+2 guranty that if DCBx attention was scheduled it already changed
8427 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8428 * received complettion for the transaction the state is TX_STOPPED.
8429 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8430 * transaction.
8431 */
8432
8433 /* make sure default SB ISR is done */
8434 if (msix)
8435 synchronize_irq(bp->msix_table[0].vector);
8436 else
8437 synchronize_irq(bp->pdev->irq);
8438
8439 flush_workqueue(bnx2x_wq);
8440
8441 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8442 BNX2X_F_STATE_STARTED && tout--)
8443 msleep(20);
8444
8445 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8446 BNX2X_F_STATE_STARTED) {
8447#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8448 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8449 return -EBUSY;
8450#else
8451 /*
8452 * Failed to complete the transaction in a "good way"
8453 * Force both transactions with CLR bit
8454 */
3b603066 8455 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8456
51c1a580
MS
8457 DP(NETIF_MSG_IFDOWN,
8458 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8459
8460 func_params.f_obj = &bp->func_obj;
8461 __set_bit(RAMROD_DRV_CLR_ONLY,
8462 &func_params.ramrod_flags);
8463
8464 /* STARTED-->TX_ST0PPED */
8465 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8466 bnx2x_func_state_change(bp, &func_params);
8467
8468 /* TX_ST0PPED-->STARTED */
8469 func_params.cmd = BNX2X_F_CMD_TX_START;
8470 return bnx2x_func_state_change(bp, &func_params);
8471#endif
8472 }
8473
8474 return 0;
8475}
8476
5d07d868 8477void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8478{
8479 int port = BP_PORT(bp);
6383c0b3
AE
8480 int i, rc = 0;
8481 u8 cos;
3b603066 8482 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8483 u32 reset_code;
8484
8485 /* Wait until tx fastpath tasks complete */
8486 for_each_tx_queue(bp, i) {
8487 struct bnx2x_fastpath *fp = &bp->fp[i];
8488
6383c0b3 8489 for_each_cos_in_tx_queue(fp, cos)
65565884 8490 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8491#ifdef BNX2X_STOP_ON_ERROR
8492 if (rc)
8493 return;
8494#endif
8495 }
8496
8497 /* Give HW time to discard old tx messages */
8498 usleep_range(1000, 1000);
8499
8500 /* Clean all ETH MACs */
15192a8c
BW
8501 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8502 false);
619c5cb6
VZ
8503 if (rc < 0)
8504 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8505
8506 /* Clean up UC list */
15192a8c 8507 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8508 true);
8509 if (rc < 0)
51c1a580
MS
8510 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8511 rc);
619c5cb6
VZ
8512
8513 /* Disable LLH */
8514 if (!CHIP_IS_E1(bp))
8515 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8516
8517 /* Set "drop all" (stop Rx).
8518 * We need to take a netif_addr_lock() here in order to prevent
8519 * a race between the completion code and this code.
8520 */
8521 netif_addr_lock_bh(bp->dev);
8522 /* Schedule the rx_mode command */
8523 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8524 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8525 else
8526 bnx2x_set_storm_rx_mode(bp);
8527
8528 /* Cleanup multicast configuration */
8529 rparam.mcast_obj = &bp->mcast_obj;
8530 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8531 if (rc < 0)
8532 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8533
8534 netif_addr_unlock_bh(bp->dev);
8535
8536
6debea87
DK
8537
8538 /*
8539 * Send the UNLOAD_REQUEST to the MCP. This will return if
8540 * this function should perform FUNC, PORT or COMMON HW
8541 * reset.
8542 */
8543 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8544
8545 /*
8546 * (assumption: No Attention from MCP at this stage)
8547 * PMF probably in the middle of TXdisable/enable transaction
8548 */
8549 rc = bnx2x_func_wait_started(bp);
8550 if (rc) {
8551 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8552#ifdef BNX2X_STOP_ON_ERROR
8553 return;
8554#endif
8555 }
8556
34f80b04 8557 /* Close multi and leading connections
619c5cb6
VZ
8558 * Completions for ramrods are collected in a synchronous way
8559 */
55c11941 8560 for_each_eth_queue(bp, i)
619c5cb6 8561 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8562#ifdef BNX2X_STOP_ON_ERROR
8563 return;
8564#else
228241eb 8565 goto unload_error;
523224a3 8566#endif
55c11941
MS
8567
8568 if (CNIC_LOADED(bp)) {
8569 for_each_cnic_queue(bp, i)
8570 if (bnx2x_stop_queue(bp, i))
8571#ifdef BNX2X_STOP_ON_ERROR
8572 return;
8573#else
8574 goto unload_error;
8575#endif
8576 }
8577
619c5cb6
VZ
8578 /* If SP settings didn't get completed so far - something
8579 * very wrong has happen.
8580 */
8581 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8582 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8583
619c5cb6
VZ
8584#ifndef BNX2X_STOP_ON_ERROR
8585unload_error:
8586#endif
523224a3 8587 rc = bnx2x_func_stop(bp);
da5a662a 8588 if (rc) {
523224a3 8589 BNX2X_ERR("Function stop failed!\n");
da5a662a 8590#ifdef BNX2X_STOP_ON_ERROR
523224a3 8591 return;
523224a3 8592#endif
34f80b04 8593 }
a2fbb9ea 8594
523224a3
DK
8595 /* Disable HW interrupts, NAPI */
8596 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8597 /* Delete all NAPI objects */
8598 bnx2x_del_all_napi(bp);
55c11941
MS
8599 if (CNIC_LOADED(bp))
8600 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8601
8602 /* Release IRQs */
d6214d7a 8603 bnx2x_free_irq(bp);
523224a3 8604
a2fbb9ea 8605 /* Reset the chip */
619c5cb6
VZ
8606 rc = bnx2x_reset_hw(bp, reset_code);
8607 if (rc)
8608 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8609
356e2385 8610
619c5cb6 8611 /* Report UNLOAD_DONE to MCP */
5d07d868 8612 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8613}
8614
9f6c9258 8615void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8616{
8617 u32 val;
8618
51c1a580 8619 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8620
8621 if (CHIP_IS_E1(bp)) {
8622 int port = BP_PORT(bp);
8623 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8624 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8625
8626 val = REG_RD(bp, addr);
8627 val &= ~(0x300);
8628 REG_WR(bp, addr, val);
619c5cb6 8629 } else {
72fd0718
VZ
8630 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8631 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8632 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8633 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8634 }
8635}
8636
72fd0718
VZ
8637/* Close gates #2, #3 and #4: */
8638static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8639{
c9ee9206 8640 u32 val;
72fd0718
VZ
8641
8642 /* Gates #2 and #4a are closed/opened for "not E1" only */
8643 if (!CHIP_IS_E1(bp)) {
8644 /* #4 */
c9ee9206 8645 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8646 /* #2 */
c9ee9206 8647 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8648 }
8649
8650 /* #3 */
c9ee9206
VZ
8651 if (CHIP_IS_E1x(bp)) {
8652 /* Prevent interrupts from HC on both ports */
8653 val = REG_RD(bp, HC_REG_CONFIG_1);
8654 REG_WR(bp, HC_REG_CONFIG_1,
8655 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8656 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8657
8658 val = REG_RD(bp, HC_REG_CONFIG_0);
8659 REG_WR(bp, HC_REG_CONFIG_0,
8660 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8661 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8662 } else {
8663 /* Prevent incomming interrupts in IGU */
8664 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8665
8666 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8667 (!close) ?
8668 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8669 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8670 }
72fd0718 8671
51c1a580 8672 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8673 close ? "closing" : "opening");
8674 mmiowb();
8675}
8676
8677#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8678
8679static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8680{
8681 /* Do some magic... */
8682 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8683 *magic_val = val & SHARED_MF_CLP_MAGIC;
8684 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8685}
8686
e8920674
DK
8687/**
8688 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8689 *
e8920674
DK
8690 * @bp: driver handle
8691 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8692 */
8693static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8694{
8695 /* Restore the `magic' bit value... */
72fd0718
VZ
8696 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8697 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8698 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8699}
8700
f85582f8 8701/**
e8920674 8702 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8703 *
e8920674
DK
8704 * @bp: driver handle
8705 * @magic_val: old value of 'magic' bit.
8706 *
8707 * Takes care of CLP configurations.
72fd0718
VZ
8708 */
8709static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8710{
8711 u32 shmem;
8712 u32 validity_offset;
8713
51c1a580 8714 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8715
8716 /* Set `magic' bit in order to save MF config */
8717 if (!CHIP_IS_E1(bp))
8718 bnx2x_clp_reset_prep(bp, magic_val);
8719
8720 /* Get shmem offset */
8721 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
8722 validity_offset =
8723 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
8724
8725 /* Clear validity map flags */
8726 if (shmem > 0)
8727 REG_WR(bp, shmem + validity_offset, 0);
8728}
8729
8730#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8731#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8732
e8920674
DK
8733/**
8734 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8735 *
e8920674 8736 * @bp: driver handle
72fd0718 8737 */
1191cb83 8738static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8739{
8740 /* special handling for emulation and FPGA,
8741 wait 10 times longer */
8742 if (CHIP_REV_IS_SLOW(bp))
8743 msleep(MCP_ONE_TIMEOUT*10);
8744 else
8745 msleep(MCP_ONE_TIMEOUT);
8746}
8747
1b6e2ceb
DK
8748/*
8749 * initializes bp->common.shmem_base and waits for validity signature to appear
8750 */
8751static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8752{
1b6e2ceb
DK
8753 int cnt = 0;
8754 u32 val = 0;
72fd0718 8755
1b6e2ceb
DK
8756 do {
8757 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8758 if (bp->common.shmem_base) {
8759 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8760 if (val & SHR_MEM_VALIDITY_MB)
8761 return 0;
8762 }
72fd0718 8763
1b6e2ceb 8764 bnx2x_mcp_wait_one(bp);
72fd0718 8765
1b6e2ceb 8766 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8767
1b6e2ceb 8768 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8769
1b6e2ceb
DK
8770 return -ENODEV;
8771}
72fd0718 8772
1b6e2ceb
DK
8773static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8774{
8775 int rc = bnx2x_init_shmem(bp);
72fd0718 8776
72fd0718
VZ
8777 /* Restore the `magic' bit value */
8778 if (!CHIP_IS_E1(bp))
8779 bnx2x_clp_reset_done(bp, magic_val);
8780
8781 return rc;
8782}
8783
8784static void bnx2x_pxp_prep(struct bnx2x *bp)
8785{
8786 if (!CHIP_IS_E1(bp)) {
8787 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8788 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8789 mmiowb();
8790 }
8791}
8792
8793/*
8794 * Reset the whole chip except for:
8795 * - PCIE core
8796 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8797 * one reset bit)
8798 * - IGU
8799 * - MISC (including AEU)
8800 * - GRC
8801 * - RBCN, RBCP
8802 */
c9ee9206 8803static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8804{
8805 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8806 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8807
8808 /*
8809 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8810 * (per chip) blocks.
8811 */
8812 global_bits2 =
8813 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8814 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 8815
c55e771b
BW
8816 /* Don't reset the following blocks.
8817 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
8818 * reset, as in 4 port device they might still be owned
8819 * by the MCP (there is only one leader per path).
8820 */
72fd0718
VZ
8821 not_reset_mask1 =
8822 MISC_REGISTERS_RESET_REG_1_RST_HC |
8823 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8824 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8825
8826 not_reset_mask2 =
c9ee9206 8827 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
8828 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8829 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8830 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8831 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8832 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8833 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
8834 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8835 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
8836 MISC_REGISTERS_RESET_REG_2_PGLC |
8837 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8838 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8839 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8840 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8841 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8842 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 8843
8736c826
VZ
8844 /*
8845 * Keep the following blocks in reset:
8846 * - all xxMACs are handled by the bnx2x_link code.
8847 */
8848 stay_reset2 =
8736c826
VZ
8849 MISC_REGISTERS_RESET_REG_2_XMAC |
8850 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8851
8852 /* Full reset masks according to the chip */
72fd0718
VZ
8853 reset_mask1 = 0xffffffff;
8854
8855 if (CHIP_IS_E1(bp))
8856 reset_mask2 = 0xffff;
8736c826 8857 else if (CHIP_IS_E1H(bp))
72fd0718 8858 reset_mask2 = 0x1ffff;
8736c826
VZ
8859 else if (CHIP_IS_E2(bp))
8860 reset_mask2 = 0xfffff;
8861 else /* CHIP_IS_E3 */
8862 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
8863
8864 /* Don't reset global blocks unless we need to */
8865 if (!global)
8866 reset_mask2 &= ~global_bits2;
8867
8868 /*
8869 * In case of attention in the QM, we need to reset PXP
8870 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8871 * because otherwise QM reset would release 'close the gates' shortly
8872 * before resetting the PXP, then the PSWRQ would send a write
8873 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8874 * read the payload data from PSWWR, but PSWWR would not
8875 * respond. The write queue in PGLUE would stuck, dmae commands
8876 * would not return. Therefore it's important to reset the second
8877 * reset register (containing the
8878 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8879 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8880 * bit).
8881 */
72fd0718
VZ
8882 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8883 reset_mask2 & (~not_reset_mask2));
8884
c9ee9206
VZ
8885 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8886 reset_mask1 & (~not_reset_mask1));
8887
72fd0718
VZ
8888 barrier();
8889 mmiowb();
8890
8736c826
VZ
8891 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8892 reset_mask2 & (~stay_reset2));
8893
8894 barrier();
8895 mmiowb();
8896
c9ee9206 8897 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
8898 mmiowb();
8899}
8900
c9ee9206
VZ
8901/**
8902 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8903 * It should get cleared in no more than 1s.
8904 *
8905 * @bp: driver handle
8906 *
8907 * It should get cleared in no more than 1s. Returns 0 if
8908 * pending writes bit gets cleared.
8909 */
8910static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8911{
8912 u32 cnt = 1000;
8913 u32 pend_bits = 0;
8914
8915 do {
8916 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8917
8918 if (pend_bits == 0)
8919 break;
8920
8921 usleep_range(1000, 1000);
8922 } while (cnt-- > 0);
8923
8924 if (cnt <= 0) {
8925 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8926 pend_bits);
8927 return -EBUSY;
8928 }
8929
8930 return 0;
8931}
8932
8933static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
8934{
8935 int cnt = 1000;
8936 u32 val = 0;
8937 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
c55e771b 8938 u32 tags_63_32 = 0;
72fd0718
VZ
8939
8940
8941 /* Empty the Tetris buffer, wait for 1s */
8942 do {
8943 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8944 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8945 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8946 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8947 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
8948 if (CHIP_IS_E3(bp))
8949 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
8950
72fd0718
VZ
8951 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8952 ((port_is_idle_0 & 0x1) == 0x1) &&
8953 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
8954 (pgl_exp_rom2 == 0xffffffff) &&
8955 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 8956 break;
c9ee9206 8957 usleep_range(1000, 1000);
72fd0718
VZ
8958 } while (cnt-- > 0);
8959
8960 if (cnt <= 0) {
51c1a580
MS
8961 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8962 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
8963 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8964 pgl_exp_rom2);
8965 return -EAGAIN;
8966 }
8967
8968 barrier();
8969
8970 /* Close gates #2, #3 and #4 */
8971 bnx2x_set_234_gates(bp, true);
8972
c9ee9206
VZ
8973 /* Poll for IGU VQs for 57712 and newer chips */
8974 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8975 return -EAGAIN;
8976
8977
72fd0718
VZ
8978 /* TBD: Indicate that "process kill" is in progress to MCP */
8979
8980 /* Clear "unprepared" bit */
8981 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8982 barrier();
8983
8984 /* Make sure all is written to the chip before the reset */
8985 mmiowb();
8986
8987 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8988 * PSWHST, GRC and PSWRD Tetris buffer.
8989 */
c9ee9206 8990 usleep_range(1000, 1000);
72fd0718
VZ
8991
8992 /* Prepare to chip reset: */
8993 /* MCP */
c9ee9206
VZ
8994 if (global)
8995 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
8996
8997 /* PXP */
8998 bnx2x_pxp_prep(bp);
8999 barrier();
9000
9001 /* reset the chip */
c9ee9206 9002 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9003 barrier();
9004
9005 /* Recover after reset: */
9006 /* MCP */
c9ee9206 9007 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9008 return -EAGAIN;
9009
c9ee9206
VZ
9010 /* TBD: Add resetting the NO_MCP mode DB here */
9011
72fd0718
VZ
9012 /* Open the gates #2, #3 and #4 */
9013 bnx2x_set_234_gates(bp, false);
9014
9015 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9016 * reset state, re-enable attentions. */
9017
a2fbb9ea
ET
9018 return 0;
9019}
9020
910cc727 9021static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9022{
9023 int rc = 0;
c9ee9206 9024 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9025 u32 load_code;
9026
9027 /* if not going to reset MCP - load "fake" driver to reset HW while
9028 * driver is owner of the HW
9029 */
9030 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9031 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9032 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9033 if (!load_code) {
9034 BNX2X_ERR("MCP response failure, aborting\n");
9035 rc = -EAGAIN;
9036 goto exit_leader_reset;
9037 }
9038 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9039 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9040 BNX2X_ERR("MCP unexpected resp, aborting\n");
9041 rc = -EAGAIN;
9042 goto exit_leader_reset2;
9043 }
9044 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9045 if (!load_code) {
9046 BNX2X_ERR("MCP response failure, aborting\n");
9047 rc = -EAGAIN;
9048 goto exit_leader_reset2;
9049 }
9050 }
c9ee9206 9051
72fd0718 9052 /* Try to recover after the failure */
c9ee9206 9053 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9054 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9055 BP_PATH(bp));
72fd0718 9056 rc = -EAGAIN;
95c6c616 9057 goto exit_leader_reset2;
72fd0718
VZ
9058 }
9059
c9ee9206
VZ
9060 /*
9061 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9062 * state.
9063 */
72fd0718 9064 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9065 if (global)
9066 bnx2x_clear_reset_global(bp);
72fd0718 9067
95c6c616
AE
9068exit_leader_reset2:
9069 /* unload "fake driver" if it was loaded */
9070 if (!global && !BP_NOMCP(bp)) {
9071 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9072 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9073 }
72fd0718
VZ
9074exit_leader_reset:
9075 bp->is_leader = 0;
c9ee9206
VZ
9076 bnx2x_release_leader_lock(bp);
9077 smp_mb();
72fd0718
VZ
9078 return rc;
9079}
9080
1191cb83 9081static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9082{
9083 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9084
9085 /* Disconnect this device */
9086 netif_device_detach(bp->dev);
9087
9088 /*
9089 * Block ifup for all function on this engine until "process kill"
9090 * or power cycle.
9091 */
9092 bnx2x_set_reset_in_progress(bp);
9093
9094 /* Shut down the power */
9095 bnx2x_set_power_state(bp, PCI_D3hot);
9096
9097 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9098
9099 smp_mb();
9100}
9101
9102/*
9103 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9104 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9105 * will never be called when netif_running(bp->dev) is false.
9106 */
9107static void bnx2x_parity_recover(struct bnx2x *bp)
9108{
c9ee9206 9109 bool global = false;
7a752993 9110 u32 error_recovered, error_unrecovered;
95c6c616 9111 bool is_parity;
c9ee9206 9112
72fd0718
VZ
9113 DP(NETIF_MSG_HW, "Handling parity\n");
9114 while (1) {
9115 switch (bp->recovery_state) {
9116 case BNX2X_RECOVERY_INIT:
9117 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9118 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9119 WARN_ON(!is_parity);
c9ee9206 9120
72fd0718 9121 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9122 if (bnx2x_trylock_leader_lock(bp)) {
9123 bnx2x_set_reset_in_progress(bp);
9124 /*
9125 * Check if there is a global attention and if
9126 * there was a global attention, set the global
9127 * reset bit.
9128 */
9129
9130 if (global)
9131 bnx2x_set_reset_global(bp);
9132
72fd0718 9133 bp->is_leader = 1;
c9ee9206 9134 }
72fd0718
VZ
9135
9136 /* Stop the driver */
9137 /* If interface has been removed - break */
5d07d868 9138 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9139 return;
9140
9141 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9142
c9ee9206
VZ
9143 /* Ensure "is_leader", MCP command sequence and
9144 * "recovery_state" update values are seen on other
9145 * CPUs.
72fd0718 9146 */
c9ee9206 9147 smp_mb();
72fd0718
VZ
9148 break;
9149
9150 case BNX2X_RECOVERY_WAIT:
9151 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9152 if (bp->is_leader) {
c9ee9206 9153 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9154 bool other_load_status =
9155 bnx2x_get_load_status(bp, other_engine);
9156 bool load_status =
9157 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9158 global = bnx2x_reset_is_global(bp);
9159
9160 /*
9161 * In case of a parity in a global block, let
9162 * the first leader that performs a
9163 * leader_reset() reset the global blocks in
9164 * order to clear global attentions. Otherwise
9165 * the the gates will remain closed for that
9166 * engine.
9167 */
889b9af3
AE
9168 if (load_status ||
9169 (global && other_load_status)) {
72fd0718
VZ
9170 /* Wait until all other functions get
9171 * down.
9172 */
7be08a72 9173 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9174 HZ/10);
9175 return;
9176 } else {
9177 /* If all other functions got down -
9178 * try to bring the chip back to
9179 * normal. In any case it's an exit
9180 * point for a leader.
9181 */
c9ee9206
VZ
9182 if (bnx2x_leader_reset(bp)) {
9183 bnx2x_recovery_failed(bp);
72fd0718
VZ
9184 return;
9185 }
9186
c9ee9206
VZ
9187 /* If we are here, means that the
9188 * leader has succeeded and doesn't
9189 * want to be a leader any more. Try
9190 * to continue as a none-leader.
9191 */
9192 break;
72fd0718
VZ
9193 }
9194 } else { /* non-leader */
c9ee9206 9195 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9196 /* Try to get a LEADER_LOCK HW lock as
9197 * long as a former leader may have
9198 * been unloaded by the user or
9199 * released a leadership by another
9200 * reason.
9201 */
c9ee9206 9202 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9203 /* I'm a leader now! Restart a
9204 * switch case.
9205 */
9206 bp->is_leader = 1;
9207 break;
9208 }
9209
7be08a72 9210 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9211 HZ/10);
9212 return;
9213
c9ee9206
VZ
9214 } else {
9215 /*
9216 * If there was a global attention, wait
9217 * for it to be cleared.
9218 */
9219 if (bnx2x_reset_is_global(bp)) {
9220 schedule_delayed_work(
7be08a72
AE
9221 &bp->sp_rtnl_task,
9222 HZ/10);
c9ee9206
VZ
9223 return;
9224 }
9225
7a752993
AE
9226 error_recovered =
9227 bp->eth_stats.recoverable_error;
9228 error_unrecovered =
9229 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9230 bp->recovery_state =
9231 BNX2X_RECOVERY_NIC_LOADING;
9232 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9233 error_unrecovered++;
95c6c616 9234 netdev_err(bp->dev,
51c1a580 9235 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9236 /* Disconnect this device */
9237 netif_device_detach(bp->dev);
9238 /* Shut down the power */
9239 bnx2x_set_power_state(
9240 bp, PCI_D3hot);
9241 smp_mb();
9242 } else {
c9ee9206
VZ
9243 bp->recovery_state =
9244 BNX2X_RECOVERY_DONE;
7a752993 9245 error_recovered++;
c9ee9206
VZ
9246 smp_mb();
9247 }
7a752993
AE
9248 bp->eth_stats.recoverable_error =
9249 error_recovered;
9250 bp->eth_stats.unrecoverable_error =
9251 error_unrecovered;
c9ee9206 9252
72fd0718
VZ
9253 return;
9254 }
9255 }
9256 default:
9257 return;
9258 }
9259 }
9260}
9261
56ad3152
MS
9262static int bnx2x_close(struct net_device *dev);
9263
72fd0718
VZ
9264/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9265 * scheduled on a general queue in order to prevent a dead lock.
9266 */
7be08a72 9267static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9268{
7be08a72 9269 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9270
9271 rtnl_lock();
9272
9273 if (!netif_running(bp->dev))
7be08a72
AE
9274 goto sp_rtnl_exit;
9275
9276 /* if stop on error is defined no recovery flows should be executed */
9277#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9278 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9279 "you will need to reboot when done\n");
b1fb8740 9280 goto sp_rtnl_not_reset;
7be08a72 9281#endif
34f80b04 9282
7be08a72
AE
9283 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9284 /*
b1fb8740
VZ
9285 * Clear all pending SP commands as we are going to reset the
9286 * function anyway.
7be08a72 9287 */
b1fb8740
VZ
9288 bp->sp_rtnl_state = 0;
9289 smp_mb();
9290
72fd0718 9291 bnx2x_parity_recover(bp);
b1fb8740
VZ
9292
9293 goto sp_rtnl_exit;
9294 }
9295
9296 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9297 /*
9298 * Clear all pending SP commands as we are going to reset the
9299 * function anyway.
9300 */
9301 bp->sp_rtnl_state = 0;
9302 smp_mb();
9303
5d07d868 9304 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9305 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740
VZ
9306
9307 goto sp_rtnl_exit;
72fd0718 9308 }
b1fb8740
VZ
9309#ifdef BNX2X_STOP_ON_ERROR
9310sp_rtnl_not_reset:
9311#endif
9312 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9313 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9314 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9315 bnx2x_after_function_update(bp);
8304859a
AE
9316 /*
9317 * in case of fan failure we need to reset id if the "stop on error"
9318 * debug flag is set, since we trying to prevent permanent overheating
9319 * damage
9320 */
9321 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9322 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9323 netif_device_detach(bp->dev);
9324 bnx2x_close(bp->dev);
9325 }
9326
7be08a72 9327sp_rtnl_exit:
34f80b04
EG
9328 rtnl_unlock();
9329}
9330
a2fbb9ea
ET
9331/* end of nic load/unload */
9332
3deb8167
YR
9333static void bnx2x_period_task(struct work_struct *work)
9334{
9335 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9336
9337 if (!netif_running(bp->dev))
9338 goto period_task_exit;
9339
9340 if (CHIP_REV_IS_SLOW(bp)) {
9341 BNX2X_ERR("period task called on emulation, ignoring\n");
9342 goto period_task_exit;
9343 }
9344
9345 bnx2x_acquire_phy_lock(bp);
9346 /*
9347 * The barrier is needed to ensure the ordering between the writing to
9348 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9349 * the reading here.
9350 */
9351 smp_mb();
9352 if (bp->port.pmf) {
9353 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9354
9355 /* Re-queue task in 1 sec */
9356 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9357 }
9358
9359 bnx2x_release_phy_lock(bp);
9360period_task_exit:
9361 return;
9362}
9363
a2fbb9ea
ET
9364/*
9365 * Init service functions
9366 */
9367
8d96286a 9368static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9369{
9370 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9371 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9372 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9373}
9374
f2e0899f 9375static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
f1ef27ef 9376{
f2e0899f 9377 u32 reg = bnx2x_get_pretend_reg(bp);
f1ef27ef
EG
9378
9379 /* Flush all outstanding writes */
9380 mmiowb();
9381
9382 /* Pretend to be function 0 */
9383 REG_WR(bp, reg, 0);
f2e0899f 9384 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
f1ef27ef
EG
9385
9386 /* From now we are in the "like-E1" mode */
9387 bnx2x_int_disable(bp);
9388
9389 /* Flush all outstanding writes */
9390 mmiowb();
9391
f2e0899f
DK
9392 /* Restore the original function */
9393 REG_WR(bp, reg, BP_ABS_FUNC(bp));
9394 REG_RD(bp, reg);
f1ef27ef
EG
9395}
9396
f2e0899f 9397static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
f1ef27ef 9398{
f2e0899f 9399 if (CHIP_IS_E1(bp))
f1ef27ef 9400 bnx2x_int_disable(bp);
f2e0899f
DK
9401 else
9402 bnx2x_undi_int_disable_e1h(bp);
f1ef27ef
EG
9403}
9404
452427b0 9405static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
34f80b04 9406{
452427b0
YM
9407 u32 val, base_addr, offset, mask, reset_reg;
9408 bool mac_stopped = false;
9409 u8 port = BP_PORT(bp);
34f80b04 9410
452427b0 9411 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9412
452427b0
YM
9413 if (!CHIP_IS_E3(bp)) {
9414 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9415 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9416 if ((mask & reset_reg) && val) {
9417 u32 wb_data[2];
9418 BNX2X_DEV_INFO("Disable bmac Rx\n");
9419 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9420 : NIG_REG_INGRESS_BMAC0_MEM;
9421 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9422 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9423
452427b0
YM
9424 /*
9425 * use rd/wr since we cannot use dmae. This is safe
9426 * since MCP won't access the bus due to the request
9427 * to unload, and no function on the path can be
9428 * loaded at this time.
9429 */
9430 wb_data[0] = REG_RD(bp, base_addr + offset);
9431 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
9432 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
9433 REG_WR(bp, base_addr + offset, wb_data[0]);
9434 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
9435
9436 }
9437 BNX2X_DEV_INFO("Disable emac Rx\n");
9438 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
9439
9440 mac_stopped = true;
9441 } else {
9442 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9443 BNX2X_DEV_INFO("Disable xmac Rx\n");
9444 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9445 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9446 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9447 val & ~(1 << 1));
9448 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9449 val | (1 << 1));
9450 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
9451 mac_stopped = true;
9452 }
9453 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9454 if (mask & reset_reg) {
9455 BNX2X_DEV_INFO("Disable umac Rx\n");
9456 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9457 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
9458 mac_stopped = true;
9459 }
9460 }
9461
9462 if (mac_stopped)
9463 msleep(20);
9464
9465}
9466
9467#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9468#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9469#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9470#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9471
9472static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
9473 u8 inc)
9474{
9475 u16 rcq, bd;
9476 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9477
9478 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9479 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9480
9481 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9482 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9483
9484 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9485 port, bd, rcq);
9486}
9487
9488static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
9489{
5d07d868
YM
9490 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9491 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9492 if (!rc) {
9493 BNX2X_ERR("MCP response failure, aborting\n");
9494 return -EBUSY;
9495 }
9496
9497 return 0;
9498}
9499
9500static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
9501{
9502 struct bnx2x_prev_path_list *tmp_list;
9503 int rc = false;
9504
9505 if (down_trylock(&bnx2x_prev_sem))
9506 return false;
9507
9508 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9509 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9510 bp->pdev->bus->number == tmp_list->bus &&
9511 BP_PATH(bp) == tmp_list->path) {
9512 rc = true;
9513 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9514 BP_PATH(bp));
9515 break;
9516 }
9517 }
9518
9519 up(&bnx2x_prev_sem);
9520
9521 return rc;
9522}
9523
9524static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
9525{
9526 struct bnx2x_prev_path_list *tmp_list;
9527 int rc;
9528
ea4b3857 9529 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9530 if (!tmp_list) {
9531 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9532 return -ENOMEM;
9533 }
9534
9535 tmp_list->bus = bp->pdev->bus->number;
9536 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9537 tmp_list->path = BP_PATH(bp);
9538
9539 rc = down_interruptible(&bnx2x_prev_sem);
9540 if (rc) {
9541 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9542 kfree(tmp_list);
9543 } else {
9544 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9545 BP_PATH(bp));
9546 list_add(&tmp_list->list, &bnx2x_prev_list);
9547 up(&bnx2x_prev_sem);
9548 }
9549
9550 return rc;
9551}
9552
452427b0
YM
9553static int __devinit bnx2x_do_flr(struct bnx2x *bp)
9554{
2a80eebc 9555 int i;
452427b0
YM
9556 u16 status;
9557 struct pci_dev *dev = bp->pdev;
9558
8eee694c
YM
9559
9560 if (CHIP_IS_E1x(bp)) {
9561 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9562 return -EINVAL;
9563 }
9564
9565 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9566 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9567 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9568 bp->common.bc_ver);
9569 return -EINVAL;
9570 }
452427b0 9571
452427b0
YM
9572 /* Wait for Transaction Pending bit clean */
9573 for (i = 0; i < 4; i++) {
9574 if (i)
9575 msleep((1 << (i - 1)) * 100);
9576
2a80eebc 9577 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9578 if (!(status & PCI_EXP_DEVSTA_TRPND))
9579 goto clear;
9580 }
9581
9582 dev_err(&dev->dev,
9583 "transaction is not cleared; proceeding with reset anyway\n");
9584
9585clear:
452427b0 9586
8eee694c 9587 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9588 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9589
9590 return 0;
9591}
9592
9593static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
9594{
9595 int rc;
9596
9597 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9598
9599 /* Test if previous unload process was already finished for this path */
9600 if (bnx2x_prev_is_path_marked(bp))
9601 return bnx2x_prev_mcp_done(bp);
9602
9603 /* If function has FLR capabilities, and existing FW version matches
9604 * the one required, then FLR will be sufficient to clean any residue
9605 * left by previous driver
9606 */
8eee694c
YM
9607 rc = bnx2x_test_firmware_version(bp, false);
9608
9609 if (!rc) {
9610 /* fw version is good */
9611 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9612 rc = bnx2x_do_flr(bp);
9613 }
9614
9615 if (!rc) {
9616 /* FLR was performed */
9617 BNX2X_DEV_INFO("FLR successful\n");
9618 return 0;
9619 }
9620
9621 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9622
9623 /* Close the MCP request, return failure*/
9624 rc = bnx2x_prev_mcp_done(bp);
9625 if (!rc)
9626 rc = BNX2X_PREV_WAIT_NEEDED;
9627
9628 return rc;
9629}
9630
9631static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
9632{
9633 u32 reset_reg, tmp_reg = 0, rc;
9634 /* It is possible a previous function received 'common' answer,
9635 * but hasn't loaded yet, therefore creating a scenario of
9636 * multiple functions receiving 'common' on the same path.
9637 */
9638 BNX2X_DEV_INFO("Common unload Flow\n");
9639
9640 if (bnx2x_prev_is_path_marked(bp))
9641 return bnx2x_prev_mcp_done(bp);
9642
9643 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9644
9645 /* Reset should be performed after BRB is emptied */
9646 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9647 u32 timer_count = 1000;
9648 bool prev_undi = false;
9649
9650 /* Close the MAC Rx to prevent BRB from filling up */
9651 bnx2x_prev_unload_close_mac(bp);
9652
9653 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9654 * UNDI driver initializes CID offset for normal bell to 0x7
9655 */
452427b0
YM
9656 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9657 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9658 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9659 if (tmp_reg == 0x7) {
9660 BNX2X_DEV_INFO("UNDI previously loaded\n");
9661 prev_undi = true;
9662 /* clear the UNDI indication */
9663 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
34f80b04 9664 }
452427b0
YM
9665 }
9666 /* wait until BRB is empty */
9667 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9668 while (timer_count) {
9669 u32 prev_brb = tmp_reg;
34f80b04 9670
452427b0
YM
9671 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9672 if (!tmp_reg)
9673 break;
619c5cb6 9674
452427b0 9675 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9676
452427b0
YM
9677 /* reset timer as long as BRB actually gets emptied */
9678 if (prev_brb > tmp_reg)
9679 timer_count = 1000;
9680 else
9681 timer_count--;
da5a662a 9682
452427b0
YM
9683 /* If UNDI resides in memory, manually increment it */
9684 if (prev_undi)
9685 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9686
452427b0 9687 udelay(10);
7a06a122 9688 }
452427b0
YM
9689
9690 if (!timer_count)
9691 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9692
34f80b04 9693 }
f16da43b 9694
452427b0
YM
9695 /* No packets are in the pipeline, path is ready for reset */
9696 bnx2x_reset_common(bp);
9697
9698 rc = bnx2x_prev_mark_path(bp);
9699 if (rc) {
9700 bnx2x_prev_mcp_done(bp);
9701 return rc;
9702 }
9703
9704 return bnx2x_prev_mcp_done(bp);
9705}
9706
24f06716
AE
9707/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9708 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9709 * the addresses of the transaction, resulting in was-error bit set in the pci
9710 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9711 * to clear the interrupt which detected this from the pglueb and the was done
9712 * bit
9713 */
9714static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
9715{
4a25417c
AE
9716 if (!CHIP_IS_E1x(bp)) {
9717 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9718 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9719 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9720 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9721 1 << BP_FUNC(bp));
9722 }
24f06716
AE
9723 }
9724}
9725
452427b0
YM
9726static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9727{
9728 int time_counter = 10;
9729 u32 rc, fw, hw_lock_reg, hw_lock_val;
9730 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9731
24f06716
AE
9732 /* clear hw from errors which may have resulted from an interrupted
9733 * dmae transaction.
9734 */
9735 bnx2x_prev_interrupted_dmae(bp);
9736
9737 /* Release previously held locks */
452427b0
YM
9738 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9739 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9740 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9741
9742 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9743 if (hw_lock_val) {
9744 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9745 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9746 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9747 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9748 }
9749
9750 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9751 REG_WR(bp, hw_lock_reg, 0xffffffff);
9752 } else
9753 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9754
9755 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9756 BNX2X_DEV_INFO("Release previously held alr\n");
9757 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9758 }
9759
9760
9761 do {
9762 /* Lock MCP using an unload request */
9763 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9764 if (!fw) {
9765 BNX2X_ERR("MCP response failure, aborting\n");
9766 rc = -EBUSY;
9767 break;
9768 }
9769
9770 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9771 rc = bnx2x_prev_unload_common(bp);
9772 break;
9773 }
9774
9775 /* non-common reply from MCP night require looping */
9776 rc = bnx2x_prev_unload_uncommon(bp);
9777 if (rc != BNX2X_PREV_WAIT_NEEDED)
9778 break;
9779
9780 msleep(20);
9781 } while (--time_counter);
9782
9783 if (!time_counter || rc) {
9784 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9785 rc = -EBUSY;
9786 }
9787
9788 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9789
9790 return rc;
34f80b04
EG
9791}
9792
9793static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9794{
1d187b34 9795 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 9796 u16 pmc;
34f80b04
EG
9797
9798 /* Get the chip revision id and number. */
9799 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9800 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9801 id = ((val & 0xffff) << 16);
9802 val = REG_RD(bp, MISC_REG_CHIP_REV);
9803 id |= ((val & 0xf) << 12);
9804 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9805 id |= ((val & 0xff) << 4);
5a40e08e 9806 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
9807 id |= (val & 0xf);
9808 bp->common.chip_id = id;
523224a3 9809
7e8e02df
BW
9810 /* force 57811 according to MISC register */
9811 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
9812 if (CHIP_IS_57810(bp))
9813 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
9814 (bp->common.chip_id & 0x0000FFFF);
9815 else if (CHIP_IS_57810_MF(bp))
9816 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
9817 (bp->common.chip_id & 0x0000FFFF);
9818 bp->common.chip_id |= 0x1;
9819 }
9820
523224a3
DK
9821 /* Set doorbell size */
9822 bp->db_size = (1 << BNX2X_DB_SHIFT);
9823
619c5cb6 9824 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
9825 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9826 if ((val & 1) == 0)
9827 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9828 else
9829 val = (val >> 1) & 1;
9830 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9831 "2_PORT_MODE");
9832 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9833 CHIP_2_PORT_MODE;
9834
9835 if (CHIP_MODE_IS_4_PORT(bp))
9836 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9837 else
9838 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9839 } else {
9840 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9841 bp->pfid = bp->pf_num; /* 0..7 */
9842 }
9843
51c1a580
MS
9844 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9845
f2e0899f
DK
9846 bp->link_params.chip_id = bp->common.chip_id;
9847 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 9848
1c06328c
EG
9849 val = (REG_RD(bp, 0x2874) & 0x55);
9850 if ((bp->common.chip_id & 0x1) ||
9851 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9852 bp->flags |= ONE_PORT_FLAG;
9853 BNX2X_DEV_INFO("single port device\n");
9854 }
9855
34f80b04 9856 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 9857 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
9858 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9859 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9860 bp->common.flash_size, bp->common.flash_size);
9861
1b6e2ceb
DK
9862 bnx2x_init_shmem(bp);
9863
619c5cb6
VZ
9864
9865
f2e0899f
DK
9866 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9867 MISC_REG_GENERIC_CR_1 :
9868 MISC_REG_GENERIC_CR_0));
1b6e2ceb 9869
34f80b04 9870 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 9871 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
9872 if (SHMEM2_RD(bp, size) >
9873 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
9874 bp->link_params.lfa_base =
9875 REG_RD(bp, bp->common.shmem2_base +
9876 (u32)offsetof(struct shmem2_region,
9877 lfa_host_addr[BP_PORT(bp)]));
9878 else
9879 bp->link_params.lfa_base = 0;
2691d51d
EG
9880 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9881 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 9882
f2e0899f 9883 if (!bp->common.shmem_base) {
34f80b04
EG
9884 BNX2X_DEV_INFO("MCP not active\n");
9885 bp->flags |= NO_MCP_FLAG;
9886 return;
9887 }
9888
34f80b04 9889 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 9890 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
9891
9892 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9893 SHARED_HW_CFG_LED_MODE_MASK) >>
9894 SHARED_HW_CFG_LED_MODE_SHIFT);
9895
c2c8b03e
EG
9896 bp->link_params.feature_config_flags = 0;
9897 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9898 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9899 bp->link_params.feature_config_flags |=
9900 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9901 else
9902 bp->link_params.feature_config_flags &=
9903 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9904
34f80b04
EG
9905 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9906 bp->common.bc_ver = val;
9907 BNX2X_DEV_INFO("bc_ver %X\n", val);
9908 if (val < BNX2X_BC_VER) {
9909 /* for now only warn
9910 * later we might need to enforce this */
51c1a580
MS
9911 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9912 BNX2X_BC_VER, val);
34f80b04 9913 }
4d295db0 9914 bp->link_params.feature_config_flags |=
a22f0788 9915 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
9916 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9917
a22f0788
YR
9918 bp->link_params.feature_config_flags |=
9919 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9920 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
9921 bp->link_params.feature_config_flags |=
9922 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
9923 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
9924 bp->link_params.feature_config_flags |=
9925 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9926 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
9927
9928 bp->link_params.feature_config_flags |=
9929 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
9930 FEATURE_CONFIG_MT_SUPPORT : 0;
9931
0e898dd7
BW
9932 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9933 BC_SUPPORTS_PFC_STATS : 0;
85242eea 9934
2e499d3c
BW
9935 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
9936 BC_SUPPORTS_FCOE_FEATURES : 0;
9937
9876879f
BW
9938 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
9939 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
9940 boot_mode = SHMEM_RD(bp,
9941 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9942 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9943 switch (boot_mode) {
9944 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9945 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9946 break;
9947 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9948 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9949 break;
9950 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9951 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9952 break;
9953 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9954 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9955 break;
9956 }
9957
f9a3ebbe
DK
9958 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9959 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9960
72ce58c3 9961 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 9962 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
9963
9964 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9965 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9966 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9967 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9968
cdaa7cb8
VZ
9969 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9970 val, val2, val3, val4);
34f80b04
EG
9971}
9972
f2e0899f
DK
9973#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9974#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9975
9b341bb1 9976static int __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
9977{
9978 int pfid = BP_FUNC(bp);
f2e0899f
DK
9979 int igu_sb_id;
9980 u32 val;
6383c0b3 9981 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
9982
9983 bp->igu_base_sb = 0xff;
f2e0899f 9984 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 9985 int vn = BP_VN(bp);
6383c0b3 9986 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
9987 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9988 FP_SB_MAX_E1x;
9989
9990 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9991 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9992
9b341bb1 9993 return 0;
f2e0899f
DK
9994 }
9995
9996 /* IGU in normal mode - read CAM */
9997 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9998 igu_sb_id++) {
9999 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10000 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10001 continue;
10002 fid = IGU_FID(val);
10003 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10004 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10005 continue;
10006 if (IGU_VEC(val) == 0)
10007 /* default status block */
10008 bp->igu_dsb_id = igu_sb_id;
10009 else {
10010 if (bp->igu_base_sb == 0xff)
10011 bp->igu_base_sb = igu_sb_id;
6383c0b3 10012 igu_sb_cnt++;
f2e0899f
DK
10013 }
10014 }
10015 }
619c5cb6 10016
6383c0b3 10017#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10018 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10019 * optional that number of CAM entries will not be equal to the value
10020 * advertised in PCI.
10021 * Driver should use the minimal value of both as the actual status
10022 * block count
619c5cb6 10023 */
185d4c8b 10024 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10025#endif
619c5cb6 10026
9b341bb1 10027 if (igu_sb_cnt == 0) {
f2e0899f 10028 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10029 return -EINVAL;
10030 }
10031
10032 return 0;
f2e0899f
DK
10033}
10034
34f80b04
EG
10035static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
10036 u32 switch_cfg)
a2fbb9ea 10037{
a22f0788
YR
10038 int cfg_size = 0, idx, port = BP_PORT(bp);
10039
10040 /* Aggregation of supported attributes of all external phys */
10041 bp->port.supported[0] = 0;
10042 bp->port.supported[1] = 0;
b7737c9b
YR
10043 switch (bp->link_params.num_phys) {
10044 case 1:
a22f0788
YR
10045 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10046 cfg_size = 1;
10047 break;
b7737c9b 10048 case 2:
a22f0788
YR
10049 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10050 cfg_size = 1;
10051 break;
10052 case 3:
10053 if (bp->link_params.multi_phy_config &
10054 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10055 bp->port.supported[1] =
10056 bp->link_params.phy[EXT_PHY1].supported;
10057 bp->port.supported[0] =
10058 bp->link_params.phy[EXT_PHY2].supported;
10059 } else {
10060 bp->port.supported[0] =
10061 bp->link_params.phy[EXT_PHY1].supported;
10062 bp->port.supported[1] =
10063 bp->link_params.phy[EXT_PHY2].supported;
10064 }
10065 cfg_size = 2;
10066 break;
b7737c9b 10067 }
a2fbb9ea 10068
a22f0788 10069 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10070 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10071 SHMEM_RD(bp,
a22f0788
YR
10072 dev_info.port_hw_config[port].external_phy_config),
10073 SHMEM_RD(bp,
10074 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10075 return;
f85582f8 10076 }
a2fbb9ea 10077
619c5cb6
VZ
10078 if (CHIP_IS_E3(bp))
10079 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10080 else {
10081 switch (switch_cfg) {
10082 case SWITCH_CFG_1G:
10083 bp->port.phy_addr = REG_RD(
10084 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10085 break;
10086 case SWITCH_CFG_10G:
10087 bp->port.phy_addr = REG_RD(
10088 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10089 break;
10090 default:
10091 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10092 bp->port.link_config[0]);
10093 return;
10094 }
a2fbb9ea 10095 }
619c5cb6 10096 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10097 /* mask what we support according to speed_cap_mask per configuration */
10098 for (idx = 0; idx < cfg_size; idx++) {
10099 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10100 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10101 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10102
a22f0788 10103 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10104 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10105 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10106
a22f0788 10107 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10108 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10109 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10110
a22f0788 10111 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10112 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10113 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10114
a22f0788 10115 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10116 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10117 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10118 SUPPORTED_1000baseT_Full);
a2fbb9ea 10119
a22f0788 10120 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10121 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10122 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10123
a22f0788 10124 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10125 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
10126 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10127
10128 }
a2fbb9ea 10129
a22f0788
YR
10130 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10131 bp->port.supported[1]);
a2fbb9ea
ET
10132}
10133
34f80b04 10134static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10135{
a22f0788
YR
10136 u32 link_config, idx, cfg_size = 0;
10137 bp->port.advertising[0] = 0;
10138 bp->port.advertising[1] = 0;
10139 switch (bp->link_params.num_phys) {
10140 case 1:
10141 case 2:
10142 cfg_size = 1;
10143 break;
10144 case 3:
10145 cfg_size = 2;
10146 break;
10147 }
10148 for (idx = 0; idx < cfg_size; idx++) {
10149 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10150 link_config = bp->port.link_config[idx];
10151 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10152 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10153 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10154 bp->link_params.req_line_speed[idx] =
10155 SPEED_AUTO_NEG;
10156 bp->port.advertising[idx] |=
10157 bp->port.supported[idx];
10bd1f24
MY
10158 if (bp->link_params.phy[EXT_PHY1].type ==
10159 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10160 bp->port.advertising[idx] |=
10161 (SUPPORTED_100baseT_Half |
10162 SUPPORTED_100baseT_Full);
f85582f8
DK
10163 } else {
10164 /* force 10G, no AN */
a22f0788
YR
10165 bp->link_params.req_line_speed[idx] =
10166 SPEED_10000;
10167 bp->port.advertising[idx] |=
10168 (ADVERTISED_10000baseT_Full |
f85582f8 10169 ADVERTISED_FIBRE);
a22f0788 10170 continue;
f85582f8
DK
10171 }
10172 break;
a2fbb9ea 10173
f85582f8 10174 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10175 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10176 bp->link_params.req_line_speed[idx] =
10177 SPEED_10;
10178 bp->port.advertising[idx] |=
10179 (ADVERTISED_10baseT_Full |
f85582f8
DK
10180 ADVERTISED_TP);
10181 } else {
51c1a580 10182 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10183 link_config,
a22f0788 10184 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10185 return;
10186 }
10187 break;
a2fbb9ea 10188
f85582f8 10189 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10190 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10191 bp->link_params.req_line_speed[idx] =
10192 SPEED_10;
10193 bp->link_params.req_duplex[idx] =
10194 DUPLEX_HALF;
10195 bp->port.advertising[idx] |=
10196 (ADVERTISED_10baseT_Half |
f85582f8
DK
10197 ADVERTISED_TP);
10198 } else {
51c1a580 10199 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10200 link_config,
10201 bp->link_params.speed_cap_mask[idx]);
10202 return;
10203 }
10204 break;
a2fbb9ea 10205
f85582f8
DK
10206 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10207 if (bp->port.supported[idx] &
10208 SUPPORTED_100baseT_Full) {
a22f0788
YR
10209 bp->link_params.req_line_speed[idx] =
10210 SPEED_100;
10211 bp->port.advertising[idx] |=
10212 (ADVERTISED_100baseT_Full |
f85582f8
DK
10213 ADVERTISED_TP);
10214 } else {
51c1a580 10215 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10216 link_config,
10217 bp->link_params.speed_cap_mask[idx]);
10218 return;
10219 }
10220 break;
a2fbb9ea 10221
f85582f8
DK
10222 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10223 if (bp->port.supported[idx] &
10224 SUPPORTED_100baseT_Half) {
10225 bp->link_params.req_line_speed[idx] =
10226 SPEED_100;
10227 bp->link_params.req_duplex[idx] =
10228 DUPLEX_HALF;
a22f0788
YR
10229 bp->port.advertising[idx] |=
10230 (ADVERTISED_100baseT_Half |
f85582f8
DK
10231 ADVERTISED_TP);
10232 } else {
51c1a580 10233 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10234 link_config,
10235 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10236 return;
10237 }
10238 break;
a2fbb9ea 10239
f85582f8 10240 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10241 if (bp->port.supported[idx] &
10242 SUPPORTED_1000baseT_Full) {
10243 bp->link_params.req_line_speed[idx] =
10244 SPEED_1000;
10245 bp->port.advertising[idx] |=
10246 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10247 ADVERTISED_TP);
10248 } else {
51c1a580 10249 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10250 link_config,
10251 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10252 return;
10253 }
10254 break;
a2fbb9ea 10255
f85582f8 10256 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10257 if (bp->port.supported[idx] &
10258 SUPPORTED_2500baseX_Full) {
10259 bp->link_params.req_line_speed[idx] =
10260 SPEED_2500;
10261 bp->port.advertising[idx] |=
10262 (ADVERTISED_2500baseX_Full |
34f80b04 10263 ADVERTISED_TP);
f85582f8 10264 } else {
51c1a580 10265 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10266 link_config,
f85582f8
DK
10267 bp->link_params.speed_cap_mask[idx]);
10268 return;
10269 }
10270 break;
a2fbb9ea 10271
f85582f8 10272 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10273 if (bp->port.supported[idx] &
10274 SUPPORTED_10000baseT_Full) {
10275 bp->link_params.req_line_speed[idx] =
10276 SPEED_10000;
10277 bp->port.advertising[idx] |=
10278 (ADVERTISED_10000baseT_Full |
34f80b04 10279 ADVERTISED_FIBRE);
f85582f8 10280 } else {
51c1a580 10281 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10282 link_config,
f85582f8
DK
10283 bp->link_params.speed_cap_mask[idx]);
10284 return;
10285 }
10286 break;
3c9ada22
YR
10287 case PORT_FEATURE_LINK_SPEED_20G:
10288 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10289
3c9ada22 10290 break;
f85582f8 10291 default:
51c1a580 10292 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10293 link_config);
f85582f8
DK
10294 bp->link_params.req_line_speed[idx] =
10295 SPEED_AUTO_NEG;
10296 bp->port.advertising[idx] =
10297 bp->port.supported[idx];
10298 break;
10299 }
a2fbb9ea 10300
a22f0788 10301 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10302 PORT_FEATURE_FLOW_CONTROL_MASK);
a22f0788
YR
10303 if ((bp->link_params.req_flow_ctrl[idx] ==
10304 BNX2X_FLOW_CTRL_AUTO) &&
10305 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
10306 bp->link_params.req_flow_ctrl[idx] =
10307 BNX2X_FLOW_CTRL_NONE;
10308 }
a2fbb9ea 10309
51c1a580 10310 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10311 bp->link_params.req_line_speed[idx],
10312 bp->link_params.req_duplex[idx],
10313 bp->link_params.req_flow_ctrl[idx],
10314 bp->port.advertising[idx]);
10315 }
a2fbb9ea
ET
10316}
10317
e665bfda
MC
10318static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
10319{
10320 mac_hi = cpu_to_be16(mac_hi);
10321 mac_lo = cpu_to_be32(mac_lo);
10322 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
10323 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
10324}
10325
34f80b04 10326static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10327{
34f80b04 10328 int port = BP_PORT(bp);
589abe3a 10329 u32 config;
c8c60d88 10330 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10331
c18487ee 10332 bp->link_params.bp = bp;
34f80b04 10333 bp->link_params.port = port;
c18487ee 10334
c18487ee 10335 bp->link_params.lane_config =
a2fbb9ea 10336 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10337
a22f0788 10338 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
10339 SHMEM_RD(bp,
10340 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
10341 bp->link_params.speed_cap_mask[1] =
10342 SHMEM_RD(bp,
10343 dev_info.port_hw_config[port].speed_capability_mask2);
10344 bp->port.link_config[0] =
a2fbb9ea
ET
10345 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10346
a22f0788
YR
10347 bp->port.link_config[1] =
10348 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10349
a22f0788
YR
10350 bp->link_params.multi_phy_config =
10351 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10352 /* If the device is capable of WoL, set the default state according
10353 * to the HW
10354 */
4d295db0 10355 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10356 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10357 (config & PORT_FEATURE_WOL_ENABLED));
10358
51c1a580 10359 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10360 bp->link_params.lane_config,
a22f0788
YR
10361 bp->link_params.speed_cap_mask[0],
10362 bp->port.link_config[0]);
a2fbb9ea 10363
a22f0788 10364 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10365 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10366 bnx2x_phy_probe(&bp->link_params);
c18487ee 10367 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10368
10369 bnx2x_link_settings_requested(bp);
10370
01cd4528
EG
10371 /*
10372 * If connected directly, work with the internal PHY, otherwise, work
10373 * with the external PHY
10374 */
b7737c9b
YR
10375 ext_phy_config =
10376 SHMEM_RD(bp,
10377 dev_info.port_hw_config[port].external_phy_config);
10378 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10379 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10380 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10381
10382 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10383 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10384 bp->mdio.prtad =
b7737c9b 10385 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10386
c8c60d88
YM
10387 /* Configure link feature according to nvram value */
10388 eee_mode = (((SHMEM_RD(bp, dev_info.
10389 port_feature_config[port].eee_power_mode)) &
10390 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10391 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10392 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10393 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10394 EEE_MODE_ENABLE_LPI |
10395 EEE_MODE_OUTPUT_TIME;
10396 } else {
10397 bp->link_params.eee_mode = 0;
10398 }
0793f83f 10399}
01cd4528 10400
b306f5ed 10401void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10402{
9e62e912 10403 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10404 int port = BP_PORT(bp);
2ba45142 10405 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10406 drv_lic_key[port].max_iscsi_conn);
2ba45142 10407
55c11941
MS
10408 if (!CNIC_SUPPORT(bp)) {
10409 bp->flags |= no_flags;
10410 return;
10411 }
10412
b306f5ed 10413 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10414 bp->cnic_eth_dev.max_iscsi_conn =
10415 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10416 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10417
b306f5ed
DK
10418 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10419 bp->cnic_eth_dev.max_iscsi_conn);
10420
10421 /*
10422 * If maximum allowed number of connections is zero -
10423 * disable the feature.
10424 */
10425 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10426 bp->flags |= no_flags;
55c11941 10427
b306f5ed
DK
10428}
10429
9e62e912
DK
10430static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
10431{
10432 /* Port info */
10433 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10434 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10435 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10436 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10437
10438 /* Node info */
10439 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10440 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10441 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10442 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10443}
b306f5ed
DK
10444static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
10445{
10446 int port = BP_PORT(bp);
10447 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10448 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10449 drv_lic_key[port].max_fcoe_conn);
10450
55c11941
MS
10451 if (!CNIC_SUPPORT(bp)) {
10452 bp->flags |= NO_FCOE_FLAG;
10453 return;
10454 }
10455
b306f5ed 10456 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10457 bp->cnic_eth_dev.max_fcoe_conn =
10458 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10459 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10460
bf61ee14
VZ
10461 /* Read the WWN: */
10462 if (!IS_MF(bp)) {
10463 /* Port info */
10464 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10465 SHMEM_RD(bp,
10466 dev_info.port_hw_config[port].
10467 fcoe_wwn_port_name_upper);
10468 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10469 SHMEM_RD(bp,
10470 dev_info.port_hw_config[port].
10471 fcoe_wwn_port_name_lower);
10472
10473 /* Node info */
10474 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10475 SHMEM_RD(bp,
10476 dev_info.port_hw_config[port].
10477 fcoe_wwn_node_name_upper);
10478 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10479 SHMEM_RD(bp,
10480 dev_info.port_hw_config[port].
10481 fcoe_wwn_node_name_lower);
10482 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10483 /*
10484 * Read the WWN info only if the FCoE feature is enabled for
10485 * this function.
10486 */
7b5342d9 10487 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10488 bnx2x_get_ext_wwn_info(bp, func);
10489
382e513a 10490 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 10491 bnx2x_get_ext_wwn_info(bp, func);
382e513a 10492 }
bf61ee14 10493
b306f5ed 10494 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10495
bf61ee14
VZ
10496 /*
10497 * If maximum allowed number of connections is zero -
2ba45142
VZ
10498 * disable the feature.
10499 */
2ba45142
VZ
10500 if (!bp->cnic_eth_dev.max_fcoe_conn)
10501 bp->flags |= NO_FCOE_FLAG;
10502}
b306f5ed
DK
10503
10504static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
10505{
10506 /*
10507 * iSCSI may be dynamically disabled but reading
10508 * info here we will decrease memory usage by driver
10509 * if the feature is disabled for good
10510 */
10511 bnx2x_get_iscsi_info(bp);
10512 bnx2x_get_fcoe_info(bp);
10513}
2ba45142 10514
55c11941 10515static void __devinit bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10516{
10517 u32 val, val2;
10518 int func = BP_ABS_FUNC(bp);
10519 int port = BP_PORT(bp);
2ba45142
VZ
10520 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10521 u8 *fip_mac = bp->fip_mac;
0793f83f 10522
55c11941
MS
10523 if (IS_MF(bp)) {
10524 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10525 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10526 * In non SD mode features configuration comes from struct
10527 * func_ext_config.
2ba45142 10528 */
55c11941 10529 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10530 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10531 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10532 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10533 iscsi_mac_addr_upper);
0793f83f 10534 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10535 iscsi_mac_addr_lower);
2ba45142 10536 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10537 BNX2X_DEV_INFO
10538 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10539 } else {
2ba45142 10540 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10541 }
2ba45142
VZ
10542
10543 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10544 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10545 fcoe_mac_addr_upper);
2ba45142 10546 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10547 fcoe_mac_addr_lower);
2ba45142 10548 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10549 BNX2X_DEV_INFO
10550 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10551 } else {
2ba45142 10552 bp->flags |= NO_FCOE_FLAG;
55c11941 10553 }
a3348722
BW
10554
10555 bp->mf_ext_config = cfg;
10556
9e62e912 10557 } else { /* SD MODE */
55c11941
MS
10558 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10559 /* use primary mac as iscsi mac */
10560 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10561
10562 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10563 BNX2X_DEV_INFO
10564 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10565 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10566 /* use primary mac as fip mac */
10567 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10568 BNX2X_DEV_INFO("SD FCoE MODE\n");
10569 BNX2X_DEV_INFO
10570 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10571 }
0793f83f 10572 }
a3348722 10573
55c11941
MS
10574 if (IS_MF_STORAGE_SD(bp))
10575 /* Zero primary MAC configuration */
10576 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10577
a3348722
BW
10578 if (IS_MF_FCOE_AFEX(bp))
10579 /* use FIP MAC as primary MAC */
10580 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10581
0793f83f 10582 } else {
0793f83f 10583 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10584 iscsi_mac_upper);
0793f83f 10585 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10586 iscsi_mac_lower);
2ba45142 10587 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10588
10589 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10590 fcoe_fip_mac_upper);
c03bd39c 10591 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10592 fcoe_fip_mac_lower);
c03bd39c 10593 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10594 }
10595
55c11941 10596 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10597 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10598 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10599 memset(iscsi_mac, 0, ETH_ALEN);
10600 }
10601
55c11941 10602 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10603 if (!is_valid_ether_addr(fip_mac)) {
10604 bp->flags |= NO_FCOE_FLAG;
10605 memset(bp->fip_mac, 0, ETH_ALEN);
10606 }
55c11941
MS
10607}
10608
10609static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
10610{
10611 u32 val, val2;
10612 int func = BP_ABS_FUNC(bp);
10613 int port = BP_PORT(bp);
10614
10615 /* Zero primary MAC configuration */
10616 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10617
10618 if (BP_NOMCP(bp)) {
10619 BNX2X_ERROR("warning: random MAC workaround active\n");
10620 eth_hw_addr_random(bp->dev);
10621 } else if (IS_MF(bp)) {
10622 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10623 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10624 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10625 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10626 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10627
10628 if (CNIC_SUPPORT(bp))
10629 bnx2x_get_cnic_mac_hwinfo(bp);
10630 } else {
10631 /* in SF read MACs from port configuration */
10632 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10633 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10634 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10635
10636 if (CNIC_SUPPORT(bp))
10637 bnx2x_get_cnic_mac_hwinfo(bp);
10638 }
10639
10640 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
10641 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10642
614c76df 10643 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10644 dev_err(&bp->pdev->dev,
51c1a580
MS
10645 "bad Ethernet MAC address configuration: %pM\n"
10646 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10647 bp->dev->dev_addr);
7964211d 10648}
51c1a580 10649
7964211d
YM
10650static bool __devinit bnx2x_get_dropless_info(struct bnx2x *bp)
10651{
10652 int tmp;
10653 u32 cfg;
51c1a580 10654
7964211d
YM
10655 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
10656 /* Take function: tmp = func */
10657 tmp = BP_ABS_FUNC(bp);
10658 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
10659 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
10660 } else {
10661 /* Take port: tmp = port */
10662 tmp = BP_PORT(bp);
10663 cfg = SHMEM_RD(bp,
10664 dev_info.port_hw_config[tmp].generic_features);
10665 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
10666 }
10667 return cfg;
34f80b04
EG
10668}
10669
10670static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
10671{
0793f83f 10672 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 10673 int vn;
0793f83f 10674 u32 val = 0;
34f80b04 10675 int rc = 0;
a2fbb9ea 10676
34f80b04 10677 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 10678
6383c0b3
AE
10679 /*
10680 * initialize IGU parameters
10681 */
f2e0899f
DK
10682 if (CHIP_IS_E1x(bp)) {
10683 bp->common.int_block = INT_BLOCK_HC;
10684
10685 bp->igu_dsb_id = DEF_SB_IGU_ID;
10686 bp->igu_base_sb = 0;
f2e0899f
DK
10687 } else {
10688 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
10689
10690 /* do not allow device reset during IGU info preocessing */
10691 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10692
f2e0899f 10693 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
10694
10695 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10696 int tout = 5000;
10697
10698 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10699
10700 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10701 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10702 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10703
10704 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10705 tout--;
10706 usleep_range(1000, 1000);
10707 }
10708
10709 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10710 dev_err(&bp->pdev->dev,
10711 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
10712 bnx2x_release_hw_lock(bp,
10713 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
10714 return -EPERM;
10715 }
10716 }
10717
f2e0899f 10718 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 10719 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
10720 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10721 } else
619c5cb6 10722 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 10723
9b341bb1 10724 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 10725 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
10726 if (rc)
10727 return rc;
f2e0899f 10728 }
619c5cb6
VZ
10729
10730 /*
10731 * set base FW non-default (fast path) status block id, this value is
10732 * used to initialize the fw_sb_id saved on the fp/queue structure to
10733 * determine the id used by the FW.
10734 */
10735 if (CHIP_IS_E1x(bp))
10736 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10737 else /*
10738 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10739 * the same queue are indicated on the same IGU SB). So we prefer
10740 * FW and IGU SBs to be the same value.
10741 */
10742 bp->base_fw_ndsb = bp->igu_base_sb;
10743
10744 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10745 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10746 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
10747
10748 /*
10749 * Initialize MF configuration
10750 */
523224a3 10751
fb3bff17
DK
10752 bp->mf_ov = 0;
10753 bp->mf_mode = 0;
3395a033 10754 vn = BP_VN(bp);
0793f83f 10755
f2e0899f 10756 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
10757 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10758 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10759 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10760
f2e0899f
DK
10761 if (SHMEM2_HAS(bp, mf_cfg_addr))
10762 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10763 else
10764 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
10765 offsetof(struct shmem_region, func_mb) +
10766 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
10767 /*
10768 * get mf configuration:
25985edc 10769 * 1. existence of MF configuration
0793f83f
DK
10770 * 2. MAC address must be legal (check only upper bytes)
10771 * for Switch-Independent mode;
10772 * OVLAN must be legal for Switch-Dependent mode
10773 * 3. SF_MODE configures specific MF mode
10774 */
10775 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10776 /* get mf configuration */
10777 val = SHMEM_RD(bp,
10778 dev_info.shared_feature_config.config);
10779 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10780
10781 switch (val) {
10782 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10783 val = MF_CFG_RD(bp, func_mf_config[func].
10784 mac_upper);
10785 /* check for legal mac (upper bytes)*/
10786 if (val != 0xffff) {
10787 bp->mf_mode = MULTI_FUNCTION_SI;
10788 bp->mf_config[vn] = MF_CFG_RD(bp,
10789 func_mf_config[func].config);
10790 } else
51c1a580 10791 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 10792 break;
a3348722
BW
10793 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
10794 if ((!CHIP_IS_E1x(bp)) &&
10795 (MF_CFG_RD(bp, func_mf_config[func].
10796 mac_upper) != 0xffff) &&
10797 (SHMEM2_HAS(bp,
10798 afex_driver_support))) {
10799 bp->mf_mode = MULTI_FUNCTION_AFEX;
10800 bp->mf_config[vn] = MF_CFG_RD(bp,
10801 func_mf_config[func].config);
10802 } else {
10803 BNX2X_DEV_INFO("can not configure afex mode\n");
10804 }
10805 break;
0793f83f
DK
10806 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10807 /* get OV configuration */
10808 val = MF_CFG_RD(bp,
10809 func_mf_config[FUNC_0].e1hov_tag);
10810 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10811
10812 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10813 bp->mf_mode = MULTI_FUNCTION_SD;
10814 bp->mf_config[vn] = MF_CFG_RD(bp,
10815 func_mf_config[func].config);
10816 } else
754a2f52 10817 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
10818 break;
10819 default:
10820 /* Unknown configuration: reset mf_config */
10821 bp->mf_config[vn] = 0;
51c1a580 10822 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
10823 }
10824 }
a2fbb9ea 10825
2691d51d 10826 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 10827 IS_MF(bp) ? "multi" : "single");
2691d51d 10828
0793f83f
DK
10829 switch (bp->mf_mode) {
10830 case MULTI_FUNCTION_SD:
10831 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10832 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 10833 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 10834 bp->mf_ov = val;
619c5cb6
VZ
10835 bp->path_has_ovlan = true;
10836
51c1a580
MS
10837 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10838 func, bp->mf_ov, bp->mf_ov);
2691d51d 10839 } else {
619c5cb6 10840 dev_err(&bp->pdev->dev,
51c1a580
MS
10841 "No valid MF OV for func %d, aborting\n",
10842 func);
619c5cb6 10843 return -EPERM;
34f80b04 10844 }
0793f83f 10845 break;
a3348722
BW
10846 case MULTI_FUNCTION_AFEX:
10847 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
10848 break;
0793f83f 10849 case MULTI_FUNCTION_SI:
51c1a580
MS
10850 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10851 func);
0793f83f
DK
10852 break;
10853 default:
10854 if (vn) {
619c5cb6 10855 dev_err(&bp->pdev->dev,
51c1a580
MS
10856 "VN %d is in a single function mode, aborting\n",
10857 vn);
619c5cb6 10858 return -EPERM;
2691d51d 10859 }
0793f83f 10860 break;
34f80b04 10861 }
0793f83f 10862
619c5cb6
VZ
10863 /* check if other port on the path needs ovlan:
10864 * Since MF configuration is shared between ports
10865 * Possible mixed modes are only
10866 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10867 */
10868 if (CHIP_MODE_IS_4_PORT(bp) &&
10869 !bp->path_has_ovlan &&
10870 !IS_MF(bp) &&
10871 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10872 u8 other_port = !BP_PORT(bp);
10873 u8 other_func = BP_PATH(bp) + 2*other_port;
10874 val = MF_CFG_RD(bp,
10875 func_mf_config[other_func].e1hov_tag);
10876 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10877 bp->path_has_ovlan = true;
10878 }
34f80b04 10879 }
a2fbb9ea 10880
f2e0899f
DK
10881 /* adjust igu_sb_cnt to MF for E1x */
10882 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
10883 bp->igu_sb_cnt /= E1HVN_MAX;
10884
619c5cb6
VZ
10885 /* port info */
10886 bnx2x_get_port_hwinfo(bp);
f2e0899f 10887
0793f83f
DK
10888 /* Get MAC addresses */
10889 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 10890
2ba45142 10891 bnx2x_get_cnic_info(bp);
2ba45142 10892
34f80b04
EG
10893 return rc;
10894}
10895
34f24c7f
VZ
10896static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10897{
10898 int cnt, i, block_end, rodi;
fcdf95cb 10899 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
10900 char str_id_reg[VENDOR_ID_LEN+1];
10901 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
10902 char *vpd_data;
10903 char *vpd_extended_data = NULL;
34f24c7f
VZ
10904 u8 len;
10905
fcdf95cb 10906 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
10907 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10908
10909 if (cnt < BNX2X_VPD_LEN)
10910 goto out_not_found;
10911
fcdf95cb
BW
10912 /* VPD RO tag should be first tag after identifier string, hence
10913 * we should be able to find it in first BNX2X_VPD_LEN chars
10914 */
10915 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
10916 PCI_VPD_LRDT_RO_DATA);
10917 if (i < 0)
10918 goto out_not_found;
10919
34f24c7f 10920 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 10921 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
10922
10923 i += PCI_VPD_LRDT_TAG_SIZE;
10924
fcdf95cb
BW
10925 if (block_end > BNX2X_VPD_LEN) {
10926 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10927 if (vpd_extended_data == NULL)
10928 goto out_not_found;
10929
10930 /* read rest of vpd image into vpd_extended_data */
10931 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10932 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10933 block_end - BNX2X_VPD_LEN,
10934 vpd_extended_data + BNX2X_VPD_LEN);
10935 if (cnt < (block_end - BNX2X_VPD_LEN))
10936 goto out_not_found;
10937 vpd_data = vpd_extended_data;
10938 } else
10939 vpd_data = vpd_start;
10940
10941 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
10942
10943 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10944 PCI_VPD_RO_KEYWORD_MFR_ID);
10945 if (rodi < 0)
10946 goto out_not_found;
10947
10948 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10949
10950 if (len != VENDOR_ID_LEN)
10951 goto out_not_found;
10952
10953 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10954
10955 /* vendor specific info */
10956 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10957 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10958 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10959 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10960
10961 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10962 PCI_VPD_RO_KEYWORD_VENDOR0);
10963 if (rodi >= 0) {
10964 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10965
10966 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10967
10968 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10969 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10970 bp->fw_ver[len] = ' ';
10971 }
10972 }
fcdf95cb 10973 kfree(vpd_extended_data);
34f24c7f
VZ
10974 return;
10975 }
10976out_not_found:
fcdf95cb 10977 kfree(vpd_extended_data);
34f24c7f
VZ
10978 return;
10979}
10980
619c5cb6
VZ
10981static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10982{
10983 u32 flags = 0;
10984
10985 if (CHIP_REV_IS_FPGA(bp))
10986 SET_FLAGS(flags, MODE_FPGA);
10987 else if (CHIP_REV_IS_EMUL(bp))
10988 SET_FLAGS(flags, MODE_EMUL);
10989 else
10990 SET_FLAGS(flags, MODE_ASIC);
10991
10992 if (CHIP_MODE_IS_4_PORT(bp))
10993 SET_FLAGS(flags, MODE_PORT4);
10994 else
10995 SET_FLAGS(flags, MODE_PORT2);
10996
10997 if (CHIP_IS_E2(bp))
10998 SET_FLAGS(flags, MODE_E2);
10999 else if (CHIP_IS_E3(bp)) {
11000 SET_FLAGS(flags, MODE_E3);
11001 if (CHIP_REV(bp) == CHIP_REV_Ax)
11002 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11003 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11004 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11005 }
11006
11007 if (IS_MF(bp)) {
11008 SET_FLAGS(flags, MODE_MF);
11009 switch (bp->mf_mode) {
11010 case MULTI_FUNCTION_SD:
11011 SET_FLAGS(flags, MODE_MF_SD);
11012 break;
11013 case MULTI_FUNCTION_SI:
11014 SET_FLAGS(flags, MODE_MF_SI);
11015 break;
a3348722
BW
11016 case MULTI_FUNCTION_AFEX:
11017 SET_FLAGS(flags, MODE_MF_AFEX);
11018 break;
619c5cb6
VZ
11019 }
11020 } else
11021 SET_FLAGS(flags, MODE_SF);
11022
11023#if defined(__LITTLE_ENDIAN)
11024 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11025#else /*(__BIG_ENDIAN)*/
11026 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11027#endif
11028 INIT_MODE_FLAGS(bp) = flags;
11029}
11030
34f80b04
EG
11031static int __devinit bnx2x_init_bp(struct bnx2x *bp)
11032{
f2e0899f 11033 int func;
34f80b04
EG
11034 int rc;
11035
34f80b04 11036 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11037 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11038 spin_lock_init(&bp->stats_lock);
55c11941 11039
a2fbb9ea 11040
1cf167f2 11041 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11042 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11043 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
34f80b04 11044 rc = bnx2x_get_hwinfo(bp);
619c5cb6
VZ
11045 if (rc)
11046 return rc;
34f80b04 11047
619c5cb6
VZ
11048 bnx2x_set_modes_bitmap(bp);
11049
11050 rc = bnx2x_alloc_mem_bp(bp);
11051 if (rc)
11052 return rc;
523224a3 11053
34f24c7f 11054 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11055
11056 func = BP_FUNC(bp);
11057
34f80b04 11058 /* need to reset chip if undi was active */
452427b0
YM
11059 if (!BP_NOMCP(bp)) {
11060 /* init fw_seq */
11061 bp->fw_seq =
11062 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11063 DRV_MSG_SEQ_NUMBER_MASK;
11064 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11065
11066 bnx2x_prev_unload(bp);
11067 }
11068
34f80b04
EG
11069
11070 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11071 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11072
11073 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11074 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11075
614c76df 11076 bp->disable_tpa = disable_tpa;
a3348722 11077 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11078
7a9b2557 11079 /* Set TPA flags */
614c76df 11080 if (bp->disable_tpa) {
621b4d66 11081 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11082 bp->dev->features &= ~NETIF_F_LRO;
11083 } else {
621b4d66 11084 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11085 bp->dev->features |= NETIF_F_LRO;
11086 }
11087
a18f5128
EG
11088 if (CHIP_IS_E1(bp))
11089 bp->dropless_fc = 0;
11090 else
7964211d 11091 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11092
8d5726c4 11093 bp->mrrs = mrrs;
7a9b2557 11094
a3348722 11095 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
34f80b04 11096
7d323bfd 11097 /* make sure that the numbers are in the right granularity */
523224a3
DK
11098 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11099 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11100
fc543637 11101 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11102
11103 init_timer(&bp->timer);
11104 bp->timer.expires = jiffies + bp->current_interval;
11105 bp->timer.data = (unsigned long) bp;
11106 bp->timer.function = bnx2x_timer;
11107
785b9b1a 11108 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
e4901dde
VZ
11109 bnx2x_dcbx_init_params(bp);
11110
619c5cb6
VZ
11111 if (CHIP_IS_E1x(bp))
11112 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11113 else
11114 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11115
6383c0b3
AE
11116 /* multiple tx priority */
11117 if (CHIP_IS_E1x(bp))
11118 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
11119 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
11120 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
11121 if (CHIP_IS_E3B0(bp))
11122 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
11123
55c11941
MS
11124 /* We need at least one default status block for slow-path events,
11125 * second status block for the L2 queue, and a third status block for
11126 * CNIC if supproted.
11127 */
11128 if (CNIC_SUPPORT(bp))
11129 bp->min_msix_vec_cnt = 3;
11130 else
11131 bp->min_msix_vec_cnt = 2;
11132 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11133
34f80b04 11134 return rc;
a2fbb9ea
ET
11135}
11136
a2fbb9ea 11137
de0c62db
DK
11138/****************************************************************************
11139* General service functions
11140****************************************************************************/
a2fbb9ea 11141
619c5cb6
VZ
11142/*
11143 * net_device service functions
11144 */
11145
bb2a0f7a 11146/* called with rtnl_lock */
a2fbb9ea
ET
11147static int bnx2x_open(struct net_device *dev)
11148{
11149 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11150 bool global = false;
11151 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11152 bool other_load_status, load_status;
a2fbb9ea 11153
1355b704
MY
11154 bp->stats_init = true;
11155
6eccabb3
EG
11156 netif_carrier_off(dev);
11157
a2fbb9ea
ET
11158 bnx2x_set_power_state(bp, PCI_D0);
11159
889b9af3
AE
11160 other_load_status = bnx2x_get_load_status(bp, other_engine);
11161 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
11162
11163 /*
11164 * If parity had happen during the unload, then attentions
11165 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11166 * want the first function loaded on the current engine to
11167 * complete the recovery.
11168 */
11169 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11170 bnx2x_chk_parity_attn(bp, &global, true))
72fd0718 11171 do {
c9ee9206
VZ
11172 /*
11173 * If there are attentions and they are in a global
11174 * blocks, set the GLOBAL_RESET bit regardless whether
11175 * it will be this function that will complete the
11176 * recovery or not.
72fd0718 11177 */
c9ee9206
VZ
11178 if (global)
11179 bnx2x_set_reset_global(bp);
72fd0718 11180
c9ee9206
VZ
11181 /*
11182 * Only the first function on the current engine should
11183 * try to recover in open. In case of attentions in
11184 * global blocks only the first in the chip should try
11185 * to recover.
72fd0718 11186 */
889b9af3
AE
11187 if ((!load_status &&
11188 (!global || !other_load_status)) &&
c9ee9206
VZ
11189 bnx2x_trylock_leader_lock(bp) &&
11190 !bnx2x_leader_reset(bp)) {
11191 netdev_info(bp->dev, "Recovered in open\n");
72fd0718
VZ
11192 break;
11193 }
11194
c9ee9206 11195 /* recovery has failed... */
72fd0718 11196 bnx2x_set_power_state(bp, PCI_D3hot);
c9ee9206 11197 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11198
51c1a580
MS
11199 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11200 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718
VZ
11201
11202 return -EAGAIN;
11203 } while (0);
72fd0718
VZ
11204
11205 bp->recovery_state = BNX2X_RECOVERY_DONE;
bb2a0f7a 11206 return bnx2x_nic_load(bp, LOAD_OPEN);
a2fbb9ea
ET
11207}
11208
bb2a0f7a 11209/* called with rtnl_lock */
56ad3152 11210static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11211{
a2fbb9ea
ET
11212 struct bnx2x *bp = netdev_priv(dev);
11213
11214 /* Unload the driver, release IRQs */
5d07d868 11215 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206
VZ
11216
11217 /* Power off */
d3dbfee0 11218 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
11219
11220 return 0;
11221}
11222
1191cb83
ED
11223static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11224 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11225{
619c5cb6
VZ
11226 int mc_count = netdev_mc_count(bp->dev);
11227 struct bnx2x_mcast_list_elem *mc_mac =
11228 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11229 struct netdev_hw_addr *ha;
6e30dd4e 11230
619c5cb6
VZ
11231 if (!mc_mac)
11232 return -ENOMEM;
6e30dd4e 11233
619c5cb6 11234 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11235
619c5cb6
VZ
11236 netdev_for_each_mc_addr(ha, bp->dev) {
11237 mc_mac->mac = bnx2x_mc_addr(ha);
11238 list_add_tail(&mc_mac->link, &p->mcast_list);
11239 mc_mac++;
6e30dd4e 11240 }
619c5cb6
VZ
11241
11242 p->mcast_list_len = mc_count;
11243
11244 return 0;
6e30dd4e
VZ
11245}
11246
1191cb83 11247static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11248 struct bnx2x_mcast_ramrod_params *p)
11249{
11250 struct bnx2x_mcast_list_elem *mc_mac =
11251 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11252 link);
11253
11254 WARN_ON(!mc_mac);
11255 kfree(mc_mac);
11256}
11257
11258/**
11259 * bnx2x_set_uc_list - configure a new unicast MACs list.
11260 *
11261 * @bp: driver handle
6e30dd4e 11262 *
619c5cb6 11263 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11264 */
1191cb83 11265static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11266{
619c5cb6 11267 int rc;
6e30dd4e 11268 struct net_device *dev = bp->dev;
6e30dd4e 11269 struct netdev_hw_addr *ha;
15192a8c 11270 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11271 unsigned long ramrod_flags = 0;
6e30dd4e 11272
619c5cb6
VZ
11273 /* First schedule a cleanup up of old configuration */
11274 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11275 if (rc < 0) {
11276 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11277 return rc;
11278 }
6e30dd4e
VZ
11279
11280 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11281 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11282 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11283 if (rc == -EEXIST) {
11284 DP(BNX2X_MSG_SP,
11285 "Failed to schedule ADD operations: %d\n", rc);
11286 /* do not treat adding same MAC as error */
11287 rc = 0;
11288
11289 } else if (rc < 0) {
11290
619c5cb6
VZ
11291 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11292 rc);
11293 return rc;
6e30dd4e
VZ
11294 }
11295 }
11296
619c5cb6
VZ
11297 /* Execute the pending commands */
11298 __set_bit(RAMROD_CONT, &ramrod_flags);
11299 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11300 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11301}
11302
1191cb83 11303static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11304{
619c5cb6 11305 struct net_device *dev = bp->dev;
3b603066 11306 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11307 int rc = 0;
6e30dd4e 11308
619c5cb6 11309 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11310
619c5cb6
VZ
11311 /* first, clear all configured multicast MACs */
11312 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11313 if (rc < 0) {
51c1a580 11314 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11315 return rc;
11316 }
6e30dd4e 11317
619c5cb6
VZ
11318 /* then, configure a new MACs list */
11319 if (netdev_mc_count(dev)) {
11320 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11321 if (rc) {
51c1a580
MS
11322 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11323 rc);
619c5cb6
VZ
11324 return rc;
11325 }
6e30dd4e 11326
619c5cb6
VZ
11327 /* Now add the new MACs */
11328 rc = bnx2x_config_mcast(bp, &rparam,
11329 BNX2X_MCAST_CMD_ADD);
11330 if (rc < 0)
51c1a580
MS
11331 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11332 rc);
6e30dd4e 11333
619c5cb6
VZ
11334 bnx2x_free_mcast_macs_list(&rparam);
11335 }
6e30dd4e 11336
619c5cb6 11337 return rc;
6e30dd4e
VZ
11338}
11339
6e30dd4e 11340
619c5cb6 11341/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11342void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11343{
11344 struct bnx2x *bp = netdev_priv(dev);
11345 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11346
11347 if (bp->state != BNX2X_STATE_OPEN) {
11348 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11349 return;
11350 }
11351
619c5cb6 11352 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11353
11354 if (dev->flags & IFF_PROMISC)
11355 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11356 else if ((dev->flags & IFF_ALLMULTI) ||
11357 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11358 CHIP_IS_E1(bp)))
34f80b04 11359 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e
VZ
11360 else {
11361 /* some multicasts */
619c5cb6 11362 if (bnx2x_set_mc_list(bp) < 0)
6e30dd4e 11363 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11364
619c5cb6 11365 if (bnx2x_set_uc_list(bp) < 0)
6e30dd4e 11366 rx_mode = BNX2X_RX_MODE_PROMISC;
34f80b04
EG
11367 }
11368
11369 bp->rx_mode = rx_mode;
614c76df
DK
11370 /* handle ISCSI SD mode */
11371 if (IS_MF_ISCSI_SD(bp))
11372 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11373
11374 /* Schedule the rx_mode command */
11375 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11376 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11377 return;
11378 }
11379
34f80b04
EG
11380 bnx2x_set_storm_rx_mode(bp);
11381}
11382
c18487ee 11383/* called with rtnl_lock */
01cd4528
EG
11384static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11385 int devad, u16 addr)
a2fbb9ea 11386{
01cd4528
EG
11387 struct bnx2x *bp = netdev_priv(netdev);
11388 u16 value;
11389 int rc;
a2fbb9ea 11390
01cd4528
EG
11391 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11392 prtad, devad, addr);
a2fbb9ea 11393
01cd4528
EG
11394 /* The HW expects different devad if CL22 is used */
11395 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11396
01cd4528 11397 bnx2x_acquire_phy_lock(bp);
e10bc84d 11398 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11399 bnx2x_release_phy_lock(bp);
11400 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11401
01cd4528
EG
11402 if (!rc)
11403 rc = value;
11404 return rc;
11405}
a2fbb9ea 11406
01cd4528
EG
11407/* called with rtnl_lock */
11408static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11409 u16 addr, u16 value)
11410{
11411 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11412 int rc;
11413
51c1a580
MS
11414 DP(NETIF_MSG_LINK,
11415 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11416 prtad, devad, addr, value);
01cd4528 11417
01cd4528
EG
11418 /* The HW expects different devad if CL22 is used */
11419 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11420
01cd4528 11421 bnx2x_acquire_phy_lock(bp);
e10bc84d 11422 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11423 bnx2x_release_phy_lock(bp);
11424 return rc;
11425}
c18487ee 11426
01cd4528
EG
11427/* called with rtnl_lock */
11428static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11429{
11430 struct bnx2x *bp = netdev_priv(dev);
11431 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11432
01cd4528
EG
11433 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11434 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11435
01cd4528
EG
11436 if (!netif_running(dev))
11437 return -EAGAIN;
11438
11439 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11440}
11441
257ddbda 11442#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11443static void poll_bnx2x(struct net_device *dev)
11444{
11445 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11446 int i;
a2fbb9ea 11447
14a15d61
MS
11448 for_each_eth_queue(bp, i) {
11449 struct bnx2x_fastpath *fp = &bp->fp[i];
11450 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11451 }
a2fbb9ea
ET
11452}
11453#endif
11454
614c76df
DK
11455static int bnx2x_validate_addr(struct net_device *dev)
11456{
11457 struct bnx2x *bp = netdev_priv(dev);
11458
51c1a580
MS
11459 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11460 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11461 return -EADDRNOTAVAIL;
51c1a580 11462 }
614c76df
DK
11463 return 0;
11464}
11465
c64213cd
SH
11466static const struct net_device_ops bnx2x_netdev_ops = {
11467 .ndo_open = bnx2x_open,
11468 .ndo_stop = bnx2x_close,
11469 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11470 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11471 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11472 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11473 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11474 .ndo_do_ioctl = bnx2x_ioctl,
11475 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11476 .ndo_fix_features = bnx2x_fix_features,
11477 .ndo_set_features = bnx2x_set_features,
c64213cd 11478 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11479#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11480 .ndo_poll_controller = poll_bnx2x,
11481#endif
6383c0b3
AE
11482 .ndo_setup_tc = bnx2x_setup_tc,
11483
55c11941 11484#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11485 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11486#endif
c64213cd
SH
11487};
11488
1191cb83 11489static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11490{
11491 struct device *dev = &bp->pdev->dev;
11492
11493 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11494 bp->flags |= USING_DAC_FLAG;
11495 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11496 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11497 return -EIO;
11498 }
11499 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11500 dev_err(dev, "System does not support DMA, aborting\n");
11501 return -EIO;
11502 }
11503
11504 return 0;
11505}
11506
34f80b04 11507static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
619c5cb6
VZ
11508 struct net_device *dev,
11509 unsigned long board_type)
a2fbb9ea
ET
11510{
11511 struct bnx2x *bp;
11512 int rc;
c22610d0 11513 u32 pci_cfg_dword;
65087cfe
AE
11514 bool chip_is_e1x = (board_type == BCM57710 ||
11515 board_type == BCM57711 ||
11516 board_type == BCM57711E);
a2fbb9ea
ET
11517
11518 SET_NETDEV_DEV(dev, &pdev->dev);
11519 bp = netdev_priv(dev);
11520
34f80b04
EG
11521 bp->dev = dev;
11522 bp->pdev = pdev;
a2fbb9ea 11523 bp->flags = 0;
a2fbb9ea
ET
11524
11525 rc = pci_enable_device(pdev);
11526 if (rc) {
cdaa7cb8
VZ
11527 dev_err(&bp->pdev->dev,
11528 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11529 goto err_out;
11530 }
11531
11532 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11533 dev_err(&bp->pdev->dev,
11534 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11535 rc = -ENODEV;
11536 goto err_out_disable;
11537 }
11538
11539 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11540 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
11541 " base address, aborting\n");
a2fbb9ea
ET
11542 rc = -ENODEV;
11543 goto err_out_disable;
11544 }
11545
34f80b04
EG
11546 if (atomic_read(&pdev->enable_cnt) == 1) {
11547 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11548 if (rc) {
cdaa7cb8
VZ
11549 dev_err(&bp->pdev->dev,
11550 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11551 goto err_out_disable;
11552 }
a2fbb9ea 11553
34f80b04
EG
11554 pci_set_master(pdev);
11555 pci_save_state(pdev);
11556 }
a2fbb9ea
ET
11557
11558 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11559 if (bp->pm_cap == 0) {
cdaa7cb8
VZ
11560 dev_err(&bp->pdev->dev,
11561 "Cannot find power management capability, aborting\n");
a2fbb9ea
ET
11562 rc = -EIO;
11563 goto err_out_release;
11564 }
11565
77c98e6a 11566 if (!pci_is_pcie(pdev)) {
51c1a580 11567 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11568 rc = -EIO;
11569 goto err_out_release;
11570 }
11571
619c5cb6
VZ
11572 rc = bnx2x_set_coherency_mask(bp);
11573 if (rc)
a2fbb9ea 11574 goto err_out_release;
a2fbb9ea 11575
34f80b04
EG
11576 dev->mem_start = pci_resource_start(pdev, 0);
11577 dev->base_addr = dev->mem_start;
11578 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11579
11580 dev->irq = pdev->irq;
11581
275f165f 11582 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11583 if (!bp->regview) {
cdaa7cb8
VZ
11584 dev_err(&bp->pdev->dev,
11585 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11586 rc = -ENOMEM;
11587 goto err_out_release;
11588 }
11589
c22610d0
AE
11590 /* In E1/E1H use pci device function given by kernel.
11591 * In E2/E3 read physical function from ME register since these chips
11592 * support Physical Device Assignment where kernel BDF maybe arbitrary
11593 * (depending on hypervisor).
11594 */
11595 if (chip_is_e1x)
11596 bp->pf_num = PCI_FUNC(pdev->devfn);
11597 else {/* chip is E2/3*/
11598 pci_read_config_dword(bp->pdev,
11599 PCICFG_ME_REGISTER, &pci_cfg_dword);
11600 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
11601 ME_REG_ABS_PF_NUM_SHIFT);
11602 }
51c1a580 11603 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 11604
a2fbb9ea
ET
11605 bnx2x_set_power_state(bp, PCI_D0);
11606
34f80b04
EG
11607 /* clean indirect addresses */
11608 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11609 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
11610 /*
11611 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
11612 * is not used by the driver.
11613 */
11614 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11615 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11616 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11617 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
a5c53dbc 11618
65087cfe 11619 if (chip_is_e1x) {
a5c53dbc
DK
11620 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11621 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11622 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11623 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11624 }
a2fbb9ea 11625
2189400b 11626 /*
619c5cb6 11627 * Enable internal target-read (in case we are probed after PF FLR).
2189400b 11628 * Must be done prior to any BAR read access. Only for 57712 and up
619c5cb6 11629 */
65087cfe 11630 if (!chip_is_e1x)
2189400b 11631 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
619c5cb6 11632
34f80b04 11633 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 11634
c64213cd 11635 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 11636 bnx2x_set_ethtool_ops(dev);
5316bc0b 11637
01789349
JP
11638 dev->priv_flags |= IFF_UNICAST_FLT;
11639
66371c44 11640 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
11641 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11642 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11643 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
11644
11645 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11646 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11647
11648 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 11649 if (bp->flags & USING_DAC_FLAG)
66371c44 11650 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 11651
538dd2e3
MB
11652 /* Add Loopback capability to the device */
11653 dev->hw_features |= NETIF_F_LOOPBACK;
11654
98507672 11655#ifdef BCM_DCBNL
785b9b1a
SR
11656 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11657#endif
11658
01cd4528
EG
11659 /* get_port_hwinfo() will set prtad and mmds properly */
11660 bp->mdio.prtad = MDIO_PRTAD_NONE;
11661 bp->mdio.mmds = 0;
11662 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11663 bp->mdio.dev = dev;
11664 bp->mdio.mdio_read = bnx2x_mdio_read;
11665 bp->mdio.mdio_write = bnx2x_mdio_write;
11666
a2fbb9ea
ET
11667 return 0;
11668
a2fbb9ea 11669err_out_release:
34f80b04
EG
11670 if (atomic_read(&pdev->enable_cnt) == 1)
11671 pci_release_regions(pdev);
a2fbb9ea
ET
11672
11673err_out_disable:
11674 pci_disable_device(pdev);
11675 pci_set_drvdata(pdev, NULL);
11676
11677err_out:
11678 return rc;
11679}
11680
37f9ce62
EG
11681static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
11682 int *width, int *speed)
25047950
ET
11683{
11684 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
11685
37f9ce62 11686 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 11687
37f9ce62
EG
11688 /* return value of 1=2.5GHz 2=5GHz */
11689 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 11690}
37f9ce62 11691
6891dd25 11692static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 11693{
37f9ce62 11694 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
11695 struct bnx2x_fw_file_hdr *fw_hdr;
11696 struct bnx2x_fw_file_section *sections;
94a78b79 11697 u32 offset, len, num_ops;
37f9ce62 11698 u16 *ops_offsets;
94a78b79 11699 int i;
37f9ce62 11700 const u8 *fw_ver;
94a78b79 11701
51c1a580
MS
11702 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
11703 BNX2X_ERR("Wrong FW size\n");
94a78b79 11704 return -EINVAL;
51c1a580 11705 }
94a78b79
VZ
11706
11707 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
11708 sections = (struct bnx2x_fw_file_section *)fw_hdr;
11709
11710 /* Make sure none of the offsets and sizes make us read beyond
11711 * the end of the firmware data */
11712 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
11713 offset = be32_to_cpu(sections[i].offset);
11714 len = be32_to_cpu(sections[i].len);
11715 if (offset + len > firmware->size) {
51c1a580 11716 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
11717 return -EINVAL;
11718 }
11719 }
11720
11721 /* Likewise for the init_ops offsets */
11722 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
11723 ops_offsets = (u16 *)(firmware->data + offset);
11724 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
11725
11726 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
11727 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 11728 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
11729 return -EINVAL;
11730 }
11731 }
11732
11733 /* Check FW version */
11734 offset = be32_to_cpu(fw_hdr->fw_version.offset);
11735 fw_ver = firmware->data + offset;
11736 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
11737 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
11738 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
11739 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
11740 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11741 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
11742 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
11743 BCM_5710_FW_MINOR_VERSION,
11744 BCM_5710_FW_REVISION_VERSION,
11745 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 11746 return -EINVAL;
94a78b79
VZ
11747 }
11748
11749 return 0;
11750}
11751
1191cb83 11752static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11753{
ab6ad5a4
EG
11754 const __be32 *source = (const __be32 *)_source;
11755 u32 *target = (u32 *)_target;
94a78b79 11756 u32 i;
94a78b79
VZ
11757
11758 for (i = 0; i < n/4; i++)
11759 target[i] = be32_to_cpu(source[i]);
11760}
11761
11762/*
11763 Ops array is stored in the following format:
11764 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11765 */
1191cb83 11766static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 11767{
ab6ad5a4
EG
11768 const __be32 *source = (const __be32 *)_source;
11769 struct raw_op *target = (struct raw_op *)_target;
94a78b79 11770 u32 i, j, tmp;
94a78b79 11771
ab6ad5a4 11772 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
11773 tmp = be32_to_cpu(source[j]);
11774 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
11775 target[i].offset = tmp & 0xffffff;
11776 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
11777 }
11778}
ab6ad5a4 11779
1aa8b471 11780/* IRO array is stored in the following format:
523224a3
DK
11781 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11782 */
1191cb83 11783static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
11784{
11785 const __be32 *source = (const __be32 *)_source;
11786 struct iro *target = (struct iro *)_target;
11787 u32 i, j, tmp;
11788
11789 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11790 target[i].base = be32_to_cpu(source[j]);
11791 j++;
11792 tmp = be32_to_cpu(source[j]);
11793 target[i].m1 = (tmp >> 16) & 0xffff;
11794 target[i].m2 = tmp & 0xffff;
11795 j++;
11796 tmp = be32_to_cpu(source[j]);
11797 target[i].m3 = (tmp >> 16) & 0xffff;
11798 target[i].size = tmp & 0xffff;
11799 j++;
11800 }
11801}
11802
1191cb83 11803static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11804{
ab6ad5a4
EG
11805 const __be16 *source = (const __be16 *)_source;
11806 u16 *target = (u16 *)_target;
94a78b79 11807 u32 i;
94a78b79
VZ
11808
11809 for (i = 0; i < n/2; i++)
11810 target[i] = be16_to_cpu(source[i]);
11811}
11812
7995c64e
JP
11813#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11814do { \
11815 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11816 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 11817 if (!bp->arr) \
7995c64e 11818 goto lbl; \
7995c64e
JP
11819 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11820 (u8 *)bp->arr, len); \
11821} while (0)
94a78b79 11822
3b603066 11823static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 11824{
c0ea452e 11825 const char *fw_file_name;
94a78b79 11826 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 11827 int rc;
94a78b79 11828
c0ea452e
MS
11829 if (bp->firmware)
11830 return 0;
94a78b79 11831
c0ea452e
MS
11832 if (CHIP_IS_E1(bp))
11833 fw_file_name = FW_FILE_NAME_E1;
11834 else if (CHIP_IS_E1H(bp))
11835 fw_file_name = FW_FILE_NAME_E1H;
11836 else if (!CHIP_IS_E1x(bp))
11837 fw_file_name = FW_FILE_NAME_E2;
11838 else {
11839 BNX2X_ERR("Unsupported chip revision\n");
11840 return -EINVAL;
11841 }
11842 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 11843
c0ea452e
MS
11844 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11845 if (rc) {
11846 BNX2X_ERR("Can't load firmware file %s\n",
11847 fw_file_name);
11848 goto request_firmware_exit;
11849 }
eb2afd4a 11850
c0ea452e
MS
11851 rc = bnx2x_check_firmware(bp);
11852 if (rc) {
11853 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11854 goto request_firmware_exit;
94a78b79
VZ
11855 }
11856
11857 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11858
11859 /* Initialize the pointers to the init arrays */
11860 /* Blob */
11861 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11862
11863 /* Opcodes */
11864 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11865
11866 /* Offsets */
ab6ad5a4
EG
11867 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11868 be16_to_cpu_n);
94a78b79
VZ
11869
11870 /* STORMs firmware */
573f2035
EG
11871 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11872 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11873 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11874 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11875 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11876 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11877 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11878 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11879 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11880 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11881 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11882 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11883 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11884 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11885 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11886 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
11887 /* IRO */
11888 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
11889
11890 return 0;
ab6ad5a4 11891
523224a3
DK
11892iro_alloc_err:
11893 kfree(bp->init_ops_offsets);
94a78b79
VZ
11894init_offsets_alloc_err:
11895 kfree(bp->init_ops);
11896init_ops_alloc_err:
11897 kfree(bp->init_data);
11898request_firmware_exit:
11899 release_firmware(bp->firmware);
127d0a19 11900 bp->firmware = NULL;
94a78b79
VZ
11901
11902 return rc;
11903}
11904
619c5cb6
VZ
11905static void bnx2x_release_firmware(struct bnx2x *bp)
11906{
11907 kfree(bp->init_ops_offsets);
11908 kfree(bp->init_ops);
11909 kfree(bp->init_data);
11910 release_firmware(bp->firmware);
eb2afd4a 11911 bp->firmware = NULL;
619c5cb6
VZ
11912}
11913
11914
11915static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11916 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11917 .init_hw_cmn = bnx2x_init_hw_common,
11918 .init_hw_port = bnx2x_init_hw_port,
11919 .init_hw_func = bnx2x_init_hw_func,
11920
11921 .reset_hw_cmn = bnx2x_reset_common,
11922 .reset_hw_port = bnx2x_reset_port,
11923 .reset_hw_func = bnx2x_reset_func,
11924
11925 .gunzip_init = bnx2x_gunzip_init,
11926 .gunzip_end = bnx2x_gunzip_end,
11927
11928 .init_fw = bnx2x_init_firmware,
11929 .release_fw = bnx2x_release_firmware,
11930};
11931
11932void bnx2x__init_func_obj(struct bnx2x *bp)
11933{
11934 /* Prepare DMAE related driver resources */
11935 bnx2x_setup_dmae(bp);
11936
11937 bnx2x_init_func_obj(bp, &bp->func_obj,
11938 bnx2x_sp(bp, func_rdata),
11939 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
11940 bnx2x_sp(bp, func_afex_rdata),
11941 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
11942 &bnx2x_func_sp_drv);
11943}
11944
11945/* must be called after sriov-enable */
1191cb83 11946static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 11947{
37ae41a9 11948 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 11949
55c11941
MS
11950 if (CNIC_SUPPORT(bp))
11951 cid_count += CNIC_CID_MAX;
523224a3
DK
11952 return roundup(cid_count, QM_CID_ROUND);
11953}
f85582f8 11954
619c5cb6 11955/**
6383c0b3 11956 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
11957 *
11958 * @dev: pci device
11959 *
11960 */
55c11941
MS
11961static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
11962 int cnic_cnt)
619c5cb6
VZ
11963{
11964 int pos;
11965 u16 control;
11966
11967 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
11968
11969 /*
11970 * If MSI-X is not supported - return number of SBs needed to support
11971 * one fast path queue: one FP queue + SB for CNIC
11972 */
619c5cb6 11973 if (!pos)
55c11941 11974 return 1 + cnic_cnt;
619c5cb6 11975
6383c0b3
AE
11976 /*
11977 * The value in the PCI configuration space is the index of the last
11978 * entry, namely one less than the actual size of the table, which is
11979 * exactly what we want to return from this function: number of all SBs
11980 * without the default SB.
11981 */
619c5cb6 11982 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
6383c0b3 11983 return control & PCI_MSIX_FLAGS_QSIZE;
619c5cb6
VZ
11984}
11985
a2fbb9ea
ET
11986static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11987 const struct pci_device_id *ent)
11988{
a2fbb9ea
ET
11989 struct net_device *dev = NULL;
11990 struct bnx2x *bp;
37f9ce62 11991 int pcie_width, pcie_speed;
6383c0b3 11992 int rc, max_non_def_sbs;
65565884 11993 int rx_count, tx_count, rss_count, doorbell_size;
55c11941 11994 int cnic_cnt;
6383c0b3
AE
11995 /*
11996 * An estimated maximum supported CoS number according to the chip
11997 * version.
11998 * We will try to roughly estimate the maximum number of CoSes this chip
11999 * may support in order to minimize the memory allocated for Tx
12000 * netdev_queue's. This number will be accurately calculated during the
12001 * initialization of bp->max_cos based on the chip versions AND chip
12002 * revision in the bnx2x_init_bp().
12003 */
12004 u8 max_cos_est = 0;
523224a3 12005
f2e0899f
DK
12006 switch (ent->driver_data) {
12007 case BCM57710:
12008 case BCM57711:
12009 case BCM57711E:
6383c0b3
AE
12010 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
12011 break;
12012
f2e0899f 12013 case BCM57712:
619c5cb6 12014 case BCM57712_MF:
6383c0b3
AE
12015 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
12016 break;
12017
619c5cb6
VZ
12018 case BCM57800:
12019 case BCM57800_MF:
12020 case BCM57810:
12021 case BCM57810_MF:
c3def943
YM
12022 case BCM57840_O:
12023 case BCM57840_4_10:
12024 case BCM57840_2_20:
12025 case BCM57840_MFO:
619c5cb6 12026 case BCM57840_MF:
7e8e02df
BW
12027 case BCM57811:
12028 case BCM57811_MF:
6383c0b3 12029 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
f2e0899f 12030 break;
a2fbb9ea 12031
f2e0899f
DK
12032 default:
12033 pr_err("Unknown board_type (%ld), aborting\n",
12034 ent->driver_data);
870634b0 12035 return -ENODEV;
f2e0899f
DK
12036 }
12037
55c11941
MS
12038 cnic_cnt = 1;
12039 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
6383c0b3 12040
6383c0b3
AE
12041 WARN_ON(!max_non_def_sbs);
12042
12043 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
55c11941 12044 rss_count = max_non_def_sbs - cnic_cnt;
6383c0b3
AE
12045
12046 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12047 rx_count = rss_count + cnic_cnt;
6383c0b3
AE
12048
12049 /*
12050 * Maximum number of netdev Tx queues:
37ae41a9 12051 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12052 */
55c11941 12053 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12054
a2fbb9ea 12055 /* dev zeroed in init_etherdev */
6383c0b3 12056 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12057 if (!dev)
a2fbb9ea
ET
12058 return -ENOMEM;
12059
a2fbb9ea 12060 bp = netdev_priv(dev);
a2fbb9ea 12061
6383c0b3
AE
12062 bp->igu_sb_cnt = max_non_def_sbs;
12063 bp->msg_enable = debug;
55c11941
MS
12064 bp->cnic_support = cnic_cnt;
12065
6383c0b3 12066 pci_set_drvdata(pdev, dev);
523224a3 12067
619c5cb6 12068 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
a2fbb9ea
ET
12069 if (rc < 0) {
12070 free_netdev(dev);
12071 return rc;
12072 }
12073
55c11941 12074 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
51c1a580 12075 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
619c5cb6 12076
60aa0509
MS
12077 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
12078 tx_count, rx_count);
12079
34f80b04 12080 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12081 if (rc)
12082 goto init_one_exit;
12083
6383c0b3
AE
12084 /*
12085 * Map doorbels here as we need the real value of bp->max_cos which
12086 * is initialized in bnx2x_init_bp().
12087 */
37ae41a9
MS
12088 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12089 if (doorbell_size > pci_resource_len(pdev, 2)) {
12090 dev_err(&bp->pdev->dev,
12091 "Cannot map doorbells, bar size too small, aborting\n");
12092 rc = -ENOMEM;
12093 goto init_one_exit;
12094 }
6383c0b3 12095 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
37ae41a9 12096 doorbell_size);
6383c0b3
AE
12097 if (!bp->doorbells) {
12098 dev_err(&bp->pdev->dev,
12099 "Cannot map doorbell space, aborting\n");
12100 rc = -ENOMEM;
12101 goto init_one_exit;
12102 }
12103
523224a3 12104 /* calc qm_cid_count */
6383c0b3 12105 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
523224a3 12106
55c11941 12107 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12108 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12109 bp->flags |= NO_FCOE_FLAG;
12110
477864dd
DK
12111 /* disable FCOE for 57840 device, until FW supports it */
12112 switch (ent->driver_data) {
12113 case BCM57840_O:
12114 case BCM57840_4_10:
12115 case BCM57840_2_20:
12116 case BCM57840_MFO:
12117 case BCM57840_MF:
12118 bp->flags |= NO_FCOE_FLAG;
12119 }
0e8d2ec5
MS
12120
12121 /* Set bp->num_queues for MSI-X mode*/
12122 bnx2x_set_num_queues(bp);
12123
25985edc 12124 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12125 * needed.
d6214d7a
DK
12126 */
12127 bnx2x_set_int_mode(bp);
12128
b340007f
VZ
12129 rc = register_netdev(dev);
12130 if (rc) {
12131 dev_err(&pdev->dev, "Cannot register net device\n");
12132 goto init_one_exit;
12133 }
12134
55c11941 12135
ec6ba945
VZ
12136 if (!NO_FCOE(bp)) {
12137 /* Add storage MAC address */
12138 rtnl_lock();
12139 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12140 rtnl_unlock();
12141 }
ec6ba945 12142
37f9ce62 12143 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
d6214d7a 12144
51c1a580
MS
12145 BNX2X_DEV_INFO(
12146 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
12147 board_info[ent->driver_data].name,
12148 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12149 pcie_width,
12150 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
12151 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
12152 "5GHz (Gen2)" : "2.5GHz",
12153 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12154
a2fbb9ea 12155 return 0;
34f80b04
EG
12156
12157init_one_exit:
12158 if (bp->regview)
12159 iounmap(bp->regview);
12160
12161 if (bp->doorbells)
12162 iounmap(bp->doorbells);
12163
12164 free_netdev(dev);
12165
12166 if (atomic_read(&pdev->enable_cnt) == 1)
12167 pci_release_regions(pdev);
12168
12169 pci_disable_device(pdev);
12170 pci_set_drvdata(pdev, NULL);
12171
12172 return rc;
a2fbb9ea
ET
12173}
12174
12175static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
12176{
12177 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
12178 struct bnx2x *bp;
12179
12180 if (!dev) {
cdaa7cb8 12181 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
12182 return;
12183 }
228241eb 12184 bp = netdev_priv(dev);
a2fbb9ea 12185
ec6ba945
VZ
12186 /* Delete storage MAC address */
12187 if (!NO_FCOE(bp)) {
12188 rtnl_lock();
12189 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12190 rtnl_unlock();
12191 }
ec6ba945 12192
98507672
SR
12193#ifdef BCM_DCBNL
12194 /* Delete app tlvs from dcbnl */
12195 bnx2x_dcbnl_update_applist(bp, true);
12196#endif
12197
a2fbb9ea
ET
12198 unregister_netdev(dev);
12199
084d6cbb
VZ
12200 /* Power on: we can't let PCI layer write to us while we are in D3 */
12201 bnx2x_set_power_state(bp, PCI_D0);
12202
d6214d7a
DK
12203 /* Disable MSI/MSI-X */
12204 bnx2x_disable_msi(bp);
f85582f8 12205
084d6cbb
VZ
12206 /* Power off */
12207 bnx2x_set_power_state(bp, PCI_D3hot);
12208
72fd0718 12209 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12210 cancel_delayed_work_sync(&bp->sp_rtnl_task);
72fd0718 12211
a2fbb9ea
ET
12212 if (bp->regview)
12213 iounmap(bp->regview);
12214
12215 if (bp->doorbells)
12216 iounmap(bp->doorbells);
12217
eb2afd4a
DK
12218 bnx2x_release_firmware(bp);
12219
523224a3
DK
12220 bnx2x_free_mem_bp(bp);
12221
a2fbb9ea 12222 free_netdev(dev);
34f80b04
EG
12223
12224 if (atomic_read(&pdev->enable_cnt) == 1)
12225 pci_release_regions(pdev);
12226
a2fbb9ea
ET
12227 pci_disable_device(pdev);
12228 pci_set_drvdata(pdev, NULL);
12229}
12230
f8ef6e44
YG
12231static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12232{
12233 int i;
12234
12235 bp->state = BNX2X_STATE_ERROR;
12236
12237 bp->rx_mode = BNX2X_RX_MODE_NONE;
12238
55c11941
MS
12239 if (CNIC_LOADED(bp))
12240 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12241
619c5cb6
VZ
12242 /* Stop Tx */
12243 bnx2x_tx_disable(bp);
12244
f8ef6e44 12245 bnx2x_netif_stop(bp, 0);
26614ba5
MS
12246 /* Delete all NAPI objects */
12247 bnx2x_del_all_napi(bp);
55c11941
MS
12248 if (CNIC_LOADED(bp))
12249 bnx2x_del_all_napi_cnic(bp);
f8ef6e44
YG
12250
12251 del_timer_sync(&bp->timer);
619c5cb6
VZ
12252
12253 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
12254
12255 /* Release IRQs */
d6214d7a 12256 bnx2x_free_irq(bp);
f8ef6e44 12257
f8ef6e44
YG
12258 /* Free SKBs, SGEs, TPA pool and driver internals */
12259 bnx2x_free_skbs(bp);
523224a3 12260
ec6ba945 12261 for_each_rx_queue(bp, i)
f8ef6e44 12262 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 12263
f8ef6e44
YG
12264 bnx2x_free_mem(bp);
12265
12266 bp->state = BNX2X_STATE_CLOSED;
12267
619c5cb6
VZ
12268 netif_carrier_off(bp->dev);
12269
f8ef6e44
YG
12270 return 0;
12271}
12272
12273static void bnx2x_eeh_recover(struct bnx2x *bp)
12274{
12275 u32 val;
12276
12277 mutex_init(&bp->port.phy_mutex);
12278
f8ef6e44
YG
12279
12280 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12281 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12282 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12283 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
12284}
12285
493adb1f
WX
12286/**
12287 * bnx2x_io_error_detected - called when PCI error is detected
12288 * @pdev: Pointer to PCI device
12289 * @state: The current pci connection state
12290 *
12291 * This function is called after a PCI bus error affecting
12292 * this device has been detected.
12293 */
12294static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12295 pci_channel_state_t state)
12296{
12297 struct net_device *dev = pci_get_drvdata(pdev);
12298 struct bnx2x *bp = netdev_priv(dev);
12299
12300 rtnl_lock();
12301
12302 netif_device_detach(dev);
12303
07ce50e4
DN
12304 if (state == pci_channel_io_perm_failure) {
12305 rtnl_unlock();
12306 return PCI_ERS_RESULT_DISCONNECT;
12307 }
12308
493adb1f 12309 if (netif_running(dev))
f8ef6e44 12310 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
12311
12312 pci_disable_device(pdev);
12313
12314 rtnl_unlock();
12315
12316 /* Request a slot reset */
12317 return PCI_ERS_RESULT_NEED_RESET;
12318}
12319
12320/**
12321 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12322 * @pdev: Pointer to PCI device
12323 *
12324 * Restart the card from scratch, as if from a cold-boot.
12325 */
12326static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12327{
12328 struct net_device *dev = pci_get_drvdata(pdev);
12329 struct bnx2x *bp = netdev_priv(dev);
12330
12331 rtnl_lock();
12332
12333 if (pci_enable_device(pdev)) {
12334 dev_err(&pdev->dev,
12335 "Cannot re-enable PCI device after reset\n");
12336 rtnl_unlock();
12337 return PCI_ERS_RESULT_DISCONNECT;
12338 }
12339
12340 pci_set_master(pdev);
12341 pci_restore_state(pdev);
12342
12343 if (netif_running(dev))
12344 bnx2x_set_power_state(bp, PCI_D0);
12345
12346 rtnl_unlock();
12347
12348 return PCI_ERS_RESULT_RECOVERED;
12349}
12350
12351/**
12352 * bnx2x_io_resume - called when traffic can start flowing again
12353 * @pdev: Pointer to PCI device
12354 *
12355 * This callback is called when the error recovery driver tells us that
12356 * its OK to resume normal operation.
12357 */
12358static void bnx2x_io_resume(struct pci_dev *pdev)
12359{
12360 struct net_device *dev = pci_get_drvdata(pdev);
12361 struct bnx2x *bp = netdev_priv(dev);
12362
72fd0718 12363 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12364 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12365 return;
12366 }
12367
493adb1f
WX
12368 rtnl_lock();
12369
f8ef6e44
YG
12370 bnx2x_eeh_recover(bp);
12371
493adb1f 12372 if (netif_running(dev))
f8ef6e44 12373 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12374
12375 netif_device_attach(dev);
12376
12377 rtnl_unlock();
12378}
12379
3646f0e5 12380static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12381 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12382 .slot_reset = bnx2x_io_slot_reset,
12383 .resume = bnx2x_io_resume,
493adb1f
WX
12384};
12385
a2fbb9ea 12386static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12387 .name = DRV_MODULE_NAME,
12388 .id_table = bnx2x_pci_tbl,
12389 .probe = bnx2x_init_one,
12390 .remove = __devexit_p(bnx2x_remove_one),
12391 .suspend = bnx2x_suspend,
12392 .resume = bnx2x_resume,
12393 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
12394};
12395
12396static int __init bnx2x_init(void)
12397{
dd21ca6d
SG
12398 int ret;
12399
7995c64e 12400 pr_info("%s", version);
938cf541 12401
1cf167f2
EG
12402 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12403 if (bnx2x_wq == NULL) {
7995c64e 12404 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12405 return -ENOMEM;
12406 }
12407
dd21ca6d
SG
12408 ret = pci_register_driver(&bnx2x_pci_driver);
12409 if (ret) {
7995c64e 12410 pr_err("Cannot register driver\n");
dd21ca6d
SG
12411 destroy_workqueue(bnx2x_wq);
12412 }
12413 return ret;
a2fbb9ea
ET
12414}
12415
12416static void __exit bnx2x_cleanup(void)
12417{
452427b0 12418 struct list_head *pos, *q;
a2fbb9ea 12419 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12420
12421 destroy_workqueue(bnx2x_wq);
452427b0
YM
12422
12423 /* Free globablly allocated resources */
12424 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12425 struct bnx2x_prev_path_list *tmp =
12426 list_entry(pos, struct bnx2x_prev_path_list, list);
12427 list_del(pos);
12428 kfree(tmp);
12429 }
a2fbb9ea
ET
12430}
12431
3deb8167
YR
12432void bnx2x_notify_link_changed(struct bnx2x *bp)
12433{
12434 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12435}
12436
a2fbb9ea
ET
12437module_init(bnx2x_init);
12438module_exit(bnx2x_cleanup);
12439
619c5cb6
VZ
12440/**
12441 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12442 *
12443 * @bp: driver handle
12444 * @set: set or clear the CAM entry
12445 *
12446 * This function will wait until the ramdord completion returns.
12447 * Return 0 if success, -ENODEV if ramrod doesn't return.
12448 */
1191cb83 12449static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
12450{
12451 unsigned long ramrod_flags = 0;
12452
12453 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12454 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12455 &bp->iscsi_l2_mac_obj, true,
12456 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12457}
993ac7b5
MC
12458
12459/* count denotes the number of new completions we have seen */
12460static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12461{
12462 struct eth_spe *spe;
a052997e 12463 int cxt_index, cxt_offset;
993ac7b5
MC
12464
12465#ifdef BNX2X_STOP_ON_ERROR
12466 if (unlikely(bp->panic))
12467 return;
12468#endif
12469
12470 spin_lock_bh(&bp->spq_lock);
c2bff63f 12471 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
12472 bp->cnic_spq_pending -= count;
12473
993ac7b5 12474
c2bff63f
DK
12475 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12476 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12477 & SPE_HDR_CONN_TYPE) >>
12478 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
12479 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12480 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
12481
12482 /* Set validation for iSCSI L2 client before sending SETUP
12483 * ramrod
12484 */
12485 if (type == ETH_CONNECTION_TYPE) {
a052997e 12486 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 12487 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 12488 ILT_PAGE_CIDS;
37ae41a9 12489 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
12490 (cxt_index * ILT_PAGE_CIDS);
12491 bnx2x_set_ctx_validation(bp,
12492 &bp->context[cxt_index].
12493 vcxt[cxt_offset].eth,
37ae41a9 12494 BNX2X_ISCSI_ETH_CID(bp));
a052997e 12495 }
c2bff63f
DK
12496 }
12497
619c5cb6
VZ
12498 /*
12499 * There may be not more than 8 L2, not more than 8 L5 SPEs
12500 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
12501 * COMMON ramrods is not more than the EQ and SPQ can
12502 * accommodate.
c2bff63f 12503 */
6e30dd4e
VZ
12504 if (type == ETH_CONNECTION_TYPE) {
12505 if (!atomic_read(&bp->cq_spq_left))
12506 break;
12507 else
12508 atomic_dec(&bp->cq_spq_left);
12509 } else if (type == NONE_CONNECTION_TYPE) {
12510 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
12511 break;
12512 else
6e30dd4e 12513 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
12514 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12515 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
12516 if (bp->cnic_spq_pending >=
12517 bp->cnic_eth_dev.max_kwqe_pending)
12518 break;
12519 else
12520 bp->cnic_spq_pending++;
12521 } else {
12522 BNX2X_ERR("Unknown SPE type: %d\n", type);
12523 bnx2x_panic();
993ac7b5 12524 break;
c2bff63f 12525 }
993ac7b5
MC
12526
12527 spe = bnx2x_sp_get_next(bp);
12528 *spe = *bp->cnic_kwq_cons;
12529
51c1a580 12530 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
12531 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12532
12533 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12534 bp->cnic_kwq_cons = bp->cnic_kwq;
12535 else
12536 bp->cnic_kwq_cons++;
12537 }
12538 bnx2x_sp_prod_update(bp);
12539 spin_unlock_bh(&bp->spq_lock);
12540}
12541
12542static int bnx2x_cnic_sp_queue(struct net_device *dev,
12543 struct kwqe_16 *kwqes[], u32 count)
12544{
12545 struct bnx2x *bp = netdev_priv(dev);
12546 int i;
12547
12548#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
12549 if (unlikely(bp->panic)) {
12550 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 12551 return -EIO;
51c1a580 12552 }
993ac7b5
MC
12553#endif
12554
95c6c616
AE
12555 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12556 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 12557 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
12558 return -EAGAIN;
12559 }
12560
993ac7b5
MC
12561 spin_lock_bh(&bp->spq_lock);
12562
12563 for (i = 0; i < count; i++) {
12564 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12565
12566 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12567 break;
12568
12569 *bp->cnic_kwq_prod = *spe;
12570
12571 bp->cnic_kwq_pending++;
12572
51c1a580 12573 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 12574 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
12575 spe->data.update_data_addr.hi,
12576 spe->data.update_data_addr.lo,
993ac7b5
MC
12577 bp->cnic_kwq_pending);
12578
12579 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12580 bp->cnic_kwq_prod = bp->cnic_kwq;
12581 else
12582 bp->cnic_kwq_prod++;
12583 }
12584
12585 spin_unlock_bh(&bp->spq_lock);
12586
12587 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12588 bnx2x_cnic_sp_post(bp, 0);
12589
12590 return i;
12591}
12592
12593static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12594{
12595 struct cnic_ops *c_ops;
12596 int rc = 0;
12597
12598 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
12599 c_ops = rcu_dereference_protected(bp->cnic_ops,
12600 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
12601 if (c_ops)
12602 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12603 mutex_unlock(&bp->cnic_mutex);
12604
12605 return rc;
12606}
12607
12608static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12609{
12610 struct cnic_ops *c_ops;
12611 int rc = 0;
12612
12613 rcu_read_lock();
12614 c_ops = rcu_dereference(bp->cnic_ops);
12615 if (c_ops)
12616 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12617 rcu_read_unlock();
12618
12619 return rc;
12620}
12621
12622/*
12623 * for commands that have no data
12624 */
9f6c9258 12625int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
12626{
12627 struct cnic_ctl_info ctl = {0};
12628
12629 ctl.cmd = cmd;
12630
12631 return bnx2x_cnic_ctl_send(bp, &ctl);
12632}
12633
619c5cb6 12634static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 12635{
619c5cb6 12636 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
12637
12638 /* first we tell CNIC and only then we count this as a completion */
12639 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
12640 ctl.data.comp.cid = cid;
619c5cb6 12641 ctl.data.comp.error = err;
993ac7b5
MC
12642
12643 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 12644 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
12645}
12646
619c5cb6
VZ
12647
12648/* Called with netif_addr_lock_bh() taken.
12649 * Sets an rx_mode config for an iSCSI ETH client.
12650 * Doesn't block.
12651 * Completion should be checked outside.
12652 */
12653static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
12654{
12655 unsigned long accept_flags = 0, ramrod_flags = 0;
12656 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12657 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
12658
12659 if (start) {
12660 /* Start accepting on iSCSI L2 ring. Accept all multicasts
12661 * because it's the only way for UIO Queue to accept
12662 * multicasts (in non-promiscuous mode only one Queue per
12663 * function will receive multicast packets (leading in our
12664 * case).
12665 */
12666 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
12667 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
12668 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
12669 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
12670
12671 /* Clear STOP_PENDING bit if START is requested */
12672 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
12673
12674 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
12675 } else
12676 /* Clear START_PENDING bit if STOP is requested */
12677 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
12678
12679 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
12680 set_bit(sched_state, &bp->sp_state);
12681 else {
12682 __set_bit(RAMROD_RX, &ramrod_flags);
12683 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
12684 ramrod_flags);
12685 }
12686}
12687
12688
993ac7b5
MC
12689static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
12690{
12691 struct bnx2x *bp = netdev_priv(dev);
12692 int rc = 0;
12693
12694 switch (ctl->cmd) {
12695 case DRV_CTL_CTXTBL_WR_CMD: {
12696 u32 index = ctl->data.io.offset;
12697 dma_addr_t addr = ctl->data.io.dma_addr;
12698
12699 bnx2x_ilt_wr(bp, index, addr);
12700 break;
12701 }
12702
c2bff63f
DK
12703 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
12704 int count = ctl->data.credit.credit_count;
993ac7b5
MC
12705
12706 bnx2x_cnic_sp_post(bp, count);
12707 break;
12708 }
12709
12710 /* rtnl_lock is held. */
12711 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
12712 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12713 unsigned long sp_bits = 0;
12714
12715 /* Configure the iSCSI classification object */
12716 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
12717 cp->iscsi_l2_client_id,
12718 cp->iscsi_l2_cid, BP_FUNC(bp),
12719 bnx2x_sp(bp, mac_rdata),
12720 bnx2x_sp_mapping(bp, mac_rdata),
12721 BNX2X_FILTER_MAC_PENDING,
12722 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
12723 &bp->macs_pool);
ec6ba945 12724
523224a3 12725 /* Set iSCSI MAC address */
619c5cb6
VZ
12726 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
12727 if (rc)
12728 break;
523224a3
DK
12729
12730 mmiowb();
12731 barrier();
12732
619c5cb6
VZ
12733 /* Start accepting on iSCSI L2 ring */
12734
12735 netif_addr_lock_bh(dev);
12736 bnx2x_set_iscsi_eth_rx_mode(bp, true);
12737 netif_addr_unlock_bh(dev);
12738
12739 /* bits to wait on */
12740 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12741 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
12742
12743 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12744 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 12745
993ac7b5
MC
12746 break;
12747 }
12748
12749 /* rtnl_lock is held. */
12750 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 12751 unsigned long sp_bits = 0;
993ac7b5 12752
523224a3 12753 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
12754 netif_addr_lock_bh(dev);
12755 bnx2x_set_iscsi_eth_rx_mode(bp, false);
12756 netif_addr_unlock_bh(dev);
12757
12758 /* bits to wait on */
12759 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12760 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
12761
12762 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12763 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
12764
12765 mmiowb();
12766 barrier();
12767
12768 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
12769 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
12770 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
12771 break;
12772 }
c2bff63f
DK
12773 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
12774 int count = ctl->data.credit.credit_count;
12775
12776 smp_mb__before_atomic_inc();
6e30dd4e 12777 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
12778 smp_mb__after_atomic_inc();
12779 break;
12780 }
1d187b34 12781 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 12782 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
12783
12784 if (CHIP_IS_E3(bp)) {
12785 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
12786 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12787 int path = BP_PATH(bp);
12788 int port = BP_PORT(bp);
12789 int i;
12790 u32 scratch_offset;
12791 u32 *host_addr;
1d187b34 12792
2e499d3c 12793 /* first write capability to shmem2 */
1d187b34
BW
12794 if (ulp_type == CNIC_ULP_ISCSI)
12795 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12796 else if (ulp_type == CNIC_ULP_FCOE)
12797 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12798 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
12799
12800 if ((ulp_type != CNIC_ULP_FCOE) ||
12801 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
12802 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
12803 break;
12804
12805 /* if reached here - should write fcoe capabilities */
12806 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
12807 if (!scratch_offset)
12808 break;
12809 scratch_offset += offsetof(struct glob_ncsi_oem_data,
12810 fcoe_features[path][port]);
12811 host_addr = (u32 *) &(ctl->data.register_data.
12812 fcoe_features);
12813 for (i = 0; i < sizeof(struct fcoe_capabilities);
12814 i += 4)
12815 REG_WR(bp, scratch_offset + i,
12816 *(host_addr + i/4));
1d187b34
BW
12817 }
12818 break;
12819 }
2e499d3c 12820
1d187b34
BW
12821 case DRV_CTL_ULP_UNREGISTER_CMD: {
12822 int ulp_type = ctl->data.ulp_type;
12823
12824 if (CHIP_IS_E3(bp)) {
12825 int idx = BP_FW_MB_IDX(bp);
12826 u32 cap;
12827
12828 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12829 if (ulp_type == CNIC_ULP_ISCSI)
12830 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12831 else if (ulp_type == CNIC_ULP_FCOE)
12832 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12833 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12834 }
12835 break;
12836 }
993ac7b5
MC
12837
12838 default:
12839 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12840 rc = -EINVAL;
12841 }
12842
12843 return rc;
12844}
12845
9f6c9258 12846void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
12847{
12848 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12849
12850 if (bp->flags & USING_MSIX_FLAG) {
12851 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12852 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12853 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12854 } else {
12855 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12856 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12857 }
619c5cb6 12858 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
12859 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12860 else
12861 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12862
619c5cb6
VZ
12863 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12864 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
12865 cp->irq_arr[1].status_blk = bp->def_status_blk;
12866 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 12867 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
12868
12869 cp->num_irq = 2;
12870}
12871
37ae41a9
MS
12872void bnx2x_setup_cnic_info(struct bnx2x *bp)
12873{
12874 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12875
12876
12877 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12878 bnx2x_cid_ilt_lines(bp);
12879 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12880 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
12881 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
12882
12883 if (NO_ISCSI_OOO(bp))
12884 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12885}
12886
993ac7b5
MC
12887static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12888 void *data)
12889{
12890 struct bnx2x *bp = netdev_priv(dev);
12891 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
12892 int rc;
12893
12894 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 12895
51c1a580
MS
12896 if (ops == NULL) {
12897 BNX2X_ERR("NULL ops received\n");
993ac7b5 12898 return -EINVAL;
51c1a580 12899 }
993ac7b5 12900
55c11941
MS
12901 if (!CNIC_SUPPORT(bp)) {
12902 BNX2X_ERR("Can't register CNIC when not supported\n");
12903 return -EOPNOTSUPP;
12904 }
12905
12906 if (!CNIC_LOADED(bp)) {
12907 rc = bnx2x_load_cnic(bp);
12908 if (rc) {
12909 BNX2X_ERR("CNIC-related load failed\n");
12910 return rc;
12911 }
12912
12913 }
12914
12915 bp->cnic_enabled = true;
12916
993ac7b5
MC
12917 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12918 if (!bp->cnic_kwq)
12919 return -ENOMEM;
12920
12921 bp->cnic_kwq_cons = bp->cnic_kwq;
12922 bp->cnic_kwq_prod = bp->cnic_kwq;
12923 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12924
12925 bp->cnic_spq_pending = 0;
12926 bp->cnic_kwq_pending = 0;
12927
12928 bp->cnic_data = data;
12929
12930 cp->num_irq = 0;
619c5cb6 12931 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 12932 cp->iro_arr = bp->iro_arr;
993ac7b5 12933
993ac7b5 12934 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 12935
993ac7b5
MC
12936 rcu_assign_pointer(bp->cnic_ops, ops);
12937
12938 return 0;
12939}
12940
12941static int bnx2x_unregister_cnic(struct net_device *dev)
12942{
12943 struct bnx2x *bp = netdev_priv(dev);
12944 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12945
12946 mutex_lock(&bp->cnic_mutex);
993ac7b5 12947 cp->drv_state = 0;
2cfa5a04 12948 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
12949 mutex_unlock(&bp->cnic_mutex);
12950 synchronize_rcu();
12951 kfree(bp->cnic_kwq);
12952 bp->cnic_kwq = NULL;
12953
12954 return 0;
12955}
12956
12957struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12958{
12959 struct bnx2x *bp = netdev_priv(dev);
12960 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12961
2ba45142
VZ
12962 /* If both iSCSI and FCoE are disabled - return NULL in
12963 * order to indicate CNIC that it should not try to work
12964 * with this device.
12965 */
12966 if (NO_ISCSI(bp) && NO_FCOE(bp))
12967 return NULL;
12968
993ac7b5
MC
12969 cp->drv_owner = THIS_MODULE;
12970 cp->chip_id = CHIP_ID(bp);
12971 cp->pdev = bp->pdev;
12972 cp->io_base = bp->regview;
12973 cp->io_base2 = bp->doorbells;
12974 cp->max_kwqe_pending = 8;
523224a3 12975 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
12976 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12977 bnx2x_cid_ilt_lines(bp);
993ac7b5 12978 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 12979 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
12980 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12981 cp->drv_ctl = bnx2x_drv_ctl;
12982 cp->drv_register_cnic = bnx2x_register_cnic;
12983 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 12984 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
12985 cp->iscsi_l2_client_id =
12986 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 12987 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 12988
2ba45142
VZ
12989 if (NO_ISCSI_OOO(bp))
12990 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12991
12992 if (NO_ISCSI(bp))
12993 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12994
12995 if (NO_FCOE(bp))
12996 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12997
51c1a580
MS
12998 BNX2X_DEV_INFO(
12999 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13000 cp->ctx_blk_size,
13001 cp->ctx_tbl_offset,
13002 cp->ctx_tbl_len,
13003 cp->starting_cid);
993ac7b5
MC
13004 return cp;
13005}
13006EXPORT_SYMBOL(bnx2x_cnic_probe);
13007
94a78b79 13008