net/mlx4_en: Set number of rx/tx channels using ethtool
[deliverable/linux.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
c18487ee 2035static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
a2fbb9ea 2036{
c18487ee
YR
2037 u32 spio_mask = (1 << spio_num);
2038 u32 spio_reg;
a2fbb9ea 2039
c18487ee
YR
2040 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2041 (spio_num > MISC_REGISTERS_SPIO_7)) {
2042 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2043 return -EINVAL;
a2fbb9ea
ET
2044 }
2045
4a37fb66 2046 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee
YR
2047 /* read SPIO and mask except the float bits */
2048 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
a2fbb9ea 2049
c18487ee 2050 switch (mode) {
6378c025 2051 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
51c1a580 2052 DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
c18487ee
YR
2053 /* clear FLOAT and set CLR */
2054 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2055 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2056 break;
a2fbb9ea 2057
6378c025 2058 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
51c1a580 2059 DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
c18487ee
YR
2060 /* clear FLOAT and set SET */
2061 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2062 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2063 break;
a2fbb9ea 2064
c18487ee 2065 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
51c1a580 2066 DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
c18487ee
YR
2067 /* set FLOAT */
2068 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2069 break;
a2fbb9ea 2070
c18487ee
YR
2071 default:
2072 break;
a2fbb9ea
ET
2073 }
2074
c18487ee 2075 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2076 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2077
a2fbb9ea
ET
2078 return 0;
2079}
2080
9f6c9258 2081void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2082{
a22f0788 2083 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2084 switch (bp->link_vars.ieee_fc &
2085 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2086 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2087 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2088 ADVERTISED_Pause);
c18487ee 2089 break;
356e2385 2090
c18487ee 2091 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2092 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2093 ADVERTISED_Pause);
c18487ee 2094 break;
356e2385 2095
c18487ee 2096 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2097 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2098 break;
356e2385 2099
c18487ee 2100 default:
a22f0788 2101 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2102 ADVERTISED_Pause);
c18487ee
YR
2103 break;
2104 }
2105}
f1410647 2106
9f6c9258 2107u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
c18487ee 2108{
19680c48
EG
2109 if (!BP_NOMCP(bp)) {
2110 u8 rc;
a22f0788
YR
2111 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2112 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
1cb0c788
YR
2113 /*
2114 * Initialize link parameters structure variables
2115 * It is recommended to turn off RX FC for jumbo frames
2116 * for better performance
2117 */
2118 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
c0700f90 2119 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
8c99e7b0 2120 else
c0700f90 2121 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
a2fbb9ea 2122
4a37fb66 2123 bnx2x_acquire_phy_lock(bp);
b5bf9068 2124
a22f0788 2125 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2126 struct link_params *lp = &bp->link_params;
2127 lp->loopback_mode = LOOPBACK_XGXS;
2128 /* do PHY loopback at 10G speed, if possible */
2129 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2130 if (lp->speed_cap_mask[cfx_idx] &
2131 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2132 lp->req_line_speed[cfx_idx] =
2133 SPEED_10000;
2134 else
2135 lp->req_line_speed[cfx_idx] =
2136 SPEED_1000;
2137 }
a22f0788 2138 }
b5bf9068 2139
8970b2e4
MS
2140 if (load_mode == LOAD_LOOPBACK_EXT) {
2141 struct link_params *lp = &bp->link_params;
2142 lp->loopback_mode = LOOPBACK_EXT;
2143 }
2144
19680c48 2145 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2146
4a37fb66 2147 bnx2x_release_phy_lock(bp);
a2fbb9ea 2148
3c96c68b
EG
2149 bnx2x_calc_fc_adv(bp);
2150
b5bf9068
EG
2151 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2152 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2153 bnx2x_link_report(bp);
3deb8167
YR
2154 } else
2155 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2156 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2157 return rc;
2158 }
f5372251 2159 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2160 return -EINVAL;
a2fbb9ea
ET
2161}
2162
9f6c9258 2163void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2164{
19680c48 2165 if (!BP_NOMCP(bp)) {
4a37fb66 2166 bnx2x_acquire_phy_lock(bp);
19680c48 2167 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2168 bnx2x_release_phy_lock(bp);
a2fbb9ea 2169
19680c48
EG
2170 bnx2x_calc_fc_adv(bp);
2171 } else
f5372251 2172 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2173}
a2fbb9ea 2174
c18487ee
YR
2175static void bnx2x__link_reset(struct bnx2x *bp)
2176{
19680c48 2177 if (!BP_NOMCP(bp)) {
4a37fb66 2178 bnx2x_acquire_phy_lock(bp);
5d07d868 2179 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2180 bnx2x_release_phy_lock(bp);
19680c48 2181 } else
f5372251 2182 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2183}
a2fbb9ea 2184
5d07d868
YM
2185void bnx2x_force_link_reset(struct bnx2x *bp)
2186{
2187 bnx2x_acquire_phy_lock(bp);
2188 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2189 bnx2x_release_phy_lock(bp);
2190}
2191
a22f0788 2192u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2193{
2145a920 2194 u8 rc = 0;
a2fbb9ea 2195
2145a920
VZ
2196 if (!BP_NOMCP(bp)) {
2197 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2198 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2199 is_serdes);
2145a920
VZ
2200 bnx2x_release_phy_lock(bp);
2201 } else
2202 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2203
c18487ee
YR
2204 return rc;
2205}
a2fbb9ea 2206
34f80b04 2207
2691d51d
EG
2208/* Calculates the sum of vn_min_rates.
2209 It's needed for further normalizing of the min_rates.
2210 Returns:
2211 sum of vn_min_rates.
2212 or
2213 0 - if all the min_rates are 0.
2214 In the later case fainess algorithm should be deactivated.
2215 If not all min_rates are zero then those that are zeroes will be set to 1.
2216 */
b475d78f
YM
2217static void bnx2x_calc_vn_min(struct bnx2x *bp,
2218 struct cmng_init_input *input)
2691d51d
EG
2219{
2220 int all_zero = 1;
2691d51d
EG
2221 int vn;
2222
3395a033 2223 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2224 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2225 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2226 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2227
2228 /* Skip hidden vns */
2229 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2230 vn_min_rate = 0;
2691d51d 2231 /* If min rate is zero - set it to 1 */
b475d78f 2232 else if (!vn_min_rate)
2691d51d
EG
2233 vn_min_rate = DEF_MIN_RATE;
2234 else
2235 all_zero = 0;
2236
b475d78f 2237 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2238 }
2239
30ae438b
DK
2240 /* if ETS or all min rates are zeros - disable fairness */
2241 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2242 input->flags.cmng_enables &=
30ae438b
DK
2243 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2244 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2245 } else if (all_zero) {
b475d78f 2246 input->flags.cmng_enables &=
b015e3d1 2247 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2248 DP(NETIF_MSG_IFUP,
2249 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2250 } else
b475d78f 2251 input->flags.cmng_enables |=
b015e3d1 2252 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2253}
2254
b475d78f
YM
2255static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2256 struct cmng_init_input *input)
34f80b04 2257{
b475d78f 2258 u16 vn_max_rate;
f2e0899f 2259 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2260
b475d78f 2261 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2262 vn_max_rate = 0;
b475d78f 2263 else {
faa6fcbb
DK
2264 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2265
b475d78f 2266 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2267 /* maxCfg in percents of linkspeed */
2268 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2269 } else /* SD modes */
faa6fcbb
DK
2270 /* maxCfg is absolute in 100Mb units */
2271 vn_max_rate = maxCfg * 100;
34f80b04 2272 }
f85582f8 2273
b475d78f 2274 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2275
b475d78f 2276 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2277}
f85582f8 2278
b475d78f 2279
523224a3
DK
2280static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2281{
2282 if (CHIP_REV_IS_SLOW(bp))
2283 return CMNG_FNS_NONE;
fb3bff17 2284 if (IS_MF(bp))
523224a3
DK
2285 return CMNG_FNS_MINMAX;
2286
2287 return CMNG_FNS_NONE;
2288}
2289
2ae17f66 2290void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2291{
0793f83f 2292 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2293
2294 if (BP_NOMCP(bp))
2295 return; /* what should be the default bvalue in this case */
2296
0793f83f
DK
2297 /* For 2 port configuration the absolute function number formula
2298 * is:
2299 * abs_func = 2 * vn + BP_PORT + BP_PATH
2300 *
2301 * and there are 4 functions per port
2302 *
2303 * For 4 port configuration it is
2304 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2305 *
2306 * and there are 2 functions per port
2307 */
3395a033 2308 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2309 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2310
2311 if (func >= E1H_FUNC_MAX)
2312 break;
2313
f2e0899f 2314 bp->mf_config[vn] =
523224a3
DK
2315 MF_CFG_RD(bp, func_mf_config[func].config);
2316 }
a3348722
BW
2317 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2318 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2319 bp->flags |= MF_FUNC_DIS;
2320 } else {
2321 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2322 bp->flags &= ~MF_FUNC_DIS;
2323 }
523224a3
DK
2324}
2325
2326static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2327{
b475d78f
YM
2328 struct cmng_init_input input;
2329 memset(&input, 0, sizeof(struct cmng_init_input));
2330
2331 input.port_rate = bp->link_vars.line_speed;
523224a3
DK
2332
2333 if (cmng_type == CMNG_FNS_MINMAX) {
2334 int vn;
2335
523224a3
DK
2336 /* read mf conf from shmem */
2337 if (read_cfg)
2338 bnx2x_read_mf_cfg(bp);
2339
523224a3 2340 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2341 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2342
2343 /* calculate and set min-max rate for each vn */
c4154f25 2344 if (bp->port.pmf)
3395a033 2345 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2346 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2347
2348 /* always enable rate shaping and fairness */
b475d78f 2349 input.flags.cmng_enables |=
523224a3 2350 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2351
2352 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2353 return;
2354 }
2355
2356 /* rate shaping and fairness are disabled */
2357 DP(NETIF_MSG_IFUP,
2358 "rate shaping and fairness are disabled\n");
2359}
34f80b04 2360
1191cb83
ED
2361static void storm_memset_cmng(struct bnx2x *bp,
2362 struct cmng_init *cmng,
2363 u8 port)
2364{
2365 int vn;
2366 size_t size = sizeof(struct cmng_struct_per_port);
2367
2368 u32 addr = BAR_XSTRORM_INTMEM +
2369 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2370
2371 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2372
2373 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2374 int func = func_by_vn(bp, vn);
2375
2376 addr = BAR_XSTRORM_INTMEM +
2377 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2378 size = sizeof(struct rate_shaping_vars_per_vn);
2379 __storm_memset_struct(bp, addr, size,
2380 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2381
2382 addr = BAR_XSTRORM_INTMEM +
2383 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2384 size = sizeof(struct fairness_vars_per_vn);
2385 __storm_memset_struct(bp, addr, size,
2386 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2387 }
2388}
2389
c18487ee
YR
2390/* This function is called upon link interrupt */
2391static void bnx2x_link_attn(struct bnx2x *bp)
2392{
bb2a0f7a
YG
2393 /* Make sure that we are synced with the current statistics */
2394 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2395
c18487ee 2396 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2397
bb2a0f7a
YG
2398 if (bp->link_vars.link_up) {
2399
1c06328c 2400 /* dropless flow control */
f2e0899f 2401 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2402 int port = BP_PORT(bp);
2403 u32 pause_enabled = 0;
2404
2405 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2406 pause_enabled = 1;
2407
2408 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2409 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2410 pause_enabled);
2411 }
2412
619c5cb6 2413 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2414 struct host_port_stats *pstats;
2415
2416 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2417 /* reset old mac stats */
bb2a0f7a
YG
2418 memset(&(pstats->mac_stx[0]), 0,
2419 sizeof(struct mac_stx));
2420 }
f34d28ea 2421 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2422 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2423 }
2424
f2e0899f
DK
2425 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2426 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2427
f2e0899f
DK
2428 if (cmng_fns != CMNG_FNS_NONE) {
2429 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2430 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2431 } else
2432 /* rate shaping and fairness are disabled */
2433 DP(NETIF_MSG_IFUP,
2434 "single function mode without fairness\n");
34f80b04 2435 }
9fdc3e95 2436
2ae17f66
VZ
2437 __bnx2x_link_report(bp);
2438
9fdc3e95
DK
2439 if (IS_MF(bp))
2440 bnx2x_link_sync_notify(bp);
c18487ee 2441}
a2fbb9ea 2442
9f6c9258 2443void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2444{
2ae17f66 2445 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2446 return;
a2fbb9ea 2447
00253a8c
DK
2448 /* read updated dcb configuration */
2449 bnx2x_dcbx_pmf_update(bp);
2450
c18487ee 2451 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2452
bb2a0f7a
YG
2453 if (bp->link_vars.link_up)
2454 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2455 else
2456 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2457
c18487ee
YR
2458 /* indicate link status */
2459 bnx2x_link_report(bp);
a2fbb9ea 2460}
a2fbb9ea 2461
a3348722
BW
2462static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2463 u16 vlan_val, u8 allowed_prio)
2464{
2465 struct bnx2x_func_state_params func_params = {0};
2466 struct bnx2x_func_afex_update_params *f_update_params =
2467 &func_params.params.afex_update;
2468
2469 func_params.f_obj = &bp->func_obj;
2470 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2471
2472 /* no need to wait for RAMROD completion, so don't
2473 * set RAMROD_COMP_WAIT flag
2474 */
2475
2476 f_update_params->vif_id = vifid;
2477 f_update_params->afex_default_vlan = vlan_val;
2478 f_update_params->allowed_priorities = allowed_prio;
2479
2480 /* if ramrod can not be sent, response to MCP immediately */
2481 if (bnx2x_func_state_change(bp, &func_params) < 0)
2482 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2483
2484 return 0;
2485}
2486
2487static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2488 u16 vif_index, u8 func_bit_map)
2489{
2490 struct bnx2x_func_state_params func_params = {0};
2491 struct bnx2x_func_afex_viflists_params *update_params =
2492 &func_params.params.afex_viflists;
2493 int rc;
2494 u32 drv_msg_code;
2495
2496 /* validate only LIST_SET and LIST_GET are received from switch */
2497 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2498 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2499 cmd_type);
2500
2501 func_params.f_obj = &bp->func_obj;
2502 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2503
2504 /* set parameters according to cmd_type */
2505 update_params->afex_vif_list_command = cmd_type;
2506 update_params->vif_list_index = cpu_to_le16(vif_index);
2507 update_params->func_bit_map =
2508 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2509 update_params->func_to_clear = 0;
2510 drv_msg_code =
2511 (cmd_type == VIF_LIST_RULE_GET) ?
2512 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2513 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2514
2515 /* if ramrod can not be sent, respond to MCP immediately for
2516 * SET and GET requests (other are not triggered from MCP)
2517 */
2518 rc = bnx2x_func_state_change(bp, &func_params);
2519 if (rc < 0)
2520 bnx2x_fw_command(bp, drv_msg_code, 0);
2521
2522 return 0;
2523}
2524
2525static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2526{
2527 struct afex_stats afex_stats;
2528 u32 func = BP_ABS_FUNC(bp);
2529 u32 mf_config;
2530 u16 vlan_val;
2531 u32 vlan_prio;
2532 u16 vif_id;
2533 u8 allowed_prio;
2534 u8 vlan_mode;
2535 u32 addr_to_write, vifid, addrs, stats_type, i;
2536
2537 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2538 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2539 DP(BNX2X_MSG_MCP,
2540 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2541 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2542 }
2543
2544 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2545 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2546 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2547 DP(BNX2X_MSG_MCP,
2548 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2549 vifid, addrs);
2550 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2551 addrs);
2552 }
2553
2554 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2555 addr_to_write = SHMEM2_RD(bp,
2556 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2557 stats_type = SHMEM2_RD(bp,
2558 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2559
2560 DP(BNX2X_MSG_MCP,
2561 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2562 addr_to_write);
2563
2564 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2565
2566 /* write response to scratchpad, for MCP */
2567 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2568 REG_WR(bp, addr_to_write + i*sizeof(u32),
2569 *(((u32 *)(&afex_stats))+i));
2570
2571 /* send ack message to MCP */
2572 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2573 }
2574
2575 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2576 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2577 bp->mf_config[BP_VN(bp)] = mf_config;
2578 DP(BNX2X_MSG_MCP,
2579 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2580 mf_config);
2581
2582 /* if VIF_SET is "enabled" */
2583 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2584 /* set rate limit directly to internal RAM */
2585 struct cmng_init_input cmng_input;
2586 struct rate_shaping_vars_per_vn m_rs_vn;
2587 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2588 u32 addr = BAR_XSTRORM_INTMEM +
2589 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2590
2591 bp->mf_config[BP_VN(bp)] = mf_config;
2592
2593 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2594 m_rs_vn.vn_counter.rate =
2595 cmng_input.vnic_max_rate[BP_VN(bp)];
2596 m_rs_vn.vn_counter.quota =
2597 (m_rs_vn.vn_counter.rate *
2598 RS_PERIODIC_TIMEOUT_USEC) / 8;
2599
2600 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2601
2602 /* read relevant values from mf_cfg struct in shmem */
2603 vif_id =
2604 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2605 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2606 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2607 vlan_val =
2608 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2609 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2610 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2611 vlan_prio = (mf_config &
2612 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2613 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2614 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2615 vlan_mode =
2616 (MF_CFG_RD(bp,
2617 func_mf_config[func].afex_config) &
2618 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2619 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2620 allowed_prio =
2621 (MF_CFG_RD(bp,
2622 func_mf_config[func].afex_config) &
2623 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2624 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2625
2626 /* send ramrod to FW, return in case of failure */
2627 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2628 allowed_prio))
2629 return;
2630
2631 bp->afex_def_vlan_tag = vlan_val;
2632 bp->afex_vlan_mode = vlan_mode;
2633 } else {
2634 /* notify link down because BP->flags is disabled */
2635 bnx2x_link_report(bp);
2636
2637 /* send INVALID VIF ramrod to FW */
2638 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2639
2640 /* Reset the default afex VLAN */
2641 bp->afex_def_vlan_tag = -1;
2642 }
2643 }
2644}
2645
34f80b04
EG
2646static void bnx2x_pmf_update(struct bnx2x *bp)
2647{
2648 int port = BP_PORT(bp);
2649 u32 val;
2650
2651 bp->port.pmf = 1;
51c1a580 2652 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2653
3deb8167
YR
2654 /*
2655 * We need the mb() to ensure the ordering between the writing to
2656 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2657 */
2658 smp_mb();
2659
2660 /* queue a periodic task */
2661 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2662
ef01854e
DK
2663 bnx2x_dcbx_pmf_update(bp);
2664
34f80b04 2665 /* enable nig attention */
3395a033 2666 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2667 if (bp->common.int_block == INT_BLOCK_HC) {
2668 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2669 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2670 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2671 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2672 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2673 }
bb2a0f7a
YG
2674
2675 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2676}
2677
c18487ee 2678/* end of Link */
a2fbb9ea
ET
2679
2680/* slow path */
2681
2682/*
2683 * General service functions
2684 */
2685
2691d51d 2686/* send the MCP a request, block until there is a reply */
a22f0788 2687u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2688{
f2e0899f 2689 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2690 u32 seq;
2691d51d
EG
2691 u32 rc = 0;
2692 u32 cnt = 1;
2693 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2694
c4ff7cbf 2695 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2696 seq = ++bp->fw_seq;
f2e0899f
DK
2697 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2698 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2699
754a2f52
DK
2700 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2701 (command | seq), param);
2691d51d
EG
2702
2703 do {
2704 /* let the FW do it's magic ... */
2705 msleep(delay);
2706
f2e0899f 2707 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2708
c4ff7cbf
EG
2709 /* Give the FW up to 5 second (500*10ms) */
2710 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2711
2712 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2713 cnt*delay, rc, seq);
2714
2715 /* is this a reply to our command? */
2716 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2717 rc &= FW_MSG_CODE_MASK;
2718 else {
2719 /* FW BUG! */
2720 BNX2X_ERR("FW failed to respond!\n");
2721 bnx2x_fw_dump(bp);
2722 rc = 0;
2723 }
c4ff7cbf 2724 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2725
2726 return rc;
2727}
2728
ec6ba945 2729
1191cb83
ED
2730static void storm_memset_func_cfg(struct bnx2x *bp,
2731 struct tstorm_eth_function_common_config *tcfg,
2732 u16 abs_fid)
2733{
2734 size_t size = sizeof(struct tstorm_eth_function_common_config);
2735
2736 u32 addr = BAR_TSTRORM_INTMEM +
2737 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2738
2739 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2740}
2741
619c5cb6
VZ
2742void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2743{
2744 if (CHIP_IS_E1x(bp)) {
2745 struct tstorm_eth_function_common_config tcfg = {0};
2746
2747 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2748 }
2749
2750 /* Enable the function in the FW */
2751 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2752 storm_memset_func_en(bp, p->func_id, 1);
2753
2754 /* spq */
2755 if (p->func_flgs & FUNC_FLG_SPQ) {
2756 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2757 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2758 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2759 }
2760}
2761
6383c0b3
AE
2762/**
2763 * bnx2x_get_tx_only_flags - Return common flags
2764 *
2765 * @bp device handle
2766 * @fp queue handle
2767 * @zero_stats TRUE if statistics zeroing is needed
2768 *
2769 * Return the flags that are common for the Tx-only and not normal connections.
2770 */
1191cb83
ED
2771static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2772 struct bnx2x_fastpath *fp,
2773 bool zero_stats)
28912902 2774{
619c5cb6
VZ
2775 unsigned long flags = 0;
2776
2777 /* PF driver will always initialize the Queue to an ACTIVE state */
2778 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2779
6383c0b3
AE
2780 /* tx only connections collect statistics (on the same index as the
2781 * parent connection). The statistics are zeroed when the parent
2782 * connection is initialized.
2783 */
50f0a562
BW
2784
2785 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2786 if (zero_stats)
2787 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2788
6383c0b3
AE
2789
2790 return flags;
2791}
2792
1191cb83
ED
2793static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2794 struct bnx2x_fastpath *fp,
2795 bool leading)
6383c0b3
AE
2796{
2797 unsigned long flags = 0;
2798
619c5cb6
VZ
2799 /* calculate other queue flags */
2800 if (IS_MF_SD(bp))
2801 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2802
a3348722 2803 if (IS_FCOE_FP(fp)) {
619c5cb6 2804 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
2805 /* For FCoE - force usage of default priority (for afex) */
2806 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2807 }
523224a3 2808
f5219d8e 2809 if (!fp->disable_tpa) {
619c5cb6 2810 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2811 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2812 if (fp->mode == TPA_MODE_GRO)
2813 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2814 }
619c5cb6 2815
619c5cb6
VZ
2816 if (leading) {
2817 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2818 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2819 }
523224a3 2820
619c5cb6
VZ
2821 /* Always set HW VLAN stripping */
2822 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 2823
a3348722
BW
2824 /* configure silent vlan removal */
2825 if (IS_MF_AFEX(bp))
2826 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
2827
6383c0b3
AE
2828
2829 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
2830}
2831
619c5cb6 2832static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
2833 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2834 u8 cos)
619c5cb6
VZ
2835{
2836 gen_init->stat_id = bnx2x_stats_id(fp);
2837 gen_init->spcl_id = fp->cl_id;
2838
2839 /* Always use mini-jumbo MTU for FCoE L2 ring */
2840 if (IS_FCOE_FP(fp))
2841 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2842 else
2843 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
2844
2845 gen_init->cos = cos;
619c5cb6
VZ
2846}
2847
2848static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 2849 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 2850 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 2851{
619c5cb6 2852 u8 max_sge = 0;
523224a3
DK
2853 u16 sge_sz = 0;
2854 u16 tpa_agg_size = 0;
2855
523224a3 2856 if (!fp->disable_tpa) {
dfacf138
DK
2857 pause->sge_th_lo = SGE_TH_LO(bp);
2858 pause->sge_th_hi = SGE_TH_HI(bp);
2859
2860 /* validate SGE ring has enough to cross high threshold */
2861 WARN_ON(bp->dropless_fc &&
2862 pause->sge_th_hi + FW_PREFETCH_CNT >
2863 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2864
523224a3
DK
2865 tpa_agg_size = min_t(u32,
2866 (min_t(u32, 8, MAX_SKB_FRAGS) *
2867 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2868 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2869 SGE_PAGE_SHIFT;
2870 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2871 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2872 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2873 0xffff);
2874 }
2875
2876 /* pause - not for e1 */
2877 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
2878 pause->bd_th_lo = BD_TH_LO(bp);
2879 pause->bd_th_hi = BD_TH_HI(bp);
2880
2881 pause->rcq_th_lo = RCQ_TH_LO(bp);
2882 pause->rcq_th_hi = RCQ_TH_HI(bp);
2883 /*
2884 * validate that rings have enough entries to cross
2885 * high thresholds
2886 */
2887 WARN_ON(bp->dropless_fc &&
2888 pause->bd_th_hi + FW_PREFETCH_CNT >
2889 bp->rx_ring_size);
2890 WARN_ON(bp->dropless_fc &&
2891 pause->rcq_th_hi + FW_PREFETCH_CNT >
2892 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 2893
523224a3
DK
2894 pause->pri_map = 1;
2895 }
2896
2897 /* rxq setup */
523224a3
DK
2898 rxq_init->dscr_map = fp->rx_desc_mapping;
2899 rxq_init->sge_map = fp->rx_sge_mapping;
2900 rxq_init->rcq_map = fp->rx_comp_mapping;
2901 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 2902
619c5cb6
VZ
2903 /* This should be a maximum number of data bytes that may be
2904 * placed on the BD (not including paddings).
2905 */
e52fcb24
ED
2906 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2907 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 2908
523224a3 2909 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
2910 rxq_init->tpa_agg_sz = tpa_agg_size;
2911 rxq_init->sge_buf_sz = sge_sz;
2912 rxq_init->max_sges_pkt = max_sge;
619c5cb6 2913 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 2914 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
2915
2916 /* Maximum number or simultaneous TPA aggregation for this Queue.
2917 *
2918 * For PF Clients it should be the maximum avaliable number.
2919 * VF driver(s) may want to define it to a smaller value.
2920 */
dfacf138 2921 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 2922
523224a3
DK
2923 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2924 rxq_init->fw_sb_id = fp->fw_sb_id;
2925
ec6ba945
VZ
2926 if (IS_FCOE_FP(fp))
2927 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2928 else
6383c0b3 2929 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
2930 /* configure silent vlan removal
2931 * if multi function mode is afex, then mask default vlan
2932 */
2933 if (IS_MF_AFEX(bp)) {
2934 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
2935 rxq_init->silent_removal_mask = VLAN_VID_MASK;
2936 }
523224a3
DK
2937}
2938
619c5cb6 2939static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
2940 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2941 u8 cos)
523224a3 2942{
65565884 2943 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 2944 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
2945 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2946 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 2947
619c5cb6
VZ
2948 /*
2949 * set the tss leading client id for TX classfication ==
2950 * leading RSS client id
2951 */
2952 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2953
ec6ba945
VZ
2954 if (IS_FCOE_FP(fp)) {
2955 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2956 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2957 }
523224a3
DK
2958}
2959
8d96286a 2960static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
2961{
2962 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
2963 struct event_ring_data eq_data = { {0} };
2964 u16 flags;
2965
619c5cb6 2966 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2967 /* reset IGU PF statistics: MSIX + ATTN */
2968 /* PF */
2969 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2970 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2971 (CHIP_MODE_IS_4_PORT(bp) ?
2972 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2973 /* ATTN */
2974 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2975 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2976 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2977 (CHIP_MODE_IS_4_PORT(bp) ?
2978 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2979 }
2980
523224a3
DK
2981 /* function setup flags */
2982 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2983
619c5cb6
VZ
2984 /* This flag is relevant for E1x only.
2985 * E2 doesn't have a TPA configuration in a function level.
523224a3 2986 */
619c5cb6 2987 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
2988
2989 func_init.func_flgs = flags;
2990 func_init.pf_id = BP_FUNC(bp);
2991 func_init.func_id = BP_FUNC(bp);
523224a3
DK
2992 func_init.spq_map = bp->spq_mapping;
2993 func_init.spq_prod = bp->spq_prod_idx;
2994
2995 bnx2x_func_init(bp, &func_init);
2996
2997 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2998
2999 /*
619c5cb6
VZ
3000 * Congestion management values depend on the link rate
3001 * There is no active link so initial link rate is set to 10 Gbps.
3002 * When the link comes up The congestion management values are
3003 * re-calculated according to the actual link rate.
3004 */
523224a3
DK
3005 bp->link_vars.line_speed = SPEED_10000;
3006 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3007
3008 /* Only the PMF sets the HW */
3009 if (bp->port.pmf)
3010 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3011
523224a3
DK
3012 /* init Event Queue */
3013 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3014 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3015 eq_data.producer = bp->eq_prod;
3016 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3017 eq_data.sb_id = DEF_SB_ID;
3018 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3019}
3020
3021
3022static void bnx2x_e1h_disable(struct bnx2x *bp)
3023{
3024 int port = BP_PORT(bp);
3025
619c5cb6 3026 bnx2x_tx_disable(bp);
523224a3
DK
3027
3028 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3029}
3030
3031static void bnx2x_e1h_enable(struct bnx2x *bp)
3032{
3033 int port = BP_PORT(bp);
3034
3035 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3036
3037 /* Tx queue should be only reenabled */
3038 netif_tx_wake_all_queues(bp->dev);
3039
3040 /*
3041 * Should not call netif_carrier_on since it will be called if the link
3042 * is up when checking for link state
3043 */
3044}
3045
1d187b34
BW
3046#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3047
3048static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3049{
3050 struct eth_stats_info *ether_stat =
3051 &bp->slowpath->drv_info_to_mcp.ether_stat;
3052
786fdf0b
DC
3053 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3054 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3055
15192a8c
BW
3056 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3057 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3058 ether_stat->mac_local);
1d187b34
BW
3059
3060 ether_stat->mtu_size = bp->dev->mtu;
3061
3062 if (bp->dev->features & NETIF_F_RXCSUM)
3063 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3064 if (bp->dev->features & NETIF_F_TSO)
3065 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3066 ether_stat->feature_flags |= bp->common.boot_mode;
3067
3068 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3069
3070 ether_stat->txq_size = bp->tx_ring_size;
3071 ether_stat->rxq_size = bp->rx_ring_size;
3072}
3073
3074static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3075{
3076 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3077 struct fcoe_stats_info *fcoe_stat =
3078 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3079
55c11941
MS
3080 if (!CNIC_LOADED(bp))
3081 return;
3082
2e499d3c
BW
3083 memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
3084 bp->fip_mac, ETH_ALEN);
1d187b34
BW
3085
3086 fcoe_stat->qos_priority =
3087 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3088
3089 /* insert FCoE stats from ramrod response */
3090 if (!NO_FCOE(bp)) {
3091 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3092 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3093 tstorm_queue_statistics;
3094
3095 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3096 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3097 xstorm_queue_statistics;
3098
3099 struct fcoe_statistics_params *fw_fcoe_stat =
3100 &bp->fw_stats_data->fcoe;
3101
3102 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
3103 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
3104
3105 ADD_64(fcoe_stat->rx_bytes_hi,
3106 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3107 fcoe_stat->rx_bytes_lo,
3108 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
3109
3110 ADD_64(fcoe_stat->rx_bytes_hi,
3111 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3112 fcoe_stat->rx_bytes_lo,
3113 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
3114
3115 ADD_64(fcoe_stat->rx_bytes_hi,
3116 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3117 fcoe_stat->rx_bytes_lo,
3118 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
3119
3120 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3121 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
3122
3123 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3124 fcoe_q_tstorm_stats->rcv_ucast_pkts);
3125
3126 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3127 fcoe_q_tstorm_stats->rcv_bcast_pkts);
3128
3129 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
f33f1fcc 3130 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34
BW
3131
3132 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
3133 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
3134
3135 ADD_64(fcoe_stat->tx_bytes_hi,
3136 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3137 fcoe_stat->tx_bytes_lo,
3138 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3139
3140 ADD_64(fcoe_stat->tx_bytes_hi,
3141 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3142 fcoe_stat->tx_bytes_lo,
3143 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3144
3145 ADD_64(fcoe_stat->tx_bytes_hi,
3146 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3147 fcoe_stat->tx_bytes_lo,
3148 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3149
3150 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3151 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3152
3153 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3154 fcoe_q_xstorm_stats->ucast_pkts_sent);
3155
3156 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3157 fcoe_q_xstorm_stats->bcast_pkts_sent);
3158
3159 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3160 fcoe_q_xstorm_stats->mcast_pkts_sent);
3161 }
3162
1d187b34
BW
3163 /* ask L5 driver to add data to the struct */
3164 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3165}
3166
3167static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3168{
3169 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3170 struct iscsi_stats_info *iscsi_stat =
3171 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3172
55c11941
MS
3173 if (!CNIC_LOADED(bp))
3174 return;
3175
2e499d3c
BW
3176 memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
3177 bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
1d187b34
BW
3178
3179 iscsi_stat->qos_priority =
3180 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3181
1d187b34
BW
3182 /* ask L5 driver to add data to the struct */
3183 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3184}
3185
0793f83f
DK
3186/* called due to MCP event (on pmf):
3187 * reread new bandwidth configuration
3188 * configure FW
3189 * notify others function about the change
3190 */
1191cb83 3191static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3192{
3193 if (bp->link_vars.link_up) {
3194 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3195 bnx2x_link_sync_notify(bp);
3196 }
3197 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3198}
3199
1191cb83 3200static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3201{
3202 bnx2x_config_mf_bw(bp);
3203 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3204}
3205
c8c60d88
YM
3206static void bnx2x_handle_eee_event(struct bnx2x *bp)
3207{
3208 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3209 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3210}
3211
1d187b34
BW
3212static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3213{
3214 enum drv_info_opcode op_code;
3215 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3216
3217 /* if drv_info version supported by MFW doesn't match - send NACK */
3218 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3219 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3220 return;
3221 }
3222
3223 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3224 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3225
3226 memset(&bp->slowpath->drv_info_to_mcp, 0,
3227 sizeof(union drv_info_to_mcp));
3228
3229 switch (op_code) {
3230 case ETH_STATS_OPCODE:
3231 bnx2x_drv_info_ether_stat(bp);
3232 break;
3233 case FCOE_STATS_OPCODE:
3234 bnx2x_drv_info_fcoe_stat(bp);
3235 break;
3236 case ISCSI_STATS_OPCODE:
3237 bnx2x_drv_info_iscsi_stat(bp);
3238 break;
3239 default:
3240 /* if op code isn't supported - send NACK */
3241 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3242 return;
3243 }
3244
3245 /* if we got drv_info attn from MFW then these fields are defined in
3246 * shmem2 for sure
3247 */
3248 SHMEM2_WR(bp, drv_info_host_addr_lo,
3249 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3250 SHMEM2_WR(bp, drv_info_host_addr_hi,
3251 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3252
3253 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3254}
3255
523224a3
DK
3256static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3257{
3258 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3259
3260 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3261
3262 /*
3263 * This is the only place besides the function initialization
3264 * where the bp->flags can change so it is done without any
3265 * locks
3266 */
f2e0899f 3267 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3268 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3269 bp->flags |= MF_FUNC_DIS;
3270
3271 bnx2x_e1h_disable(bp);
3272 } else {
51c1a580 3273 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3274 bp->flags &= ~MF_FUNC_DIS;
3275
3276 bnx2x_e1h_enable(bp);
3277 }
3278 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3279 }
3280 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3281 bnx2x_config_mf_bw(bp);
523224a3
DK
3282 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3283 }
3284
3285 /* Report results to MCP */
3286 if (dcc_event)
3287 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3288 else
3289 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3290}
3291
3292/* must be called under the spq lock */
1191cb83 3293static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3294{
3295 struct eth_spe *next_spe = bp->spq_prod_bd;
3296
3297 if (bp->spq_prod_bd == bp->spq_last_bd) {
3298 bp->spq_prod_bd = bp->spq;
3299 bp->spq_prod_idx = 0;
51c1a580 3300 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3301 } else {
3302 bp->spq_prod_bd++;
3303 bp->spq_prod_idx++;
3304 }
3305 return next_spe;
3306}
3307
3308/* must be called under the spq lock */
1191cb83 3309static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3310{
3311 int func = BP_FUNC(bp);
3312
53e51e2f
VZ
3313 /*
3314 * Make sure that BD data is updated before writing the producer:
3315 * BD data is written to the memory, the producer is read from the
3316 * memory, thus we need a full memory barrier to ensure the ordering.
3317 */
3318 mb();
28912902 3319
523224a3 3320 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3321 bp->spq_prod_idx);
28912902
MC
3322 mmiowb();
3323}
3324
619c5cb6
VZ
3325/**
3326 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3327 *
3328 * @cmd: command to check
3329 * @cmd_type: command type
3330 */
1191cb83 3331static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3332{
3333 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3334 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3335 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3336 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3337 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3338 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3339 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3340 return true;
3341 else
3342 return false;
3343
3344}
3345
3346
3347/**
3348 * bnx2x_sp_post - place a single command on an SP ring
3349 *
3350 * @bp: driver handle
3351 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3352 * @cid: SW CID the command is related to
3353 * @data_hi: command private data address (high 32 bits)
3354 * @data_lo: command private data address (low 32 bits)
3355 * @cmd_type: command type (e.g. NONE, ETH)
3356 *
3357 * SP data is handled as if it's always an address pair, thus data fields are
3358 * not swapped to little endian in upper functions. Instead this function swaps
3359 * data as if it's two u32 fields.
3360 */
9f6c9258 3361int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3362 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3363{
28912902 3364 struct eth_spe *spe;
523224a3 3365 u16 type;
619c5cb6 3366 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3367
a2fbb9ea 3368#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3369 if (unlikely(bp->panic)) {
3370 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3371 return -EIO;
51c1a580 3372 }
a2fbb9ea
ET
3373#endif
3374
34f80b04 3375 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3376
6e30dd4e
VZ
3377 if (common) {
3378 if (!atomic_read(&bp->eq_spq_left)) {
3379 BNX2X_ERR("BUG! EQ ring full!\n");
3380 spin_unlock_bh(&bp->spq_lock);
3381 bnx2x_panic();
3382 return -EBUSY;
3383 }
3384 } else if (!atomic_read(&bp->cq_spq_left)) {
3385 BNX2X_ERR("BUG! SPQ ring full!\n");
3386 spin_unlock_bh(&bp->spq_lock);
3387 bnx2x_panic();
3388 return -EBUSY;
a2fbb9ea 3389 }
f1410647 3390
28912902
MC
3391 spe = bnx2x_sp_get_next(bp);
3392
a2fbb9ea 3393 /* CID needs port number to be encoded int it */
28912902 3394 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3395 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3396 HW_CID(bp, cid));
523224a3 3397
619c5cb6 3398 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3399
523224a3
DK
3400 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3401 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3402
523224a3
DK
3403 spe->hdr.type = cpu_to_le16(type);
3404
3405 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3406 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3407
d6cae238
VZ
3408 /*
3409 * It's ok if the actual decrement is issued towards the memory
3410 * somewhere between the spin_lock and spin_unlock. Thus no
3411 * more explict memory barrier is needed.
3412 */
3413 if (common)
3414 atomic_dec(&bp->eq_spq_left);
3415 else
3416 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3417
a2fbb9ea 3418
51c1a580
MS
3419 DP(BNX2X_MSG_SP,
3420 "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
3421 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3422 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3423 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3424 HW_CID(bp, cid), data_hi, data_lo, type,
3425 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3426
28912902 3427 bnx2x_sp_prod_update(bp);
34f80b04 3428 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3429 return 0;
3430}
3431
3432/* acquire split MCP access lock register */
4a37fb66 3433static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3434{
72fd0718 3435 u32 j, val;
34f80b04 3436 int rc = 0;
a2fbb9ea
ET
3437
3438 might_sleep();
72fd0718 3439 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3440 val = (1UL << 31);
3441 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3442 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3443 if (val & (1L << 31))
3444 break;
3445
3446 msleep(5);
3447 }
a2fbb9ea 3448 if (!(val & (1L << 31))) {
19680c48 3449 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3450 rc = -EBUSY;
3451 }
3452
3453 return rc;
3454}
3455
4a37fb66
YG
3456/* release split MCP access lock register */
3457static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3458{
72fd0718 3459 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3460}
3461
523224a3
DK
3462#define BNX2X_DEF_SB_ATT_IDX 0x0001
3463#define BNX2X_DEF_SB_IDX 0x0002
3464
1191cb83 3465static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3466{
523224a3 3467 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3468 u16 rc = 0;
3469
3470 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3471 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3472 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3473 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3474 }
523224a3
DK
3475
3476 if (bp->def_idx != def_sb->sp_sb.running_index) {
3477 bp->def_idx = def_sb->sp_sb.running_index;
3478 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3479 }
523224a3
DK
3480
3481 /* Do not reorder: indecies reading should complete before handling */
3482 barrier();
a2fbb9ea
ET
3483 return rc;
3484}
3485
3486/*
3487 * slow path service functions
3488 */
3489
3490static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3491{
34f80b04 3492 int port = BP_PORT(bp);
a2fbb9ea
ET
3493 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3494 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3495 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3496 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3497 u32 aeu_mask;
87942b46 3498 u32 nig_mask = 0;
f2e0899f 3499 u32 reg_addr;
a2fbb9ea 3500
a2fbb9ea
ET
3501 if (bp->attn_state & asserted)
3502 BNX2X_ERR("IGU ERROR\n");
3503
3fcaf2e5
EG
3504 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3505 aeu_mask = REG_RD(bp, aeu_addr);
3506
a2fbb9ea 3507 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3508 aeu_mask, asserted);
72fd0718 3509 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3510 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3511
3fcaf2e5
EG
3512 REG_WR(bp, aeu_addr, aeu_mask);
3513 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3514
3fcaf2e5 3515 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3516 bp->attn_state |= asserted;
3fcaf2e5 3517 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3518
3519 if (asserted & ATTN_HARD_WIRED_MASK) {
3520 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3521
a5e9a7cf
EG
3522 bnx2x_acquire_phy_lock(bp);
3523
877e9aa4 3524 /* save nig interrupt mask */
87942b46 3525 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3526
361c391e
YR
3527 /* If nig_mask is not set, no need to call the update
3528 * function.
3529 */
3530 if (nig_mask) {
3531 REG_WR(bp, nig_int_mask_addr, 0);
3532
3533 bnx2x_link_attn(bp);
3534 }
a2fbb9ea
ET
3535
3536 /* handle unicore attn? */
3537 }
3538 if (asserted & ATTN_SW_TIMER_4_FUNC)
3539 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3540
3541 if (asserted & GPIO_2_FUNC)
3542 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3543
3544 if (asserted & GPIO_3_FUNC)
3545 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3546
3547 if (asserted & GPIO_4_FUNC)
3548 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3549
3550 if (port == 0) {
3551 if (asserted & ATTN_GENERAL_ATTN_1) {
3552 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3553 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3554 }
3555 if (asserted & ATTN_GENERAL_ATTN_2) {
3556 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3557 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3558 }
3559 if (asserted & ATTN_GENERAL_ATTN_3) {
3560 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3561 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3562 }
3563 } else {
3564 if (asserted & ATTN_GENERAL_ATTN_4) {
3565 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3566 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3567 }
3568 if (asserted & ATTN_GENERAL_ATTN_5) {
3569 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3570 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3571 }
3572 if (asserted & ATTN_GENERAL_ATTN_6) {
3573 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3574 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3575 }
3576 }
3577
3578 } /* if hardwired */
3579
f2e0899f
DK
3580 if (bp->common.int_block == INT_BLOCK_HC)
3581 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3582 COMMAND_REG_ATTN_BITS_SET);
3583 else
3584 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3585
3586 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3587 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3588 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3589
3590 /* now set back the mask */
a5e9a7cf 3591 if (asserted & ATTN_NIG_FOR_FUNC) {
87942b46 3592 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3593 bnx2x_release_phy_lock(bp);
3594 }
a2fbb9ea
ET
3595}
3596
1191cb83 3597static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3598{
3599 int port = BP_PORT(bp);
b7737c9b 3600 u32 ext_phy_config;
fd4ef40d 3601 /* mark the failure */
b7737c9b
YR
3602 ext_phy_config =
3603 SHMEM_RD(bp,
3604 dev_info.port_hw_config[port].external_phy_config);
3605
3606 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3607 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3608 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3609 ext_phy_config);
fd4ef40d
EG
3610
3611 /* log the failure */
51c1a580
MS
3612 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3613 "Please contact OEM Support for assistance\n");
8304859a
AE
3614
3615 /*
3616 * Scheudle device reset (unload)
3617 * This is due to some boards consuming sufficient power when driver is
3618 * up to overheat if fan fails.
3619 */
3620 smp_mb__before_clear_bit();
3621 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3622 smp_mb__after_clear_bit();
3623 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3624
fd4ef40d 3625}
ab6ad5a4 3626
1191cb83 3627static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3628{
34f80b04 3629 int port = BP_PORT(bp);
877e9aa4 3630 int reg_offset;
d90d96ba 3631 u32 val;
877e9aa4 3632
34f80b04
EG
3633 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3634 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3635
34f80b04 3636 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3637
3638 val = REG_RD(bp, reg_offset);
3639 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3640 REG_WR(bp, reg_offset, val);
3641
3642 BNX2X_ERR("SPIO5 hw attention\n");
3643
fd4ef40d 3644 /* Fan failure attention */
d90d96ba 3645 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3646 bnx2x_fan_failure(bp);
877e9aa4 3647 }
34f80b04 3648
3deb8167 3649 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3650 bnx2x_acquire_phy_lock(bp);
3651 bnx2x_handle_module_detect_int(&bp->link_params);
3652 bnx2x_release_phy_lock(bp);
3653 }
3654
34f80b04
EG
3655 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3656
3657 val = REG_RD(bp, reg_offset);
3658 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3659 REG_WR(bp, reg_offset, val);
3660
3661 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3662 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3663 bnx2x_panic();
3664 }
877e9aa4
ET
3665}
3666
1191cb83 3667static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3668{
3669 u32 val;
3670
0626b899 3671 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3672
3673 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3674 BNX2X_ERR("DB hw attention 0x%x\n", val);
3675 /* DORQ discard attention */
3676 if (val & 0x2)
3677 BNX2X_ERR("FATAL error from DORQ\n");
3678 }
34f80b04
EG
3679
3680 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3681
3682 int port = BP_PORT(bp);
3683 int reg_offset;
3684
3685 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3686 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3687
3688 val = REG_RD(bp, reg_offset);
3689 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3690 REG_WR(bp, reg_offset, val);
3691
3692 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3693 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3694 bnx2x_panic();
3695 }
877e9aa4
ET
3696}
3697
1191cb83 3698static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3699{
3700 u32 val;
3701
3702 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3703
3704 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3705 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3706 /* CFC error attention */
3707 if (val & 0x2)
3708 BNX2X_ERR("FATAL error from CFC\n");
3709 }
3710
3711 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3712 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3713 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3714 /* RQ_USDMDP_FIFO_OVERFLOW */
3715 if (val & 0x18000)
3716 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3717
3718 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3719 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3720 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3721 }
877e9aa4 3722 }
34f80b04
EG
3723
3724 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3725
3726 int port = BP_PORT(bp);
3727 int reg_offset;
3728
3729 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3730 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3731
3732 val = REG_RD(bp, reg_offset);
3733 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3734 REG_WR(bp, reg_offset, val);
3735
3736 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3737 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3738 bnx2x_panic();
3739 }
877e9aa4
ET
3740}
3741
1191cb83 3742static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3743{
34f80b04
EG
3744 u32 val;
3745
877e9aa4
ET
3746 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3747
34f80b04
EG
3748 if (attn & BNX2X_PMF_LINK_ASSERT) {
3749 int func = BP_FUNC(bp);
3750
3751 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 3752 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
3753 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3754 func_mf_config[BP_ABS_FUNC(bp)].config);
3755 val = SHMEM_RD(bp,
3756 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3757 if (val & DRV_STATUS_DCC_EVENT_MASK)
3758 bnx2x_dcc_event(bp,
3759 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3760
3761 if (val & DRV_STATUS_SET_MF_BW)
3762 bnx2x_set_mf_bw(bp);
3763
1d187b34
BW
3764 if (val & DRV_STATUS_DRV_INFO_REQ)
3765 bnx2x_handle_drv_info_req(bp);
2691d51d 3766 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3767 bnx2x_pmf_update(bp);
3768
e4901dde 3769 if (bp->port.pmf &&
785b9b1a
SR
3770 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3771 bp->dcbx_enabled > 0)
e4901dde
VZ
3772 /* start dcbx state machine */
3773 bnx2x_dcbx_set_params(bp,
3774 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
3775 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3776 bnx2x_handle_afex_cmd(bp,
3777 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
3778 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3779 bnx2x_handle_eee_event(bp);
3deb8167
YR
3780 if (bp->link_vars.periodic_flags &
3781 PERIODIC_FLAGS_LINK_EVENT) {
3782 /* sync with link */
3783 bnx2x_acquire_phy_lock(bp);
3784 bp->link_vars.periodic_flags &=
3785 ~PERIODIC_FLAGS_LINK_EVENT;
3786 bnx2x_release_phy_lock(bp);
3787 if (IS_MF(bp))
3788 bnx2x_link_sync_notify(bp);
3789 bnx2x_link_report(bp);
3790 }
3791 /* Always call it here: bnx2x_link_report() will
3792 * prevent the link indication duplication.
3793 */
3794 bnx2x__link_status_update(bp);
34f80b04 3795 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
3796
3797 BNX2X_ERR("MC assert!\n");
d6cae238 3798 bnx2x_mc_assert(bp);
877e9aa4
ET
3799 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3800 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3801 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3802 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3803 bnx2x_panic();
3804
3805 } else if (attn & BNX2X_MCP_ASSERT) {
3806
3807 BNX2X_ERR("MCP assert!\n");
3808 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 3809 bnx2x_fw_dump(bp);
877e9aa4
ET
3810
3811 } else
3812 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3813 }
3814
3815 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
3816 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3817 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
3818 val = CHIP_IS_E1(bp) ? 0 :
3819 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
3820 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3821 }
3822 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
3823 val = CHIP_IS_E1(bp) ? 0 :
3824 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
3825 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3826 }
877e9aa4 3827 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
3828 }
3829}
3830
c9ee9206
VZ
3831/*
3832 * Bits map:
3833 * 0-7 - Engine0 load counter.
3834 * 8-15 - Engine1 load counter.
3835 * 16 - Engine0 RESET_IN_PROGRESS bit.
3836 * 17 - Engine1 RESET_IN_PROGRESS bit.
3837 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3838 * on the engine
3839 * 19 - Engine1 ONE_IS_LOADED.
3840 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3841 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3842 * just the one belonging to its engine).
3843 *
3844 */
3845#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3846
3847#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3848#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3849#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3850#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3851#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3852#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3853#define BNX2X_GLOBAL_RESET_BIT 0x00040000
3854
3855/*
3856 * Set the GLOBAL_RESET bit.
3857 *
3858 * Should be run under rtnl lock
3859 */
3860void bnx2x_set_reset_global(struct bnx2x *bp)
3861{
f16da43b
AE
3862 u32 val;
3863 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3864 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3865 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 3866 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
3867}
3868
3869/*
3870 * Clear the GLOBAL_RESET bit.
3871 *
3872 * Should be run under rtnl lock
3873 */
1191cb83 3874static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 3875{
f16da43b
AE
3876 u32 val;
3877 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3878 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 3879 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 3880 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 3881}
f85582f8 3882
72fd0718 3883/*
c9ee9206
VZ
3884 * Checks the GLOBAL_RESET bit.
3885 *
72fd0718
VZ
3886 * should be run under rtnl lock
3887 */
1191cb83 3888static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206
VZ
3889{
3890 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3891
3892 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3893 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3894}
3895
3896/*
3897 * Clear RESET_IN_PROGRESS bit for the current engine.
3898 *
3899 * Should be run under rtnl lock
3900 */
1191cb83 3901static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 3902{
f16da43b 3903 u32 val;
c9ee9206
VZ
3904 u32 bit = BP_PATH(bp) ?
3905 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3906 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3907 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3908
3909 /* Clear the bit */
3910 val &= ~bit;
3911 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
3912
3913 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3914}
3915
3916/*
c9ee9206
VZ
3917 * Set RESET_IN_PROGRESS for the current engine.
3918 *
72fd0718
VZ
3919 * should be run under rtnl lock
3920 */
c9ee9206 3921void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 3922{
f16da43b 3923 u32 val;
c9ee9206
VZ
3924 u32 bit = BP_PATH(bp) ?
3925 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
3926 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3927 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
3928
3929 /* Set the bit */
3930 val |= bit;
3931 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3932 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3933}
3934
3935/*
c9ee9206 3936 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
3937 * should be run under rtnl lock
3938 */
c9ee9206 3939bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 3940{
c9ee9206
VZ
3941 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3942 u32 bit = engine ?
3943 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3944
3945 /* return false if bit is set */
3946 return (val & bit) ? false : true;
72fd0718
VZ
3947}
3948
3949/*
889b9af3 3950 * set pf load for the current pf.
c9ee9206 3951 *
72fd0718
VZ
3952 * should be run under rtnl lock
3953 */
889b9af3 3954void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 3955{
f16da43b 3956 u32 val1, val;
c9ee9206
VZ
3957 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3958 BNX2X_PATH0_LOAD_CNT_MASK;
3959 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3960 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3961
f16da43b
AE
3962 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3963 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3964
51c1a580 3965 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 3966
c9ee9206
VZ
3967 /* get the current counter value */
3968 val1 = (val & mask) >> shift;
3969
889b9af3
AE
3970 /* set bit of that PF */
3971 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
3972
3973 /* clear the old value */
3974 val &= ~mask;
3975
3976 /* set the new one */
3977 val |= ((val1 << shift) & mask);
3978
3979 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 3980 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
3981}
3982
c9ee9206 3983/**
889b9af3 3984 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
3985 *
3986 * @bp: driver handle
3987 *
3988 * Should be run under rtnl lock.
3989 * Decrements the load counter for the current engine. Returns
889b9af3 3990 * whether other functions are still loaded
72fd0718 3991 */
889b9af3 3992bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 3993{
f16da43b 3994 u32 val1, val;
c9ee9206
VZ
3995 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3996 BNX2X_PATH0_LOAD_CNT_MASK;
3997 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3998 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 3999
f16da43b
AE
4000 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4001 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4002 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4003
c9ee9206
VZ
4004 /* get the current counter value */
4005 val1 = (val & mask) >> shift;
4006
889b9af3
AE
4007 /* clear bit of that PF */
4008 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4009
4010 /* clear the old value */
4011 val &= ~mask;
4012
4013 /* set the new one */
4014 val |= ((val1 << shift) & mask);
4015
4016 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4017 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4018 return val1 != 0;
72fd0718
VZ
4019}
4020
4021/*
889b9af3 4022 * Read the load status for the current engine.
c9ee9206 4023 *
72fd0718
VZ
4024 * should be run under rtnl lock
4025 */
1191cb83 4026static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4027{
c9ee9206
VZ
4028 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4029 BNX2X_PATH0_LOAD_CNT_MASK);
4030 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4031 BNX2X_PATH0_LOAD_CNT_SHIFT);
4032 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4033
51c1a580 4034 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4035
4036 val = (val & mask) >> shift;
4037
51c1a580
MS
4038 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4039 engine, val);
c9ee9206 4040
889b9af3 4041 return val != 0;
72fd0718
VZ
4042}
4043
1191cb83 4044static void _print_next_block(int idx, const char *blk)
72fd0718 4045{
f1deab50 4046 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4047}
4048
1191cb83
ED
4049static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4050 bool print)
72fd0718
VZ
4051{
4052 int i = 0;
4053 u32 cur_bit = 0;
4054 for (i = 0; sig; i++) {
4055 cur_bit = ((u32)0x1 << i);
4056 if (sig & cur_bit) {
4057 switch (cur_bit) {
4058 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
4059 if (print)
4060 _print_next_block(par_num++, "BRB");
72fd0718
VZ
4061 break;
4062 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
4063 if (print)
4064 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
4065 break;
4066 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
4067 if (print)
4068 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
4069 break;
4070 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
4071 if (print)
4072 _print_next_block(par_num++,
4073 "SEARCHER");
4074 break;
4075 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4076 if (print)
4077 _print_next_block(par_num++, "TCM");
72fd0718
VZ
4078 break;
4079 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
4080 if (print)
4081 _print_next_block(par_num++, "TSEMI");
4082 break;
4083 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4084 if (print)
4085 _print_next_block(par_num++, "XPB");
72fd0718
VZ
4086 break;
4087 }
4088
4089 /* Clear the bit */
4090 sig &= ~cur_bit;
4091 }
4092 }
4093
4094 return par_num;
4095}
4096
1191cb83
ED
4097static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4098 bool *global, bool print)
72fd0718
VZ
4099{
4100 int i = 0;
4101 u32 cur_bit = 0;
4102 for (i = 0; sig; i++) {
4103 cur_bit = ((u32)0x1 << i);
4104 if (sig & cur_bit) {
4105 switch (cur_bit) {
c9ee9206
VZ
4106 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4107 if (print)
4108 _print_next_block(par_num++, "PBF");
72fd0718
VZ
4109 break;
4110 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
4111 if (print)
4112 _print_next_block(par_num++, "QM");
4113 break;
4114 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4115 if (print)
4116 _print_next_block(par_num++, "TM");
72fd0718
VZ
4117 break;
4118 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
4119 if (print)
4120 _print_next_block(par_num++, "XSDM");
4121 break;
4122 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4123 if (print)
4124 _print_next_block(par_num++, "XCM");
72fd0718
VZ
4125 break;
4126 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
4127 if (print)
4128 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
4129 break;
4130 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
4131 if (print)
4132 _print_next_block(par_num++,
4133 "DOORBELLQ");
4134 break;
4135 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4136 if (print)
4137 _print_next_block(par_num++, "NIG");
72fd0718
VZ
4138 break;
4139 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
4140 if (print)
4141 _print_next_block(par_num++,
4142 "VAUX PCI CORE");
4143 *global = true;
72fd0718
VZ
4144 break;
4145 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
4146 if (print)
4147 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
4148 break;
4149 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
4150 if (print)
4151 _print_next_block(par_num++, "USDM");
72fd0718 4152 break;
8736c826
VZ
4153 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4154 if (print)
4155 _print_next_block(par_num++, "UCM");
4156 break;
72fd0718 4157 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
4158 if (print)
4159 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
4160 break;
4161 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
4162 if (print)
4163 _print_next_block(par_num++, "UPB");
72fd0718
VZ
4164 break;
4165 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
4166 if (print)
4167 _print_next_block(par_num++, "CSDM");
72fd0718 4168 break;
8736c826
VZ
4169 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4170 if (print)
4171 _print_next_block(par_num++, "CCM");
4172 break;
72fd0718
VZ
4173 }
4174
4175 /* Clear the bit */
4176 sig &= ~cur_bit;
4177 }
4178 }
4179
4180 return par_num;
4181}
4182
1191cb83
ED
4183static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4184 bool print)
72fd0718
VZ
4185{
4186 int i = 0;
4187 u32 cur_bit = 0;
4188 for (i = 0; sig; i++) {
4189 cur_bit = ((u32)0x1 << i);
4190 if (sig & cur_bit) {
4191 switch (cur_bit) {
4192 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
4193 if (print)
4194 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
4195 break;
4196 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
4197 if (print)
4198 _print_next_block(par_num++, "PXP");
72fd0718
VZ
4199 break;
4200 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
4201 if (print)
4202 _print_next_block(par_num++,
72fd0718
VZ
4203 "PXPPCICLOCKCLIENT");
4204 break;
4205 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
4206 if (print)
4207 _print_next_block(par_num++, "CFC");
72fd0718
VZ
4208 break;
4209 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
4210 if (print)
4211 _print_next_block(par_num++, "CDU");
4212 break;
4213 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4214 if (print)
4215 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
4216 break;
4217 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
4218 if (print)
4219 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4220 break;
4221 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4222 if (print)
4223 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4224 break;
4225 }
4226
4227 /* Clear the bit */
4228 sig &= ~cur_bit;
4229 }
4230 }
4231
4232 return par_num;
4233}
4234
1191cb83
ED
4235static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4236 bool *global, bool print)
72fd0718
VZ
4237{
4238 int i = 0;
4239 u32 cur_bit = 0;
4240 for (i = 0; sig; i++) {
4241 cur_bit = ((u32)0x1 << i);
4242 if (sig & cur_bit) {
4243 switch (cur_bit) {
4244 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4245 if (print)
4246 _print_next_block(par_num++, "MCP ROM");
4247 *global = true;
72fd0718
VZ
4248 break;
4249 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4250 if (print)
4251 _print_next_block(par_num++,
4252 "MCP UMP RX");
4253 *global = true;
72fd0718
VZ
4254 break;
4255 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4256 if (print)
4257 _print_next_block(par_num++,
4258 "MCP UMP TX");
4259 *global = true;
72fd0718
VZ
4260 break;
4261 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4262 if (print)
4263 _print_next_block(par_num++,
4264 "MCP SCPAD");
4265 *global = true;
72fd0718
VZ
4266 break;
4267 }
4268
4269 /* Clear the bit */
4270 sig &= ~cur_bit;
4271 }
4272 }
4273
4274 return par_num;
4275}
4276
1191cb83
ED
4277static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4278 bool print)
8736c826
VZ
4279{
4280 int i = 0;
4281 u32 cur_bit = 0;
4282 for (i = 0; sig; i++) {
4283 cur_bit = ((u32)0x1 << i);
4284 if (sig & cur_bit) {
4285 switch (cur_bit) {
4286 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4287 if (print)
4288 _print_next_block(par_num++, "PGLUE_B");
4289 break;
4290 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4291 if (print)
4292 _print_next_block(par_num++, "ATC");
4293 break;
4294 }
4295
4296 /* Clear the bit */
4297 sig &= ~cur_bit;
4298 }
4299 }
4300
4301 return par_num;
4302}
4303
1191cb83
ED
4304static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4305 u32 *sig)
72fd0718 4306{
8736c826
VZ
4307 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4308 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4309 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4310 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4311 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4312 int par_num = 0;
51c1a580
MS
4313 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4314 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4315 sig[0] & HW_PRTY_ASSERT_SET_0,
4316 sig[1] & HW_PRTY_ASSERT_SET_1,
4317 sig[2] & HW_PRTY_ASSERT_SET_2,
4318 sig[3] & HW_PRTY_ASSERT_SET_3,
4319 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4320 if (print)
4321 netdev_err(bp->dev,
4322 "Parity errors detected in blocks: ");
4323 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4324 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4325 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4326 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4327 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4328 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4329 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4330 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4331 par_num = bnx2x_check_blocks_with_parity4(
4332 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4333
c9ee9206
VZ
4334 if (print)
4335 pr_cont("\n");
8736c826 4336
72fd0718
VZ
4337 return true;
4338 } else
4339 return false;
4340}
4341
c9ee9206
VZ
4342/**
4343 * bnx2x_chk_parity_attn - checks for parity attentions.
4344 *
4345 * @bp: driver handle
4346 * @global: true if there was a global attention
4347 * @print: show parity attention in syslog
4348 */
4349bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4350{
8736c826 4351 struct attn_route attn = { {0} };
72fd0718
VZ
4352 int port = BP_PORT(bp);
4353
4354 attn.sig[0] = REG_RD(bp,
4355 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4356 port*4);
4357 attn.sig[1] = REG_RD(bp,
4358 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4359 port*4);
4360 attn.sig[2] = REG_RD(bp,
4361 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4362 port*4);
4363 attn.sig[3] = REG_RD(bp,
4364 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4365 port*4);
4366
8736c826
VZ
4367 if (!CHIP_IS_E1x(bp))
4368 attn.sig[4] = REG_RD(bp,
4369 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4370 port*4);
4371
4372 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4373}
4374
f2e0899f 4375
1191cb83 4376static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4377{
4378 u32 val;
4379 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4380
4381 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4382 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4383 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4384 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4385 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4386 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4387 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4388 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4389 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4390 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4391 if (val &
4392 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4393 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4394 if (val &
4395 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4396 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4397 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4398 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4399 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4400 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4401 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4402 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4403 }
4404 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4405 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4406 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4407 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4408 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4409 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4410 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4411 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4412 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4413 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4414 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4415 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4416 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4417 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4418 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4419 }
4420
4421 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4422 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4423 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4424 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4425 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4426 }
4427
4428}
4429
72fd0718
VZ
4430static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4431{
4432 struct attn_route attn, *group_mask;
34f80b04 4433 int port = BP_PORT(bp);
877e9aa4 4434 int index;
a2fbb9ea
ET
4435 u32 reg_addr;
4436 u32 val;
3fcaf2e5 4437 u32 aeu_mask;
c9ee9206 4438 bool global = false;
a2fbb9ea
ET
4439
4440 /* need to take HW lock because MCP or other port might also
4441 try to handle this event */
4a37fb66 4442 bnx2x_acquire_alr(bp);
a2fbb9ea 4443
c9ee9206
VZ
4444 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4445#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4446 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4447 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4448 /* Disable HW interrupts */
4449 bnx2x_int_disable(bp);
72fd0718
VZ
4450 /* In case of parity errors don't handle attentions so that
4451 * other function would "see" parity errors.
4452 */
c9ee9206
VZ
4453#else
4454 bnx2x_panic();
4455#endif
4456 bnx2x_release_alr(bp);
72fd0718
VZ
4457 return;
4458 }
4459
a2fbb9ea
ET
4460 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4461 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4462 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4463 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4464 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4465 attn.sig[4] =
4466 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4467 else
4468 attn.sig[4] = 0;
4469
4470 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4471 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4472
4473 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4474 if (deasserted & (1 << index)) {
72fd0718 4475 group_mask = &bp->attn_group[index];
a2fbb9ea 4476
51c1a580 4477 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4478 index,
4479 group_mask->sig[0], group_mask->sig[1],
4480 group_mask->sig[2], group_mask->sig[3],
4481 group_mask->sig[4]);
a2fbb9ea 4482
f2e0899f
DK
4483 bnx2x_attn_int_deasserted4(bp,
4484 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4485 bnx2x_attn_int_deasserted3(bp,
72fd0718 4486 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4487 bnx2x_attn_int_deasserted1(bp,
72fd0718 4488 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4489 bnx2x_attn_int_deasserted2(bp,
72fd0718 4490 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4491 bnx2x_attn_int_deasserted0(bp,
72fd0718 4492 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4493 }
4494 }
4495
4a37fb66 4496 bnx2x_release_alr(bp);
a2fbb9ea 4497
f2e0899f
DK
4498 if (bp->common.int_block == INT_BLOCK_HC)
4499 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4500 COMMAND_REG_ATTN_BITS_CLR);
4501 else
4502 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4503
4504 val = ~deasserted;
f2e0899f
DK
4505 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4506 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4507 REG_WR(bp, reg_addr, val);
a2fbb9ea 4508
a2fbb9ea 4509 if (~bp->attn_state & deasserted)
3fcaf2e5 4510 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4511
4512 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4513 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4514
3fcaf2e5
EG
4515 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4516 aeu_mask = REG_RD(bp, reg_addr);
4517
4518 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4519 aeu_mask, deasserted);
72fd0718 4520 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4521 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4522
3fcaf2e5
EG
4523 REG_WR(bp, reg_addr, aeu_mask);
4524 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4525
4526 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4527 bp->attn_state &= ~deasserted;
4528 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4529}
4530
4531static void bnx2x_attn_int(struct bnx2x *bp)
4532{
4533 /* read local copy of bits */
68d59484
EG
4534 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4535 attn_bits);
4536 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4537 attn_bits_ack);
a2fbb9ea
ET
4538 u32 attn_state = bp->attn_state;
4539
4540 /* look for changed bits */
4541 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4542 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4543
4544 DP(NETIF_MSG_HW,
4545 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4546 attn_bits, attn_ack, asserted, deasserted);
4547
4548 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4549 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4550
4551 /* handle bits that were raised */
4552 if (asserted)
4553 bnx2x_attn_int_asserted(bp, asserted);
4554
4555 if (deasserted)
4556 bnx2x_attn_int_deasserted(bp, deasserted);
4557}
4558
619c5cb6
VZ
4559void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4560 u16 index, u8 op, u8 update)
4561{
4562 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4563
4564 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4565 igu_addr);
4566}
4567
1191cb83 4568static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4569{
4570 /* No memory barriers */
4571 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4572 mmiowb(); /* keep prod updates ordered */
4573}
4574
523224a3
DK
4575static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4576 union event_ring_elem *elem)
4577{
619c5cb6
VZ
4578 u8 err = elem->message.error;
4579
523224a3 4580 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4581 (cid < bp->cnic_eth_dev.starting_cid &&
4582 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4583 return 1;
4584
4585 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4586
619c5cb6
VZ
4587 if (unlikely(err)) {
4588
523224a3
DK
4589 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4590 cid);
4591 bnx2x_panic_dump(bp);
4592 }
619c5cb6 4593 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4594 return 0;
4595}
523224a3 4596
1191cb83 4597static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4598{
4599 struct bnx2x_mcast_ramrod_params rparam;
4600 int rc;
4601
4602 memset(&rparam, 0, sizeof(rparam));
4603
4604 rparam.mcast_obj = &bp->mcast_obj;
4605
4606 netif_addr_lock_bh(bp->dev);
4607
4608 /* Clear pending state for the last command */
4609 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4610
4611 /* If there are pending mcast commands - send them */
4612 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4613 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4614 if (rc < 0)
4615 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4616 rc);
4617 }
4618
4619 netif_addr_unlock_bh(bp->dev);
4620}
4621
1191cb83
ED
4622static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4623 union event_ring_elem *elem)
619c5cb6
VZ
4624{
4625 unsigned long ramrod_flags = 0;
4626 int rc = 0;
4627 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4628 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4629
4630 /* Always push next commands out, don't wait here */
4631 __set_bit(RAMROD_CONT, &ramrod_flags);
4632
4633 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4634 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4635 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 4636 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
4637 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4638 else
15192a8c 4639 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
4640
4641 break;
619c5cb6 4642 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4643 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4644 /* This is only relevant for 57710 where multicast MACs are
4645 * configured as unicast MACs using the same ramrod.
4646 */
4647 bnx2x_handle_mcast_eqe(bp);
4648 return;
4649 default:
4650 BNX2X_ERR("Unsupported classification command: %d\n",
4651 elem->message.data.eth_event.echo);
4652 return;
4653 }
4654
4655 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4656
4657 if (rc < 0)
4658 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4659 else if (rc > 0)
4660 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4661
4662}
4663
619c5cb6 4664static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 4665
1191cb83 4666static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
4667{
4668 netif_addr_lock_bh(bp->dev);
4669
4670 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4671
4672 /* Send rx_mode command again if was requested */
4673 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4674 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
4675 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4676 &bp->sp_state))
4677 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4678 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4679 &bp->sp_state))
4680 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
4681
4682 netif_addr_unlock_bh(bp->dev);
4683}
4684
1191cb83 4685static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
4686 union event_ring_elem *elem)
4687{
4688 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4689 DP(BNX2X_MSG_SP,
4690 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4691 elem->message.data.vif_list_event.func_bit_map);
4692 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4693 elem->message.data.vif_list_event.func_bit_map);
4694 } else if (elem->message.data.vif_list_event.echo ==
4695 VIF_LIST_RULE_SET) {
4696 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4697 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4698 }
4699}
4700
4701/* called with rtnl_lock */
1191cb83 4702static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
4703{
4704 int q, rc;
4705 struct bnx2x_fastpath *fp;
4706 struct bnx2x_queue_state_params queue_params = {NULL};
4707 struct bnx2x_queue_update_params *q_update_params =
4708 &queue_params.params.update;
4709
4710 /* Send Q update command with afex vlan removal values for all Qs */
4711 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4712
4713 /* set silent vlan removal values according to vlan mode */
4714 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4715 &q_update_params->update_flags);
4716 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4717 &q_update_params->update_flags);
4718 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4719
4720 /* in access mode mark mask and value are 0 to strip all vlans */
4721 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4722 q_update_params->silent_removal_value = 0;
4723 q_update_params->silent_removal_mask = 0;
4724 } else {
4725 q_update_params->silent_removal_value =
4726 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4727 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4728 }
4729
4730 for_each_eth_queue(bp, q) {
4731 /* Set the appropriate Queue object */
4732 fp = &bp->fp[q];
15192a8c 4733 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4734
4735 /* send the ramrod */
4736 rc = bnx2x_queue_state_change(bp, &queue_params);
4737 if (rc < 0)
4738 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4739 q);
4740 }
4741
a3348722 4742 if (!NO_FCOE(bp)) {
65565884 4743 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 4744 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4745
4746 /* clear pending completion bit */
4747 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4748
4749 /* mark latest Q bit */
4750 smp_mb__before_clear_bit();
4751 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4752 smp_mb__after_clear_bit();
4753
4754 /* send Q update ramrod for FCoE Q */
4755 rc = bnx2x_queue_state_change(bp, &queue_params);
4756 if (rc < 0)
4757 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4758 q);
4759 } else {
4760 /* If no FCoE ring - ACK MCP now */
4761 bnx2x_link_report(bp);
4762 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4763 }
a3348722
BW
4764}
4765
1191cb83 4766static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
4767 struct bnx2x *bp, u32 cid)
4768{
94f05b0f 4769 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
4770
4771 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 4772 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 4773 else
15192a8c 4774 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
4775}
4776
523224a3
DK
4777static void bnx2x_eq_int(struct bnx2x *bp)
4778{
4779 u16 hw_cons, sw_cons, sw_prod;
4780 union event_ring_elem *elem;
55c11941 4781 u8 echo;
523224a3
DK
4782 u32 cid;
4783 u8 opcode;
4784 int spqe_cnt = 0;
619c5cb6
VZ
4785 struct bnx2x_queue_sp_obj *q_obj;
4786 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4787 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4788
4789 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4790
4791 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4792 * when we get the the next-page we nned to adjust so the loop
4793 * condition below will be met. The next element is the size of a
4794 * regular element and hence incrementing by 1
4795 */
4796 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4797 hw_cons++;
4798
25985edc 4799 /* This function may never run in parallel with itself for a
523224a3
DK
4800 * specific bp, thus there is no need in "paired" read memory
4801 * barrier here.
4802 */
4803 sw_cons = bp->eq_cons;
4804 sw_prod = bp->eq_prod;
4805
d6cae238 4806 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 4807 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
4808
4809 for (; sw_cons != hw_cons;
4810 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4811
4812
4813 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4814
4815 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4816 opcode = elem->message.opcode;
4817
4818
4819 /* handle eq element */
4820 switch (opcode) {
4821 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
4822 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4823 "got statistics comp event %d\n",
619c5cb6 4824 bp->stats_comp++);
523224a3 4825 /* nothing to do with stats comp */
d6cae238 4826 goto next_spqe;
523224a3
DK
4827
4828 case EVENT_RING_OPCODE_CFC_DEL:
4829 /* handle according to cid range */
4830 /*
4831 * we may want to verify here that the bp state is
4832 * HALTING
4833 */
d6cae238 4834 DP(BNX2X_MSG_SP,
523224a3 4835 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
4836
4837 if (CNIC_LOADED(bp) &&
4838 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 4839 goto next_spqe;
55c11941 4840
619c5cb6
VZ
4841 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4842
4843 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4844 break;
4845
4846
523224a3
DK
4847
4848 goto next_spqe;
e4901dde
VZ
4849
4850 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 4851 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
4852 if (f_obj->complete_cmd(bp, f_obj,
4853 BNX2X_F_CMD_TX_STOP))
4854 break;
e4901dde
VZ
4855 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4856 goto next_spqe;
619c5cb6 4857
e4901dde 4858 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 4859 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
4860 if (f_obj->complete_cmd(bp, f_obj,
4861 BNX2X_F_CMD_TX_START))
4862 break;
e4901dde
VZ
4863 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4864 goto next_spqe;
55c11941 4865
a3348722 4866 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
4867 echo = elem->message.data.function_update_event.echo;
4868 if (echo == SWITCH_UPDATE) {
4869 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4870 "got FUNC_SWITCH_UPDATE ramrod\n");
4871 if (f_obj->complete_cmd(
4872 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
4873 break;
a3348722 4874
55c11941
MS
4875 } else {
4876 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
4877 "AFEX: ramrod completed FUNCTION_UPDATE\n");
4878 f_obj->complete_cmd(bp, f_obj,
4879 BNX2X_F_CMD_AFEX_UPDATE);
4880
4881 /* We will perform the Queues update from
4882 * sp_rtnl task as all Queue SP operations
4883 * should run under rtnl_lock.
4884 */
4885 smp_mb__before_clear_bit();
4886 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
4887 &bp->sp_rtnl_state);
4888 smp_mb__after_clear_bit();
4889
4890 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4891 }
a3348722 4892
a3348722
BW
4893 goto next_spqe;
4894
4895 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
4896 f_obj->complete_cmd(bp, f_obj,
4897 BNX2X_F_CMD_AFEX_VIFLISTS);
4898 bnx2x_after_afex_vif_lists(bp, elem);
4899 goto next_spqe;
619c5cb6 4900 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
4901 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4902 "got FUNC_START ramrod\n");
619c5cb6
VZ
4903 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4904 break;
4905
4906 goto next_spqe;
4907
4908 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
4909 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4910 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
4911 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4912 break;
4913
4914 goto next_spqe;
523224a3
DK
4915 }
4916
4917 switch (opcode | bp->state) {
619c5cb6
VZ
4918 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4919 BNX2X_STATE_OPEN):
4920 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 4921 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
4922 cid = elem->message.data.eth_event.echo &
4923 BNX2X_SWCID_MASK;
d6cae238 4924 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
4925 cid);
4926 rss_raw->clear_pending(rss_raw);
523224a3
DK
4927 break;
4928
619c5cb6
VZ
4929 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4930 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4931 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 4932 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
4933 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4934 BNX2X_STATE_OPEN):
4935 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4936 BNX2X_STATE_DIAG):
4937 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4938 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4939 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 4940 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
4941 break;
4942
619c5cb6
VZ
4943 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4944 BNX2X_STATE_OPEN):
4945 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4946 BNX2X_STATE_DIAG):
4947 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4948 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4949 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 4950 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
4951 break;
4952
619c5cb6
VZ
4953 case (EVENT_RING_OPCODE_FILTERS_RULES |
4954 BNX2X_STATE_OPEN):
4955 case (EVENT_RING_OPCODE_FILTERS_RULES |
4956 BNX2X_STATE_DIAG):
4957 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 4958 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 4959 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 4960 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
4961 break;
4962 default:
4963 /* unknown event log error and continue */
619c5cb6
VZ
4964 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4965 elem->message.opcode, bp->state);
523224a3
DK
4966 }
4967next_spqe:
4968 spqe_cnt++;
4969 } /* for */
4970
8fe23fbd 4971 smp_mb__before_atomic_inc();
6e30dd4e 4972 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
4973
4974 bp->eq_cons = sw_cons;
4975 bp->eq_prod = sw_prod;
4976 /* Make sure that above mem writes were issued towards the memory */
4977 smp_wmb();
4978
4979 /* update producer */
4980 bnx2x_update_eq_prod(bp, bp->eq_prod);
4981}
4982
a2fbb9ea
ET
4983static void bnx2x_sp_task(struct work_struct *work)
4984{
1cf167f2 4985 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea
ET
4986 u16 status;
4987
a2fbb9ea 4988 status = bnx2x_update_dsb_idx(bp);
34f80b04
EG
4989/* if (status == 0) */
4990/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
a2fbb9ea 4991
51c1a580 4992 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
a2fbb9ea 4993
877e9aa4 4994 /* HW attentions */
523224a3 4995 if (status & BNX2X_DEF_SB_ATT_IDX) {
a2fbb9ea 4996 bnx2x_attn_int(bp);
523224a3 4997 status &= ~BNX2X_DEF_SB_ATT_IDX;
cdaa7cb8
VZ
4998 }
4999
523224a3
DK
5000 /* SP events: STAT_QUERY and others */
5001 if (status & BNX2X_DEF_SB_IDX) {
ec6ba945 5002 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5003
55c11941
MS
5004 if (FCOE_INIT(bp) &&
5005 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
019dbb4c
VZ
5006 /*
5007 * Prevent local bottom-halves from running as
5008 * we are going to change the local NAPI list.
5009 */
5010 local_bh_disable();
ec6ba945 5011 napi_schedule(&bnx2x_fcoe(bp, napi));
019dbb4c
VZ
5012 local_bh_enable();
5013 }
55c11941 5014
523224a3
DK
5015 /* Handle EQ completions */
5016 bnx2x_eq_int(bp);
5017
5018 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5019 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5020
5021 status &= ~BNX2X_DEF_SB_IDX;
cdaa7cb8
VZ
5022 }
5023
5024 if (unlikely(status))
51c1a580 5025 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
cdaa7cb8 5026 status);
a2fbb9ea 5027
523224a3
DK
5028 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5029 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
a3348722
BW
5030
5031 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5032 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5033 &bp->sp_state)) {
5034 bnx2x_link_report(bp);
5035 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5036 }
a2fbb9ea
ET
5037}
5038
9f6c9258 5039irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5040{
5041 struct net_device *dev = dev_instance;
5042 struct bnx2x *bp = netdev_priv(dev);
5043
523224a3
DK
5044 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5045 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5046
5047#ifdef BNX2X_STOP_ON_ERROR
5048 if (unlikely(bp->panic))
5049 return IRQ_HANDLED;
5050#endif
5051
55c11941 5052 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5053 struct cnic_ops *c_ops;
5054
5055 rcu_read_lock();
5056 c_ops = rcu_dereference(bp->cnic_ops);
5057 if (c_ops)
5058 c_ops->cnic_handler(bp->cnic_data, NULL);
5059 rcu_read_unlock();
5060 }
55c11941 5061
1cf167f2 5062 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
a2fbb9ea
ET
5063
5064 return IRQ_HANDLED;
5065}
5066
5067/* end of slow path */
5068
619c5cb6
VZ
5069
5070void bnx2x_drv_pulse(struct bnx2x *bp)
5071{
5072 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5073 bp->fw_drv_pulse_wr_seq);
5074}
5075
5076
a2fbb9ea
ET
5077static void bnx2x_timer(unsigned long data)
5078{
5079 struct bnx2x *bp = (struct bnx2x *) data;
5080
5081 if (!netif_running(bp->dev))
5082 return;
5083
34f80b04 5084 if (!BP_NOMCP(bp)) {
f2e0899f 5085 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
5086 u32 drv_pulse;
5087 u32 mcp_pulse;
5088
5089 ++bp->fw_drv_pulse_wr_seq;
5090 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5091 /* TBD - add SYSTEM_TIME */
5092 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5093 bnx2x_drv_pulse(bp);
a2fbb9ea 5094
f2e0899f 5095 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5096 MCP_PULSE_SEQ_MASK);
5097 /* The delta between driver pulse and mcp response
5098 * should be 1 (before mcp response) or 0 (after mcp response)
5099 */
5100 if ((drv_pulse != mcp_pulse) &&
5101 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5102 /* someone lost a heartbeat... */
5103 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5104 drv_pulse, mcp_pulse);
5105 }
5106 }
5107
f34d28ea 5108 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5109 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5110
a2fbb9ea
ET
5111 mod_timer(&bp->timer, jiffies + bp->current_interval);
5112}
5113
5114/* end of Statistics */
5115
5116/* nic init */
5117
5118/*
5119 * nic init service functions
5120 */
5121
1191cb83 5122static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5123{
523224a3
DK
5124 u32 i;
5125 if (!(len%4) && !(addr%4))
5126 for (i = 0; i < len; i += 4)
5127 REG_WR(bp, addr + i, fill);
5128 else
5129 for (i = 0; i < len; i++)
5130 REG_WR8(bp, addr + i, fill);
34f80b04 5131
34f80b04
EG
5132}
5133
523224a3 5134/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5135static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5136 int fw_sb_id,
5137 u32 *sb_data_p,
5138 u32 data_size)
34f80b04 5139{
a2fbb9ea 5140 int index;
523224a3
DK
5141 for (index = 0; index < data_size; index++)
5142 REG_WR(bp, BAR_CSTRORM_INTMEM +
5143 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5144 sizeof(u32)*index,
5145 *(sb_data_p + index));
5146}
a2fbb9ea 5147
1191cb83 5148static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5149{
5150 u32 *sb_data_p;
5151 u32 data_size = 0;
f2e0899f 5152 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5153 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5154
523224a3 5155 /* disable the function first */
619c5cb6 5156 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5157 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5158 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5159 sb_data_e2.common.p_func.vf_valid = false;
5160 sb_data_p = (u32 *)&sb_data_e2;
5161 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5162 } else {
5163 memset(&sb_data_e1x, 0,
5164 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5165 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5166 sb_data_e1x.common.p_func.vf_valid = false;
5167 sb_data_p = (u32 *)&sb_data_e1x;
5168 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5169 }
523224a3 5170 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5171
523224a3
DK
5172 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5173 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5174 CSTORM_STATUS_BLOCK_SIZE);
5175 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5176 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5177 CSTORM_SYNC_BLOCK_SIZE);
5178}
34f80b04 5179
523224a3 5180/* helper: writes SP SB data to FW */
1191cb83 5181static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5182 struct hc_sp_status_block_data *sp_sb_data)
5183{
5184 int func = BP_FUNC(bp);
5185 int i;
5186 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5187 REG_WR(bp, BAR_CSTRORM_INTMEM +
5188 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5189 i*sizeof(u32),
5190 *((u32 *)sp_sb_data + i));
34f80b04
EG
5191}
5192
1191cb83 5193static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5194{
5195 int func = BP_FUNC(bp);
523224a3
DK
5196 struct hc_sp_status_block_data sp_sb_data;
5197 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5198
619c5cb6 5199 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5200 sp_sb_data.p_func.vf_valid = false;
5201
5202 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5203
5204 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5205 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5206 CSTORM_SP_STATUS_BLOCK_SIZE);
5207 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5208 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5209 CSTORM_SP_SYNC_BLOCK_SIZE);
5210
5211}
5212
5213
1191cb83 5214static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5215 int igu_sb_id, int igu_seg_id)
5216{
5217 hc_sm->igu_sb_id = igu_sb_id;
5218 hc_sm->igu_seg_id = igu_seg_id;
5219 hc_sm->timer_value = 0xFF;
5220 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5221}
5222
150966ad
AE
5223
5224/* allocates state machine ids. */
1191cb83 5225static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5226{
5227 /* zero out state machine indices */
5228 /* rx indices */
5229 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5230
5231 /* tx indices */
5232 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5233 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5234 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5235 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5236
5237 /* map indices */
5238 /* rx indices */
5239 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5240 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5241
5242 /* tx indices */
5243 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5244 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5245 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5246 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5247 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5248 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5249 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5250 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5251}
5252
8d96286a 5253static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5254 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5255{
523224a3
DK
5256 int igu_seg_id;
5257
f2e0899f 5258 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5259 struct hc_status_block_data_e1x sb_data_e1x;
5260 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5261 int data_size;
5262 u32 *sb_data_p;
5263
f2e0899f
DK
5264 if (CHIP_INT_MODE_IS_BC(bp))
5265 igu_seg_id = HC_SEG_ACCESS_NORM;
5266 else
5267 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5268
5269 bnx2x_zero_fp_sb(bp, fw_sb_id);
5270
619c5cb6 5271 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5272 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5273 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5274 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5275 sb_data_e2.common.p_func.vf_id = vfid;
5276 sb_data_e2.common.p_func.vf_valid = vf_valid;
5277 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5278 sb_data_e2.common.same_igu_sb_1b = true;
5279 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5280 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5281 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5282 sb_data_p = (u32 *)&sb_data_e2;
5283 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5284 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5285 } else {
5286 memset(&sb_data_e1x, 0,
5287 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5288 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5289 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5290 sb_data_e1x.common.p_func.vf_id = 0xff;
5291 sb_data_e1x.common.p_func.vf_valid = false;
5292 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5293 sb_data_e1x.common.same_igu_sb_1b = true;
5294 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5295 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5296 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5297 sb_data_p = (u32 *)&sb_data_e1x;
5298 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5299 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5300 }
523224a3
DK
5301
5302 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5303 igu_sb_id, igu_seg_id);
5304 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5305 igu_sb_id, igu_seg_id);
5306
51c1a580 5307 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3
DK
5308
5309 /* write indecies to HW */
5310 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5311}
5312
619c5cb6 5313static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5314 u16 tx_usec, u16 rx_usec)
5315{
6383c0b3 5316 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5317 false, rx_usec);
6383c0b3
AE
5318 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5319 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5320 tx_usec);
5321 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5322 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5323 tx_usec);
5324 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5325 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5326 tx_usec);
523224a3 5327}
f2e0899f 5328
523224a3
DK
5329static void bnx2x_init_def_sb(struct bnx2x *bp)
5330{
5331 struct host_sp_status_block *def_sb = bp->def_status_blk;
5332 dma_addr_t mapping = bp->def_status_blk_mapping;
5333 int igu_sp_sb_index;
5334 int igu_seg_id;
34f80b04
EG
5335 int port = BP_PORT(bp);
5336 int func = BP_FUNC(bp);
f2eaeb58 5337 int reg_offset, reg_offset_en5;
a2fbb9ea 5338 u64 section;
523224a3
DK
5339 int index;
5340 struct hc_sp_status_block_data sp_sb_data;
5341 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5342
f2e0899f
DK
5343 if (CHIP_INT_MODE_IS_BC(bp)) {
5344 igu_sp_sb_index = DEF_SB_IGU_ID;
5345 igu_seg_id = HC_SEG_ACCESS_DEF;
5346 } else {
5347 igu_sp_sb_index = bp->igu_dsb_id;
5348 igu_seg_id = IGU_SEG_ACCESS_DEF;
5349 }
a2fbb9ea
ET
5350
5351 /* ATTN */
523224a3 5352 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5353 atten_status_block);
523224a3 5354 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5355
49d66772
ET
5356 bp->attn_state = 0;
5357
a2fbb9ea
ET
5358 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5359 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5360 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5361 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5362 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5363 int sindex;
5364 /* take care of sig[0]..sig[4] */
5365 for (sindex = 0; sindex < 4; sindex++)
5366 bp->attn_group[index].sig[sindex] =
5367 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5368
619c5cb6 5369 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5370 /*
5371 * enable5 is separate from the rest of the registers,
5372 * and therefore the address skip is 4
5373 * and not 16 between the different groups
5374 */
5375 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5376 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5377 else
5378 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5379 }
5380
f2e0899f
DK
5381 if (bp->common.int_block == INT_BLOCK_HC) {
5382 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5383 HC_REG_ATTN_MSG0_ADDR_L);
5384
5385 REG_WR(bp, reg_offset, U64_LO(section));
5386 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5387 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5388 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5389 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5390 }
a2fbb9ea 5391
523224a3
DK
5392 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5393 sp_sb);
a2fbb9ea 5394
523224a3 5395 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5396
619c5cb6 5397 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5398 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5399 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5400 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5401 sp_sb_data.igu_seg_id = igu_seg_id;
5402 sp_sb_data.p_func.pf_id = func;
f2e0899f 5403 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5404 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5405
523224a3 5406 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5407
523224a3 5408 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5409}
5410
9f6c9258 5411void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5412{
a2fbb9ea
ET
5413 int i;
5414
ec6ba945 5415 for_each_eth_queue(bp, i)
523224a3 5416 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5417 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5418}
5419
a2fbb9ea
ET
5420static void bnx2x_init_sp_ring(struct bnx2x *bp)
5421{
a2fbb9ea 5422 spin_lock_init(&bp->spq_lock);
6e30dd4e 5423 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5424
a2fbb9ea 5425 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5426 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5427 bp->spq_prod_bd = bp->spq;
5428 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5429}
5430
523224a3 5431static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5432{
5433 int i;
523224a3
DK
5434 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5435 union event_ring_elem *elem =
5436 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5437
523224a3
DK
5438 elem->next_page.addr.hi =
5439 cpu_to_le32(U64_HI(bp->eq_mapping +
5440 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5441 elem->next_page.addr.lo =
5442 cpu_to_le32(U64_LO(bp->eq_mapping +
5443 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5444 }
523224a3
DK
5445 bp->eq_cons = 0;
5446 bp->eq_prod = NUM_EQ_DESC;
5447 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6e30dd4e
VZ
5448 /* we want a warning message before it gets rought... */
5449 atomic_set(&bp->eq_spq_left,
5450 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5451}
5452
619c5cb6
VZ
5453
5454/* called with netif_addr_lock_bh() */
5455void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5456 unsigned long rx_mode_flags,
5457 unsigned long rx_accept_flags,
5458 unsigned long tx_accept_flags,
5459 unsigned long ramrod_flags)
ab532cf3 5460{
619c5cb6
VZ
5461 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5462 int rc;
5463
5464 memset(&ramrod_param, 0, sizeof(ramrod_param));
5465
5466 /* Prepare ramrod parameters */
5467 ramrod_param.cid = 0;
5468 ramrod_param.cl_id = cl_id;
5469 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5470 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5471
619c5cb6
VZ
5472 ramrod_param.pstate = &bp->sp_state;
5473 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5474
619c5cb6
VZ
5475 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5476 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5477
5478 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5479
5480 ramrod_param.ramrod_flags = ramrod_flags;
5481 ramrod_param.rx_mode_flags = rx_mode_flags;
5482
5483 ramrod_param.rx_accept_flags = rx_accept_flags;
5484 ramrod_param.tx_accept_flags = tx_accept_flags;
5485
5486 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5487 if (rc < 0) {
5488 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5489 return;
5490 }
a2fbb9ea
ET
5491}
5492
619c5cb6
VZ
5493/* called with netif_addr_lock_bh() */
5494void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
471de716 5495{
619c5cb6
VZ
5496 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5497 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
471de716 5498
619c5cb6
VZ
5499 if (!NO_FCOE(bp))
5500
5501 /* Configure rx_mode of FCoE Queue */
5502 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
619c5cb6
VZ
5503
5504 switch (bp->rx_mode) {
5505 case BNX2X_RX_MODE_NONE:
5506 /*
5507 * 'drop all' supersedes any accept flags that may have been
5508 * passed to the function.
5509 */
5510 break;
5511 case BNX2X_RX_MODE_NORMAL:
5512 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5513 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5514 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5515
5516 /* internal switching mode */
5517 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5518 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5519 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5520
5521 break;
5522 case BNX2X_RX_MODE_ALLMULTI:
5523 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5524 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5525 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5526
5527 /* internal switching mode */
5528 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5529 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5530 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5531
5532 break;
5533 case BNX2X_RX_MODE_PROMISC:
5534 /* According to deffinition of SI mode, iface in promisc mode
5535 * should receive matched and unmatched (in resolution of port)
5536 * unicast packets.
5537 */
5538 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5539 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5540 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5541 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5542
5543 /* internal switching mode */
5544 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5545 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5546
5547 if (IS_MF_SI(bp))
5548 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5549 else
5550 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5551
5552 break;
5553 default:
5554 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5555 return;
5556 }
de832a55 5557
619c5cb6
VZ
5558 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5559 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5560 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
34f80b04
EG
5561 }
5562
619c5cb6
VZ
5563 __set_bit(RAMROD_RX, &ramrod_flags);
5564 __set_bit(RAMROD_TX, &ramrod_flags);
5565
5566 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5567 tx_accept_flags, ramrod_flags);
5568}
5569
5570static void bnx2x_init_internal_common(struct bnx2x *bp)
5571{
5572 int i;
5573
0793f83f
DK
5574 if (IS_MF_SI(bp))
5575 /*
5576 * In switch independent mode, the TSTORM needs to accept
5577 * packets that failed classification, since approximate match
5578 * mac addresses aren't written to NIG LLH
5579 */
5580 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5581 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5582 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5583 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5584 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5585
523224a3
DK
5586 /* Zero this manually as its initialization is
5587 currently missing in the initTool */
5588 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5589 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5590 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5591 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5592 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5593 CHIP_INT_MODE_IS_BC(bp) ?
5594 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5595 }
523224a3 5596}
8a1c38d1 5597
471de716
EG
5598static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5599{
5600 switch (load_code) {
5601 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5602 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5603 bnx2x_init_internal_common(bp);
5604 /* no break */
5605
5606 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5607 /* nothing to do */
471de716
EG
5608 /* no break */
5609
5610 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5611 /* internal memory per function is
5612 initialized inside bnx2x_pf_init */
471de716
EG
5613 break;
5614
5615 default:
5616 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5617 break;
5618 }
5619}
5620
619c5cb6 5621static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5622{
55c11941 5623 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 5624}
523224a3 5625
619c5cb6
VZ
5626static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5627{
55c11941 5628 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
5629}
5630
1191cb83 5631static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
5632{
5633 if (CHIP_IS_E1x(fp->bp))
5634 return BP_L_ID(fp->bp) + fp->index;
5635 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5636 return bnx2x_fp_igu_sb_id(fp);
5637}
5638
6383c0b3 5639static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5640{
5641 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5642 u8 cos;
619c5cb6 5643 unsigned long q_type = 0;
6383c0b3 5644 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5645 fp->rx_queue = fp_idx;
b3b83c3f 5646 fp->cid = fp_idx;
619c5cb6
VZ
5647 fp->cl_id = bnx2x_fp_cl_id(fp);
5648 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5649 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5650 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5651 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5652
523224a3 5653 /* init shortcut */
619c5cb6 5654 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5655
523224a3
DK
5656 /* Setup SB indicies */
5657 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5658
619c5cb6
VZ
5659 /* Configure Queue State object */
5660 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5661 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5662
5663 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5664
5665 /* init tx data */
5666 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
5667 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5668 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5669 FP_COS_TO_TXQ(fp, cos, bp),
5670 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5671 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
5672 }
5673
15192a8c
BW
5674 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5675 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 5676 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5677
5678 /**
5679 * Configure classification DBs: Always enable Tx switching
5680 */
5681 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5682
51c1a580 5683 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
619c5cb6 5684 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
523224a3
DK
5685 fp->igu_sb_id);
5686 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5687 fp->fw_sb_id, fp->igu_sb_id);
5688
5689 bnx2x_update_fpsb_idx(fp);
5690}
5691
1191cb83
ED
5692static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5693{
5694 int i;
5695
5696 for (i = 1; i <= NUM_TX_RINGS; i++) {
5697 struct eth_tx_next_bd *tx_next_bd =
5698 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5699
5700 tx_next_bd->addr_hi =
5701 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5702 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5703 tx_next_bd->addr_lo =
5704 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5705 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5706 }
5707
5708 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5709 txdata->tx_db.data.zero_fill1 = 0;
5710 txdata->tx_db.data.prod = 0;
5711
5712 txdata->tx_pkt_prod = 0;
5713 txdata->tx_pkt_cons = 0;
5714 txdata->tx_bd_prod = 0;
5715 txdata->tx_bd_cons = 0;
5716 txdata->tx_pkt = 0;
5717}
5718
55c11941
MS
5719static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
5720{
5721 int i;
5722
5723 for_each_tx_queue_cnic(bp, i)
5724 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
5725}
1191cb83
ED
5726static void bnx2x_init_tx_rings(struct bnx2x *bp)
5727{
5728 int i;
5729 u8 cos;
5730
55c11941 5731 for_each_eth_queue(bp, i)
1191cb83 5732 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 5733 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
5734}
5735
55c11941 5736void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 5737{
ec6ba945
VZ
5738 if (!NO_FCOE(bp))
5739 bnx2x_init_fcoe_fp(bp);
523224a3
DK
5740
5741 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5742 BNX2X_VF_ID_INVALID, false,
619c5cb6 5743 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 5744
55c11941
MS
5745 /* ensure status block indices were read */
5746 rmb();
5747 bnx2x_init_rx_rings_cnic(bp);
5748 bnx2x_init_tx_rings_cnic(bp);
5749
5750 /* flush all */
5751 mb();
5752 mmiowb();
5753}
a2fbb9ea 5754
55c11941
MS
5755void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5756{
5757 int i;
5758
5759 for_each_eth_queue(bp, i)
5760 bnx2x_init_eth_fp(bp, i);
020c7e3f
YR
5761 /* Initialize MOD_ABS interrupts */
5762 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5763 bp->common.shmem_base, bp->common.shmem2_base,
5764 BP_PORT(bp));
16119785
EG
5765 /* ensure status block indices were read */
5766 rmb();
5767
523224a3 5768 bnx2x_init_def_sb(bp);
5c862848 5769 bnx2x_update_dsb_idx(bp);
a2fbb9ea 5770 bnx2x_init_rx_rings(bp);
523224a3 5771 bnx2x_init_tx_rings(bp);
a2fbb9ea 5772 bnx2x_init_sp_ring(bp);
523224a3 5773 bnx2x_init_eq_ring(bp);
471de716 5774 bnx2x_init_internal(bp, load_code);
523224a3 5775 bnx2x_pf_init(bp);
0ef00459
EG
5776 bnx2x_stats_init(bp);
5777
0ef00459
EG
5778 /* flush all before enabling interrupts */
5779 mb();
5780 mmiowb();
5781
615f8fd9 5782 bnx2x_int_enable(bp);
eb8da205
EG
5783
5784 /* Check for SPIO5 */
5785 bnx2x_attn_int_deasserted0(bp,
5786 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5787 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
5788}
5789
5790/* end of nic init */
5791
5792/*
5793 * gzip service functions
5794 */
5795
5796static int bnx2x_gunzip_init(struct bnx2x *bp)
5797{
1a983142
FT
5798 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5799 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
5800 if (bp->gunzip_buf == NULL)
5801 goto gunzip_nomem1;
5802
5803 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5804 if (bp->strm == NULL)
5805 goto gunzip_nomem2;
5806
7ab24bfd 5807 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
5808 if (bp->strm->workspace == NULL)
5809 goto gunzip_nomem3;
5810
5811 return 0;
5812
5813gunzip_nomem3:
5814 kfree(bp->strm);
5815 bp->strm = NULL;
5816
5817gunzip_nomem2:
1a983142
FT
5818 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5819 bp->gunzip_mapping);
a2fbb9ea
ET
5820 bp->gunzip_buf = NULL;
5821
5822gunzip_nomem1:
51c1a580 5823 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
5824 return -ENOMEM;
5825}
5826
5827static void bnx2x_gunzip_end(struct bnx2x *bp)
5828{
b3b83c3f 5829 if (bp->strm) {
7ab24bfd 5830 vfree(bp->strm->workspace);
b3b83c3f
DK
5831 kfree(bp->strm);
5832 bp->strm = NULL;
5833 }
a2fbb9ea
ET
5834
5835 if (bp->gunzip_buf) {
1a983142
FT
5836 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5837 bp->gunzip_mapping);
a2fbb9ea
ET
5838 bp->gunzip_buf = NULL;
5839 }
5840}
5841
94a78b79 5842static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
5843{
5844 int n, rc;
5845
5846 /* check gzip header */
94a78b79
VZ
5847 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5848 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 5849 return -EINVAL;
94a78b79 5850 }
a2fbb9ea
ET
5851
5852 n = 10;
5853
34f80b04 5854#define FNAME 0x8
a2fbb9ea
ET
5855
5856 if (zbuf[3] & FNAME)
5857 while ((zbuf[n++] != 0) && (n < len));
5858
94a78b79 5859 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
5860 bp->strm->avail_in = len - n;
5861 bp->strm->next_out = bp->gunzip_buf;
5862 bp->strm->avail_out = FW_BUF_SIZE;
5863
5864 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5865 if (rc != Z_OK)
5866 return rc;
5867
5868 rc = zlib_inflate(bp->strm, Z_FINISH);
5869 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
5870 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5871 bp->strm->msg);
a2fbb9ea
ET
5872
5873 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5874 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
5875 netdev_err(bp->dev,
5876 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 5877 bp->gunzip_outlen);
a2fbb9ea
ET
5878 bp->gunzip_outlen >>= 2;
5879
5880 zlib_inflateEnd(bp->strm);
5881
5882 if (rc == Z_STREAM_END)
5883 return 0;
5884
5885 return rc;
5886}
5887
5888/* nic load/unload */
5889
5890/*
34f80b04 5891 * General service functions
a2fbb9ea
ET
5892 */
5893
5894/* send a NIG loopback debug packet */
5895static void bnx2x_lb_pckt(struct bnx2x *bp)
5896{
a2fbb9ea 5897 u32 wb_write[3];
a2fbb9ea
ET
5898
5899 /* Ethernet source and destination addresses */
a2fbb9ea
ET
5900 wb_write[0] = 0x55555555;
5901 wb_write[1] = 0x55555555;
34f80b04 5902 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 5903 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5904
5905 /* NON-IP protocol */
a2fbb9ea
ET
5906 wb_write[0] = 0x09000000;
5907 wb_write[1] = 0x55555555;
34f80b04 5908 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 5909 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
5910}
5911
5912/* some of the internal memories
5913 * are not directly readable from the driver
5914 * to test them we send debug packets
5915 */
5916static int bnx2x_int_mem_test(struct bnx2x *bp)
5917{
5918 int factor;
5919 int count, i;
5920 u32 val = 0;
5921
ad8d3948 5922 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 5923 factor = 120;
ad8d3948
EG
5924 else if (CHIP_REV_IS_EMUL(bp))
5925 factor = 200;
5926 else
a2fbb9ea 5927 factor = 1;
a2fbb9ea 5928
a2fbb9ea
ET
5929 /* Disable inputs of parser neighbor blocks */
5930 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5931 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5932 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5933 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5934
5935 /* Write 0 to parser credits for CFC search request */
5936 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5937
5938 /* send Ethernet packet */
5939 bnx2x_lb_pckt(bp);
5940
5941 /* TODO do i reset NIG statistic? */
5942 /* Wait until NIG register shows 1 packet of size 0x10 */
5943 count = 1000 * factor;
5944 while (count) {
34f80b04 5945
a2fbb9ea
ET
5946 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5947 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
5948 if (val == 0x10)
5949 break;
5950
5951 msleep(10);
5952 count--;
5953 }
5954 if (val != 0x10) {
5955 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5956 return -1;
5957 }
5958
5959 /* Wait until PRS register shows 1 packet */
5960 count = 1000 * factor;
5961 while (count) {
5962 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
5963 if (val == 1)
5964 break;
5965
5966 msleep(10);
5967 count--;
5968 }
5969 if (val != 0x1) {
5970 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5971 return -2;
5972 }
5973
5974 /* Reset and init BRB, PRS */
34f80b04 5975 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 5976 msleep(50);
34f80b04 5977 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 5978 msleep(50);
619c5cb6
VZ
5979 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5980 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
5981
5982 DP(NETIF_MSG_HW, "part2\n");
5983
5984 /* Disable inputs of parser neighbor blocks */
5985 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5986 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5987 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 5988 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
5989
5990 /* Write 0 to parser credits for CFC search request */
5991 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5992
5993 /* send 10 Ethernet packets */
5994 for (i = 0; i < 10; i++)
5995 bnx2x_lb_pckt(bp);
5996
5997 /* Wait until NIG register shows 10 + 1
5998 packets of size 11*0x10 = 0xb0 */
5999 count = 1000 * factor;
6000 while (count) {
34f80b04 6001
a2fbb9ea
ET
6002 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6003 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6004 if (val == 0xb0)
6005 break;
6006
6007 msleep(10);
6008 count--;
6009 }
6010 if (val != 0xb0) {
6011 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6012 return -3;
6013 }
6014
6015 /* Wait until PRS register shows 2 packets */
6016 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6017 if (val != 2)
6018 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6019
6020 /* Write 1 to parser credits for CFC search request */
6021 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6022
6023 /* Wait until PRS register shows 3 packets */
6024 msleep(10 * factor);
6025 /* Wait until NIG register shows 1 packet of size 0x10 */
6026 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6027 if (val != 3)
6028 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6029
6030 /* clear NIG EOP FIFO */
6031 for (i = 0; i < 11; i++)
6032 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6033 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6034 if (val != 1) {
6035 BNX2X_ERR("clear of NIG failed\n");
6036 return -4;
6037 }
6038
6039 /* Reset and init BRB, PRS, NIG */
6040 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6041 msleep(50);
6042 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6043 msleep(50);
619c5cb6
VZ
6044 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6045 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6046 if (!CNIC_SUPPORT(bp))
6047 /* set NIC mode */
6048 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6049
6050 /* Enable inputs of parser neighbor blocks */
6051 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6052 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6053 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6054 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6055
6056 DP(NETIF_MSG_HW, "done\n");
6057
6058 return 0; /* OK */
6059}
6060
4a33bc03 6061static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea
ET
6062{
6063 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6064 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6065 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6066 else
6067 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6068 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6069 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6070 /*
6071 * mask read length error interrupts in brb for parser
6072 * (parsing unit and 'checksum and crc' unit)
6073 * these errors are legal (PU reads fixed length and CAC can cause
6074 * read length error on truncated packets)
6075 */
6076 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6077 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6078 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6079 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6080 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6081 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6082/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6083/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6084 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6085 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6086 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6087/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6088/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6089 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6090 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6091 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6092 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6093/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6094/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6095
34f80b04
EG
6096 if (CHIP_REV_IS_FPGA(bp))
6097 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
619c5cb6 6098 else if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6099 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
6100 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
6101 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
6102 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
6103 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
6104 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
34f80b04
EG
6105 else
6106 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
a2fbb9ea
ET
6107 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6108 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6109 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6110/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6111
6112 if (!CHIP_IS_E1x(bp))
6113 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6114 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6115
a2fbb9ea
ET
6116 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6117 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6118/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6119 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6120}
6121
81f75bbf
EG
6122static void bnx2x_reset_common(struct bnx2x *bp)
6123{
619c5cb6
VZ
6124 u32 val = 0x1400;
6125
81f75bbf
EG
6126 /* reset_common */
6127 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6128 0xd3ffff7f);
619c5cb6
VZ
6129
6130 if (CHIP_IS_E3(bp)) {
6131 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6132 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6133 }
6134
6135 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6136}
6137
6138static void bnx2x_setup_dmae(struct bnx2x *bp)
6139{
6140 bp->dmae_ready = 0;
6141 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6142}
6143
573f2035
EG
6144static void bnx2x_init_pxp(struct bnx2x *bp)
6145{
6146 u16 devctl;
6147 int r_order, w_order;
6148
2a80eebc 6149 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6150 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6151 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6152 if (bp->mrrs == -1)
6153 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6154 else {
6155 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6156 r_order = bp->mrrs;
6157 }
6158
6159 bnx2x_init_pxp_arb(bp, r_order, w_order);
6160}
fd4ef40d
EG
6161
6162static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6163{
2145a920 6164 int is_required;
fd4ef40d 6165 u32 val;
2145a920 6166 int port;
fd4ef40d 6167
2145a920
VZ
6168 if (BP_NOMCP(bp))
6169 return;
6170
6171 is_required = 0;
fd4ef40d
EG
6172 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6173 SHARED_HW_CFG_FAN_FAILURE_MASK;
6174
6175 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6176 is_required = 1;
6177
6178 /*
6179 * The fan failure mechanism is usually related to the PHY type since
6180 * the power consumption of the board is affected by the PHY. Currently,
6181 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6182 */
6183 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6184 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6185 is_required |=
d90d96ba
YR
6186 bnx2x_fan_failure_det_req(
6187 bp,
6188 bp->common.shmem_base,
a22f0788 6189 bp->common.shmem2_base,
d90d96ba 6190 port);
fd4ef40d
EG
6191 }
6192
6193 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6194
6195 if (is_required == 0)
6196 return;
6197
6198 /* Fan failure is indicated by SPIO 5 */
6199 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
6200 MISC_REGISTERS_SPIO_INPUT_HI_Z);
6201
6202 /* set to active low mode */
6203 val = REG_RD(bp, MISC_REG_SPIO_INT);
6204 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
cdaa7cb8 6205 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6206 REG_WR(bp, MISC_REG_SPIO_INT, val);
6207
6208 /* enable interrupt to signal the IGU */
6209 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6210 val |= (1 << MISC_REGISTERS_SPIO_5);
6211 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6212}
6213
f2e0899f
DK
6214static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
6215{
6216 u32 offset = 0;
6217
6218 if (CHIP_IS_E1(bp))
6219 return;
6220 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
6221 return;
6222
6223 switch (BP_ABS_FUNC(bp)) {
6224 case 0:
6225 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
6226 break;
6227 case 1:
6228 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
6229 break;
6230 case 2:
6231 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
6232 break;
6233 case 3:
6234 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
6235 break;
6236 case 4:
6237 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
6238 break;
6239 case 5:
6240 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
6241 break;
6242 case 6:
6243 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
6244 break;
6245 case 7:
6246 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
6247 break;
6248 default:
6249 return;
6250 }
6251
6252 REG_WR(bp, offset, pretend_func_num);
6253 REG_RD(bp, offset);
6254 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
6255}
6256
c9ee9206 6257void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6258{
6259 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6260 val &= ~IGU_PF_CONF_FUNC_EN;
6261
6262 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6263 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6264 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6265}
6266
1191cb83 6267static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6268{
6269 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6270 /* Avoid common init in case MFW supports LFA */
6271 if (SHMEM2_RD(bp, size) >
6272 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6273 return;
619c5cb6
VZ
6274 shmem_base[0] = bp->common.shmem_base;
6275 shmem2_base[0] = bp->common.shmem2_base;
6276 if (!CHIP_IS_E1x(bp)) {
6277 shmem_base[1] =
6278 SHMEM2_RD(bp, other_shmem_base_addr);
6279 shmem2_base[1] =
6280 SHMEM2_RD(bp, other_shmem2_base_addr);
6281 }
6282 bnx2x_acquire_phy_lock(bp);
6283 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6284 bp->common.chip_id);
6285 bnx2x_release_phy_lock(bp);
6286}
6287
6288/**
6289 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6290 *
6291 * @bp: driver handle
6292 */
6293static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6294{
619c5cb6 6295 u32 val;
a2fbb9ea 6296
51c1a580 6297 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6298
2031bd3a
DK
6299 /*
6300 * take the UNDI lock to protect undi_unload flow from accessing
6301 * registers while we're resetting the chip
6302 */
7a06a122 6303 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6304
81f75bbf 6305 bnx2x_reset_common(bp);
34f80b04 6306 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6307
619c5cb6
VZ
6308 val = 0xfffc;
6309 if (CHIP_IS_E3(bp)) {
6310 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6311 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6312 }
6313 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6314
7a06a122 6315 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6316
619c5cb6 6317 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6318
619c5cb6
VZ
6319 if (!CHIP_IS_E1x(bp)) {
6320 u8 abs_func_id;
f2e0899f
DK
6321
6322 /**
6323 * 4-port mode or 2-port mode we need to turn of master-enable
6324 * for everyone, after that, turn it back on for self.
6325 * so, we disregard multi-function or not, and always disable
6326 * for all functions on the given path, this means 0,2,4,6 for
6327 * path 0 and 1,3,5,7 for path 1
6328 */
619c5cb6
VZ
6329 for (abs_func_id = BP_PATH(bp);
6330 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6331 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6332 REG_WR(bp,
6333 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6334 1);
6335 continue;
6336 }
6337
619c5cb6 6338 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6339 /* clear pf enable */
6340 bnx2x_pf_disable(bp);
6341 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6342 }
6343 }
a2fbb9ea 6344
619c5cb6 6345 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6346 if (CHIP_IS_E1(bp)) {
6347 /* enable HW interrupt from PXP on USDM overflow
6348 bit 16 on INT_MASK_0 */
6349 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6350 }
a2fbb9ea 6351
619c5cb6 6352 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6353 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6354
6355#ifdef __BIG_ENDIAN
34f80b04
EG
6356 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6357 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6358 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6359 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6360 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6361 /* make sure this value is 0 */
6362 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6363
6364/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6365 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6366 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6367 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6368 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6369#endif
6370
523224a3
DK
6371 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6372
34f80b04
EG
6373 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6374 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6375
34f80b04
EG
6376 /* let the HW do it's magic ... */
6377 msleep(100);
6378 /* finish PXP init */
6379 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6380 if (val != 1) {
6381 BNX2X_ERR("PXP2 CFG failed\n");
6382 return -EBUSY;
6383 }
6384 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6385 if (val != 1) {
6386 BNX2X_ERR("PXP2 RD_INIT failed\n");
6387 return -EBUSY;
6388 }
a2fbb9ea 6389
f2e0899f
DK
6390 /* Timers bug workaround E2 only. We need to set the entire ILT to
6391 * have entries with value "0" and valid bit on.
6392 * This needs to be done by the first PF that is loaded in a path
6393 * (i.e. common phase)
6394 */
619c5cb6
VZ
6395 if (!CHIP_IS_E1x(bp)) {
6396/* In E2 there is a bug in the timers block that can cause function 6 / 7
6397 * (i.e. vnic3) to start even if it is marked as "scan-off".
6398 * This occurs when a different function (func2,3) is being marked
6399 * as "scan-off". Real-life scenario for example: if a driver is being
6400 * load-unloaded while func6,7 are down. This will cause the timer to access
6401 * the ilt, translate to a logical address and send a request to read/write.
6402 * Since the ilt for the function that is down is not valid, this will cause
6403 * a translation error which is unrecoverable.
6404 * The Workaround is intended to make sure that when this happens nothing fatal
6405 * will occur. The workaround:
6406 * 1. First PF driver which loads on a path will:
6407 * a. After taking the chip out of reset, by using pretend,
6408 * it will write "0" to the following registers of
6409 * the other vnics.
6410 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6411 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6412 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6413 * And for itself it will write '1' to
6414 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6415 * dmae-operations (writing to pram for example.)
6416 * note: can be done for only function 6,7 but cleaner this
6417 * way.
6418 * b. Write zero+valid to the entire ILT.
6419 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6420 * VNIC3 (of that port). The range allocated will be the
6421 * entire ILT. This is needed to prevent ILT range error.
6422 * 2. Any PF driver load flow:
6423 * a. ILT update with the physical addresses of the allocated
6424 * logical pages.
6425 * b. Wait 20msec. - note that this timeout is needed to make
6426 * sure there are no requests in one of the PXP internal
6427 * queues with "old" ILT addresses.
6428 * c. PF enable in the PGLC.
6429 * d. Clear the was_error of the PF in the PGLC. (could have
6430 * occured while driver was down)
6431 * e. PF enable in the CFC (WEAK + STRONG)
6432 * f. Timers scan enable
6433 * 3. PF driver unload flow:
6434 * a. Clear the Timers scan_en.
6435 * b. Polling for scan_on=0 for that PF.
6436 * c. Clear the PF enable bit in the PXP.
6437 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6438 * e. Write zero+valid to all ILT entries (The valid bit must
6439 * stay set)
6440 * f. If this is VNIC 3 of a port then also init
6441 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6442 * to the last enrty in the ILT.
6443 *
6444 * Notes:
6445 * Currently the PF error in the PGLC is non recoverable.
6446 * In the future the there will be a recovery routine for this error.
6447 * Currently attention is masked.
6448 * Having an MCP lock on the load/unload process does not guarantee that
6449 * there is no Timer disable during Func6/7 enable. This is because the
6450 * Timers scan is currently being cleared by the MCP on FLR.
6451 * Step 2.d can be done only for PF6/7 and the driver can also check if
6452 * there is error before clearing it. But the flow above is simpler and
6453 * more general.
6454 * All ILT entries are written by zero+valid and not just PF6/7
6455 * ILT entries since in the future the ILT entries allocation for
6456 * PF-s might be dynamic.
6457 */
f2e0899f
DK
6458 struct ilt_client_info ilt_cli;
6459 struct bnx2x_ilt ilt;
6460 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6461 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6462
b595076a 6463 /* initialize dummy TM client */
f2e0899f
DK
6464 ilt_cli.start = 0;
6465 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6466 ilt_cli.client_num = ILT_CLIENT_TM;
6467
6468 /* Step 1: set zeroes to all ilt page entries with valid bit on
6469 * Step 2: set the timers first/last ilt entry to point
6470 * to the entire range to prevent ILT range error for 3rd/4th
619c5cb6 6471 * vnic (this code assumes existance of the vnic)
f2e0899f
DK
6472 *
6473 * both steps performed by call to bnx2x_ilt_client_init_op()
6474 * with dummy TM client
6475 *
6476 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6477 * and his brother are split registers
6478 */
6479 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6480 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6481 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6482
6483 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6484 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6485 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6486 }
6487
6488
34f80b04
EG
6489 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6490 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6491
619c5cb6 6492 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6493 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6494 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6495 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6496
619c5cb6 6497 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6498
6499 /* let the HW do it's magic ... */
6500 do {
6501 msleep(200);
6502 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6503 } while (factor-- && (val != 1));
6504
6505 if (val != 1) {
6506 BNX2X_ERR("ATC_INIT failed\n");
6507 return -EBUSY;
6508 }
6509 }
6510
619c5cb6 6511 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6512
34f80b04
EG
6513 /* clean the DMAE memory */
6514 bp->dmae_ready = 1;
619c5cb6
VZ
6515 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6516
6517 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6518
6519 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6520
6521 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6522
619c5cb6 6523 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6524
34f80b04
EG
6525 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6526 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6527 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6528 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6529
619c5cb6 6530 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6531
f85582f8 6532
523224a3
DK
6533 /* QM queues pointers table */
6534 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6535
34f80b04
EG
6536 /* soft reset pulse */
6537 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6538 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6539
55c11941
MS
6540 if (CNIC_SUPPORT(bp))
6541 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6542
619c5cb6 6543 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6544 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6545 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6546 /* enable hw interrupt from doorbell Q */
6547 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6548
619c5cb6 6549 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6550
619c5cb6 6551 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6552 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6553
f2e0899f 6554 if (!CHIP_IS_E1(bp))
619c5cb6 6555 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6556
a3348722
BW
6557 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6558 if (IS_MF_AFEX(bp)) {
6559 /* configure that VNTag and VLAN headers must be
6560 * received in afex mode
6561 */
6562 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6563 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6564 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6565 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6566 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6567 } else {
6568 /* Bit-map indicating which L2 hdrs may appear
6569 * after the basic Ethernet header
6570 */
6571 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6572 bp->path_has_ovlan ? 7 : 6);
6573 }
6574 }
a2fbb9ea 6575
619c5cb6
VZ
6576 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6577 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6578 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6579 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6580
619c5cb6
VZ
6581 if (!CHIP_IS_E1x(bp)) {
6582 /* reset VFC memories */
6583 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6584 VFC_MEMORIES_RST_REG_CAM_RST |
6585 VFC_MEMORIES_RST_REG_RAM_RST);
6586 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6587 VFC_MEMORIES_RST_REG_CAM_RST |
6588 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6589
619c5cb6
VZ
6590 msleep(20);
6591 }
a2fbb9ea 6592
619c5cb6
VZ
6593 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6594 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6595 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6596 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6597
34f80b04
EG
6598 /* sync semi rtc */
6599 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6600 0x80000000);
6601 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6602 0x80000000);
a2fbb9ea 6603
619c5cb6
VZ
6604 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6605 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6606 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6607
a3348722
BW
6608 if (!CHIP_IS_E1x(bp)) {
6609 if (IS_MF_AFEX(bp)) {
6610 /* configure that VNTag and VLAN headers must be
6611 * sent in afex mode
6612 */
6613 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6614 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6615 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6616 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6617 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6618 } else {
6619 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6620 bp->path_has_ovlan ? 7 : 6);
6621 }
6622 }
f2e0899f 6623
34f80b04 6624 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6625
619c5cb6
VZ
6626 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6627
55c11941
MS
6628 if (CNIC_SUPPORT(bp)) {
6629 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6630 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6631 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6632 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6633 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6634 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6635 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6636 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6637 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6638 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6639 }
34f80b04 6640 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6641
34f80b04
EG
6642 if (sizeof(union cdu_context) != 1024)
6643 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6644 dev_alert(&bp->pdev->dev,
6645 "please adjust the size of cdu_context(%ld)\n",
6646 (long)sizeof(union cdu_context));
a2fbb9ea 6647
619c5cb6 6648 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6649 val = (4 << 24) + (0 << 12) + 1024;
6650 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6651
619c5cb6 6652 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6653 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6654 /* enable context validation interrupt from CFC */
6655 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6656
6657 /* set the thresholds to prevent CFC/CDU race */
6658 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6659
619c5cb6 6660 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6661
619c5cb6 6662 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6663 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6664
619c5cb6
VZ
6665 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6666 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6667
34f80b04
EG
6668 /* Reset PCIE errors for debug */
6669 REG_WR(bp, 0x2814, 0xffffffff);
6670 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6671
619c5cb6 6672 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6673 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6674 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6675 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6676 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6677 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6678 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6679 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6680 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6681 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6682 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6683 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6684 }
6685
619c5cb6 6686 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6687 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6688 /* in E3 this done in per-port section */
6689 if (!CHIP_IS_E3(bp))
6690 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6691 }
619c5cb6
VZ
6692 if (CHIP_IS_E1H(bp))
6693 /* not applicable for E2 (and above ...) */
6694 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6695
6696 if (CHIP_REV_IS_SLOW(bp))
6697 msleep(200);
6698
6699 /* finish CFC init */
6700 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6701 if (val != 1) {
6702 BNX2X_ERR("CFC LL_INIT failed\n");
6703 return -EBUSY;
6704 }
6705 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6706 if (val != 1) {
6707 BNX2X_ERR("CFC AC_INIT failed\n");
6708 return -EBUSY;
6709 }
6710 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6711 if (val != 1) {
6712 BNX2X_ERR("CFC CAM_INIT failed\n");
6713 return -EBUSY;
6714 }
6715 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6716
f2e0899f
DK
6717 if (CHIP_IS_E1(bp)) {
6718 /* read NIG statistic
6719 to see if this is our first up since powerup */
6720 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6721 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6722
f2e0899f
DK
6723 /* do internal memory self test */
6724 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6725 BNX2X_ERR("internal mem self test failed\n");
6726 return -EBUSY;
6727 }
34f80b04
EG
6728 }
6729
fd4ef40d
EG
6730 bnx2x_setup_fan_failure_detection(bp);
6731
34f80b04
EG
6732 /* clear PXP2 attentions */
6733 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6734
4a33bc03 6735 bnx2x_enable_blocks_attention(bp);
c9ee9206 6736 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6737
6bbca910 6738 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6739 if (CHIP_IS_E1x(bp))
6740 bnx2x__common_init_phy(bp);
6bbca910
YR
6741 } else
6742 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6743
34f80b04
EG
6744 return 0;
6745}
a2fbb9ea 6746
619c5cb6
VZ
6747/**
6748 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6749 *
6750 * @bp: driver handle
6751 */
6752static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6753{
6754 int rc = bnx2x_init_hw_common(bp);
6755
6756 if (rc)
6757 return rc;
6758
6759 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6760 if (!BP_NOMCP(bp))
6761 bnx2x__common_init_phy(bp);
6762
6763 return 0;
6764}
6765
523224a3 6766static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6767{
6768 int port = BP_PORT(bp);
619c5cb6 6769 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6770 u32 low, high;
34f80b04 6771 u32 val;
a2fbb9ea 6772
619c5cb6 6773
51c1a580 6774 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
6775
6776 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 6777
619c5cb6
VZ
6778 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6779 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6780 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 6781
f2e0899f
DK
6782 /* Timers bug workaround: disables the pf_master bit in pglue at
6783 * common phase, we need to enable it here before any dmae access are
6784 * attempted. Therefore we manually added the enable-master to the
6785 * port phase (it also happens in the function phase)
6786 */
619c5cb6 6787 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6788 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6789
619c5cb6
VZ
6790 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6791 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6792 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6793 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6794
6795 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6796 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6797 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6798 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 6799
523224a3
DK
6800 /* QM cid (connection) count */
6801 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 6802
55c11941
MS
6803 if (CNIC_SUPPORT(bp)) {
6804 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6805 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6806 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6807 }
cdaa7cb8 6808
619c5cb6 6809 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 6810
2b674047
DK
6811 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6812
f2e0899f 6813 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
6814
6815 if (IS_MF(bp))
6816 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6817 else if (bp->dev->mtu > 4096) {
6818 if (bp->flags & ONE_PORT_FLAG)
6819 low = 160;
6820 else {
6821 val = bp->dev->mtu;
6822 /* (24*1024 + val*4)/256 */
6823 low = 96 + (val/64) +
6824 ((val % 64) ? 1 : 0);
6825 }
6826 } else
6827 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6828 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
6829 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6830 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 6831 }
1c06328c 6832
619c5cb6
VZ
6833 if (CHIP_MODE_IS_4_PORT(bp))
6834 REG_WR(bp, (BP_PORT(bp) ?
6835 BRB1_REG_MAC_GUARANTIED_1 :
6836 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 6837
ca00392c 6838
619c5cb6 6839 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
6840 if (CHIP_IS_E3B0(bp)) {
6841 if (IS_MF_AFEX(bp)) {
6842 /* configure headers for AFEX mode */
6843 REG_WR(bp, BP_PORT(bp) ?
6844 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6845 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
6846 REG_WR(bp, BP_PORT(bp) ?
6847 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
6848 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
6849 REG_WR(bp, BP_PORT(bp) ?
6850 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
6851 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
6852 } else {
6853 /* Ovlan exists only if we are in multi-function +
6854 * switch-dependent mode, in switch-independent there
6855 * is no ovlan headers
6856 */
6857 REG_WR(bp, BP_PORT(bp) ?
6858 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6859 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6860 (bp->path_has_ovlan ? 7 : 6));
6861 }
6862 }
356e2385 6863
619c5cb6
VZ
6864 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6865 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6866 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6867 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 6868
619c5cb6
VZ
6869 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6870 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6871 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6872 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 6873
619c5cb6
VZ
6874 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6875 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 6876
619c5cb6
VZ
6877 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6878
6879 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
6880 /* configure PBF to work without PAUSE mtu 9000 */
6881 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 6882
f2e0899f
DK
6883 /* update threshold */
6884 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6885 /* update init credit */
6886 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 6887
f2e0899f
DK
6888 /* probe changes */
6889 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6890 udelay(50);
6891 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6892 }
a2fbb9ea 6893
55c11941
MS
6894 if (CNIC_SUPPORT(bp))
6895 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6896
619c5cb6
VZ
6897 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6898 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
6899
6900 if (CHIP_IS_E1(bp)) {
6901 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6902 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6903 }
619c5cb6 6904 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 6905
619c5cb6 6906 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 6907
619c5cb6 6908 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04
EG
6909 /* init aeu_mask_attn_func_0/1:
6910 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6911 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6912 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
6913 val = IS_MF(bp) ? 0xF7 : 0x7;
6914 /* Enable DCBX attention for all but E1 */
6915 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6916 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 6917
619c5cb6
VZ
6918 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6919
6920 if (!CHIP_IS_E1x(bp)) {
6921 /* Bit-map indicating which L2 hdrs may appear after the
6922 * basic Ethernet header
6923 */
a3348722
BW
6924 if (IS_MF_AFEX(bp))
6925 REG_WR(bp, BP_PORT(bp) ?
6926 NIG_REG_P1_HDRS_AFTER_BASIC :
6927 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
6928 else
6929 REG_WR(bp, BP_PORT(bp) ?
6930 NIG_REG_P1_HDRS_AFTER_BASIC :
6931 NIG_REG_P0_HDRS_AFTER_BASIC,
6932 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
6933
6934 if (CHIP_IS_E3(bp))
6935 REG_WR(bp, BP_PORT(bp) ?
6936 NIG_REG_LLH1_MF_MODE :
6937 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6938 }
6939 if (!CHIP_IS_E3(bp))
6940 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 6941
f2e0899f 6942 if (!CHIP_IS_E1(bp)) {
fb3bff17 6943 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 6944 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 6945 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 6946
619c5cb6 6947 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6948 val = 0;
6949 switch (bp->mf_mode) {
6950 case MULTI_FUNCTION_SD:
6951 val = 1;
6952 break;
6953 case MULTI_FUNCTION_SI:
a3348722 6954 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
6955 val = 2;
6956 break;
6957 }
6958
6959 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6960 NIG_REG_LLH0_CLS_TYPE), val);
6961 }
1c06328c
EG
6962 {
6963 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6964 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6965 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6966 }
34f80b04
EG
6967 }
6968
619c5cb6
VZ
6969
6970 /* If SPIO5 is set to generate interrupts, enable it for this port */
6971 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6972 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
4d295db0
EG
6973 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6974 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6975 val = REG_RD(bp, reg_addr);
f1410647 6976 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 6977 REG_WR(bp, reg_addr, val);
f1410647 6978 }
a2fbb9ea 6979
34f80b04
EG
6980 return 0;
6981}
6982
34f80b04
EG
6983static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6984{
6985 int reg;
32d68de1 6986 u32 wb_write[2];
34f80b04 6987
f2e0899f 6988 if (CHIP_IS_E1(bp))
34f80b04 6989 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
6990 else
6991 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 6992
32d68de1
YM
6993 wb_write[0] = ONCHIP_ADDR1(addr);
6994 wb_write[1] = ONCHIP_ADDR2(addr);
6995 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
6996}
6997
1191cb83
ED
6998static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
6999 u8 idu_sb_id, bool is_Pf)
7000{
7001 u32 data, ctl, cnt = 100;
7002 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7003 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7004 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7005 u32 sb_bit = 1 << (idu_sb_id%32);
7006 u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
7007 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7008
7009 /* Not supported in BC mode */
7010 if (CHIP_INT_MODE_IS_BC(bp))
7011 return;
7012
7013 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7014 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7015 IGU_REGULAR_CLEANUP_SET |
7016 IGU_REGULAR_BCLEANUP;
7017
7018 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7019 func_encode << IGU_CTRL_REG_FID_SHIFT |
7020 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7021
7022 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7023 data, igu_addr_data);
7024 REG_WR(bp, igu_addr_data, data);
7025 mmiowb();
7026 barrier();
7027 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7028 ctl, igu_addr_ctl);
7029 REG_WR(bp, igu_addr_ctl, ctl);
7030 mmiowb();
7031 barrier();
7032
7033 /* wait for clean up to finish */
7034 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7035 msleep(20);
7036
7037
7038 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7039 DP(NETIF_MSG_HW,
7040 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7041 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7042 }
7043}
7044
7045static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7046{
619c5cb6 7047 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7048}
7049
1191cb83 7050static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7051{
7052 u32 i, base = FUNC_ILT_BASE(func);
7053 for (i = base; i < base + ILT_PER_FUNC; i++)
7054 bnx2x_ilt_wr(bp, i, 0);
7055}
7056
55c11941 7057
910cc727 7058static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7059{
7060 int port = BP_PORT(bp);
7061 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7062 /* T1 hash bits value determines the T1 number of entries */
7063 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7064}
7065
7066static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7067{
7068 int rc;
7069 struct bnx2x_func_state_params func_params = {NULL};
7070 struct bnx2x_func_switch_update_params *switch_update_params =
7071 &func_params.params.switch_update;
7072
7073 /* Prepare parameters for function state transitions */
7074 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7075 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7076
7077 func_params.f_obj = &bp->func_obj;
7078 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7079
7080 /* Function parameters */
7081 switch_update_params->suspend = suspend;
7082
7083 rc = bnx2x_func_state_change(bp, &func_params);
7084
7085 return rc;
7086}
7087
910cc727 7088static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7089{
7090 int rc, i, port = BP_PORT(bp);
7091 int vlan_en = 0, mac_en[NUM_MACS];
7092
7093
7094 /* Close input from network */
7095 if (bp->mf_mode == SINGLE_FUNCTION) {
7096 bnx2x_set_rx_filter(&bp->link_params, 0);
7097 } else {
7098 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7099 NIG_REG_LLH0_FUNC_EN);
7100 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7101 NIG_REG_LLH0_FUNC_EN, 0);
7102 for (i = 0; i < NUM_MACS; i++) {
7103 mac_en[i] = REG_RD(bp, port ?
7104 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7105 4 * i) :
7106 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7107 4 * i));
7108 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7109 4 * i) :
7110 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7111 }
7112 }
7113
7114 /* Close BMC to host */
7115 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7116 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7117
7118 /* Suspend Tx switching to the PF. Completion of this ramrod
7119 * further guarantees that all the packets of that PF / child
7120 * VFs in BRB were processed by the Parser, so it is safe to
7121 * change the NIC_MODE register.
7122 */
7123 rc = bnx2x_func_switch_update(bp, 1);
7124 if (rc) {
7125 BNX2X_ERR("Can't suspend tx-switching!\n");
7126 return rc;
7127 }
7128
7129 /* Change NIC_MODE register */
7130 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7131
7132 /* Open input from network */
7133 if (bp->mf_mode == SINGLE_FUNCTION) {
7134 bnx2x_set_rx_filter(&bp->link_params, 1);
7135 } else {
7136 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7137 NIG_REG_LLH0_FUNC_EN, vlan_en);
7138 for (i = 0; i < NUM_MACS; i++) {
7139 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7140 4 * i) :
7141 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7142 mac_en[i]);
7143 }
7144 }
7145
7146 /* Enable BMC to host */
7147 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7148 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7149
7150 /* Resume Tx switching to the PF */
7151 rc = bnx2x_func_switch_update(bp, 0);
7152 if (rc) {
7153 BNX2X_ERR("Can't resume tx-switching!\n");
7154 return rc;
7155 }
7156
7157 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7158 return 0;
7159}
7160
7161int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7162{
7163 int rc;
7164
7165 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7166
7167 if (CONFIGURE_NIC_MODE(bp)) {
7168 /* Configrue searcher as part of function hw init */
7169 bnx2x_init_searcher(bp);
7170
7171 /* Reset NIC mode */
7172 rc = bnx2x_reset_nic_mode(bp);
7173 if (rc)
7174 BNX2X_ERR("Can't change NIC mode!\n");
7175 return rc;
7176 }
7177
7178 return 0;
7179}
7180
523224a3 7181static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7182{
7183 int port = BP_PORT(bp);
7184 int func = BP_FUNC(bp);
619c5cb6 7185 int init_phase = PHASE_PF0 + func;
523224a3
DK
7186 struct bnx2x_ilt *ilt = BP_ILT(bp);
7187 u16 cdu_ilt_start;
8badd27a 7188 u32 addr, val;
f4a66897 7189 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7190 int i, main_mem_width, rc;
34f80b04 7191
51c1a580 7192 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7193
619c5cb6 7194 /* FLR cleanup - hmmm */
89db4ad8
AE
7195 if (!CHIP_IS_E1x(bp)) {
7196 rc = bnx2x_pf_flr_clnup(bp);
7197 if (rc)
7198 return rc;
7199 }
619c5cb6 7200
8badd27a 7201 /* set MSI reconfigure capability */
f2e0899f
DK
7202 if (bp->common.int_block == INT_BLOCK_HC) {
7203 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7204 val = REG_RD(bp, addr);
7205 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7206 REG_WR(bp, addr, val);
7207 }
8badd27a 7208
619c5cb6
VZ
7209 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7210 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7211
523224a3
DK
7212 ilt = BP_ILT(bp);
7213 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7214
523224a3 7215 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7216 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7217 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7218 bp->context[i].cxt_mapping;
7219 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7220 }
523224a3 7221 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7222
55c11941
MS
7223 if (!CONFIGURE_NIC_MODE(bp)) {
7224 bnx2x_init_searcher(bp);
7225 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7226 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7227 } else {
7228 /* Set NIC mode */
7229 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7230 DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
37b091ba 7231
55c11941 7232 }
37b091ba 7233
619c5cb6 7234 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7235 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7236
7237 /* Turn on a single ISR mode in IGU if driver is going to use
7238 * INT#x or MSI
7239 */
7240 if (!(bp->flags & USING_MSIX_FLAG))
7241 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7242 /*
7243 * Timers workaround bug: function init part.
7244 * Need to wait 20msec after initializing ILT,
7245 * needed to make sure there are no requests in
7246 * one of the PXP internal queues with "old" ILT addresses
7247 */
7248 msleep(20);
7249 /*
7250 * Master enable - Due to WB DMAE writes performed before this
7251 * register is re-initialized as part of the regular function
7252 * init
7253 */
7254 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7255 /* Enable the function in IGU */
7256 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7257 }
7258
523224a3 7259 bp->dmae_ready = 1;
34f80b04 7260
619c5cb6 7261 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7262
619c5cb6 7263 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7264 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7265
619c5cb6
VZ
7266 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7267 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7268 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7269 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7270 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7271 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7272 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7273 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7274 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7275 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7276 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7277 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7278 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7279
7280 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7281 REG_WR(bp, QM_REG_PF_EN, 1);
7282
619c5cb6
VZ
7283 if (!CHIP_IS_E1x(bp)) {
7284 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7285 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7286 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7287 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7288 }
7289 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7290
7291 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7292 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
7293 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7294 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7295 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7296 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7297 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7298 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7299 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7300 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7301 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7302 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7303 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7304
619c5cb6 7305 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7306
619c5cb6 7307 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7308
619c5cb6 7309 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7310 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7311
fb3bff17 7312 if (IS_MF(bp)) {
34f80b04 7313 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7314 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7315 }
7316
619c5cb6 7317 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7318
34f80b04 7319 /* HC init per function */
f2e0899f
DK
7320 if (bp->common.int_block == INT_BLOCK_HC) {
7321 if (CHIP_IS_E1H(bp)) {
7322 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7323
7324 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7325 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7326 }
619c5cb6 7327 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7328
7329 } else {
7330 int num_segs, sb_idx, prod_offset;
7331
34f80b04
EG
7332 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7333
619c5cb6 7334 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7335 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7336 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7337 }
7338
619c5cb6 7339 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7340
619c5cb6 7341 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7342 int dsb_idx = 0;
7343 /**
7344 * Producer memory:
7345 * E2 mode: address 0-135 match to the mapping memory;
7346 * 136 - PF0 default prod; 137 - PF1 default prod;
7347 * 138 - PF2 default prod; 139 - PF3 default prod;
7348 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7349 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7350 * 144-147 reserved.
7351 *
7352 * E1.5 mode - In backward compatible mode;
7353 * for non default SB; each even line in the memory
7354 * holds the U producer and each odd line hold
7355 * the C producer. The first 128 producers are for
7356 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7357 * producers are for the DSB for each PF.
7358 * Each PF has five segments: (the order inside each
7359 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7360 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7361 * 144-147 attn prods;
7362 */
7363 /* non-default-status-blocks */
7364 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7365 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7366 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7367 prod_offset = (bp->igu_base_sb + sb_idx) *
7368 num_segs;
7369
7370 for (i = 0; i < num_segs; i++) {
7371 addr = IGU_REG_PROD_CONS_MEMORY +
7372 (prod_offset + i) * 4;
7373 REG_WR(bp, addr, 0);
7374 }
7375 /* send consumer update with value 0 */
7376 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7377 USTORM_ID, 0, IGU_INT_NOP, 1);
7378 bnx2x_igu_clear_sb(bp,
7379 bp->igu_base_sb + sb_idx);
7380 }
7381
7382 /* default-status-blocks */
7383 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7384 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7385
7386 if (CHIP_MODE_IS_4_PORT(bp))
7387 dsb_idx = BP_FUNC(bp);
7388 else
3395a033 7389 dsb_idx = BP_VN(bp);
f2e0899f
DK
7390
7391 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7392 IGU_BC_BASE_DSB_PROD + dsb_idx :
7393 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7394
3395a033
DK
7395 /*
7396 * igu prods come in chunks of E1HVN_MAX (4) -
7397 * does not matters what is the current chip mode
7398 */
f2e0899f
DK
7399 for (i = 0; i < (num_segs * E1HVN_MAX);
7400 i += E1HVN_MAX) {
7401 addr = IGU_REG_PROD_CONS_MEMORY +
7402 (prod_offset + i)*4;
7403 REG_WR(bp, addr, 0);
7404 }
7405 /* send consumer update with 0 */
7406 if (CHIP_INT_MODE_IS_BC(bp)) {
7407 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7408 USTORM_ID, 0, IGU_INT_NOP, 1);
7409 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7410 CSTORM_ID, 0, IGU_INT_NOP, 1);
7411 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7412 XSTORM_ID, 0, IGU_INT_NOP, 1);
7413 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7414 TSTORM_ID, 0, IGU_INT_NOP, 1);
7415 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7416 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7417 } else {
7418 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7419 USTORM_ID, 0, IGU_INT_NOP, 1);
7420 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7421 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7422 }
7423 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7424
7425 /* !!! these should become driver const once
7426 rf-tool supports split-68 const */
7427 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7428 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7429 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7430 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7431 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7432 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7433 }
34f80b04 7434 }
34f80b04 7435
c14423fe 7436 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7437 REG_WR(bp, 0x2114, 0xffffffff);
7438 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7439
f4a66897
VZ
7440 if (CHIP_IS_E1x(bp)) {
7441 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7442 main_mem_base = HC_REG_MAIN_MEMORY +
7443 BP_PORT(bp) * (main_mem_size * 4);
7444 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7445 main_mem_width = 8;
7446
7447 val = REG_RD(bp, main_mem_prty_clr);
7448 if (val)
51c1a580
MS
7449 DP(NETIF_MSG_HW,
7450 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7451 val);
f4a66897
VZ
7452
7453 /* Clear "false" parity errors in MSI-X table */
7454 for (i = main_mem_base;
7455 i < main_mem_base + main_mem_size * 4;
7456 i += main_mem_width) {
7457 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7458 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7459 i, main_mem_width / 4);
7460 }
7461 /* Clear HC parity attention */
7462 REG_RD(bp, main_mem_prty_clr);
7463 }
7464
619c5cb6
VZ
7465#ifdef BNX2X_STOP_ON_ERROR
7466 /* Enable STORMs SP logging */
7467 REG_WR8(bp, BAR_USTRORM_INTMEM +
7468 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7469 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7470 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7471 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7472 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7473 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7474 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7475#endif
7476
b7737c9b 7477 bnx2x_phy_probe(&bp->link_params);
f85582f8 7478
34f80b04
EG
7479 return 0;
7480}
7481
a2fbb9ea 7482
55c11941
MS
7483void bnx2x_free_mem_cnic(struct bnx2x *bp)
7484{
7485 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7486
7487 if (!CHIP_IS_E1x(bp))
7488 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7489 sizeof(struct host_hc_status_block_e2));
7490 else
7491 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7492 sizeof(struct host_hc_status_block_e1x));
7493
7494 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7495}
7496
9f6c9258 7497void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7498{
a052997e
MS
7499 int i;
7500
a2fbb9ea 7501 /* fastpath */
b3b83c3f 7502 bnx2x_free_fp_mem(bp);
a2fbb9ea
ET
7503 /* end of fastpath */
7504
7505 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7506 sizeof(struct host_sp_status_block));
a2fbb9ea 7507
619c5cb6
VZ
7508 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7509 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7510
a2fbb9ea 7511 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7512 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7513
a052997e
MS
7514 for (i = 0; i < L2_ILT_LINES(bp); i++)
7515 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7516 bp->context[i].size);
523224a3
DK
7517 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7518
7519 BNX2X_FREE(bp->ilt->lines);
f85582f8 7520
7a9b2557 7521 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7522
523224a3
DK
7523 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7524 BCM_PAGE_SIZE * NUM_EQ_PAGES);
619c5cb6
VZ
7525}
7526
1191cb83 7527static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
619c5cb6
VZ
7528{
7529 int num_groups;
50f0a562 7530 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
619c5cb6 7531
50f0a562
BW
7532 /* number of queues for statistics is number of eth queues + FCoE */
7533 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
619c5cb6
VZ
7534
7535 /* Total number of FW statistics requests =
50f0a562
BW
7536 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
7537 * num of queues
7538 */
7539 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
523224a3 7540
619c5cb6
VZ
7541
7542 /* Request is built from stats_query_header and an array of
7543 * stats_query_cmd_group each of which contains
7544 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
7545 * configured in the stats_query_header.
7546 */
50f0a562
BW
7547 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
7548 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
619c5cb6
VZ
7549
7550 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
7551 num_groups * sizeof(struct stats_query_cmd_group);
7552
7553 /* Data for statistics requests + stats_conter
7554 *
7555 * stats_counter holds per-STORM counters that are incremented
7556 * when STORM has finished with the current request.
50f0a562
BW
7557 *
7558 * memory for FCoE offloaded statistics are counted anyway,
7559 * even if they will not be sent.
619c5cb6
VZ
7560 */
7561 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
7562 sizeof(struct per_pf_stats) +
50f0a562 7563 sizeof(struct fcoe_statistics_params) +
619c5cb6
VZ
7564 sizeof(struct per_queue_stats) * num_queue_stats +
7565 sizeof(struct stats_counter);
7566
7567 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
7568 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7569
7570 /* Set shortcuts */
7571 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
7572 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
7573
7574 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
7575 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
7576
7577 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
7578 bp->fw_stats_req_sz;
7579 return 0;
7580
7581alloc_mem_err:
7582 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7583 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
51c1a580 7584 BNX2X_ERR("Can't allocate memory\n");
619c5cb6 7585 return -ENOMEM;
a2fbb9ea
ET
7586}
7587
55c11941 7588int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7589{
619c5cb6
VZ
7590 if (!CHIP_IS_E1x(bp))
7591 /* size = the status block + ramrod buffers */
f2e0899f
DK
7592 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7593 sizeof(struct host_hc_status_block_e2));
7594 else
55c11941
MS
7595 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7596 &bp->cnic_sb_mapping,
7597 sizeof(struct
7598 host_hc_status_block_e1x));
8badd27a 7599
55c11941
MS
7600 if (CONFIGURE_NIC_MODE(bp))
7601 /* allocate searcher T2 table, as it wan't allocated before */
7602 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7603
7604 /* write address to which L5 should insert its values */
7605 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7606 &bp->slowpath->drv_info_to_mcp;
7607
7608 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7609 goto alloc_mem_err;
7610
7611 return 0;
7612
7613alloc_mem_err:
7614 bnx2x_free_mem_cnic(bp);
7615 BNX2X_ERR("Can't allocate memory\n");
7616 return -ENOMEM;
7617}
7618
7619int bnx2x_alloc_mem(struct bnx2x *bp)
7620{
7621 int i, allocated, context_size;
a2fbb9ea 7622
55c11941
MS
7623 if (!CONFIGURE_NIC_MODE(bp))
7624 /* allocate searcher T2 table */
7625 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7626
523224a3
DK
7627 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7628 sizeof(struct host_sp_status_block));
a2fbb9ea 7629
523224a3
DK
7630 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7631 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7632
619c5cb6
VZ
7633 /* Allocated memory for FW statistics */
7634 if (bnx2x_alloc_fw_stats_mem(bp))
7635 goto alloc_mem_err;
7636
a052997e
MS
7637 /* Allocate memory for CDU context:
7638 * This memory is allocated separately and not in the generic ILT
7639 * functions because CDU differs in few aspects:
7640 * 1. There are multiple entities allocating memory for context -
7641 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7642 * its own ILT lines.
7643 * 2. Since CDU page-size is not a single 4KB page (which is the case
7644 * for the other ILT clients), to be efficient we want to support
7645 * allocation of sub-page-size in the last entry.
7646 * 3. Context pointers are used by the driver to pass to FW / update
7647 * the context (for the other ILT clients the pointers are used just to
7648 * free the memory during unload).
7649 */
7650 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7651
a052997e
MS
7652 for (i = 0, allocated = 0; allocated < context_size; i++) {
7653 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7654 (context_size - allocated));
7655 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7656 &bp->context[i].cxt_mapping,
7657 bp->context[i].size);
7658 allocated += bp->context[i].size;
7659 }
523224a3 7660 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7661
523224a3
DK
7662 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7663 goto alloc_mem_err;
65abd74d 7664
9f6c9258
DK
7665 /* Slow path ring */
7666 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7667
523224a3
DK
7668 /* EQ */
7669 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7670 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7671
b3b83c3f
DK
7672
7673 /* fastpath */
7674 /* need to be done at the end, since it's self adjusting to amount
7675 * of memory available for RSS queues
7676 */
7677 if (bnx2x_alloc_fp_mem(bp))
7678 goto alloc_mem_err;
9f6c9258 7679 return 0;
e1510706 7680
9f6c9258
DK
7681alloc_mem_err:
7682 bnx2x_free_mem(bp);
51c1a580 7683 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7684 return -ENOMEM;
65abd74d
YG
7685}
7686
a2fbb9ea
ET
7687/*
7688 * Init service functions
7689 */
a2fbb9ea 7690
619c5cb6
VZ
7691int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7692 struct bnx2x_vlan_mac_obj *obj, bool set,
7693 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7694{
619c5cb6
VZ
7695 int rc;
7696 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7697
619c5cb6 7698 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7699
619c5cb6
VZ
7700 /* Fill general parameters */
7701 ramrod_param.vlan_mac_obj = obj;
7702 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7703
619c5cb6
VZ
7704 /* Fill a user request section if needed */
7705 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7706 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7707
619c5cb6 7708 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7709
619c5cb6
VZ
7710 /* Set the command: ADD or DEL */
7711 if (set)
7712 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7713 else
7714 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7715 }
7716
619c5cb6 7717 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7718
7719 if (rc == -EEXIST) {
7720 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7721 /* do not treat adding same MAC as error */
7722 rc = 0;
7723 } else if (rc < 0)
619c5cb6 7724 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7725
619c5cb6 7726 return rc;
a2fbb9ea
ET
7727}
7728
619c5cb6
VZ
7729int bnx2x_del_all_macs(struct bnx2x *bp,
7730 struct bnx2x_vlan_mac_obj *mac_obj,
7731 int mac_type, bool wait_for_comp)
e665bfda 7732{
619c5cb6
VZ
7733 int rc;
7734 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7735
619c5cb6
VZ
7736 /* Wait for completion of requested */
7737 if (wait_for_comp)
7738 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7739
619c5cb6
VZ
7740 /* Set the mac type of addresses we want to clear */
7741 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7742
619c5cb6
VZ
7743 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7744 if (rc < 0)
7745 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7746
619c5cb6 7747 return rc;
0793f83f
DK
7748}
7749
619c5cb6 7750int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7751{
619c5cb6 7752 unsigned long ramrod_flags = 0;
e665bfda 7753
a3348722
BW
7754 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7755 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7756 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7757 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7758 return 0;
7759 }
614c76df 7760
619c5cb6 7761 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7762
619c5cb6
VZ
7763 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7764 /* Eth MAC is set on RSS leading client (fp[0]) */
15192a8c
BW
7765 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7766 set, BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7767}
6e30dd4e 7768
619c5cb6 7769int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7770{
619c5cb6 7771 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7772}
a2fbb9ea 7773
d6214d7a 7774/**
e8920674 7775 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7776 *
e8920674 7777 * @bp: driver handle
d6214d7a 7778 *
e8920674 7779 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7780 */
0e8d2ec5 7781void bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7782{
9ee3d37b 7783 switch (int_mode) {
d6214d7a
DK
7784 case INT_MODE_MSI:
7785 bnx2x_enable_msi(bp);
7786 /* falling through... */
7787 case INT_MODE_INTx:
55c11941
MS
7788 bp->num_ethernet_queues = 1;
7789 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7790 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7791 break;
d6214d7a 7792 default:
d6214d7a
DK
7793 /* if we can't use MSI-X we only need one fp,
7794 * so try to enable MSI-X with the requested number of fp's
7795 * and fallback to MSI or legacy INTx with one fp
7796 */
30a5de77
DK
7797 if (bnx2x_enable_msix(bp) ||
7798 bp->flags & USING_SINGLE_MSIX_FLAG) {
7799 /* failed to enable multiple MSI-X */
7800 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
55c11941
MS
7801 bp->num_queues,
7802 1 + bp->num_cnic_queues);
51c1a580 7803
55c11941 7804 bp->num_queues = 1 + bp->num_cnic_queues;
d6214d7a 7805
9ee3d37b 7806 /* Try to enable MSI */
30a5de77
DK
7807 if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
7808 !(bp->flags & DISABLE_MSI_FLAG))
d6214d7a
DK
7809 bnx2x_enable_msi(bp);
7810 }
9f6c9258
DK
7811 break;
7812 }
a2fbb9ea
ET
7813}
7814
c2bff63f
DK
7815/* must be called prioir to any HW initializations */
7816static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7817{
7818 return L2_ILT_LINES(bp);
7819}
7820
523224a3
DK
7821void bnx2x_ilt_set_info(struct bnx2x *bp)
7822{
7823 struct ilt_client_info *ilt_client;
7824 struct bnx2x_ilt *ilt = BP_ILT(bp);
7825 u16 line = 0;
7826
7827 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7828 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7829
7830 /* CDU */
7831 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7832 ilt_client->client_num = ILT_CLIENT_CDU;
7833 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7834 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7835 ilt_client->start = line;
619c5cb6 7836 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
7837
7838 if (CNIC_SUPPORT(bp))
7839 line += CNIC_ILT_LINES;
523224a3
DK
7840 ilt_client->end = line - 1;
7841
51c1a580 7842 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7843 ilt_client->start,
7844 ilt_client->end,
7845 ilt_client->page_size,
7846 ilt_client->flags,
7847 ilog2(ilt_client->page_size >> 12));
7848
7849 /* QM */
7850 if (QM_INIT(bp->qm_cid_count)) {
7851 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7852 ilt_client->client_num = ILT_CLIENT_QM;
7853 ilt_client->page_size = QM_ILT_PAGE_SZ;
7854 ilt_client->flags = 0;
7855 ilt_client->start = line;
7856
7857 /* 4 bytes for each cid */
7858 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7859 QM_ILT_PAGE_SZ);
7860
7861 ilt_client->end = line - 1;
7862
51c1a580
MS
7863 DP(NETIF_MSG_IFUP,
7864 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7865 ilt_client->start,
7866 ilt_client->end,
7867 ilt_client->page_size,
7868 ilt_client->flags,
7869 ilog2(ilt_client->page_size >> 12));
7870
7871 }
523224a3 7872
55c11941
MS
7873 if (CNIC_SUPPORT(bp)) {
7874 /* SRC */
7875 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7876 ilt_client->client_num = ILT_CLIENT_SRC;
7877 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7878 ilt_client->flags = 0;
7879 ilt_client->start = line;
7880 line += SRC_ILT_LINES;
7881 ilt_client->end = line - 1;
523224a3 7882
55c11941
MS
7883 DP(NETIF_MSG_IFUP,
7884 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7885 ilt_client->start,
7886 ilt_client->end,
7887 ilt_client->page_size,
7888 ilt_client->flags,
7889 ilog2(ilt_client->page_size >> 12));
9f6c9258 7890
55c11941
MS
7891 /* TM */
7892 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7893 ilt_client->client_num = ILT_CLIENT_TM;
7894 ilt_client->page_size = TM_ILT_PAGE_SZ;
7895 ilt_client->flags = 0;
7896 ilt_client->start = line;
7897 line += TM_ILT_LINES;
7898 ilt_client->end = line - 1;
523224a3 7899
55c11941
MS
7900 DP(NETIF_MSG_IFUP,
7901 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7902 ilt_client->start,
7903 ilt_client->end,
7904 ilt_client->page_size,
7905 ilt_client->flags,
7906 ilog2(ilt_client->page_size >> 12));
7907 }
9f6c9258 7908
619c5cb6 7909 BUG_ON(line > ILT_MAX_LINES);
523224a3 7910}
f85582f8 7911
619c5cb6
VZ
7912/**
7913 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7914 *
7915 * @bp: driver handle
7916 * @fp: pointer to fastpath
7917 * @init_params: pointer to parameters structure
7918 *
7919 * parameters configured:
7920 * - HC configuration
7921 * - Queue's CDU context
7922 */
1191cb83 7923static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 7924 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 7925{
6383c0b3
AE
7926
7927 u8 cos;
a052997e
MS
7928 int cxt_index, cxt_offset;
7929
619c5cb6
VZ
7930 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7931 if (!IS_FCOE_FP(fp)) {
7932 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7933 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7934
7935 /* If HC is supporterd, enable host coalescing in the transition
7936 * to INIT state.
7937 */
7938 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7939 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7940
7941 /* HC rate */
7942 init_params->rx.hc_rate = bp->rx_ticks ?
7943 (1000000 / bp->rx_ticks) : 0;
7944 init_params->tx.hc_rate = bp->tx_ticks ?
7945 (1000000 / bp->tx_ticks) : 0;
7946
7947 /* FW SB ID */
7948 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7949 fp->fw_sb_id;
7950
7951 /*
7952 * CQ index among the SB indices: FCoE clients uses the default
7953 * SB, therefore it's different.
7954 */
6383c0b3
AE
7955 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7956 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
7957 }
7958
6383c0b3
AE
7959 /* set maximum number of COSs supported by this queue */
7960 init_params->max_cos = fp->max_cos;
7961
51c1a580 7962 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
7963 fp->index, init_params->max_cos);
7964
7965 /* set the context pointers queue object */
a052997e 7966 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
7967 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
7968 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 7969 ILT_PAGE_CIDS);
6383c0b3 7970 init_params->cxts[cos] =
a052997e
MS
7971 &bp->context[cxt_index].vcxt[cxt_offset].eth;
7972 }
619c5cb6
VZ
7973}
7974
910cc727 7975static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
7976 struct bnx2x_queue_state_params *q_params,
7977 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7978 int tx_index, bool leading)
7979{
7980 memset(tx_only_params, 0, sizeof(*tx_only_params));
7981
7982 /* Set the command */
7983 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7984
7985 /* Set tx-only QUEUE flags: don't zero statistics */
7986 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7987
7988 /* choose the index of the cid to send the slow path on */
7989 tx_only_params->cid_index = tx_index;
7990
7991 /* Set general TX_ONLY_SETUP parameters */
7992 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7993
7994 /* Set Tx TX_ONLY_SETUP parameters */
7995 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7996
51c1a580
MS
7997 DP(NETIF_MSG_IFUP,
7998 "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
7999 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8000 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8001 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8002
8003 /* send the ramrod */
8004 return bnx2x_queue_state_change(bp, q_params);
8005}
8006
8007
619c5cb6
VZ
8008/**
8009 * bnx2x_setup_queue - setup queue
8010 *
8011 * @bp: driver handle
8012 * @fp: pointer to fastpath
8013 * @leading: is leading
8014 *
8015 * This function performs 2 steps in a Queue state machine
8016 * actually: 1) RESET->INIT 2) INIT->SETUP
8017 */
8018
8019int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8020 bool leading)
8021{
3b603066 8022 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8023 struct bnx2x_queue_setup_params *setup_params =
8024 &q_params.params.setup;
6383c0b3
AE
8025 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8026 &q_params.params.tx_only;
a2fbb9ea 8027 int rc;
6383c0b3
AE
8028 u8 tx_index;
8029
51c1a580 8030 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8031
ec6ba945
VZ
8032 /* reset IGU state skip FCoE L2 queue */
8033 if (!IS_FCOE_FP(fp))
8034 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8035 IGU_INT_ENABLE, 0);
a2fbb9ea 8036
15192a8c 8037 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8038 /* We want to wait for completion in this context */
8039 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8040
619c5cb6
VZ
8041 /* Prepare the INIT parameters */
8042 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8043
619c5cb6
VZ
8044 /* Set the command */
8045 q_params.cmd = BNX2X_Q_CMD_INIT;
8046
8047 /* Change the state to INIT */
8048 rc = bnx2x_queue_state_change(bp, &q_params);
8049 if (rc) {
6383c0b3 8050 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8051 return rc;
8052 }
ec6ba945 8053
51c1a580 8054 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
8055
8056
619c5cb6
VZ
8057 /* Now move the Queue to the SETUP state... */
8058 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8059
619c5cb6
VZ
8060 /* Set QUEUE flags */
8061 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8062
619c5cb6 8063 /* Set general SETUP parameters */
6383c0b3
AE
8064 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8065 FIRST_TX_COS_INDEX);
619c5cb6 8066
6383c0b3 8067 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8068 &setup_params->rxq_params);
8069
6383c0b3
AE
8070 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8071 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8072
8073 /* Set the command */
8074 q_params.cmd = BNX2X_Q_CMD_SETUP;
8075
55c11941
MS
8076 if (IS_FCOE_FP(fp))
8077 bp->fcoe_init = true;
8078
619c5cb6
VZ
8079 /* Change the state to SETUP */
8080 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8081 if (rc) {
8082 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8083 return rc;
8084 }
8085
8086 /* loop through the relevant tx-only indices */
8087 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8088 tx_index < fp->max_cos;
8089 tx_index++) {
8090
8091 /* prepare and send tx-only ramrod*/
8092 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8093 tx_only_params, tx_index, leading);
8094 if (rc) {
8095 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8096 fp->index, tx_index);
8097 return rc;
8098 }
8099 }
523224a3 8100
34f80b04 8101 return rc;
a2fbb9ea
ET
8102}
8103
619c5cb6 8104static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8105{
619c5cb6 8106 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8107 struct bnx2x_fp_txdata *txdata;
3b603066 8108 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8109 int rc, tx_index;
8110
51c1a580 8111 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8112
15192a8c 8113 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8114 /* We want to wait for completion in this context */
8115 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8116
6383c0b3
AE
8117
8118 /* close tx-only connections */
8119 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8120 tx_index < fp->max_cos;
8121 tx_index++){
8122
8123 /* ascertain this is a normal queue*/
65565884 8124 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8125
51c1a580 8126 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8127 txdata->txq_index);
8128
8129 /* send halt terminate on tx-only connection */
8130 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8131 memset(&q_params.params.terminate, 0,
8132 sizeof(q_params.params.terminate));
8133 q_params.params.terminate.cid_index = tx_index;
8134
8135 rc = bnx2x_queue_state_change(bp, &q_params);
8136 if (rc)
8137 return rc;
8138
8139 /* send halt terminate on tx-only connection */
8140 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8141 memset(&q_params.params.cfc_del, 0,
8142 sizeof(q_params.params.cfc_del));
8143 q_params.params.cfc_del.cid_index = tx_index;
8144 rc = bnx2x_queue_state_change(bp, &q_params);
8145 if (rc)
8146 return rc;
8147 }
8148 /* Stop the primary connection: */
8149 /* ...halt the connection */
619c5cb6
VZ
8150 q_params.cmd = BNX2X_Q_CMD_HALT;
8151 rc = bnx2x_queue_state_change(bp, &q_params);
8152 if (rc)
da5a662a 8153 return rc;
a2fbb9ea 8154
6383c0b3 8155 /* ...terminate the connection */
619c5cb6 8156 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8157 memset(&q_params.params.terminate, 0,
8158 sizeof(q_params.params.terminate));
8159 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8160 rc = bnx2x_queue_state_change(bp, &q_params);
8161 if (rc)
523224a3 8162 return rc;
6383c0b3 8163 /* ...delete cfc entry */
619c5cb6 8164 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8165 memset(&q_params.params.cfc_del, 0,
8166 sizeof(q_params.params.cfc_del));
8167 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8168 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8169}
8170
8171
34f80b04
EG
8172static void bnx2x_reset_func(struct bnx2x *bp)
8173{
8174 int port = BP_PORT(bp);
8175 int func = BP_FUNC(bp);
f2e0899f 8176 int i;
523224a3
DK
8177
8178 /* Disable the function in the FW */
8179 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8180 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8181 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8182 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8183
8184 /* FP SBs */
ec6ba945 8185 for_each_eth_queue(bp, i) {
523224a3 8186 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8187 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8188 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8189 SB_DISABLED);
523224a3
DK
8190 }
8191
55c11941
MS
8192 if (CNIC_LOADED(bp))
8193 /* CNIC SB */
8194 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8195 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8196 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8197
523224a3 8198 /* SP SB */
619c5cb6 8199 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8200 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8201 SB_DISABLED);
523224a3
DK
8202
8203 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8204 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8205 0);
34f80b04
EG
8206
8207 /* Configure IGU */
f2e0899f
DK
8208 if (bp->common.int_block == INT_BLOCK_HC) {
8209 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8210 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8211 } else {
8212 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8213 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8214 }
34f80b04 8215
55c11941
MS
8216 if (CNIC_LOADED(bp)) {
8217 /* Disable Timer scan */
8218 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8219 /*
8220 * Wait for at least 10ms and up to 2 second for the timers
8221 * scan to complete
8222 */
8223 for (i = 0; i < 200; i++) {
8224 msleep(10);
8225 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8226 break;
8227 }
37b091ba 8228 }
34f80b04 8229 /* Clear ILT */
f2e0899f
DK
8230 bnx2x_clear_func_ilt(bp, func);
8231
8232 /* Timers workaround bug for E2: if this is vnic-3,
8233 * we need to set the entire ilt range for this timers.
8234 */
619c5cb6 8235 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8236 struct ilt_client_info ilt_cli;
8237 /* use dummy TM client */
8238 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8239 ilt_cli.start = 0;
8240 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8241 ilt_cli.client_num = ILT_CLIENT_TM;
8242
8243 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8244 }
8245
8246 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8247 if (!CHIP_IS_E1x(bp))
f2e0899f 8248 bnx2x_pf_disable(bp);
523224a3
DK
8249
8250 bp->dmae_ready = 0;
34f80b04
EG
8251}
8252
8253static void bnx2x_reset_port(struct bnx2x *bp)
8254{
8255 int port = BP_PORT(bp);
8256 u32 val;
8257
619c5cb6
VZ
8258 /* Reset physical Link */
8259 bnx2x__link_reset(bp);
8260
34f80b04
EG
8261 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8262
8263 /* Do not rcv packets to BRB */
8264 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8265 /* Do not direct rcv packets that are not for MCP to the BRB */
8266 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8267 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8268
8269 /* Configure AEU */
8270 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8271
8272 msleep(100);
8273 /* Check for BRB port occupancy */
8274 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8275 if (val)
8276 DP(NETIF_MSG_IFDOWN,
33471629 8277 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8278
8279 /* TODO: Close Doorbell port? */
8280}
8281
1191cb83 8282static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8283{
3b603066 8284 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8285
619c5cb6
VZ
8286 /* Prepare parameters for function state transitions */
8287 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8288
619c5cb6
VZ
8289 func_params.f_obj = &bp->func_obj;
8290 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8291
619c5cb6 8292 func_params.params.hw_init.load_phase = load_code;
49d66772 8293
619c5cb6 8294 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8295}
8296
1191cb83 8297static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8298{
3b603066 8299 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8300 int rc;
228241eb 8301
619c5cb6
VZ
8302 /* Prepare parameters for function state transitions */
8303 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8304 func_params.f_obj = &bp->func_obj;
8305 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8306
619c5cb6
VZ
8307 /*
8308 * Try to stop the function the 'good way'. If fails (in case
8309 * of a parity error during bnx2x_chip_cleanup()) and we are
8310 * not in a debug mode, perform a state transaction in order to
8311 * enable further HW_RESET transaction.
8312 */
8313 rc = bnx2x_func_state_change(bp, &func_params);
8314 if (rc) {
34f80b04 8315#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8316 return rc;
34f80b04 8317#else
51c1a580 8318 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8319 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8320 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8321#endif
228241eb 8322 }
a2fbb9ea 8323
619c5cb6
VZ
8324 return 0;
8325}
523224a3 8326
619c5cb6
VZ
8327/**
8328 * bnx2x_send_unload_req - request unload mode from the MCP.
8329 *
8330 * @bp: driver handle
8331 * @unload_mode: requested function's unload mode
8332 *
8333 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8334 */
8335u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8336{
8337 u32 reset_code = 0;
8338 int port = BP_PORT(bp);
3101c2bc 8339
619c5cb6 8340 /* Select the UNLOAD request mode */
65abd74d
YG
8341 if (unload_mode == UNLOAD_NORMAL)
8342 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8343
7d0446c2 8344 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8345 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8346
7d0446c2 8347 else if (bp->wol) {
65abd74d
YG
8348 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8349 u8 *mac_addr = bp->dev->dev_addr;
8350 u32 val;
f9977903
DK
8351 u16 pmc;
8352
65abd74d 8353 /* The mac address is written to entries 1-4 to
f9977903
DK
8354 * preserve entry 0 which is used by the PMF
8355 */
3395a033 8356 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8357
8358 val = (mac_addr[0] << 8) | mac_addr[1];
8359 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8360
8361 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8362 (mac_addr[4] << 8) | mac_addr[5];
8363 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8364
f9977903
DK
8365 /* Enable the PME and clear the status */
8366 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8367 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8368 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8369
65abd74d
YG
8370 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8371
8372 } else
8373 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8374
619c5cb6
VZ
8375 /* Send the request to the MCP */
8376 if (!BP_NOMCP(bp))
8377 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8378 else {
8379 int path = BP_PATH(bp);
8380
51c1a580 8381 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8382 path, load_count[path][0], load_count[path][1],
8383 load_count[path][2]);
8384 load_count[path][0]--;
8385 load_count[path][1 + port]--;
51c1a580 8386 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8387 path, load_count[path][0], load_count[path][1],
8388 load_count[path][2]);
8389 if (load_count[path][0] == 0)
8390 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8391 else if (load_count[path][1 + port] == 0)
8392 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8393 else
8394 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8395 }
8396
8397 return reset_code;
8398}
8399
8400/**
8401 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8402 *
8403 * @bp: driver handle
5d07d868 8404 * @keep_link: true iff link should be kept up
619c5cb6 8405 */
5d07d868 8406void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8407{
5d07d868
YM
8408 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8409
619c5cb6
VZ
8410 /* Report UNLOAD_DONE to MCP */
8411 if (!BP_NOMCP(bp))
5d07d868 8412 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8413}
8414
1191cb83 8415static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8416{
8417 int tout = 50;
8418 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8419
8420 if (!bp->port.pmf)
8421 return 0;
8422
8423 /*
8424 * (assumption: No Attention from MCP at this stage)
8425 * PMF probably in the middle of TXdisable/enable transaction
8426 * 1. Sync IRS for default SB
8427 * 2. Sync SP queue - this guarantes us that attention handling started
8428 * 3. Wait, that TXdisable/enable transaction completes
8429 *
8430 * 1+2 guranty that if DCBx attention was scheduled it already changed
8431 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8432 * received complettion for the transaction the state is TX_STOPPED.
8433 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8434 * transaction.
8435 */
8436
8437 /* make sure default SB ISR is done */
8438 if (msix)
8439 synchronize_irq(bp->msix_table[0].vector);
8440 else
8441 synchronize_irq(bp->pdev->irq);
8442
8443 flush_workqueue(bnx2x_wq);
8444
8445 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8446 BNX2X_F_STATE_STARTED && tout--)
8447 msleep(20);
8448
8449 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8450 BNX2X_F_STATE_STARTED) {
8451#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8452 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8453 return -EBUSY;
8454#else
8455 /*
8456 * Failed to complete the transaction in a "good way"
8457 * Force both transactions with CLR bit
8458 */
3b603066 8459 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8460
51c1a580
MS
8461 DP(NETIF_MSG_IFDOWN,
8462 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8463
8464 func_params.f_obj = &bp->func_obj;
8465 __set_bit(RAMROD_DRV_CLR_ONLY,
8466 &func_params.ramrod_flags);
8467
8468 /* STARTED-->TX_ST0PPED */
8469 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8470 bnx2x_func_state_change(bp, &func_params);
8471
8472 /* TX_ST0PPED-->STARTED */
8473 func_params.cmd = BNX2X_F_CMD_TX_START;
8474 return bnx2x_func_state_change(bp, &func_params);
8475#endif
8476 }
8477
8478 return 0;
8479}
8480
5d07d868 8481void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8482{
8483 int port = BP_PORT(bp);
6383c0b3
AE
8484 int i, rc = 0;
8485 u8 cos;
3b603066 8486 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8487 u32 reset_code;
8488
8489 /* Wait until tx fastpath tasks complete */
8490 for_each_tx_queue(bp, i) {
8491 struct bnx2x_fastpath *fp = &bp->fp[i];
8492
6383c0b3 8493 for_each_cos_in_tx_queue(fp, cos)
65565884 8494 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8495#ifdef BNX2X_STOP_ON_ERROR
8496 if (rc)
8497 return;
8498#endif
8499 }
8500
8501 /* Give HW time to discard old tx messages */
8502 usleep_range(1000, 1000);
8503
8504 /* Clean all ETH MACs */
15192a8c
BW
8505 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8506 false);
619c5cb6
VZ
8507 if (rc < 0)
8508 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8509
8510 /* Clean up UC list */
15192a8c 8511 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8512 true);
8513 if (rc < 0)
51c1a580
MS
8514 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8515 rc);
619c5cb6
VZ
8516
8517 /* Disable LLH */
8518 if (!CHIP_IS_E1(bp))
8519 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8520
8521 /* Set "drop all" (stop Rx).
8522 * We need to take a netif_addr_lock() here in order to prevent
8523 * a race between the completion code and this code.
8524 */
8525 netif_addr_lock_bh(bp->dev);
8526 /* Schedule the rx_mode command */
8527 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8528 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8529 else
8530 bnx2x_set_storm_rx_mode(bp);
8531
8532 /* Cleanup multicast configuration */
8533 rparam.mcast_obj = &bp->mcast_obj;
8534 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8535 if (rc < 0)
8536 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8537
8538 netif_addr_unlock_bh(bp->dev);
8539
8540
6debea87
DK
8541
8542 /*
8543 * Send the UNLOAD_REQUEST to the MCP. This will return if
8544 * this function should perform FUNC, PORT or COMMON HW
8545 * reset.
8546 */
8547 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8548
8549 /*
8550 * (assumption: No Attention from MCP at this stage)
8551 * PMF probably in the middle of TXdisable/enable transaction
8552 */
8553 rc = bnx2x_func_wait_started(bp);
8554 if (rc) {
8555 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8556#ifdef BNX2X_STOP_ON_ERROR
8557 return;
8558#endif
8559 }
8560
34f80b04 8561 /* Close multi and leading connections
619c5cb6
VZ
8562 * Completions for ramrods are collected in a synchronous way
8563 */
55c11941 8564 for_each_eth_queue(bp, i)
619c5cb6 8565 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8566#ifdef BNX2X_STOP_ON_ERROR
8567 return;
8568#else
228241eb 8569 goto unload_error;
523224a3 8570#endif
55c11941
MS
8571
8572 if (CNIC_LOADED(bp)) {
8573 for_each_cnic_queue(bp, i)
8574 if (bnx2x_stop_queue(bp, i))
8575#ifdef BNX2X_STOP_ON_ERROR
8576 return;
8577#else
8578 goto unload_error;
8579#endif
8580 }
8581
619c5cb6
VZ
8582 /* If SP settings didn't get completed so far - something
8583 * very wrong has happen.
8584 */
8585 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8586 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8587
619c5cb6
VZ
8588#ifndef BNX2X_STOP_ON_ERROR
8589unload_error:
8590#endif
523224a3 8591 rc = bnx2x_func_stop(bp);
da5a662a 8592 if (rc) {
523224a3 8593 BNX2X_ERR("Function stop failed!\n");
da5a662a 8594#ifdef BNX2X_STOP_ON_ERROR
523224a3 8595 return;
523224a3 8596#endif
34f80b04 8597 }
a2fbb9ea 8598
523224a3
DK
8599 /* Disable HW interrupts, NAPI */
8600 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8601 /* Delete all NAPI objects */
8602 bnx2x_del_all_napi(bp);
55c11941
MS
8603 if (CNIC_LOADED(bp))
8604 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8605
8606 /* Release IRQs */
d6214d7a 8607 bnx2x_free_irq(bp);
523224a3 8608
a2fbb9ea 8609 /* Reset the chip */
619c5cb6
VZ
8610 rc = bnx2x_reset_hw(bp, reset_code);
8611 if (rc)
8612 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8613
356e2385 8614
619c5cb6 8615 /* Report UNLOAD_DONE to MCP */
5d07d868 8616 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8617}
8618
9f6c9258 8619void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8620{
8621 u32 val;
8622
51c1a580 8623 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8624
8625 if (CHIP_IS_E1(bp)) {
8626 int port = BP_PORT(bp);
8627 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8628 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8629
8630 val = REG_RD(bp, addr);
8631 val &= ~(0x300);
8632 REG_WR(bp, addr, val);
619c5cb6 8633 } else {
72fd0718
VZ
8634 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8635 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8636 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8637 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8638 }
8639}
8640
72fd0718
VZ
8641/* Close gates #2, #3 and #4: */
8642static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8643{
c9ee9206 8644 u32 val;
72fd0718
VZ
8645
8646 /* Gates #2 and #4a are closed/opened for "not E1" only */
8647 if (!CHIP_IS_E1(bp)) {
8648 /* #4 */
c9ee9206 8649 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8650 /* #2 */
c9ee9206 8651 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8652 }
8653
8654 /* #3 */
c9ee9206
VZ
8655 if (CHIP_IS_E1x(bp)) {
8656 /* Prevent interrupts from HC on both ports */
8657 val = REG_RD(bp, HC_REG_CONFIG_1);
8658 REG_WR(bp, HC_REG_CONFIG_1,
8659 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8660 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8661
8662 val = REG_RD(bp, HC_REG_CONFIG_0);
8663 REG_WR(bp, HC_REG_CONFIG_0,
8664 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8665 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8666 } else {
8667 /* Prevent incomming interrupts in IGU */
8668 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8669
8670 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8671 (!close) ?
8672 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8673 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8674 }
72fd0718 8675
51c1a580 8676 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8677 close ? "closing" : "opening");
8678 mmiowb();
8679}
8680
8681#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8682
8683static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8684{
8685 /* Do some magic... */
8686 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8687 *magic_val = val & SHARED_MF_CLP_MAGIC;
8688 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8689}
8690
e8920674
DK
8691/**
8692 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8693 *
e8920674
DK
8694 * @bp: driver handle
8695 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8696 */
8697static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8698{
8699 /* Restore the `magic' bit value... */
72fd0718
VZ
8700 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8701 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8702 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8703}
8704
f85582f8 8705/**
e8920674 8706 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8707 *
e8920674
DK
8708 * @bp: driver handle
8709 * @magic_val: old value of 'magic' bit.
8710 *
8711 * Takes care of CLP configurations.
72fd0718
VZ
8712 */
8713static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8714{
8715 u32 shmem;
8716 u32 validity_offset;
8717
51c1a580 8718 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8719
8720 /* Set `magic' bit in order to save MF config */
8721 if (!CHIP_IS_E1(bp))
8722 bnx2x_clp_reset_prep(bp, magic_val);
8723
8724 /* Get shmem offset */
8725 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8726 validity_offset = offsetof(struct shmem_region, validity_map[0]);
8727
8728 /* Clear validity map flags */
8729 if (shmem > 0)
8730 REG_WR(bp, shmem + validity_offset, 0);
8731}
8732
8733#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8734#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8735
e8920674
DK
8736/**
8737 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8738 *
e8920674 8739 * @bp: driver handle
72fd0718 8740 */
1191cb83 8741static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8742{
8743 /* special handling for emulation and FPGA,
8744 wait 10 times longer */
8745 if (CHIP_REV_IS_SLOW(bp))
8746 msleep(MCP_ONE_TIMEOUT*10);
8747 else
8748 msleep(MCP_ONE_TIMEOUT);
8749}
8750
1b6e2ceb
DK
8751/*
8752 * initializes bp->common.shmem_base and waits for validity signature to appear
8753 */
8754static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8755{
1b6e2ceb
DK
8756 int cnt = 0;
8757 u32 val = 0;
72fd0718 8758
1b6e2ceb
DK
8759 do {
8760 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8761 if (bp->common.shmem_base) {
8762 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8763 if (val & SHR_MEM_VALIDITY_MB)
8764 return 0;
8765 }
72fd0718 8766
1b6e2ceb 8767 bnx2x_mcp_wait_one(bp);
72fd0718 8768
1b6e2ceb 8769 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8770
1b6e2ceb 8771 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8772
1b6e2ceb
DK
8773 return -ENODEV;
8774}
72fd0718 8775
1b6e2ceb
DK
8776static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8777{
8778 int rc = bnx2x_init_shmem(bp);
72fd0718 8779
72fd0718
VZ
8780 /* Restore the `magic' bit value */
8781 if (!CHIP_IS_E1(bp))
8782 bnx2x_clp_reset_done(bp, magic_val);
8783
8784 return rc;
8785}
8786
8787static void bnx2x_pxp_prep(struct bnx2x *bp)
8788{
8789 if (!CHIP_IS_E1(bp)) {
8790 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8791 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8792 mmiowb();
8793 }
8794}
8795
8796/*
8797 * Reset the whole chip except for:
8798 * - PCIE core
8799 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8800 * one reset bit)
8801 * - IGU
8802 * - MISC (including AEU)
8803 * - GRC
8804 * - RBCN, RBCP
8805 */
c9ee9206 8806static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8807{
8808 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8809 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8810
8811 /*
8812 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8813 * (per chip) blocks.
8814 */
8815 global_bits2 =
8816 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8817 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 8818
8736c826 8819 /* Don't reset the following blocks */
72fd0718
VZ
8820 not_reset_mask1 =
8821 MISC_REGISTERS_RESET_REG_1_RST_HC |
8822 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8823 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8824
8825 not_reset_mask2 =
c9ee9206 8826 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
8827 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8828 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8829 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8830 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8831 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8832 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
8833 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8834 MISC_REGISTERS_RESET_REG_2_RST_ATC |
8835 MISC_REGISTERS_RESET_REG_2_PGLC;
72fd0718 8836
8736c826
VZ
8837 /*
8838 * Keep the following blocks in reset:
8839 * - all xxMACs are handled by the bnx2x_link code.
8840 */
8841 stay_reset2 =
8842 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8843 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8844 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8845 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8846 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8847 MISC_REGISTERS_RESET_REG_2_UMAC1 |
8848 MISC_REGISTERS_RESET_REG_2_XMAC |
8849 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8850
8851 /* Full reset masks according to the chip */
72fd0718
VZ
8852 reset_mask1 = 0xffffffff;
8853
8854 if (CHIP_IS_E1(bp))
8855 reset_mask2 = 0xffff;
8736c826 8856 else if (CHIP_IS_E1H(bp))
72fd0718 8857 reset_mask2 = 0x1ffff;
8736c826
VZ
8858 else if (CHIP_IS_E2(bp))
8859 reset_mask2 = 0xfffff;
8860 else /* CHIP_IS_E3 */
8861 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
8862
8863 /* Don't reset global blocks unless we need to */
8864 if (!global)
8865 reset_mask2 &= ~global_bits2;
8866
8867 /*
8868 * In case of attention in the QM, we need to reset PXP
8869 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8870 * because otherwise QM reset would release 'close the gates' shortly
8871 * before resetting the PXP, then the PSWRQ would send a write
8872 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8873 * read the payload data from PSWWR, but PSWWR would not
8874 * respond. The write queue in PGLUE would stuck, dmae commands
8875 * would not return. Therefore it's important to reset the second
8876 * reset register (containing the
8877 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8878 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8879 * bit).
8880 */
72fd0718
VZ
8881 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8882 reset_mask2 & (~not_reset_mask2));
8883
c9ee9206
VZ
8884 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8885 reset_mask1 & (~not_reset_mask1));
8886
72fd0718
VZ
8887 barrier();
8888 mmiowb();
8889
8736c826
VZ
8890 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8891 reset_mask2 & (~stay_reset2));
8892
8893 barrier();
8894 mmiowb();
8895
c9ee9206 8896 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
8897 mmiowb();
8898}
8899
c9ee9206
VZ
8900/**
8901 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8902 * It should get cleared in no more than 1s.
8903 *
8904 * @bp: driver handle
8905 *
8906 * It should get cleared in no more than 1s. Returns 0 if
8907 * pending writes bit gets cleared.
8908 */
8909static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8910{
8911 u32 cnt = 1000;
8912 u32 pend_bits = 0;
8913
8914 do {
8915 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8916
8917 if (pend_bits == 0)
8918 break;
8919
8920 usleep_range(1000, 1000);
8921 } while (cnt-- > 0);
8922
8923 if (cnt <= 0) {
8924 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8925 pend_bits);
8926 return -EBUSY;
8927 }
8928
8929 return 0;
8930}
8931
8932static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
8933{
8934 int cnt = 1000;
8935 u32 val = 0;
8936 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8937
8938
8939 /* Empty the Tetris buffer, wait for 1s */
8940 do {
8941 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8942 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8943 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8944 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8945 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8946 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8947 ((port_is_idle_0 & 0x1) == 0x1) &&
8948 ((port_is_idle_1 & 0x1) == 0x1) &&
8949 (pgl_exp_rom2 == 0xffffffff))
8950 break;
c9ee9206 8951 usleep_range(1000, 1000);
72fd0718
VZ
8952 } while (cnt-- > 0);
8953
8954 if (cnt <= 0) {
51c1a580
MS
8955 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8956 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
8957 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8958 pgl_exp_rom2);
8959 return -EAGAIN;
8960 }
8961
8962 barrier();
8963
8964 /* Close gates #2, #3 and #4 */
8965 bnx2x_set_234_gates(bp, true);
8966
c9ee9206
VZ
8967 /* Poll for IGU VQs for 57712 and newer chips */
8968 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8969 return -EAGAIN;
8970
8971
72fd0718
VZ
8972 /* TBD: Indicate that "process kill" is in progress to MCP */
8973
8974 /* Clear "unprepared" bit */
8975 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8976 barrier();
8977
8978 /* Make sure all is written to the chip before the reset */
8979 mmiowb();
8980
8981 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8982 * PSWHST, GRC and PSWRD Tetris buffer.
8983 */
c9ee9206 8984 usleep_range(1000, 1000);
72fd0718
VZ
8985
8986 /* Prepare to chip reset: */
8987 /* MCP */
c9ee9206
VZ
8988 if (global)
8989 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
8990
8991 /* PXP */
8992 bnx2x_pxp_prep(bp);
8993 barrier();
8994
8995 /* reset the chip */
c9ee9206 8996 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
8997 barrier();
8998
8999 /* Recover after reset: */
9000 /* MCP */
c9ee9206 9001 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9002 return -EAGAIN;
9003
c9ee9206
VZ
9004 /* TBD: Add resetting the NO_MCP mode DB here */
9005
72fd0718
VZ
9006 /* PXP */
9007 bnx2x_pxp_prep(bp);
9008
9009 /* Open the gates #2, #3 and #4 */
9010 bnx2x_set_234_gates(bp, false);
9011
9012 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9013 * reset state, re-enable attentions. */
9014
a2fbb9ea
ET
9015 return 0;
9016}
9017
910cc727 9018static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9019{
9020 int rc = 0;
c9ee9206 9021 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9022 u32 load_code;
9023
9024 /* if not going to reset MCP - load "fake" driver to reset HW while
9025 * driver is owner of the HW
9026 */
9027 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9028 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9029 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9030 if (!load_code) {
9031 BNX2X_ERR("MCP response failure, aborting\n");
9032 rc = -EAGAIN;
9033 goto exit_leader_reset;
9034 }
9035 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9036 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9037 BNX2X_ERR("MCP unexpected resp, aborting\n");
9038 rc = -EAGAIN;
9039 goto exit_leader_reset2;
9040 }
9041 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9042 if (!load_code) {
9043 BNX2X_ERR("MCP response failure, aborting\n");
9044 rc = -EAGAIN;
9045 goto exit_leader_reset2;
9046 }
9047 }
c9ee9206 9048
72fd0718 9049 /* Try to recover after the failure */
c9ee9206 9050 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9051 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9052 BP_PATH(bp));
72fd0718 9053 rc = -EAGAIN;
95c6c616 9054 goto exit_leader_reset2;
72fd0718
VZ
9055 }
9056
c9ee9206
VZ
9057 /*
9058 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9059 * state.
9060 */
72fd0718 9061 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9062 if (global)
9063 bnx2x_clear_reset_global(bp);
72fd0718 9064
95c6c616
AE
9065exit_leader_reset2:
9066 /* unload "fake driver" if it was loaded */
9067 if (!global && !BP_NOMCP(bp)) {
9068 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9069 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9070 }
72fd0718
VZ
9071exit_leader_reset:
9072 bp->is_leader = 0;
c9ee9206
VZ
9073 bnx2x_release_leader_lock(bp);
9074 smp_mb();
72fd0718
VZ
9075 return rc;
9076}
9077
1191cb83 9078static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9079{
9080 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9081
9082 /* Disconnect this device */
9083 netif_device_detach(bp->dev);
9084
9085 /*
9086 * Block ifup for all function on this engine until "process kill"
9087 * or power cycle.
9088 */
9089 bnx2x_set_reset_in_progress(bp);
9090
9091 /* Shut down the power */
9092 bnx2x_set_power_state(bp, PCI_D3hot);
9093
9094 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9095
9096 smp_mb();
9097}
9098
9099/*
9100 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9101 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9102 * will never be called when netif_running(bp->dev) is false.
9103 */
9104static void bnx2x_parity_recover(struct bnx2x *bp)
9105{
c9ee9206 9106 bool global = false;
7a752993 9107 u32 error_recovered, error_unrecovered;
95c6c616 9108 bool is_parity;
c9ee9206 9109
72fd0718
VZ
9110 DP(NETIF_MSG_HW, "Handling parity\n");
9111 while (1) {
9112 switch (bp->recovery_state) {
9113 case BNX2X_RECOVERY_INIT:
9114 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9115 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9116 WARN_ON(!is_parity);
c9ee9206 9117
72fd0718 9118 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9119 if (bnx2x_trylock_leader_lock(bp)) {
9120 bnx2x_set_reset_in_progress(bp);
9121 /*
9122 * Check if there is a global attention and if
9123 * there was a global attention, set the global
9124 * reset bit.
9125 */
9126
9127 if (global)
9128 bnx2x_set_reset_global(bp);
9129
72fd0718 9130 bp->is_leader = 1;
c9ee9206 9131 }
72fd0718
VZ
9132
9133 /* Stop the driver */
9134 /* If interface has been removed - break */
5d07d868 9135 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9136 return;
9137
9138 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9139
c9ee9206
VZ
9140 /* Ensure "is_leader", MCP command sequence and
9141 * "recovery_state" update values are seen on other
9142 * CPUs.
72fd0718 9143 */
c9ee9206 9144 smp_mb();
72fd0718
VZ
9145 break;
9146
9147 case BNX2X_RECOVERY_WAIT:
9148 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9149 if (bp->is_leader) {
c9ee9206 9150 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9151 bool other_load_status =
9152 bnx2x_get_load_status(bp, other_engine);
9153 bool load_status =
9154 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9155 global = bnx2x_reset_is_global(bp);
9156
9157 /*
9158 * In case of a parity in a global block, let
9159 * the first leader that performs a
9160 * leader_reset() reset the global blocks in
9161 * order to clear global attentions. Otherwise
9162 * the the gates will remain closed for that
9163 * engine.
9164 */
889b9af3
AE
9165 if (load_status ||
9166 (global && other_load_status)) {
72fd0718
VZ
9167 /* Wait until all other functions get
9168 * down.
9169 */
7be08a72 9170 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9171 HZ/10);
9172 return;
9173 } else {
9174 /* If all other functions got down -
9175 * try to bring the chip back to
9176 * normal. In any case it's an exit
9177 * point for a leader.
9178 */
c9ee9206
VZ
9179 if (bnx2x_leader_reset(bp)) {
9180 bnx2x_recovery_failed(bp);
72fd0718
VZ
9181 return;
9182 }
9183
c9ee9206
VZ
9184 /* If we are here, means that the
9185 * leader has succeeded and doesn't
9186 * want to be a leader any more. Try
9187 * to continue as a none-leader.
9188 */
9189 break;
72fd0718
VZ
9190 }
9191 } else { /* non-leader */
c9ee9206 9192 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9193 /* Try to get a LEADER_LOCK HW lock as
9194 * long as a former leader may have
9195 * been unloaded by the user or
9196 * released a leadership by another
9197 * reason.
9198 */
c9ee9206 9199 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9200 /* I'm a leader now! Restart a
9201 * switch case.
9202 */
9203 bp->is_leader = 1;
9204 break;
9205 }
9206
7be08a72 9207 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9208 HZ/10);
9209 return;
9210
c9ee9206
VZ
9211 } else {
9212 /*
9213 * If there was a global attention, wait
9214 * for it to be cleared.
9215 */
9216 if (bnx2x_reset_is_global(bp)) {
9217 schedule_delayed_work(
7be08a72
AE
9218 &bp->sp_rtnl_task,
9219 HZ/10);
c9ee9206
VZ
9220 return;
9221 }
9222
7a752993
AE
9223 error_recovered =
9224 bp->eth_stats.recoverable_error;
9225 error_unrecovered =
9226 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9227 bp->recovery_state =
9228 BNX2X_RECOVERY_NIC_LOADING;
9229 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9230 error_unrecovered++;
95c6c616 9231 netdev_err(bp->dev,
51c1a580 9232 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9233 /* Disconnect this device */
9234 netif_device_detach(bp->dev);
9235 /* Shut down the power */
9236 bnx2x_set_power_state(
9237 bp, PCI_D3hot);
9238 smp_mb();
9239 } else {
c9ee9206
VZ
9240 bp->recovery_state =
9241 BNX2X_RECOVERY_DONE;
7a752993 9242 error_recovered++;
c9ee9206
VZ
9243 smp_mb();
9244 }
7a752993
AE
9245 bp->eth_stats.recoverable_error =
9246 error_recovered;
9247 bp->eth_stats.unrecoverable_error =
9248 error_unrecovered;
c9ee9206 9249
72fd0718
VZ
9250 return;
9251 }
9252 }
9253 default:
9254 return;
9255 }
9256 }
9257}
9258
56ad3152
MS
9259static int bnx2x_close(struct net_device *dev);
9260
72fd0718
VZ
9261/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9262 * scheduled on a general queue in order to prevent a dead lock.
9263 */
7be08a72 9264static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9265{
7be08a72 9266 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9267
9268 rtnl_lock();
9269
9270 if (!netif_running(bp->dev))
7be08a72
AE
9271 goto sp_rtnl_exit;
9272
9273 /* if stop on error is defined no recovery flows should be executed */
9274#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9275 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9276 "you will need to reboot when done\n");
b1fb8740 9277 goto sp_rtnl_not_reset;
7be08a72 9278#endif
34f80b04 9279
7be08a72
AE
9280 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9281 /*
b1fb8740
VZ
9282 * Clear all pending SP commands as we are going to reset the
9283 * function anyway.
7be08a72 9284 */
b1fb8740
VZ
9285 bp->sp_rtnl_state = 0;
9286 smp_mb();
9287
72fd0718 9288 bnx2x_parity_recover(bp);
b1fb8740
VZ
9289
9290 goto sp_rtnl_exit;
9291 }
9292
9293 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9294 /*
9295 * Clear all pending SP commands as we are going to reset the
9296 * function anyway.
9297 */
9298 bp->sp_rtnl_state = 0;
9299 smp_mb();
9300
5d07d868 9301 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9302 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740
VZ
9303
9304 goto sp_rtnl_exit;
72fd0718 9305 }
b1fb8740
VZ
9306#ifdef BNX2X_STOP_ON_ERROR
9307sp_rtnl_not_reset:
9308#endif
9309 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9310 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9311 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9312 bnx2x_after_function_update(bp);
8304859a
AE
9313 /*
9314 * in case of fan failure we need to reset id if the "stop on error"
9315 * debug flag is set, since we trying to prevent permanent overheating
9316 * damage
9317 */
9318 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9319 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9320 netif_device_detach(bp->dev);
9321 bnx2x_close(bp->dev);
9322 }
9323
7be08a72 9324sp_rtnl_exit:
34f80b04
EG
9325 rtnl_unlock();
9326}
9327
a2fbb9ea
ET
9328/* end of nic load/unload */
9329
3deb8167
YR
9330static void bnx2x_period_task(struct work_struct *work)
9331{
9332 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9333
9334 if (!netif_running(bp->dev))
9335 goto period_task_exit;
9336
9337 if (CHIP_REV_IS_SLOW(bp)) {
9338 BNX2X_ERR("period task called on emulation, ignoring\n");
9339 goto period_task_exit;
9340 }
9341
9342 bnx2x_acquire_phy_lock(bp);
9343 /*
9344 * The barrier is needed to ensure the ordering between the writing to
9345 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9346 * the reading here.
9347 */
9348 smp_mb();
9349 if (bp->port.pmf) {
9350 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9351
9352 /* Re-queue task in 1 sec */
9353 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9354 }
9355
9356 bnx2x_release_phy_lock(bp);
9357period_task_exit:
9358 return;
9359}
9360
a2fbb9ea
ET
9361/*
9362 * Init service functions
9363 */
9364
8d96286a 9365static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9366{
9367 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9368 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9369 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9370}
9371
f2e0899f 9372static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
f1ef27ef 9373{
f2e0899f 9374 u32 reg = bnx2x_get_pretend_reg(bp);
f1ef27ef
EG
9375
9376 /* Flush all outstanding writes */
9377 mmiowb();
9378
9379 /* Pretend to be function 0 */
9380 REG_WR(bp, reg, 0);
f2e0899f 9381 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
f1ef27ef
EG
9382
9383 /* From now we are in the "like-E1" mode */
9384 bnx2x_int_disable(bp);
9385
9386 /* Flush all outstanding writes */
9387 mmiowb();
9388
f2e0899f
DK
9389 /* Restore the original function */
9390 REG_WR(bp, reg, BP_ABS_FUNC(bp));
9391 REG_RD(bp, reg);
f1ef27ef
EG
9392}
9393
f2e0899f 9394static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
f1ef27ef 9395{
f2e0899f 9396 if (CHIP_IS_E1(bp))
f1ef27ef 9397 bnx2x_int_disable(bp);
f2e0899f
DK
9398 else
9399 bnx2x_undi_int_disable_e1h(bp);
f1ef27ef
EG
9400}
9401
452427b0 9402static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
34f80b04 9403{
452427b0
YM
9404 u32 val, base_addr, offset, mask, reset_reg;
9405 bool mac_stopped = false;
9406 u8 port = BP_PORT(bp);
34f80b04 9407
452427b0 9408 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9409
452427b0
YM
9410 if (!CHIP_IS_E3(bp)) {
9411 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9412 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9413 if ((mask & reset_reg) && val) {
9414 u32 wb_data[2];
9415 BNX2X_DEV_INFO("Disable bmac Rx\n");
9416 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9417 : NIG_REG_INGRESS_BMAC0_MEM;
9418 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9419 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9420
452427b0
YM
9421 /*
9422 * use rd/wr since we cannot use dmae. This is safe
9423 * since MCP won't access the bus due to the request
9424 * to unload, and no function on the path can be
9425 * loaded at this time.
9426 */
9427 wb_data[0] = REG_RD(bp, base_addr + offset);
9428 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
9429 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
9430 REG_WR(bp, base_addr + offset, wb_data[0]);
9431 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
9432
9433 }
9434 BNX2X_DEV_INFO("Disable emac Rx\n");
9435 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
9436
9437 mac_stopped = true;
9438 } else {
9439 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9440 BNX2X_DEV_INFO("Disable xmac Rx\n");
9441 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9442 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9443 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9444 val & ~(1 << 1));
9445 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9446 val | (1 << 1));
9447 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
9448 mac_stopped = true;
9449 }
9450 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9451 if (mask & reset_reg) {
9452 BNX2X_DEV_INFO("Disable umac Rx\n");
9453 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9454 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
9455 mac_stopped = true;
9456 }
9457 }
9458
9459 if (mac_stopped)
9460 msleep(20);
9461
9462}
9463
9464#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9465#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9466#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9467#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9468
9469static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
9470 u8 inc)
9471{
9472 u16 rcq, bd;
9473 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9474
9475 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9476 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9477
9478 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9479 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9480
9481 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9482 port, bd, rcq);
9483}
9484
9485static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
9486{
5d07d868
YM
9487 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9488 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9489 if (!rc) {
9490 BNX2X_ERR("MCP response failure, aborting\n");
9491 return -EBUSY;
9492 }
9493
9494 return 0;
9495}
9496
9497static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
9498{
9499 struct bnx2x_prev_path_list *tmp_list;
9500 int rc = false;
9501
9502 if (down_trylock(&bnx2x_prev_sem))
9503 return false;
9504
9505 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9506 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9507 bp->pdev->bus->number == tmp_list->bus &&
9508 BP_PATH(bp) == tmp_list->path) {
9509 rc = true;
9510 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9511 BP_PATH(bp));
9512 break;
9513 }
9514 }
9515
9516 up(&bnx2x_prev_sem);
9517
9518 return rc;
9519}
9520
9521static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
9522{
9523 struct bnx2x_prev_path_list *tmp_list;
9524 int rc;
9525
ea4b3857 9526 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9527 if (!tmp_list) {
9528 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9529 return -ENOMEM;
9530 }
9531
9532 tmp_list->bus = bp->pdev->bus->number;
9533 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9534 tmp_list->path = BP_PATH(bp);
9535
9536 rc = down_interruptible(&bnx2x_prev_sem);
9537 if (rc) {
9538 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9539 kfree(tmp_list);
9540 } else {
9541 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9542 BP_PATH(bp));
9543 list_add(&tmp_list->list, &bnx2x_prev_list);
9544 up(&bnx2x_prev_sem);
9545 }
9546
9547 return rc;
9548}
9549
452427b0
YM
9550static int __devinit bnx2x_do_flr(struct bnx2x *bp)
9551{
2a80eebc 9552 int i;
452427b0
YM
9553 u16 status;
9554 struct pci_dev *dev = bp->pdev;
9555
8eee694c
YM
9556
9557 if (CHIP_IS_E1x(bp)) {
9558 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9559 return -EINVAL;
9560 }
9561
9562 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9563 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9564 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9565 bp->common.bc_ver);
9566 return -EINVAL;
9567 }
452427b0 9568
452427b0
YM
9569 /* Wait for Transaction Pending bit clean */
9570 for (i = 0; i < 4; i++) {
9571 if (i)
9572 msleep((1 << (i - 1)) * 100);
9573
2a80eebc 9574 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9575 if (!(status & PCI_EXP_DEVSTA_TRPND))
9576 goto clear;
9577 }
9578
9579 dev_err(&dev->dev,
9580 "transaction is not cleared; proceeding with reset anyway\n");
9581
9582clear:
452427b0 9583
8eee694c 9584 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9585 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9586
9587 return 0;
9588}
9589
9590static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
9591{
9592 int rc;
9593
9594 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9595
9596 /* Test if previous unload process was already finished for this path */
9597 if (bnx2x_prev_is_path_marked(bp))
9598 return bnx2x_prev_mcp_done(bp);
9599
9600 /* If function has FLR capabilities, and existing FW version matches
9601 * the one required, then FLR will be sufficient to clean any residue
9602 * left by previous driver
9603 */
8eee694c
YM
9604 rc = bnx2x_test_firmware_version(bp, false);
9605
9606 if (!rc) {
9607 /* fw version is good */
9608 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9609 rc = bnx2x_do_flr(bp);
9610 }
9611
9612 if (!rc) {
9613 /* FLR was performed */
9614 BNX2X_DEV_INFO("FLR successful\n");
9615 return 0;
9616 }
9617
9618 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9619
9620 /* Close the MCP request, return failure*/
9621 rc = bnx2x_prev_mcp_done(bp);
9622 if (!rc)
9623 rc = BNX2X_PREV_WAIT_NEEDED;
9624
9625 return rc;
9626}
9627
9628static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
9629{
9630 u32 reset_reg, tmp_reg = 0, rc;
9631 /* It is possible a previous function received 'common' answer,
9632 * but hasn't loaded yet, therefore creating a scenario of
9633 * multiple functions receiving 'common' on the same path.
9634 */
9635 BNX2X_DEV_INFO("Common unload Flow\n");
9636
9637 if (bnx2x_prev_is_path_marked(bp))
9638 return bnx2x_prev_mcp_done(bp);
9639
9640 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9641
9642 /* Reset should be performed after BRB is emptied */
9643 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9644 u32 timer_count = 1000;
9645 bool prev_undi = false;
9646
9647 /* Close the MAC Rx to prevent BRB from filling up */
9648 bnx2x_prev_unload_close_mac(bp);
9649
9650 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9651 * UNDI driver initializes CID offset for normal bell to 0x7
9652 */
452427b0
YM
9653 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9654 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9655 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9656 if (tmp_reg == 0x7) {
9657 BNX2X_DEV_INFO("UNDI previously loaded\n");
9658 prev_undi = true;
9659 /* clear the UNDI indication */
9660 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
34f80b04 9661 }
452427b0
YM
9662 }
9663 /* wait until BRB is empty */
9664 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9665 while (timer_count) {
9666 u32 prev_brb = tmp_reg;
34f80b04 9667
452427b0
YM
9668 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9669 if (!tmp_reg)
9670 break;
619c5cb6 9671
452427b0 9672 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9673
452427b0
YM
9674 /* reset timer as long as BRB actually gets emptied */
9675 if (prev_brb > tmp_reg)
9676 timer_count = 1000;
9677 else
9678 timer_count--;
da5a662a 9679
452427b0
YM
9680 /* If UNDI resides in memory, manually increment it */
9681 if (prev_undi)
9682 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9683
452427b0 9684 udelay(10);
7a06a122 9685 }
452427b0
YM
9686
9687 if (!timer_count)
9688 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9689
34f80b04 9690 }
f16da43b 9691
452427b0
YM
9692 /* No packets are in the pipeline, path is ready for reset */
9693 bnx2x_reset_common(bp);
9694
9695 rc = bnx2x_prev_mark_path(bp);
9696 if (rc) {
9697 bnx2x_prev_mcp_done(bp);
9698 return rc;
9699 }
9700
9701 return bnx2x_prev_mcp_done(bp);
9702}
9703
24f06716
AE
9704/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9705 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9706 * the addresses of the transaction, resulting in was-error bit set in the pci
9707 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9708 * to clear the interrupt which detected this from the pglueb and the was done
9709 * bit
9710 */
9711static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
9712{
4a25417c
AE
9713 if (!CHIP_IS_E1x(bp)) {
9714 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9715 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9716 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9717 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9718 1 << BP_FUNC(bp));
9719 }
24f06716
AE
9720 }
9721}
9722
452427b0
YM
9723static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9724{
9725 int time_counter = 10;
9726 u32 rc, fw, hw_lock_reg, hw_lock_val;
9727 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9728
24f06716
AE
9729 /* clear hw from errors which may have resulted from an interrupted
9730 * dmae transaction.
9731 */
9732 bnx2x_prev_interrupted_dmae(bp);
9733
9734 /* Release previously held locks */
452427b0
YM
9735 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9736 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9737 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9738
9739 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9740 if (hw_lock_val) {
9741 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9742 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9743 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9744 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9745 }
9746
9747 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9748 REG_WR(bp, hw_lock_reg, 0xffffffff);
9749 } else
9750 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9751
9752 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9753 BNX2X_DEV_INFO("Release previously held alr\n");
9754 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9755 }
9756
9757
9758 do {
9759 /* Lock MCP using an unload request */
9760 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9761 if (!fw) {
9762 BNX2X_ERR("MCP response failure, aborting\n");
9763 rc = -EBUSY;
9764 break;
9765 }
9766
9767 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9768 rc = bnx2x_prev_unload_common(bp);
9769 break;
9770 }
9771
9772 /* non-common reply from MCP night require looping */
9773 rc = bnx2x_prev_unload_uncommon(bp);
9774 if (rc != BNX2X_PREV_WAIT_NEEDED)
9775 break;
9776
9777 msleep(20);
9778 } while (--time_counter);
9779
9780 if (!time_counter || rc) {
9781 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9782 rc = -EBUSY;
9783 }
9784
9785 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9786
9787 return rc;
34f80b04
EG
9788}
9789
9790static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9791{
1d187b34 9792 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 9793 u16 pmc;
34f80b04
EG
9794
9795 /* Get the chip revision id and number. */
9796 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9797 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9798 id = ((val & 0xffff) << 16);
9799 val = REG_RD(bp, MISC_REG_CHIP_REV);
9800 id |= ((val & 0xf) << 12);
9801 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9802 id |= ((val & 0xff) << 4);
5a40e08e 9803 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
9804 id |= (val & 0xf);
9805 bp->common.chip_id = id;
523224a3 9806
7e8e02df
BW
9807 /* force 57811 according to MISC register */
9808 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
9809 if (CHIP_IS_57810(bp))
9810 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
9811 (bp->common.chip_id & 0x0000FFFF);
9812 else if (CHIP_IS_57810_MF(bp))
9813 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
9814 (bp->common.chip_id & 0x0000FFFF);
9815 bp->common.chip_id |= 0x1;
9816 }
9817
523224a3
DK
9818 /* Set doorbell size */
9819 bp->db_size = (1 << BNX2X_DB_SHIFT);
9820
619c5cb6 9821 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
9822 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9823 if ((val & 1) == 0)
9824 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9825 else
9826 val = (val >> 1) & 1;
9827 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9828 "2_PORT_MODE");
9829 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9830 CHIP_2_PORT_MODE;
9831
9832 if (CHIP_MODE_IS_4_PORT(bp))
9833 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9834 else
9835 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9836 } else {
9837 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9838 bp->pfid = bp->pf_num; /* 0..7 */
9839 }
9840
51c1a580
MS
9841 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9842
f2e0899f
DK
9843 bp->link_params.chip_id = bp->common.chip_id;
9844 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 9845
1c06328c
EG
9846 val = (REG_RD(bp, 0x2874) & 0x55);
9847 if ((bp->common.chip_id & 0x1) ||
9848 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9849 bp->flags |= ONE_PORT_FLAG;
9850 BNX2X_DEV_INFO("single port device\n");
9851 }
9852
34f80b04 9853 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 9854 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
9855 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9856 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9857 bp->common.flash_size, bp->common.flash_size);
9858
1b6e2ceb
DK
9859 bnx2x_init_shmem(bp);
9860
619c5cb6
VZ
9861
9862
f2e0899f
DK
9863 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9864 MISC_REG_GENERIC_CR_1 :
9865 MISC_REG_GENERIC_CR_0));
1b6e2ceb 9866
34f80b04 9867 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 9868 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
9869 if (SHMEM2_RD(bp, size) >
9870 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
9871 bp->link_params.lfa_base =
9872 REG_RD(bp, bp->common.shmem2_base +
9873 (u32)offsetof(struct shmem2_region,
9874 lfa_host_addr[BP_PORT(bp)]));
9875 else
9876 bp->link_params.lfa_base = 0;
2691d51d
EG
9877 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9878 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 9879
f2e0899f 9880 if (!bp->common.shmem_base) {
34f80b04
EG
9881 BNX2X_DEV_INFO("MCP not active\n");
9882 bp->flags |= NO_MCP_FLAG;
9883 return;
9884 }
9885
34f80b04 9886 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 9887 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
9888
9889 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9890 SHARED_HW_CFG_LED_MODE_MASK) >>
9891 SHARED_HW_CFG_LED_MODE_SHIFT);
9892
c2c8b03e
EG
9893 bp->link_params.feature_config_flags = 0;
9894 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9895 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9896 bp->link_params.feature_config_flags |=
9897 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9898 else
9899 bp->link_params.feature_config_flags &=
9900 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9901
34f80b04
EG
9902 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9903 bp->common.bc_ver = val;
9904 BNX2X_DEV_INFO("bc_ver %X\n", val);
9905 if (val < BNX2X_BC_VER) {
9906 /* for now only warn
9907 * later we might need to enforce this */
51c1a580
MS
9908 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9909 BNX2X_BC_VER, val);
34f80b04 9910 }
4d295db0 9911 bp->link_params.feature_config_flags |=
a22f0788 9912 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
9913 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9914
a22f0788
YR
9915 bp->link_params.feature_config_flags |=
9916 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9917 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
9918 bp->link_params.feature_config_flags |=
9919 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
9920 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
9921 bp->link_params.feature_config_flags |=
9922 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9923 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
9924
9925 bp->link_params.feature_config_flags |=
9926 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
9927 FEATURE_CONFIG_MT_SUPPORT : 0;
9928
0e898dd7
BW
9929 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9930 BC_SUPPORTS_PFC_STATS : 0;
85242eea 9931
2e499d3c
BW
9932 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
9933 BC_SUPPORTS_FCOE_FEATURES : 0;
9934
9876879f
BW
9935 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
9936 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
9937 boot_mode = SHMEM_RD(bp,
9938 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9939 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9940 switch (boot_mode) {
9941 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9942 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9943 break;
9944 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9945 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9946 break;
9947 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9948 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9949 break;
9950 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9951 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9952 break;
9953 }
9954
f9a3ebbe
DK
9955 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9956 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9957
72ce58c3 9958 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 9959 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
9960
9961 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9962 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9963 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9964 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9965
cdaa7cb8
VZ
9966 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9967 val, val2, val3, val4);
34f80b04
EG
9968}
9969
f2e0899f
DK
9970#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9971#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9972
9973static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9974{
9975 int pfid = BP_FUNC(bp);
f2e0899f
DK
9976 int igu_sb_id;
9977 u32 val;
6383c0b3 9978 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
9979
9980 bp->igu_base_sb = 0xff;
f2e0899f 9981 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 9982 int vn = BP_VN(bp);
6383c0b3 9983 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
9984 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9985 FP_SB_MAX_E1x;
9986
9987 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9988 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9989
9990 return;
9991 }
9992
9993 /* IGU in normal mode - read CAM */
9994 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9995 igu_sb_id++) {
9996 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
9997 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
9998 continue;
9999 fid = IGU_FID(val);
10000 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10001 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10002 continue;
10003 if (IGU_VEC(val) == 0)
10004 /* default status block */
10005 bp->igu_dsb_id = igu_sb_id;
10006 else {
10007 if (bp->igu_base_sb == 0xff)
10008 bp->igu_base_sb = igu_sb_id;
6383c0b3 10009 igu_sb_cnt++;
f2e0899f
DK
10010 }
10011 }
10012 }
619c5cb6 10013
6383c0b3 10014#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10015 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10016 * optional that number of CAM entries will not be equal to the value
10017 * advertised in PCI.
10018 * Driver should use the minimal value of both as the actual status
10019 * block count
619c5cb6 10020 */
185d4c8b 10021 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10022#endif
619c5cb6 10023
6383c0b3 10024 if (igu_sb_cnt == 0)
f2e0899f
DK
10025 BNX2X_ERR("CAM configuration error\n");
10026}
10027
34f80b04
EG
10028static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
10029 u32 switch_cfg)
a2fbb9ea 10030{
a22f0788
YR
10031 int cfg_size = 0, idx, port = BP_PORT(bp);
10032
10033 /* Aggregation of supported attributes of all external phys */
10034 bp->port.supported[0] = 0;
10035 bp->port.supported[1] = 0;
b7737c9b
YR
10036 switch (bp->link_params.num_phys) {
10037 case 1:
a22f0788
YR
10038 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10039 cfg_size = 1;
10040 break;
b7737c9b 10041 case 2:
a22f0788
YR
10042 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10043 cfg_size = 1;
10044 break;
10045 case 3:
10046 if (bp->link_params.multi_phy_config &
10047 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10048 bp->port.supported[1] =
10049 bp->link_params.phy[EXT_PHY1].supported;
10050 bp->port.supported[0] =
10051 bp->link_params.phy[EXT_PHY2].supported;
10052 } else {
10053 bp->port.supported[0] =
10054 bp->link_params.phy[EXT_PHY1].supported;
10055 bp->port.supported[1] =
10056 bp->link_params.phy[EXT_PHY2].supported;
10057 }
10058 cfg_size = 2;
10059 break;
b7737c9b 10060 }
a2fbb9ea 10061
a22f0788 10062 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10063 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10064 SHMEM_RD(bp,
a22f0788
YR
10065 dev_info.port_hw_config[port].external_phy_config),
10066 SHMEM_RD(bp,
10067 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10068 return;
f85582f8 10069 }
a2fbb9ea 10070
619c5cb6
VZ
10071 if (CHIP_IS_E3(bp))
10072 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10073 else {
10074 switch (switch_cfg) {
10075 case SWITCH_CFG_1G:
10076 bp->port.phy_addr = REG_RD(
10077 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10078 break;
10079 case SWITCH_CFG_10G:
10080 bp->port.phy_addr = REG_RD(
10081 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10082 break;
10083 default:
10084 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10085 bp->port.link_config[0]);
10086 return;
10087 }
a2fbb9ea 10088 }
619c5cb6 10089 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10090 /* mask what we support according to speed_cap_mask per configuration */
10091 for (idx = 0; idx < cfg_size; idx++) {
10092 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10093 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10094 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10095
a22f0788 10096 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10097 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10098 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10099
a22f0788 10100 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10101 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10102 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10103
a22f0788 10104 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10105 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10106 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10107
a22f0788 10108 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10109 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10110 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10111 SUPPORTED_1000baseT_Full);
a2fbb9ea 10112
a22f0788 10113 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10114 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10115 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10116
a22f0788 10117 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10118 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
10119 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10120
10121 }
a2fbb9ea 10122
a22f0788
YR
10123 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10124 bp->port.supported[1]);
a2fbb9ea
ET
10125}
10126
34f80b04 10127static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10128{
a22f0788
YR
10129 u32 link_config, idx, cfg_size = 0;
10130 bp->port.advertising[0] = 0;
10131 bp->port.advertising[1] = 0;
10132 switch (bp->link_params.num_phys) {
10133 case 1:
10134 case 2:
10135 cfg_size = 1;
10136 break;
10137 case 3:
10138 cfg_size = 2;
10139 break;
10140 }
10141 for (idx = 0; idx < cfg_size; idx++) {
10142 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10143 link_config = bp->port.link_config[idx];
10144 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10145 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10146 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10147 bp->link_params.req_line_speed[idx] =
10148 SPEED_AUTO_NEG;
10149 bp->port.advertising[idx] |=
10150 bp->port.supported[idx];
10bd1f24
MY
10151 if (bp->link_params.phy[EXT_PHY1].type ==
10152 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10153 bp->port.advertising[idx] |=
10154 (SUPPORTED_100baseT_Half |
10155 SUPPORTED_100baseT_Full);
f85582f8
DK
10156 } else {
10157 /* force 10G, no AN */
a22f0788
YR
10158 bp->link_params.req_line_speed[idx] =
10159 SPEED_10000;
10160 bp->port.advertising[idx] |=
10161 (ADVERTISED_10000baseT_Full |
f85582f8 10162 ADVERTISED_FIBRE);
a22f0788 10163 continue;
f85582f8
DK
10164 }
10165 break;
a2fbb9ea 10166
f85582f8 10167 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10168 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10169 bp->link_params.req_line_speed[idx] =
10170 SPEED_10;
10171 bp->port.advertising[idx] |=
10172 (ADVERTISED_10baseT_Full |
f85582f8
DK
10173 ADVERTISED_TP);
10174 } else {
51c1a580 10175 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10176 link_config,
a22f0788 10177 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10178 return;
10179 }
10180 break;
a2fbb9ea 10181
f85582f8 10182 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10183 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10184 bp->link_params.req_line_speed[idx] =
10185 SPEED_10;
10186 bp->link_params.req_duplex[idx] =
10187 DUPLEX_HALF;
10188 bp->port.advertising[idx] |=
10189 (ADVERTISED_10baseT_Half |
f85582f8
DK
10190 ADVERTISED_TP);
10191 } else {
51c1a580 10192 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10193 link_config,
10194 bp->link_params.speed_cap_mask[idx]);
10195 return;
10196 }
10197 break;
a2fbb9ea 10198
f85582f8
DK
10199 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10200 if (bp->port.supported[idx] &
10201 SUPPORTED_100baseT_Full) {
a22f0788
YR
10202 bp->link_params.req_line_speed[idx] =
10203 SPEED_100;
10204 bp->port.advertising[idx] |=
10205 (ADVERTISED_100baseT_Full |
f85582f8
DK
10206 ADVERTISED_TP);
10207 } else {
51c1a580 10208 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10209 link_config,
10210 bp->link_params.speed_cap_mask[idx]);
10211 return;
10212 }
10213 break;
a2fbb9ea 10214
f85582f8
DK
10215 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10216 if (bp->port.supported[idx] &
10217 SUPPORTED_100baseT_Half) {
10218 bp->link_params.req_line_speed[idx] =
10219 SPEED_100;
10220 bp->link_params.req_duplex[idx] =
10221 DUPLEX_HALF;
a22f0788
YR
10222 bp->port.advertising[idx] |=
10223 (ADVERTISED_100baseT_Half |
f85582f8
DK
10224 ADVERTISED_TP);
10225 } else {
51c1a580 10226 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10227 link_config,
10228 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10229 return;
10230 }
10231 break;
a2fbb9ea 10232
f85582f8 10233 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10234 if (bp->port.supported[idx] &
10235 SUPPORTED_1000baseT_Full) {
10236 bp->link_params.req_line_speed[idx] =
10237 SPEED_1000;
10238 bp->port.advertising[idx] |=
10239 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10240 ADVERTISED_TP);
10241 } else {
51c1a580 10242 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10243 link_config,
10244 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10245 return;
10246 }
10247 break;
a2fbb9ea 10248
f85582f8 10249 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10250 if (bp->port.supported[idx] &
10251 SUPPORTED_2500baseX_Full) {
10252 bp->link_params.req_line_speed[idx] =
10253 SPEED_2500;
10254 bp->port.advertising[idx] |=
10255 (ADVERTISED_2500baseX_Full |
34f80b04 10256 ADVERTISED_TP);
f85582f8 10257 } else {
51c1a580 10258 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10259 link_config,
f85582f8
DK
10260 bp->link_params.speed_cap_mask[idx]);
10261 return;
10262 }
10263 break;
a2fbb9ea 10264
f85582f8 10265 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10266 if (bp->port.supported[idx] &
10267 SUPPORTED_10000baseT_Full) {
10268 bp->link_params.req_line_speed[idx] =
10269 SPEED_10000;
10270 bp->port.advertising[idx] |=
10271 (ADVERTISED_10000baseT_Full |
34f80b04 10272 ADVERTISED_FIBRE);
f85582f8 10273 } else {
51c1a580 10274 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10275 link_config,
f85582f8
DK
10276 bp->link_params.speed_cap_mask[idx]);
10277 return;
10278 }
10279 break;
3c9ada22
YR
10280 case PORT_FEATURE_LINK_SPEED_20G:
10281 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10282
3c9ada22 10283 break;
f85582f8 10284 default:
51c1a580 10285 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10286 link_config);
f85582f8
DK
10287 bp->link_params.req_line_speed[idx] =
10288 SPEED_AUTO_NEG;
10289 bp->port.advertising[idx] =
10290 bp->port.supported[idx];
10291 break;
10292 }
a2fbb9ea 10293
a22f0788 10294 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10295 PORT_FEATURE_FLOW_CONTROL_MASK);
a22f0788
YR
10296 if ((bp->link_params.req_flow_ctrl[idx] ==
10297 BNX2X_FLOW_CTRL_AUTO) &&
10298 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
10299 bp->link_params.req_flow_ctrl[idx] =
10300 BNX2X_FLOW_CTRL_NONE;
10301 }
a2fbb9ea 10302
51c1a580 10303 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10304 bp->link_params.req_line_speed[idx],
10305 bp->link_params.req_duplex[idx],
10306 bp->link_params.req_flow_ctrl[idx],
10307 bp->port.advertising[idx]);
10308 }
a2fbb9ea
ET
10309}
10310
e665bfda
MC
10311static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
10312{
10313 mac_hi = cpu_to_be16(mac_hi);
10314 mac_lo = cpu_to_be32(mac_lo);
10315 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
10316 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
10317}
10318
34f80b04 10319static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10320{
34f80b04 10321 int port = BP_PORT(bp);
589abe3a 10322 u32 config;
c8c60d88 10323 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10324
c18487ee 10325 bp->link_params.bp = bp;
34f80b04 10326 bp->link_params.port = port;
c18487ee 10327
c18487ee 10328 bp->link_params.lane_config =
a2fbb9ea 10329 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10330
a22f0788 10331 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
10332 SHMEM_RD(bp,
10333 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
10334 bp->link_params.speed_cap_mask[1] =
10335 SHMEM_RD(bp,
10336 dev_info.port_hw_config[port].speed_capability_mask2);
10337 bp->port.link_config[0] =
a2fbb9ea
ET
10338 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10339
a22f0788
YR
10340 bp->port.link_config[1] =
10341 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10342
a22f0788
YR
10343 bp->link_params.multi_phy_config =
10344 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10345 /* If the device is capable of WoL, set the default state according
10346 * to the HW
10347 */
4d295db0 10348 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10349 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10350 (config & PORT_FEATURE_WOL_ENABLED));
10351
51c1a580 10352 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10353 bp->link_params.lane_config,
a22f0788
YR
10354 bp->link_params.speed_cap_mask[0],
10355 bp->port.link_config[0]);
a2fbb9ea 10356
a22f0788 10357 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10358 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10359 bnx2x_phy_probe(&bp->link_params);
c18487ee 10360 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10361
10362 bnx2x_link_settings_requested(bp);
10363
01cd4528
EG
10364 /*
10365 * If connected directly, work with the internal PHY, otherwise, work
10366 * with the external PHY
10367 */
b7737c9b
YR
10368 ext_phy_config =
10369 SHMEM_RD(bp,
10370 dev_info.port_hw_config[port].external_phy_config);
10371 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10372 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10373 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10374
10375 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10376 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10377 bp->mdio.prtad =
b7737c9b 10378 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10379
c8c60d88
YM
10380 /* Configure link feature according to nvram value */
10381 eee_mode = (((SHMEM_RD(bp, dev_info.
10382 port_feature_config[port].eee_power_mode)) &
10383 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10384 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10385 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10386 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10387 EEE_MODE_ENABLE_LPI |
10388 EEE_MODE_OUTPUT_TIME;
10389 } else {
10390 bp->link_params.eee_mode = 0;
10391 }
0793f83f 10392}
01cd4528 10393
b306f5ed 10394void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10395{
9e62e912 10396 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10397 int port = BP_PORT(bp);
2ba45142 10398 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10399 drv_lic_key[port].max_iscsi_conn);
2ba45142 10400
55c11941
MS
10401 if (!CNIC_SUPPORT(bp)) {
10402 bp->flags |= no_flags;
10403 return;
10404 }
10405
b306f5ed 10406 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10407 bp->cnic_eth_dev.max_iscsi_conn =
10408 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10409 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10410
b306f5ed
DK
10411 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10412 bp->cnic_eth_dev.max_iscsi_conn);
10413
10414 /*
10415 * If maximum allowed number of connections is zero -
10416 * disable the feature.
10417 */
10418 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10419 bp->flags |= no_flags;
55c11941 10420
b306f5ed
DK
10421}
10422
9e62e912
DK
10423static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
10424{
10425 /* Port info */
10426 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10427 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10428 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10429 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10430
10431 /* Node info */
10432 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10433 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10434 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10435 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10436}
b306f5ed
DK
10437static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
10438{
10439 int port = BP_PORT(bp);
10440 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10441 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10442 drv_lic_key[port].max_fcoe_conn);
10443
55c11941
MS
10444 if (!CNIC_SUPPORT(bp)) {
10445 bp->flags |= NO_FCOE_FLAG;
10446 return;
10447 }
10448
b306f5ed 10449 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10450 bp->cnic_eth_dev.max_fcoe_conn =
10451 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10452 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10453
bf61ee14
VZ
10454 /* Read the WWN: */
10455 if (!IS_MF(bp)) {
10456 /* Port info */
10457 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10458 SHMEM_RD(bp,
10459 dev_info.port_hw_config[port].
10460 fcoe_wwn_port_name_upper);
10461 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10462 SHMEM_RD(bp,
10463 dev_info.port_hw_config[port].
10464 fcoe_wwn_port_name_lower);
10465
10466 /* Node info */
10467 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10468 SHMEM_RD(bp,
10469 dev_info.port_hw_config[port].
10470 fcoe_wwn_node_name_upper);
10471 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10472 SHMEM_RD(bp,
10473 dev_info.port_hw_config[port].
10474 fcoe_wwn_node_name_lower);
10475 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10476 /*
10477 * Read the WWN info only if the FCoE feature is enabled for
10478 * this function.
10479 */
7b5342d9 10480 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10481 bnx2x_get_ext_wwn_info(bp, func);
10482
10483 } else if (IS_MF_FCOE_SD(bp))
10484 bnx2x_get_ext_wwn_info(bp, func);
bf61ee14 10485
b306f5ed 10486 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10487
bf61ee14
VZ
10488 /*
10489 * If maximum allowed number of connections is zero -
2ba45142
VZ
10490 * disable the feature.
10491 */
2ba45142
VZ
10492 if (!bp->cnic_eth_dev.max_fcoe_conn)
10493 bp->flags |= NO_FCOE_FLAG;
10494}
b306f5ed
DK
10495
10496static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
10497{
10498 /*
10499 * iSCSI may be dynamically disabled but reading
10500 * info here we will decrease memory usage by driver
10501 * if the feature is disabled for good
10502 */
10503 bnx2x_get_iscsi_info(bp);
10504 bnx2x_get_fcoe_info(bp);
10505}
2ba45142 10506
55c11941 10507static void __devinit bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10508{
10509 u32 val, val2;
10510 int func = BP_ABS_FUNC(bp);
10511 int port = BP_PORT(bp);
2ba45142
VZ
10512 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10513 u8 *fip_mac = bp->fip_mac;
0793f83f 10514
55c11941
MS
10515 if (IS_MF(bp)) {
10516 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10517 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10518 * In non SD mode features configuration comes from struct
10519 * func_ext_config.
2ba45142 10520 */
55c11941 10521 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10522 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10523 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10524 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10525 iscsi_mac_addr_upper);
0793f83f 10526 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10527 iscsi_mac_addr_lower);
2ba45142 10528 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10529 BNX2X_DEV_INFO
10530 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10531 } else {
2ba45142 10532 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10533 }
2ba45142
VZ
10534
10535 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10536 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10537 fcoe_mac_addr_upper);
2ba45142 10538 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10539 fcoe_mac_addr_lower);
2ba45142 10540 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10541 BNX2X_DEV_INFO
10542 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10543 } else {
2ba45142 10544 bp->flags |= NO_FCOE_FLAG;
55c11941 10545 }
a3348722
BW
10546
10547 bp->mf_ext_config = cfg;
10548
9e62e912 10549 } else { /* SD MODE */
55c11941
MS
10550 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10551 /* use primary mac as iscsi mac */
10552 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10553
10554 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10555 BNX2X_DEV_INFO
10556 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10557 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10558 /* use primary mac as fip mac */
10559 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10560 BNX2X_DEV_INFO("SD FCoE MODE\n");
10561 BNX2X_DEV_INFO
10562 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10563 }
0793f83f 10564 }
a3348722 10565
55c11941
MS
10566 if (IS_MF_STORAGE_SD(bp))
10567 /* Zero primary MAC configuration */
10568 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10569
a3348722
BW
10570 if (IS_MF_FCOE_AFEX(bp))
10571 /* use FIP MAC as primary MAC */
10572 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10573
0793f83f 10574 } else {
0793f83f 10575 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10576 iscsi_mac_upper);
0793f83f 10577 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10578 iscsi_mac_lower);
2ba45142 10579 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10580
10581 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10582 fcoe_fip_mac_upper);
c03bd39c 10583 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10584 fcoe_fip_mac_lower);
c03bd39c 10585 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10586 }
10587
55c11941 10588 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10589 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10590 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10591 memset(iscsi_mac, 0, ETH_ALEN);
10592 }
10593
55c11941 10594 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10595 if (!is_valid_ether_addr(fip_mac)) {
10596 bp->flags |= NO_FCOE_FLAG;
10597 memset(bp->fip_mac, 0, ETH_ALEN);
10598 }
55c11941
MS
10599}
10600
10601static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
10602{
10603 u32 val, val2;
10604 int func = BP_ABS_FUNC(bp);
10605 int port = BP_PORT(bp);
10606
10607 /* Zero primary MAC configuration */
10608 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10609
10610 if (BP_NOMCP(bp)) {
10611 BNX2X_ERROR("warning: random MAC workaround active\n");
10612 eth_hw_addr_random(bp->dev);
10613 } else if (IS_MF(bp)) {
10614 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10615 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10616 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10617 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10618 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10619
10620 if (CNIC_SUPPORT(bp))
10621 bnx2x_get_cnic_mac_hwinfo(bp);
10622 } else {
10623 /* in SF read MACs from port configuration */
10624 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10625 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
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 }
10631
10632 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
10633 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10634
614c76df 10635 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10636 dev_err(&bp->pdev->dev,
51c1a580
MS
10637 "bad Ethernet MAC address configuration: %pM\n"
10638 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10639 bp->dev->dev_addr);
51c1a580
MS
10640
10641
34f80b04
EG
10642}
10643
10644static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
10645{
0793f83f 10646 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 10647 int vn;
0793f83f 10648 u32 val = 0;
34f80b04 10649 int rc = 0;
a2fbb9ea 10650
34f80b04 10651 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 10652
6383c0b3
AE
10653 /*
10654 * initialize IGU parameters
10655 */
f2e0899f
DK
10656 if (CHIP_IS_E1x(bp)) {
10657 bp->common.int_block = INT_BLOCK_HC;
10658
10659 bp->igu_dsb_id = DEF_SB_IGU_ID;
10660 bp->igu_base_sb = 0;
f2e0899f
DK
10661 } else {
10662 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
10663
10664 /* do not allow device reset during IGU info preocessing */
10665 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10666
f2e0899f 10667 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
10668
10669 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10670 int tout = 5000;
10671
10672 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10673
10674 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10675 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10676 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10677
10678 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10679 tout--;
10680 usleep_range(1000, 1000);
10681 }
10682
10683 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10684 dev_err(&bp->pdev->dev,
10685 "FORCING Normal Mode failed!!!\n");
10686 return -EPERM;
10687 }
10688 }
10689
f2e0899f 10690 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 10691 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
10692 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10693 } else
619c5cb6 10694 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 10695
f2e0899f
DK
10696 bnx2x_get_igu_cam_info(bp);
10697
7a06a122 10698 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
f2e0899f 10699 }
619c5cb6
VZ
10700
10701 /*
10702 * set base FW non-default (fast path) status block id, this value is
10703 * used to initialize the fw_sb_id saved on the fp/queue structure to
10704 * determine the id used by the FW.
10705 */
10706 if (CHIP_IS_E1x(bp))
10707 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10708 else /*
10709 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10710 * the same queue are indicated on the same IGU SB). So we prefer
10711 * FW and IGU SBs to be the same value.
10712 */
10713 bp->base_fw_ndsb = bp->igu_base_sb;
10714
10715 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10716 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10717 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
10718
10719 /*
10720 * Initialize MF configuration
10721 */
523224a3 10722
fb3bff17
DK
10723 bp->mf_ov = 0;
10724 bp->mf_mode = 0;
3395a033 10725 vn = BP_VN(bp);
0793f83f 10726
f2e0899f 10727 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
10728 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10729 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10730 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10731
f2e0899f
DK
10732 if (SHMEM2_HAS(bp, mf_cfg_addr))
10733 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10734 else
10735 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
10736 offsetof(struct shmem_region, func_mb) +
10737 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
10738 /*
10739 * get mf configuration:
25985edc 10740 * 1. existence of MF configuration
0793f83f
DK
10741 * 2. MAC address must be legal (check only upper bytes)
10742 * for Switch-Independent mode;
10743 * OVLAN must be legal for Switch-Dependent mode
10744 * 3. SF_MODE configures specific MF mode
10745 */
10746 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10747 /* get mf configuration */
10748 val = SHMEM_RD(bp,
10749 dev_info.shared_feature_config.config);
10750 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10751
10752 switch (val) {
10753 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10754 val = MF_CFG_RD(bp, func_mf_config[func].
10755 mac_upper);
10756 /* check for legal mac (upper bytes)*/
10757 if (val != 0xffff) {
10758 bp->mf_mode = MULTI_FUNCTION_SI;
10759 bp->mf_config[vn] = MF_CFG_RD(bp,
10760 func_mf_config[func].config);
10761 } else
51c1a580 10762 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 10763 break;
a3348722
BW
10764 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
10765 if ((!CHIP_IS_E1x(bp)) &&
10766 (MF_CFG_RD(bp, func_mf_config[func].
10767 mac_upper) != 0xffff) &&
10768 (SHMEM2_HAS(bp,
10769 afex_driver_support))) {
10770 bp->mf_mode = MULTI_FUNCTION_AFEX;
10771 bp->mf_config[vn] = MF_CFG_RD(bp,
10772 func_mf_config[func].config);
10773 } else {
10774 BNX2X_DEV_INFO("can not configure afex mode\n");
10775 }
10776 break;
0793f83f
DK
10777 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10778 /* get OV configuration */
10779 val = MF_CFG_RD(bp,
10780 func_mf_config[FUNC_0].e1hov_tag);
10781 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10782
10783 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10784 bp->mf_mode = MULTI_FUNCTION_SD;
10785 bp->mf_config[vn] = MF_CFG_RD(bp,
10786 func_mf_config[func].config);
10787 } else
754a2f52 10788 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
10789 break;
10790 default:
10791 /* Unknown configuration: reset mf_config */
10792 bp->mf_config[vn] = 0;
51c1a580 10793 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
10794 }
10795 }
a2fbb9ea 10796
2691d51d 10797 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 10798 IS_MF(bp) ? "multi" : "single");
2691d51d 10799
0793f83f
DK
10800 switch (bp->mf_mode) {
10801 case MULTI_FUNCTION_SD:
10802 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10803 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 10804 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 10805 bp->mf_ov = val;
619c5cb6
VZ
10806 bp->path_has_ovlan = true;
10807
51c1a580
MS
10808 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10809 func, bp->mf_ov, bp->mf_ov);
2691d51d 10810 } else {
619c5cb6 10811 dev_err(&bp->pdev->dev,
51c1a580
MS
10812 "No valid MF OV for func %d, aborting\n",
10813 func);
619c5cb6 10814 return -EPERM;
34f80b04 10815 }
0793f83f 10816 break;
a3348722
BW
10817 case MULTI_FUNCTION_AFEX:
10818 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
10819 break;
0793f83f 10820 case MULTI_FUNCTION_SI:
51c1a580
MS
10821 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10822 func);
0793f83f
DK
10823 break;
10824 default:
10825 if (vn) {
619c5cb6 10826 dev_err(&bp->pdev->dev,
51c1a580
MS
10827 "VN %d is in a single function mode, aborting\n",
10828 vn);
619c5cb6 10829 return -EPERM;
2691d51d 10830 }
0793f83f 10831 break;
34f80b04 10832 }
0793f83f 10833
619c5cb6
VZ
10834 /* check if other port on the path needs ovlan:
10835 * Since MF configuration is shared between ports
10836 * Possible mixed modes are only
10837 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10838 */
10839 if (CHIP_MODE_IS_4_PORT(bp) &&
10840 !bp->path_has_ovlan &&
10841 !IS_MF(bp) &&
10842 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10843 u8 other_port = !BP_PORT(bp);
10844 u8 other_func = BP_PATH(bp) + 2*other_port;
10845 val = MF_CFG_RD(bp,
10846 func_mf_config[other_func].e1hov_tag);
10847 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10848 bp->path_has_ovlan = true;
10849 }
34f80b04 10850 }
a2fbb9ea 10851
f2e0899f
DK
10852 /* adjust igu_sb_cnt to MF for E1x */
10853 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
10854 bp->igu_sb_cnt /= E1HVN_MAX;
10855
619c5cb6
VZ
10856 /* port info */
10857 bnx2x_get_port_hwinfo(bp);
f2e0899f 10858
0793f83f
DK
10859 /* Get MAC addresses */
10860 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 10861
2ba45142 10862 bnx2x_get_cnic_info(bp);
2ba45142 10863
34f80b04
EG
10864 return rc;
10865}
10866
34f24c7f
VZ
10867static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10868{
10869 int cnt, i, block_end, rodi;
fcdf95cb 10870 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
10871 char str_id_reg[VENDOR_ID_LEN+1];
10872 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
10873 char *vpd_data;
10874 char *vpd_extended_data = NULL;
34f24c7f
VZ
10875 u8 len;
10876
fcdf95cb 10877 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
10878 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10879
10880 if (cnt < BNX2X_VPD_LEN)
10881 goto out_not_found;
10882
fcdf95cb
BW
10883 /* VPD RO tag should be first tag after identifier string, hence
10884 * we should be able to find it in first BNX2X_VPD_LEN chars
10885 */
10886 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
10887 PCI_VPD_LRDT_RO_DATA);
10888 if (i < 0)
10889 goto out_not_found;
10890
34f24c7f 10891 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 10892 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
10893
10894 i += PCI_VPD_LRDT_TAG_SIZE;
10895
fcdf95cb
BW
10896 if (block_end > BNX2X_VPD_LEN) {
10897 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10898 if (vpd_extended_data == NULL)
10899 goto out_not_found;
10900
10901 /* read rest of vpd image into vpd_extended_data */
10902 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10903 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10904 block_end - BNX2X_VPD_LEN,
10905 vpd_extended_data + BNX2X_VPD_LEN);
10906 if (cnt < (block_end - BNX2X_VPD_LEN))
10907 goto out_not_found;
10908 vpd_data = vpd_extended_data;
10909 } else
10910 vpd_data = vpd_start;
10911
10912 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
10913
10914 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10915 PCI_VPD_RO_KEYWORD_MFR_ID);
10916 if (rodi < 0)
10917 goto out_not_found;
10918
10919 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10920
10921 if (len != VENDOR_ID_LEN)
10922 goto out_not_found;
10923
10924 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10925
10926 /* vendor specific info */
10927 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10928 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10929 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10930 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10931
10932 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10933 PCI_VPD_RO_KEYWORD_VENDOR0);
10934 if (rodi >= 0) {
10935 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10936
10937 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10938
10939 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10940 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10941 bp->fw_ver[len] = ' ';
10942 }
10943 }
fcdf95cb 10944 kfree(vpd_extended_data);
34f24c7f
VZ
10945 return;
10946 }
10947out_not_found:
fcdf95cb 10948 kfree(vpd_extended_data);
34f24c7f
VZ
10949 return;
10950}
10951
619c5cb6
VZ
10952static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10953{
10954 u32 flags = 0;
10955
10956 if (CHIP_REV_IS_FPGA(bp))
10957 SET_FLAGS(flags, MODE_FPGA);
10958 else if (CHIP_REV_IS_EMUL(bp))
10959 SET_FLAGS(flags, MODE_EMUL);
10960 else
10961 SET_FLAGS(flags, MODE_ASIC);
10962
10963 if (CHIP_MODE_IS_4_PORT(bp))
10964 SET_FLAGS(flags, MODE_PORT4);
10965 else
10966 SET_FLAGS(flags, MODE_PORT2);
10967
10968 if (CHIP_IS_E2(bp))
10969 SET_FLAGS(flags, MODE_E2);
10970 else if (CHIP_IS_E3(bp)) {
10971 SET_FLAGS(flags, MODE_E3);
10972 if (CHIP_REV(bp) == CHIP_REV_Ax)
10973 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
10974 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
10975 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
10976 }
10977
10978 if (IS_MF(bp)) {
10979 SET_FLAGS(flags, MODE_MF);
10980 switch (bp->mf_mode) {
10981 case MULTI_FUNCTION_SD:
10982 SET_FLAGS(flags, MODE_MF_SD);
10983 break;
10984 case MULTI_FUNCTION_SI:
10985 SET_FLAGS(flags, MODE_MF_SI);
10986 break;
a3348722
BW
10987 case MULTI_FUNCTION_AFEX:
10988 SET_FLAGS(flags, MODE_MF_AFEX);
10989 break;
619c5cb6
VZ
10990 }
10991 } else
10992 SET_FLAGS(flags, MODE_SF);
10993
10994#if defined(__LITTLE_ENDIAN)
10995 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
10996#else /*(__BIG_ENDIAN)*/
10997 SET_FLAGS(flags, MODE_BIG_ENDIAN);
10998#endif
10999 INIT_MODE_FLAGS(bp) = flags;
11000}
11001
34f80b04
EG
11002static int __devinit bnx2x_init_bp(struct bnx2x *bp)
11003{
f2e0899f 11004 int func;
34f80b04
EG
11005 int rc;
11006
34f80b04 11007 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11008 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11009 spin_lock_init(&bp->stats_lock);
55c11941 11010
a2fbb9ea 11011
1cf167f2 11012 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11013 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11014 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
34f80b04 11015 rc = bnx2x_get_hwinfo(bp);
619c5cb6
VZ
11016 if (rc)
11017 return rc;
34f80b04 11018
619c5cb6
VZ
11019 bnx2x_set_modes_bitmap(bp);
11020
11021 rc = bnx2x_alloc_mem_bp(bp);
11022 if (rc)
11023 return rc;
523224a3 11024
34f24c7f 11025 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11026
11027 func = BP_FUNC(bp);
11028
34f80b04 11029 /* need to reset chip if undi was active */
452427b0
YM
11030 if (!BP_NOMCP(bp)) {
11031 /* init fw_seq */
11032 bp->fw_seq =
11033 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11034 DRV_MSG_SEQ_NUMBER_MASK;
11035 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11036
11037 bnx2x_prev_unload(bp);
11038 }
11039
34f80b04
EG
11040
11041 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11042 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11043
11044 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11045 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11046
614c76df 11047 bp->disable_tpa = disable_tpa;
a3348722 11048 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11049
7a9b2557 11050 /* Set TPA flags */
614c76df 11051 if (bp->disable_tpa) {
621b4d66 11052 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11053 bp->dev->features &= ~NETIF_F_LRO;
11054 } else {
621b4d66 11055 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11056 bp->dev->features |= NETIF_F_LRO;
11057 }
11058
a18f5128
EG
11059 if (CHIP_IS_E1(bp))
11060 bp->dropless_fc = 0;
11061 else
11062 bp->dropless_fc = dropless_fc;
11063
8d5726c4 11064 bp->mrrs = mrrs;
7a9b2557 11065
a3348722 11066 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
34f80b04 11067
7d323bfd 11068 /* make sure that the numbers are in the right granularity */
523224a3
DK
11069 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11070 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11071
fc543637 11072 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11073
11074 init_timer(&bp->timer);
11075 bp->timer.expires = jiffies + bp->current_interval;
11076 bp->timer.data = (unsigned long) bp;
11077 bp->timer.function = bnx2x_timer;
11078
785b9b1a 11079 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
e4901dde
VZ
11080 bnx2x_dcbx_init_params(bp);
11081
619c5cb6
VZ
11082 if (CHIP_IS_E1x(bp))
11083 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11084 else
11085 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11086
6383c0b3
AE
11087 /* multiple tx priority */
11088 if (CHIP_IS_E1x(bp))
11089 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
11090 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
11091 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
11092 if (CHIP_IS_E3B0(bp))
11093 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
11094
55c11941
MS
11095 /* We need at least one default status block for slow-path events,
11096 * second status block for the L2 queue, and a third status block for
11097 * CNIC if supproted.
11098 */
11099 if (CNIC_SUPPORT(bp))
11100 bp->min_msix_vec_cnt = 3;
11101 else
11102 bp->min_msix_vec_cnt = 2;
11103 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11104
34f80b04 11105 return rc;
a2fbb9ea
ET
11106}
11107
a2fbb9ea 11108
de0c62db
DK
11109/****************************************************************************
11110* General service functions
11111****************************************************************************/
a2fbb9ea 11112
619c5cb6
VZ
11113/*
11114 * net_device service functions
11115 */
11116
bb2a0f7a 11117/* called with rtnl_lock */
a2fbb9ea
ET
11118static int bnx2x_open(struct net_device *dev)
11119{
11120 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11121 bool global = false;
11122 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11123 bool other_load_status, load_status;
a2fbb9ea 11124
1355b704
MY
11125 bp->stats_init = true;
11126
6eccabb3
EG
11127 netif_carrier_off(dev);
11128
a2fbb9ea
ET
11129 bnx2x_set_power_state(bp, PCI_D0);
11130
889b9af3
AE
11131 other_load_status = bnx2x_get_load_status(bp, other_engine);
11132 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
11133
11134 /*
11135 * If parity had happen during the unload, then attentions
11136 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11137 * want the first function loaded on the current engine to
11138 * complete the recovery.
11139 */
11140 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11141 bnx2x_chk_parity_attn(bp, &global, true))
72fd0718 11142 do {
c9ee9206
VZ
11143 /*
11144 * If there are attentions and they are in a global
11145 * blocks, set the GLOBAL_RESET bit regardless whether
11146 * it will be this function that will complete the
11147 * recovery or not.
72fd0718 11148 */
c9ee9206
VZ
11149 if (global)
11150 bnx2x_set_reset_global(bp);
72fd0718 11151
c9ee9206
VZ
11152 /*
11153 * Only the first function on the current engine should
11154 * try to recover in open. In case of attentions in
11155 * global blocks only the first in the chip should try
11156 * to recover.
72fd0718 11157 */
889b9af3
AE
11158 if ((!load_status &&
11159 (!global || !other_load_status)) &&
c9ee9206
VZ
11160 bnx2x_trylock_leader_lock(bp) &&
11161 !bnx2x_leader_reset(bp)) {
11162 netdev_info(bp->dev, "Recovered in open\n");
72fd0718
VZ
11163 break;
11164 }
11165
c9ee9206 11166 /* recovery has failed... */
72fd0718 11167 bnx2x_set_power_state(bp, PCI_D3hot);
c9ee9206 11168 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11169
51c1a580
MS
11170 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11171 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718
VZ
11172
11173 return -EAGAIN;
11174 } while (0);
72fd0718
VZ
11175
11176 bp->recovery_state = BNX2X_RECOVERY_DONE;
bb2a0f7a 11177 return bnx2x_nic_load(bp, LOAD_OPEN);
a2fbb9ea
ET
11178}
11179
bb2a0f7a 11180/* called with rtnl_lock */
56ad3152 11181static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11182{
a2fbb9ea
ET
11183 struct bnx2x *bp = netdev_priv(dev);
11184
11185 /* Unload the driver, release IRQs */
5d07d868 11186 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206
VZ
11187
11188 /* Power off */
d3dbfee0 11189 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
11190
11191 return 0;
11192}
11193
1191cb83
ED
11194static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11195 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11196{
619c5cb6
VZ
11197 int mc_count = netdev_mc_count(bp->dev);
11198 struct bnx2x_mcast_list_elem *mc_mac =
11199 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11200 struct netdev_hw_addr *ha;
6e30dd4e 11201
619c5cb6
VZ
11202 if (!mc_mac)
11203 return -ENOMEM;
6e30dd4e 11204
619c5cb6 11205 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11206
619c5cb6
VZ
11207 netdev_for_each_mc_addr(ha, bp->dev) {
11208 mc_mac->mac = bnx2x_mc_addr(ha);
11209 list_add_tail(&mc_mac->link, &p->mcast_list);
11210 mc_mac++;
6e30dd4e 11211 }
619c5cb6
VZ
11212
11213 p->mcast_list_len = mc_count;
11214
11215 return 0;
6e30dd4e
VZ
11216}
11217
1191cb83 11218static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11219 struct bnx2x_mcast_ramrod_params *p)
11220{
11221 struct bnx2x_mcast_list_elem *mc_mac =
11222 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11223 link);
11224
11225 WARN_ON(!mc_mac);
11226 kfree(mc_mac);
11227}
11228
11229/**
11230 * bnx2x_set_uc_list - configure a new unicast MACs list.
11231 *
11232 * @bp: driver handle
6e30dd4e 11233 *
619c5cb6 11234 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11235 */
1191cb83 11236static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11237{
619c5cb6 11238 int rc;
6e30dd4e 11239 struct net_device *dev = bp->dev;
6e30dd4e 11240 struct netdev_hw_addr *ha;
15192a8c 11241 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11242 unsigned long ramrod_flags = 0;
6e30dd4e 11243
619c5cb6
VZ
11244 /* First schedule a cleanup up of old configuration */
11245 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11246 if (rc < 0) {
11247 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11248 return rc;
11249 }
6e30dd4e
VZ
11250
11251 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11252 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11253 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11254 if (rc == -EEXIST) {
11255 DP(BNX2X_MSG_SP,
11256 "Failed to schedule ADD operations: %d\n", rc);
11257 /* do not treat adding same MAC as error */
11258 rc = 0;
11259
11260 } else if (rc < 0) {
11261
619c5cb6
VZ
11262 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11263 rc);
11264 return rc;
6e30dd4e
VZ
11265 }
11266 }
11267
619c5cb6
VZ
11268 /* Execute the pending commands */
11269 __set_bit(RAMROD_CONT, &ramrod_flags);
11270 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11271 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11272}
11273
1191cb83 11274static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11275{
619c5cb6 11276 struct net_device *dev = bp->dev;
3b603066 11277 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11278 int rc = 0;
6e30dd4e 11279
619c5cb6 11280 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11281
619c5cb6
VZ
11282 /* first, clear all configured multicast MACs */
11283 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11284 if (rc < 0) {
51c1a580 11285 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11286 return rc;
11287 }
6e30dd4e 11288
619c5cb6
VZ
11289 /* then, configure a new MACs list */
11290 if (netdev_mc_count(dev)) {
11291 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11292 if (rc) {
51c1a580
MS
11293 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11294 rc);
619c5cb6
VZ
11295 return rc;
11296 }
6e30dd4e 11297
619c5cb6
VZ
11298 /* Now add the new MACs */
11299 rc = bnx2x_config_mcast(bp, &rparam,
11300 BNX2X_MCAST_CMD_ADD);
11301 if (rc < 0)
51c1a580
MS
11302 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11303 rc);
6e30dd4e 11304
619c5cb6
VZ
11305 bnx2x_free_mcast_macs_list(&rparam);
11306 }
6e30dd4e 11307
619c5cb6 11308 return rc;
6e30dd4e
VZ
11309}
11310
6e30dd4e 11311
619c5cb6 11312/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11313void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11314{
11315 struct bnx2x *bp = netdev_priv(dev);
11316 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11317
11318 if (bp->state != BNX2X_STATE_OPEN) {
11319 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11320 return;
11321 }
11322
619c5cb6 11323 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11324
11325 if (dev->flags & IFF_PROMISC)
11326 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11327 else if ((dev->flags & IFF_ALLMULTI) ||
11328 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11329 CHIP_IS_E1(bp)))
34f80b04 11330 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e
VZ
11331 else {
11332 /* some multicasts */
619c5cb6 11333 if (bnx2x_set_mc_list(bp) < 0)
6e30dd4e 11334 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11335
619c5cb6 11336 if (bnx2x_set_uc_list(bp) < 0)
6e30dd4e 11337 rx_mode = BNX2X_RX_MODE_PROMISC;
34f80b04
EG
11338 }
11339
11340 bp->rx_mode = rx_mode;
614c76df
DK
11341 /* handle ISCSI SD mode */
11342 if (IS_MF_ISCSI_SD(bp))
11343 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11344
11345 /* Schedule the rx_mode command */
11346 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11347 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11348 return;
11349 }
11350
34f80b04
EG
11351 bnx2x_set_storm_rx_mode(bp);
11352}
11353
c18487ee 11354/* called with rtnl_lock */
01cd4528
EG
11355static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11356 int devad, u16 addr)
a2fbb9ea 11357{
01cd4528
EG
11358 struct bnx2x *bp = netdev_priv(netdev);
11359 u16 value;
11360 int rc;
a2fbb9ea 11361
01cd4528
EG
11362 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11363 prtad, devad, addr);
a2fbb9ea 11364
01cd4528
EG
11365 /* The HW expects different devad if CL22 is used */
11366 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11367
01cd4528 11368 bnx2x_acquire_phy_lock(bp);
e10bc84d 11369 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11370 bnx2x_release_phy_lock(bp);
11371 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11372
01cd4528
EG
11373 if (!rc)
11374 rc = value;
11375 return rc;
11376}
a2fbb9ea 11377
01cd4528
EG
11378/* called with rtnl_lock */
11379static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11380 u16 addr, u16 value)
11381{
11382 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11383 int rc;
11384
51c1a580
MS
11385 DP(NETIF_MSG_LINK,
11386 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11387 prtad, devad, addr, value);
01cd4528 11388
01cd4528
EG
11389 /* The HW expects different devad if CL22 is used */
11390 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11391
01cd4528 11392 bnx2x_acquire_phy_lock(bp);
e10bc84d 11393 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11394 bnx2x_release_phy_lock(bp);
11395 return rc;
11396}
c18487ee 11397
01cd4528
EG
11398/* called with rtnl_lock */
11399static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11400{
11401 struct bnx2x *bp = netdev_priv(dev);
11402 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11403
01cd4528
EG
11404 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11405 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11406
01cd4528
EG
11407 if (!netif_running(dev))
11408 return -EAGAIN;
11409
11410 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11411}
11412
257ddbda 11413#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11414static void poll_bnx2x(struct net_device *dev)
11415{
11416 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11417 int i;
a2fbb9ea 11418
14a15d61
MS
11419 for_each_eth_queue(bp, i) {
11420 struct bnx2x_fastpath *fp = &bp->fp[i];
11421 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11422 }
a2fbb9ea
ET
11423}
11424#endif
11425
614c76df
DK
11426static int bnx2x_validate_addr(struct net_device *dev)
11427{
11428 struct bnx2x *bp = netdev_priv(dev);
11429
51c1a580
MS
11430 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11431 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11432 return -EADDRNOTAVAIL;
51c1a580 11433 }
614c76df
DK
11434 return 0;
11435}
11436
c64213cd
SH
11437static const struct net_device_ops bnx2x_netdev_ops = {
11438 .ndo_open = bnx2x_open,
11439 .ndo_stop = bnx2x_close,
11440 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11441 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11442 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11443 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11444 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11445 .ndo_do_ioctl = bnx2x_ioctl,
11446 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11447 .ndo_fix_features = bnx2x_fix_features,
11448 .ndo_set_features = bnx2x_set_features,
c64213cd 11449 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11450#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11451 .ndo_poll_controller = poll_bnx2x,
11452#endif
6383c0b3
AE
11453 .ndo_setup_tc = bnx2x_setup_tc,
11454
55c11941 11455#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11456 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11457#endif
c64213cd
SH
11458};
11459
1191cb83 11460static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11461{
11462 struct device *dev = &bp->pdev->dev;
11463
11464 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11465 bp->flags |= USING_DAC_FLAG;
11466 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11467 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11468 return -EIO;
11469 }
11470 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11471 dev_err(dev, "System does not support DMA, aborting\n");
11472 return -EIO;
11473 }
11474
11475 return 0;
11476}
11477
34f80b04 11478static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
619c5cb6
VZ
11479 struct net_device *dev,
11480 unsigned long board_type)
a2fbb9ea
ET
11481{
11482 struct bnx2x *bp;
11483 int rc;
c22610d0 11484 u32 pci_cfg_dword;
65087cfe
AE
11485 bool chip_is_e1x = (board_type == BCM57710 ||
11486 board_type == BCM57711 ||
11487 board_type == BCM57711E);
a2fbb9ea
ET
11488
11489 SET_NETDEV_DEV(dev, &pdev->dev);
11490 bp = netdev_priv(dev);
11491
34f80b04
EG
11492 bp->dev = dev;
11493 bp->pdev = pdev;
a2fbb9ea 11494 bp->flags = 0;
a2fbb9ea
ET
11495
11496 rc = pci_enable_device(pdev);
11497 if (rc) {
cdaa7cb8
VZ
11498 dev_err(&bp->pdev->dev,
11499 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11500 goto err_out;
11501 }
11502
11503 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11504 dev_err(&bp->pdev->dev,
11505 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11506 rc = -ENODEV;
11507 goto err_out_disable;
11508 }
11509
11510 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11511 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
11512 " base address, aborting\n");
a2fbb9ea
ET
11513 rc = -ENODEV;
11514 goto err_out_disable;
11515 }
11516
34f80b04
EG
11517 if (atomic_read(&pdev->enable_cnt) == 1) {
11518 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11519 if (rc) {
cdaa7cb8
VZ
11520 dev_err(&bp->pdev->dev,
11521 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11522 goto err_out_disable;
11523 }
a2fbb9ea 11524
34f80b04
EG
11525 pci_set_master(pdev);
11526 pci_save_state(pdev);
11527 }
a2fbb9ea
ET
11528
11529 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11530 if (bp->pm_cap == 0) {
cdaa7cb8
VZ
11531 dev_err(&bp->pdev->dev,
11532 "Cannot find power management capability, aborting\n");
a2fbb9ea
ET
11533 rc = -EIO;
11534 goto err_out_release;
11535 }
11536
77c98e6a 11537 if (!pci_is_pcie(pdev)) {
51c1a580 11538 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11539 rc = -EIO;
11540 goto err_out_release;
11541 }
11542
619c5cb6
VZ
11543 rc = bnx2x_set_coherency_mask(bp);
11544 if (rc)
a2fbb9ea 11545 goto err_out_release;
a2fbb9ea 11546
34f80b04
EG
11547 dev->mem_start = pci_resource_start(pdev, 0);
11548 dev->base_addr = dev->mem_start;
11549 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11550
11551 dev->irq = pdev->irq;
11552
275f165f 11553 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11554 if (!bp->regview) {
cdaa7cb8
VZ
11555 dev_err(&bp->pdev->dev,
11556 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11557 rc = -ENOMEM;
11558 goto err_out_release;
11559 }
11560
c22610d0
AE
11561 /* In E1/E1H use pci device function given by kernel.
11562 * In E2/E3 read physical function from ME register since these chips
11563 * support Physical Device Assignment where kernel BDF maybe arbitrary
11564 * (depending on hypervisor).
11565 */
11566 if (chip_is_e1x)
11567 bp->pf_num = PCI_FUNC(pdev->devfn);
11568 else {/* chip is E2/3*/
11569 pci_read_config_dword(bp->pdev,
11570 PCICFG_ME_REGISTER, &pci_cfg_dword);
11571 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
11572 ME_REG_ABS_PF_NUM_SHIFT);
11573 }
51c1a580 11574 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 11575
a2fbb9ea
ET
11576 bnx2x_set_power_state(bp, PCI_D0);
11577
34f80b04
EG
11578 /* clean indirect addresses */
11579 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11580 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
11581 /*
11582 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
11583 * is not used by the driver.
11584 */
11585 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11586 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11587 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11588 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
a5c53dbc 11589
65087cfe 11590 if (chip_is_e1x) {
a5c53dbc
DK
11591 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11592 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11593 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11594 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11595 }
a2fbb9ea 11596
2189400b 11597 /*
619c5cb6 11598 * Enable internal target-read (in case we are probed after PF FLR).
2189400b 11599 * Must be done prior to any BAR read access. Only for 57712 and up
619c5cb6 11600 */
65087cfe 11601 if (!chip_is_e1x)
2189400b 11602 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
619c5cb6 11603
34f80b04 11604 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 11605
c64213cd 11606 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 11607 bnx2x_set_ethtool_ops(dev);
5316bc0b 11608
01789349
JP
11609 dev->priv_flags |= IFF_UNICAST_FLT;
11610
66371c44 11611 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
11612 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11613 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11614 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
11615
11616 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11617 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11618
11619 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 11620 if (bp->flags & USING_DAC_FLAG)
66371c44 11621 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 11622
538dd2e3
MB
11623 /* Add Loopback capability to the device */
11624 dev->hw_features |= NETIF_F_LOOPBACK;
11625
98507672 11626#ifdef BCM_DCBNL
785b9b1a
SR
11627 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11628#endif
11629
01cd4528
EG
11630 /* get_port_hwinfo() will set prtad and mmds properly */
11631 bp->mdio.prtad = MDIO_PRTAD_NONE;
11632 bp->mdio.mmds = 0;
11633 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11634 bp->mdio.dev = dev;
11635 bp->mdio.mdio_read = bnx2x_mdio_read;
11636 bp->mdio.mdio_write = bnx2x_mdio_write;
11637
a2fbb9ea
ET
11638 return 0;
11639
a2fbb9ea 11640err_out_release:
34f80b04
EG
11641 if (atomic_read(&pdev->enable_cnt) == 1)
11642 pci_release_regions(pdev);
a2fbb9ea
ET
11643
11644err_out_disable:
11645 pci_disable_device(pdev);
11646 pci_set_drvdata(pdev, NULL);
11647
11648err_out:
11649 return rc;
11650}
11651
37f9ce62
EG
11652static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
11653 int *width, int *speed)
25047950
ET
11654{
11655 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
11656
37f9ce62 11657 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 11658
37f9ce62
EG
11659 /* return value of 1=2.5GHz 2=5GHz */
11660 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 11661}
37f9ce62 11662
6891dd25 11663static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 11664{
37f9ce62 11665 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
11666 struct bnx2x_fw_file_hdr *fw_hdr;
11667 struct bnx2x_fw_file_section *sections;
94a78b79 11668 u32 offset, len, num_ops;
37f9ce62 11669 u16 *ops_offsets;
94a78b79 11670 int i;
37f9ce62 11671 const u8 *fw_ver;
94a78b79 11672
51c1a580
MS
11673 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
11674 BNX2X_ERR("Wrong FW size\n");
94a78b79 11675 return -EINVAL;
51c1a580 11676 }
94a78b79
VZ
11677
11678 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
11679 sections = (struct bnx2x_fw_file_section *)fw_hdr;
11680
11681 /* Make sure none of the offsets and sizes make us read beyond
11682 * the end of the firmware data */
11683 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
11684 offset = be32_to_cpu(sections[i].offset);
11685 len = be32_to_cpu(sections[i].len);
11686 if (offset + len > firmware->size) {
51c1a580 11687 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
11688 return -EINVAL;
11689 }
11690 }
11691
11692 /* Likewise for the init_ops offsets */
11693 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
11694 ops_offsets = (u16 *)(firmware->data + offset);
11695 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
11696
11697 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
11698 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 11699 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
11700 return -EINVAL;
11701 }
11702 }
11703
11704 /* Check FW version */
11705 offset = be32_to_cpu(fw_hdr->fw_version.offset);
11706 fw_ver = firmware->data + offset;
11707 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
11708 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
11709 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
11710 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
11711 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11712 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
11713 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
11714 BCM_5710_FW_MINOR_VERSION,
11715 BCM_5710_FW_REVISION_VERSION,
11716 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 11717 return -EINVAL;
94a78b79
VZ
11718 }
11719
11720 return 0;
11721}
11722
1191cb83 11723static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11724{
ab6ad5a4
EG
11725 const __be32 *source = (const __be32 *)_source;
11726 u32 *target = (u32 *)_target;
94a78b79 11727 u32 i;
94a78b79
VZ
11728
11729 for (i = 0; i < n/4; i++)
11730 target[i] = be32_to_cpu(source[i]);
11731}
11732
11733/*
11734 Ops array is stored in the following format:
11735 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11736 */
1191cb83 11737static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 11738{
ab6ad5a4
EG
11739 const __be32 *source = (const __be32 *)_source;
11740 struct raw_op *target = (struct raw_op *)_target;
94a78b79 11741 u32 i, j, tmp;
94a78b79 11742
ab6ad5a4 11743 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
11744 tmp = be32_to_cpu(source[j]);
11745 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
11746 target[i].offset = tmp & 0xffffff;
11747 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
11748 }
11749}
ab6ad5a4 11750
1aa8b471 11751/* IRO array is stored in the following format:
523224a3
DK
11752 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11753 */
1191cb83 11754static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
11755{
11756 const __be32 *source = (const __be32 *)_source;
11757 struct iro *target = (struct iro *)_target;
11758 u32 i, j, tmp;
11759
11760 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11761 target[i].base = be32_to_cpu(source[j]);
11762 j++;
11763 tmp = be32_to_cpu(source[j]);
11764 target[i].m1 = (tmp >> 16) & 0xffff;
11765 target[i].m2 = tmp & 0xffff;
11766 j++;
11767 tmp = be32_to_cpu(source[j]);
11768 target[i].m3 = (tmp >> 16) & 0xffff;
11769 target[i].size = tmp & 0xffff;
11770 j++;
11771 }
11772}
11773
1191cb83 11774static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11775{
ab6ad5a4
EG
11776 const __be16 *source = (const __be16 *)_source;
11777 u16 *target = (u16 *)_target;
94a78b79 11778 u32 i;
94a78b79
VZ
11779
11780 for (i = 0; i < n/2; i++)
11781 target[i] = be16_to_cpu(source[i]);
11782}
11783
7995c64e
JP
11784#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11785do { \
11786 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11787 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 11788 if (!bp->arr) \
7995c64e 11789 goto lbl; \
7995c64e
JP
11790 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11791 (u8 *)bp->arr, len); \
11792} while (0)
94a78b79 11793
3b603066 11794static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 11795{
c0ea452e 11796 const char *fw_file_name;
94a78b79 11797 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 11798 int rc;
94a78b79 11799
c0ea452e
MS
11800 if (bp->firmware)
11801 return 0;
94a78b79 11802
c0ea452e
MS
11803 if (CHIP_IS_E1(bp))
11804 fw_file_name = FW_FILE_NAME_E1;
11805 else if (CHIP_IS_E1H(bp))
11806 fw_file_name = FW_FILE_NAME_E1H;
11807 else if (!CHIP_IS_E1x(bp))
11808 fw_file_name = FW_FILE_NAME_E2;
11809 else {
11810 BNX2X_ERR("Unsupported chip revision\n");
11811 return -EINVAL;
11812 }
11813 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 11814
c0ea452e
MS
11815 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11816 if (rc) {
11817 BNX2X_ERR("Can't load firmware file %s\n",
11818 fw_file_name);
11819 goto request_firmware_exit;
11820 }
eb2afd4a 11821
c0ea452e
MS
11822 rc = bnx2x_check_firmware(bp);
11823 if (rc) {
11824 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11825 goto request_firmware_exit;
94a78b79
VZ
11826 }
11827
11828 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11829
11830 /* Initialize the pointers to the init arrays */
11831 /* Blob */
11832 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11833
11834 /* Opcodes */
11835 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11836
11837 /* Offsets */
ab6ad5a4
EG
11838 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11839 be16_to_cpu_n);
94a78b79
VZ
11840
11841 /* STORMs firmware */
573f2035
EG
11842 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11843 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11844 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11845 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11846 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11847 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11848 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11849 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11850 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11851 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11852 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11853 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11854 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11855 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11856 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11857 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
11858 /* IRO */
11859 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
11860
11861 return 0;
ab6ad5a4 11862
523224a3
DK
11863iro_alloc_err:
11864 kfree(bp->init_ops_offsets);
94a78b79
VZ
11865init_offsets_alloc_err:
11866 kfree(bp->init_ops);
11867init_ops_alloc_err:
11868 kfree(bp->init_data);
11869request_firmware_exit:
11870 release_firmware(bp->firmware);
127d0a19 11871 bp->firmware = NULL;
94a78b79
VZ
11872
11873 return rc;
11874}
11875
619c5cb6
VZ
11876static void bnx2x_release_firmware(struct bnx2x *bp)
11877{
11878 kfree(bp->init_ops_offsets);
11879 kfree(bp->init_ops);
11880 kfree(bp->init_data);
11881 release_firmware(bp->firmware);
eb2afd4a 11882 bp->firmware = NULL;
619c5cb6
VZ
11883}
11884
11885
11886static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11887 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11888 .init_hw_cmn = bnx2x_init_hw_common,
11889 .init_hw_port = bnx2x_init_hw_port,
11890 .init_hw_func = bnx2x_init_hw_func,
11891
11892 .reset_hw_cmn = bnx2x_reset_common,
11893 .reset_hw_port = bnx2x_reset_port,
11894 .reset_hw_func = bnx2x_reset_func,
11895
11896 .gunzip_init = bnx2x_gunzip_init,
11897 .gunzip_end = bnx2x_gunzip_end,
11898
11899 .init_fw = bnx2x_init_firmware,
11900 .release_fw = bnx2x_release_firmware,
11901};
11902
11903void bnx2x__init_func_obj(struct bnx2x *bp)
11904{
11905 /* Prepare DMAE related driver resources */
11906 bnx2x_setup_dmae(bp);
11907
11908 bnx2x_init_func_obj(bp, &bp->func_obj,
11909 bnx2x_sp(bp, func_rdata),
11910 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
11911 bnx2x_sp(bp, func_afex_rdata),
11912 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
11913 &bnx2x_func_sp_drv);
11914}
11915
11916/* must be called after sriov-enable */
1191cb83 11917static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 11918{
37ae41a9 11919 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 11920
55c11941
MS
11921 if (CNIC_SUPPORT(bp))
11922 cid_count += CNIC_CID_MAX;
523224a3
DK
11923 return roundup(cid_count, QM_CID_ROUND);
11924}
f85582f8 11925
619c5cb6 11926/**
6383c0b3 11927 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
11928 *
11929 * @dev: pci device
11930 *
11931 */
55c11941
MS
11932static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
11933 int cnic_cnt)
619c5cb6
VZ
11934{
11935 int pos;
11936 u16 control;
11937
11938 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
11939
11940 /*
11941 * If MSI-X is not supported - return number of SBs needed to support
11942 * one fast path queue: one FP queue + SB for CNIC
11943 */
619c5cb6 11944 if (!pos)
55c11941 11945 return 1 + cnic_cnt;
619c5cb6 11946
6383c0b3
AE
11947 /*
11948 * The value in the PCI configuration space is the index of the last
11949 * entry, namely one less than the actual size of the table, which is
11950 * exactly what we want to return from this function: number of all SBs
11951 * without the default SB.
11952 */
619c5cb6 11953 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
6383c0b3 11954 return control & PCI_MSIX_FLAGS_QSIZE;
619c5cb6
VZ
11955}
11956
a2fbb9ea
ET
11957static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11958 const struct pci_device_id *ent)
11959{
a2fbb9ea
ET
11960 struct net_device *dev = NULL;
11961 struct bnx2x *bp;
37f9ce62 11962 int pcie_width, pcie_speed;
6383c0b3 11963 int rc, max_non_def_sbs;
65565884 11964 int rx_count, tx_count, rss_count, doorbell_size;
55c11941 11965 int cnic_cnt;
6383c0b3
AE
11966 /*
11967 * An estimated maximum supported CoS number according to the chip
11968 * version.
11969 * We will try to roughly estimate the maximum number of CoSes this chip
11970 * may support in order to minimize the memory allocated for Tx
11971 * netdev_queue's. This number will be accurately calculated during the
11972 * initialization of bp->max_cos based on the chip versions AND chip
11973 * revision in the bnx2x_init_bp().
11974 */
11975 u8 max_cos_est = 0;
523224a3 11976
f2e0899f
DK
11977 switch (ent->driver_data) {
11978 case BCM57710:
11979 case BCM57711:
11980 case BCM57711E:
6383c0b3
AE
11981 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
11982 break;
11983
f2e0899f 11984 case BCM57712:
619c5cb6 11985 case BCM57712_MF:
6383c0b3
AE
11986 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
11987 break;
11988
619c5cb6
VZ
11989 case BCM57800:
11990 case BCM57800_MF:
11991 case BCM57810:
11992 case BCM57810_MF:
c3def943
YM
11993 case BCM57840_O:
11994 case BCM57840_4_10:
11995 case BCM57840_2_20:
11996 case BCM57840_MFO:
619c5cb6 11997 case BCM57840_MF:
7e8e02df
BW
11998 case BCM57811:
11999 case BCM57811_MF:
6383c0b3 12000 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
f2e0899f 12001 break;
a2fbb9ea 12002
f2e0899f
DK
12003 default:
12004 pr_err("Unknown board_type (%ld), aborting\n",
12005 ent->driver_data);
870634b0 12006 return -ENODEV;
f2e0899f
DK
12007 }
12008
55c11941
MS
12009 cnic_cnt = 1;
12010 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
6383c0b3 12011
6383c0b3
AE
12012 WARN_ON(!max_non_def_sbs);
12013
12014 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
55c11941 12015 rss_count = max_non_def_sbs - cnic_cnt;
6383c0b3
AE
12016
12017 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12018 rx_count = rss_count + cnic_cnt;
6383c0b3
AE
12019
12020 /*
12021 * Maximum number of netdev Tx queues:
37ae41a9 12022 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12023 */
55c11941 12024 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12025
a2fbb9ea 12026 /* dev zeroed in init_etherdev */
6383c0b3 12027 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12028 if (!dev)
a2fbb9ea
ET
12029 return -ENOMEM;
12030
a2fbb9ea 12031 bp = netdev_priv(dev);
a2fbb9ea 12032
6383c0b3
AE
12033 bp->igu_sb_cnt = max_non_def_sbs;
12034 bp->msg_enable = debug;
55c11941
MS
12035 bp->cnic_support = cnic_cnt;
12036
6383c0b3 12037 pci_set_drvdata(pdev, dev);
523224a3 12038
619c5cb6 12039 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
a2fbb9ea
ET
12040 if (rc < 0) {
12041 free_netdev(dev);
12042 return rc;
12043 }
12044
55c11941 12045 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
51c1a580 12046 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
619c5cb6 12047
60aa0509
MS
12048 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
12049 tx_count, rx_count);
12050
34f80b04 12051 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12052 if (rc)
12053 goto init_one_exit;
12054
6383c0b3
AE
12055 /*
12056 * Map doorbels here as we need the real value of bp->max_cos which
12057 * is initialized in bnx2x_init_bp().
12058 */
37ae41a9
MS
12059 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12060 if (doorbell_size > pci_resource_len(pdev, 2)) {
12061 dev_err(&bp->pdev->dev,
12062 "Cannot map doorbells, bar size too small, aborting\n");
12063 rc = -ENOMEM;
12064 goto init_one_exit;
12065 }
6383c0b3 12066 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
37ae41a9 12067 doorbell_size);
6383c0b3
AE
12068 if (!bp->doorbells) {
12069 dev_err(&bp->pdev->dev,
12070 "Cannot map doorbell space, aborting\n");
12071 rc = -ENOMEM;
12072 goto init_one_exit;
12073 }
12074
523224a3 12075 /* calc qm_cid_count */
6383c0b3 12076 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
523224a3 12077
55c11941 12078 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12079 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12080 bp->flags |= NO_FCOE_FLAG;
12081
477864dd
DK
12082 /* disable FCOE for 57840 device, until FW supports it */
12083 switch (ent->driver_data) {
12084 case BCM57840_O:
12085 case BCM57840_4_10:
12086 case BCM57840_2_20:
12087 case BCM57840_MFO:
12088 case BCM57840_MF:
12089 bp->flags |= NO_FCOE_FLAG;
12090 }
0e8d2ec5
MS
12091
12092 /* Set bp->num_queues for MSI-X mode*/
12093 bnx2x_set_num_queues(bp);
12094
25985edc 12095 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12096 * needed.
d6214d7a
DK
12097 */
12098 bnx2x_set_int_mode(bp);
12099
b340007f
VZ
12100 rc = register_netdev(dev);
12101 if (rc) {
12102 dev_err(&pdev->dev, "Cannot register net device\n");
12103 goto init_one_exit;
12104 }
12105
55c11941 12106
ec6ba945
VZ
12107 if (!NO_FCOE(bp)) {
12108 /* Add storage MAC address */
12109 rtnl_lock();
12110 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12111 rtnl_unlock();
12112 }
ec6ba945 12113
37f9ce62 12114 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
d6214d7a 12115
51c1a580
MS
12116 BNX2X_DEV_INFO(
12117 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
12118 board_info[ent->driver_data].name,
12119 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12120 pcie_width,
12121 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
12122 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
12123 "5GHz (Gen2)" : "2.5GHz",
12124 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12125
a2fbb9ea 12126 return 0;
34f80b04
EG
12127
12128init_one_exit:
12129 if (bp->regview)
12130 iounmap(bp->regview);
12131
12132 if (bp->doorbells)
12133 iounmap(bp->doorbells);
12134
12135 free_netdev(dev);
12136
12137 if (atomic_read(&pdev->enable_cnt) == 1)
12138 pci_release_regions(pdev);
12139
12140 pci_disable_device(pdev);
12141 pci_set_drvdata(pdev, NULL);
12142
12143 return rc;
a2fbb9ea
ET
12144}
12145
12146static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
12147{
12148 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
12149 struct bnx2x *bp;
12150
12151 if (!dev) {
cdaa7cb8 12152 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
12153 return;
12154 }
228241eb 12155 bp = netdev_priv(dev);
a2fbb9ea 12156
ec6ba945
VZ
12157 /* Delete storage MAC address */
12158 if (!NO_FCOE(bp)) {
12159 rtnl_lock();
12160 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12161 rtnl_unlock();
12162 }
ec6ba945 12163
98507672
SR
12164#ifdef BCM_DCBNL
12165 /* Delete app tlvs from dcbnl */
12166 bnx2x_dcbnl_update_applist(bp, true);
12167#endif
12168
a2fbb9ea
ET
12169 unregister_netdev(dev);
12170
084d6cbb
VZ
12171 /* Power on: we can't let PCI layer write to us while we are in D3 */
12172 bnx2x_set_power_state(bp, PCI_D0);
12173
d6214d7a
DK
12174 /* Disable MSI/MSI-X */
12175 bnx2x_disable_msi(bp);
f85582f8 12176
084d6cbb
VZ
12177 /* Power off */
12178 bnx2x_set_power_state(bp, PCI_D3hot);
12179
72fd0718 12180 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12181 cancel_delayed_work_sync(&bp->sp_rtnl_task);
72fd0718 12182
a2fbb9ea
ET
12183 if (bp->regview)
12184 iounmap(bp->regview);
12185
12186 if (bp->doorbells)
12187 iounmap(bp->doorbells);
12188
eb2afd4a
DK
12189 bnx2x_release_firmware(bp);
12190
523224a3
DK
12191 bnx2x_free_mem_bp(bp);
12192
a2fbb9ea 12193 free_netdev(dev);
34f80b04
EG
12194
12195 if (atomic_read(&pdev->enable_cnt) == 1)
12196 pci_release_regions(pdev);
12197
a2fbb9ea
ET
12198 pci_disable_device(pdev);
12199 pci_set_drvdata(pdev, NULL);
12200}
12201
f8ef6e44
YG
12202static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12203{
12204 int i;
12205
12206 bp->state = BNX2X_STATE_ERROR;
12207
12208 bp->rx_mode = BNX2X_RX_MODE_NONE;
12209
55c11941
MS
12210 if (CNIC_LOADED(bp))
12211 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12212
619c5cb6
VZ
12213 /* Stop Tx */
12214 bnx2x_tx_disable(bp);
12215
f8ef6e44 12216 bnx2x_netif_stop(bp, 0);
26614ba5
MS
12217 /* Delete all NAPI objects */
12218 bnx2x_del_all_napi(bp);
55c11941
MS
12219 if (CNIC_LOADED(bp))
12220 bnx2x_del_all_napi_cnic(bp);
f8ef6e44
YG
12221
12222 del_timer_sync(&bp->timer);
619c5cb6
VZ
12223
12224 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
12225
12226 /* Release IRQs */
d6214d7a 12227 bnx2x_free_irq(bp);
f8ef6e44 12228
f8ef6e44
YG
12229 /* Free SKBs, SGEs, TPA pool and driver internals */
12230 bnx2x_free_skbs(bp);
523224a3 12231
ec6ba945 12232 for_each_rx_queue(bp, i)
f8ef6e44 12233 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 12234
f8ef6e44
YG
12235 bnx2x_free_mem(bp);
12236
12237 bp->state = BNX2X_STATE_CLOSED;
12238
619c5cb6
VZ
12239 netif_carrier_off(bp->dev);
12240
f8ef6e44
YG
12241 return 0;
12242}
12243
12244static void bnx2x_eeh_recover(struct bnx2x *bp)
12245{
12246 u32 val;
12247
12248 mutex_init(&bp->port.phy_mutex);
12249
f8ef6e44
YG
12250
12251 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12252 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12253 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12254 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
12255}
12256
493adb1f
WX
12257/**
12258 * bnx2x_io_error_detected - called when PCI error is detected
12259 * @pdev: Pointer to PCI device
12260 * @state: The current pci connection state
12261 *
12262 * This function is called after a PCI bus error affecting
12263 * this device has been detected.
12264 */
12265static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12266 pci_channel_state_t state)
12267{
12268 struct net_device *dev = pci_get_drvdata(pdev);
12269 struct bnx2x *bp = netdev_priv(dev);
12270
12271 rtnl_lock();
12272
12273 netif_device_detach(dev);
12274
07ce50e4
DN
12275 if (state == pci_channel_io_perm_failure) {
12276 rtnl_unlock();
12277 return PCI_ERS_RESULT_DISCONNECT;
12278 }
12279
493adb1f 12280 if (netif_running(dev))
f8ef6e44 12281 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
12282
12283 pci_disable_device(pdev);
12284
12285 rtnl_unlock();
12286
12287 /* Request a slot reset */
12288 return PCI_ERS_RESULT_NEED_RESET;
12289}
12290
12291/**
12292 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12293 * @pdev: Pointer to PCI device
12294 *
12295 * Restart the card from scratch, as if from a cold-boot.
12296 */
12297static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12298{
12299 struct net_device *dev = pci_get_drvdata(pdev);
12300 struct bnx2x *bp = netdev_priv(dev);
12301
12302 rtnl_lock();
12303
12304 if (pci_enable_device(pdev)) {
12305 dev_err(&pdev->dev,
12306 "Cannot re-enable PCI device after reset\n");
12307 rtnl_unlock();
12308 return PCI_ERS_RESULT_DISCONNECT;
12309 }
12310
12311 pci_set_master(pdev);
12312 pci_restore_state(pdev);
12313
12314 if (netif_running(dev))
12315 bnx2x_set_power_state(bp, PCI_D0);
12316
12317 rtnl_unlock();
12318
12319 return PCI_ERS_RESULT_RECOVERED;
12320}
12321
12322/**
12323 * bnx2x_io_resume - called when traffic can start flowing again
12324 * @pdev: Pointer to PCI device
12325 *
12326 * This callback is called when the error recovery driver tells us that
12327 * its OK to resume normal operation.
12328 */
12329static void bnx2x_io_resume(struct pci_dev *pdev)
12330{
12331 struct net_device *dev = pci_get_drvdata(pdev);
12332 struct bnx2x *bp = netdev_priv(dev);
12333
72fd0718 12334 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12335 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12336 return;
12337 }
12338
493adb1f
WX
12339 rtnl_lock();
12340
f8ef6e44
YG
12341 bnx2x_eeh_recover(bp);
12342
493adb1f 12343 if (netif_running(dev))
f8ef6e44 12344 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12345
12346 netif_device_attach(dev);
12347
12348 rtnl_unlock();
12349}
12350
3646f0e5 12351static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12352 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12353 .slot_reset = bnx2x_io_slot_reset,
12354 .resume = bnx2x_io_resume,
493adb1f
WX
12355};
12356
a2fbb9ea 12357static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12358 .name = DRV_MODULE_NAME,
12359 .id_table = bnx2x_pci_tbl,
12360 .probe = bnx2x_init_one,
12361 .remove = __devexit_p(bnx2x_remove_one),
12362 .suspend = bnx2x_suspend,
12363 .resume = bnx2x_resume,
12364 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
12365};
12366
12367static int __init bnx2x_init(void)
12368{
dd21ca6d
SG
12369 int ret;
12370
7995c64e 12371 pr_info("%s", version);
938cf541 12372
1cf167f2
EG
12373 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12374 if (bnx2x_wq == NULL) {
7995c64e 12375 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12376 return -ENOMEM;
12377 }
12378
dd21ca6d
SG
12379 ret = pci_register_driver(&bnx2x_pci_driver);
12380 if (ret) {
7995c64e 12381 pr_err("Cannot register driver\n");
dd21ca6d
SG
12382 destroy_workqueue(bnx2x_wq);
12383 }
12384 return ret;
a2fbb9ea
ET
12385}
12386
12387static void __exit bnx2x_cleanup(void)
12388{
452427b0 12389 struct list_head *pos, *q;
a2fbb9ea 12390 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12391
12392 destroy_workqueue(bnx2x_wq);
452427b0
YM
12393
12394 /* Free globablly allocated resources */
12395 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12396 struct bnx2x_prev_path_list *tmp =
12397 list_entry(pos, struct bnx2x_prev_path_list, list);
12398 list_del(pos);
12399 kfree(tmp);
12400 }
a2fbb9ea
ET
12401}
12402
3deb8167
YR
12403void bnx2x_notify_link_changed(struct bnx2x *bp)
12404{
12405 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12406}
12407
a2fbb9ea
ET
12408module_init(bnx2x_init);
12409module_exit(bnx2x_cleanup);
12410
619c5cb6
VZ
12411/**
12412 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12413 *
12414 * @bp: driver handle
12415 * @set: set or clear the CAM entry
12416 *
12417 * This function will wait until the ramdord completion returns.
12418 * Return 0 if success, -ENODEV if ramrod doesn't return.
12419 */
1191cb83 12420static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
12421{
12422 unsigned long ramrod_flags = 0;
12423
12424 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12425 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12426 &bp->iscsi_l2_mac_obj, true,
12427 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12428}
993ac7b5
MC
12429
12430/* count denotes the number of new completions we have seen */
12431static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12432{
12433 struct eth_spe *spe;
a052997e 12434 int cxt_index, cxt_offset;
993ac7b5
MC
12435
12436#ifdef BNX2X_STOP_ON_ERROR
12437 if (unlikely(bp->panic))
12438 return;
12439#endif
12440
12441 spin_lock_bh(&bp->spq_lock);
c2bff63f 12442 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
12443 bp->cnic_spq_pending -= count;
12444
993ac7b5 12445
c2bff63f
DK
12446 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12447 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12448 & SPE_HDR_CONN_TYPE) >>
12449 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
12450 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12451 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
12452
12453 /* Set validation for iSCSI L2 client before sending SETUP
12454 * ramrod
12455 */
12456 if (type == ETH_CONNECTION_TYPE) {
a052997e 12457 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 12458 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 12459 ILT_PAGE_CIDS;
37ae41a9 12460 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
12461 (cxt_index * ILT_PAGE_CIDS);
12462 bnx2x_set_ctx_validation(bp,
12463 &bp->context[cxt_index].
12464 vcxt[cxt_offset].eth,
37ae41a9 12465 BNX2X_ISCSI_ETH_CID(bp));
a052997e 12466 }
c2bff63f
DK
12467 }
12468
619c5cb6
VZ
12469 /*
12470 * There may be not more than 8 L2, not more than 8 L5 SPEs
12471 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
12472 * COMMON ramrods is not more than the EQ and SPQ can
12473 * accommodate.
c2bff63f 12474 */
6e30dd4e
VZ
12475 if (type == ETH_CONNECTION_TYPE) {
12476 if (!atomic_read(&bp->cq_spq_left))
12477 break;
12478 else
12479 atomic_dec(&bp->cq_spq_left);
12480 } else if (type == NONE_CONNECTION_TYPE) {
12481 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
12482 break;
12483 else
6e30dd4e 12484 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
12485 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12486 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
12487 if (bp->cnic_spq_pending >=
12488 bp->cnic_eth_dev.max_kwqe_pending)
12489 break;
12490 else
12491 bp->cnic_spq_pending++;
12492 } else {
12493 BNX2X_ERR("Unknown SPE type: %d\n", type);
12494 bnx2x_panic();
993ac7b5 12495 break;
c2bff63f 12496 }
993ac7b5
MC
12497
12498 spe = bnx2x_sp_get_next(bp);
12499 *spe = *bp->cnic_kwq_cons;
12500
51c1a580 12501 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
12502 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12503
12504 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12505 bp->cnic_kwq_cons = bp->cnic_kwq;
12506 else
12507 bp->cnic_kwq_cons++;
12508 }
12509 bnx2x_sp_prod_update(bp);
12510 spin_unlock_bh(&bp->spq_lock);
12511}
12512
12513static int bnx2x_cnic_sp_queue(struct net_device *dev,
12514 struct kwqe_16 *kwqes[], u32 count)
12515{
12516 struct bnx2x *bp = netdev_priv(dev);
12517 int i;
12518
12519#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
12520 if (unlikely(bp->panic)) {
12521 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 12522 return -EIO;
51c1a580 12523 }
993ac7b5
MC
12524#endif
12525
95c6c616
AE
12526 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12527 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 12528 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
12529 return -EAGAIN;
12530 }
12531
993ac7b5
MC
12532 spin_lock_bh(&bp->spq_lock);
12533
12534 for (i = 0; i < count; i++) {
12535 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12536
12537 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12538 break;
12539
12540 *bp->cnic_kwq_prod = *spe;
12541
12542 bp->cnic_kwq_pending++;
12543
51c1a580 12544 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 12545 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
12546 spe->data.update_data_addr.hi,
12547 spe->data.update_data_addr.lo,
993ac7b5
MC
12548 bp->cnic_kwq_pending);
12549
12550 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12551 bp->cnic_kwq_prod = bp->cnic_kwq;
12552 else
12553 bp->cnic_kwq_prod++;
12554 }
12555
12556 spin_unlock_bh(&bp->spq_lock);
12557
12558 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12559 bnx2x_cnic_sp_post(bp, 0);
12560
12561 return i;
12562}
12563
12564static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12565{
12566 struct cnic_ops *c_ops;
12567 int rc = 0;
12568
12569 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
12570 c_ops = rcu_dereference_protected(bp->cnic_ops,
12571 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
12572 if (c_ops)
12573 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12574 mutex_unlock(&bp->cnic_mutex);
12575
12576 return rc;
12577}
12578
12579static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12580{
12581 struct cnic_ops *c_ops;
12582 int rc = 0;
12583
12584 rcu_read_lock();
12585 c_ops = rcu_dereference(bp->cnic_ops);
12586 if (c_ops)
12587 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12588 rcu_read_unlock();
12589
12590 return rc;
12591}
12592
12593/*
12594 * for commands that have no data
12595 */
9f6c9258 12596int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
12597{
12598 struct cnic_ctl_info ctl = {0};
12599
12600 ctl.cmd = cmd;
12601
12602 return bnx2x_cnic_ctl_send(bp, &ctl);
12603}
12604
619c5cb6 12605static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 12606{
619c5cb6 12607 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
12608
12609 /* first we tell CNIC and only then we count this as a completion */
12610 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
12611 ctl.data.comp.cid = cid;
619c5cb6 12612 ctl.data.comp.error = err;
993ac7b5
MC
12613
12614 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 12615 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
12616}
12617
619c5cb6
VZ
12618
12619/* Called with netif_addr_lock_bh() taken.
12620 * Sets an rx_mode config for an iSCSI ETH client.
12621 * Doesn't block.
12622 * Completion should be checked outside.
12623 */
12624static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
12625{
12626 unsigned long accept_flags = 0, ramrod_flags = 0;
12627 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12628 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
12629
12630 if (start) {
12631 /* Start accepting on iSCSI L2 ring. Accept all multicasts
12632 * because it's the only way for UIO Queue to accept
12633 * multicasts (in non-promiscuous mode only one Queue per
12634 * function will receive multicast packets (leading in our
12635 * case).
12636 */
12637 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
12638 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
12639 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
12640 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
12641
12642 /* Clear STOP_PENDING bit if START is requested */
12643 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
12644
12645 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
12646 } else
12647 /* Clear START_PENDING bit if STOP is requested */
12648 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
12649
12650 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
12651 set_bit(sched_state, &bp->sp_state);
12652 else {
12653 __set_bit(RAMROD_RX, &ramrod_flags);
12654 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
12655 ramrod_flags);
12656 }
12657}
12658
12659
993ac7b5
MC
12660static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
12661{
12662 struct bnx2x *bp = netdev_priv(dev);
12663 int rc = 0;
12664
12665 switch (ctl->cmd) {
12666 case DRV_CTL_CTXTBL_WR_CMD: {
12667 u32 index = ctl->data.io.offset;
12668 dma_addr_t addr = ctl->data.io.dma_addr;
12669
12670 bnx2x_ilt_wr(bp, index, addr);
12671 break;
12672 }
12673
c2bff63f
DK
12674 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
12675 int count = ctl->data.credit.credit_count;
993ac7b5
MC
12676
12677 bnx2x_cnic_sp_post(bp, count);
12678 break;
12679 }
12680
12681 /* rtnl_lock is held. */
12682 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
12683 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12684 unsigned long sp_bits = 0;
12685
12686 /* Configure the iSCSI classification object */
12687 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
12688 cp->iscsi_l2_client_id,
12689 cp->iscsi_l2_cid, BP_FUNC(bp),
12690 bnx2x_sp(bp, mac_rdata),
12691 bnx2x_sp_mapping(bp, mac_rdata),
12692 BNX2X_FILTER_MAC_PENDING,
12693 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
12694 &bp->macs_pool);
ec6ba945 12695
523224a3 12696 /* Set iSCSI MAC address */
619c5cb6
VZ
12697 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
12698 if (rc)
12699 break;
523224a3
DK
12700
12701 mmiowb();
12702 barrier();
12703
619c5cb6
VZ
12704 /* Start accepting on iSCSI L2 ring */
12705
12706 netif_addr_lock_bh(dev);
12707 bnx2x_set_iscsi_eth_rx_mode(bp, true);
12708 netif_addr_unlock_bh(dev);
12709
12710 /* bits to wait on */
12711 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12712 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
12713
12714 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12715 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 12716
993ac7b5
MC
12717 break;
12718 }
12719
12720 /* rtnl_lock is held. */
12721 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 12722 unsigned long sp_bits = 0;
993ac7b5 12723
523224a3 12724 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
12725 netif_addr_lock_bh(dev);
12726 bnx2x_set_iscsi_eth_rx_mode(bp, false);
12727 netif_addr_unlock_bh(dev);
12728
12729 /* bits to wait on */
12730 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12731 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
12732
12733 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12734 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
12735
12736 mmiowb();
12737 barrier();
12738
12739 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
12740 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
12741 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
12742 break;
12743 }
c2bff63f
DK
12744 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
12745 int count = ctl->data.credit.credit_count;
12746
12747 smp_mb__before_atomic_inc();
6e30dd4e 12748 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
12749 smp_mb__after_atomic_inc();
12750 break;
12751 }
1d187b34 12752 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 12753 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
12754
12755 if (CHIP_IS_E3(bp)) {
12756 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
12757 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12758 int path = BP_PATH(bp);
12759 int port = BP_PORT(bp);
12760 int i;
12761 u32 scratch_offset;
12762 u32 *host_addr;
1d187b34 12763
2e499d3c 12764 /* first write capability to shmem2 */
1d187b34
BW
12765 if (ulp_type == CNIC_ULP_ISCSI)
12766 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12767 else if (ulp_type == CNIC_ULP_FCOE)
12768 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12769 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
12770
12771 if ((ulp_type != CNIC_ULP_FCOE) ||
12772 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
12773 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
12774 break;
12775
12776 /* if reached here - should write fcoe capabilities */
12777 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
12778 if (!scratch_offset)
12779 break;
12780 scratch_offset += offsetof(struct glob_ncsi_oem_data,
12781 fcoe_features[path][port]);
12782 host_addr = (u32 *) &(ctl->data.register_data.
12783 fcoe_features);
12784 for (i = 0; i < sizeof(struct fcoe_capabilities);
12785 i += 4)
12786 REG_WR(bp, scratch_offset + i,
12787 *(host_addr + i/4));
1d187b34
BW
12788 }
12789 break;
12790 }
2e499d3c 12791
1d187b34
BW
12792 case DRV_CTL_ULP_UNREGISTER_CMD: {
12793 int ulp_type = ctl->data.ulp_type;
12794
12795 if (CHIP_IS_E3(bp)) {
12796 int idx = BP_FW_MB_IDX(bp);
12797 u32 cap;
12798
12799 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12800 if (ulp_type == CNIC_ULP_ISCSI)
12801 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12802 else if (ulp_type == CNIC_ULP_FCOE)
12803 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12804 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12805 }
12806 break;
12807 }
993ac7b5
MC
12808
12809 default:
12810 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12811 rc = -EINVAL;
12812 }
12813
12814 return rc;
12815}
12816
9f6c9258 12817void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
12818{
12819 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12820
12821 if (bp->flags & USING_MSIX_FLAG) {
12822 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12823 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12824 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12825 } else {
12826 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12827 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12828 }
619c5cb6 12829 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
12830 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12831 else
12832 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12833
619c5cb6
VZ
12834 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12835 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
12836 cp->irq_arr[1].status_blk = bp->def_status_blk;
12837 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 12838 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
12839
12840 cp->num_irq = 2;
12841}
12842
37ae41a9
MS
12843void bnx2x_setup_cnic_info(struct bnx2x *bp)
12844{
12845 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12846
12847
12848 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12849 bnx2x_cid_ilt_lines(bp);
12850 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12851 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
12852 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
12853
12854 if (NO_ISCSI_OOO(bp))
12855 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12856}
12857
993ac7b5
MC
12858static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12859 void *data)
12860{
12861 struct bnx2x *bp = netdev_priv(dev);
12862 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
12863 int rc;
12864
12865 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 12866
51c1a580
MS
12867 if (ops == NULL) {
12868 BNX2X_ERR("NULL ops received\n");
993ac7b5 12869 return -EINVAL;
51c1a580 12870 }
993ac7b5 12871
55c11941
MS
12872 if (!CNIC_SUPPORT(bp)) {
12873 BNX2X_ERR("Can't register CNIC when not supported\n");
12874 return -EOPNOTSUPP;
12875 }
12876
12877 if (!CNIC_LOADED(bp)) {
12878 rc = bnx2x_load_cnic(bp);
12879 if (rc) {
12880 BNX2X_ERR("CNIC-related load failed\n");
12881 return rc;
12882 }
12883
12884 }
12885
12886 bp->cnic_enabled = true;
12887
993ac7b5
MC
12888 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12889 if (!bp->cnic_kwq)
12890 return -ENOMEM;
12891
12892 bp->cnic_kwq_cons = bp->cnic_kwq;
12893 bp->cnic_kwq_prod = bp->cnic_kwq;
12894 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12895
12896 bp->cnic_spq_pending = 0;
12897 bp->cnic_kwq_pending = 0;
12898
12899 bp->cnic_data = data;
12900
12901 cp->num_irq = 0;
619c5cb6 12902 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 12903 cp->iro_arr = bp->iro_arr;
993ac7b5 12904
993ac7b5 12905 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 12906
993ac7b5
MC
12907 rcu_assign_pointer(bp->cnic_ops, ops);
12908
12909 return 0;
12910}
12911
12912static int bnx2x_unregister_cnic(struct net_device *dev)
12913{
12914 struct bnx2x *bp = netdev_priv(dev);
12915 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12916
12917 mutex_lock(&bp->cnic_mutex);
993ac7b5 12918 cp->drv_state = 0;
2cfa5a04 12919 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
12920 mutex_unlock(&bp->cnic_mutex);
12921 synchronize_rcu();
12922 kfree(bp->cnic_kwq);
12923 bp->cnic_kwq = NULL;
12924
12925 return 0;
12926}
12927
12928struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12929{
12930 struct bnx2x *bp = netdev_priv(dev);
12931 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12932
2ba45142
VZ
12933 /* If both iSCSI and FCoE are disabled - return NULL in
12934 * order to indicate CNIC that it should not try to work
12935 * with this device.
12936 */
12937 if (NO_ISCSI(bp) && NO_FCOE(bp))
12938 return NULL;
12939
993ac7b5
MC
12940 cp->drv_owner = THIS_MODULE;
12941 cp->chip_id = CHIP_ID(bp);
12942 cp->pdev = bp->pdev;
12943 cp->io_base = bp->regview;
12944 cp->io_base2 = bp->doorbells;
12945 cp->max_kwqe_pending = 8;
523224a3 12946 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
12947 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12948 bnx2x_cid_ilt_lines(bp);
993ac7b5 12949 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 12950 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
12951 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12952 cp->drv_ctl = bnx2x_drv_ctl;
12953 cp->drv_register_cnic = bnx2x_register_cnic;
12954 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 12955 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
12956 cp->iscsi_l2_client_id =
12957 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 12958 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 12959
2ba45142
VZ
12960 if (NO_ISCSI_OOO(bp))
12961 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12962
12963 if (NO_ISCSI(bp))
12964 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12965
12966 if (NO_FCOE(bp))
12967 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12968
51c1a580
MS
12969 BNX2X_DEV_INFO(
12970 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
12971 cp->ctx_blk_size,
12972 cp->ctx_tbl_offset,
12973 cp->ctx_tbl_len,
12974 cp->starting_cid);
993ac7b5
MC
12975 return cp;
12976}
12977EXPORT_SYMBOL(bnx2x_cnic_probe);
12978
94a78b79 12979
This page took 1.934312 seconds and 5 git commands to generate.