]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
bnx2x: Support VF FLR
[mirror_ubuntu-eoan-kernel.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_main.c
CommitLineData
34f80b04 1/* bnx2x_main.c: Broadcom Everest network driver.
a2fbb9ea 2 *
85b26ea1 3 * Copyright (c) 2007-2012 Broadcom Corporation
a2fbb9ea
ET
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
24e3fcef
EG
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
a2fbb9ea
ET
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
ca00392c 13 * Slowpath and fastpath rework by Vladislav Zolotarov
c14423fe 14 * Statistics and Link management by Yitchak Gertner
a2fbb9ea
ET
15 *
16 */
17
f1deab50
JP
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
a2fbb9ea
ET
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/kernel.h>
23#include <linux/device.h> /* for dev_info() */
24#include <linux/timer.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
a2fbb9ea
ET
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/dma-mapping.h>
35#include <linux/bitops.h>
36#include <linux/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
0c6671b0 42#include <linux/if_vlan.h>
a2fbb9ea 43#include <net/ip.h>
619c5cb6 44#include <net/ipv6.h>
a2fbb9ea
ET
45#include <net/tcp.h>
46#include <net/checksum.h>
34f80b04 47#include <net/ip6_checksum.h>
a2fbb9ea
ET
48#include <linux/workqueue.h>
49#include <linux/crc32.h>
34f80b04 50#include <linux/crc32c.h>
a2fbb9ea
ET
51#include <linux/prefetch.h>
52#include <linux/zlib.h>
a2fbb9ea 53#include <linux/io.h>
452427b0 54#include <linux/semaphore.h>
45229b42 55#include <linux/stringify.h>
7ab24bfd 56#include <linux/vmalloc.h>
a2fbb9ea 57
a2fbb9ea
ET
58#include "bnx2x.h"
59#include "bnx2x_init.h"
94a78b79 60#include "bnx2x_init_ops.h"
9f6c9258 61#include "bnx2x_cmn.h"
1ab4434c
AE
62#include "bnx2x_vfpf.h"
63#include "bnx2x_sriov.h"
e4901dde 64#include "bnx2x_dcb.h"
042181f5 65#include "bnx2x_sp.h"
a2fbb9ea 66
94a78b79
VZ
67#include <linux/firmware.h>
68#include "bnx2x_fw_file_hdr.h"
69/* FW files */
45229b42
BH
70#define FW_FILE_VERSION \
71 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
72 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
73 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
74 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
560131f3
DK
75#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
76#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
f2e0899f 77#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
94a78b79 78
2e499d3c
BW
79#define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
80
34f80b04
EG
81/* Time in jiffies before concluding the transmitter is hung */
82#define TX_TIMEOUT (5*HZ)
a2fbb9ea 83
0329aba1 84static char version[] =
619c5cb6 85 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
86 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
87
24e3fcef 88MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 89MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
90 "BCM57710/57711/57711E/"
91 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
92 "57840/57840_MF Driver");
a2fbb9ea
ET
93MODULE_LICENSE("GPL");
94MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
95MODULE_FIRMWARE(FW_FILE_NAME_E1);
96MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 97MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 98
ca00392c 99
d6214d7a 100int num_queues;
54b9ddaa 101module_param(num_queues, int, 0);
96305234
DK
102MODULE_PARM_DESC(num_queues,
103 " Set number of queues (default is as a number of CPUs)");
555f6c78 104
19680c48 105static int disable_tpa;
19680c48 106module_param(disable_tpa, int, 0);
9898f86d 107MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 108
9ee3d37b
DK
109#define INT_MODE_INTx 1
110#define INT_MODE_MSI 2
0e8d2ec5 111int int_mode;
8badd27a 112module_param(int_mode, int, 0);
619c5cb6 113MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 114 "(1 INT#x; 2 MSI)");
8badd27a 115
a18f5128
EG
116static int dropless_fc;
117module_param(dropless_fc, int, 0);
118MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
119
8d5726c4
EG
120static int mrrs = -1;
121module_param(mrrs, int, 0);
122MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
123
9898f86d 124static int debug;
a2fbb9ea 125module_param(debug, int, 0);
9898f86d
EG
126MODULE_PARM_DESC(debug, " Default debug msglevel");
127
a2fbb9ea 128
619c5cb6
VZ
129
130struct workqueue_struct *bnx2x_wq;
ec6ba945 131
a2fbb9ea
ET
132enum bnx2x_board_type {
133 BCM57710 = 0,
619c5cb6
VZ
134 BCM57711,
135 BCM57711E,
136 BCM57712,
137 BCM57712_MF,
1ab4434c 138 BCM57712_VF,
619c5cb6
VZ
139 BCM57800,
140 BCM57800_MF,
1ab4434c 141 BCM57800_VF,
619c5cb6
VZ
142 BCM57810,
143 BCM57810_MF,
1ab4434c 144 BCM57810_VF,
c3def943
YM
145 BCM57840_4_10,
146 BCM57840_2_20,
7e8e02df 147 BCM57840_MF,
1ab4434c 148 BCM57840_VF,
7e8e02df 149 BCM57811,
1ab4434c
AE
150 BCM57811_MF,
151 BCM57840_O,
152 BCM57840_MFO,
153 BCM57811_VF
a2fbb9ea
ET
154};
155
34f80b04 156/* indexed by board_type, above */
53a10565 157static struct {
a2fbb9ea 158 char *name;
0329aba1 159} board_info[] = {
1ab4434c
AE
160 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
161 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
162 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
163 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
164 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
165 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
166 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
167 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
168 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
169 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
170 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
171 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
172 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
173 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
174 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
175 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
176 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
177 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
178 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
179 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
180 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
a2fbb9ea
ET
181};
182
619c5cb6
VZ
183#ifndef PCI_DEVICE_ID_NX2_57710
184#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
185#endif
186#ifndef PCI_DEVICE_ID_NX2_57711
187#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
188#endif
189#ifndef PCI_DEVICE_ID_NX2_57711E
190#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
191#endif
192#ifndef PCI_DEVICE_ID_NX2_57712
193#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
194#endif
195#ifndef PCI_DEVICE_ID_NX2_57712_MF
196#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
197#endif
198#ifndef PCI_DEVICE_ID_NX2_57800
199#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
200#endif
201#ifndef PCI_DEVICE_ID_NX2_57800_MF
202#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
203#endif
204#ifndef PCI_DEVICE_ID_NX2_57810
205#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
206#endif
207#ifndef PCI_DEVICE_ID_NX2_57810_MF
208#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
209#endif
c3def943
YM
210#ifndef PCI_DEVICE_ID_NX2_57840_O
211#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
212#endif
213#ifndef PCI_DEVICE_ID_NX2_57840_4_10
214#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
215#endif
216#ifndef PCI_DEVICE_ID_NX2_57840_2_20
217#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
218#endif
219#ifndef PCI_DEVICE_ID_NX2_57840_MFO
220#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
619c5cb6
VZ
221#endif
222#ifndef PCI_DEVICE_ID_NX2_57840_MF
223#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
224#endif
7e8e02df
BW
225#ifndef PCI_DEVICE_ID_NX2_57811
226#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
227#endif
228#ifndef PCI_DEVICE_ID_NX2_57811_MF
229#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
230#endif
a3aa1884 231static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
232 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
233 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
234 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 235 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6
VZ
236 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
237 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
238 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
239 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
240 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
c3def943
YM
241 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
242 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
243 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
244 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
619c5cb6 245 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
7e8e02df
BW
246 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
247 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
a2fbb9ea
ET
248 { 0 }
249};
250
251MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
252
452427b0
YM
253/* Global resources for unloading a previously loaded device */
254#define BNX2X_PREV_WAIT_NEEDED 1
255static DEFINE_SEMAPHORE(bnx2x_prev_sem);
256static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
257/****************************************************************************
258* General service functions
259****************************************************************************/
260
1191cb83 261static void __storm_memset_dma_mapping(struct bnx2x *bp,
619c5cb6
VZ
262 u32 addr, dma_addr_t mapping)
263{
264 REG_WR(bp, addr, U64_LO(mapping));
265 REG_WR(bp, addr + 4, U64_HI(mapping));
266}
267
1191cb83
ED
268static void storm_memset_spq_addr(struct bnx2x *bp,
269 dma_addr_t mapping, u16 abs_fid)
619c5cb6
VZ
270{
271 u32 addr = XSEM_REG_FAST_MEMORY +
272 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
273
274 __storm_memset_dma_mapping(bp, addr, mapping);
275}
276
1191cb83
ED
277static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
278 u16 pf_id)
523224a3 279{
619c5cb6
VZ
280 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
281 pf_id);
282 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
283 pf_id);
284 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
285 pf_id);
286 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
287 pf_id);
523224a3
DK
288}
289
1191cb83
ED
290static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
291 u8 enable)
619c5cb6
VZ
292{
293 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
294 enable);
295 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
296 enable);
297 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
298 enable);
299 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
300 enable);
301}
523224a3 302
1191cb83
ED
303static void storm_memset_eq_data(struct bnx2x *bp,
304 struct event_ring_data *eq_data,
523224a3
DK
305 u16 pfid)
306{
307 size_t size = sizeof(struct event_ring_data);
308
309 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
310
311 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
312}
313
1191cb83
ED
314static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
315 u16 pfid)
523224a3
DK
316{
317 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
318 REG_WR16(bp, addr, eq_prod);
319}
320
a2fbb9ea
ET
321/* used only at init
322 * locking is done by mcp
323 */
8d96286a 324static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
325{
326 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
327 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
328 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
329 PCICFG_VENDOR_ID_OFFSET);
330}
331
a2fbb9ea
ET
332static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
333{
334 u32 val;
335
336 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
337 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
338 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
339 PCICFG_VENDOR_ID_OFFSET);
340
341 return val;
342}
a2fbb9ea 343
f2e0899f
DK
344#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
345#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
346#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
347#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
348#define DMAE_DP_DST_NONE "dst_addr [none]"
349
fd1fc79d
AE
350void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
351{
352 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
353
354 switch (dmae->opcode & DMAE_COMMAND_DST) {
355 case DMAE_CMD_DST_PCI:
356 if (src_type == DMAE_CMD_SRC_PCI)
357 DP(msglvl, "DMAE: opcode 0x%08x\n"
358 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
359 "comp_addr [%x:%08x], comp_val 0x%08x\n",
360 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
361 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
362 dmae->comp_addr_hi, dmae->comp_addr_lo,
363 dmae->comp_val);
364 else
365 DP(msglvl, "DMAE: opcode 0x%08x\n"
366 "src [%08x], len [%d*4], dst [%x:%08x]\n"
367 "comp_addr [%x:%08x], comp_val 0x%08x\n",
368 dmae->opcode, dmae->src_addr_lo >> 2,
369 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
370 dmae->comp_addr_hi, dmae->comp_addr_lo,
371 dmae->comp_val);
372 break;
373 case DMAE_CMD_DST_GRC:
374 if (src_type == DMAE_CMD_SRC_PCI)
375 DP(msglvl, "DMAE: opcode 0x%08x\n"
376 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
377 "comp_addr [%x:%08x], comp_val 0x%08x\n",
378 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
379 dmae->len, dmae->dst_addr_lo >> 2,
380 dmae->comp_addr_hi, dmae->comp_addr_lo,
381 dmae->comp_val);
382 else
383 DP(msglvl, "DMAE: opcode 0x%08x\n"
384 "src [%08x], len [%d*4], dst [%08x]\n"
385 "comp_addr [%x:%08x], comp_val 0x%08x\n",
386 dmae->opcode, dmae->src_addr_lo >> 2,
387 dmae->len, dmae->dst_addr_lo >> 2,
388 dmae->comp_addr_hi, dmae->comp_addr_lo,
389 dmae->comp_val);
390 break;
391 default:
392 if (src_type == DMAE_CMD_SRC_PCI)
393 DP(msglvl, "DMAE: opcode 0x%08x\n"
394 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
395 "comp_addr [%x:%08x] comp_val 0x%08x\n",
396 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
397 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
398 dmae->comp_val);
399 else
400 DP(msglvl, "DMAE: opcode 0x%08x\n"
401 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
402 "comp_addr [%x:%08x] comp_val 0x%08x\n",
403 dmae->opcode, dmae->src_addr_lo >> 2,
404 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
405 dmae->comp_val);
406 break;
407 }
408}
f2e0899f 409
a2fbb9ea 410/* copy command into DMAE command memory and set DMAE command go */
6c719d00 411void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
412{
413 u32 cmd_offset;
414 int i;
415
416 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
417 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
418 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
419 }
420 REG_WR(bp, dmae_reg_go_c[idx], 1);
421}
422
f2e0899f 423u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 424{
f2e0899f
DK
425 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
426 DMAE_CMD_C_ENABLE);
427}
ad8d3948 428
f2e0899f
DK
429u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
430{
431 return opcode & ~DMAE_CMD_SRC_RESET;
432}
ad8d3948 433
f2e0899f
DK
434u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
435 bool with_comp, u8 comp_type)
436{
437 u32 opcode = 0;
438
439 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
440 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 441
f2e0899f
DK
442 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
443
444 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
445 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
446 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 447 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 448
a2fbb9ea 449#ifdef __BIG_ENDIAN
f2e0899f 450 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 451#else
f2e0899f 452 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 453#endif
f2e0899f
DK
454 if (with_comp)
455 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
456 return opcode;
457}
458
fd1fc79d 459void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
8d96286a 460 struct dmae_command *dmae,
461 u8 src_type, u8 dst_type)
f2e0899f
DK
462{
463 memset(dmae, 0, sizeof(struct dmae_command));
464
465 /* set the opcode */
466 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
467 true, DMAE_COMP_PCI);
468
469 /* fill in the completion parameters */
470 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
471 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
472 dmae->comp_val = DMAE_COMP_VAL;
473}
474
fd1fc79d
AE
475/* issue a dmae command over the init-channel and wait for completion */
476int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
f2e0899f
DK
477{
478 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
5e374b5a 479 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
480 int rc = 0;
481
619c5cb6
VZ
482 /*
483 * Lock the dmae channel. Disable BHs to prevent a dead-lock
484 * as long as this code is called both from syscall context and
485 * from ndo_set_rx_mode() flow that may be called from BH.
486 */
6e30dd4e 487 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 488
f2e0899f 489 /* reset completion */
a2fbb9ea
ET
490 *wb_comp = 0;
491
f2e0899f
DK
492 /* post the command on the channel used for initializations */
493 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 494
f2e0899f 495 /* wait for completion */
a2fbb9ea 496 udelay(5);
f2e0899f 497 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 498
95c6c616
AE
499 if (!cnt ||
500 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
501 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 502 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
503 rc = DMAE_TIMEOUT;
504 goto unlock;
a2fbb9ea 505 }
ad8d3948 506 cnt--;
f2e0899f 507 udelay(50);
a2fbb9ea 508 }
f2e0899f
DK
509 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
510 BNX2X_ERR("DMAE PCI error!\n");
511 rc = DMAE_PCI_ERROR;
512 }
513
f2e0899f 514unlock:
6e30dd4e 515 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
516 return rc;
517}
518
519void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
520 u32 len32)
521{
522 struct dmae_command dmae;
523
524 if (!bp->dmae_ready) {
525 u32 *data = bnx2x_sp(bp, wb_data[0]);
526
127a425e
AE
527 if (CHIP_IS_E1(bp))
528 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
529 else
530 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
531 return;
532 }
533
534 /* set opcode and fixed command fields */
535 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
536
537 /* fill in addresses and len */
538 dmae.src_addr_lo = U64_LO(dma_addr);
539 dmae.src_addr_hi = U64_HI(dma_addr);
540 dmae.dst_addr_lo = dst_addr >> 2;
541 dmae.dst_addr_hi = 0;
542 dmae.len = len32;
543
f2e0899f
DK
544 /* issue the command and wait for completion */
545 bnx2x_issue_dmae_with_comp(bp, &dmae);
a2fbb9ea
ET
546}
547
c18487ee 548void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 549{
5ff7b6d4 550 struct dmae_command dmae;
ad8d3948
EG
551
552 if (!bp->dmae_ready) {
553 u32 *data = bnx2x_sp(bp, wb_data[0]);
554 int i;
555
51c1a580 556 if (CHIP_IS_E1(bp))
127a425e
AE
557 for (i = 0; i < len32; i++)
558 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 559 else
127a425e
AE
560 for (i = 0; i < len32; i++)
561 data[i] = REG_RD(bp, src_addr + i*4);
562
ad8d3948
EG
563 return;
564 }
565
f2e0899f
DK
566 /* set opcode and fixed command fields */
567 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 568
f2e0899f 569 /* fill in addresses and len */
5ff7b6d4
EG
570 dmae.src_addr_lo = src_addr >> 2;
571 dmae.src_addr_hi = 0;
572 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
573 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
574 dmae.len = len32;
ad8d3948 575
f2e0899f
DK
576 /* issue the command and wait for completion */
577 bnx2x_issue_dmae_with_comp(bp, &dmae);
ad8d3948
EG
578}
579
8d96286a 580static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
581 u32 addr, u32 len)
573f2035 582{
02e3c6cb 583 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
584 int offset = 0;
585
02e3c6cb 586 while (len > dmae_wr_max) {
573f2035 587 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
588 addr + offset, dmae_wr_max);
589 offset += dmae_wr_max * 4;
590 len -= dmae_wr_max;
573f2035
EG
591 }
592
593 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
594}
595
a2fbb9ea
ET
596static int bnx2x_mc_assert(struct bnx2x *bp)
597{
a2fbb9ea 598 char last_idx;
34f80b04
EG
599 int i, rc = 0;
600 u32 row0, row1, row2, row3;
601
602 /* XSTORM */
603 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
604 XSTORM_ASSERT_LIST_INDEX_OFFSET);
605 if (last_idx)
606 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
607
608 /* print the asserts */
609 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
610
611 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
612 XSTORM_ASSERT_LIST_OFFSET(i));
613 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
614 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
615 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
616 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
617 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
618 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
619
620 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 621 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
622 i, row3, row2, row1, row0);
623 rc++;
624 } else {
625 break;
626 }
627 }
628
629 /* TSTORM */
630 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
631 TSTORM_ASSERT_LIST_INDEX_OFFSET);
632 if (last_idx)
633 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
634
635 /* print the asserts */
636 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
637
638 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
639 TSTORM_ASSERT_LIST_OFFSET(i));
640 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
641 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
642 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
643 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
644 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
645 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
646
647 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 648 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
649 i, row3, row2, row1, row0);
650 rc++;
651 } else {
652 break;
653 }
654 }
655
656 /* CSTORM */
657 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
658 CSTORM_ASSERT_LIST_INDEX_OFFSET);
659 if (last_idx)
660 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
661
662 /* print the asserts */
663 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
664
665 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
666 CSTORM_ASSERT_LIST_OFFSET(i));
667 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
668 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
669 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
670 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
671 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
672 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
673
674 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 675 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
676 i, row3, row2, row1, row0);
677 rc++;
678 } else {
679 break;
680 }
681 }
682
683 /* USTORM */
684 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
685 USTORM_ASSERT_LIST_INDEX_OFFSET);
686 if (last_idx)
687 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
688
689 /* print the asserts */
690 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
691
692 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
693 USTORM_ASSERT_LIST_OFFSET(i));
694 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
695 USTORM_ASSERT_LIST_OFFSET(i) + 4);
696 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
697 USTORM_ASSERT_LIST_OFFSET(i) + 8);
698 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
699 USTORM_ASSERT_LIST_OFFSET(i) + 12);
700
701 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 702 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
703 i, row3, row2, row1, row0);
704 rc++;
705 } else {
706 break;
a2fbb9ea
ET
707 }
708 }
34f80b04 709
a2fbb9ea
ET
710 return rc;
711}
c14423fe 712
7a25cc73 713void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 714{
7a25cc73 715 u32 addr, val;
a2fbb9ea 716 u32 mark, offset;
4781bfad 717 __be32 data[9];
a2fbb9ea 718 int word;
f2e0899f 719 u32 trace_shmem_base;
2145a920
VZ
720 if (BP_NOMCP(bp)) {
721 BNX2X_ERR("NO MCP - can not dump\n");
722 return;
723 }
7a25cc73
DK
724 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
725 (bp->common.bc_ver & 0xff0000) >> 16,
726 (bp->common.bc_ver & 0xff00) >> 8,
727 (bp->common.bc_ver & 0xff));
728
729 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
730 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 731 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 732
f2e0899f
DK
733 if (BP_PATH(bp) == 0)
734 trace_shmem_base = bp->common.shmem_base;
735 else
736 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
de128804
DK
737 addr = trace_shmem_base - 0x800;
738
739 /* validate TRCB signature */
740 mark = REG_RD(bp, addr);
741 if (mark != MFW_TRACE_SIGNATURE) {
742 BNX2X_ERR("Trace buffer signature is missing.");
743 return ;
744 }
745
746 /* read cyclic buffer pointer */
747 addr += 4;
cdaa7cb8 748 mark = REG_RD(bp, addr);
f2e0899f
DK
749 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
750 + ((mark + 0x3) & ~0x3) - 0x08000000;
7a25cc73 751 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 752
7a25cc73 753 printk("%s", lvl);
f2e0899f 754 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 755 for (word = 0; word < 8; word++)
cdaa7cb8 756 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 757 data[8] = 0x0;
7995c64e 758 pr_cont("%s", (char *)data);
a2fbb9ea 759 }
cdaa7cb8 760 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 761 for (word = 0; word < 8; word++)
cdaa7cb8 762 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 763 data[8] = 0x0;
7995c64e 764 pr_cont("%s", (char *)data);
a2fbb9ea 765 }
7a25cc73
DK
766 printk("%s" "end of fw dump\n", lvl);
767}
768
1191cb83 769static void bnx2x_fw_dump(struct bnx2x *bp)
7a25cc73
DK
770{
771 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
772}
773
6c719d00 774void bnx2x_panic_dump(struct bnx2x *bp)
a2fbb9ea
ET
775{
776 int i;
523224a3
DK
777 u16 j;
778 struct hc_sp_status_block_data sp_sb_data;
779 int func = BP_FUNC(bp);
780#ifdef BNX2X_STOP_ON_ERROR
781 u16 start = 0, end = 0;
6383c0b3 782 u8 cos;
523224a3 783#endif
a2fbb9ea 784
66e855f3 785 bp->stats_state = STATS_STATE_DISABLED;
7a752993 786 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
787 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
788
a2fbb9ea
ET
789 BNX2X_ERR("begin crash dump -----------------\n");
790
8440d2b6
EG
791 /* Indices */
792 /* Common */
51c1a580 793 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
794 bp->def_idx, bp->def_att_idx, bp->attn_state,
795 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
796 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
797 bp->def_status_blk->atten_status_block.attn_bits,
798 bp->def_status_blk->atten_status_block.attn_bits_ack,
799 bp->def_status_blk->atten_status_block.status_block_id,
800 bp->def_status_blk->atten_status_block.attn_bits_index);
801 BNX2X_ERR(" def (");
802 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
803 pr_cont("0x%x%s",
f1deab50
JP
804 bp->def_status_blk->sp_sb.index_values[i],
805 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
806
807 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
808 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
809 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
810 i*sizeof(u32));
811
f1deab50 812 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
813 sp_sb_data.igu_sb_id,
814 sp_sb_data.igu_seg_id,
815 sp_sb_data.p_func.pf_id,
816 sp_sb_data.p_func.vnic_id,
817 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
818 sp_sb_data.p_func.vf_valid,
819 sp_sb_data.state);
523224a3 820
8440d2b6 821
ec6ba945 822 for_each_eth_queue(bp, i) {
a2fbb9ea 823 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 824 int loop;
f2e0899f 825 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
826 struct hc_status_block_data_e1x sb_data_e1x;
827 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
828 CHIP_IS_E1x(bp) ?
829 sb_data_e1x.common.state_machine :
830 sb_data_e2.common.state_machine;
523224a3 831 struct hc_index_data *hc_index_p =
619c5cb6
VZ
832 CHIP_IS_E1x(bp) ?
833 sb_data_e1x.index_data :
834 sb_data_e2.index_data;
6383c0b3 835 u8 data_size, cos;
523224a3 836 u32 *sb_data_p;
6383c0b3 837 struct bnx2x_fp_txdata txdata;
523224a3
DK
838
839 /* Rx */
51c1a580 840 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 841 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 842 fp->rx_comp_prod,
66e855f3 843 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 844 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 845 fp->rx_sge_prod, fp->last_max_sge,
523224a3 846 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 847
523224a3 848 /* Tx */
6383c0b3
AE
849 for_each_cos_in_tx_queue(fp, cos)
850 {
65565884 851 txdata = *fp->txdata_ptr[cos];
51c1a580 852 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
853 i, txdata.tx_pkt_prod,
854 txdata.tx_pkt_cons, txdata.tx_bd_prod,
855 txdata.tx_bd_cons,
856 le16_to_cpu(*txdata.tx_cons_sb));
857 }
523224a3 858
619c5cb6
VZ
859 loop = CHIP_IS_E1x(bp) ?
860 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
861
862 /* host sb data */
863
ec6ba945
VZ
864 if (IS_FCOE_FP(fp))
865 continue;
55c11941 866
523224a3
DK
867 BNX2X_ERR(" run indexes (");
868 for (j = 0; j < HC_SB_MAX_SM; j++)
869 pr_cont("0x%x%s",
870 fp->sb_running_index[j],
871 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
872
873 BNX2X_ERR(" indexes (");
874 for (j = 0; j < loop; j++)
875 pr_cont("0x%x%s",
876 fp->sb_index_values[j],
877 (j == loop - 1) ? ")" : " ");
878 /* fw sb data */
619c5cb6
VZ
879 data_size = CHIP_IS_E1x(bp) ?
880 sizeof(struct hc_status_block_data_e1x) :
881 sizeof(struct hc_status_block_data_e2);
523224a3 882 data_size /= sizeof(u32);
619c5cb6
VZ
883 sb_data_p = CHIP_IS_E1x(bp) ?
884 (u32 *)&sb_data_e1x :
885 (u32 *)&sb_data_e2;
523224a3
DK
886 /* copy sb data in here */
887 for (j = 0; j < data_size; j++)
888 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
889 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
890 j * sizeof(u32));
891
619c5cb6 892 if (!CHIP_IS_E1x(bp)) {
51c1a580 893 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
894 sb_data_e2.common.p_func.pf_id,
895 sb_data_e2.common.p_func.vf_id,
896 sb_data_e2.common.p_func.vf_valid,
897 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
898 sb_data_e2.common.same_igu_sb_1b,
899 sb_data_e2.common.state);
f2e0899f 900 } else {
51c1a580 901 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
902 sb_data_e1x.common.p_func.pf_id,
903 sb_data_e1x.common.p_func.vf_id,
904 sb_data_e1x.common.p_func.vf_valid,
905 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
906 sb_data_e1x.common.same_igu_sb_1b,
907 sb_data_e1x.common.state);
f2e0899f 908 }
523224a3
DK
909
910 /* SB_SMs data */
911 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
912 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",
913 j, hc_sm_p[j].__flags,
914 hc_sm_p[j].igu_sb_id,
915 hc_sm_p[j].igu_seg_id,
916 hc_sm_p[j].time_to_expire,
917 hc_sm_p[j].timer_value);
523224a3
DK
918 }
919
920 /* Indecies data */
921 for (j = 0; j < loop; j++) {
51c1a580 922 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
923 hc_index_p[j].flags,
924 hc_index_p[j].timeout);
925 }
8440d2b6 926 }
a2fbb9ea 927
523224a3 928#ifdef BNX2X_STOP_ON_ERROR
8440d2b6
EG
929 /* Rings */
930 /* Rx */
55c11941 931 for_each_valid_rx_queue(bp, i) {
8440d2b6 932 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
933
934 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
935 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 936 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
937 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
938 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
939
c3eefaf6 940 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 941 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
942 }
943
3196a88a
EG
944 start = RX_SGE(fp->rx_sge_prod);
945 end = RX_SGE(fp->last_max_sge);
8440d2b6 946 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
947 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
948 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
949
c3eefaf6
EG
950 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
951 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
952 }
953
a2fbb9ea
ET
954 start = RCQ_BD(fp->rx_comp_cons - 10);
955 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 956 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
957 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
958
c3eefaf6
EG
959 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
960 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
961 }
962 }
963
8440d2b6 964 /* Tx */
55c11941 965 for_each_valid_tx_queue(bp, i) {
8440d2b6 966 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3 967 for_each_cos_in_tx_queue(fp, cos) {
65565884 968 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
6383c0b3
AE
969
970 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
971 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
972 for (j = start; j != end; j = TX_BD(j + 1)) {
973 struct sw_tx_bd *sw_bd =
974 &txdata->tx_buf_ring[j];
975
51c1a580 976 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
977 i, cos, j, sw_bd->skb,
978 sw_bd->first_bd);
979 }
8440d2b6 980
6383c0b3
AE
981 start = TX_BD(txdata->tx_bd_cons - 10);
982 end = TX_BD(txdata->tx_bd_cons + 254);
983 for (j = start; j != end; j = TX_BD(j + 1)) {
984 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 985
51c1a580 986 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
987 i, cos, j, tx_bd[0], tx_bd[1],
988 tx_bd[2], tx_bd[3]);
989 }
8440d2b6
EG
990 }
991 }
523224a3 992#endif
34f80b04 993 bnx2x_fw_dump(bp);
a2fbb9ea
ET
994 bnx2x_mc_assert(bp);
995 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
996}
997
619c5cb6
VZ
998/*
999 * FLR Support for E2
1000 *
1001 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1002 * initialization.
1003 */
1004#define FLR_WAIT_USEC 10000 /* 10 miliseconds */
89db4ad8
AE
1005#define FLR_WAIT_INTERVAL 50 /* usec */
1006#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
1007
1008struct pbf_pN_buf_regs {
1009 int pN;
1010 u32 init_crd;
1011 u32 crd;
1012 u32 crd_freed;
1013};
1014
1015struct pbf_pN_cmd_regs {
1016 int pN;
1017 u32 lines_occup;
1018 u32 lines_freed;
1019};
1020
1021static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1022 struct pbf_pN_buf_regs *regs,
1023 u32 poll_count)
1024{
1025 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1026 u32 cur_cnt = poll_count;
1027
1028 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1029 crd = crd_start = REG_RD(bp, regs->crd);
1030 init_crd = REG_RD(bp, regs->init_crd);
1031
1032 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1033 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1034 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1035
1036 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1037 (init_crd - crd_start))) {
1038 if (cur_cnt--) {
89db4ad8 1039 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1040 crd = REG_RD(bp, regs->crd);
1041 crd_freed = REG_RD(bp, regs->crd_freed);
1042 } else {
1043 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1044 regs->pN);
1045 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1046 regs->pN, crd);
1047 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1048 regs->pN, crd_freed);
1049 break;
1050 }
1051 }
1052 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 1053 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1054}
1055
1056static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1057 struct pbf_pN_cmd_regs *regs,
1058 u32 poll_count)
1059{
1060 u32 occup, to_free, freed, freed_start;
1061 u32 cur_cnt = poll_count;
1062
1063 occup = to_free = REG_RD(bp, regs->lines_occup);
1064 freed = freed_start = REG_RD(bp, regs->lines_freed);
1065
1066 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1067 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1068
1069 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1070 if (cur_cnt--) {
89db4ad8 1071 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1072 occup = REG_RD(bp, regs->lines_occup);
1073 freed = REG_RD(bp, regs->lines_freed);
1074 } else {
1075 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1076 regs->pN);
1077 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1078 regs->pN, occup);
1079 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1080 regs->pN, freed);
1081 break;
1082 }
1083 }
1084 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 1085 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1086}
1087
1191cb83
ED
1088static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1089 u32 expected, u32 poll_count)
619c5cb6
VZ
1090{
1091 u32 cur_cnt = poll_count;
1092 u32 val;
1093
1094 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 1095 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1096
1097 return val;
1098}
1099
d16132ce
AE
1100int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1101 char *msg, u32 poll_cnt)
619c5cb6
VZ
1102{
1103 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1104 if (val != 0) {
1105 BNX2X_ERR("%s usage count=%d\n", msg, val);
1106 return 1;
1107 }
1108 return 0;
1109}
1110
d16132ce
AE
1111/* Common routines with VF FLR cleanup */
1112u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
619c5cb6
VZ
1113{
1114 /* adjust polling timeout */
1115 if (CHIP_REV_IS_EMUL(bp))
1116 return FLR_POLL_CNT * 2000;
1117
1118 if (CHIP_REV_IS_FPGA(bp))
1119 return FLR_POLL_CNT * 120;
1120
1121 return FLR_POLL_CNT;
1122}
1123
d16132ce 1124void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
619c5cb6
VZ
1125{
1126 struct pbf_pN_cmd_regs cmd_regs[] = {
1127 {0, (CHIP_IS_E3B0(bp)) ?
1128 PBF_REG_TQ_OCCUPANCY_Q0 :
1129 PBF_REG_P0_TQ_OCCUPANCY,
1130 (CHIP_IS_E3B0(bp)) ?
1131 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1132 PBF_REG_P0_TQ_LINES_FREED_CNT},
1133 {1, (CHIP_IS_E3B0(bp)) ?
1134 PBF_REG_TQ_OCCUPANCY_Q1 :
1135 PBF_REG_P1_TQ_OCCUPANCY,
1136 (CHIP_IS_E3B0(bp)) ?
1137 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1138 PBF_REG_P1_TQ_LINES_FREED_CNT},
1139 {4, (CHIP_IS_E3B0(bp)) ?
1140 PBF_REG_TQ_OCCUPANCY_LB_Q :
1141 PBF_REG_P4_TQ_OCCUPANCY,
1142 (CHIP_IS_E3B0(bp)) ?
1143 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1144 PBF_REG_P4_TQ_LINES_FREED_CNT}
1145 };
1146
1147 struct pbf_pN_buf_regs buf_regs[] = {
1148 {0, (CHIP_IS_E3B0(bp)) ?
1149 PBF_REG_INIT_CRD_Q0 :
1150 PBF_REG_P0_INIT_CRD ,
1151 (CHIP_IS_E3B0(bp)) ?
1152 PBF_REG_CREDIT_Q0 :
1153 PBF_REG_P0_CREDIT,
1154 (CHIP_IS_E3B0(bp)) ?
1155 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1156 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1157 {1, (CHIP_IS_E3B0(bp)) ?
1158 PBF_REG_INIT_CRD_Q1 :
1159 PBF_REG_P1_INIT_CRD,
1160 (CHIP_IS_E3B0(bp)) ?
1161 PBF_REG_CREDIT_Q1 :
1162 PBF_REG_P1_CREDIT,
1163 (CHIP_IS_E3B0(bp)) ?
1164 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1165 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1166 {4, (CHIP_IS_E3B0(bp)) ?
1167 PBF_REG_INIT_CRD_LB_Q :
1168 PBF_REG_P4_INIT_CRD,
1169 (CHIP_IS_E3B0(bp)) ?
1170 PBF_REG_CREDIT_LB_Q :
1171 PBF_REG_P4_CREDIT,
1172 (CHIP_IS_E3B0(bp)) ?
1173 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1174 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1175 };
1176
1177 int i;
1178
1179 /* Verify the command queues are flushed P0, P1, P4 */
1180 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1181 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1182
1183
1184 /* Verify the transmission buffers are flushed P0, P1, P4 */
1185 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1186 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1187}
1188
1189#define OP_GEN_PARAM(param) \
1190 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1191
1192#define OP_GEN_TYPE(type) \
1193 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1194
1195#define OP_GEN_AGG_VECT(index) \
1196 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1197
1198
d16132ce 1199int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
619c5cb6
VZ
1200{
1201 struct sdm_op_gen op_gen = {0};
1202
1203 u32 comp_addr = BAR_CSTRORM_INTMEM +
1204 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1205 int ret = 0;
1206
1207 if (REG_RD(bp, comp_addr)) {
89db4ad8 1208 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1209 return 1;
1210 }
1211
1212 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1213 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1214 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1215 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1216
89db4ad8 1217 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
619c5cb6
VZ
1218 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1219
1220 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1221 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1222 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1223 (REG_RD(bp, comp_addr)));
d16132ce
AE
1224 bnx2x_panic();
1225 return 1;
619c5cb6
VZ
1226 }
1227 /* Zero completion for nxt FLR */
1228 REG_WR(bp, comp_addr, 0);
1229
1230 return ret;
1231}
1232
b56e9670 1233u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
619c5cb6 1234{
619c5cb6
VZ
1235 u16 status;
1236
2a80eebc 1237 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
619c5cb6
VZ
1238 return status & PCI_EXP_DEVSTA_TRPND;
1239}
1240
1241/* PF FLR specific routines
1242*/
1243static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1244{
1245
1246 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1247 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1248 CFC_REG_NUM_LCIDS_INSIDE_PF,
1249 "CFC PF usage counter timed out",
1250 poll_cnt))
1251 return 1;
1252
1253
1254 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1255 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1256 DORQ_REG_PF_USAGE_CNT,
1257 "DQ PF usage counter timed out",
1258 poll_cnt))
1259 return 1;
1260
1261 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1262 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1263 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1264 "QM PF usage counter timed out",
1265 poll_cnt))
1266 return 1;
1267
1268 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1269 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1270 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1271 "Timers VNIC usage counter timed out",
1272 poll_cnt))
1273 return 1;
1274 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1275 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1276 "Timers NUM_SCANS usage counter timed out",
1277 poll_cnt))
1278 return 1;
1279
1280 /* Wait DMAE PF usage counter to zero */
1281 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1282 dmae_reg_go_c[INIT_DMAE_C(bp)],
1283 "DMAE dommand register timed out",
1284 poll_cnt))
1285 return 1;
1286
1287 return 0;
1288}
1289
1290static void bnx2x_hw_enable_status(struct bnx2x *bp)
1291{
1292 u32 val;
1293
1294 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1295 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1296
1297 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1298 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1299
1300 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1301 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1302
1303 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1304 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1305
1306 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1307 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1308
1309 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1310 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1311
1312 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1313 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1314
1315 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1316 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1317 val);
1318}
1319
1320static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1321{
1322 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1323
1324 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1325
1326 /* Re-enable PF target read access */
1327 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1328
1329 /* Poll HW usage counters */
89db4ad8 1330 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1331 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1332 return -EBUSY;
1333
1334 /* Zero the igu 'trailing edge' and 'leading edge' */
1335
1336 /* Send the FW cleanup command */
1337 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1338 return -EBUSY;
1339
1340 /* ATC cleanup */
1341
1342 /* Verify TX hw is flushed */
1343 bnx2x_tx_hw_flushed(bp, poll_cnt);
1344
1345 /* Wait 100ms (not adjusted according to platform) */
1346 msleep(100);
1347
1348 /* Verify no pending pci transactions */
1349 if (bnx2x_is_pcie_pending(bp->pdev))
1350 BNX2X_ERR("PCIE Transactions still pending\n");
1351
1352 /* Debug */
1353 bnx2x_hw_enable_status(bp);
1354
1355 /*
1356 * Master enable - Due to WB DMAE writes performed before this
1357 * register is re-initialized as part of the regular function init
1358 */
1359 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1360
1361 return 0;
1362}
1363
f2e0899f 1364static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1365{
34f80b04 1366 int port = BP_PORT(bp);
a2fbb9ea
ET
1367 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1368 u32 val = REG_RD(bp, addr);
69c326b3
DK
1369 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1370 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1371 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
a2fbb9ea
ET
1372
1373 if (msix) {
8badd27a
EG
1374 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1375 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1376 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1377 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
69c326b3
DK
1378 if (single_msix)
1379 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
8badd27a
EG
1380 } else if (msi) {
1381 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1382 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1383 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1384 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea
ET
1385 } else {
1386 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1387 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1388 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1389 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1390
a0fd065c 1391 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1392 DP(NETIF_MSG_IFUP,
1393 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1394
a0fd065c 1395 REG_WR(bp, addr, val);
615f8fd9 1396
a0fd065c
DK
1397 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1398 }
a2fbb9ea
ET
1399 }
1400
a0fd065c
DK
1401 if (CHIP_IS_E1(bp))
1402 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1403
51c1a580
MS
1404 DP(NETIF_MSG_IFUP,
1405 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1406 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1407
1408 REG_WR(bp, addr, val);
37dbbf32
EG
1409 /*
1410 * Ensure that HC_CONFIG is written before leading/trailing edge config
1411 */
1412 mmiowb();
1413 barrier();
34f80b04 1414
f2e0899f 1415 if (!CHIP_IS_E1(bp)) {
34f80b04 1416 /* init leading/trailing edge */
fb3bff17 1417 if (IS_MF(bp)) {
3395a033 1418 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1419 if (bp->port.pmf)
4acac6a5
EG
1420 /* enable nig and gpio3 attention */
1421 val |= 0x1100;
34f80b04
EG
1422 } else
1423 val = 0xffff;
1424
1425 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1426 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1427 }
37dbbf32
EG
1428
1429 /* Make sure that interrupts are indeed enabled from here on */
1430 mmiowb();
a2fbb9ea
ET
1431}
1432
f2e0899f
DK
1433static void bnx2x_igu_int_enable(struct bnx2x *bp)
1434{
1435 u32 val;
30a5de77
DK
1436 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1437 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1438 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
f2e0899f
DK
1439
1440 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1441
1442 if (msix) {
1443 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1444 IGU_PF_CONF_SINGLE_ISR_EN);
1445 val |= (IGU_PF_CONF_FUNC_EN |
1446 IGU_PF_CONF_MSI_MSIX_EN |
1447 IGU_PF_CONF_ATTN_BIT_EN);
30a5de77
DK
1448
1449 if (single_msix)
1450 val |= IGU_PF_CONF_SINGLE_ISR_EN;
f2e0899f
DK
1451 } else if (msi) {
1452 val &= ~IGU_PF_CONF_INT_LINE_EN;
1453 val |= (IGU_PF_CONF_FUNC_EN |
1454 IGU_PF_CONF_MSI_MSIX_EN |
1455 IGU_PF_CONF_ATTN_BIT_EN |
1456 IGU_PF_CONF_SINGLE_ISR_EN);
1457 } else {
1458 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1459 val |= (IGU_PF_CONF_FUNC_EN |
1460 IGU_PF_CONF_INT_LINE_EN |
1461 IGU_PF_CONF_ATTN_BIT_EN |
1462 IGU_PF_CONF_SINGLE_ISR_EN);
1463 }
1464
51c1a580 1465 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1466 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1467
1468 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1469
79a8557a
YM
1470 if (val & IGU_PF_CONF_INT_LINE_EN)
1471 pci_intx(bp->pdev, true);
1472
f2e0899f
DK
1473 barrier();
1474
1475 /* init leading/trailing edge */
1476 if (IS_MF(bp)) {
3395a033 1477 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1478 if (bp->port.pmf)
1479 /* enable nig and gpio3 attention */
1480 val |= 0x1100;
1481 } else
1482 val = 0xffff;
1483
1484 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1485 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1486
1487 /* Make sure that interrupts are indeed enabled from here on */
1488 mmiowb();
1489}
1490
1491void bnx2x_int_enable(struct bnx2x *bp)
1492{
1493 if (bp->common.int_block == INT_BLOCK_HC)
1494 bnx2x_hc_int_enable(bp);
1495 else
1496 bnx2x_igu_int_enable(bp);
1497}
1498
1499static void bnx2x_hc_int_disable(struct bnx2x *bp)
a2fbb9ea 1500{
34f80b04 1501 int port = BP_PORT(bp);
a2fbb9ea
ET
1502 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1503 u32 val = REG_RD(bp, addr);
1504
a0fd065c
DK
1505 /*
1506 * in E1 we must use only PCI configuration space to disable
1507 * MSI/MSIX capablility
1508 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1509 */
1510 if (CHIP_IS_E1(bp)) {
1511 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1512 * Use mask register to prevent from HC sending interrupts
1513 * after we exit the function
1514 */
1515 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1516
1517 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1518 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1519 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1520 } else
1521 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1522 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1523 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1524 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea 1525
51c1a580
MS
1526 DP(NETIF_MSG_IFDOWN,
1527 "write %x to HC %d (addr 0x%x)\n",
a2fbb9ea
ET
1528 val, port, addr);
1529
8badd27a
EG
1530 /* flush all outstanding writes */
1531 mmiowb();
1532
a2fbb9ea
ET
1533 REG_WR(bp, addr, val);
1534 if (REG_RD(bp, addr) != val)
1535 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1536}
1537
f2e0899f
DK
1538static void bnx2x_igu_int_disable(struct bnx2x *bp)
1539{
1540 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1541
1542 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1543 IGU_PF_CONF_INT_LINE_EN |
1544 IGU_PF_CONF_ATTN_BIT_EN);
1545
51c1a580 1546 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
f2e0899f
DK
1547
1548 /* flush all outstanding writes */
1549 mmiowb();
1550
1551 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1552 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1553 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1554}
1555
910cc727 1556static void bnx2x_int_disable(struct bnx2x *bp)
f2e0899f
DK
1557{
1558 if (bp->common.int_block == INT_BLOCK_HC)
1559 bnx2x_hc_int_disable(bp);
1560 else
1561 bnx2x_igu_int_disable(bp);
1562}
1563
9f6c9258 1564void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1565{
a2fbb9ea 1566 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1567 int i, offset;
a2fbb9ea 1568
f8ef6e44
YG
1569 if (disable_hw)
1570 /* prevent the HW from sending interrupts */
1571 bnx2x_int_disable(bp);
a2fbb9ea
ET
1572
1573 /* make sure all ISRs are done */
1574 if (msix) {
8badd27a
EG
1575 synchronize_irq(bp->msix_table[0].vector);
1576 offset = 1;
55c11941
MS
1577 if (CNIC_SUPPORT(bp))
1578 offset++;
ec6ba945 1579 for_each_eth_queue(bp, i)
754a2f52 1580 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1581 } else
1582 synchronize_irq(bp->pdev->irq);
1583
1584 /* make sure sp_task is not running */
1cf167f2 1585 cancel_delayed_work(&bp->sp_task);
3deb8167 1586 cancel_delayed_work(&bp->period_task);
1cf167f2 1587 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1588}
1589
34f80b04 1590/* fast path */
a2fbb9ea
ET
1591
1592/*
34f80b04 1593 * General service functions
a2fbb9ea
ET
1594 */
1595
72fd0718
VZ
1596/* Return true if succeeded to acquire the lock */
1597static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1598{
1599 u32 lock_status;
1600 u32 resource_bit = (1 << resource);
1601 int func = BP_FUNC(bp);
1602 u32 hw_lock_control_reg;
1603
51c1a580
MS
1604 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1605 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1606
1607 /* Validating that the resource is within range */
1608 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1609 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1610 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1611 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1612 return false;
72fd0718
VZ
1613 }
1614
1615 if (func <= 5)
1616 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1617 else
1618 hw_lock_control_reg =
1619 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1620
1621 /* Try to acquire the lock */
1622 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1623 lock_status = REG_RD(bp, hw_lock_control_reg);
1624 if (lock_status & resource_bit)
1625 return true;
1626
51c1a580
MS
1627 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1628 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1629 return false;
1630}
1631
c9ee9206
VZ
1632/**
1633 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1634 *
1635 * @bp: driver handle
1636 *
1637 * Returns the recovery leader resource id according to the engine this function
1638 * belongs to. Currently only only 2 engines is supported.
1639 */
1191cb83 1640static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
c9ee9206
VZ
1641{
1642 if (BP_PATH(bp))
1643 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1644 else
1645 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1646}
1647
1648/**
1649 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1650 *
1651 * @bp: driver handle
1652 *
1191cb83 1653 * Tries to aquire a leader lock for current engine.
c9ee9206 1654 */
1191cb83 1655static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
c9ee9206
VZ
1656{
1657 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1658}
1659
619c5cb6 1660static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
55c11941 1661
fd1fc79d
AE
1662/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1663static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1664{
1665 /* Set the interrupt occurred bit for the sp-task to recognize it
1666 * must ack the interrupt and transition according to the IGU
1667 * state machine.
1668 */
1669 atomic_set(&bp->interrupt_occurred, 1);
1670
1671 /* The sp_task must execute only after this bit
1672 * is set, otherwise we will get out of sync and miss all
1673 * further interrupts. Hence, the barrier.
1674 */
1675 smp_wmb();
1676
1677 /* schedule sp_task to workqueue */
1678 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1679}
3196a88a 1680
619c5cb6 1681void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1682{
1683 struct bnx2x *bp = fp->bp;
1684 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1685 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6 1686 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
15192a8c 1687 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a2fbb9ea 1688
34f80b04 1689 DP(BNX2X_MSG_SP,
a2fbb9ea 1690 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1691 fp->index, cid, command, bp->state,
34f80b04 1692 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1693
fd1fc79d
AE
1694 /* If cid is within VF range, replace the slowpath object with the
1695 * one corresponding to this VF
1696 */
1697 if (cid >= BNX2X_FIRST_VF_CID &&
1698 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1699 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1700
619c5cb6
VZ
1701 switch (command) {
1702 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1703 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1704 drv_cmd = BNX2X_Q_CMD_UPDATE;
1705 break;
d6cae238 1706
619c5cb6 1707 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1708 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1709 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1710 break;
1711
6383c0b3 1712 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1713 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1714 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1715 break;
1716
619c5cb6 1717 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1718 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1719 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1720 break;
1721
619c5cb6 1722 case (RAMROD_CMD_ID_ETH_TERMINATE):
d6cae238 1723 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
619c5cb6 1724 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1725 break;
1726
619c5cb6 1727 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1728 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1729 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1730 break;
619c5cb6
VZ
1731
1732 default:
1733 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1734 command, fp->index);
1735 return;
523224a3 1736 }
3196a88a 1737
619c5cb6
VZ
1738 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1739 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1740 /* q_obj->complete_cmd() failure means that this was
1741 * an unexpected completion.
1742 *
1743 * In this case we don't want to increase the bp->spq_left
1744 * because apparently we haven't sent this command the first
1745 * place.
1746 */
1747#ifdef BNX2X_STOP_ON_ERROR
1748 bnx2x_panic();
1749#else
1750 return;
1751#endif
fd1fc79d
AE
1752 /* SRIOV: reschedule any 'in_progress' operations */
1753 bnx2x_iov_sp_event(bp, cid, true);
619c5cb6 1754
8fe23fbd 1755 smp_mb__before_atomic_inc();
6e30dd4e 1756 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1757 /* push the change in bp->spq_left and towards the memory */
1758 smp_mb__after_atomic_inc();
49d66772 1759
d6cae238
VZ
1760 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1761
a3348722
BW
1762 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1763 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1764 /* if Q update ramrod is completed for last Q in AFEX vif set
1765 * flow, then ACK MCP at the end
1766 *
1767 * mark pending ACK to MCP bit.
1768 * prevent case that both bits are cleared.
1769 * At the end of load/unload driver checks that
1770 * sp_state is cleaerd, and this order prevents
1771 * races
1772 */
1773 smp_mb__before_clear_bit();
1774 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1775 wmb();
1776 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1777 smp_mb__after_clear_bit();
1778
fd1fc79d
AE
1779 /* schedule the sp task as mcp ack is required */
1780 bnx2x_schedule_sp_task(bp);
a3348722
BW
1781 }
1782
523224a3 1783 return;
a2fbb9ea
ET
1784}
1785
9f6c9258 1786irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1787{
555f6c78 1788 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1789 u16 status = bnx2x_ack_int(bp);
34f80b04 1790 u16 mask;
ca00392c 1791 int i;
6383c0b3 1792 u8 cos;
a2fbb9ea 1793
34f80b04 1794 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1795 if (unlikely(status == 0)) {
1796 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1797 return IRQ_NONE;
1798 }
f5372251 1799 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1800
3196a88a
EG
1801#ifdef BNX2X_STOP_ON_ERROR
1802 if (unlikely(bp->panic))
1803 return IRQ_HANDLED;
1804#endif
1805
ec6ba945 1806 for_each_eth_queue(bp, i) {
ca00392c 1807 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1808
55c11941 1809 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
ca00392c 1810 if (status & mask) {
619c5cb6 1811 /* Handle Rx or Tx according to SB id */
54b9ddaa 1812 prefetch(fp->rx_cons_sb);
6383c0b3 1813 for_each_cos_in_tx_queue(fp, cos)
65565884 1814 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
523224a3 1815 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1816 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1817 status &= ~mask;
1818 }
a2fbb9ea
ET
1819 }
1820
55c11941
MS
1821 if (CNIC_SUPPORT(bp)) {
1822 mask = 0x2;
1823 if (status & (mask | 0x1)) {
1824 struct cnic_ops *c_ops = NULL;
993ac7b5 1825
55c11941
MS
1826 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1827 rcu_read_lock();
1828 c_ops = rcu_dereference(bp->cnic_ops);
1829 if (c_ops)
1830 c_ops->cnic_handler(bp->cnic_data,
1831 NULL);
1832 rcu_read_unlock();
1833 }
993ac7b5 1834
55c11941
MS
1835 status &= ~mask;
1836 }
993ac7b5 1837 }
a2fbb9ea 1838
34f80b04 1839 if (unlikely(status & 0x1)) {
fd1fc79d
AE
1840
1841 /* schedule sp task to perform default status block work, ack
1842 * attentions and enable interrupts.
1843 */
1844 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
1845
1846 status &= ~0x1;
1847 if (!status)
1848 return IRQ_HANDLED;
1849 }
1850
cdaa7cb8
VZ
1851 if (unlikely(status))
1852 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1853 status);
a2fbb9ea 1854
c18487ee 1855 return IRQ_HANDLED;
a2fbb9ea
ET
1856}
1857
c18487ee
YR
1858/* Link */
1859
1860/*
1861 * General service functions
1862 */
a2fbb9ea 1863
9f6c9258 1864int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1865{
1866 u32 lock_status;
1867 u32 resource_bit = (1 << resource);
4a37fb66
YG
1868 int func = BP_FUNC(bp);
1869 u32 hw_lock_control_reg;
c18487ee 1870 int cnt;
a2fbb9ea 1871
c18487ee
YR
1872 /* Validating that the resource is within range */
1873 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1874 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1875 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1876 return -EINVAL;
1877 }
a2fbb9ea 1878
4a37fb66
YG
1879 if (func <= 5) {
1880 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1881 } else {
1882 hw_lock_control_reg =
1883 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1884 }
1885
c18487ee 1886 /* Validating that the resource is not already taken */
4a37fb66 1887 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1888 if (lock_status & resource_bit) {
51c1a580 1889 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
c18487ee
YR
1890 lock_status, resource_bit);
1891 return -EEXIST;
1892 }
a2fbb9ea 1893
46230476
EG
1894 /* Try for 5 second every 5ms */
1895 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1896 /* Try to acquire the lock */
4a37fb66
YG
1897 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1898 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1899 if (lock_status & resource_bit)
1900 return 0;
a2fbb9ea 1901
c18487ee 1902 msleep(5);
a2fbb9ea 1903 }
51c1a580 1904 BNX2X_ERR("Timeout\n");
c18487ee
YR
1905 return -EAGAIN;
1906}
a2fbb9ea 1907
c9ee9206
VZ
1908int bnx2x_release_leader_lock(struct bnx2x *bp)
1909{
1910 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1911}
1912
9f6c9258 1913int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1914{
1915 u32 lock_status;
1916 u32 resource_bit = (1 << resource);
4a37fb66
YG
1917 int func = BP_FUNC(bp);
1918 u32 hw_lock_control_reg;
a2fbb9ea 1919
c18487ee
YR
1920 /* Validating that the resource is within range */
1921 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1922 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1923 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1924 return -EINVAL;
1925 }
1926
4a37fb66
YG
1927 if (func <= 5) {
1928 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1929 } else {
1930 hw_lock_control_reg =
1931 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1932 }
1933
c18487ee 1934 /* Validating that the resource is currently taken */
4a37fb66 1935 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1936 if (!(lock_status & resource_bit)) {
51c1a580 1937 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
c18487ee
YR
1938 lock_status, resource_bit);
1939 return -EFAULT;
a2fbb9ea
ET
1940 }
1941
9f6c9258
DK
1942 REG_WR(bp, hw_lock_control_reg, resource_bit);
1943 return 0;
c18487ee 1944}
a2fbb9ea 1945
9f6c9258 1946
4acac6a5
EG
1947int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1948{
1949 /* The GPIO should be swapped if swap register is set and active */
1950 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1951 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1952 int gpio_shift = gpio_num +
1953 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1954 u32 gpio_mask = (1 << gpio_shift);
1955 u32 gpio_reg;
1956 int value;
1957
1958 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1959 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1960 return -EINVAL;
1961 }
1962
1963 /* read GPIO value */
1964 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1965
1966 /* get the requested pin value */
1967 if ((gpio_reg & gpio_mask) == gpio_mask)
1968 value = 1;
1969 else
1970 value = 0;
1971
1972 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1973
1974 return value;
1975}
1976
17de50b7 1977int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
1978{
1979 /* The GPIO should be swapped if swap register is set and active */
1980 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 1981 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
1982 int gpio_shift = gpio_num +
1983 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1984 u32 gpio_mask = (1 << gpio_shift);
1985 u32 gpio_reg;
a2fbb9ea 1986
c18487ee
YR
1987 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1988 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1989 return -EINVAL;
1990 }
a2fbb9ea 1991
4a37fb66 1992 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
1993 /* read GPIO and mask except the float bits */
1994 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 1995
c18487ee
YR
1996 switch (mode) {
1997 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
1998 DP(NETIF_MSG_LINK,
1999 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
2000 gpio_num, gpio_shift);
2001 /* clear FLOAT and set CLR */
2002 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2003 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2004 break;
a2fbb9ea 2005
c18487ee 2006 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
2007 DP(NETIF_MSG_LINK,
2008 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
2009 gpio_num, gpio_shift);
2010 /* clear FLOAT and set SET */
2011 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2012 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2013 break;
a2fbb9ea 2014
17de50b7 2015 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
2016 DP(NETIF_MSG_LINK,
2017 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
2018 gpio_num, gpio_shift);
2019 /* set FLOAT */
2020 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2021 break;
a2fbb9ea 2022
c18487ee
YR
2023 default:
2024 break;
a2fbb9ea
ET
2025 }
2026
c18487ee 2027 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 2028 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 2029
c18487ee 2030 return 0;
a2fbb9ea
ET
2031}
2032
0d40f0d4
YR
2033int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2034{
2035 u32 gpio_reg = 0;
2036 int rc = 0;
2037
2038 /* Any port swapping should be handled by caller. */
2039
2040 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2041 /* read GPIO and mask except the float bits */
2042 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2043 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2044 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2045 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2046
2047 switch (mode) {
2048 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2049 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2050 /* set CLR */
2051 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2052 break;
2053
2054 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2055 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2056 /* set SET */
2057 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2058 break;
2059
2060 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2061 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2062 /* set FLOAT */
2063 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2064 break;
2065
2066 default:
2067 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2068 rc = -EINVAL;
2069 break;
2070 }
2071
2072 if (rc == 0)
2073 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2074
2075 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2076
2077 return rc;
2078}
2079
4acac6a5
EG
2080int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2081{
2082 /* The GPIO should be swapped if swap register is set and active */
2083 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2084 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2085 int gpio_shift = gpio_num +
2086 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2087 u32 gpio_mask = (1 << gpio_shift);
2088 u32 gpio_reg;
2089
2090 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2091 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2092 return -EINVAL;
2093 }
2094
2095 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2096 /* read GPIO int */
2097 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2098
2099 switch (mode) {
2100 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
2101 DP(NETIF_MSG_LINK,
2102 "Clear GPIO INT %d (shift %d) -> output low\n",
2103 gpio_num, gpio_shift);
4acac6a5
EG
2104 /* clear SET and set CLR */
2105 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2106 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2107 break;
2108
2109 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
2110 DP(NETIF_MSG_LINK,
2111 "Set GPIO INT %d (shift %d) -> output high\n",
2112 gpio_num, gpio_shift);
4acac6a5
EG
2113 /* clear CLR and set SET */
2114 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2115 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2116 break;
2117
2118 default:
2119 break;
2120 }
2121
2122 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2123 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2124
2125 return 0;
2126}
2127
d6d99a3f 2128static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
a2fbb9ea 2129{
c18487ee 2130 u32 spio_reg;
a2fbb9ea 2131
d6d99a3f
YM
2132 /* Only 2 SPIOs are configurable */
2133 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2134 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
c18487ee 2135 return -EINVAL;
a2fbb9ea
ET
2136 }
2137
4a37fb66 2138 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2139 /* read SPIO and mask except the float bits */
d6d99a3f 2140 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
a2fbb9ea 2141
c18487ee 2142 switch (mode) {
d6d99a3f
YM
2143 case MISC_SPIO_OUTPUT_LOW:
2144 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
c18487ee 2145 /* clear FLOAT and set CLR */
d6d99a3f
YM
2146 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2147 spio_reg |= (spio << MISC_SPIO_CLR_POS);
c18487ee 2148 break;
a2fbb9ea 2149
d6d99a3f
YM
2150 case MISC_SPIO_OUTPUT_HIGH:
2151 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
c18487ee 2152 /* clear FLOAT and set SET */
d6d99a3f
YM
2153 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2154 spio_reg |= (spio << MISC_SPIO_SET_POS);
c18487ee 2155 break;
a2fbb9ea 2156
d6d99a3f
YM
2157 case MISC_SPIO_INPUT_HI_Z:
2158 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
c18487ee 2159 /* set FLOAT */
d6d99a3f 2160 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
c18487ee 2161 break;
a2fbb9ea 2162
c18487ee
YR
2163 default:
2164 break;
a2fbb9ea
ET
2165 }
2166
c18487ee 2167 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2168 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2169
a2fbb9ea
ET
2170 return 0;
2171}
2172
9f6c9258 2173void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2174{
a22f0788 2175 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2176 switch (bp->link_vars.ieee_fc &
2177 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2178 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2179 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2180 ADVERTISED_Pause);
c18487ee 2181 break;
356e2385 2182
c18487ee 2183 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2184 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2185 ADVERTISED_Pause);
c18487ee 2186 break;
356e2385 2187
c18487ee 2188 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2189 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2190 break;
356e2385 2191
c18487ee 2192 default:
a22f0788 2193 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2194 ADVERTISED_Pause);
c18487ee
YR
2195 break;
2196 }
2197}
f1410647 2198
cd1dfce2 2199static void bnx2x_set_requested_fc(struct bnx2x *bp)
c18487ee 2200{
cd1dfce2
YM
2201 /* Initialize link parameters structure variables
2202 * It is recommended to turn off RX FC for jumbo frames
2203 * for better performance
2204 */
2205 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2206 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2207 else
2208 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2209}
a2fbb9ea 2210
cd1dfce2
YM
2211int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2212{
2213 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2214 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2215
2216 if (!BP_NOMCP(bp)) {
2217 bnx2x_set_requested_fc(bp);
4a37fb66 2218 bnx2x_acquire_phy_lock(bp);
b5bf9068 2219
a22f0788 2220 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2221 struct link_params *lp = &bp->link_params;
2222 lp->loopback_mode = LOOPBACK_XGXS;
2223 /* do PHY loopback at 10G speed, if possible */
2224 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2225 if (lp->speed_cap_mask[cfx_idx] &
2226 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2227 lp->req_line_speed[cfx_idx] =
2228 SPEED_10000;
2229 else
2230 lp->req_line_speed[cfx_idx] =
2231 SPEED_1000;
2232 }
a22f0788 2233 }
b5bf9068 2234
8970b2e4
MS
2235 if (load_mode == LOAD_LOOPBACK_EXT) {
2236 struct link_params *lp = &bp->link_params;
2237 lp->loopback_mode = LOOPBACK_EXT;
2238 }
2239
19680c48 2240 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2241
4a37fb66 2242 bnx2x_release_phy_lock(bp);
a2fbb9ea 2243
3c96c68b
EG
2244 bnx2x_calc_fc_adv(bp);
2245
cd1dfce2 2246 if (bp->link_vars.link_up) {
b5bf9068 2247 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2248 bnx2x_link_report(bp);
cd1dfce2
YM
2249 }
2250 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2251 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2252 return rc;
2253 }
f5372251 2254 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2255 return -EINVAL;
a2fbb9ea
ET
2256}
2257
9f6c9258 2258void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2259{
19680c48 2260 if (!BP_NOMCP(bp)) {
4a37fb66 2261 bnx2x_acquire_phy_lock(bp);
19680c48 2262 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2263 bnx2x_release_phy_lock(bp);
a2fbb9ea 2264
19680c48
EG
2265 bnx2x_calc_fc_adv(bp);
2266 } else
f5372251 2267 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2268}
a2fbb9ea 2269
c18487ee
YR
2270static void bnx2x__link_reset(struct bnx2x *bp)
2271{
19680c48 2272 if (!BP_NOMCP(bp)) {
4a37fb66 2273 bnx2x_acquire_phy_lock(bp);
5d07d868 2274 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2275 bnx2x_release_phy_lock(bp);
19680c48 2276 } else
f5372251 2277 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2278}
a2fbb9ea 2279
5d07d868
YM
2280void bnx2x_force_link_reset(struct bnx2x *bp)
2281{
2282 bnx2x_acquire_phy_lock(bp);
2283 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2284 bnx2x_release_phy_lock(bp);
2285}
2286
a22f0788 2287u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2288{
2145a920 2289 u8 rc = 0;
a2fbb9ea 2290
2145a920
VZ
2291 if (!BP_NOMCP(bp)) {
2292 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2293 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2294 is_serdes);
2145a920
VZ
2295 bnx2x_release_phy_lock(bp);
2296 } else
2297 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2298
c18487ee
YR
2299 return rc;
2300}
a2fbb9ea 2301
34f80b04 2302
2691d51d
EG
2303/* Calculates the sum of vn_min_rates.
2304 It's needed for further normalizing of the min_rates.
2305 Returns:
2306 sum of vn_min_rates.
2307 or
2308 0 - if all the min_rates are 0.
2309 In the later case fainess algorithm should be deactivated.
2310 If not all min_rates are zero then those that are zeroes will be set to 1.
2311 */
b475d78f
YM
2312static void bnx2x_calc_vn_min(struct bnx2x *bp,
2313 struct cmng_init_input *input)
2691d51d
EG
2314{
2315 int all_zero = 1;
2691d51d
EG
2316 int vn;
2317
3395a033 2318 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2319 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2320 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2321 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2322
2323 /* Skip hidden vns */
2324 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2325 vn_min_rate = 0;
2691d51d 2326 /* If min rate is zero - set it to 1 */
b475d78f 2327 else if (!vn_min_rate)
2691d51d
EG
2328 vn_min_rate = DEF_MIN_RATE;
2329 else
2330 all_zero = 0;
2331
b475d78f 2332 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2333 }
2334
30ae438b
DK
2335 /* if ETS or all min rates are zeros - disable fairness */
2336 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2337 input->flags.cmng_enables &=
30ae438b
DK
2338 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2339 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2340 } else if (all_zero) {
b475d78f 2341 input->flags.cmng_enables &=
b015e3d1 2342 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2343 DP(NETIF_MSG_IFUP,
2344 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2345 } else
b475d78f 2346 input->flags.cmng_enables |=
b015e3d1 2347 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2348}
2349
b475d78f
YM
2350static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2351 struct cmng_init_input *input)
34f80b04 2352{
b475d78f 2353 u16 vn_max_rate;
f2e0899f 2354 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2355
b475d78f 2356 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2357 vn_max_rate = 0;
b475d78f 2358 else {
faa6fcbb
DK
2359 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2360
b475d78f 2361 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2362 /* maxCfg in percents of linkspeed */
2363 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2364 } else /* SD modes */
faa6fcbb
DK
2365 /* maxCfg is absolute in 100Mb units */
2366 vn_max_rate = maxCfg * 100;
34f80b04 2367 }
f85582f8 2368
b475d78f 2369 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2370
b475d78f 2371 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2372}
f85582f8 2373
b475d78f 2374
523224a3
DK
2375static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2376{
2377 if (CHIP_REV_IS_SLOW(bp))
2378 return CMNG_FNS_NONE;
fb3bff17 2379 if (IS_MF(bp))
523224a3
DK
2380 return CMNG_FNS_MINMAX;
2381
2382 return CMNG_FNS_NONE;
2383}
2384
2ae17f66 2385void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2386{
0793f83f 2387 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2388
2389 if (BP_NOMCP(bp))
2390 return; /* what should be the default bvalue in this case */
2391
0793f83f
DK
2392 /* For 2 port configuration the absolute function number formula
2393 * is:
2394 * abs_func = 2 * vn + BP_PORT + BP_PATH
2395 *
2396 * and there are 4 functions per port
2397 *
2398 * For 4 port configuration it is
2399 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2400 *
2401 * and there are 2 functions per port
2402 */
3395a033 2403 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2404 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2405
2406 if (func >= E1H_FUNC_MAX)
2407 break;
2408
f2e0899f 2409 bp->mf_config[vn] =
523224a3
DK
2410 MF_CFG_RD(bp, func_mf_config[func].config);
2411 }
a3348722
BW
2412 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2413 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2414 bp->flags |= MF_FUNC_DIS;
2415 } else {
2416 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2417 bp->flags &= ~MF_FUNC_DIS;
2418 }
523224a3
DK
2419}
2420
2421static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2422{
b475d78f
YM
2423 struct cmng_init_input input;
2424 memset(&input, 0, sizeof(struct cmng_init_input));
2425
2426 input.port_rate = bp->link_vars.line_speed;
523224a3
DK
2427
2428 if (cmng_type == CMNG_FNS_MINMAX) {
2429 int vn;
2430
523224a3
DK
2431 /* read mf conf from shmem */
2432 if (read_cfg)
2433 bnx2x_read_mf_cfg(bp);
2434
523224a3 2435 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2436 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2437
2438 /* calculate and set min-max rate for each vn */
c4154f25 2439 if (bp->port.pmf)
3395a033 2440 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2441 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2442
2443 /* always enable rate shaping and fairness */
b475d78f 2444 input.flags.cmng_enables |=
523224a3 2445 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2446
2447 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2448 return;
2449 }
2450
2451 /* rate shaping and fairness are disabled */
2452 DP(NETIF_MSG_IFUP,
2453 "rate shaping and fairness are disabled\n");
2454}
34f80b04 2455
1191cb83
ED
2456static void storm_memset_cmng(struct bnx2x *bp,
2457 struct cmng_init *cmng,
2458 u8 port)
2459{
2460 int vn;
2461 size_t size = sizeof(struct cmng_struct_per_port);
2462
2463 u32 addr = BAR_XSTRORM_INTMEM +
2464 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2465
2466 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2467
2468 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2469 int func = func_by_vn(bp, vn);
2470
2471 addr = BAR_XSTRORM_INTMEM +
2472 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2473 size = sizeof(struct rate_shaping_vars_per_vn);
2474 __storm_memset_struct(bp, addr, size,
2475 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2476
2477 addr = BAR_XSTRORM_INTMEM +
2478 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2479 size = sizeof(struct fairness_vars_per_vn);
2480 __storm_memset_struct(bp, addr, size,
2481 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2482 }
2483}
2484
c18487ee
YR
2485/* This function is called upon link interrupt */
2486static void bnx2x_link_attn(struct bnx2x *bp)
2487{
bb2a0f7a
YG
2488 /* Make sure that we are synced with the current statistics */
2489 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2490
c18487ee 2491 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2492
bb2a0f7a
YG
2493 if (bp->link_vars.link_up) {
2494
1c06328c 2495 /* dropless flow control */
f2e0899f 2496 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2497 int port = BP_PORT(bp);
2498 u32 pause_enabled = 0;
2499
2500 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2501 pause_enabled = 1;
2502
2503 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2504 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2505 pause_enabled);
2506 }
2507
619c5cb6 2508 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2509 struct host_port_stats *pstats;
2510
2511 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2512 /* reset old mac stats */
bb2a0f7a
YG
2513 memset(&(pstats->mac_stx[0]), 0,
2514 sizeof(struct mac_stx));
2515 }
f34d28ea 2516 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2517 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2518 }
2519
f2e0899f
DK
2520 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2521 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2522
f2e0899f
DK
2523 if (cmng_fns != CMNG_FNS_NONE) {
2524 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2525 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2526 } else
2527 /* rate shaping and fairness are disabled */
2528 DP(NETIF_MSG_IFUP,
2529 "single function mode without fairness\n");
34f80b04 2530 }
9fdc3e95 2531
2ae17f66
VZ
2532 __bnx2x_link_report(bp);
2533
9fdc3e95
DK
2534 if (IS_MF(bp))
2535 bnx2x_link_sync_notify(bp);
c18487ee 2536}
a2fbb9ea 2537
9f6c9258 2538void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2539{
2ae17f66 2540 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2541 return;
a2fbb9ea 2542
00253a8c 2543 /* read updated dcb configuration */
ad5afc89
AE
2544 if (IS_PF(bp)) {
2545 bnx2x_dcbx_pmf_update(bp);
2546 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2547 if (bp->link_vars.link_up)
2548 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2549 else
2550 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2551 /* indicate link status */
2552 bnx2x_link_report(bp);
a2fbb9ea 2553
ad5afc89
AE
2554 } else { /* VF */
2555 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2556 SUPPORTED_10baseT_Full |
2557 SUPPORTED_100baseT_Half |
2558 SUPPORTED_100baseT_Full |
2559 SUPPORTED_1000baseT_Full |
2560 SUPPORTED_2500baseX_Full |
2561 SUPPORTED_10000baseT_Full |
2562 SUPPORTED_TP |
2563 SUPPORTED_FIBRE |
2564 SUPPORTED_Autoneg |
2565 SUPPORTED_Pause |
2566 SUPPORTED_Asym_Pause);
2567 bp->port.advertising[0] = bp->port.supported[0];
2568
2569 bp->link_params.bp = bp;
2570 bp->link_params.port = BP_PORT(bp);
2571 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2572 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2573 bp->link_params.req_line_speed[0] = SPEED_10000;
2574 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2575 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2576 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2577 bp->link_vars.line_speed = SPEED_10000;
2578 bp->link_vars.link_status =
2579 (LINK_STATUS_LINK_UP |
2580 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2581 bp->link_vars.link_up = 1;
2582 bp->link_vars.duplex = DUPLEX_FULL;
2583 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2584 __bnx2x_link_report(bp);
bb2a0f7a 2585 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
ad5afc89 2586 }
a2fbb9ea 2587}
a2fbb9ea 2588
a3348722
BW
2589static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2590 u16 vlan_val, u8 allowed_prio)
2591{
2592 struct bnx2x_func_state_params func_params = {0};
2593 struct bnx2x_func_afex_update_params *f_update_params =
2594 &func_params.params.afex_update;
2595
2596 func_params.f_obj = &bp->func_obj;
2597 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2598
2599 /* no need to wait for RAMROD completion, so don't
2600 * set RAMROD_COMP_WAIT flag
2601 */
2602
2603 f_update_params->vif_id = vifid;
2604 f_update_params->afex_default_vlan = vlan_val;
2605 f_update_params->allowed_priorities = allowed_prio;
2606
2607 /* if ramrod can not be sent, response to MCP immediately */
2608 if (bnx2x_func_state_change(bp, &func_params) < 0)
2609 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2610
2611 return 0;
2612}
2613
2614static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2615 u16 vif_index, u8 func_bit_map)
2616{
2617 struct bnx2x_func_state_params func_params = {0};
2618 struct bnx2x_func_afex_viflists_params *update_params =
2619 &func_params.params.afex_viflists;
2620 int rc;
2621 u32 drv_msg_code;
2622
2623 /* validate only LIST_SET and LIST_GET are received from switch */
2624 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2625 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2626 cmd_type);
2627
2628 func_params.f_obj = &bp->func_obj;
2629 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2630
2631 /* set parameters according to cmd_type */
2632 update_params->afex_vif_list_command = cmd_type;
2633 update_params->vif_list_index = cpu_to_le16(vif_index);
2634 update_params->func_bit_map =
2635 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2636 update_params->func_to_clear = 0;
2637 drv_msg_code =
2638 (cmd_type == VIF_LIST_RULE_GET) ?
2639 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2640 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2641
2642 /* if ramrod can not be sent, respond to MCP immediately for
2643 * SET and GET requests (other are not triggered from MCP)
2644 */
2645 rc = bnx2x_func_state_change(bp, &func_params);
2646 if (rc < 0)
2647 bnx2x_fw_command(bp, drv_msg_code, 0);
2648
2649 return 0;
2650}
2651
2652static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2653{
2654 struct afex_stats afex_stats;
2655 u32 func = BP_ABS_FUNC(bp);
2656 u32 mf_config;
2657 u16 vlan_val;
2658 u32 vlan_prio;
2659 u16 vif_id;
2660 u8 allowed_prio;
2661 u8 vlan_mode;
2662 u32 addr_to_write, vifid, addrs, stats_type, i;
2663
2664 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2665 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2666 DP(BNX2X_MSG_MCP,
2667 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2668 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2669 }
2670
2671 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2672 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2673 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2674 DP(BNX2X_MSG_MCP,
2675 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2676 vifid, addrs);
2677 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2678 addrs);
2679 }
2680
2681 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2682 addr_to_write = SHMEM2_RD(bp,
2683 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2684 stats_type = SHMEM2_RD(bp,
2685 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2686
2687 DP(BNX2X_MSG_MCP,
2688 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2689 addr_to_write);
2690
2691 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2692
2693 /* write response to scratchpad, for MCP */
2694 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2695 REG_WR(bp, addr_to_write + i*sizeof(u32),
2696 *(((u32 *)(&afex_stats))+i));
2697
2698 /* send ack message to MCP */
2699 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2700 }
2701
2702 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2703 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2704 bp->mf_config[BP_VN(bp)] = mf_config;
2705 DP(BNX2X_MSG_MCP,
2706 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2707 mf_config);
2708
2709 /* if VIF_SET is "enabled" */
2710 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2711 /* set rate limit directly to internal RAM */
2712 struct cmng_init_input cmng_input;
2713 struct rate_shaping_vars_per_vn m_rs_vn;
2714 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2715 u32 addr = BAR_XSTRORM_INTMEM +
2716 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2717
2718 bp->mf_config[BP_VN(bp)] = mf_config;
2719
2720 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2721 m_rs_vn.vn_counter.rate =
2722 cmng_input.vnic_max_rate[BP_VN(bp)];
2723 m_rs_vn.vn_counter.quota =
2724 (m_rs_vn.vn_counter.rate *
2725 RS_PERIODIC_TIMEOUT_USEC) / 8;
2726
2727 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2728
2729 /* read relevant values from mf_cfg struct in shmem */
2730 vif_id =
2731 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2732 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2733 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2734 vlan_val =
2735 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2736 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2737 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2738 vlan_prio = (mf_config &
2739 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2740 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2741 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2742 vlan_mode =
2743 (MF_CFG_RD(bp,
2744 func_mf_config[func].afex_config) &
2745 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2746 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2747 allowed_prio =
2748 (MF_CFG_RD(bp,
2749 func_mf_config[func].afex_config) &
2750 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2751 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2752
2753 /* send ramrod to FW, return in case of failure */
2754 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2755 allowed_prio))
2756 return;
2757
2758 bp->afex_def_vlan_tag = vlan_val;
2759 bp->afex_vlan_mode = vlan_mode;
2760 } else {
2761 /* notify link down because BP->flags is disabled */
2762 bnx2x_link_report(bp);
2763
2764 /* send INVALID VIF ramrod to FW */
2765 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2766
2767 /* Reset the default afex VLAN */
2768 bp->afex_def_vlan_tag = -1;
2769 }
2770 }
2771}
2772
34f80b04
EG
2773static void bnx2x_pmf_update(struct bnx2x *bp)
2774{
2775 int port = BP_PORT(bp);
2776 u32 val;
2777
2778 bp->port.pmf = 1;
51c1a580 2779 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2780
3deb8167
YR
2781 /*
2782 * We need the mb() to ensure the ordering between the writing to
2783 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2784 */
2785 smp_mb();
2786
2787 /* queue a periodic task */
2788 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2789
ef01854e
DK
2790 bnx2x_dcbx_pmf_update(bp);
2791
34f80b04 2792 /* enable nig attention */
3395a033 2793 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2794 if (bp->common.int_block == INT_BLOCK_HC) {
2795 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2796 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2797 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2798 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2799 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2800 }
bb2a0f7a
YG
2801
2802 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2803}
2804
c18487ee 2805/* end of Link */
a2fbb9ea
ET
2806
2807/* slow path */
2808
2809/*
2810 * General service functions
2811 */
2812
2691d51d 2813/* send the MCP a request, block until there is a reply */
a22f0788 2814u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2815{
f2e0899f 2816 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2817 u32 seq;
2691d51d
EG
2818 u32 rc = 0;
2819 u32 cnt = 1;
2820 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2821
c4ff7cbf 2822 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2823 seq = ++bp->fw_seq;
f2e0899f
DK
2824 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2825 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2826
754a2f52
DK
2827 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2828 (command | seq), param);
2691d51d
EG
2829
2830 do {
2831 /* let the FW do it's magic ... */
2832 msleep(delay);
2833
f2e0899f 2834 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2835
c4ff7cbf
EG
2836 /* Give the FW up to 5 second (500*10ms) */
2837 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2838
2839 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2840 cnt*delay, rc, seq);
2841
2842 /* is this a reply to our command? */
2843 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2844 rc &= FW_MSG_CODE_MASK;
2845 else {
2846 /* FW BUG! */
2847 BNX2X_ERR("FW failed to respond!\n");
2848 bnx2x_fw_dump(bp);
2849 rc = 0;
2850 }
c4ff7cbf 2851 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2852
2853 return rc;
2854}
2855
ec6ba945 2856
1191cb83
ED
2857static void storm_memset_func_cfg(struct bnx2x *bp,
2858 struct tstorm_eth_function_common_config *tcfg,
2859 u16 abs_fid)
2860{
2861 size_t size = sizeof(struct tstorm_eth_function_common_config);
2862
2863 u32 addr = BAR_TSTRORM_INTMEM +
2864 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2865
2866 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2867}
2868
619c5cb6
VZ
2869void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2870{
2871 if (CHIP_IS_E1x(bp)) {
2872 struct tstorm_eth_function_common_config tcfg = {0};
2873
2874 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2875 }
2876
2877 /* Enable the function in the FW */
2878 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2879 storm_memset_func_en(bp, p->func_id, 1);
2880
2881 /* spq */
2882 if (p->func_flgs & FUNC_FLG_SPQ) {
2883 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2884 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2885 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2886 }
2887}
2888
6383c0b3
AE
2889/**
2890 * bnx2x_get_tx_only_flags - Return common flags
2891 *
2892 * @bp device handle
2893 * @fp queue handle
2894 * @zero_stats TRUE if statistics zeroing is needed
2895 *
2896 * Return the flags that are common for the Tx-only and not normal connections.
2897 */
1191cb83
ED
2898static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2899 struct bnx2x_fastpath *fp,
2900 bool zero_stats)
28912902 2901{
619c5cb6
VZ
2902 unsigned long flags = 0;
2903
2904 /* PF driver will always initialize the Queue to an ACTIVE state */
2905 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2906
6383c0b3
AE
2907 /* tx only connections collect statistics (on the same index as the
2908 * parent connection). The statistics are zeroed when the parent
2909 * connection is initialized.
2910 */
50f0a562
BW
2911
2912 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2913 if (zero_stats)
2914 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2915
6383c0b3
AE
2916
2917 return flags;
2918}
2919
1191cb83
ED
2920static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2921 struct bnx2x_fastpath *fp,
2922 bool leading)
6383c0b3
AE
2923{
2924 unsigned long flags = 0;
2925
619c5cb6
VZ
2926 /* calculate other queue flags */
2927 if (IS_MF_SD(bp))
2928 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2929
a3348722 2930 if (IS_FCOE_FP(fp)) {
619c5cb6 2931 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
2932 /* For FCoE - force usage of default priority (for afex) */
2933 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2934 }
523224a3 2935
f5219d8e 2936 if (!fp->disable_tpa) {
619c5cb6 2937 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2938 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2939 if (fp->mode == TPA_MODE_GRO)
2940 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2941 }
619c5cb6 2942
619c5cb6
VZ
2943 if (leading) {
2944 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2945 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2946 }
523224a3 2947
619c5cb6
VZ
2948 /* Always set HW VLAN stripping */
2949 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 2950
a3348722
BW
2951 /* configure silent vlan removal */
2952 if (IS_MF_AFEX(bp))
2953 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
2954
6383c0b3
AE
2955
2956 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
2957}
2958
619c5cb6 2959static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
2960 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2961 u8 cos)
619c5cb6
VZ
2962{
2963 gen_init->stat_id = bnx2x_stats_id(fp);
2964 gen_init->spcl_id = fp->cl_id;
2965
2966 /* Always use mini-jumbo MTU for FCoE L2 ring */
2967 if (IS_FCOE_FP(fp))
2968 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2969 else
2970 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
2971
2972 gen_init->cos = cos;
619c5cb6
VZ
2973}
2974
2975static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 2976 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 2977 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 2978{
619c5cb6 2979 u8 max_sge = 0;
523224a3
DK
2980 u16 sge_sz = 0;
2981 u16 tpa_agg_size = 0;
2982
523224a3 2983 if (!fp->disable_tpa) {
dfacf138
DK
2984 pause->sge_th_lo = SGE_TH_LO(bp);
2985 pause->sge_th_hi = SGE_TH_HI(bp);
2986
2987 /* validate SGE ring has enough to cross high threshold */
2988 WARN_ON(bp->dropless_fc &&
2989 pause->sge_th_hi + FW_PREFETCH_CNT >
2990 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2991
523224a3
DK
2992 tpa_agg_size = min_t(u32,
2993 (min_t(u32, 8, MAX_SKB_FRAGS) *
2994 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2995 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2996 SGE_PAGE_SHIFT;
2997 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2998 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2999 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
3000 0xffff);
3001 }
3002
3003 /* pause - not for e1 */
3004 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
3005 pause->bd_th_lo = BD_TH_LO(bp);
3006 pause->bd_th_hi = BD_TH_HI(bp);
3007
3008 pause->rcq_th_lo = RCQ_TH_LO(bp);
3009 pause->rcq_th_hi = RCQ_TH_HI(bp);
3010 /*
3011 * validate that rings have enough entries to cross
3012 * high thresholds
3013 */
3014 WARN_ON(bp->dropless_fc &&
3015 pause->bd_th_hi + FW_PREFETCH_CNT >
3016 bp->rx_ring_size);
3017 WARN_ON(bp->dropless_fc &&
3018 pause->rcq_th_hi + FW_PREFETCH_CNT >
3019 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 3020
523224a3
DK
3021 pause->pri_map = 1;
3022 }
3023
3024 /* rxq setup */
523224a3
DK
3025 rxq_init->dscr_map = fp->rx_desc_mapping;
3026 rxq_init->sge_map = fp->rx_sge_mapping;
3027 rxq_init->rcq_map = fp->rx_comp_mapping;
3028 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 3029
619c5cb6
VZ
3030 /* This should be a maximum number of data bytes that may be
3031 * placed on the BD (not including paddings).
3032 */
e52fcb24
ED
3033 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
3034 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 3035
523224a3 3036 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
3037 rxq_init->tpa_agg_sz = tpa_agg_size;
3038 rxq_init->sge_buf_sz = sge_sz;
3039 rxq_init->max_sges_pkt = max_sge;
619c5cb6 3040 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 3041 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
3042
3043 /* Maximum number or simultaneous TPA aggregation for this Queue.
3044 *
3045 * For PF Clients it should be the maximum avaliable number.
3046 * VF driver(s) may want to define it to a smaller value.
3047 */
dfacf138 3048 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 3049
523224a3
DK
3050 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3051 rxq_init->fw_sb_id = fp->fw_sb_id;
3052
ec6ba945
VZ
3053 if (IS_FCOE_FP(fp))
3054 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3055 else
6383c0b3 3056 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
3057 /* configure silent vlan removal
3058 * if multi function mode is afex, then mask default vlan
3059 */
3060 if (IS_MF_AFEX(bp)) {
3061 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3062 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3063 }
523224a3
DK
3064}
3065
619c5cb6 3066static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
3067 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3068 u8 cos)
523224a3 3069{
65565884 3070 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 3071 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
3072 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3073 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 3074
619c5cb6
VZ
3075 /*
3076 * set the tss leading client id for TX classfication ==
3077 * leading RSS client id
3078 */
3079 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3080
ec6ba945
VZ
3081 if (IS_FCOE_FP(fp)) {
3082 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3083 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3084 }
523224a3
DK
3085}
3086
8d96286a 3087static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
3088{
3089 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
3090 struct event_ring_data eq_data = { {0} };
3091 u16 flags;
3092
619c5cb6 3093 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3094 /* reset IGU PF statistics: MSIX + ATTN */
3095 /* PF */
3096 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3097 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3098 (CHIP_MODE_IS_4_PORT(bp) ?
3099 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3100 /* ATTN */
3101 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3102 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3103 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3104 (CHIP_MODE_IS_4_PORT(bp) ?
3105 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3106 }
3107
523224a3
DK
3108 /* function setup flags */
3109 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3110
619c5cb6
VZ
3111 /* This flag is relevant for E1x only.
3112 * E2 doesn't have a TPA configuration in a function level.
523224a3 3113 */
619c5cb6 3114 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
3115
3116 func_init.func_flgs = flags;
3117 func_init.pf_id = BP_FUNC(bp);
3118 func_init.func_id = BP_FUNC(bp);
523224a3
DK
3119 func_init.spq_map = bp->spq_mapping;
3120 func_init.spq_prod = bp->spq_prod_idx;
3121
3122 bnx2x_func_init(bp, &func_init);
3123
3124 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3125
3126 /*
619c5cb6
VZ
3127 * Congestion management values depend on the link rate
3128 * There is no active link so initial link rate is set to 10 Gbps.
3129 * When the link comes up The congestion management values are
3130 * re-calculated according to the actual link rate.
3131 */
523224a3
DK
3132 bp->link_vars.line_speed = SPEED_10000;
3133 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3134
3135 /* Only the PMF sets the HW */
3136 if (bp->port.pmf)
3137 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3138
523224a3
DK
3139 /* init Event Queue */
3140 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3141 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3142 eq_data.producer = bp->eq_prod;
3143 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3144 eq_data.sb_id = DEF_SB_ID;
3145 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3146}
3147
3148
3149static void bnx2x_e1h_disable(struct bnx2x *bp)
3150{
3151 int port = BP_PORT(bp);
3152
619c5cb6 3153 bnx2x_tx_disable(bp);
523224a3
DK
3154
3155 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3156}
3157
3158static void bnx2x_e1h_enable(struct bnx2x *bp)
3159{
3160 int port = BP_PORT(bp);
3161
3162 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3163
3164 /* Tx queue should be only reenabled */
3165 netif_tx_wake_all_queues(bp->dev);
3166
3167 /*
3168 * Should not call netif_carrier_on since it will be called if the link
3169 * is up when checking for link state
3170 */
3171}
3172
1d187b34
BW
3173#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3174
3175static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3176{
3177 struct eth_stats_info *ether_stat =
3178 &bp->slowpath->drv_info_to_mcp.ether_stat;
3179
786fdf0b
DC
3180 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3181 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3182
15192a8c
BW
3183 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3184 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3185 ether_stat->mac_local);
1d187b34
BW
3186
3187 ether_stat->mtu_size = bp->dev->mtu;
3188
3189 if (bp->dev->features & NETIF_F_RXCSUM)
3190 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3191 if (bp->dev->features & NETIF_F_TSO)
3192 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3193 ether_stat->feature_flags |= bp->common.boot_mode;
3194
3195 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3196
3197 ether_stat->txq_size = bp->tx_ring_size;
3198 ether_stat->rxq_size = bp->rx_ring_size;
3199}
3200
3201static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3202{
3203 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3204 struct fcoe_stats_info *fcoe_stat =
3205 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3206
55c11941
MS
3207 if (!CNIC_LOADED(bp))
3208 return;
3209
2e499d3c
BW
3210 memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
3211 bp->fip_mac, ETH_ALEN);
1d187b34
BW
3212
3213 fcoe_stat->qos_priority =
3214 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3215
3216 /* insert FCoE stats from ramrod response */
3217 if (!NO_FCOE(bp)) {
3218 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3219 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3220 tstorm_queue_statistics;
3221
3222 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3223 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3224 xstorm_queue_statistics;
3225
3226 struct fcoe_statistics_params *fw_fcoe_stat =
3227 &bp->fw_stats_data->fcoe;
3228
3229 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
3230 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
3231
3232 ADD_64(fcoe_stat->rx_bytes_hi,
3233 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3234 fcoe_stat->rx_bytes_lo,
3235 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
3236
3237 ADD_64(fcoe_stat->rx_bytes_hi,
3238 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3239 fcoe_stat->rx_bytes_lo,
3240 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
3241
3242 ADD_64(fcoe_stat->rx_bytes_hi,
3243 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3244 fcoe_stat->rx_bytes_lo,
3245 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
3246
3247 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3248 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
3249
3250 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3251 fcoe_q_tstorm_stats->rcv_ucast_pkts);
3252
3253 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3254 fcoe_q_tstorm_stats->rcv_bcast_pkts);
3255
3256 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
f33f1fcc 3257 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34
BW
3258
3259 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
3260 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
3261
3262 ADD_64(fcoe_stat->tx_bytes_hi,
3263 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3264 fcoe_stat->tx_bytes_lo,
3265 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3266
3267 ADD_64(fcoe_stat->tx_bytes_hi,
3268 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3269 fcoe_stat->tx_bytes_lo,
3270 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3271
3272 ADD_64(fcoe_stat->tx_bytes_hi,
3273 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3274 fcoe_stat->tx_bytes_lo,
3275 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3276
3277 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3278 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3279
3280 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3281 fcoe_q_xstorm_stats->ucast_pkts_sent);
3282
3283 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3284 fcoe_q_xstorm_stats->bcast_pkts_sent);
3285
3286 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3287 fcoe_q_xstorm_stats->mcast_pkts_sent);
3288 }
3289
1d187b34
BW
3290 /* ask L5 driver to add data to the struct */
3291 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3292}
3293
3294static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3295{
3296 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3297 struct iscsi_stats_info *iscsi_stat =
3298 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3299
55c11941
MS
3300 if (!CNIC_LOADED(bp))
3301 return;
3302
2e499d3c
BW
3303 memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
3304 bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
1d187b34
BW
3305
3306 iscsi_stat->qos_priority =
3307 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3308
1d187b34
BW
3309 /* ask L5 driver to add data to the struct */
3310 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3311}
3312
0793f83f
DK
3313/* called due to MCP event (on pmf):
3314 * reread new bandwidth configuration
3315 * configure FW
3316 * notify others function about the change
3317 */
1191cb83 3318static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3319{
3320 if (bp->link_vars.link_up) {
3321 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3322 bnx2x_link_sync_notify(bp);
3323 }
3324 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3325}
3326
1191cb83 3327static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3328{
3329 bnx2x_config_mf_bw(bp);
3330 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3331}
3332
c8c60d88
YM
3333static void bnx2x_handle_eee_event(struct bnx2x *bp)
3334{
3335 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3336 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3337}
3338
1d187b34
BW
3339static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3340{
3341 enum drv_info_opcode op_code;
3342 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3343
3344 /* if drv_info version supported by MFW doesn't match - send NACK */
3345 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3346 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3347 return;
3348 }
3349
3350 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3351 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3352
3353 memset(&bp->slowpath->drv_info_to_mcp, 0,
3354 sizeof(union drv_info_to_mcp));
3355
3356 switch (op_code) {
3357 case ETH_STATS_OPCODE:
3358 bnx2x_drv_info_ether_stat(bp);
3359 break;
3360 case FCOE_STATS_OPCODE:
3361 bnx2x_drv_info_fcoe_stat(bp);
3362 break;
3363 case ISCSI_STATS_OPCODE:
3364 bnx2x_drv_info_iscsi_stat(bp);
3365 break;
3366 default:
3367 /* if op code isn't supported - send NACK */
3368 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3369 return;
3370 }
3371
3372 /* if we got drv_info attn from MFW then these fields are defined in
3373 * shmem2 for sure
3374 */
3375 SHMEM2_WR(bp, drv_info_host_addr_lo,
3376 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3377 SHMEM2_WR(bp, drv_info_host_addr_hi,
3378 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3379
3380 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3381}
3382
523224a3
DK
3383static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3384{
3385 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3386
3387 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3388
3389 /*
3390 * This is the only place besides the function initialization
3391 * where the bp->flags can change so it is done without any
3392 * locks
3393 */
f2e0899f 3394 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3395 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3396 bp->flags |= MF_FUNC_DIS;
3397
3398 bnx2x_e1h_disable(bp);
3399 } else {
51c1a580 3400 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3401 bp->flags &= ~MF_FUNC_DIS;
3402
3403 bnx2x_e1h_enable(bp);
3404 }
3405 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3406 }
3407 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3408 bnx2x_config_mf_bw(bp);
523224a3
DK
3409 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3410 }
3411
3412 /* Report results to MCP */
3413 if (dcc_event)
3414 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3415 else
3416 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3417}
3418
3419/* must be called under the spq lock */
1191cb83 3420static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3421{
3422 struct eth_spe *next_spe = bp->spq_prod_bd;
3423
3424 if (bp->spq_prod_bd == bp->spq_last_bd) {
3425 bp->spq_prod_bd = bp->spq;
3426 bp->spq_prod_idx = 0;
51c1a580 3427 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3428 } else {
3429 bp->spq_prod_bd++;
3430 bp->spq_prod_idx++;
3431 }
3432 return next_spe;
3433}
3434
3435/* must be called under the spq lock */
1191cb83 3436static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3437{
3438 int func = BP_FUNC(bp);
3439
53e51e2f
VZ
3440 /*
3441 * Make sure that BD data is updated before writing the producer:
3442 * BD data is written to the memory, the producer is read from the
3443 * memory, thus we need a full memory barrier to ensure the ordering.
3444 */
3445 mb();
28912902 3446
523224a3 3447 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3448 bp->spq_prod_idx);
28912902
MC
3449 mmiowb();
3450}
3451
619c5cb6
VZ
3452/**
3453 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3454 *
3455 * @cmd: command to check
3456 * @cmd_type: command type
3457 */
1191cb83 3458static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3459{
3460 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3461 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3462 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3463 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3464 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3465 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3466 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3467 return true;
3468 else
3469 return false;
3470
3471}
3472
3473
3474/**
3475 * bnx2x_sp_post - place a single command on an SP ring
3476 *
3477 * @bp: driver handle
3478 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3479 * @cid: SW CID the command is related to
3480 * @data_hi: command private data address (high 32 bits)
3481 * @data_lo: command private data address (low 32 bits)
3482 * @cmd_type: command type (e.g. NONE, ETH)
3483 *
3484 * SP data is handled as if it's always an address pair, thus data fields are
3485 * not swapped to little endian in upper functions. Instead this function swaps
3486 * data as if it's two u32 fields.
3487 */
9f6c9258 3488int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3489 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3490{
28912902 3491 struct eth_spe *spe;
523224a3 3492 u16 type;
619c5cb6 3493 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3494
a2fbb9ea 3495#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3496 if (unlikely(bp->panic)) {
3497 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3498 return -EIO;
51c1a580 3499 }
a2fbb9ea
ET
3500#endif
3501
34f80b04 3502 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3503
6e30dd4e
VZ
3504 if (common) {
3505 if (!atomic_read(&bp->eq_spq_left)) {
3506 BNX2X_ERR("BUG! EQ ring full!\n");
3507 spin_unlock_bh(&bp->spq_lock);
3508 bnx2x_panic();
3509 return -EBUSY;
3510 }
3511 } else if (!atomic_read(&bp->cq_spq_left)) {
3512 BNX2X_ERR("BUG! SPQ ring full!\n");
3513 spin_unlock_bh(&bp->spq_lock);
3514 bnx2x_panic();
3515 return -EBUSY;
a2fbb9ea 3516 }
f1410647 3517
28912902
MC
3518 spe = bnx2x_sp_get_next(bp);
3519
a2fbb9ea 3520 /* CID needs port number to be encoded int it */
28912902 3521 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3522 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3523 HW_CID(bp, cid));
523224a3 3524
619c5cb6 3525 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3526
523224a3
DK
3527 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3528 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3529
523224a3
DK
3530 spe->hdr.type = cpu_to_le16(type);
3531
3532 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3533 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3534
d6cae238
VZ
3535 /*
3536 * It's ok if the actual decrement is issued towards the memory
3537 * somewhere between the spin_lock and spin_unlock. Thus no
3538 * more explict memory barrier is needed.
3539 */
3540 if (common)
3541 atomic_dec(&bp->eq_spq_left);
3542 else
3543 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3544
a2fbb9ea 3545
51c1a580
MS
3546 DP(BNX2X_MSG_SP,
3547 "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
3548 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3549 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3550 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3551 HW_CID(bp, cid), data_hi, data_lo, type,
3552 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3553
28912902 3554 bnx2x_sp_prod_update(bp);
34f80b04 3555 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3556 return 0;
3557}
3558
3559/* acquire split MCP access lock register */
4a37fb66 3560static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3561{
72fd0718 3562 u32 j, val;
34f80b04 3563 int rc = 0;
a2fbb9ea
ET
3564
3565 might_sleep();
72fd0718 3566 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3567 val = (1UL << 31);
3568 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3569 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3570 if (val & (1L << 31))
3571 break;
3572
3573 msleep(5);
3574 }
a2fbb9ea 3575 if (!(val & (1L << 31))) {
19680c48 3576 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3577 rc = -EBUSY;
3578 }
3579
3580 return rc;
3581}
3582
4a37fb66
YG
3583/* release split MCP access lock register */
3584static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3585{
72fd0718 3586 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3587}
3588
523224a3
DK
3589#define BNX2X_DEF_SB_ATT_IDX 0x0001
3590#define BNX2X_DEF_SB_IDX 0x0002
3591
1191cb83 3592static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3593{
523224a3 3594 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3595 u16 rc = 0;
3596
3597 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3598 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3599 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3600 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3601 }
523224a3
DK
3602
3603 if (bp->def_idx != def_sb->sp_sb.running_index) {
3604 bp->def_idx = def_sb->sp_sb.running_index;
3605 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3606 }
523224a3
DK
3607
3608 /* Do not reorder: indecies reading should complete before handling */
3609 barrier();
a2fbb9ea
ET
3610 return rc;
3611}
3612
3613/*
3614 * slow path service functions
3615 */
3616
3617static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3618{
34f80b04 3619 int port = BP_PORT(bp);
a2fbb9ea
ET
3620 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3621 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3622 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3623 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3624 u32 aeu_mask;
87942b46 3625 u32 nig_mask = 0;
f2e0899f 3626 u32 reg_addr;
a2fbb9ea 3627
a2fbb9ea
ET
3628 if (bp->attn_state & asserted)
3629 BNX2X_ERR("IGU ERROR\n");
3630
3fcaf2e5
EG
3631 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3632 aeu_mask = REG_RD(bp, aeu_addr);
3633
a2fbb9ea 3634 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3635 aeu_mask, asserted);
72fd0718 3636 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3637 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3638
3fcaf2e5
EG
3639 REG_WR(bp, aeu_addr, aeu_mask);
3640 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3641
3fcaf2e5 3642 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3643 bp->attn_state |= asserted;
3fcaf2e5 3644 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3645
3646 if (asserted & ATTN_HARD_WIRED_MASK) {
3647 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3648
a5e9a7cf
EG
3649 bnx2x_acquire_phy_lock(bp);
3650
877e9aa4 3651 /* save nig interrupt mask */
87942b46 3652 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3653
361c391e
YR
3654 /* If nig_mask is not set, no need to call the update
3655 * function.
3656 */
3657 if (nig_mask) {
3658 REG_WR(bp, nig_int_mask_addr, 0);
3659
3660 bnx2x_link_attn(bp);
3661 }
a2fbb9ea
ET
3662
3663 /* handle unicore attn? */
3664 }
3665 if (asserted & ATTN_SW_TIMER_4_FUNC)
3666 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3667
3668 if (asserted & GPIO_2_FUNC)
3669 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3670
3671 if (asserted & GPIO_3_FUNC)
3672 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3673
3674 if (asserted & GPIO_4_FUNC)
3675 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3676
3677 if (port == 0) {
3678 if (asserted & ATTN_GENERAL_ATTN_1) {
3679 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3680 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3681 }
3682 if (asserted & ATTN_GENERAL_ATTN_2) {
3683 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3684 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3685 }
3686 if (asserted & ATTN_GENERAL_ATTN_3) {
3687 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3688 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3689 }
3690 } else {
3691 if (asserted & ATTN_GENERAL_ATTN_4) {
3692 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3693 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3694 }
3695 if (asserted & ATTN_GENERAL_ATTN_5) {
3696 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3697 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3698 }
3699 if (asserted & ATTN_GENERAL_ATTN_6) {
3700 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3701 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3702 }
3703 }
3704
3705 } /* if hardwired */
3706
f2e0899f
DK
3707 if (bp->common.int_block == INT_BLOCK_HC)
3708 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3709 COMMAND_REG_ATTN_BITS_SET);
3710 else
3711 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3712
3713 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3714 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3715 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3716
3717 /* now set back the mask */
a5e9a7cf 3718 if (asserted & ATTN_NIG_FOR_FUNC) {
27c1151c
YR
3719 /* Verify that IGU ack through BAR was written before restoring
3720 * NIG mask. This loop should exit after 2-3 iterations max.
3721 */
3722 if (bp->common.int_block != INT_BLOCK_HC) {
3723 u32 cnt = 0, igu_acked;
3724 do {
3725 igu_acked = REG_RD(bp,
3726 IGU_REG_ATTENTION_ACK_BITS);
3727 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3728 (++cnt < MAX_IGU_ATTN_ACK_TO));
3729 if (!igu_acked)
3730 DP(NETIF_MSG_HW,
3731 "Failed to verify IGU ack on time\n");
3732 barrier();
3733 }
87942b46 3734 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3735 bnx2x_release_phy_lock(bp);
3736 }
a2fbb9ea
ET
3737}
3738
1191cb83 3739static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3740{
3741 int port = BP_PORT(bp);
b7737c9b 3742 u32 ext_phy_config;
fd4ef40d 3743 /* mark the failure */
b7737c9b
YR
3744 ext_phy_config =
3745 SHMEM_RD(bp,
3746 dev_info.port_hw_config[port].external_phy_config);
3747
3748 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3749 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3750 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3751 ext_phy_config);
fd4ef40d
EG
3752
3753 /* log the failure */
51c1a580
MS
3754 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3755 "Please contact OEM Support for assistance\n");
8304859a
AE
3756
3757 /*
3758 * Scheudle device reset (unload)
3759 * This is due to some boards consuming sufficient power when driver is
3760 * up to overheat if fan fails.
3761 */
3762 smp_mb__before_clear_bit();
3763 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3764 smp_mb__after_clear_bit();
3765 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3766
fd4ef40d 3767}
ab6ad5a4 3768
1191cb83 3769static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3770{
34f80b04 3771 int port = BP_PORT(bp);
877e9aa4 3772 int reg_offset;
d90d96ba 3773 u32 val;
877e9aa4 3774
34f80b04
EG
3775 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3776 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3777
34f80b04 3778 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3779
3780 val = REG_RD(bp, reg_offset);
3781 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3782 REG_WR(bp, reg_offset, val);
3783
3784 BNX2X_ERR("SPIO5 hw attention\n");
3785
fd4ef40d 3786 /* Fan failure attention */
d90d96ba 3787 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3788 bnx2x_fan_failure(bp);
877e9aa4 3789 }
34f80b04 3790
3deb8167 3791 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3792 bnx2x_acquire_phy_lock(bp);
3793 bnx2x_handle_module_detect_int(&bp->link_params);
3794 bnx2x_release_phy_lock(bp);
3795 }
3796
34f80b04
EG
3797 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3798
3799 val = REG_RD(bp, reg_offset);
3800 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3801 REG_WR(bp, reg_offset, val);
3802
3803 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3804 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3805 bnx2x_panic();
3806 }
877e9aa4
ET
3807}
3808
1191cb83 3809static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3810{
3811 u32 val;
3812
0626b899 3813 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3814
3815 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3816 BNX2X_ERR("DB hw attention 0x%x\n", val);
3817 /* DORQ discard attention */
3818 if (val & 0x2)
3819 BNX2X_ERR("FATAL error from DORQ\n");
3820 }
34f80b04
EG
3821
3822 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3823
3824 int port = BP_PORT(bp);
3825 int reg_offset;
3826
3827 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3828 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3829
3830 val = REG_RD(bp, reg_offset);
3831 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3832 REG_WR(bp, reg_offset, val);
3833
3834 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3835 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3836 bnx2x_panic();
3837 }
877e9aa4
ET
3838}
3839
1191cb83 3840static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3841{
3842 u32 val;
3843
3844 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3845
3846 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3847 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3848 /* CFC error attention */
3849 if (val & 0x2)
3850 BNX2X_ERR("FATAL error from CFC\n");
3851 }
3852
3853 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3854 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3855 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3856 /* RQ_USDMDP_FIFO_OVERFLOW */
3857 if (val & 0x18000)
3858 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3859
3860 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3861 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3862 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3863 }
877e9aa4 3864 }
34f80b04
EG
3865
3866 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3867
3868 int port = BP_PORT(bp);
3869 int reg_offset;
3870
3871 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3872 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3873
3874 val = REG_RD(bp, reg_offset);
3875 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3876 REG_WR(bp, reg_offset, val);
3877
3878 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3879 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3880 bnx2x_panic();
3881 }
877e9aa4
ET
3882}
3883
1191cb83 3884static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3885{
34f80b04
EG
3886 u32 val;
3887
877e9aa4
ET
3888 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3889
34f80b04
EG
3890 if (attn & BNX2X_PMF_LINK_ASSERT) {
3891 int func = BP_FUNC(bp);
3892
3893 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 3894 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
3895 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3896 func_mf_config[BP_ABS_FUNC(bp)].config);
3897 val = SHMEM_RD(bp,
3898 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3899 if (val & DRV_STATUS_DCC_EVENT_MASK)
3900 bnx2x_dcc_event(bp,
3901 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3902
3903 if (val & DRV_STATUS_SET_MF_BW)
3904 bnx2x_set_mf_bw(bp);
3905
1d187b34
BW
3906 if (val & DRV_STATUS_DRV_INFO_REQ)
3907 bnx2x_handle_drv_info_req(bp);
d16132ce
AE
3908
3909 if (val & DRV_STATUS_VF_DISABLED)
3910 bnx2x_vf_handle_flr_event(bp);
3911
2691d51d 3912 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3913 bnx2x_pmf_update(bp);
3914
e4901dde 3915 if (bp->port.pmf &&
785b9b1a
SR
3916 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3917 bp->dcbx_enabled > 0)
e4901dde
VZ
3918 /* start dcbx state machine */
3919 bnx2x_dcbx_set_params(bp,
3920 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
3921 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3922 bnx2x_handle_afex_cmd(bp,
3923 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
3924 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3925 bnx2x_handle_eee_event(bp);
3deb8167
YR
3926 if (bp->link_vars.periodic_flags &
3927 PERIODIC_FLAGS_LINK_EVENT) {
3928 /* sync with link */
3929 bnx2x_acquire_phy_lock(bp);
3930 bp->link_vars.periodic_flags &=
3931 ~PERIODIC_FLAGS_LINK_EVENT;
3932 bnx2x_release_phy_lock(bp);
3933 if (IS_MF(bp))
3934 bnx2x_link_sync_notify(bp);
3935 bnx2x_link_report(bp);
3936 }
3937 /* Always call it here: bnx2x_link_report() will
3938 * prevent the link indication duplication.
3939 */
3940 bnx2x__link_status_update(bp);
34f80b04 3941 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
3942
3943 BNX2X_ERR("MC assert!\n");
d6cae238 3944 bnx2x_mc_assert(bp);
877e9aa4
ET
3945 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3946 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3947 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3948 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3949 bnx2x_panic();
3950
3951 } else if (attn & BNX2X_MCP_ASSERT) {
3952
3953 BNX2X_ERR("MCP assert!\n");
3954 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 3955 bnx2x_fw_dump(bp);
877e9aa4
ET
3956
3957 } else
3958 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3959 }
3960
3961 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
3962 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3963 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
3964 val = CHIP_IS_E1(bp) ? 0 :
3965 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
3966 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3967 }
3968 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
3969 val = CHIP_IS_E1(bp) ? 0 :
3970 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
3971 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3972 }
877e9aa4 3973 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
3974 }
3975}
3976
c9ee9206
VZ
3977/*
3978 * Bits map:
3979 * 0-7 - Engine0 load counter.
3980 * 8-15 - Engine1 load counter.
3981 * 16 - Engine0 RESET_IN_PROGRESS bit.
3982 * 17 - Engine1 RESET_IN_PROGRESS bit.
3983 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3984 * on the engine
3985 * 19 - Engine1 ONE_IS_LOADED.
3986 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3987 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3988 * just the one belonging to its engine).
3989 *
3990 */
3991#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3992
3993#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3994#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3995#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3996#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3997#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3998#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3999#define BNX2X_GLOBAL_RESET_BIT 0x00040000
4000
4001/*
4002 * Set the GLOBAL_RESET bit.
4003 *
4004 * Should be run under rtnl lock
4005 */
4006void bnx2x_set_reset_global(struct bnx2x *bp)
4007{
f16da43b
AE
4008 u32 val;
4009 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4010 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4011 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 4012 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
4013}
4014
4015/*
4016 * Clear the GLOBAL_RESET bit.
4017 *
4018 * Should be run under rtnl lock
4019 */
1191cb83 4020static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 4021{
f16da43b
AE
4022 u32 val;
4023 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4024 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4025 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 4026 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 4027}
f85582f8 4028
72fd0718 4029/*
c9ee9206
VZ
4030 * Checks the GLOBAL_RESET bit.
4031 *
72fd0718
VZ
4032 * should be run under rtnl lock
4033 */
1191cb83 4034static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206
VZ
4035{
4036 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4037
4038 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4039 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4040}
4041
4042/*
4043 * Clear RESET_IN_PROGRESS bit for the current engine.
4044 *
4045 * Should be run under rtnl lock
4046 */
1191cb83 4047static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 4048{
f16da43b 4049 u32 val;
c9ee9206
VZ
4050 u32 bit = BP_PATH(bp) ?
4051 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4052 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4053 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4054
4055 /* Clear the bit */
4056 val &= ~bit;
4057 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4058
4059 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4060}
4061
4062/*
c9ee9206
VZ
4063 * Set RESET_IN_PROGRESS for the current engine.
4064 *
72fd0718
VZ
4065 * should be run under rtnl lock
4066 */
c9ee9206 4067void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 4068{
f16da43b 4069 u32 val;
c9ee9206
VZ
4070 u32 bit = BP_PATH(bp) ?
4071 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4072 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4073 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4074
4075 /* Set the bit */
4076 val |= bit;
4077 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4078 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4079}
4080
4081/*
c9ee9206 4082 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
4083 * should be run under rtnl lock
4084 */
c9ee9206 4085bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 4086{
c9ee9206
VZ
4087 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4088 u32 bit = engine ?
4089 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4090
4091 /* return false if bit is set */
4092 return (val & bit) ? false : true;
72fd0718
VZ
4093}
4094
4095/*
889b9af3 4096 * set pf load for the current pf.
c9ee9206 4097 *
72fd0718
VZ
4098 * should be run under rtnl lock
4099 */
889b9af3 4100void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 4101{
f16da43b 4102 u32 val1, val;
c9ee9206
VZ
4103 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4104 BNX2X_PATH0_LOAD_CNT_MASK;
4105 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4106 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4107
f16da43b
AE
4108 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4109 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4110
51c1a580 4111 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4112
c9ee9206
VZ
4113 /* get the current counter value */
4114 val1 = (val & mask) >> shift;
4115
889b9af3
AE
4116 /* set bit of that PF */
4117 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
4118
4119 /* clear the old value */
4120 val &= ~mask;
4121
4122 /* set the new one */
4123 val |= ((val1 << shift) & mask);
4124
4125 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4126 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4127}
4128
c9ee9206 4129/**
889b9af3 4130 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
4131 *
4132 * @bp: driver handle
4133 *
4134 * Should be run under rtnl lock.
4135 * Decrements the load counter for the current engine. Returns
889b9af3 4136 * whether other functions are still loaded
72fd0718 4137 */
889b9af3 4138bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 4139{
f16da43b 4140 u32 val1, val;
c9ee9206
VZ
4141 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4142 BNX2X_PATH0_LOAD_CNT_MASK;
4143 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4144 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4145
f16da43b
AE
4146 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4147 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4148 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4149
c9ee9206
VZ
4150 /* get the current counter value */
4151 val1 = (val & mask) >> shift;
4152
889b9af3
AE
4153 /* clear bit of that PF */
4154 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4155
4156 /* clear the old value */
4157 val &= ~mask;
4158
4159 /* set the new one */
4160 val |= ((val1 << shift) & mask);
4161
4162 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4163 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4164 return val1 != 0;
72fd0718
VZ
4165}
4166
4167/*
889b9af3 4168 * Read the load status for the current engine.
c9ee9206 4169 *
72fd0718
VZ
4170 * should be run under rtnl lock
4171 */
1191cb83 4172static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4173{
c9ee9206
VZ
4174 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4175 BNX2X_PATH0_LOAD_CNT_MASK);
4176 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4177 BNX2X_PATH0_LOAD_CNT_SHIFT);
4178 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4179
51c1a580 4180 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4181
4182 val = (val & mask) >> shift;
4183
51c1a580
MS
4184 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4185 engine, val);
c9ee9206 4186
889b9af3 4187 return val != 0;
72fd0718
VZ
4188}
4189
1191cb83 4190static void _print_next_block(int idx, const char *blk)
72fd0718 4191{
f1deab50 4192 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4193}
4194
1191cb83
ED
4195static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4196 bool print)
72fd0718
VZ
4197{
4198 int i = 0;
4199 u32 cur_bit = 0;
4200 for (i = 0; sig; i++) {
4201 cur_bit = ((u32)0x1 << i);
4202 if (sig & cur_bit) {
4203 switch (cur_bit) {
4204 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
4205 if (print)
4206 _print_next_block(par_num++, "BRB");
72fd0718
VZ
4207 break;
4208 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
4209 if (print)
4210 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
4211 break;
4212 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
4213 if (print)
4214 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
4215 break;
4216 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
4217 if (print)
4218 _print_next_block(par_num++,
4219 "SEARCHER");
4220 break;
4221 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4222 if (print)
4223 _print_next_block(par_num++, "TCM");
72fd0718
VZ
4224 break;
4225 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
4226 if (print)
4227 _print_next_block(par_num++, "TSEMI");
4228 break;
4229 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4230 if (print)
4231 _print_next_block(par_num++, "XPB");
72fd0718
VZ
4232 break;
4233 }
4234
4235 /* Clear the bit */
4236 sig &= ~cur_bit;
4237 }
4238 }
4239
4240 return par_num;
4241}
4242
1191cb83
ED
4243static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4244 bool *global, bool print)
72fd0718
VZ
4245{
4246 int i = 0;
4247 u32 cur_bit = 0;
4248 for (i = 0; sig; i++) {
4249 cur_bit = ((u32)0x1 << i);
4250 if (sig & cur_bit) {
4251 switch (cur_bit) {
c9ee9206
VZ
4252 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4253 if (print)
4254 _print_next_block(par_num++, "PBF");
72fd0718
VZ
4255 break;
4256 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
4257 if (print)
4258 _print_next_block(par_num++, "QM");
4259 break;
4260 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4261 if (print)
4262 _print_next_block(par_num++, "TM");
72fd0718
VZ
4263 break;
4264 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
4265 if (print)
4266 _print_next_block(par_num++, "XSDM");
4267 break;
4268 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4269 if (print)
4270 _print_next_block(par_num++, "XCM");
72fd0718
VZ
4271 break;
4272 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
4273 if (print)
4274 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
4275 break;
4276 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
4277 if (print)
4278 _print_next_block(par_num++,
4279 "DOORBELLQ");
4280 break;
4281 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4282 if (print)
4283 _print_next_block(par_num++, "NIG");
72fd0718
VZ
4284 break;
4285 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
4286 if (print)
4287 _print_next_block(par_num++,
4288 "VAUX PCI CORE");
4289 *global = true;
72fd0718
VZ
4290 break;
4291 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
4292 if (print)
4293 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
4294 break;
4295 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
4296 if (print)
4297 _print_next_block(par_num++, "USDM");
72fd0718 4298 break;
8736c826
VZ
4299 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4300 if (print)
4301 _print_next_block(par_num++, "UCM");
4302 break;
72fd0718 4303 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
4304 if (print)
4305 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
4306 break;
4307 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
4308 if (print)
4309 _print_next_block(par_num++, "UPB");
72fd0718
VZ
4310 break;
4311 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
4312 if (print)
4313 _print_next_block(par_num++, "CSDM");
72fd0718 4314 break;
8736c826
VZ
4315 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4316 if (print)
4317 _print_next_block(par_num++, "CCM");
4318 break;
72fd0718
VZ
4319 }
4320
4321 /* Clear the bit */
4322 sig &= ~cur_bit;
4323 }
4324 }
4325
4326 return par_num;
4327}
4328
1191cb83
ED
4329static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4330 bool print)
72fd0718
VZ
4331{
4332 int i = 0;
4333 u32 cur_bit = 0;
4334 for (i = 0; sig; i++) {
4335 cur_bit = ((u32)0x1 << i);
4336 if (sig & cur_bit) {
4337 switch (cur_bit) {
4338 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
4339 if (print)
4340 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
4341 break;
4342 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
4343 if (print)
4344 _print_next_block(par_num++, "PXP");
72fd0718
VZ
4345 break;
4346 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
4347 if (print)
4348 _print_next_block(par_num++,
72fd0718
VZ
4349 "PXPPCICLOCKCLIENT");
4350 break;
4351 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
4352 if (print)
4353 _print_next_block(par_num++, "CFC");
72fd0718
VZ
4354 break;
4355 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
4356 if (print)
4357 _print_next_block(par_num++, "CDU");
4358 break;
4359 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4360 if (print)
4361 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
4362 break;
4363 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
4364 if (print)
4365 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4366 break;
4367 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4368 if (print)
4369 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4370 break;
4371 }
4372
4373 /* Clear the bit */
4374 sig &= ~cur_bit;
4375 }
4376 }
4377
4378 return par_num;
4379}
4380
1191cb83
ED
4381static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4382 bool *global, bool print)
72fd0718
VZ
4383{
4384 int i = 0;
4385 u32 cur_bit = 0;
4386 for (i = 0; sig; i++) {
4387 cur_bit = ((u32)0x1 << i);
4388 if (sig & cur_bit) {
4389 switch (cur_bit) {
4390 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4391 if (print)
4392 _print_next_block(par_num++, "MCP ROM");
4393 *global = true;
72fd0718
VZ
4394 break;
4395 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4396 if (print)
4397 _print_next_block(par_num++,
4398 "MCP UMP RX");
4399 *global = true;
72fd0718
VZ
4400 break;
4401 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4402 if (print)
4403 _print_next_block(par_num++,
4404 "MCP UMP TX");
4405 *global = true;
72fd0718
VZ
4406 break;
4407 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4408 if (print)
4409 _print_next_block(par_num++,
4410 "MCP SCPAD");
4411 *global = true;
72fd0718
VZ
4412 break;
4413 }
4414
4415 /* Clear the bit */
4416 sig &= ~cur_bit;
4417 }
4418 }
4419
4420 return par_num;
4421}
4422
1191cb83
ED
4423static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4424 bool print)
8736c826
VZ
4425{
4426 int i = 0;
4427 u32 cur_bit = 0;
4428 for (i = 0; sig; i++) {
4429 cur_bit = ((u32)0x1 << i);
4430 if (sig & cur_bit) {
4431 switch (cur_bit) {
4432 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4433 if (print)
4434 _print_next_block(par_num++, "PGLUE_B");
4435 break;
4436 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4437 if (print)
4438 _print_next_block(par_num++, "ATC");
4439 break;
4440 }
4441
4442 /* Clear the bit */
4443 sig &= ~cur_bit;
4444 }
4445 }
4446
4447 return par_num;
4448}
4449
1191cb83
ED
4450static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4451 u32 *sig)
72fd0718 4452{
8736c826
VZ
4453 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4454 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4455 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4456 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4457 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4458 int par_num = 0;
51c1a580
MS
4459 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4460 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4461 sig[0] & HW_PRTY_ASSERT_SET_0,
4462 sig[1] & HW_PRTY_ASSERT_SET_1,
4463 sig[2] & HW_PRTY_ASSERT_SET_2,
4464 sig[3] & HW_PRTY_ASSERT_SET_3,
4465 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4466 if (print)
4467 netdev_err(bp->dev,
4468 "Parity errors detected in blocks: ");
4469 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4470 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4471 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4472 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4473 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4474 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4475 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4476 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4477 par_num = bnx2x_check_blocks_with_parity4(
4478 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4479
c9ee9206
VZ
4480 if (print)
4481 pr_cont("\n");
8736c826 4482
72fd0718
VZ
4483 return true;
4484 } else
4485 return false;
4486}
4487
c9ee9206
VZ
4488/**
4489 * bnx2x_chk_parity_attn - checks for parity attentions.
4490 *
4491 * @bp: driver handle
4492 * @global: true if there was a global attention
4493 * @print: show parity attention in syslog
4494 */
4495bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4496{
8736c826 4497 struct attn_route attn = { {0} };
72fd0718
VZ
4498 int port = BP_PORT(bp);
4499
4500 attn.sig[0] = REG_RD(bp,
4501 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4502 port*4);
4503 attn.sig[1] = REG_RD(bp,
4504 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4505 port*4);
4506 attn.sig[2] = REG_RD(bp,
4507 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4508 port*4);
4509 attn.sig[3] = REG_RD(bp,
4510 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4511 port*4);
4512
8736c826
VZ
4513 if (!CHIP_IS_E1x(bp))
4514 attn.sig[4] = REG_RD(bp,
4515 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4516 port*4);
4517
4518 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4519}
4520
f2e0899f 4521
1191cb83 4522static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4523{
4524 u32 val;
4525 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4526
4527 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4528 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4529 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4530 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4531 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4532 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4533 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4534 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4535 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4536 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4537 if (val &
4538 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4539 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4540 if (val &
4541 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4542 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4543 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4544 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4545 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4546 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4547 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4548 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4549 }
4550 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4551 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4552 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4553 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4554 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4555 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4556 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4557 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4558 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4559 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4560 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4561 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4562 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4563 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4564 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4565 }
4566
4567 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4568 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4569 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4570 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4571 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4572 }
4573
4574}
4575
72fd0718
VZ
4576static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4577{
4578 struct attn_route attn, *group_mask;
34f80b04 4579 int port = BP_PORT(bp);
877e9aa4 4580 int index;
a2fbb9ea
ET
4581 u32 reg_addr;
4582 u32 val;
3fcaf2e5 4583 u32 aeu_mask;
c9ee9206 4584 bool global = false;
a2fbb9ea
ET
4585
4586 /* need to take HW lock because MCP or other port might also
4587 try to handle this event */
4a37fb66 4588 bnx2x_acquire_alr(bp);
a2fbb9ea 4589
c9ee9206
VZ
4590 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4591#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4592 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4593 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4594 /* Disable HW interrupts */
4595 bnx2x_int_disable(bp);
72fd0718
VZ
4596 /* In case of parity errors don't handle attentions so that
4597 * other function would "see" parity errors.
4598 */
c9ee9206
VZ
4599#else
4600 bnx2x_panic();
4601#endif
4602 bnx2x_release_alr(bp);
72fd0718
VZ
4603 return;
4604 }
4605
a2fbb9ea
ET
4606 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4607 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4608 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4609 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4610 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4611 attn.sig[4] =
4612 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4613 else
4614 attn.sig[4] = 0;
4615
4616 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4617 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4618
4619 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4620 if (deasserted & (1 << index)) {
72fd0718 4621 group_mask = &bp->attn_group[index];
a2fbb9ea 4622
51c1a580 4623 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4624 index,
4625 group_mask->sig[0], group_mask->sig[1],
4626 group_mask->sig[2], group_mask->sig[3],
4627 group_mask->sig[4]);
a2fbb9ea 4628
f2e0899f
DK
4629 bnx2x_attn_int_deasserted4(bp,
4630 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4631 bnx2x_attn_int_deasserted3(bp,
72fd0718 4632 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4633 bnx2x_attn_int_deasserted1(bp,
72fd0718 4634 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4635 bnx2x_attn_int_deasserted2(bp,
72fd0718 4636 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4637 bnx2x_attn_int_deasserted0(bp,
72fd0718 4638 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4639 }
4640 }
4641
4a37fb66 4642 bnx2x_release_alr(bp);
a2fbb9ea 4643
f2e0899f
DK
4644 if (bp->common.int_block == INT_BLOCK_HC)
4645 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4646 COMMAND_REG_ATTN_BITS_CLR);
4647 else
4648 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4649
4650 val = ~deasserted;
f2e0899f
DK
4651 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4652 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4653 REG_WR(bp, reg_addr, val);
a2fbb9ea 4654
a2fbb9ea 4655 if (~bp->attn_state & deasserted)
3fcaf2e5 4656 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4657
4658 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4659 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4660
3fcaf2e5
EG
4661 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4662 aeu_mask = REG_RD(bp, reg_addr);
4663
4664 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4665 aeu_mask, deasserted);
72fd0718 4666 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4667 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4668
3fcaf2e5
EG
4669 REG_WR(bp, reg_addr, aeu_mask);
4670 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4671
4672 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4673 bp->attn_state &= ~deasserted;
4674 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4675}
4676
4677static void bnx2x_attn_int(struct bnx2x *bp)
4678{
4679 /* read local copy of bits */
68d59484
EG
4680 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4681 attn_bits);
4682 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4683 attn_bits_ack);
a2fbb9ea
ET
4684 u32 attn_state = bp->attn_state;
4685
4686 /* look for changed bits */
4687 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4688 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4689
4690 DP(NETIF_MSG_HW,
4691 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4692 attn_bits, attn_ack, asserted, deasserted);
4693
4694 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4695 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4696
4697 /* handle bits that were raised */
4698 if (asserted)
4699 bnx2x_attn_int_asserted(bp, asserted);
4700
4701 if (deasserted)
4702 bnx2x_attn_int_deasserted(bp, deasserted);
4703}
4704
619c5cb6
VZ
4705void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4706 u16 index, u8 op, u8 update)
4707{
dc1ba591
AE
4708 u32 igu_addr = bp->igu_base_addr;
4709 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
619c5cb6
VZ
4710 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4711 igu_addr);
4712}
4713
1191cb83 4714static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4715{
4716 /* No memory barriers */
4717 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4718 mmiowb(); /* keep prod updates ordered */
4719}
4720
523224a3
DK
4721static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4722 union event_ring_elem *elem)
4723{
619c5cb6
VZ
4724 u8 err = elem->message.error;
4725
523224a3 4726 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4727 (cid < bp->cnic_eth_dev.starting_cid &&
4728 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4729 return 1;
4730
4731 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4732
619c5cb6
VZ
4733 if (unlikely(err)) {
4734
523224a3
DK
4735 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4736 cid);
4737 bnx2x_panic_dump(bp);
4738 }
619c5cb6 4739 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4740 return 0;
4741}
523224a3 4742
1191cb83 4743static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4744{
4745 struct bnx2x_mcast_ramrod_params rparam;
4746 int rc;
4747
4748 memset(&rparam, 0, sizeof(rparam));
4749
4750 rparam.mcast_obj = &bp->mcast_obj;
4751
4752 netif_addr_lock_bh(bp->dev);
4753
4754 /* Clear pending state for the last command */
4755 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4756
4757 /* If there are pending mcast commands - send them */
4758 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4759 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4760 if (rc < 0)
4761 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4762 rc);
4763 }
4764
4765 netif_addr_unlock_bh(bp->dev);
4766}
4767
1191cb83
ED
4768static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4769 union event_ring_elem *elem)
619c5cb6
VZ
4770{
4771 unsigned long ramrod_flags = 0;
4772 int rc = 0;
4773 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4774 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4775
4776 /* Always push next commands out, don't wait here */
4777 __set_bit(RAMROD_CONT, &ramrod_flags);
4778
4779 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4780 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4781 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 4782 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
4783 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4784 else
15192a8c 4785 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
4786
4787 break;
619c5cb6 4788 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4789 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4790 /* This is only relevant for 57710 where multicast MACs are
4791 * configured as unicast MACs using the same ramrod.
4792 */
4793 bnx2x_handle_mcast_eqe(bp);
4794 return;
4795 default:
4796 BNX2X_ERR("Unsupported classification command: %d\n",
4797 elem->message.data.eth_event.echo);
4798 return;
4799 }
4800
4801 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4802
4803 if (rc < 0)
4804 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4805 else if (rc > 0)
4806 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4807
4808}
4809
619c5cb6 4810static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 4811
1191cb83 4812static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
4813{
4814 netif_addr_lock_bh(bp->dev);
4815
4816 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4817
4818 /* Send rx_mode command again if was requested */
4819 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4820 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
4821 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4822 &bp->sp_state))
4823 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4824 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4825 &bp->sp_state))
4826 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
4827
4828 netif_addr_unlock_bh(bp->dev);
4829}
4830
1191cb83 4831static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
4832 union event_ring_elem *elem)
4833{
4834 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4835 DP(BNX2X_MSG_SP,
4836 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4837 elem->message.data.vif_list_event.func_bit_map);
4838 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4839 elem->message.data.vif_list_event.func_bit_map);
4840 } else if (elem->message.data.vif_list_event.echo ==
4841 VIF_LIST_RULE_SET) {
4842 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4843 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4844 }
4845}
4846
4847/* called with rtnl_lock */
1191cb83 4848static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
4849{
4850 int q, rc;
4851 struct bnx2x_fastpath *fp;
4852 struct bnx2x_queue_state_params queue_params = {NULL};
4853 struct bnx2x_queue_update_params *q_update_params =
4854 &queue_params.params.update;
4855
4856 /* Send Q update command with afex vlan removal values for all Qs */
4857 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4858
4859 /* set silent vlan removal values according to vlan mode */
4860 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4861 &q_update_params->update_flags);
4862 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4863 &q_update_params->update_flags);
4864 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4865
4866 /* in access mode mark mask and value are 0 to strip all vlans */
4867 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4868 q_update_params->silent_removal_value = 0;
4869 q_update_params->silent_removal_mask = 0;
4870 } else {
4871 q_update_params->silent_removal_value =
4872 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4873 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4874 }
4875
4876 for_each_eth_queue(bp, q) {
4877 /* Set the appropriate Queue object */
4878 fp = &bp->fp[q];
15192a8c 4879 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4880
4881 /* send the ramrod */
4882 rc = bnx2x_queue_state_change(bp, &queue_params);
4883 if (rc < 0)
4884 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4885 q);
4886 }
4887
a3348722 4888 if (!NO_FCOE(bp)) {
65565884 4889 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 4890 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4891
4892 /* clear pending completion bit */
4893 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4894
4895 /* mark latest Q bit */
4896 smp_mb__before_clear_bit();
4897 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4898 smp_mb__after_clear_bit();
4899
4900 /* send Q update ramrod for FCoE Q */
4901 rc = bnx2x_queue_state_change(bp, &queue_params);
4902 if (rc < 0)
4903 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4904 q);
4905 } else {
4906 /* If no FCoE ring - ACK MCP now */
4907 bnx2x_link_report(bp);
4908 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4909 }
a3348722
BW
4910}
4911
1191cb83 4912static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
4913 struct bnx2x *bp, u32 cid)
4914{
94f05b0f 4915 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
4916
4917 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 4918 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 4919 else
15192a8c 4920 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
4921}
4922
523224a3
DK
4923static void bnx2x_eq_int(struct bnx2x *bp)
4924{
4925 u16 hw_cons, sw_cons, sw_prod;
4926 union event_ring_elem *elem;
55c11941 4927 u8 echo;
523224a3
DK
4928 u32 cid;
4929 u8 opcode;
fd1fc79d 4930 int rc, spqe_cnt = 0;
619c5cb6
VZ
4931 struct bnx2x_queue_sp_obj *q_obj;
4932 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4933 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4934
4935 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4936
4937 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4938 * when we get the the next-page we nned to adjust so the loop
4939 * condition below will be met. The next element is the size of a
4940 * regular element and hence incrementing by 1
4941 */
4942 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4943 hw_cons++;
4944
25985edc 4945 /* This function may never run in parallel with itself for a
523224a3
DK
4946 * specific bp, thus there is no need in "paired" read memory
4947 * barrier here.
4948 */
4949 sw_cons = bp->eq_cons;
4950 sw_prod = bp->eq_prod;
4951
d6cae238 4952 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 4953 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
4954
4955 for (; sw_cons != hw_cons;
4956 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4957
4958
4959 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4960
fd1fc79d
AE
4961 rc = bnx2x_iov_eq_sp_event(bp, elem);
4962 if (!rc) {
4963 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
4964 rc);
4965 goto next_spqe;
4966 }
523224a3
DK
4967 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4968 opcode = elem->message.opcode;
4969
4970
4971 /* handle eq element */
4972 switch (opcode) {
fd1fc79d
AE
4973 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
4974 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
4975 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
4976 continue;
4977
523224a3 4978 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
4979 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4980 "got statistics comp event %d\n",
619c5cb6 4981 bp->stats_comp++);
523224a3 4982 /* nothing to do with stats comp */
d6cae238 4983 goto next_spqe;
523224a3
DK
4984
4985 case EVENT_RING_OPCODE_CFC_DEL:
4986 /* handle according to cid range */
4987 /*
4988 * we may want to verify here that the bp state is
4989 * HALTING
4990 */
d6cae238 4991 DP(BNX2X_MSG_SP,
523224a3 4992 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
4993
4994 if (CNIC_LOADED(bp) &&
4995 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 4996 goto next_spqe;
55c11941 4997
619c5cb6
VZ
4998 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4999
5000 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5001 break;
5002
5003
523224a3
DK
5004
5005 goto next_spqe;
e4901dde
VZ
5006
5007 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 5008 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
5009 if (f_obj->complete_cmd(bp, f_obj,
5010 BNX2X_F_CMD_TX_STOP))
5011 break;
e4901dde
VZ
5012 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
5013 goto next_spqe;
619c5cb6 5014
e4901dde 5015 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 5016 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
5017 if (f_obj->complete_cmd(bp, f_obj,
5018 BNX2X_F_CMD_TX_START))
5019 break;
e4901dde
VZ
5020 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
5021 goto next_spqe;
55c11941 5022
a3348722 5023 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
5024 echo = elem->message.data.function_update_event.echo;
5025 if (echo == SWITCH_UPDATE) {
5026 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5027 "got FUNC_SWITCH_UPDATE ramrod\n");
5028 if (f_obj->complete_cmd(
5029 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5030 break;
a3348722 5031
55c11941
MS
5032 } else {
5033 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5034 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5035 f_obj->complete_cmd(bp, f_obj,
5036 BNX2X_F_CMD_AFEX_UPDATE);
5037
5038 /* We will perform the Queues update from
5039 * sp_rtnl task as all Queue SP operations
5040 * should run under rtnl_lock.
5041 */
5042 smp_mb__before_clear_bit();
5043 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5044 &bp->sp_rtnl_state);
5045 smp_mb__after_clear_bit();
5046
5047 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5048 }
a3348722 5049
a3348722
BW
5050 goto next_spqe;
5051
5052 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5053 f_obj->complete_cmd(bp, f_obj,
5054 BNX2X_F_CMD_AFEX_VIFLISTS);
5055 bnx2x_after_afex_vif_lists(bp, elem);
5056 goto next_spqe;
619c5cb6 5057 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
5058 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5059 "got FUNC_START ramrod\n");
619c5cb6
VZ
5060 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5061 break;
5062
5063 goto next_spqe;
5064
5065 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
5066 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5067 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
5068 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5069 break;
5070
5071 goto next_spqe;
523224a3
DK
5072 }
5073
5074 switch (opcode | bp->state) {
619c5cb6
VZ
5075 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5076 BNX2X_STATE_OPEN):
5077 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 5078 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
5079 cid = elem->message.data.eth_event.echo &
5080 BNX2X_SWCID_MASK;
d6cae238 5081 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
5082 cid);
5083 rss_raw->clear_pending(rss_raw);
523224a3
DK
5084 break;
5085
619c5cb6
VZ
5086 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5087 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
5088 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 5089 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
5090 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5091 BNX2X_STATE_OPEN):
5092 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5093 BNX2X_STATE_DIAG):
5094 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5095 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5096 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 5097 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
5098 break;
5099
619c5cb6
VZ
5100 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5101 BNX2X_STATE_OPEN):
5102 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5103 BNX2X_STATE_DIAG):
5104 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5105 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5106 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 5107 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
5108 break;
5109
619c5cb6
VZ
5110 case (EVENT_RING_OPCODE_FILTERS_RULES |
5111 BNX2X_STATE_OPEN):
5112 case (EVENT_RING_OPCODE_FILTERS_RULES |
5113 BNX2X_STATE_DIAG):
5114 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 5115 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5116 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 5117 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
5118 break;
5119 default:
5120 /* unknown event log error and continue */
619c5cb6
VZ
5121 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5122 elem->message.opcode, bp->state);
523224a3
DK
5123 }
5124next_spqe:
5125 spqe_cnt++;
5126 } /* for */
5127
8fe23fbd 5128 smp_mb__before_atomic_inc();
6e30dd4e 5129 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
5130
5131 bp->eq_cons = sw_cons;
5132 bp->eq_prod = sw_prod;
5133 /* Make sure that above mem writes were issued towards the memory */
5134 smp_wmb();
5135
5136 /* update producer */
5137 bnx2x_update_eq_prod(bp, bp->eq_prod);
5138}
5139
a2fbb9ea
ET
5140static void bnx2x_sp_task(struct work_struct *work)
5141{
1cf167f2 5142 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea 5143
fd1fc79d 5144 DP(BNX2X_MSG_SP, "sp task invoked\n");
a2fbb9ea 5145
fd1fc79d
AE
5146 /* make sure the atomic interupt_occurred has been written */
5147 smp_rmb();
5148 if (atomic_read(&bp->interrupt_occurred)) {
a2fbb9ea 5149
fd1fc79d
AE
5150 /* what work needs to be performed? */
5151 u16 status = bnx2x_update_dsb_idx(bp);
cdaa7cb8 5152
fd1fc79d
AE
5153 DP(BNX2X_MSG_SP, "status %x\n", status);
5154 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5155 atomic_set(&bp->interrupt_occurred, 0);
5156
5157 /* HW attentions */
5158 if (status & BNX2X_DEF_SB_ATT_IDX) {
5159 bnx2x_attn_int(bp);
5160 status &= ~BNX2X_DEF_SB_ATT_IDX;
5161 }
5162
5163 /* SP events: STAT_QUERY and others */
5164 if (status & BNX2X_DEF_SB_IDX) {
5165 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5166
55c11941 5167 if (FCOE_INIT(bp) &&
fd1fc79d
AE
5168 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5169 /* Prevent local bottom-halves from running as
5170 * we are going to change the local NAPI list.
5171 */
5172 local_bh_disable();
5173 napi_schedule(&bnx2x_fcoe(bp, napi));
5174 local_bh_enable();
5175 }
5176
5177 /* Handle EQ completions */
5178 bnx2x_eq_int(bp);
5179 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5180 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5181
5182 status &= ~BNX2X_DEF_SB_IDX;
019dbb4c 5183 }
55c11941 5184
fd1fc79d
AE
5185 /* if status is non zero then perhaps something went wrong */
5186 if (unlikely(status))
5187 DP(BNX2X_MSG_SP,
5188 "got an unknown interrupt! (status 0x%x)\n", status);
523224a3 5189
fd1fc79d
AE
5190 /* ack status block only if something was actually handled */
5191 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5192 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
523224a3 5193
cdaa7cb8
VZ
5194 }
5195
fd1fc79d
AE
5196 /* must be called after the EQ processing (since eq leads to sriov
5197 * ramrod completion flows).
5198 * This flow may have been scheduled by the arrival of a ramrod
5199 * completion, or by the sriov code rescheduling itself.
5200 */
5201 bnx2x_iov_sp_task(bp);
a3348722
BW
5202
5203 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5204 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5205 &bp->sp_state)) {
5206 bnx2x_link_report(bp);
5207 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5208 }
a2fbb9ea
ET
5209}
5210
9f6c9258 5211irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5212{
5213 struct net_device *dev = dev_instance;
5214 struct bnx2x *bp = netdev_priv(dev);
5215
523224a3
DK
5216 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5217 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5218
5219#ifdef BNX2X_STOP_ON_ERROR
5220 if (unlikely(bp->panic))
5221 return IRQ_HANDLED;
5222#endif
5223
55c11941 5224 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5225 struct cnic_ops *c_ops;
5226
5227 rcu_read_lock();
5228 c_ops = rcu_dereference(bp->cnic_ops);
5229 if (c_ops)
5230 c_ops->cnic_handler(bp->cnic_data, NULL);
5231 rcu_read_unlock();
5232 }
55c11941 5233
fd1fc79d
AE
5234 /* schedule sp task to perform default status block work, ack
5235 * attentions and enable interrupts.
5236 */
5237 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
5238
5239 return IRQ_HANDLED;
5240}
5241
5242/* end of slow path */
5243
619c5cb6
VZ
5244
5245void bnx2x_drv_pulse(struct bnx2x *bp)
5246{
5247 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5248 bp->fw_drv_pulse_wr_seq);
5249}
5250
5251
a2fbb9ea
ET
5252static void bnx2x_timer(unsigned long data)
5253{
5254 struct bnx2x *bp = (struct bnx2x *) data;
5255
5256 if (!netif_running(bp->dev))
5257 return;
5258
67c431a5
AE
5259 if (IS_PF(bp) &&
5260 !BP_NOMCP(bp)) {
f2e0899f 5261 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
5262 u32 drv_pulse;
5263 u32 mcp_pulse;
5264
5265 ++bp->fw_drv_pulse_wr_seq;
5266 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5267 /* TBD - add SYSTEM_TIME */
5268 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5269 bnx2x_drv_pulse(bp);
a2fbb9ea 5270
f2e0899f 5271 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5272 MCP_PULSE_SEQ_MASK);
5273 /* The delta between driver pulse and mcp response
5274 * should be 1 (before mcp response) or 0 (after mcp response)
5275 */
5276 if ((drv_pulse != mcp_pulse) &&
5277 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5278 /* someone lost a heartbeat... */
5279 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5280 drv_pulse, mcp_pulse);
5281 }
5282 }
5283
f34d28ea 5284 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5285 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5286
a2fbb9ea
ET
5287 mod_timer(&bp->timer, jiffies + bp->current_interval);
5288}
5289
5290/* end of Statistics */
5291
5292/* nic init */
5293
5294/*
5295 * nic init service functions
5296 */
5297
1191cb83 5298static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5299{
523224a3
DK
5300 u32 i;
5301 if (!(len%4) && !(addr%4))
5302 for (i = 0; i < len; i += 4)
5303 REG_WR(bp, addr + i, fill);
5304 else
5305 for (i = 0; i < len; i++)
5306 REG_WR8(bp, addr + i, fill);
34f80b04 5307
34f80b04
EG
5308}
5309
523224a3 5310/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5311static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5312 int fw_sb_id,
5313 u32 *sb_data_p,
5314 u32 data_size)
34f80b04 5315{
a2fbb9ea 5316 int index;
523224a3
DK
5317 for (index = 0; index < data_size; index++)
5318 REG_WR(bp, BAR_CSTRORM_INTMEM +
5319 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5320 sizeof(u32)*index,
5321 *(sb_data_p + index));
5322}
a2fbb9ea 5323
1191cb83 5324static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5325{
5326 u32 *sb_data_p;
5327 u32 data_size = 0;
f2e0899f 5328 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5329 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5330
523224a3 5331 /* disable the function first */
619c5cb6 5332 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5333 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5334 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5335 sb_data_e2.common.p_func.vf_valid = false;
5336 sb_data_p = (u32 *)&sb_data_e2;
5337 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5338 } else {
5339 memset(&sb_data_e1x, 0,
5340 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5341 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5342 sb_data_e1x.common.p_func.vf_valid = false;
5343 sb_data_p = (u32 *)&sb_data_e1x;
5344 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5345 }
523224a3 5346 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5347
523224a3
DK
5348 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5349 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5350 CSTORM_STATUS_BLOCK_SIZE);
5351 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5352 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5353 CSTORM_SYNC_BLOCK_SIZE);
5354}
34f80b04 5355
523224a3 5356/* helper: writes SP SB data to FW */
1191cb83 5357static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5358 struct hc_sp_status_block_data *sp_sb_data)
5359{
5360 int func = BP_FUNC(bp);
5361 int i;
5362 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5363 REG_WR(bp, BAR_CSTRORM_INTMEM +
5364 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5365 i*sizeof(u32),
5366 *((u32 *)sp_sb_data + i));
34f80b04
EG
5367}
5368
1191cb83 5369static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5370{
5371 int func = BP_FUNC(bp);
523224a3
DK
5372 struct hc_sp_status_block_data sp_sb_data;
5373 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5374
619c5cb6 5375 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5376 sp_sb_data.p_func.vf_valid = false;
5377
5378 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5379
5380 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5381 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5382 CSTORM_SP_STATUS_BLOCK_SIZE);
5383 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5384 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5385 CSTORM_SP_SYNC_BLOCK_SIZE);
5386
5387}
5388
5389
1191cb83 5390static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5391 int igu_sb_id, int igu_seg_id)
5392{
5393 hc_sm->igu_sb_id = igu_sb_id;
5394 hc_sm->igu_seg_id = igu_seg_id;
5395 hc_sm->timer_value = 0xFF;
5396 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5397}
5398
150966ad
AE
5399
5400/* allocates state machine ids. */
1191cb83 5401static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5402{
5403 /* zero out state machine indices */
5404 /* rx indices */
5405 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5406
5407 /* tx indices */
5408 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5409 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5410 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5411 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5412
5413 /* map indices */
5414 /* rx indices */
5415 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5416 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5417
5418 /* tx indices */
5419 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5420 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5421 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5422 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5423 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5424 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5425 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5426 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5427}
5428
b93288d5 5429void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5430 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5431{
523224a3
DK
5432 int igu_seg_id;
5433
f2e0899f 5434 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5435 struct hc_status_block_data_e1x sb_data_e1x;
5436 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5437 int data_size;
5438 u32 *sb_data_p;
5439
f2e0899f
DK
5440 if (CHIP_INT_MODE_IS_BC(bp))
5441 igu_seg_id = HC_SEG_ACCESS_NORM;
5442 else
5443 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5444
5445 bnx2x_zero_fp_sb(bp, fw_sb_id);
5446
619c5cb6 5447 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5448 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5449 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5450 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5451 sb_data_e2.common.p_func.vf_id = vfid;
5452 sb_data_e2.common.p_func.vf_valid = vf_valid;
5453 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5454 sb_data_e2.common.same_igu_sb_1b = true;
5455 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5456 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5457 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5458 sb_data_p = (u32 *)&sb_data_e2;
5459 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5460 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5461 } else {
5462 memset(&sb_data_e1x, 0,
5463 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5464 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5465 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5466 sb_data_e1x.common.p_func.vf_id = 0xff;
5467 sb_data_e1x.common.p_func.vf_valid = false;
5468 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5469 sb_data_e1x.common.same_igu_sb_1b = true;
5470 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5471 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5472 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5473 sb_data_p = (u32 *)&sb_data_e1x;
5474 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5475 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5476 }
523224a3
DK
5477
5478 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5479 igu_sb_id, igu_seg_id);
5480 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5481 igu_sb_id, igu_seg_id);
5482
51c1a580 5483 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3
DK
5484
5485 /* write indecies to HW */
5486 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5487}
5488
619c5cb6 5489static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5490 u16 tx_usec, u16 rx_usec)
5491{
6383c0b3 5492 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5493 false, rx_usec);
6383c0b3
AE
5494 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5495 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5496 tx_usec);
5497 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5498 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5499 tx_usec);
5500 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5501 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5502 tx_usec);
523224a3 5503}
f2e0899f 5504
523224a3
DK
5505static void bnx2x_init_def_sb(struct bnx2x *bp)
5506{
5507 struct host_sp_status_block *def_sb = bp->def_status_blk;
5508 dma_addr_t mapping = bp->def_status_blk_mapping;
5509 int igu_sp_sb_index;
5510 int igu_seg_id;
34f80b04
EG
5511 int port = BP_PORT(bp);
5512 int func = BP_FUNC(bp);
f2eaeb58 5513 int reg_offset, reg_offset_en5;
a2fbb9ea 5514 u64 section;
523224a3
DK
5515 int index;
5516 struct hc_sp_status_block_data sp_sb_data;
5517 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5518
f2e0899f
DK
5519 if (CHIP_INT_MODE_IS_BC(bp)) {
5520 igu_sp_sb_index = DEF_SB_IGU_ID;
5521 igu_seg_id = HC_SEG_ACCESS_DEF;
5522 } else {
5523 igu_sp_sb_index = bp->igu_dsb_id;
5524 igu_seg_id = IGU_SEG_ACCESS_DEF;
5525 }
a2fbb9ea
ET
5526
5527 /* ATTN */
523224a3 5528 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5529 atten_status_block);
523224a3 5530 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5531
49d66772
ET
5532 bp->attn_state = 0;
5533
a2fbb9ea
ET
5534 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5535 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5536 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5537 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5538 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5539 int sindex;
5540 /* take care of sig[0]..sig[4] */
5541 for (sindex = 0; sindex < 4; sindex++)
5542 bp->attn_group[index].sig[sindex] =
5543 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5544
619c5cb6 5545 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5546 /*
5547 * enable5 is separate from the rest of the registers,
5548 * and therefore the address skip is 4
5549 * and not 16 between the different groups
5550 */
5551 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5552 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5553 else
5554 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5555 }
5556
f2e0899f
DK
5557 if (bp->common.int_block == INT_BLOCK_HC) {
5558 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5559 HC_REG_ATTN_MSG0_ADDR_L);
5560
5561 REG_WR(bp, reg_offset, U64_LO(section));
5562 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5563 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5564 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5565 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5566 }
a2fbb9ea 5567
523224a3
DK
5568 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5569 sp_sb);
a2fbb9ea 5570
523224a3 5571 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5572
619c5cb6 5573 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5574 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5575 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5576 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5577 sp_sb_data.igu_seg_id = igu_seg_id;
5578 sp_sb_data.p_func.pf_id = func;
f2e0899f 5579 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5580 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5581
523224a3 5582 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5583
523224a3 5584 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5585}
5586
9f6c9258 5587void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5588{
a2fbb9ea
ET
5589 int i;
5590
ec6ba945 5591 for_each_eth_queue(bp, i)
523224a3 5592 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5593 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5594}
5595
a2fbb9ea
ET
5596static void bnx2x_init_sp_ring(struct bnx2x *bp)
5597{
a2fbb9ea 5598 spin_lock_init(&bp->spq_lock);
6e30dd4e 5599 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5600
a2fbb9ea 5601 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5602 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5603 bp->spq_prod_bd = bp->spq;
5604 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5605}
5606
523224a3 5607static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5608{
5609 int i;
523224a3
DK
5610 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5611 union event_ring_elem *elem =
5612 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5613
523224a3
DK
5614 elem->next_page.addr.hi =
5615 cpu_to_le32(U64_HI(bp->eq_mapping +
5616 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5617 elem->next_page.addr.lo =
5618 cpu_to_le32(U64_LO(bp->eq_mapping +
5619 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5620 }
523224a3
DK
5621 bp->eq_cons = 0;
5622 bp->eq_prod = NUM_EQ_DESC;
5623 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6e30dd4e
VZ
5624 /* we want a warning message before it gets rought... */
5625 atomic_set(&bp->eq_spq_left,
5626 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5627}
5628
619c5cb6
VZ
5629
5630/* called with netif_addr_lock_bh() */
5631void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5632 unsigned long rx_mode_flags,
5633 unsigned long rx_accept_flags,
5634 unsigned long tx_accept_flags,
5635 unsigned long ramrod_flags)
ab532cf3 5636{
619c5cb6
VZ
5637 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5638 int rc;
5639
5640 memset(&ramrod_param, 0, sizeof(ramrod_param));
5641
5642 /* Prepare ramrod parameters */
5643 ramrod_param.cid = 0;
5644 ramrod_param.cl_id = cl_id;
5645 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5646 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5647
619c5cb6
VZ
5648 ramrod_param.pstate = &bp->sp_state;
5649 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5650
619c5cb6
VZ
5651 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5652 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5653
5654 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5655
5656 ramrod_param.ramrod_flags = ramrod_flags;
5657 ramrod_param.rx_mode_flags = rx_mode_flags;
5658
5659 ramrod_param.rx_accept_flags = rx_accept_flags;
5660 ramrod_param.tx_accept_flags = tx_accept_flags;
5661
5662 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5663 if (rc < 0) {
5664 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5665 return;
5666 }
a2fbb9ea
ET
5667}
5668
619c5cb6
VZ
5669/* called with netif_addr_lock_bh() */
5670void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
471de716 5671{
619c5cb6
VZ
5672 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5673 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
471de716 5674
619c5cb6
VZ
5675 if (!NO_FCOE(bp))
5676
5677 /* Configure rx_mode of FCoE Queue */
5678 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
619c5cb6
VZ
5679
5680 switch (bp->rx_mode) {
5681 case BNX2X_RX_MODE_NONE:
5682 /*
5683 * 'drop all' supersedes any accept flags that may have been
5684 * passed to the function.
5685 */
5686 break;
5687 case BNX2X_RX_MODE_NORMAL:
5688 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5689 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5690 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5691
5692 /* internal switching mode */
5693 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5694 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5695 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5696
5697 break;
5698 case BNX2X_RX_MODE_ALLMULTI:
5699 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5700 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5701 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5702
5703 /* internal switching mode */
5704 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5705 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5706 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5707
5708 break;
5709 case BNX2X_RX_MODE_PROMISC:
5710 /* According to deffinition of SI mode, iface in promisc mode
5711 * should receive matched and unmatched (in resolution of port)
5712 * unicast packets.
5713 */
5714 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5715 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5716 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5717 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5718
5719 /* internal switching mode */
5720 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5721 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5722
5723 if (IS_MF_SI(bp))
5724 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5725 else
5726 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5727
5728 break;
5729 default:
5730 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5731 return;
5732 }
de832a55 5733
619c5cb6
VZ
5734 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5735 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5736 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
34f80b04
EG
5737 }
5738
619c5cb6
VZ
5739 __set_bit(RAMROD_RX, &ramrod_flags);
5740 __set_bit(RAMROD_TX, &ramrod_flags);
5741
5742 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5743 tx_accept_flags, ramrod_flags);
5744}
5745
5746static void bnx2x_init_internal_common(struct bnx2x *bp)
5747{
5748 int i;
5749
0793f83f
DK
5750 if (IS_MF_SI(bp))
5751 /*
5752 * In switch independent mode, the TSTORM needs to accept
5753 * packets that failed classification, since approximate match
5754 * mac addresses aren't written to NIG LLH
5755 */
5756 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5757 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5758 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5759 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5760 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5761
523224a3
DK
5762 /* Zero this manually as its initialization is
5763 currently missing in the initTool */
5764 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5765 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5766 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5767 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5768 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5769 CHIP_INT_MODE_IS_BC(bp) ?
5770 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5771 }
523224a3 5772}
8a1c38d1 5773
471de716
EG
5774static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5775{
5776 switch (load_code) {
5777 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5778 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5779 bnx2x_init_internal_common(bp);
5780 /* no break */
5781
5782 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5783 /* nothing to do */
471de716
EG
5784 /* no break */
5785
5786 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5787 /* internal memory per function is
5788 initialized inside bnx2x_pf_init */
471de716
EG
5789 break;
5790
5791 default:
5792 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5793 break;
5794 }
5795}
5796
619c5cb6 5797static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5798{
55c11941 5799 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 5800}
523224a3 5801
619c5cb6
VZ
5802static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5803{
55c11941 5804 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
5805}
5806
1191cb83 5807static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
5808{
5809 if (CHIP_IS_E1x(fp->bp))
5810 return BP_L_ID(fp->bp) + fp->index;
5811 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5812 return bnx2x_fp_igu_sb_id(fp);
5813}
5814
6383c0b3 5815static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5816{
5817 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5818 u8 cos;
619c5cb6 5819 unsigned long q_type = 0;
6383c0b3 5820 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5821 fp->rx_queue = fp_idx;
b3b83c3f 5822 fp->cid = fp_idx;
619c5cb6
VZ
5823 fp->cl_id = bnx2x_fp_cl_id(fp);
5824 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5825 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5826 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5827 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5828
523224a3 5829 /* init shortcut */
619c5cb6 5830 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5831
523224a3
DK
5832 /* Setup SB indicies */
5833 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5834
619c5cb6
VZ
5835 /* Configure Queue State object */
5836 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5837 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5838
5839 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5840
5841 /* init tx data */
5842 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
5843 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5844 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5845 FP_COS_TO_TXQ(fp, cos, bp),
5846 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5847 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
5848 }
5849
ad5afc89
AE
5850 /* nothing more for vf to do here */
5851 if (IS_VF(bp))
5852 return;
5853
5854 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5855 fp->fw_sb_id, fp->igu_sb_id);
5856 bnx2x_update_fpsb_idx(fp);
15192a8c
BW
5857 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5858 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 5859 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5860
5861 /**
5862 * Configure classification DBs: Always enable Tx switching
5863 */
5864 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5865
ad5afc89
AE
5866 DP(NETIF_MSG_IFUP,
5867 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5868 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5869 fp->igu_sb_id);
523224a3
DK
5870}
5871
1191cb83
ED
5872static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5873{
5874 int i;
5875
5876 for (i = 1; i <= NUM_TX_RINGS; i++) {
5877 struct eth_tx_next_bd *tx_next_bd =
5878 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5879
5880 tx_next_bd->addr_hi =
5881 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5882 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5883 tx_next_bd->addr_lo =
5884 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5885 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5886 }
5887
5888 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5889 txdata->tx_db.data.zero_fill1 = 0;
5890 txdata->tx_db.data.prod = 0;
5891
5892 txdata->tx_pkt_prod = 0;
5893 txdata->tx_pkt_cons = 0;
5894 txdata->tx_bd_prod = 0;
5895 txdata->tx_bd_cons = 0;
5896 txdata->tx_pkt = 0;
5897}
5898
55c11941
MS
5899static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
5900{
5901 int i;
5902
5903 for_each_tx_queue_cnic(bp, i)
5904 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
5905}
1191cb83
ED
5906static void bnx2x_init_tx_rings(struct bnx2x *bp)
5907{
5908 int i;
5909 u8 cos;
5910
55c11941 5911 for_each_eth_queue(bp, i)
1191cb83 5912 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 5913 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
5914}
5915
55c11941 5916void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 5917{
ec6ba945
VZ
5918 if (!NO_FCOE(bp))
5919 bnx2x_init_fcoe_fp(bp);
523224a3
DK
5920
5921 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5922 BNX2X_VF_ID_INVALID, false,
619c5cb6 5923 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 5924
55c11941
MS
5925 /* ensure status block indices were read */
5926 rmb();
5927 bnx2x_init_rx_rings_cnic(bp);
5928 bnx2x_init_tx_rings_cnic(bp);
5929
5930 /* flush all */
5931 mb();
5932 mmiowb();
5933}
a2fbb9ea 5934
55c11941
MS
5935void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5936{
5937 int i;
5938
5939 for_each_eth_queue(bp, i)
5940 bnx2x_init_eth_fp(bp, i);
ad5afc89
AE
5941
5942 /* ensure status block indices were read */
5943 rmb();
5944 bnx2x_init_rx_rings(bp);
5945 bnx2x_init_tx_rings(bp);
5946
5947 if (IS_VF(bp))
5948 return;
5949
020c7e3f
YR
5950 /* Initialize MOD_ABS interrupts */
5951 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5952 bp->common.shmem_base, bp->common.shmem2_base,
5953 BP_PORT(bp));
16119785 5954
523224a3 5955 bnx2x_init_def_sb(bp);
5c862848 5956 bnx2x_update_dsb_idx(bp);
a2fbb9ea 5957 bnx2x_init_sp_ring(bp);
523224a3 5958 bnx2x_init_eq_ring(bp);
471de716 5959 bnx2x_init_internal(bp, load_code);
523224a3 5960 bnx2x_pf_init(bp);
0ef00459
EG
5961 bnx2x_stats_init(bp);
5962
0ef00459
EG
5963 /* flush all before enabling interrupts */
5964 mb();
5965 mmiowb();
5966
615f8fd9 5967 bnx2x_int_enable(bp);
eb8da205
EG
5968
5969 /* Check for SPIO5 */
5970 bnx2x_attn_int_deasserted0(bp,
5971 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5972 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
5973}
5974
5975/* end of nic init */
5976
5977/*
5978 * gzip service functions
5979 */
5980
5981static int bnx2x_gunzip_init(struct bnx2x *bp)
5982{
1a983142
FT
5983 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5984 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
5985 if (bp->gunzip_buf == NULL)
5986 goto gunzip_nomem1;
5987
5988 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5989 if (bp->strm == NULL)
5990 goto gunzip_nomem2;
5991
7ab24bfd 5992 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
5993 if (bp->strm->workspace == NULL)
5994 goto gunzip_nomem3;
5995
5996 return 0;
5997
5998gunzip_nomem3:
5999 kfree(bp->strm);
6000 bp->strm = NULL;
6001
6002gunzip_nomem2:
1a983142
FT
6003 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6004 bp->gunzip_mapping);
a2fbb9ea
ET
6005 bp->gunzip_buf = NULL;
6006
6007gunzip_nomem1:
51c1a580 6008 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
6009 return -ENOMEM;
6010}
6011
6012static void bnx2x_gunzip_end(struct bnx2x *bp)
6013{
b3b83c3f 6014 if (bp->strm) {
7ab24bfd 6015 vfree(bp->strm->workspace);
b3b83c3f
DK
6016 kfree(bp->strm);
6017 bp->strm = NULL;
6018 }
a2fbb9ea
ET
6019
6020 if (bp->gunzip_buf) {
1a983142
FT
6021 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6022 bp->gunzip_mapping);
a2fbb9ea
ET
6023 bp->gunzip_buf = NULL;
6024 }
6025}
6026
94a78b79 6027static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
6028{
6029 int n, rc;
6030
6031 /* check gzip header */
94a78b79
VZ
6032 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6033 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 6034 return -EINVAL;
94a78b79 6035 }
a2fbb9ea
ET
6036
6037 n = 10;
6038
34f80b04 6039#define FNAME 0x8
a2fbb9ea
ET
6040
6041 if (zbuf[3] & FNAME)
6042 while ((zbuf[n++] != 0) && (n < len));
6043
94a78b79 6044 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
6045 bp->strm->avail_in = len - n;
6046 bp->strm->next_out = bp->gunzip_buf;
6047 bp->strm->avail_out = FW_BUF_SIZE;
6048
6049 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6050 if (rc != Z_OK)
6051 return rc;
6052
6053 rc = zlib_inflate(bp->strm, Z_FINISH);
6054 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
6055 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6056 bp->strm->msg);
a2fbb9ea
ET
6057
6058 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6059 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
6060 netdev_err(bp->dev,
6061 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 6062 bp->gunzip_outlen);
a2fbb9ea
ET
6063 bp->gunzip_outlen >>= 2;
6064
6065 zlib_inflateEnd(bp->strm);
6066
6067 if (rc == Z_STREAM_END)
6068 return 0;
6069
6070 return rc;
6071}
6072
6073/* nic load/unload */
6074
6075/*
34f80b04 6076 * General service functions
a2fbb9ea
ET
6077 */
6078
6079/* send a NIG loopback debug packet */
6080static void bnx2x_lb_pckt(struct bnx2x *bp)
6081{
a2fbb9ea 6082 u32 wb_write[3];
a2fbb9ea
ET
6083
6084 /* Ethernet source and destination addresses */
a2fbb9ea
ET
6085 wb_write[0] = 0x55555555;
6086 wb_write[1] = 0x55555555;
34f80b04 6087 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 6088 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6089
6090 /* NON-IP protocol */
a2fbb9ea
ET
6091 wb_write[0] = 0x09000000;
6092 wb_write[1] = 0x55555555;
34f80b04 6093 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 6094 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6095}
6096
6097/* some of the internal memories
6098 * are not directly readable from the driver
6099 * to test them we send debug packets
6100 */
6101static int bnx2x_int_mem_test(struct bnx2x *bp)
6102{
6103 int factor;
6104 int count, i;
6105 u32 val = 0;
6106
ad8d3948 6107 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 6108 factor = 120;
ad8d3948
EG
6109 else if (CHIP_REV_IS_EMUL(bp))
6110 factor = 200;
6111 else
a2fbb9ea 6112 factor = 1;
a2fbb9ea 6113
a2fbb9ea
ET
6114 /* Disable inputs of parser neighbor blocks */
6115 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6116 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6117 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6118 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6119
6120 /* Write 0 to parser credits for CFC search request */
6121 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6122
6123 /* send Ethernet packet */
6124 bnx2x_lb_pckt(bp);
6125
6126 /* TODO do i reset NIG statistic? */
6127 /* Wait until NIG register shows 1 packet of size 0x10 */
6128 count = 1000 * factor;
6129 while (count) {
34f80b04 6130
a2fbb9ea
ET
6131 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6132 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6133 if (val == 0x10)
6134 break;
6135
6136 msleep(10);
6137 count--;
6138 }
6139 if (val != 0x10) {
6140 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6141 return -1;
6142 }
6143
6144 /* Wait until PRS register shows 1 packet */
6145 count = 1000 * factor;
6146 while (count) {
6147 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
6148 if (val == 1)
6149 break;
6150
6151 msleep(10);
6152 count--;
6153 }
6154 if (val != 0x1) {
6155 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6156 return -2;
6157 }
6158
6159 /* Reset and init BRB, PRS */
34f80b04 6160 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 6161 msleep(50);
34f80b04 6162 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 6163 msleep(50);
619c5cb6
VZ
6164 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6165 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
6166
6167 DP(NETIF_MSG_HW, "part2\n");
6168
6169 /* Disable inputs of parser neighbor blocks */
6170 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6171 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6172 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6173 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6174
6175 /* Write 0 to parser credits for CFC search request */
6176 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6177
6178 /* send 10 Ethernet packets */
6179 for (i = 0; i < 10; i++)
6180 bnx2x_lb_pckt(bp);
6181
6182 /* Wait until NIG register shows 10 + 1
6183 packets of size 11*0x10 = 0xb0 */
6184 count = 1000 * factor;
6185 while (count) {
34f80b04 6186
a2fbb9ea
ET
6187 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6188 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6189 if (val == 0xb0)
6190 break;
6191
6192 msleep(10);
6193 count--;
6194 }
6195 if (val != 0xb0) {
6196 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6197 return -3;
6198 }
6199
6200 /* Wait until PRS register shows 2 packets */
6201 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6202 if (val != 2)
6203 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6204
6205 /* Write 1 to parser credits for CFC search request */
6206 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6207
6208 /* Wait until PRS register shows 3 packets */
6209 msleep(10 * factor);
6210 /* Wait until NIG register shows 1 packet of size 0x10 */
6211 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6212 if (val != 3)
6213 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6214
6215 /* clear NIG EOP FIFO */
6216 for (i = 0; i < 11; i++)
6217 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6218 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6219 if (val != 1) {
6220 BNX2X_ERR("clear of NIG failed\n");
6221 return -4;
6222 }
6223
6224 /* Reset and init BRB, PRS, NIG */
6225 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6226 msleep(50);
6227 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6228 msleep(50);
619c5cb6
VZ
6229 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6230 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6231 if (!CNIC_SUPPORT(bp))
6232 /* set NIC mode */
6233 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6234
6235 /* Enable inputs of parser neighbor blocks */
6236 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6237 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6238 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6239 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6240
6241 DP(NETIF_MSG_HW, "done\n");
6242
6243 return 0; /* OK */
6244}
6245
4a33bc03 6246static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea 6247{
b343d002
YM
6248 u32 val;
6249
a2fbb9ea 6250 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6251 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6252 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6253 else
6254 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6255 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6256 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6257 /*
6258 * mask read length error interrupts in brb for parser
6259 * (parsing unit and 'checksum and crc' unit)
6260 * these errors are legal (PU reads fixed length and CAC can cause
6261 * read length error on truncated packets)
6262 */
6263 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6264 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6265 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6266 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6267 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6268 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6269/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6270/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6271 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6272 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6273 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6274/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6275/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6276 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6277 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6278 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6279 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6280/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6281/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6282
b343d002
YM
6283 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6284 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6285 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6286 if (!CHIP_IS_E1x(bp))
6287 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6288 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6289 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6290
a2fbb9ea
ET
6291 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6292 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6293 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6294/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6295
6296 if (!CHIP_IS_E1x(bp))
6297 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6298 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6299
a2fbb9ea
ET
6300 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6301 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6302/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6303 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6304}
6305
81f75bbf
EG
6306static void bnx2x_reset_common(struct bnx2x *bp)
6307{
619c5cb6
VZ
6308 u32 val = 0x1400;
6309
81f75bbf
EG
6310 /* reset_common */
6311 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6312 0xd3ffff7f);
619c5cb6
VZ
6313
6314 if (CHIP_IS_E3(bp)) {
6315 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6316 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6317 }
6318
6319 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6320}
6321
6322static void bnx2x_setup_dmae(struct bnx2x *bp)
6323{
6324 bp->dmae_ready = 0;
6325 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6326}
6327
573f2035
EG
6328static void bnx2x_init_pxp(struct bnx2x *bp)
6329{
6330 u16 devctl;
6331 int r_order, w_order;
6332
2a80eebc 6333 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6334 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6335 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6336 if (bp->mrrs == -1)
6337 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6338 else {
6339 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6340 r_order = bp->mrrs;
6341 }
6342
6343 bnx2x_init_pxp_arb(bp, r_order, w_order);
6344}
fd4ef40d
EG
6345
6346static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6347{
2145a920 6348 int is_required;
fd4ef40d 6349 u32 val;
2145a920 6350 int port;
fd4ef40d 6351
2145a920
VZ
6352 if (BP_NOMCP(bp))
6353 return;
6354
6355 is_required = 0;
fd4ef40d
EG
6356 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6357 SHARED_HW_CFG_FAN_FAILURE_MASK;
6358
6359 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6360 is_required = 1;
6361
6362 /*
6363 * The fan failure mechanism is usually related to the PHY type since
6364 * the power consumption of the board is affected by the PHY. Currently,
6365 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6366 */
6367 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6368 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6369 is_required |=
d90d96ba
YR
6370 bnx2x_fan_failure_det_req(
6371 bp,
6372 bp->common.shmem_base,
a22f0788 6373 bp->common.shmem2_base,
d90d96ba 6374 port);
fd4ef40d
EG
6375 }
6376
6377 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6378
6379 if (is_required == 0)
6380 return;
6381
6382 /* Fan failure is indicated by SPIO 5 */
d6d99a3f 6383 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
fd4ef40d
EG
6384
6385 /* set to active low mode */
6386 val = REG_RD(bp, MISC_REG_SPIO_INT);
d6d99a3f 6387 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6388 REG_WR(bp, MISC_REG_SPIO_INT, val);
6389
6390 /* enable interrupt to signal the IGU */
6391 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6392 val |= MISC_SPIO_SPIO5;
fd4ef40d
EG
6393 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6394}
6395
c9ee9206 6396void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6397{
6398 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6399 val &= ~IGU_PF_CONF_FUNC_EN;
6400
6401 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6402 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6403 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6404}
6405
1191cb83 6406static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6407{
6408 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6409 /* Avoid common init in case MFW supports LFA */
6410 if (SHMEM2_RD(bp, size) >
6411 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6412 return;
619c5cb6
VZ
6413 shmem_base[0] = bp->common.shmem_base;
6414 shmem2_base[0] = bp->common.shmem2_base;
6415 if (!CHIP_IS_E1x(bp)) {
6416 shmem_base[1] =
6417 SHMEM2_RD(bp, other_shmem_base_addr);
6418 shmem2_base[1] =
6419 SHMEM2_RD(bp, other_shmem2_base_addr);
6420 }
6421 bnx2x_acquire_phy_lock(bp);
6422 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6423 bp->common.chip_id);
6424 bnx2x_release_phy_lock(bp);
6425}
6426
6427/**
6428 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6429 *
6430 * @bp: driver handle
6431 */
6432static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6433{
619c5cb6 6434 u32 val;
a2fbb9ea 6435
51c1a580 6436 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6437
2031bd3a
DK
6438 /*
6439 * take the UNDI lock to protect undi_unload flow from accessing
6440 * registers while we're resetting the chip
6441 */
7a06a122 6442 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6443
81f75bbf 6444 bnx2x_reset_common(bp);
34f80b04 6445 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6446
619c5cb6
VZ
6447 val = 0xfffc;
6448 if (CHIP_IS_E3(bp)) {
6449 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6450 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6451 }
6452 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6453
7a06a122 6454 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6455
619c5cb6 6456 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6457
619c5cb6
VZ
6458 if (!CHIP_IS_E1x(bp)) {
6459 u8 abs_func_id;
f2e0899f
DK
6460
6461 /**
6462 * 4-port mode or 2-port mode we need to turn of master-enable
6463 * for everyone, after that, turn it back on for self.
6464 * so, we disregard multi-function or not, and always disable
6465 * for all functions on the given path, this means 0,2,4,6 for
6466 * path 0 and 1,3,5,7 for path 1
6467 */
619c5cb6
VZ
6468 for (abs_func_id = BP_PATH(bp);
6469 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6470 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6471 REG_WR(bp,
6472 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6473 1);
6474 continue;
6475 }
6476
619c5cb6 6477 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6478 /* clear pf enable */
6479 bnx2x_pf_disable(bp);
6480 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6481 }
6482 }
a2fbb9ea 6483
619c5cb6 6484 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6485 if (CHIP_IS_E1(bp)) {
6486 /* enable HW interrupt from PXP on USDM overflow
6487 bit 16 on INT_MASK_0 */
6488 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6489 }
a2fbb9ea 6490
619c5cb6 6491 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6492 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6493
6494#ifdef __BIG_ENDIAN
34f80b04
EG
6495 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6496 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6497 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6498 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6499 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6500 /* make sure this value is 0 */
6501 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6502
6503/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6504 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6505 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6506 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6507 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6508#endif
6509
523224a3
DK
6510 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6511
34f80b04
EG
6512 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6513 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6514
34f80b04
EG
6515 /* let the HW do it's magic ... */
6516 msleep(100);
6517 /* finish PXP init */
6518 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6519 if (val != 1) {
6520 BNX2X_ERR("PXP2 CFG failed\n");
6521 return -EBUSY;
6522 }
6523 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6524 if (val != 1) {
6525 BNX2X_ERR("PXP2 RD_INIT failed\n");
6526 return -EBUSY;
6527 }
a2fbb9ea 6528
f2e0899f
DK
6529 /* Timers bug workaround E2 only. We need to set the entire ILT to
6530 * have entries with value "0" and valid bit on.
6531 * This needs to be done by the first PF that is loaded in a path
6532 * (i.e. common phase)
6533 */
619c5cb6
VZ
6534 if (!CHIP_IS_E1x(bp)) {
6535/* In E2 there is a bug in the timers block that can cause function 6 / 7
6536 * (i.e. vnic3) to start even if it is marked as "scan-off".
6537 * This occurs when a different function (func2,3) is being marked
6538 * as "scan-off". Real-life scenario for example: if a driver is being
6539 * load-unloaded while func6,7 are down. This will cause the timer to access
6540 * the ilt, translate to a logical address and send a request to read/write.
6541 * Since the ilt for the function that is down is not valid, this will cause
6542 * a translation error which is unrecoverable.
6543 * The Workaround is intended to make sure that when this happens nothing fatal
6544 * will occur. The workaround:
6545 * 1. First PF driver which loads on a path will:
6546 * a. After taking the chip out of reset, by using pretend,
6547 * it will write "0" to the following registers of
6548 * the other vnics.
6549 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6550 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6551 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6552 * And for itself it will write '1' to
6553 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6554 * dmae-operations (writing to pram for example.)
6555 * note: can be done for only function 6,7 but cleaner this
6556 * way.
6557 * b. Write zero+valid to the entire ILT.
6558 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6559 * VNIC3 (of that port). The range allocated will be the
6560 * entire ILT. This is needed to prevent ILT range error.
6561 * 2. Any PF driver load flow:
6562 * a. ILT update with the physical addresses of the allocated
6563 * logical pages.
6564 * b. Wait 20msec. - note that this timeout is needed to make
6565 * sure there are no requests in one of the PXP internal
6566 * queues with "old" ILT addresses.
6567 * c. PF enable in the PGLC.
6568 * d. Clear the was_error of the PF in the PGLC. (could have
6569 * occured while driver was down)
6570 * e. PF enable in the CFC (WEAK + STRONG)
6571 * f. Timers scan enable
6572 * 3. PF driver unload flow:
6573 * a. Clear the Timers scan_en.
6574 * b. Polling for scan_on=0 for that PF.
6575 * c. Clear the PF enable bit in the PXP.
6576 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6577 * e. Write zero+valid to all ILT entries (The valid bit must
6578 * stay set)
6579 * f. If this is VNIC 3 of a port then also init
6580 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6581 * to the last enrty in the ILT.
6582 *
6583 * Notes:
6584 * Currently the PF error in the PGLC is non recoverable.
6585 * In the future the there will be a recovery routine for this error.
6586 * Currently attention is masked.
6587 * Having an MCP lock on the load/unload process does not guarantee that
6588 * there is no Timer disable during Func6/7 enable. This is because the
6589 * Timers scan is currently being cleared by the MCP on FLR.
6590 * Step 2.d can be done only for PF6/7 and the driver can also check if
6591 * there is error before clearing it. But the flow above is simpler and
6592 * more general.
6593 * All ILT entries are written by zero+valid and not just PF6/7
6594 * ILT entries since in the future the ILT entries allocation for
6595 * PF-s might be dynamic.
6596 */
f2e0899f
DK
6597 struct ilt_client_info ilt_cli;
6598 struct bnx2x_ilt ilt;
6599 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6600 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6601
b595076a 6602 /* initialize dummy TM client */
f2e0899f
DK
6603 ilt_cli.start = 0;
6604 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6605 ilt_cli.client_num = ILT_CLIENT_TM;
6606
6607 /* Step 1: set zeroes to all ilt page entries with valid bit on
6608 * Step 2: set the timers first/last ilt entry to point
6609 * to the entire range to prevent ILT range error for 3rd/4th
619c5cb6 6610 * vnic (this code assumes existance of the vnic)
f2e0899f
DK
6611 *
6612 * both steps performed by call to bnx2x_ilt_client_init_op()
6613 * with dummy TM client
6614 *
6615 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6616 * and his brother are split registers
6617 */
6618 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6619 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6620 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6621
6622 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6623 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6624 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6625 }
6626
6627
34f80b04
EG
6628 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6629 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6630
619c5cb6 6631 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6632 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6633 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6634 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6635
619c5cb6 6636 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6637
6638 /* let the HW do it's magic ... */
6639 do {
6640 msleep(200);
6641 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6642 } while (factor-- && (val != 1));
6643
6644 if (val != 1) {
6645 BNX2X_ERR("ATC_INIT failed\n");
6646 return -EBUSY;
6647 }
6648 }
6649
619c5cb6 6650 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6651
b56e9670
AE
6652 bnx2x_iov_init_dmae(bp);
6653
34f80b04
EG
6654 /* clean the DMAE memory */
6655 bp->dmae_ready = 1;
619c5cb6
VZ
6656 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6657
6658 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6659
6660 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6661
6662 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6663
619c5cb6 6664 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6665
34f80b04
EG
6666 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6667 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6668 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6669 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6670
619c5cb6 6671 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6672
f85582f8 6673
523224a3
DK
6674 /* QM queues pointers table */
6675 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6676
34f80b04
EG
6677 /* soft reset pulse */
6678 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6679 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6680
55c11941
MS
6681 if (CNIC_SUPPORT(bp))
6682 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6683
619c5cb6 6684 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6685 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6686 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6687 /* enable hw interrupt from doorbell Q */
6688 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6689
619c5cb6 6690 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6691
619c5cb6 6692 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6693 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6694
f2e0899f 6695 if (!CHIP_IS_E1(bp))
619c5cb6 6696 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6697
a3348722
BW
6698 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6699 if (IS_MF_AFEX(bp)) {
6700 /* configure that VNTag and VLAN headers must be
6701 * received in afex mode
6702 */
6703 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6704 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6705 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6706 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6707 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6708 } else {
6709 /* Bit-map indicating which L2 hdrs may appear
6710 * after the basic Ethernet header
6711 */
6712 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6713 bp->path_has_ovlan ? 7 : 6);
6714 }
6715 }
a2fbb9ea 6716
619c5cb6
VZ
6717 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6718 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6719 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6720 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6721
619c5cb6
VZ
6722 if (!CHIP_IS_E1x(bp)) {
6723 /* reset VFC memories */
6724 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6725 VFC_MEMORIES_RST_REG_CAM_RST |
6726 VFC_MEMORIES_RST_REG_RAM_RST);
6727 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6728 VFC_MEMORIES_RST_REG_CAM_RST |
6729 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6730
619c5cb6
VZ
6731 msleep(20);
6732 }
a2fbb9ea 6733
619c5cb6
VZ
6734 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6735 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6736 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6737 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6738
34f80b04
EG
6739 /* sync semi rtc */
6740 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6741 0x80000000);
6742 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6743 0x80000000);
a2fbb9ea 6744
619c5cb6
VZ
6745 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6746 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6747 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6748
a3348722
BW
6749 if (!CHIP_IS_E1x(bp)) {
6750 if (IS_MF_AFEX(bp)) {
6751 /* configure that VNTag and VLAN headers must be
6752 * sent in afex mode
6753 */
6754 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6755 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6756 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6757 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6758 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6759 } else {
6760 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6761 bp->path_has_ovlan ? 7 : 6);
6762 }
6763 }
f2e0899f 6764
34f80b04 6765 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6766
619c5cb6
VZ
6767 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6768
55c11941
MS
6769 if (CNIC_SUPPORT(bp)) {
6770 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6771 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6772 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6773 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6774 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6775 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6776 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6777 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6778 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6779 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6780 }
34f80b04 6781 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6782
34f80b04
EG
6783 if (sizeof(union cdu_context) != 1024)
6784 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6785 dev_alert(&bp->pdev->dev,
6786 "please adjust the size of cdu_context(%ld)\n",
6787 (long)sizeof(union cdu_context));
a2fbb9ea 6788
619c5cb6 6789 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6790 val = (4 << 24) + (0 << 12) + 1024;
6791 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6792
619c5cb6 6793 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6794 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6795 /* enable context validation interrupt from CFC */
6796 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6797
6798 /* set the thresholds to prevent CFC/CDU race */
6799 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6800
619c5cb6 6801 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6802
619c5cb6 6803 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6804 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6805
619c5cb6
VZ
6806 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6807 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6808
34f80b04
EG
6809 /* Reset PCIE errors for debug */
6810 REG_WR(bp, 0x2814, 0xffffffff);
6811 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6812
619c5cb6 6813 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6814 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6815 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6816 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6817 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6818 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6819 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6820 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6821 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6822 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6823 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6824 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6825 }
6826
619c5cb6 6827 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6828 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6829 /* in E3 this done in per-port section */
6830 if (!CHIP_IS_E3(bp))
6831 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6832 }
619c5cb6
VZ
6833 if (CHIP_IS_E1H(bp))
6834 /* not applicable for E2 (and above ...) */
6835 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6836
6837 if (CHIP_REV_IS_SLOW(bp))
6838 msleep(200);
6839
6840 /* finish CFC init */
6841 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6842 if (val != 1) {
6843 BNX2X_ERR("CFC LL_INIT failed\n");
6844 return -EBUSY;
6845 }
6846 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6847 if (val != 1) {
6848 BNX2X_ERR("CFC AC_INIT failed\n");
6849 return -EBUSY;
6850 }
6851 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6852 if (val != 1) {
6853 BNX2X_ERR("CFC CAM_INIT failed\n");
6854 return -EBUSY;
6855 }
6856 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6857
f2e0899f
DK
6858 if (CHIP_IS_E1(bp)) {
6859 /* read NIG statistic
6860 to see if this is our first up since powerup */
6861 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6862 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6863
f2e0899f
DK
6864 /* do internal memory self test */
6865 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6866 BNX2X_ERR("internal mem self test failed\n");
6867 return -EBUSY;
6868 }
34f80b04
EG
6869 }
6870
fd4ef40d
EG
6871 bnx2x_setup_fan_failure_detection(bp);
6872
34f80b04
EG
6873 /* clear PXP2 attentions */
6874 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6875
4a33bc03 6876 bnx2x_enable_blocks_attention(bp);
c9ee9206 6877 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6878
6bbca910 6879 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6880 if (CHIP_IS_E1x(bp))
6881 bnx2x__common_init_phy(bp);
6bbca910
YR
6882 } else
6883 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6884
34f80b04
EG
6885 return 0;
6886}
a2fbb9ea 6887
619c5cb6
VZ
6888/**
6889 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6890 *
6891 * @bp: driver handle
6892 */
6893static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6894{
6895 int rc = bnx2x_init_hw_common(bp);
6896
6897 if (rc)
6898 return rc;
6899
6900 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6901 if (!BP_NOMCP(bp))
6902 bnx2x__common_init_phy(bp);
6903
6904 return 0;
6905}
6906
523224a3 6907static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6908{
6909 int port = BP_PORT(bp);
619c5cb6 6910 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6911 u32 low, high;
34f80b04 6912 u32 val;
a2fbb9ea 6913
619c5cb6 6914
51c1a580 6915 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
6916
6917 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 6918
619c5cb6
VZ
6919 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6920 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6921 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 6922
f2e0899f
DK
6923 /* Timers bug workaround: disables the pf_master bit in pglue at
6924 * common phase, we need to enable it here before any dmae access are
6925 * attempted. Therefore we manually added the enable-master to the
6926 * port phase (it also happens in the function phase)
6927 */
619c5cb6 6928 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6929 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6930
619c5cb6
VZ
6931 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6932 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6933 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6934 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6935
6936 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6937 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6938 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6939 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 6940
523224a3
DK
6941 /* QM cid (connection) count */
6942 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 6943
55c11941
MS
6944 if (CNIC_SUPPORT(bp)) {
6945 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6946 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6947 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6948 }
cdaa7cb8 6949
619c5cb6 6950 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 6951
2b674047
DK
6952 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6953
f2e0899f 6954 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
6955
6956 if (IS_MF(bp))
6957 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6958 else if (bp->dev->mtu > 4096) {
6959 if (bp->flags & ONE_PORT_FLAG)
6960 low = 160;
6961 else {
6962 val = bp->dev->mtu;
6963 /* (24*1024 + val*4)/256 */
6964 low = 96 + (val/64) +
6965 ((val % 64) ? 1 : 0);
6966 }
6967 } else
6968 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6969 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
6970 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6971 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 6972 }
1c06328c 6973
619c5cb6
VZ
6974 if (CHIP_MODE_IS_4_PORT(bp))
6975 REG_WR(bp, (BP_PORT(bp) ?
6976 BRB1_REG_MAC_GUARANTIED_1 :
6977 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 6978
ca00392c 6979
619c5cb6 6980 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
6981 if (CHIP_IS_E3B0(bp)) {
6982 if (IS_MF_AFEX(bp)) {
6983 /* configure headers for AFEX mode */
6984 REG_WR(bp, BP_PORT(bp) ?
6985 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6986 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
6987 REG_WR(bp, BP_PORT(bp) ?
6988 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
6989 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
6990 REG_WR(bp, BP_PORT(bp) ?
6991 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
6992 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
6993 } else {
6994 /* Ovlan exists only if we are in multi-function +
6995 * switch-dependent mode, in switch-independent there
6996 * is no ovlan headers
6997 */
6998 REG_WR(bp, BP_PORT(bp) ?
6999 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7000 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7001 (bp->path_has_ovlan ? 7 : 6));
7002 }
7003 }
356e2385 7004
619c5cb6
VZ
7005 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7006 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7007 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7008 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 7009
619c5cb6
VZ
7010 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7011 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7012 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7013 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 7014
619c5cb6
VZ
7015 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7016 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 7017
619c5cb6
VZ
7018 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7019
7020 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
7021 /* configure PBF to work without PAUSE mtu 9000 */
7022 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 7023
f2e0899f
DK
7024 /* update threshold */
7025 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7026 /* update init credit */
7027 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 7028
f2e0899f
DK
7029 /* probe changes */
7030 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7031 udelay(50);
7032 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7033 }
a2fbb9ea 7034
55c11941
MS
7035 if (CNIC_SUPPORT(bp))
7036 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7037
619c5cb6
VZ
7038 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7039 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
7040
7041 if (CHIP_IS_E1(bp)) {
7042 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7043 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7044 }
619c5cb6 7045 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 7046
619c5cb6 7047 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7048
619c5cb6 7049 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04
EG
7050 /* init aeu_mask_attn_func_0/1:
7051 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
7052 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
7053 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
7054 val = IS_MF(bp) ? 0xF7 : 0x7;
7055 /* Enable DCBX attention for all but E1 */
7056 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7057 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 7058
619c5cb6
VZ
7059 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7060
7061 if (!CHIP_IS_E1x(bp)) {
7062 /* Bit-map indicating which L2 hdrs may appear after the
7063 * basic Ethernet header
7064 */
a3348722
BW
7065 if (IS_MF_AFEX(bp))
7066 REG_WR(bp, BP_PORT(bp) ?
7067 NIG_REG_P1_HDRS_AFTER_BASIC :
7068 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7069 else
7070 REG_WR(bp, BP_PORT(bp) ?
7071 NIG_REG_P1_HDRS_AFTER_BASIC :
7072 NIG_REG_P0_HDRS_AFTER_BASIC,
7073 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
7074
7075 if (CHIP_IS_E3(bp))
7076 REG_WR(bp, BP_PORT(bp) ?
7077 NIG_REG_LLH1_MF_MODE :
7078 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7079 }
7080 if (!CHIP_IS_E3(bp))
7081 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 7082
f2e0899f 7083 if (!CHIP_IS_E1(bp)) {
fb3bff17 7084 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 7085 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 7086 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 7087
619c5cb6 7088 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7089 val = 0;
7090 switch (bp->mf_mode) {
7091 case MULTI_FUNCTION_SD:
7092 val = 1;
7093 break;
7094 case MULTI_FUNCTION_SI:
a3348722 7095 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
7096 val = 2;
7097 break;
7098 }
7099
7100 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7101 NIG_REG_LLH0_CLS_TYPE), val);
7102 }
1c06328c
EG
7103 {
7104 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7105 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7106 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7107 }
34f80b04
EG
7108 }
7109
619c5cb6
VZ
7110
7111 /* If SPIO5 is set to generate interrupts, enable it for this port */
7112 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 7113 if (val & MISC_SPIO_SPIO5) {
4d295db0
EG
7114 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7115 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7116 val = REG_RD(bp, reg_addr);
f1410647 7117 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 7118 REG_WR(bp, reg_addr, val);
f1410647 7119 }
a2fbb9ea 7120
34f80b04
EG
7121 return 0;
7122}
7123
34f80b04
EG
7124static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7125{
7126 int reg;
32d68de1 7127 u32 wb_write[2];
34f80b04 7128
f2e0899f 7129 if (CHIP_IS_E1(bp))
34f80b04 7130 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
7131 else
7132 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 7133
32d68de1
YM
7134 wb_write[0] = ONCHIP_ADDR1(addr);
7135 wb_write[1] = ONCHIP_ADDR2(addr);
7136 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
7137}
7138
b56e9670 7139void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
1191cb83
ED
7140{
7141 u32 data, ctl, cnt = 100;
7142 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7143 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7144 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7145 u32 sb_bit = 1 << (idu_sb_id%32);
b56e9670 7146 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
1191cb83
ED
7147 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7148
7149 /* Not supported in BC mode */
7150 if (CHIP_INT_MODE_IS_BC(bp))
7151 return;
7152
7153 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7154 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7155 IGU_REGULAR_CLEANUP_SET |
7156 IGU_REGULAR_BCLEANUP;
7157
7158 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7159 func_encode << IGU_CTRL_REG_FID_SHIFT |
7160 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7161
7162 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7163 data, igu_addr_data);
7164 REG_WR(bp, igu_addr_data, data);
7165 mmiowb();
7166 barrier();
7167 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7168 ctl, igu_addr_ctl);
7169 REG_WR(bp, igu_addr_ctl, ctl);
7170 mmiowb();
7171 barrier();
7172
7173 /* wait for clean up to finish */
7174 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7175 msleep(20);
7176
7177
7178 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7179 DP(NETIF_MSG_HW,
7180 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7181 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7182 }
7183}
7184
7185static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7186{
619c5cb6 7187 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7188}
7189
1191cb83 7190static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7191{
7192 u32 i, base = FUNC_ILT_BASE(func);
7193 for (i = base; i < base + ILT_PER_FUNC; i++)
7194 bnx2x_ilt_wr(bp, i, 0);
7195}
7196
55c11941 7197
910cc727 7198static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7199{
7200 int port = BP_PORT(bp);
7201 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7202 /* T1 hash bits value determines the T1 number of entries */
7203 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7204}
7205
7206static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7207{
7208 int rc;
7209 struct bnx2x_func_state_params func_params = {NULL};
7210 struct bnx2x_func_switch_update_params *switch_update_params =
7211 &func_params.params.switch_update;
7212
7213 /* Prepare parameters for function state transitions */
7214 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7215 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7216
7217 func_params.f_obj = &bp->func_obj;
7218 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7219
7220 /* Function parameters */
7221 switch_update_params->suspend = suspend;
7222
7223 rc = bnx2x_func_state_change(bp, &func_params);
7224
7225 return rc;
7226}
7227
910cc727 7228static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7229{
7230 int rc, i, port = BP_PORT(bp);
7231 int vlan_en = 0, mac_en[NUM_MACS];
7232
7233
7234 /* Close input from network */
7235 if (bp->mf_mode == SINGLE_FUNCTION) {
7236 bnx2x_set_rx_filter(&bp->link_params, 0);
7237 } else {
7238 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7239 NIG_REG_LLH0_FUNC_EN);
7240 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7241 NIG_REG_LLH0_FUNC_EN, 0);
7242 for (i = 0; i < NUM_MACS; i++) {
7243 mac_en[i] = REG_RD(bp, port ?
7244 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7245 4 * i) :
7246 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7247 4 * i));
7248 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7249 4 * i) :
7250 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7251 }
7252 }
7253
7254 /* Close BMC to host */
7255 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7256 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7257
7258 /* Suspend Tx switching to the PF. Completion of this ramrod
7259 * further guarantees that all the packets of that PF / child
7260 * VFs in BRB were processed by the Parser, so it is safe to
7261 * change the NIC_MODE register.
7262 */
7263 rc = bnx2x_func_switch_update(bp, 1);
7264 if (rc) {
7265 BNX2X_ERR("Can't suspend tx-switching!\n");
7266 return rc;
7267 }
7268
7269 /* Change NIC_MODE register */
7270 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7271
7272 /* Open input from network */
7273 if (bp->mf_mode == SINGLE_FUNCTION) {
7274 bnx2x_set_rx_filter(&bp->link_params, 1);
7275 } else {
7276 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7277 NIG_REG_LLH0_FUNC_EN, vlan_en);
7278 for (i = 0; i < NUM_MACS; i++) {
7279 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7280 4 * i) :
7281 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7282 mac_en[i]);
7283 }
7284 }
7285
7286 /* Enable BMC to host */
7287 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7288 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7289
7290 /* Resume Tx switching to the PF */
7291 rc = bnx2x_func_switch_update(bp, 0);
7292 if (rc) {
7293 BNX2X_ERR("Can't resume tx-switching!\n");
7294 return rc;
7295 }
7296
7297 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7298 return 0;
7299}
7300
7301int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7302{
7303 int rc;
7304
7305 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7306
7307 if (CONFIGURE_NIC_MODE(bp)) {
7308 /* Configrue searcher as part of function hw init */
7309 bnx2x_init_searcher(bp);
7310
7311 /* Reset NIC mode */
7312 rc = bnx2x_reset_nic_mode(bp);
7313 if (rc)
7314 BNX2X_ERR("Can't change NIC mode!\n");
7315 return rc;
7316 }
7317
7318 return 0;
7319}
7320
523224a3 7321static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7322{
7323 int port = BP_PORT(bp);
7324 int func = BP_FUNC(bp);
619c5cb6 7325 int init_phase = PHASE_PF0 + func;
523224a3
DK
7326 struct bnx2x_ilt *ilt = BP_ILT(bp);
7327 u16 cdu_ilt_start;
8badd27a 7328 u32 addr, val;
f4a66897 7329 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7330 int i, main_mem_width, rc;
34f80b04 7331
51c1a580 7332 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7333
619c5cb6 7334 /* FLR cleanup - hmmm */
89db4ad8
AE
7335 if (!CHIP_IS_E1x(bp)) {
7336 rc = bnx2x_pf_flr_clnup(bp);
7337 if (rc)
7338 return rc;
7339 }
619c5cb6 7340
8badd27a 7341 /* set MSI reconfigure capability */
f2e0899f
DK
7342 if (bp->common.int_block == INT_BLOCK_HC) {
7343 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7344 val = REG_RD(bp, addr);
7345 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7346 REG_WR(bp, addr, val);
7347 }
8badd27a 7348
619c5cb6
VZ
7349 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7350 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7351
523224a3
DK
7352 ilt = BP_ILT(bp);
7353 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7354
290ca2bb
AE
7355 if (IS_SRIOV(bp))
7356 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7357 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7358
7359 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7360 * those of the VFs, so start line should be reset
7361 */
7362 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
523224a3 7363 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7364 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7365 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7366 bp->context[i].cxt_mapping;
7367 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7368 }
290ca2bb 7369
523224a3 7370 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7371
55c11941
MS
7372 if (!CONFIGURE_NIC_MODE(bp)) {
7373 bnx2x_init_searcher(bp);
7374 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7375 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7376 } else {
7377 /* Set NIC mode */
7378 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7379 DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
37b091ba 7380
55c11941 7381 }
37b091ba 7382
619c5cb6 7383 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7384 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7385
7386 /* Turn on a single ISR mode in IGU if driver is going to use
7387 * INT#x or MSI
7388 */
7389 if (!(bp->flags & USING_MSIX_FLAG))
7390 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7391 /*
7392 * Timers workaround bug: function init part.
7393 * Need to wait 20msec after initializing ILT,
7394 * needed to make sure there are no requests in
7395 * one of the PXP internal queues with "old" ILT addresses
7396 */
7397 msleep(20);
7398 /*
7399 * Master enable - Due to WB DMAE writes performed before this
7400 * register is re-initialized as part of the regular function
7401 * init
7402 */
7403 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7404 /* Enable the function in IGU */
7405 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7406 }
7407
523224a3 7408 bp->dmae_ready = 1;
34f80b04 7409
619c5cb6 7410 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7411
619c5cb6 7412 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7413 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7414
619c5cb6
VZ
7415 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7416 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7417 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7418 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7419 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7420 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7421 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7422 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7423 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7424 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7425 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7426 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7427 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7428
7429 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7430 REG_WR(bp, QM_REG_PF_EN, 1);
7431
619c5cb6
VZ
7432 if (!CHIP_IS_E1x(bp)) {
7433 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7434 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7435 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7436 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7437 }
7438 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7439
7440 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7441 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
b56e9670
AE
7442
7443 bnx2x_iov_init_dq(bp);
7444
619c5cb6
VZ
7445 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7446 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7447 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7448 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7449 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7450 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7451 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7452 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7453 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7454 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7455 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7456
619c5cb6 7457 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7458
619c5cb6 7459 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7460
619c5cb6 7461 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7462 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7463
fb3bff17 7464 if (IS_MF(bp)) {
34f80b04 7465 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7466 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7467 }
7468
619c5cb6 7469 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7470
34f80b04 7471 /* HC init per function */
f2e0899f
DK
7472 if (bp->common.int_block == INT_BLOCK_HC) {
7473 if (CHIP_IS_E1H(bp)) {
7474 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7475
7476 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7477 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7478 }
619c5cb6 7479 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7480
7481 } else {
7482 int num_segs, sb_idx, prod_offset;
7483
34f80b04
EG
7484 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7485
619c5cb6 7486 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7487 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7488 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7489 }
7490
619c5cb6 7491 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7492
619c5cb6 7493 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7494 int dsb_idx = 0;
7495 /**
7496 * Producer memory:
7497 * E2 mode: address 0-135 match to the mapping memory;
7498 * 136 - PF0 default prod; 137 - PF1 default prod;
7499 * 138 - PF2 default prod; 139 - PF3 default prod;
7500 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7501 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7502 * 144-147 reserved.
7503 *
7504 * E1.5 mode - In backward compatible mode;
7505 * for non default SB; each even line in the memory
7506 * holds the U producer and each odd line hold
7507 * the C producer. The first 128 producers are for
7508 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7509 * producers are for the DSB for each PF.
7510 * Each PF has five segments: (the order inside each
7511 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7512 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7513 * 144-147 attn prods;
7514 */
7515 /* non-default-status-blocks */
7516 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7517 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7518 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7519 prod_offset = (bp->igu_base_sb + sb_idx) *
7520 num_segs;
7521
7522 for (i = 0; i < num_segs; i++) {
7523 addr = IGU_REG_PROD_CONS_MEMORY +
7524 (prod_offset + i) * 4;
7525 REG_WR(bp, addr, 0);
7526 }
7527 /* send consumer update with value 0 */
7528 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7529 USTORM_ID, 0, IGU_INT_NOP, 1);
7530 bnx2x_igu_clear_sb(bp,
7531 bp->igu_base_sb + sb_idx);
7532 }
7533
7534 /* default-status-blocks */
7535 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7536 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7537
7538 if (CHIP_MODE_IS_4_PORT(bp))
7539 dsb_idx = BP_FUNC(bp);
7540 else
3395a033 7541 dsb_idx = BP_VN(bp);
f2e0899f
DK
7542
7543 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7544 IGU_BC_BASE_DSB_PROD + dsb_idx :
7545 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7546
3395a033
DK
7547 /*
7548 * igu prods come in chunks of E1HVN_MAX (4) -
7549 * does not matters what is the current chip mode
7550 */
f2e0899f
DK
7551 for (i = 0; i < (num_segs * E1HVN_MAX);
7552 i += E1HVN_MAX) {
7553 addr = IGU_REG_PROD_CONS_MEMORY +
7554 (prod_offset + i)*4;
7555 REG_WR(bp, addr, 0);
7556 }
7557 /* send consumer update with 0 */
7558 if (CHIP_INT_MODE_IS_BC(bp)) {
7559 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7560 USTORM_ID, 0, IGU_INT_NOP, 1);
7561 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7562 CSTORM_ID, 0, IGU_INT_NOP, 1);
7563 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7564 XSTORM_ID, 0, IGU_INT_NOP, 1);
7565 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7566 TSTORM_ID, 0, IGU_INT_NOP, 1);
7567 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7568 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7569 } else {
7570 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7571 USTORM_ID, 0, IGU_INT_NOP, 1);
7572 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7573 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7574 }
7575 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7576
7577 /* !!! these should become driver const once
7578 rf-tool supports split-68 const */
7579 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7580 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7581 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7582 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7583 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7584 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7585 }
34f80b04 7586 }
34f80b04 7587
c14423fe 7588 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7589 REG_WR(bp, 0x2114, 0xffffffff);
7590 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7591
f4a66897
VZ
7592 if (CHIP_IS_E1x(bp)) {
7593 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7594 main_mem_base = HC_REG_MAIN_MEMORY +
7595 BP_PORT(bp) * (main_mem_size * 4);
7596 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7597 main_mem_width = 8;
7598
7599 val = REG_RD(bp, main_mem_prty_clr);
7600 if (val)
51c1a580
MS
7601 DP(NETIF_MSG_HW,
7602 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7603 val);
f4a66897
VZ
7604
7605 /* Clear "false" parity errors in MSI-X table */
7606 for (i = main_mem_base;
7607 i < main_mem_base + main_mem_size * 4;
7608 i += main_mem_width) {
7609 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7610 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7611 i, main_mem_width / 4);
7612 }
7613 /* Clear HC parity attention */
7614 REG_RD(bp, main_mem_prty_clr);
7615 }
7616
619c5cb6
VZ
7617#ifdef BNX2X_STOP_ON_ERROR
7618 /* Enable STORMs SP logging */
7619 REG_WR8(bp, BAR_USTRORM_INTMEM +
7620 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7621 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7622 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7623 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7624 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7625 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7626 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7627#endif
7628
b7737c9b 7629 bnx2x_phy_probe(&bp->link_params);
f85582f8 7630
34f80b04
EG
7631 return 0;
7632}
7633
a2fbb9ea 7634
55c11941
MS
7635void bnx2x_free_mem_cnic(struct bnx2x *bp)
7636{
7637 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7638
7639 if (!CHIP_IS_E1x(bp))
7640 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7641 sizeof(struct host_hc_status_block_e2));
7642 else
7643 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7644 sizeof(struct host_hc_status_block_e1x));
7645
7646 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7647}
7648
9f6c9258 7649void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7650{
a052997e
MS
7651 int i;
7652
a2fbb9ea 7653 /* fastpath */
b3b83c3f 7654 bnx2x_free_fp_mem(bp);
a2fbb9ea
ET
7655 /* end of fastpath */
7656
7657 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7658 sizeof(struct host_sp_status_block));
a2fbb9ea 7659
619c5cb6
VZ
7660 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7661 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7662
a2fbb9ea 7663 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7664 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7665
a052997e
MS
7666 for (i = 0; i < L2_ILT_LINES(bp); i++)
7667 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7668 bp->context[i].size);
523224a3
DK
7669 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7670
7671 BNX2X_FREE(bp->ilt->lines);
f85582f8 7672
7a9b2557 7673 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7674
523224a3
DK
7675 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7676 BCM_PAGE_SIZE * NUM_EQ_PAGES);
619c5cb6
VZ
7677}
7678
a2fbb9ea 7679
55c11941 7680int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7681{
619c5cb6
VZ
7682 if (!CHIP_IS_E1x(bp))
7683 /* size = the status block + ramrod buffers */
f2e0899f
DK
7684 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7685 sizeof(struct host_hc_status_block_e2));
7686 else
55c11941
MS
7687 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7688 &bp->cnic_sb_mapping,
7689 sizeof(struct
7690 host_hc_status_block_e1x));
8badd27a 7691
55c11941
MS
7692 if (CONFIGURE_NIC_MODE(bp))
7693 /* allocate searcher T2 table, as it wan't allocated before */
7694 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7695
7696 /* write address to which L5 should insert its values */
7697 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7698 &bp->slowpath->drv_info_to_mcp;
7699
7700 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7701 goto alloc_mem_err;
7702
7703 return 0;
7704
7705alloc_mem_err:
7706 bnx2x_free_mem_cnic(bp);
7707 BNX2X_ERR("Can't allocate memory\n");
7708 return -ENOMEM;
7709}
7710
7711int bnx2x_alloc_mem(struct bnx2x *bp)
7712{
7713 int i, allocated, context_size;
a2fbb9ea 7714
55c11941
MS
7715 if (!CONFIGURE_NIC_MODE(bp))
7716 /* allocate searcher T2 table */
7717 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7718
523224a3
DK
7719 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7720 sizeof(struct host_sp_status_block));
a2fbb9ea 7721
523224a3
DK
7722 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7723 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7724
a052997e
MS
7725 /* Allocate memory for CDU context:
7726 * This memory is allocated separately and not in the generic ILT
7727 * functions because CDU differs in few aspects:
7728 * 1. There are multiple entities allocating memory for context -
7729 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7730 * its own ILT lines.
7731 * 2. Since CDU page-size is not a single 4KB page (which is the case
7732 * for the other ILT clients), to be efficient we want to support
7733 * allocation of sub-page-size in the last entry.
7734 * 3. Context pointers are used by the driver to pass to FW / update
7735 * the context (for the other ILT clients the pointers are used just to
7736 * free the memory during unload).
7737 */
7738 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7739
a052997e
MS
7740 for (i = 0, allocated = 0; allocated < context_size; i++) {
7741 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7742 (context_size - allocated));
7743 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7744 &bp->context[i].cxt_mapping,
7745 bp->context[i].size);
7746 allocated += bp->context[i].size;
7747 }
523224a3 7748 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7749
523224a3
DK
7750 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7751 goto alloc_mem_err;
65abd74d 7752
67c431a5
AE
7753 if (bnx2x_iov_alloc_mem(bp))
7754 goto alloc_mem_err;
7755
9f6c9258
DK
7756 /* Slow path ring */
7757 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7758
523224a3
DK
7759 /* EQ */
7760 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7761 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7762
9f6c9258 7763 return 0;
e1510706 7764
9f6c9258
DK
7765alloc_mem_err:
7766 bnx2x_free_mem(bp);
51c1a580 7767 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7768 return -ENOMEM;
65abd74d
YG
7769}
7770
a2fbb9ea
ET
7771/*
7772 * Init service functions
7773 */
a2fbb9ea 7774
619c5cb6
VZ
7775int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7776 struct bnx2x_vlan_mac_obj *obj, bool set,
7777 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7778{
619c5cb6
VZ
7779 int rc;
7780 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7781
619c5cb6 7782 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7783
619c5cb6
VZ
7784 /* Fill general parameters */
7785 ramrod_param.vlan_mac_obj = obj;
7786 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7787
619c5cb6
VZ
7788 /* Fill a user request section if needed */
7789 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7790 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7791
619c5cb6 7792 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7793
619c5cb6
VZ
7794 /* Set the command: ADD or DEL */
7795 if (set)
7796 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7797 else
7798 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7799 }
7800
619c5cb6 7801 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7802
7803 if (rc == -EEXIST) {
7804 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7805 /* do not treat adding same MAC as error */
7806 rc = 0;
7807 } else if (rc < 0)
619c5cb6 7808 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7809
619c5cb6 7810 return rc;
a2fbb9ea
ET
7811}
7812
619c5cb6
VZ
7813int bnx2x_del_all_macs(struct bnx2x *bp,
7814 struct bnx2x_vlan_mac_obj *mac_obj,
7815 int mac_type, bool wait_for_comp)
e665bfda 7816{
619c5cb6
VZ
7817 int rc;
7818 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7819
619c5cb6
VZ
7820 /* Wait for completion of requested */
7821 if (wait_for_comp)
7822 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7823
619c5cb6
VZ
7824 /* Set the mac type of addresses we want to clear */
7825 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7826
619c5cb6
VZ
7827 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7828 if (rc < 0)
7829 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7830
619c5cb6 7831 return rc;
0793f83f
DK
7832}
7833
619c5cb6 7834int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7835{
619c5cb6 7836 unsigned long ramrod_flags = 0;
e665bfda 7837
a3348722
BW
7838 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7839 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7840 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7841 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7842 return 0;
7843 }
614c76df 7844
619c5cb6 7845 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7846
619c5cb6
VZ
7847 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7848 /* Eth MAC is set on RSS leading client (fp[0]) */
15192a8c
BW
7849 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7850 set, BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7851}
6e30dd4e 7852
619c5cb6 7853int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7854{
619c5cb6 7855 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7856}
a2fbb9ea 7857
d6214d7a 7858/**
e8920674 7859 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7860 *
e8920674 7861 * @bp: driver handle
d6214d7a 7862 *
e8920674 7863 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7864 */
1ab4434c 7865int bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7866{
1ab4434c
AE
7867 int rc = 0;
7868
7869 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
7870 return -EINVAL;
7871
9ee3d37b 7872 switch (int_mode) {
1ab4434c
AE
7873 case BNX2X_INT_MODE_MSIX:
7874 /* attempt to enable msix */
7875 rc = bnx2x_enable_msix(bp);
7876
7877 /* msix attained */
7878 if (!rc)
7879 return 0;
7880
7881 /* vfs use only msix */
7882 if (rc && IS_VF(bp))
7883 return rc;
7884
7885 /* failed to enable multiple MSI-X */
7886 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7887 bp->num_queues,
7888 1 + bp->num_cnic_queues);
7889
7890 /* falling through... */
7891 case BNX2X_INT_MODE_MSI:
d6214d7a 7892 bnx2x_enable_msi(bp);
1ab4434c 7893
d6214d7a 7894 /* falling through... */
1ab4434c 7895 case BNX2X_INT_MODE_INTX:
55c11941
MS
7896 bp->num_ethernet_queues = 1;
7897 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7898 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7899 break;
d6214d7a 7900 default:
1ab4434c
AE
7901 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
7902 return -EINVAL;
9f6c9258 7903 }
1ab4434c 7904 return 0;
a2fbb9ea
ET
7905}
7906
1ab4434c 7907/* must be called prior to any HW initializations */
c2bff63f
DK
7908static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7909{
290ca2bb
AE
7910 if (IS_SRIOV(bp))
7911 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
c2bff63f
DK
7912 return L2_ILT_LINES(bp);
7913}
7914
523224a3
DK
7915void bnx2x_ilt_set_info(struct bnx2x *bp)
7916{
7917 struct ilt_client_info *ilt_client;
7918 struct bnx2x_ilt *ilt = BP_ILT(bp);
7919 u16 line = 0;
7920
7921 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7922 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7923
7924 /* CDU */
7925 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7926 ilt_client->client_num = ILT_CLIENT_CDU;
7927 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7928 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7929 ilt_client->start = line;
619c5cb6 7930 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
7931
7932 if (CNIC_SUPPORT(bp))
7933 line += CNIC_ILT_LINES;
523224a3
DK
7934 ilt_client->end = line - 1;
7935
51c1a580 7936 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7937 ilt_client->start,
7938 ilt_client->end,
7939 ilt_client->page_size,
7940 ilt_client->flags,
7941 ilog2(ilt_client->page_size >> 12));
7942
7943 /* QM */
7944 if (QM_INIT(bp->qm_cid_count)) {
7945 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7946 ilt_client->client_num = ILT_CLIENT_QM;
7947 ilt_client->page_size = QM_ILT_PAGE_SZ;
7948 ilt_client->flags = 0;
7949 ilt_client->start = line;
7950
7951 /* 4 bytes for each cid */
7952 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7953 QM_ILT_PAGE_SZ);
7954
7955 ilt_client->end = line - 1;
7956
51c1a580
MS
7957 DP(NETIF_MSG_IFUP,
7958 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
7959 ilt_client->start,
7960 ilt_client->end,
7961 ilt_client->page_size,
7962 ilt_client->flags,
7963 ilog2(ilt_client->page_size >> 12));
7964
7965 }
523224a3 7966
55c11941
MS
7967 if (CNIC_SUPPORT(bp)) {
7968 /* SRC */
7969 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7970 ilt_client->client_num = ILT_CLIENT_SRC;
7971 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7972 ilt_client->flags = 0;
7973 ilt_client->start = line;
7974 line += SRC_ILT_LINES;
7975 ilt_client->end = line - 1;
523224a3 7976
55c11941
MS
7977 DP(NETIF_MSG_IFUP,
7978 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7979 ilt_client->start,
7980 ilt_client->end,
7981 ilt_client->page_size,
7982 ilt_client->flags,
7983 ilog2(ilt_client->page_size >> 12));
9f6c9258 7984
55c11941
MS
7985 /* TM */
7986 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7987 ilt_client->client_num = ILT_CLIENT_TM;
7988 ilt_client->page_size = TM_ILT_PAGE_SZ;
7989 ilt_client->flags = 0;
7990 ilt_client->start = line;
7991 line += TM_ILT_LINES;
7992 ilt_client->end = line - 1;
523224a3 7993
55c11941
MS
7994 DP(NETIF_MSG_IFUP,
7995 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7996 ilt_client->start,
7997 ilt_client->end,
7998 ilt_client->page_size,
7999 ilt_client->flags,
8000 ilog2(ilt_client->page_size >> 12));
8001 }
9f6c9258 8002
619c5cb6 8003 BUG_ON(line > ILT_MAX_LINES);
523224a3 8004}
f85582f8 8005
619c5cb6
VZ
8006/**
8007 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8008 *
8009 * @bp: driver handle
8010 * @fp: pointer to fastpath
8011 * @init_params: pointer to parameters structure
8012 *
8013 * parameters configured:
8014 * - HC configuration
8015 * - Queue's CDU context
8016 */
1191cb83 8017static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 8018 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 8019{
6383c0b3
AE
8020
8021 u8 cos;
a052997e
MS
8022 int cxt_index, cxt_offset;
8023
619c5cb6
VZ
8024 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8025 if (!IS_FCOE_FP(fp)) {
8026 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8027 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8028
8029 /* If HC is supporterd, enable host coalescing in the transition
8030 * to INIT state.
8031 */
8032 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8033 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8034
8035 /* HC rate */
8036 init_params->rx.hc_rate = bp->rx_ticks ?
8037 (1000000 / bp->rx_ticks) : 0;
8038 init_params->tx.hc_rate = bp->tx_ticks ?
8039 (1000000 / bp->tx_ticks) : 0;
8040
8041 /* FW SB ID */
8042 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8043 fp->fw_sb_id;
8044
8045 /*
8046 * CQ index among the SB indices: FCoE clients uses the default
8047 * SB, therefore it's different.
8048 */
6383c0b3
AE
8049 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8050 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
8051 }
8052
6383c0b3
AE
8053 /* set maximum number of COSs supported by this queue */
8054 init_params->max_cos = fp->max_cos;
8055
51c1a580 8056 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
8057 fp->index, init_params->max_cos);
8058
8059 /* set the context pointers queue object */
a052997e 8060 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
8061 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8062 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 8063 ILT_PAGE_CIDS);
6383c0b3 8064 init_params->cxts[cos] =
a052997e
MS
8065 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8066 }
619c5cb6
VZ
8067}
8068
910cc727 8069static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
8070 struct bnx2x_queue_state_params *q_params,
8071 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8072 int tx_index, bool leading)
8073{
8074 memset(tx_only_params, 0, sizeof(*tx_only_params));
8075
8076 /* Set the command */
8077 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8078
8079 /* Set tx-only QUEUE flags: don't zero statistics */
8080 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8081
8082 /* choose the index of the cid to send the slow path on */
8083 tx_only_params->cid_index = tx_index;
8084
8085 /* Set general TX_ONLY_SETUP parameters */
8086 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8087
8088 /* Set Tx TX_ONLY_SETUP parameters */
8089 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8090
51c1a580
MS
8091 DP(NETIF_MSG_IFUP,
8092 "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
8093 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8094 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8095 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8096
8097 /* send the ramrod */
8098 return bnx2x_queue_state_change(bp, q_params);
8099}
8100
8101
619c5cb6
VZ
8102/**
8103 * bnx2x_setup_queue - setup queue
8104 *
8105 * @bp: driver handle
8106 * @fp: pointer to fastpath
8107 * @leading: is leading
8108 *
8109 * This function performs 2 steps in a Queue state machine
8110 * actually: 1) RESET->INIT 2) INIT->SETUP
8111 */
8112
8113int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8114 bool leading)
8115{
3b603066 8116 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8117 struct bnx2x_queue_setup_params *setup_params =
8118 &q_params.params.setup;
6383c0b3
AE
8119 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8120 &q_params.params.tx_only;
a2fbb9ea 8121 int rc;
6383c0b3
AE
8122 u8 tx_index;
8123
51c1a580 8124 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8125
ec6ba945
VZ
8126 /* reset IGU state skip FCoE L2 queue */
8127 if (!IS_FCOE_FP(fp))
8128 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8129 IGU_INT_ENABLE, 0);
a2fbb9ea 8130
15192a8c 8131 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8132 /* We want to wait for completion in this context */
8133 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8134
619c5cb6
VZ
8135 /* Prepare the INIT parameters */
8136 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8137
619c5cb6
VZ
8138 /* Set the command */
8139 q_params.cmd = BNX2X_Q_CMD_INIT;
8140
8141 /* Change the state to INIT */
8142 rc = bnx2x_queue_state_change(bp, &q_params);
8143 if (rc) {
6383c0b3 8144 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8145 return rc;
8146 }
ec6ba945 8147
51c1a580 8148 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
8149
8150
619c5cb6
VZ
8151 /* Now move the Queue to the SETUP state... */
8152 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8153
619c5cb6
VZ
8154 /* Set QUEUE flags */
8155 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8156
619c5cb6 8157 /* Set general SETUP parameters */
6383c0b3
AE
8158 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8159 FIRST_TX_COS_INDEX);
619c5cb6 8160
6383c0b3 8161 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8162 &setup_params->rxq_params);
8163
6383c0b3
AE
8164 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8165 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8166
8167 /* Set the command */
8168 q_params.cmd = BNX2X_Q_CMD_SETUP;
8169
55c11941
MS
8170 if (IS_FCOE_FP(fp))
8171 bp->fcoe_init = true;
8172
619c5cb6
VZ
8173 /* Change the state to SETUP */
8174 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8175 if (rc) {
8176 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8177 return rc;
8178 }
8179
8180 /* loop through the relevant tx-only indices */
8181 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8182 tx_index < fp->max_cos;
8183 tx_index++) {
8184
8185 /* prepare and send tx-only ramrod*/
8186 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8187 tx_only_params, tx_index, leading);
8188 if (rc) {
8189 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8190 fp->index, tx_index);
8191 return rc;
8192 }
8193 }
523224a3 8194
34f80b04 8195 return rc;
a2fbb9ea
ET
8196}
8197
619c5cb6 8198static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8199{
619c5cb6 8200 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8201 struct bnx2x_fp_txdata *txdata;
3b603066 8202 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8203 int rc, tx_index;
8204
51c1a580 8205 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8206
15192a8c 8207 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8208 /* We want to wait for completion in this context */
8209 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8210
6383c0b3
AE
8211
8212 /* close tx-only connections */
8213 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8214 tx_index < fp->max_cos;
8215 tx_index++){
8216
8217 /* ascertain this is a normal queue*/
65565884 8218 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8219
51c1a580 8220 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8221 txdata->txq_index);
8222
8223 /* send halt terminate on tx-only connection */
8224 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8225 memset(&q_params.params.terminate, 0,
8226 sizeof(q_params.params.terminate));
8227 q_params.params.terminate.cid_index = tx_index;
8228
8229 rc = bnx2x_queue_state_change(bp, &q_params);
8230 if (rc)
8231 return rc;
8232
8233 /* send halt terminate on tx-only connection */
8234 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8235 memset(&q_params.params.cfc_del, 0,
8236 sizeof(q_params.params.cfc_del));
8237 q_params.params.cfc_del.cid_index = tx_index;
8238 rc = bnx2x_queue_state_change(bp, &q_params);
8239 if (rc)
8240 return rc;
8241 }
8242 /* Stop the primary connection: */
8243 /* ...halt the connection */
619c5cb6
VZ
8244 q_params.cmd = BNX2X_Q_CMD_HALT;
8245 rc = bnx2x_queue_state_change(bp, &q_params);
8246 if (rc)
da5a662a 8247 return rc;
a2fbb9ea 8248
6383c0b3 8249 /* ...terminate the connection */
619c5cb6 8250 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8251 memset(&q_params.params.terminate, 0,
8252 sizeof(q_params.params.terminate));
8253 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8254 rc = bnx2x_queue_state_change(bp, &q_params);
8255 if (rc)
523224a3 8256 return rc;
6383c0b3 8257 /* ...delete cfc entry */
619c5cb6 8258 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8259 memset(&q_params.params.cfc_del, 0,
8260 sizeof(q_params.params.cfc_del));
8261 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8262 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8263}
8264
8265
34f80b04
EG
8266static void bnx2x_reset_func(struct bnx2x *bp)
8267{
8268 int port = BP_PORT(bp);
8269 int func = BP_FUNC(bp);
f2e0899f 8270 int i;
523224a3
DK
8271
8272 /* Disable the function in the FW */
8273 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8274 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8275 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8276 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8277
8278 /* FP SBs */
ec6ba945 8279 for_each_eth_queue(bp, i) {
523224a3 8280 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8281 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8282 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8283 SB_DISABLED);
523224a3
DK
8284 }
8285
55c11941
MS
8286 if (CNIC_LOADED(bp))
8287 /* CNIC SB */
8288 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8289 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8290 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8291
523224a3 8292 /* SP SB */
619c5cb6 8293 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8294 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8295 SB_DISABLED);
523224a3
DK
8296
8297 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8298 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8299 0);
34f80b04
EG
8300
8301 /* Configure IGU */
f2e0899f
DK
8302 if (bp->common.int_block == INT_BLOCK_HC) {
8303 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8304 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8305 } else {
8306 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8307 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8308 }
34f80b04 8309
55c11941
MS
8310 if (CNIC_LOADED(bp)) {
8311 /* Disable Timer scan */
8312 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8313 /*
8314 * Wait for at least 10ms and up to 2 second for the timers
8315 * scan to complete
8316 */
8317 for (i = 0; i < 200; i++) {
8318 msleep(10);
8319 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8320 break;
8321 }
37b091ba 8322 }
34f80b04 8323 /* Clear ILT */
f2e0899f
DK
8324 bnx2x_clear_func_ilt(bp, func);
8325
8326 /* Timers workaround bug for E2: if this is vnic-3,
8327 * we need to set the entire ilt range for this timers.
8328 */
619c5cb6 8329 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8330 struct ilt_client_info ilt_cli;
8331 /* use dummy TM client */
8332 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8333 ilt_cli.start = 0;
8334 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8335 ilt_cli.client_num = ILT_CLIENT_TM;
8336
8337 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8338 }
8339
8340 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8341 if (!CHIP_IS_E1x(bp))
f2e0899f 8342 bnx2x_pf_disable(bp);
523224a3
DK
8343
8344 bp->dmae_ready = 0;
34f80b04
EG
8345}
8346
8347static void bnx2x_reset_port(struct bnx2x *bp)
8348{
8349 int port = BP_PORT(bp);
8350 u32 val;
8351
619c5cb6
VZ
8352 /* Reset physical Link */
8353 bnx2x__link_reset(bp);
8354
34f80b04
EG
8355 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8356
8357 /* Do not rcv packets to BRB */
8358 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8359 /* Do not direct rcv packets that are not for MCP to the BRB */
8360 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8361 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8362
8363 /* Configure AEU */
8364 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8365
8366 msleep(100);
8367 /* Check for BRB port occupancy */
8368 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8369 if (val)
8370 DP(NETIF_MSG_IFDOWN,
33471629 8371 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8372
8373 /* TODO: Close Doorbell port? */
8374}
8375
1191cb83 8376static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8377{
3b603066 8378 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8379
619c5cb6
VZ
8380 /* Prepare parameters for function state transitions */
8381 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8382
619c5cb6
VZ
8383 func_params.f_obj = &bp->func_obj;
8384 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8385
619c5cb6 8386 func_params.params.hw_init.load_phase = load_code;
49d66772 8387
619c5cb6 8388 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8389}
8390
1191cb83 8391static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8392{
3b603066 8393 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8394 int rc;
228241eb 8395
619c5cb6
VZ
8396 /* Prepare parameters for function state transitions */
8397 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8398 func_params.f_obj = &bp->func_obj;
8399 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8400
619c5cb6
VZ
8401 /*
8402 * Try to stop the function the 'good way'. If fails (in case
8403 * of a parity error during bnx2x_chip_cleanup()) and we are
8404 * not in a debug mode, perform a state transaction in order to
8405 * enable further HW_RESET transaction.
8406 */
8407 rc = bnx2x_func_state_change(bp, &func_params);
8408 if (rc) {
34f80b04 8409#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8410 return rc;
34f80b04 8411#else
51c1a580 8412 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8413 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8414 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8415#endif
228241eb 8416 }
a2fbb9ea 8417
619c5cb6
VZ
8418 return 0;
8419}
523224a3 8420
619c5cb6
VZ
8421/**
8422 * bnx2x_send_unload_req - request unload mode from the MCP.
8423 *
8424 * @bp: driver handle
8425 * @unload_mode: requested function's unload mode
8426 *
8427 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8428 */
8429u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8430{
8431 u32 reset_code = 0;
8432 int port = BP_PORT(bp);
3101c2bc 8433
619c5cb6 8434 /* Select the UNLOAD request mode */
65abd74d
YG
8435 if (unload_mode == UNLOAD_NORMAL)
8436 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8437
7d0446c2 8438 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8439 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8440
7d0446c2 8441 else if (bp->wol) {
65abd74d
YG
8442 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8443 u8 *mac_addr = bp->dev->dev_addr;
8444 u32 val;
f9977903
DK
8445 u16 pmc;
8446
65abd74d 8447 /* The mac address is written to entries 1-4 to
f9977903
DK
8448 * preserve entry 0 which is used by the PMF
8449 */
3395a033 8450 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8451
8452 val = (mac_addr[0] << 8) | mac_addr[1];
8453 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8454
8455 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8456 (mac_addr[4] << 8) | mac_addr[5];
8457 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8458
f9977903
DK
8459 /* Enable the PME and clear the status */
8460 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8461 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8462 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8463
65abd74d
YG
8464 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8465
8466 } else
8467 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8468
619c5cb6
VZ
8469 /* Send the request to the MCP */
8470 if (!BP_NOMCP(bp))
8471 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8472 else {
8473 int path = BP_PATH(bp);
8474
51c1a580 8475 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8476 path, load_count[path][0], load_count[path][1],
8477 load_count[path][2]);
8478 load_count[path][0]--;
8479 load_count[path][1 + port]--;
51c1a580 8480 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8481 path, load_count[path][0], load_count[path][1],
8482 load_count[path][2]);
8483 if (load_count[path][0] == 0)
8484 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8485 else if (load_count[path][1 + port] == 0)
8486 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8487 else
8488 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8489 }
8490
8491 return reset_code;
8492}
8493
8494/**
8495 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8496 *
8497 * @bp: driver handle
5d07d868 8498 * @keep_link: true iff link should be kept up
619c5cb6 8499 */
5d07d868 8500void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8501{
5d07d868
YM
8502 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8503
619c5cb6
VZ
8504 /* Report UNLOAD_DONE to MCP */
8505 if (!BP_NOMCP(bp))
5d07d868 8506 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8507}
8508
1191cb83 8509static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8510{
8511 int tout = 50;
8512 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8513
8514 if (!bp->port.pmf)
8515 return 0;
8516
8517 /*
8518 * (assumption: No Attention from MCP at this stage)
8519 * PMF probably in the middle of TXdisable/enable transaction
8520 * 1. Sync IRS for default SB
8521 * 2. Sync SP queue - this guarantes us that attention handling started
8522 * 3. Wait, that TXdisable/enable transaction completes
8523 *
8524 * 1+2 guranty that if DCBx attention was scheduled it already changed
8525 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8526 * received complettion for the transaction the state is TX_STOPPED.
8527 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8528 * transaction.
8529 */
8530
8531 /* make sure default SB ISR is done */
8532 if (msix)
8533 synchronize_irq(bp->msix_table[0].vector);
8534 else
8535 synchronize_irq(bp->pdev->irq);
8536
8537 flush_workqueue(bnx2x_wq);
8538
8539 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8540 BNX2X_F_STATE_STARTED && tout--)
8541 msleep(20);
8542
8543 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8544 BNX2X_F_STATE_STARTED) {
8545#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8546 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8547 return -EBUSY;
8548#else
8549 /*
8550 * Failed to complete the transaction in a "good way"
8551 * Force both transactions with CLR bit
8552 */
3b603066 8553 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8554
51c1a580
MS
8555 DP(NETIF_MSG_IFDOWN,
8556 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8557
8558 func_params.f_obj = &bp->func_obj;
8559 __set_bit(RAMROD_DRV_CLR_ONLY,
8560 &func_params.ramrod_flags);
8561
8562 /* STARTED-->TX_ST0PPED */
8563 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8564 bnx2x_func_state_change(bp, &func_params);
8565
8566 /* TX_ST0PPED-->STARTED */
8567 func_params.cmd = BNX2X_F_CMD_TX_START;
8568 return bnx2x_func_state_change(bp, &func_params);
8569#endif
8570 }
8571
8572 return 0;
8573}
8574
5d07d868 8575void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8576{
8577 int port = BP_PORT(bp);
6383c0b3
AE
8578 int i, rc = 0;
8579 u8 cos;
3b603066 8580 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8581 u32 reset_code;
8582
8583 /* Wait until tx fastpath tasks complete */
8584 for_each_tx_queue(bp, i) {
8585 struct bnx2x_fastpath *fp = &bp->fp[i];
8586
6383c0b3 8587 for_each_cos_in_tx_queue(fp, cos)
65565884 8588 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8589#ifdef BNX2X_STOP_ON_ERROR
8590 if (rc)
8591 return;
8592#endif
8593 }
8594
8595 /* Give HW time to discard old tx messages */
8596 usleep_range(1000, 1000);
8597
8598 /* Clean all ETH MACs */
15192a8c
BW
8599 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8600 false);
619c5cb6
VZ
8601 if (rc < 0)
8602 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8603
8604 /* Clean up UC list */
15192a8c 8605 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8606 true);
8607 if (rc < 0)
51c1a580
MS
8608 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8609 rc);
619c5cb6
VZ
8610
8611 /* Disable LLH */
8612 if (!CHIP_IS_E1(bp))
8613 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8614
8615 /* Set "drop all" (stop Rx).
8616 * We need to take a netif_addr_lock() here in order to prevent
8617 * a race between the completion code and this code.
8618 */
8619 netif_addr_lock_bh(bp->dev);
8620 /* Schedule the rx_mode command */
8621 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8622 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8623 else
8624 bnx2x_set_storm_rx_mode(bp);
8625
8626 /* Cleanup multicast configuration */
8627 rparam.mcast_obj = &bp->mcast_obj;
8628 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8629 if (rc < 0)
8630 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8631
8632 netif_addr_unlock_bh(bp->dev);
8633
f1929b01 8634 bnx2x_iov_chip_cleanup(bp);
619c5cb6 8635
6debea87
DK
8636
8637 /*
8638 * Send the UNLOAD_REQUEST to the MCP. This will return if
8639 * this function should perform FUNC, PORT or COMMON HW
8640 * reset.
8641 */
8642 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8643
8644 /*
8645 * (assumption: No Attention from MCP at this stage)
8646 * PMF probably in the middle of TXdisable/enable transaction
8647 */
8648 rc = bnx2x_func_wait_started(bp);
8649 if (rc) {
8650 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8651#ifdef BNX2X_STOP_ON_ERROR
8652 return;
8653#endif
8654 }
8655
34f80b04 8656 /* Close multi and leading connections
619c5cb6
VZ
8657 * Completions for ramrods are collected in a synchronous way
8658 */
55c11941 8659 for_each_eth_queue(bp, i)
619c5cb6 8660 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8661#ifdef BNX2X_STOP_ON_ERROR
8662 return;
8663#else
228241eb 8664 goto unload_error;
523224a3 8665#endif
55c11941
MS
8666
8667 if (CNIC_LOADED(bp)) {
8668 for_each_cnic_queue(bp, i)
8669 if (bnx2x_stop_queue(bp, i))
8670#ifdef BNX2X_STOP_ON_ERROR
8671 return;
8672#else
8673 goto unload_error;
8674#endif
8675 }
8676
619c5cb6
VZ
8677 /* If SP settings didn't get completed so far - something
8678 * very wrong has happen.
8679 */
8680 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8681 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8682
619c5cb6
VZ
8683#ifndef BNX2X_STOP_ON_ERROR
8684unload_error:
8685#endif
523224a3 8686 rc = bnx2x_func_stop(bp);
da5a662a 8687 if (rc) {
523224a3 8688 BNX2X_ERR("Function stop failed!\n");
da5a662a 8689#ifdef BNX2X_STOP_ON_ERROR
523224a3 8690 return;
523224a3 8691#endif
34f80b04 8692 }
a2fbb9ea 8693
523224a3
DK
8694 /* Disable HW interrupts, NAPI */
8695 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8696 /* Delete all NAPI objects */
8697 bnx2x_del_all_napi(bp);
55c11941
MS
8698 if (CNIC_LOADED(bp))
8699 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8700
8701 /* Release IRQs */
d6214d7a 8702 bnx2x_free_irq(bp);
523224a3 8703
a2fbb9ea 8704 /* Reset the chip */
619c5cb6
VZ
8705 rc = bnx2x_reset_hw(bp, reset_code);
8706 if (rc)
8707 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8708
356e2385 8709
619c5cb6 8710 /* Report UNLOAD_DONE to MCP */
5d07d868 8711 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8712}
8713
9f6c9258 8714void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8715{
8716 u32 val;
8717
51c1a580 8718 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8719
8720 if (CHIP_IS_E1(bp)) {
8721 int port = BP_PORT(bp);
8722 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8723 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8724
8725 val = REG_RD(bp, addr);
8726 val &= ~(0x300);
8727 REG_WR(bp, addr, val);
619c5cb6 8728 } else {
72fd0718
VZ
8729 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8730 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8731 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8732 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8733 }
8734}
8735
72fd0718
VZ
8736/* Close gates #2, #3 and #4: */
8737static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8738{
c9ee9206 8739 u32 val;
72fd0718
VZ
8740
8741 /* Gates #2 and #4a are closed/opened for "not E1" only */
8742 if (!CHIP_IS_E1(bp)) {
8743 /* #4 */
c9ee9206 8744 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8745 /* #2 */
c9ee9206 8746 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8747 }
8748
8749 /* #3 */
c9ee9206
VZ
8750 if (CHIP_IS_E1x(bp)) {
8751 /* Prevent interrupts from HC on both ports */
8752 val = REG_RD(bp, HC_REG_CONFIG_1);
8753 REG_WR(bp, HC_REG_CONFIG_1,
8754 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8755 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8756
8757 val = REG_RD(bp, HC_REG_CONFIG_0);
8758 REG_WR(bp, HC_REG_CONFIG_0,
8759 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8760 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8761 } else {
8762 /* Prevent incomming interrupts in IGU */
8763 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8764
8765 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8766 (!close) ?
8767 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8768 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8769 }
72fd0718 8770
51c1a580 8771 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8772 close ? "closing" : "opening");
8773 mmiowb();
8774}
8775
8776#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8777
8778static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8779{
8780 /* Do some magic... */
8781 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8782 *magic_val = val & SHARED_MF_CLP_MAGIC;
8783 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8784}
8785
e8920674
DK
8786/**
8787 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8788 *
e8920674
DK
8789 * @bp: driver handle
8790 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8791 */
8792static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8793{
8794 /* Restore the `magic' bit value... */
72fd0718
VZ
8795 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8796 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8797 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8798}
8799
f85582f8 8800/**
e8920674 8801 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8802 *
e8920674
DK
8803 * @bp: driver handle
8804 * @magic_val: old value of 'magic' bit.
8805 *
8806 * Takes care of CLP configurations.
72fd0718
VZ
8807 */
8808static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8809{
8810 u32 shmem;
8811 u32 validity_offset;
8812
51c1a580 8813 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8814
8815 /* Set `magic' bit in order to save MF config */
8816 if (!CHIP_IS_E1(bp))
8817 bnx2x_clp_reset_prep(bp, magic_val);
8818
8819 /* Get shmem offset */
8820 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
8821 validity_offset =
8822 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
8823
8824 /* Clear validity map flags */
8825 if (shmem > 0)
8826 REG_WR(bp, shmem + validity_offset, 0);
8827}
8828
8829#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8830#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8831
e8920674
DK
8832/**
8833 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8834 *
e8920674 8835 * @bp: driver handle
72fd0718 8836 */
1191cb83 8837static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8838{
8839 /* special handling for emulation and FPGA,
8840 wait 10 times longer */
8841 if (CHIP_REV_IS_SLOW(bp))
8842 msleep(MCP_ONE_TIMEOUT*10);
8843 else
8844 msleep(MCP_ONE_TIMEOUT);
8845}
8846
1b6e2ceb
DK
8847/*
8848 * initializes bp->common.shmem_base and waits for validity signature to appear
8849 */
8850static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8851{
1b6e2ceb
DK
8852 int cnt = 0;
8853 u32 val = 0;
72fd0718 8854
1b6e2ceb
DK
8855 do {
8856 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8857 if (bp->common.shmem_base) {
8858 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8859 if (val & SHR_MEM_VALIDITY_MB)
8860 return 0;
8861 }
72fd0718 8862
1b6e2ceb 8863 bnx2x_mcp_wait_one(bp);
72fd0718 8864
1b6e2ceb 8865 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8866
1b6e2ceb 8867 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8868
1b6e2ceb
DK
8869 return -ENODEV;
8870}
72fd0718 8871
1b6e2ceb
DK
8872static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8873{
8874 int rc = bnx2x_init_shmem(bp);
72fd0718 8875
72fd0718
VZ
8876 /* Restore the `magic' bit value */
8877 if (!CHIP_IS_E1(bp))
8878 bnx2x_clp_reset_done(bp, magic_val);
8879
8880 return rc;
8881}
8882
8883static void bnx2x_pxp_prep(struct bnx2x *bp)
8884{
8885 if (!CHIP_IS_E1(bp)) {
8886 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8887 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8888 mmiowb();
8889 }
8890}
8891
8892/*
8893 * Reset the whole chip except for:
8894 * - PCIE core
8895 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8896 * one reset bit)
8897 * - IGU
8898 * - MISC (including AEU)
8899 * - GRC
8900 * - RBCN, RBCP
8901 */
c9ee9206 8902static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8903{
8904 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8905 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8906
8907 /*
8908 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8909 * (per chip) blocks.
8910 */
8911 global_bits2 =
8912 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8913 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 8914
c55e771b
BW
8915 /* Don't reset the following blocks.
8916 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
8917 * reset, as in 4 port device they might still be owned
8918 * by the MCP (there is only one leader per path).
8919 */
72fd0718
VZ
8920 not_reset_mask1 =
8921 MISC_REGISTERS_RESET_REG_1_RST_HC |
8922 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8923 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8924
8925 not_reset_mask2 =
c9ee9206 8926 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
8927 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8928 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8929 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8930 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8931 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8932 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
8933 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8934 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
8935 MISC_REGISTERS_RESET_REG_2_PGLC |
8936 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8937 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8938 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8939 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8940 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8941 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 8942
8736c826
VZ
8943 /*
8944 * Keep the following blocks in reset:
8945 * - all xxMACs are handled by the bnx2x_link code.
8946 */
8947 stay_reset2 =
8736c826
VZ
8948 MISC_REGISTERS_RESET_REG_2_XMAC |
8949 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8950
8951 /* Full reset masks according to the chip */
72fd0718
VZ
8952 reset_mask1 = 0xffffffff;
8953
8954 if (CHIP_IS_E1(bp))
8955 reset_mask2 = 0xffff;
8736c826 8956 else if (CHIP_IS_E1H(bp))
72fd0718 8957 reset_mask2 = 0x1ffff;
8736c826
VZ
8958 else if (CHIP_IS_E2(bp))
8959 reset_mask2 = 0xfffff;
8960 else /* CHIP_IS_E3 */
8961 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
8962
8963 /* Don't reset global blocks unless we need to */
8964 if (!global)
8965 reset_mask2 &= ~global_bits2;
8966
8967 /*
8968 * In case of attention in the QM, we need to reset PXP
8969 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8970 * because otherwise QM reset would release 'close the gates' shortly
8971 * before resetting the PXP, then the PSWRQ would send a write
8972 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8973 * read the payload data from PSWWR, but PSWWR would not
8974 * respond. The write queue in PGLUE would stuck, dmae commands
8975 * would not return. Therefore it's important to reset the second
8976 * reset register (containing the
8977 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8978 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8979 * bit).
8980 */
72fd0718
VZ
8981 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8982 reset_mask2 & (~not_reset_mask2));
8983
c9ee9206
VZ
8984 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8985 reset_mask1 & (~not_reset_mask1));
8986
72fd0718
VZ
8987 barrier();
8988 mmiowb();
8989
8736c826
VZ
8990 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8991 reset_mask2 & (~stay_reset2));
8992
8993 barrier();
8994 mmiowb();
8995
c9ee9206 8996 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
8997 mmiowb();
8998}
8999
c9ee9206
VZ
9000/**
9001 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9002 * It should get cleared in no more than 1s.
9003 *
9004 * @bp: driver handle
9005 *
9006 * It should get cleared in no more than 1s. Returns 0 if
9007 * pending writes bit gets cleared.
9008 */
9009static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9010{
9011 u32 cnt = 1000;
9012 u32 pend_bits = 0;
9013
9014 do {
9015 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9016
9017 if (pend_bits == 0)
9018 break;
9019
9020 usleep_range(1000, 1000);
9021 } while (cnt-- > 0);
9022
9023 if (cnt <= 0) {
9024 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9025 pend_bits);
9026 return -EBUSY;
9027 }
9028
9029 return 0;
9030}
9031
9032static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
9033{
9034 int cnt = 1000;
9035 u32 val = 0;
9036 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
c55e771b 9037 u32 tags_63_32 = 0;
72fd0718
VZ
9038
9039
9040 /* Empty the Tetris buffer, wait for 1s */
9041 do {
9042 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9043 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9044 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9045 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9046 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
9047 if (CHIP_IS_E3(bp))
9048 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9049
72fd0718
VZ
9050 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9051 ((port_is_idle_0 & 0x1) == 0x1) &&
9052 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
9053 (pgl_exp_rom2 == 0xffffffff) &&
9054 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 9055 break;
c9ee9206 9056 usleep_range(1000, 1000);
72fd0718
VZ
9057 } while (cnt-- > 0);
9058
9059 if (cnt <= 0) {
51c1a580
MS
9060 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9061 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
9062 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9063 pgl_exp_rom2);
9064 return -EAGAIN;
9065 }
9066
9067 barrier();
9068
9069 /* Close gates #2, #3 and #4 */
9070 bnx2x_set_234_gates(bp, true);
9071
c9ee9206
VZ
9072 /* Poll for IGU VQs for 57712 and newer chips */
9073 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9074 return -EAGAIN;
9075
9076
72fd0718
VZ
9077 /* TBD: Indicate that "process kill" is in progress to MCP */
9078
9079 /* Clear "unprepared" bit */
9080 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9081 barrier();
9082
9083 /* Make sure all is written to the chip before the reset */
9084 mmiowb();
9085
9086 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9087 * PSWHST, GRC and PSWRD Tetris buffer.
9088 */
c9ee9206 9089 usleep_range(1000, 1000);
72fd0718
VZ
9090
9091 /* Prepare to chip reset: */
9092 /* MCP */
c9ee9206
VZ
9093 if (global)
9094 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
9095
9096 /* PXP */
9097 bnx2x_pxp_prep(bp);
9098 barrier();
9099
9100 /* reset the chip */
c9ee9206 9101 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9102 barrier();
9103
9104 /* Recover after reset: */
9105 /* MCP */
c9ee9206 9106 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9107 return -EAGAIN;
9108
c9ee9206
VZ
9109 /* TBD: Add resetting the NO_MCP mode DB here */
9110
72fd0718
VZ
9111 /* Open the gates #2, #3 and #4 */
9112 bnx2x_set_234_gates(bp, false);
9113
9114 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9115 * reset state, re-enable attentions. */
9116
a2fbb9ea
ET
9117 return 0;
9118}
9119
910cc727 9120static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9121{
9122 int rc = 0;
c9ee9206 9123 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9124 u32 load_code;
9125
9126 /* if not going to reset MCP - load "fake" driver to reset HW while
9127 * driver is owner of the HW
9128 */
9129 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9130 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9131 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9132 if (!load_code) {
9133 BNX2X_ERR("MCP response failure, aborting\n");
9134 rc = -EAGAIN;
9135 goto exit_leader_reset;
9136 }
9137 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9138 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9139 BNX2X_ERR("MCP unexpected resp, aborting\n");
9140 rc = -EAGAIN;
9141 goto exit_leader_reset2;
9142 }
9143 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9144 if (!load_code) {
9145 BNX2X_ERR("MCP response failure, aborting\n");
9146 rc = -EAGAIN;
9147 goto exit_leader_reset2;
9148 }
9149 }
c9ee9206 9150
72fd0718 9151 /* Try to recover after the failure */
c9ee9206 9152 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9153 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9154 BP_PATH(bp));
72fd0718 9155 rc = -EAGAIN;
95c6c616 9156 goto exit_leader_reset2;
72fd0718
VZ
9157 }
9158
c9ee9206
VZ
9159 /*
9160 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9161 * state.
9162 */
72fd0718 9163 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9164 if (global)
9165 bnx2x_clear_reset_global(bp);
72fd0718 9166
95c6c616
AE
9167exit_leader_reset2:
9168 /* unload "fake driver" if it was loaded */
9169 if (!global && !BP_NOMCP(bp)) {
9170 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9171 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9172 }
72fd0718
VZ
9173exit_leader_reset:
9174 bp->is_leader = 0;
c9ee9206
VZ
9175 bnx2x_release_leader_lock(bp);
9176 smp_mb();
72fd0718
VZ
9177 return rc;
9178}
9179
1191cb83 9180static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9181{
9182 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9183
9184 /* Disconnect this device */
9185 netif_device_detach(bp->dev);
9186
9187 /*
9188 * Block ifup for all function on this engine until "process kill"
9189 * or power cycle.
9190 */
9191 bnx2x_set_reset_in_progress(bp);
9192
9193 /* Shut down the power */
9194 bnx2x_set_power_state(bp, PCI_D3hot);
9195
9196 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9197
9198 smp_mb();
9199}
9200
9201/*
9202 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9203 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9204 * will never be called when netif_running(bp->dev) is false.
9205 */
9206static void bnx2x_parity_recover(struct bnx2x *bp)
9207{
c9ee9206 9208 bool global = false;
7a752993 9209 u32 error_recovered, error_unrecovered;
95c6c616 9210 bool is_parity;
c9ee9206 9211
72fd0718
VZ
9212 DP(NETIF_MSG_HW, "Handling parity\n");
9213 while (1) {
9214 switch (bp->recovery_state) {
9215 case BNX2X_RECOVERY_INIT:
9216 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9217 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9218 WARN_ON(!is_parity);
c9ee9206 9219
72fd0718 9220 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9221 if (bnx2x_trylock_leader_lock(bp)) {
9222 bnx2x_set_reset_in_progress(bp);
9223 /*
9224 * Check if there is a global attention and if
9225 * there was a global attention, set the global
9226 * reset bit.
9227 */
9228
9229 if (global)
9230 bnx2x_set_reset_global(bp);
9231
72fd0718 9232 bp->is_leader = 1;
c9ee9206 9233 }
72fd0718
VZ
9234
9235 /* Stop the driver */
9236 /* If interface has been removed - break */
5d07d868 9237 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9238 return;
9239
9240 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9241
c9ee9206
VZ
9242 /* Ensure "is_leader", MCP command sequence and
9243 * "recovery_state" update values are seen on other
9244 * CPUs.
72fd0718 9245 */
c9ee9206 9246 smp_mb();
72fd0718
VZ
9247 break;
9248
9249 case BNX2X_RECOVERY_WAIT:
9250 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9251 if (bp->is_leader) {
c9ee9206 9252 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9253 bool other_load_status =
9254 bnx2x_get_load_status(bp, other_engine);
9255 bool load_status =
9256 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9257 global = bnx2x_reset_is_global(bp);
9258
9259 /*
9260 * In case of a parity in a global block, let
9261 * the first leader that performs a
9262 * leader_reset() reset the global blocks in
9263 * order to clear global attentions. Otherwise
9264 * the the gates will remain closed for that
9265 * engine.
9266 */
889b9af3
AE
9267 if (load_status ||
9268 (global && other_load_status)) {
72fd0718
VZ
9269 /* Wait until all other functions get
9270 * down.
9271 */
7be08a72 9272 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9273 HZ/10);
9274 return;
9275 } else {
9276 /* If all other functions got down -
9277 * try to bring the chip back to
9278 * normal. In any case it's an exit
9279 * point for a leader.
9280 */
c9ee9206
VZ
9281 if (bnx2x_leader_reset(bp)) {
9282 bnx2x_recovery_failed(bp);
72fd0718
VZ
9283 return;
9284 }
9285
c9ee9206
VZ
9286 /* If we are here, means that the
9287 * leader has succeeded and doesn't
9288 * want to be a leader any more. Try
9289 * to continue as a none-leader.
9290 */
9291 break;
72fd0718
VZ
9292 }
9293 } else { /* non-leader */
c9ee9206 9294 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9295 /* Try to get a LEADER_LOCK HW lock as
9296 * long as a former leader may have
9297 * been unloaded by the user or
9298 * released a leadership by another
9299 * reason.
9300 */
c9ee9206 9301 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9302 /* I'm a leader now! Restart a
9303 * switch case.
9304 */
9305 bp->is_leader = 1;
9306 break;
9307 }
9308
7be08a72 9309 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9310 HZ/10);
9311 return;
9312
c9ee9206
VZ
9313 } else {
9314 /*
9315 * If there was a global attention, wait
9316 * for it to be cleared.
9317 */
9318 if (bnx2x_reset_is_global(bp)) {
9319 schedule_delayed_work(
7be08a72
AE
9320 &bp->sp_rtnl_task,
9321 HZ/10);
c9ee9206
VZ
9322 return;
9323 }
9324
7a752993
AE
9325 error_recovered =
9326 bp->eth_stats.recoverable_error;
9327 error_unrecovered =
9328 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9329 bp->recovery_state =
9330 BNX2X_RECOVERY_NIC_LOADING;
9331 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9332 error_unrecovered++;
95c6c616 9333 netdev_err(bp->dev,
51c1a580 9334 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9335 /* Disconnect this device */
9336 netif_device_detach(bp->dev);
9337 /* Shut down the power */
9338 bnx2x_set_power_state(
9339 bp, PCI_D3hot);
9340 smp_mb();
9341 } else {
c9ee9206
VZ
9342 bp->recovery_state =
9343 BNX2X_RECOVERY_DONE;
7a752993 9344 error_recovered++;
c9ee9206
VZ
9345 smp_mb();
9346 }
7a752993
AE
9347 bp->eth_stats.recoverable_error =
9348 error_recovered;
9349 bp->eth_stats.unrecoverable_error =
9350 error_unrecovered;
c9ee9206 9351
72fd0718
VZ
9352 return;
9353 }
9354 }
9355 default:
9356 return;
9357 }
9358 }
9359}
9360
56ad3152
MS
9361static int bnx2x_close(struct net_device *dev);
9362
72fd0718
VZ
9363/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9364 * scheduled on a general queue in order to prevent a dead lock.
9365 */
7be08a72 9366static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9367{
7be08a72 9368 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9369
9370 rtnl_lock();
9371
9372 if (!netif_running(bp->dev))
7be08a72
AE
9373 goto sp_rtnl_exit;
9374
9375 /* if stop on error is defined no recovery flows should be executed */
9376#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9377 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9378 "you will need to reboot when done\n");
b1fb8740 9379 goto sp_rtnl_not_reset;
7be08a72 9380#endif
34f80b04 9381
7be08a72
AE
9382 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9383 /*
b1fb8740
VZ
9384 * Clear all pending SP commands as we are going to reset the
9385 * function anyway.
7be08a72 9386 */
b1fb8740
VZ
9387 bp->sp_rtnl_state = 0;
9388 smp_mb();
9389
72fd0718 9390 bnx2x_parity_recover(bp);
b1fb8740
VZ
9391
9392 goto sp_rtnl_exit;
9393 }
9394
9395 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9396 /*
9397 * Clear all pending SP commands as we are going to reset the
9398 * function anyway.
9399 */
9400 bp->sp_rtnl_state = 0;
9401 smp_mb();
9402
5d07d868 9403 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9404 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740
VZ
9405
9406 goto sp_rtnl_exit;
72fd0718 9407 }
b1fb8740
VZ
9408#ifdef BNX2X_STOP_ON_ERROR
9409sp_rtnl_not_reset:
9410#endif
9411 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9412 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9413 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9414 bnx2x_after_function_update(bp);
8304859a
AE
9415 /*
9416 * in case of fan failure we need to reset id if the "stop on error"
9417 * debug flag is set, since we trying to prevent permanent overheating
9418 * damage
9419 */
9420 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9421 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9422 netif_device_detach(bp->dev);
9423 bnx2x_close(bp->dev);
9424 }
9425
381ac16b
AE
9426 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9427 DP(BNX2X_MSG_SP,
9428 "sending set mcast vf pf channel message from rtnl sp-task\n");
9429 bnx2x_vfpf_set_mcast(bp->dev);
9430 }
9431
9432 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
9433 &bp->sp_rtnl_state)) {
9434 DP(BNX2X_MSG_SP,
9435 "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
9436 bnx2x_vfpf_storm_rx_mode(bp);
9437 }
9438
7be08a72 9439sp_rtnl_exit:
34f80b04
EG
9440 rtnl_unlock();
9441}
9442
a2fbb9ea
ET
9443/* end of nic load/unload */
9444
3deb8167
YR
9445static void bnx2x_period_task(struct work_struct *work)
9446{
9447 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9448
9449 if (!netif_running(bp->dev))
9450 goto period_task_exit;
9451
9452 if (CHIP_REV_IS_SLOW(bp)) {
9453 BNX2X_ERR("period task called on emulation, ignoring\n");
9454 goto period_task_exit;
9455 }
9456
9457 bnx2x_acquire_phy_lock(bp);
9458 /*
9459 * The barrier is needed to ensure the ordering between the writing to
9460 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9461 * the reading here.
9462 */
9463 smp_mb();
9464 if (bp->port.pmf) {
9465 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9466
9467 /* Re-queue task in 1 sec */
9468 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9469 }
9470
9471 bnx2x_release_phy_lock(bp);
9472period_task_exit:
9473 return;
9474}
9475
a2fbb9ea
ET
9476/*
9477 * Init service functions
9478 */
9479
b56e9670 9480u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9481{
9482 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9483 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9484 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9485}
9486
f2e0899f 9487static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
f1ef27ef 9488{
f2e0899f 9489 u32 reg = bnx2x_get_pretend_reg(bp);
f1ef27ef
EG
9490
9491 /* Flush all outstanding writes */
9492 mmiowb();
9493
9494 /* Pretend to be function 0 */
9495 REG_WR(bp, reg, 0);
f2e0899f 9496 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
f1ef27ef
EG
9497
9498 /* From now we are in the "like-E1" mode */
9499 bnx2x_int_disable(bp);
9500
9501 /* Flush all outstanding writes */
9502 mmiowb();
9503
f2e0899f
DK
9504 /* Restore the original function */
9505 REG_WR(bp, reg, BP_ABS_FUNC(bp));
9506 REG_RD(bp, reg);
f1ef27ef
EG
9507}
9508
f2e0899f 9509static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
f1ef27ef 9510{
f2e0899f 9511 if (CHIP_IS_E1(bp))
f1ef27ef 9512 bnx2x_int_disable(bp);
f2e0899f
DK
9513 else
9514 bnx2x_undi_int_disable_e1h(bp);
f1ef27ef
EG
9515}
9516
0329aba1 9517static void bnx2x_prev_unload_close_mac(struct bnx2x *bp)
34f80b04 9518{
452427b0
YM
9519 u32 val, base_addr, offset, mask, reset_reg;
9520 bool mac_stopped = false;
9521 u8 port = BP_PORT(bp);
34f80b04 9522
452427b0 9523 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9524
452427b0
YM
9525 if (!CHIP_IS_E3(bp)) {
9526 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9527 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9528 if ((mask & reset_reg) && val) {
9529 u32 wb_data[2];
9530 BNX2X_DEV_INFO("Disable bmac Rx\n");
9531 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9532 : NIG_REG_INGRESS_BMAC0_MEM;
9533 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9534 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9535
452427b0
YM
9536 /*
9537 * use rd/wr since we cannot use dmae. This is safe
9538 * since MCP won't access the bus due to the request
9539 * to unload, and no function on the path can be
9540 * loaded at this time.
9541 */
9542 wb_data[0] = REG_RD(bp, base_addr + offset);
9543 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
9544 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
9545 REG_WR(bp, base_addr + offset, wb_data[0]);
9546 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
9547
9548 }
9549 BNX2X_DEV_INFO("Disable emac Rx\n");
9550 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
9551
9552 mac_stopped = true;
9553 } else {
9554 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9555 BNX2X_DEV_INFO("Disable xmac Rx\n");
9556 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9557 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9558 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9559 val & ~(1 << 1));
9560 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9561 val | (1 << 1));
9562 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
9563 mac_stopped = true;
9564 }
9565 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9566 if (mask & reset_reg) {
9567 BNX2X_DEV_INFO("Disable umac Rx\n");
9568 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9569 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
9570 mac_stopped = true;
9571 }
9572 }
9573
9574 if (mac_stopped)
9575 msleep(20);
9576
9577}
9578
9579#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9580#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9581#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9582#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9583
1dd06ae8 9584static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
452427b0
YM
9585{
9586 u16 rcq, bd;
9587 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9588
9589 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9590 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9591
9592 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9593 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9594
9595 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9596 port, bd, rcq);
9597}
9598
0329aba1 9599static int bnx2x_prev_mcp_done(struct bnx2x *bp)
452427b0 9600{
5d07d868
YM
9601 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9602 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9603 if (!rc) {
9604 BNX2X_ERR("MCP response failure, aborting\n");
9605 return -EBUSY;
9606 }
9607
9608 return 0;
9609}
9610
c63da990
BW
9611static struct bnx2x_prev_path_list *
9612 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9613{
9614 struct bnx2x_prev_path_list *tmp_list;
9615
9616 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9617 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9618 bp->pdev->bus->number == tmp_list->bus &&
9619 BP_PATH(bp) == tmp_list->path)
9620 return tmp_list;
9621
9622 return NULL;
9623}
9624
0329aba1 9625static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
452427b0
YM
9626{
9627 struct bnx2x_prev_path_list *tmp_list;
9628 int rc = false;
9629
9630 if (down_trylock(&bnx2x_prev_sem))
9631 return false;
9632
9633 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9634 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9635 bp->pdev->bus->number == tmp_list->bus &&
9636 BP_PATH(bp) == tmp_list->path) {
9637 rc = true;
9638 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9639 BP_PATH(bp));
9640 break;
9641 }
9642 }
9643
9644 up(&bnx2x_prev_sem);
9645
9646 return rc;
9647}
9648
c63da990 9649static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
452427b0
YM
9650{
9651 struct bnx2x_prev_path_list *tmp_list;
9652 int rc;
9653
ea4b3857 9654 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9655 if (!tmp_list) {
9656 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9657 return -ENOMEM;
9658 }
9659
9660 tmp_list->bus = bp->pdev->bus->number;
9661 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9662 tmp_list->path = BP_PATH(bp);
c63da990 9663 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
452427b0
YM
9664
9665 rc = down_interruptible(&bnx2x_prev_sem);
9666 if (rc) {
9667 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9668 kfree(tmp_list);
9669 } else {
9670 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9671 BP_PATH(bp));
9672 list_add(&tmp_list->list, &bnx2x_prev_list);
9673 up(&bnx2x_prev_sem);
9674 }
9675
9676 return rc;
9677}
9678
0329aba1 9679static int bnx2x_do_flr(struct bnx2x *bp)
452427b0 9680{
2a80eebc 9681 int i;
452427b0
YM
9682 u16 status;
9683 struct pci_dev *dev = bp->pdev;
9684
8eee694c
YM
9685
9686 if (CHIP_IS_E1x(bp)) {
9687 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9688 return -EINVAL;
9689 }
9690
9691 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9692 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9693 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9694 bp->common.bc_ver);
9695 return -EINVAL;
9696 }
452427b0 9697
452427b0
YM
9698 /* Wait for Transaction Pending bit clean */
9699 for (i = 0; i < 4; i++) {
9700 if (i)
9701 msleep((1 << (i - 1)) * 100);
9702
2a80eebc 9703 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9704 if (!(status & PCI_EXP_DEVSTA_TRPND))
9705 goto clear;
9706 }
9707
9708 dev_err(&dev->dev,
9709 "transaction is not cleared; proceeding with reset anyway\n");
9710
9711clear:
452427b0 9712
8eee694c 9713 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9714 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9715
9716 return 0;
9717}
9718
0329aba1 9719static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
452427b0
YM
9720{
9721 int rc;
9722
9723 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9724
9725 /* Test if previous unload process was already finished for this path */
9726 if (bnx2x_prev_is_path_marked(bp))
9727 return bnx2x_prev_mcp_done(bp);
9728
9729 /* If function has FLR capabilities, and existing FW version matches
9730 * the one required, then FLR will be sufficient to clean any residue
9731 * left by previous driver
9732 */
ad5afc89 9733 rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
8eee694c
YM
9734
9735 if (!rc) {
9736 /* fw version is good */
9737 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9738 rc = bnx2x_do_flr(bp);
9739 }
9740
9741 if (!rc) {
9742 /* FLR was performed */
9743 BNX2X_DEV_INFO("FLR successful\n");
9744 return 0;
9745 }
9746
9747 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9748
9749 /* Close the MCP request, return failure*/
9750 rc = bnx2x_prev_mcp_done(bp);
9751 if (!rc)
9752 rc = BNX2X_PREV_WAIT_NEEDED;
9753
9754 return rc;
9755}
9756
0329aba1 9757static int bnx2x_prev_unload_common(struct bnx2x *bp)
452427b0
YM
9758{
9759 u32 reset_reg, tmp_reg = 0, rc;
c63da990 9760 bool prev_undi = false;
452427b0
YM
9761 /* It is possible a previous function received 'common' answer,
9762 * but hasn't loaded yet, therefore creating a scenario of
9763 * multiple functions receiving 'common' on the same path.
9764 */
9765 BNX2X_DEV_INFO("Common unload Flow\n");
9766
9767 if (bnx2x_prev_is_path_marked(bp))
9768 return bnx2x_prev_mcp_done(bp);
9769
9770 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9771
9772 /* Reset should be performed after BRB is emptied */
9773 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9774 u32 timer_count = 1000;
452427b0
YM
9775
9776 /* Close the MAC Rx to prevent BRB from filling up */
9777 bnx2x_prev_unload_close_mac(bp);
9778
9779 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9780 * UNDI driver initializes CID offset for normal bell to 0x7
9781 */
452427b0
YM
9782 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9783 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9784 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9785 if (tmp_reg == 0x7) {
9786 BNX2X_DEV_INFO("UNDI previously loaded\n");
9787 prev_undi = true;
9788 /* clear the UNDI indication */
9789 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
34f80b04 9790 }
452427b0
YM
9791 }
9792 /* wait until BRB is empty */
9793 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9794 while (timer_count) {
9795 u32 prev_brb = tmp_reg;
34f80b04 9796
452427b0
YM
9797 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9798 if (!tmp_reg)
9799 break;
619c5cb6 9800
452427b0 9801 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9802
452427b0
YM
9803 /* reset timer as long as BRB actually gets emptied */
9804 if (prev_brb > tmp_reg)
9805 timer_count = 1000;
9806 else
9807 timer_count--;
da5a662a 9808
452427b0
YM
9809 /* If UNDI resides in memory, manually increment it */
9810 if (prev_undi)
9811 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9812
452427b0 9813 udelay(10);
7a06a122 9814 }
452427b0
YM
9815
9816 if (!timer_count)
9817 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9818
34f80b04 9819 }
f16da43b 9820
452427b0
YM
9821 /* No packets are in the pipeline, path is ready for reset */
9822 bnx2x_reset_common(bp);
9823
c63da990 9824 rc = bnx2x_prev_mark_path(bp, prev_undi);
452427b0
YM
9825 if (rc) {
9826 bnx2x_prev_mcp_done(bp);
9827 return rc;
9828 }
9829
9830 return bnx2x_prev_mcp_done(bp);
9831}
9832
24f06716
AE
9833/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9834 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9835 * the addresses of the transaction, resulting in was-error bit set in the pci
9836 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9837 * to clear the interrupt which detected this from the pglueb and the was done
9838 * bit
9839 */
0329aba1 9840static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
24f06716 9841{
4a25417c
AE
9842 if (!CHIP_IS_E1x(bp)) {
9843 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9844 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9845 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9846 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9847 1 << BP_FUNC(bp));
9848 }
24f06716
AE
9849 }
9850}
9851
0329aba1 9852static int bnx2x_prev_unload(struct bnx2x *bp)
452427b0
YM
9853{
9854 int time_counter = 10;
9855 u32 rc, fw, hw_lock_reg, hw_lock_val;
c63da990 9856 struct bnx2x_prev_path_list *prev_list;
452427b0
YM
9857 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9858
24f06716
AE
9859 /* clear hw from errors which may have resulted from an interrupted
9860 * dmae transaction.
9861 */
9862 bnx2x_prev_interrupted_dmae(bp);
9863
9864 /* Release previously held locks */
452427b0
YM
9865 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9866 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9867 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9868
9869 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9870 if (hw_lock_val) {
9871 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9872 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9873 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9874 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9875 }
9876
9877 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9878 REG_WR(bp, hw_lock_reg, 0xffffffff);
9879 } else
9880 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9881
9882 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9883 BNX2X_DEV_INFO("Release previously held alr\n");
9884 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9885 }
9886
9887
9888 do {
9889 /* Lock MCP using an unload request */
9890 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9891 if (!fw) {
9892 BNX2X_ERR("MCP response failure, aborting\n");
9893 rc = -EBUSY;
9894 break;
9895 }
9896
9897 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9898 rc = bnx2x_prev_unload_common(bp);
9899 break;
9900 }
9901
9902 /* non-common reply from MCP night require looping */
9903 rc = bnx2x_prev_unload_uncommon(bp);
9904 if (rc != BNX2X_PREV_WAIT_NEEDED)
9905 break;
9906
9907 msleep(20);
9908 } while (--time_counter);
9909
9910 if (!time_counter || rc) {
9911 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9912 rc = -EBUSY;
9913 }
9914
c63da990
BW
9915 /* Mark function if its port was used to boot from SAN */
9916 prev_list = bnx2x_prev_path_get_entry(bp);
9917 if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
9918 bp->link_params.feature_config_flags |=
9919 FEATURE_CONFIG_BOOT_FROM_SAN;
9920
452427b0
YM
9921 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9922
9923 return rc;
34f80b04
EG
9924}
9925
0329aba1 9926static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
34f80b04 9927{
1d187b34 9928 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 9929 u16 pmc;
34f80b04
EG
9930
9931 /* Get the chip revision id and number. */
9932 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9933 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9934 id = ((val & 0xffff) << 16);
9935 val = REG_RD(bp, MISC_REG_CHIP_REV);
9936 id |= ((val & 0xf) << 12);
9937 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9938 id |= ((val & 0xff) << 4);
5a40e08e 9939 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
9940 id |= (val & 0xf);
9941 bp->common.chip_id = id;
523224a3 9942
7e8e02df
BW
9943 /* force 57811 according to MISC register */
9944 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
9945 if (CHIP_IS_57810(bp))
9946 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
9947 (bp->common.chip_id & 0x0000FFFF);
9948 else if (CHIP_IS_57810_MF(bp))
9949 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
9950 (bp->common.chip_id & 0x0000FFFF);
9951 bp->common.chip_id |= 0x1;
9952 }
9953
523224a3
DK
9954 /* Set doorbell size */
9955 bp->db_size = (1 << BNX2X_DB_SHIFT);
9956
619c5cb6 9957 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
9958 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9959 if ((val & 1) == 0)
9960 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9961 else
9962 val = (val >> 1) & 1;
9963 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9964 "2_PORT_MODE");
9965 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9966 CHIP_2_PORT_MODE;
9967
9968 if (CHIP_MODE_IS_4_PORT(bp))
9969 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9970 else
9971 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9972 } else {
9973 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9974 bp->pfid = bp->pf_num; /* 0..7 */
9975 }
9976
51c1a580
MS
9977 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9978
f2e0899f
DK
9979 bp->link_params.chip_id = bp->common.chip_id;
9980 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 9981
1c06328c
EG
9982 val = (REG_RD(bp, 0x2874) & 0x55);
9983 if ((bp->common.chip_id & 0x1) ||
9984 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9985 bp->flags |= ONE_PORT_FLAG;
9986 BNX2X_DEV_INFO("single port device\n");
9987 }
9988
34f80b04 9989 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 9990 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
9991 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9992 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9993 bp->common.flash_size, bp->common.flash_size);
9994
1b6e2ceb
DK
9995 bnx2x_init_shmem(bp);
9996
619c5cb6
VZ
9997
9998
f2e0899f
DK
9999 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10000 MISC_REG_GENERIC_CR_1 :
10001 MISC_REG_GENERIC_CR_0));
1b6e2ceb 10002
34f80b04 10003 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 10004 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
10005 if (SHMEM2_RD(bp, size) >
10006 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10007 bp->link_params.lfa_base =
10008 REG_RD(bp, bp->common.shmem2_base +
10009 (u32)offsetof(struct shmem2_region,
10010 lfa_host_addr[BP_PORT(bp)]));
10011 else
10012 bp->link_params.lfa_base = 0;
2691d51d
EG
10013 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10014 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 10015
f2e0899f 10016 if (!bp->common.shmem_base) {
34f80b04
EG
10017 BNX2X_DEV_INFO("MCP not active\n");
10018 bp->flags |= NO_MCP_FLAG;
10019 return;
10020 }
10021
34f80b04 10022 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 10023 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
10024
10025 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10026 SHARED_HW_CFG_LED_MODE_MASK) >>
10027 SHARED_HW_CFG_LED_MODE_SHIFT);
10028
c2c8b03e
EG
10029 bp->link_params.feature_config_flags = 0;
10030 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10031 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10032 bp->link_params.feature_config_flags |=
10033 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10034 else
10035 bp->link_params.feature_config_flags &=
10036 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10037
34f80b04
EG
10038 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10039 bp->common.bc_ver = val;
10040 BNX2X_DEV_INFO("bc_ver %X\n", val);
10041 if (val < BNX2X_BC_VER) {
10042 /* for now only warn
10043 * later we might need to enforce this */
51c1a580
MS
10044 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10045 BNX2X_BC_VER, val);
34f80b04 10046 }
4d295db0 10047 bp->link_params.feature_config_flags |=
a22f0788 10048 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
10049 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10050
a22f0788
YR
10051 bp->link_params.feature_config_flags |=
10052 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10053 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
10054 bp->link_params.feature_config_flags |=
10055 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10056 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
10057 bp->link_params.feature_config_flags |=
10058 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10059 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
10060
10061 bp->link_params.feature_config_flags |=
10062 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10063 FEATURE_CONFIG_MT_SUPPORT : 0;
10064
0e898dd7
BW
10065 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10066 BC_SUPPORTS_PFC_STATS : 0;
85242eea 10067
2e499d3c
BW
10068 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10069 BC_SUPPORTS_FCOE_FEATURES : 0;
10070
9876879f
BW
10071 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10072 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
10073 boot_mode = SHMEM_RD(bp,
10074 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10075 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10076 switch (boot_mode) {
10077 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10078 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10079 break;
10080 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10081 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10082 break;
10083 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10084 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10085 break;
10086 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10087 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10088 break;
10089 }
10090
f9a3ebbe
DK
10091 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
10092 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10093
72ce58c3 10094 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 10095 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
10096
10097 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10098 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10099 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10100 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10101
cdaa7cb8
VZ
10102 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10103 val, val2, val3, val4);
34f80b04
EG
10104}
10105
f2e0899f
DK
10106#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10107#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10108
0329aba1 10109static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
10110{
10111 int pfid = BP_FUNC(bp);
f2e0899f
DK
10112 int igu_sb_id;
10113 u32 val;
6383c0b3 10114 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
10115
10116 bp->igu_base_sb = 0xff;
f2e0899f 10117 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 10118 int vn = BP_VN(bp);
6383c0b3 10119 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
10120 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10121 FP_SB_MAX_E1x;
10122
10123 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10124 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10125
9b341bb1 10126 return 0;
f2e0899f
DK
10127 }
10128
10129 /* IGU in normal mode - read CAM */
10130 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10131 igu_sb_id++) {
10132 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10133 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10134 continue;
10135 fid = IGU_FID(val);
10136 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10137 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10138 continue;
10139 if (IGU_VEC(val) == 0)
10140 /* default status block */
10141 bp->igu_dsb_id = igu_sb_id;
10142 else {
10143 if (bp->igu_base_sb == 0xff)
10144 bp->igu_base_sb = igu_sb_id;
6383c0b3 10145 igu_sb_cnt++;
f2e0899f
DK
10146 }
10147 }
10148 }
619c5cb6 10149
6383c0b3 10150#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10151 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10152 * optional that number of CAM entries will not be equal to the value
10153 * advertised in PCI.
10154 * Driver should use the minimal value of both as the actual status
10155 * block count
619c5cb6 10156 */
185d4c8b 10157 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10158#endif
619c5cb6 10159
9b341bb1 10160 if (igu_sb_cnt == 0) {
f2e0899f 10161 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10162 return -EINVAL;
10163 }
10164
10165 return 0;
f2e0899f
DK
10166}
10167
1dd06ae8 10168static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
a2fbb9ea 10169{
a22f0788
YR
10170 int cfg_size = 0, idx, port = BP_PORT(bp);
10171
10172 /* Aggregation of supported attributes of all external phys */
10173 bp->port.supported[0] = 0;
10174 bp->port.supported[1] = 0;
b7737c9b
YR
10175 switch (bp->link_params.num_phys) {
10176 case 1:
a22f0788
YR
10177 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10178 cfg_size = 1;
10179 break;
b7737c9b 10180 case 2:
a22f0788
YR
10181 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10182 cfg_size = 1;
10183 break;
10184 case 3:
10185 if (bp->link_params.multi_phy_config &
10186 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10187 bp->port.supported[1] =
10188 bp->link_params.phy[EXT_PHY1].supported;
10189 bp->port.supported[0] =
10190 bp->link_params.phy[EXT_PHY2].supported;
10191 } else {
10192 bp->port.supported[0] =
10193 bp->link_params.phy[EXT_PHY1].supported;
10194 bp->port.supported[1] =
10195 bp->link_params.phy[EXT_PHY2].supported;
10196 }
10197 cfg_size = 2;
10198 break;
b7737c9b 10199 }
a2fbb9ea 10200
a22f0788 10201 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10202 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10203 SHMEM_RD(bp,
a22f0788
YR
10204 dev_info.port_hw_config[port].external_phy_config),
10205 SHMEM_RD(bp,
10206 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10207 return;
f85582f8 10208 }
a2fbb9ea 10209
619c5cb6
VZ
10210 if (CHIP_IS_E3(bp))
10211 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10212 else {
10213 switch (switch_cfg) {
10214 case SWITCH_CFG_1G:
10215 bp->port.phy_addr = REG_RD(
10216 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10217 break;
10218 case SWITCH_CFG_10G:
10219 bp->port.phy_addr = REG_RD(
10220 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10221 break;
10222 default:
10223 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10224 bp->port.link_config[0]);
10225 return;
10226 }
a2fbb9ea 10227 }
619c5cb6 10228 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10229 /* mask what we support according to speed_cap_mask per configuration */
10230 for (idx = 0; idx < cfg_size; idx++) {
10231 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10232 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10233 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10234
a22f0788 10235 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10236 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10237 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10238
a22f0788 10239 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10240 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10241 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10242
a22f0788 10243 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10244 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10245 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10246
a22f0788 10247 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10248 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10249 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10250 SUPPORTED_1000baseT_Full);
a2fbb9ea 10251
a22f0788 10252 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10253 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10254 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10255
a22f0788 10256 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10257 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
10258 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10259
10260 }
a2fbb9ea 10261
a22f0788
YR
10262 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10263 bp->port.supported[1]);
a2fbb9ea
ET
10264}
10265
0329aba1 10266static void bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10267{
a22f0788
YR
10268 u32 link_config, idx, cfg_size = 0;
10269 bp->port.advertising[0] = 0;
10270 bp->port.advertising[1] = 0;
10271 switch (bp->link_params.num_phys) {
10272 case 1:
10273 case 2:
10274 cfg_size = 1;
10275 break;
10276 case 3:
10277 cfg_size = 2;
10278 break;
10279 }
10280 for (idx = 0; idx < cfg_size; idx++) {
10281 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10282 link_config = bp->port.link_config[idx];
10283 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10284 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10285 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10286 bp->link_params.req_line_speed[idx] =
10287 SPEED_AUTO_NEG;
10288 bp->port.advertising[idx] |=
10289 bp->port.supported[idx];
10bd1f24
MY
10290 if (bp->link_params.phy[EXT_PHY1].type ==
10291 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10292 bp->port.advertising[idx] |=
10293 (SUPPORTED_100baseT_Half |
10294 SUPPORTED_100baseT_Full);
f85582f8
DK
10295 } else {
10296 /* force 10G, no AN */
a22f0788
YR
10297 bp->link_params.req_line_speed[idx] =
10298 SPEED_10000;
10299 bp->port.advertising[idx] |=
10300 (ADVERTISED_10000baseT_Full |
f85582f8 10301 ADVERTISED_FIBRE);
a22f0788 10302 continue;
f85582f8
DK
10303 }
10304 break;
a2fbb9ea 10305
f85582f8 10306 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10307 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10308 bp->link_params.req_line_speed[idx] =
10309 SPEED_10;
10310 bp->port.advertising[idx] |=
10311 (ADVERTISED_10baseT_Full |
f85582f8
DK
10312 ADVERTISED_TP);
10313 } else {
51c1a580 10314 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10315 link_config,
a22f0788 10316 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10317 return;
10318 }
10319 break;
a2fbb9ea 10320
f85582f8 10321 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10322 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10323 bp->link_params.req_line_speed[idx] =
10324 SPEED_10;
10325 bp->link_params.req_duplex[idx] =
10326 DUPLEX_HALF;
10327 bp->port.advertising[idx] |=
10328 (ADVERTISED_10baseT_Half |
f85582f8
DK
10329 ADVERTISED_TP);
10330 } else {
51c1a580 10331 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10332 link_config,
10333 bp->link_params.speed_cap_mask[idx]);
10334 return;
10335 }
10336 break;
a2fbb9ea 10337
f85582f8
DK
10338 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10339 if (bp->port.supported[idx] &
10340 SUPPORTED_100baseT_Full) {
a22f0788
YR
10341 bp->link_params.req_line_speed[idx] =
10342 SPEED_100;
10343 bp->port.advertising[idx] |=
10344 (ADVERTISED_100baseT_Full |
f85582f8
DK
10345 ADVERTISED_TP);
10346 } else {
51c1a580 10347 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10348 link_config,
10349 bp->link_params.speed_cap_mask[idx]);
10350 return;
10351 }
10352 break;
a2fbb9ea 10353
f85582f8
DK
10354 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10355 if (bp->port.supported[idx] &
10356 SUPPORTED_100baseT_Half) {
10357 bp->link_params.req_line_speed[idx] =
10358 SPEED_100;
10359 bp->link_params.req_duplex[idx] =
10360 DUPLEX_HALF;
a22f0788
YR
10361 bp->port.advertising[idx] |=
10362 (ADVERTISED_100baseT_Half |
f85582f8
DK
10363 ADVERTISED_TP);
10364 } else {
51c1a580 10365 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10366 link_config,
10367 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10368 return;
10369 }
10370 break;
a2fbb9ea 10371
f85582f8 10372 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10373 if (bp->port.supported[idx] &
10374 SUPPORTED_1000baseT_Full) {
10375 bp->link_params.req_line_speed[idx] =
10376 SPEED_1000;
10377 bp->port.advertising[idx] |=
10378 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10379 ADVERTISED_TP);
10380 } else {
51c1a580 10381 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10382 link_config,
10383 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10384 return;
10385 }
10386 break;
a2fbb9ea 10387
f85582f8 10388 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10389 if (bp->port.supported[idx] &
10390 SUPPORTED_2500baseX_Full) {
10391 bp->link_params.req_line_speed[idx] =
10392 SPEED_2500;
10393 bp->port.advertising[idx] |=
10394 (ADVERTISED_2500baseX_Full |
34f80b04 10395 ADVERTISED_TP);
f85582f8 10396 } else {
51c1a580 10397 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10398 link_config,
f85582f8
DK
10399 bp->link_params.speed_cap_mask[idx]);
10400 return;
10401 }
10402 break;
a2fbb9ea 10403
f85582f8 10404 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10405 if (bp->port.supported[idx] &
10406 SUPPORTED_10000baseT_Full) {
10407 bp->link_params.req_line_speed[idx] =
10408 SPEED_10000;
10409 bp->port.advertising[idx] |=
10410 (ADVERTISED_10000baseT_Full |
34f80b04 10411 ADVERTISED_FIBRE);
f85582f8 10412 } else {
51c1a580 10413 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10414 link_config,
f85582f8
DK
10415 bp->link_params.speed_cap_mask[idx]);
10416 return;
10417 }
10418 break;
3c9ada22
YR
10419 case PORT_FEATURE_LINK_SPEED_20G:
10420 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10421
3c9ada22 10422 break;
f85582f8 10423 default:
51c1a580 10424 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10425 link_config);
f85582f8
DK
10426 bp->link_params.req_line_speed[idx] =
10427 SPEED_AUTO_NEG;
10428 bp->port.advertising[idx] =
10429 bp->port.supported[idx];
10430 break;
10431 }
a2fbb9ea 10432
a22f0788 10433 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10434 PORT_FEATURE_FLOW_CONTROL_MASK);
cd1dfce2
YM
10435 if (bp->link_params.req_flow_ctrl[idx] ==
10436 BNX2X_FLOW_CTRL_AUTO) {
10437 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10438 bp->link_params.req_flow_ctrl[idx] =
10439 BNX2X_FLOW_CTRL_NONE;
10440 else
10441 bnx2x_set_requested_fc(bp);
a22f0788 10442 }
a2fbb9ea 10443
51c1a580 10444 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10445 bp->link_params.req_line_speed[idx],
10446 bp->link_params.req_duplex[idx],
10447 bp->link_params.req_flow_ctrl[idx],
10448 bp->port.advertising[idx]);
10449 }
a2fbb9ea
ET
10450}
10451
0329aba1 10452static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
e665bfda
MC
10453{
10454 mac_hi = cpu_to_be16(mac_hi);
10455 mac_lo = cpu_to_be32(mac_lo);
10456 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
10457 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
10458}
10459
0329aba1 10460static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10461{
34f80b04 10462 int port = BP_PORT(bp);
589abe3a 10463 u32 config;
c8c60d88 10464 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10465
c18487ee 10466 bp->link_params.bp = bp;
34f80b04 10467 bp->link_params.port = port;
c18487ee 10468
c18487ee 10469 bp->link_params.lane_config =
a2fbb9ea 10470 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10471
a22f0788 10472 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
10473 SHMEM_RD(bp,
10474 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
10475 bp->link_params.speed_cap_mask[1] =
10476 SHMEM_RD(bp,
10477 dev_info.port_hw_config[port].speed_capability_mask2);
10478 bp->port.link_config[0] =
a2fbb9ea
ET
10479 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10480
a22f0788
YR
10481 bp->port.link_config[1] =
10482 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10483
a22f0788
YR
10484 bp->link_params.multi_phy_config =
10485 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10486 /* If the device is capable of WoL, set the default state according
10487 * to the HW
10488 */
4d295db0 10489 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10490 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10491 (config & PORT_FEATURE_WOL_ENABLED));
10492
51c1a580 10493 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10494 bp->link_params.lane_config,
a22f0788
YR
10495 bp->link_params.speed_cap_mask[0],
10496 bp->port.link_config[0]);
a2fbb9ea 10497
a22f0788 10498 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10499 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10500 bnx2x_phy_probe(&bp->link_params);
c18487ee 10501 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10502
10503 bnx2x_link_settings_requested(bp);
10504
01cd4528
EG
10505 /*
10506 * If connected directly, work with the internal PHY, otherwise, work
10507 * with the external PHY
10508 */
b7737c9b
YR
10509 ext_phy_config =
10510 SHMEM_RD(bp,
10511 dev_info.port_hw_config[port].external_phy_config);
10512 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10513 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10514 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10515
10516 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10517 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10518 bp->mdio.prtad =
b7737c9b 10519 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10520
c8c60d88
YM
10521 /* Configure link feature according to nvram value */
10522 eee_mode = (((SHMEM_RD(bp, dev_info.
10523 port_feature_config[port].eee_power_mode)) &
10524 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10525 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10526 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10527 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10528 EEE_MODE_ENABLE_LPI |
10529 EEE_MODE_OUTPUT_TIME;
10530 } else {
10531 bp->link_params.eee_mode = 0;
10532 }
0793f83f 10533}
01cd4528 10534
b306f5ed 10535void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10536{
9e62e912 10537 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10538 int port = BP_PORT(bp);
2ba45142 10539 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10540 drv_lic_key[port].max_iscsi_conn);
2ba45142 10541
55c11941
MS
10542 if (!CNIC_SUPPORT(bp)) {
10543 bp->flags |= no_flags;
10544 return;
10545 }
10546
b306f5ed 10547 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10548 bp->cnic_eth_dev.max_iscsi_conn =
10549 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10550 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10551
b306f5ed
DK
10552 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10553 bp->cnic_eth_dev.max_iscsi_conn);
10554
10555 /*
10556 * If maximum allowed number of connections is zero -
10557 * disable the feature.
10558 */
10559 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10560 bp->flags |= no_flags;
55c11941 10561
b306f5ed
DK
10562}
10563
0329aba1 10564static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9e62e912
DK
10565{
10566 /* Port info */
10567 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10568 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10569 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10570 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10571
10572 /* Node info */
10573 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10574 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10575 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10576 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10577}
0329aba1 10578static void bnx2x_get_fcoe_info(struct bnx2x *bp)
b306f5ed
DK
10579{
10580 int port = BP_PORT(bp);
10581 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10582 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10583 drv_lic_key[port].max_fcoe_conn);
10584
55c11941
MS
10585 if (!CNIC_SUPPORT(bp)) {
10586 bp->flags |= NO_FCOE_FLAG;
10587 return;
10588 }
10589
b306f5ed 10590 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10591 bp->cnic_eth_dev.max_fcoe_conn =
10592 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10593 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10594
bf61ee14
VZ
10595 /* Read the WWN: */
10596 if (!IS_MF(bp)) {
10597 /* Port info */
10598 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10599 SHMEM_RD(bp,
10600 dev_info.port_hw_config[port].
10601 fcoe_wwn_port_name_upper);
10602 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10603 SHMEM_RD(bp,
10604 dev_info.port_hw_config[port].
10605 fcoe_wwn_port_name_lower);
10606
10607 /* Node info */
10608 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10609 SHMEM_RD(bp,
10610 dev_info.port_hw_config[port].
10611 fcoe_wwn_node_name_upper);
10612 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10613 SHMEM_RD(bp,
10614 dev_info.port_hw_config[port].
10615 fcoe_wwn_node_name_lower);
10616 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10617 /*
10618 * Read the WWN info only if the FCoE feature is enabled for
10619 * this function.
10620 */
7b5342d9 10621 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10622 bnx2x_get_ext_wwn_info(bp, func);
10623
382e513a 10624 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 10625 bnx2x_get_ext_wwn_info(bp, func);
382e513a 10626 }
bf61ee14 10627
b306f5ed 10628 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10629
bf61ee14
VZ
10630 /*
10631 * If maximum allowed number of connections is zero -
2ba45142
VZ
10632 * disable the feature.
10633 */
2ba45142
VZ
10634 if (!bp->cnic_eth_dev.max_fcoe_conn)
10635 bp->flags |= NO_FCOE_FLAG;
10636}
b306f5ed 10637
0329aba1 10638static void bnx2x_get_cnic_info(struct bnx2x *bp)
b306f5ed
DK
10639{
10640 /*
10641 * iSCSI may be dynamically disabled but reading
10642 * info here we will decrease memory usage by driver
10643 * if the feature is disabled for good
10644 */
10645 bnx2x_get_iscsi_info(bp);
10646 bnx2x_get_fcoe_info(bp);
10647}
2ba45142 10648
0329aba1 10649static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10650{
10651 u32 val, val2;
10652 int func = BP_ABS_FUNC(bp);
10653 int port = BP_PORT(bp);
2ba45142
VZ
10654 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10655 u8 *fip_mac = bp->fip_mac;
0793f83f 10656
55c11941
MS
10657 if (IS_MF(bp)) {
10658 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10659 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10660 * In non SD mode features configuration comes from struct
10661 * func_ext_config.
2ba45142 10662 */
55c11941 10663 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10664 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10665 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10666 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10667 iscsi_mac_addr_upper);
0793f83f 10668 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10669 iscsi_mac_addr_lower);
2ba45142 10670 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10671 BNX2X_DEV_INFO
10672 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10673 } else {
2ba45142 10674 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10675 }
2ba45142
VZ
10676
10677 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10678 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10679 fcoe_mac_addr_upper);
2ba45142 10680 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10681 fcoe_mac_addr_lower);
2ba45142 10682 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10683 BNX2X_DEV_INFO
10684 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10685 } else {
2ba45142 10686 bp->flags |= NO_FCOE_FLAG;
55c11941 10687 }
a3348722
BW
10688
10689 bp->mf_ext_config = cfg;
10690
9e62e912 10691 } else { /* SD MODE */
55c11941
MS
10692 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10693 /* use primary mac as iscsi mac */
10694 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10695
10696 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10697 BNX2X_DEV_INFO
10698 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10699 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10700 /* use primary mac as fip mac */
10701 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10702 BNX2X_DEV_INFO("SD FCoE MODE\n");
10703 BNX2X_DEV_INFO
10704 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10705 }
0793f83f 10706 }
a3348722 10707
55c11941
MS
10708 if (IS_MF_STORAGE_SD(bp))
10709 /* Zero primary MAC configuration */
10710 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10711
a3348722
BW
10712 if (IS_MF_FCOE_AFEX(bp))
10713 /* use FIP MAC as primary MAC */
10714 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10715
0793f83f 10716 } else {
0793f83f 10717 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10718 iscsi_mac_upper);
0793f83f 10719 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10720 iscsi_mac_lower);
2ba45142 10721 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10722
10723 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10724 fcoe_fip_mac_upper);
c03bd39c 10725 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10726 fcoe_fip_mac_lower);
c03bd39c 10727 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10728 }
10729
55c11941 10730 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10731 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10732 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10733 memset(iscsi_mac, 0, ETH_ALEN);
10734 }
10735
55c11941 10736 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10737 if (!is_valid_ether_addr(fip_mac)) {
10738 bp->flags |= NO_FCOE_FLAG;
10739 memset(bp->fip_mac, 0, ETH_ALEN);
10740 }
55c11941
MS
10741}
10742
0329aba1 10743static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
55c11941
MS
10744{
10745 u32 val, val2;
10746 int func = BP_ABS_FUNC(bp);
10747 int port = BP_PORT(bp);
10748
10749 /* Zero primary MAC configuration */
10750 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10751
10752 if (BP_NOMCP(bp)) {
10753 BNX2X_ERROR("warning: random MAC workaround active\n");
10754 eth_hw_addr_random(bp->dev);
10755 } else if (IS_MF(bp)) {
10756 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10757 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10758 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10759 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10760 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10761
10762 if (CNIC_SUPPORT(bp))
10763 bnx2x_get_cnic_mac_hwinfo(bp);
10764 } else {
10765 /* in SF read MACs from port configuration */
10766 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10767 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10768 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10769
10770 if (CNIC_SUPPORT(bp))
10771 bnx2x_get_cnic_mac_hwinfo(bp);
10772 }
10773
10774 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
10775 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10776
614c76df 10777 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10778 dev_err(&bp->pdev->dev,
51c1a580
MS
10779 "bad Ethernet MAC address configuration: %pM\n"
10780 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10781 bp->dev->dev_addr);
7964211d 10782}
51c1a580 10783
0329aba1 10784static bool bnx2x_get_dropless_info(struct bnx2x *bp)
7964211d
YM
10785{
10786 int tmp;
10787 u32 cfg;
51c1a580 10788
7964211d
YM
10789 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
10790 /* Take function: tmp = func */
10791 tmp = BP_ABS_FUNC(bp);
10792 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
10793 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
10794 } else {
10795 /* Take port: tmp = port */
10796 tmp = BP_PORT(bp);
10797 cfg = SHMEM_RD(bp,
10798 dev_info.port_hw_config[tmp].generic_features);
10799 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
10800 }
10801 return cfg;
34f80b04
EG
10802}
10803
0329aba1 10804static int bnx2x_get_hwinfo(struct bnx2x *bp)
34f80b04 10805{
0793f83f 10806 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 10807 int vn;
0793f83f 10808 u32 val = 0;
34f80b04 10809 int rc = 0;
a2fbb9ea 10810
34f80b04 10811 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 10812
6383c0b3
AE
10813 /*
10814 * initialize IGU parameters
10815 */
f2e0899f
DK
10816 if (CHIP_IS_E1x(bp)) {
10817 bp->common.int_block = INT_BLOCK_HC;
10818
10819 bp->igu_dsb_id = DEF_SB_IGU_ID;
10820 bp->igu_base_sb = 0;
f2e0899f
DK
10821 } else {
10822 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
10823
10824 /* do not allow device reset during IGU info preocessing */
10825 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10826
f2e0899f 10827 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
10828
10829 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10830 int tout = 5000;
10831
10832 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10833
10834 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10835 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10836 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10837
10838 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10839 tout--;
10840 usleep_range(1000, 1000);
10841 }
10842
10843 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10844 dev_err(&bp->pdev->dev,
10845 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
10846 bnx2x_release_hw_lock(bp,
10847 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
10848 return -EPERM;
10849 }
10850 }
10851
f2e0899f 10852 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 10853 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
10854 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10855 } else
619c5cb6 10856 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 10857
9b341bb1 10858 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 10859 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
10860 if (rc)
10861 return rc;
f2e0899f 10862 }
619c5cb6
VZ
10863
10864 /*
10865 * set base FW non-default (fast path) status block id, this value is
10866 * used to initialize the fw_sb_id saved on the fp/queue structure to
10867 * determine the id used by the FW.
10868 */
10869 if (CHIP_IS_E1x(bp))
10870 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10871 else /*
10872 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10873 * the same queue are indicated on the same IGU SB). So we prefer
10874 * FW and IGU SBs to be the same value.
10875 */
10876 bp->base_fw_ndsb = bp->igu_base_sb;
10877
10878 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10879 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10880 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
10881
10882 /*
10883 * Initialize MF configuration
10884 */
523224a3 10885
fb3bff17
DK
10886 bp->mf_ov = 0;
10887 bp->mf_mode = 0;
3395a033 10888 vn = BP_VN(bp);
0793f83f 10889
f2e0899f 10890 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
10891 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10892 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10893 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10894
f2e0899f
DK
10895 if (SHMEM2_HAS(bp, mf_cfg_addr))
10896 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10897 else
10898 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
10899 offsetof(struct shmem_region, func_mb) +
10900 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
10901 /*
10902 * get mf configuration:
25985edc 10903 * 1. existence of MF configuration
0793f83f
DK
10904 * 2. MAC address must be legal (check only upper bytes)
10905 * for Switch-Independent mode;
10906 * OVLAN must be legal for Switch-Dependent mode
10907 * 3. SF_MODE configures specific MF mode
10908 */
10909 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10910 /* get mf configuration */
10911 val = SHMEM_RD(bp,
10912 dev_info.shared_feature_config.config);
10913 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10914
10915 switch (val) {
10916 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10917 val = MF_CFG_RD(bp, func_mf_config[func].
10918 mac_upper);
10919 /* check for legal mac (upper bytes)*/
10920 if (val != 0xffff) {
10921 bp->mf_mode = MULTI_FUNCTION_SI;
10922 bp->mf_config[vn] = MF_CFG_RD(bp,
10923 func_mf_config[func].config);
10924 } else
51c1a580 10925 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 10926 break;
a3348722
BW
10927 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
10928 if ((!CHIP_IS_E1x(bp)) &&
10929 (MF_CFG_RD(bp, func_mf_config[func].
10930 mac_upper) != 0xffff) &&
10931 (SHMEM2_HAS(bp,
10932 afex_driver_support))) {
10933 bp->mf_mode = MULTI_FUNCTION_AFEX;
10934 bp->mf_config[vn] = MF_CFG_RD(bp,
10935 func_mf_config[func].config);
10936 } else {
10937 BNX2X_DEV_INFO("can not configure afex mode\n");
10938 }
10939 break;
0793f83f
DK
10940 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10941 /* get OV configuration */
10942 val = MF_CFG_RD(bp,
10943 func_mf_config[FUNC_0].e1hov_tag);
10944 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10945
10946 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10947 bp->mf_mode = MULTI_FUNCTION_SD;
10948 bp->mf_config[vn] = MF_CFG_RD(bp,
10949 func_mf_config[func].config);
10950 } else
754a2f52 10951 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
10952 break;
10953 default:
10954 /* Unknown configuration: reset mf_config */
10955 bp->mf_config[vn] = 0;
51c1a580 10956 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
10957 }
10958 }
a2fbb9ea 10959
2691d51d 10960 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 10961 IS_MF(bp) ? "multi" : "single");
2691d51d 10962
0793f83f
DK
10963 switch (bp->mf_mode) {
10964 case MULTI_FUNCTION_SD:
10965 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10966 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 10967 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 10968 bp->mf_ov = val;
619c5cb6
VZ
10969 bp->path_has_ovlan = true;
10970
51c1a580
MS
10971 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10972 func, bp->mf_ov, bp->mf_ov);
2691d51d 10973 } else {
619c5cb6 10974 dev_err(&bp->pdev->dev,
51c1a580
MS
10975 "No valid MF OV for func %d, aborting\n",
10976 func);
619c5cb6 10977 return -EPERM;
34f80b04 10978 }
0793f83f 10979 break;
a3348722
BW
10980 case MULTI_FUNCTION_AFEX:
10981 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
10982 break;
0793f83f 10983 case MULTI_FUNCTION_SI:
51c1a580
MS
10984 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10985 func);
0793f83f
DK
10986 break;
10987 default:
10988 if (vn) {
619c5cb6 10989 dev_err(&bp->pdev->dev,
51c1a580
MS
10990 "VN %d is in a single function mode, aborting\n",
10991 vn);
619c5cb6 10992 return -EPERM;
2691d51d 10993 }
0793f83f 10994 break;
34f80b04 10995 }
0793f83f 10996
619c5cb6
VZ
10997 /* check if other port on the path needs ovlan:
10998 * Since MF configuration is shared between ports
10999 * Possible mixed modes are only
11000 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11001 */
11002 if (CHIP_MODE_IS_4_PORT(bp) &&
11003 !bp->path_has_ovlan &&
11004 !IS_MF(bp) &&
11005 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11006 u8 other_port = !BP_PORT(bp);
11007 u8 other_func = BP_PATH(bp) + 2*other_port;
11008 val = MF_CFG_RD(bp,
11009 func_mf_config[other_func].e1hov_tag);
11010 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11011 bp->path_has_ovlan = true;
11012 }
34f80b04 11013 }
a2fbb9ea 11014
f2e0899f
DK
11015 /* adjust igu_sb_cnt to MF for E1x */
11016 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
11017 bp->igu_sb_cnt /= E1HVN_MAX;
11018
619c5cb6
VZ
11019 /* port info */
11020 bnx2x_get_port_hwinfo(bp);
f2e0899f 11021
0793f83f
DK
11022 /* Get MAC addresses */
11023 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 11024
2ba45142 11025 bnx2x_get_cnic_info(bp);
2ba45142 11026
34f80b04
EG
11027 return rc;
11028}
11029
0329aba1 11030static void bnx2x_read_fwinfo(struct bnx2x *bp)
34f24c7f
VZ
11031{
11032 int cnt, i, block_end, rodi;
fcdf95cb 11033 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
11034 char str_id_reg[VENDOR_ID_LEN+1];
11035 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
11036 char *vpd_data;
11037 char *vpd_extended_data = NULL;
34f24c7f
VZ
11038 u8 len;
11039
fcdf95cb 11040 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
11041 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11042
11043 if (cnt < BNX2X_VPD_LEN)
11044 goto out_not_found;
11045
fcdf95cb
BW
11046 /* VPD RO tag should be first tag after identifier string, hence
11047 * we should be able to find it in first BNX2X_VPD_LEN chars
11048 */
11049 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
11050 PCI_VPD_LRDT_RO_DATA);
11051 if (i < 0)
11052 goto out_not_found;
11053
34f24c7f 11054 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 11055 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
11056
11057 i += PCI_VPD_LRDT_TAG_SIZE;
11058
fcdf95cb
BW
11059 if (block_end > BNX2X_VPD_LEN) {
11060 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11061 if (vpd_extended_data == NULL)
11062 goto out_not_found;
11063
11064 /* read rest of vpd image into vpd_extended_data */
11065 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11066 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11067 block_end - BNX2X_VPD_LEN,
11068 vpd_extended_data + BNX2X_VPD_LEN);
11069 if (cnt < (block_end - BNX2X_VPD_LEN))
11070 goto out_not_found;
11071 vpd_data = vpd_extended_data;
11072 } else
11073 vpd_data = vpd_start;
11074
11075 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
11076
11077 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11078 PCI_VPD_RO_KEYWORD_MFR_ID);
11079 if (rodi < 0)
11080 goto out_not_found;
11081
11082 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11083
11084 if (len != VENDOR_ID_LEN)
11085 goto out_not_found;
11086
11087 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11088
11089 /* vendor specific info */
11090 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11091 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11092 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11093 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11094
11095 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11096 PCI_VPD_RO_KEYWORD_VENDOR0);
11097 if (rodi >= 0) {
11098 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11099
11100 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11101
11102 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11103 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11104 bp->fw_ver[len] = ' ';
11105 }
11106 }
fcdf95cb 11107 kfree(vpd_extended_data);
34f24c7f
VZ
11108 return;
11109 }
11110out_not_found:
fcdf95cb 11111 kfree(vpd_extended_data);
34f24c7f
VZ
11112 return;
11113}
11114
0329aba1 11115static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
619c5cb6
VZ
11116{
11117 u32 flags = 0;
11118
11119 if (CHIP_REV_IS_FPGA(bp))
11120 SET_FLAGS(flags, MODE_FPGA);
11121 else if (CHIP_REV_IS_EMUL(bp))
11122 SET_FLAGS(flags, MODE_EMUL);
11123 else
11124 SET_FLAGS(flags, MODE_ASIC);
11125
11126 if (CHIP_MODE_IS_4_PORT(bp))
11127 SET_FLAGS(flags, MODE_PORT4);
11128 else
11129 SET_FLAGS(flags, MODE_PORT2);
11130
11131 if (CHIP_IS_E2(bp))
11132 SET_FLAGS(flags, MODE_E2);
11133 else if (CHIP_IS_E3(bp)) {
11134 SET_FLAGS(flags, MODE_E3);
11135 if (CHIP_REV(bp) == CHIP_REV_Ax)
11136 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11137 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11138 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11139 }
11140
11141 if (IS_MF(bp)) {
11142 SET_FLAGS(flags, MODE_MF);
11143 switch (bp->mf_mode) {
11144 case MULTI_FUNCTION_SD:
11145 SET_FLAGS(flags, MODE_MF_SD);
11146 break;
11147 case MULTI_FUNCTION_SI:
11148 SET_FLAGS(flags, MODE_MF_SI);
11149 break;
a3348722
BW
11150 case MULTI_FUNCTION_AFEX:
11151 SET_FLAGS(flags, MODE_MF_AFEX);
11152 break;
619c5cb6
VZ
11153 }
11154 } else
11155 SET_FLAGS(flags, MODE_SF);
11156
11157#if defined(__LITTLE_ENDIAN)
11158 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11159#else /*(__BIG_ENDIAN)*/
11160 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11161#endif
11162 INIT_MODE_FLAGS(bp) = flags;
11163}
11164
0329aba1 11165static int bnx2x_init_bp(struct bnx2x *bp)
34f80b04 11166{
f2e0899f 11167 int func;
34f80b04
EG
11168 int rc;
11169
34f80b04 11170 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11171 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11172 spin_lock_init(&bp->stats_lock);
55c11941 11173
a2fbb9ea 11174
1cf167f2 11175 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11176 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11177 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
1ab4434c
AE
11178 if (IS_PF(bp)) {
11179 rc = bnx2x_get_hwinfo(bp);
11180 if (rc)
11181 return rc;
11182 } else {
11183 random_ether_addr(bp->dev->dev_addr);
11184 }
34f80b04 11185
619c5cb6
VZ
11186 bnx2x_set_modes_bitmap(bp);
11187
11188 rc = bnx2x_alloc_mem_bp(bp);
11189 if (rc)
11190 return rc;
523224a3 11191
34f24c7f 11192 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11193
11194 func = BP_FUNC(bp);
11195
34f80b04 11196 /* need to reset chip if undi was active */
1ab4434c 11197 if (IS_PF(bp) && !BP_NOMCP(bp)) {
452427b0
YM
11198 /* init fw_seq */
11199 bp->fw_seq =
11200 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11201 DRV_MSG_SEQ_NUMBER_MASK;
11202 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11203
11204 bnx2x_prev_unload(bp);
11205 }
11206
34f80b04
EG
11207
11208 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11209 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11210
11211 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11212 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11213
614c76df 11214 bp->disable_tpa = disable_tpa;
a3348722 11215 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11216
7a9b2557 11217 /* Set TPA flags */
614c76df 11218 if (bp->disable_tpa) {
621b4d66 11219 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11220 bp->dev->features &= ~NETIF_F_LRO;
11221 } else {
621b4d66 11222 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11223 bp->dev->features |= NETIF_F_LRO;
11224 }
11225
a18f5128
EG
11226 if (CHIP_IS_E1(bp))
11227 bp->dropless_fc = 0;
11228 else
7964211d 11229 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11230
8d5726c4 11231 bp->mrrs = mrrs;
7a9b2557 11232
a3348722 11233 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1ab4434c
AE
11234 if (IS_VF(bp))
11235 bp->rx_ring_size = MAX_RX_AVAIL;
34f80b04 11236
7d323bfd 11237 /* make sure that the numbers are in the right granularity */
523224a3
DK
11238 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11239 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11240
fc543637 11241 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11242
11243 init_timer(&bp->timer);
11244 bp->timer.expires = jiffies + bp->current_interval;
11245 bp->timer.data = (unsigned long) bp;
11246 bp->timer.function = bnx2x_timer;
11247
0370cf90
BW
11248 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11249 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11250 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11251 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11252 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11253 bnx2x_dcbx_init_params(bp);
11254 } else {
11255 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11256 }
e4901dde 11257
619c5cb6
VZ
11258 if (CHIP_IS_E1x(bp))
11259 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11260 else
11261 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11262
6383c0b3 11263 /* multiple tx priority */
1ab4434c
AE
11264 if (IS_VF(bp))
11265 bp->max_cos = 1;
11266 else if (CHIP_IS_E1x(bp))
6383c0b3 11267 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
1ab4434c 11268 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
6383c0b3 11269 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
1ab4434c 11270 else if (CHIP_IS_E3B0(bp))
6383c0b3 11271 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
1ab4434c
AE
11272 else
11273 BNX2X_ERR("unknown chip %x revision %x\n",
11274 CHIP_NUM(bp), CHIP_REV(bp));
11275 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
6383c0b3 11276
55c11941
MS
11277 /* We need at least one default status block for slow-path events,
11278 * second status block for the L2 queue, and a third status block for
11279 * CNIC if supproted.
11280 */
11281 if (CNIC_SUPPORT(bp))
11282 bp->min_msix_vec_cnt = 3;
11283 else
11284 bp->min_msix_vec_cnt = 2;
11285 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11286
34f80b04 11287 return rc;
a2fbb9ea
ET
11288}
11289
a2fbb9ea 11290
de0c62db
DK
11291/****************************************************************************
11292* General service functions
11293****************************************************************************/
a2fbb9ea 11294
619c5cb6
VZ
11295/*
11296 * net_device service functions
11297 */
11298
bb2a0f7a 11299/* called with rtnl_lock */
a2fbb9ea
ET
11300static int bnx2x_open(struct net_device *dev)
11301{
11302 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11303 bool global = false;
11304 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11305 bool other_load_status, load_status;
a2fbb9ea 11306
1355b704
MY
11307 bp->stats_init = true;
11308
6eccabb3
EG
11309 netif_carrier_off(dev);
11310
a2fbb9ea
ET
11311 bnx2x_set_power_state(bp, PCI_D0);
11312
ad5afc89 11313 /* If parity had happen during the unload, then attentions
c9ee9206
VZ
11314 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11315 * want the first function loaded on the current engine to
11316 * complete the recovery.
ad5afc89 11317 * Parity recovery is only relevant for PF driver.
c9ee9206 11318 */
ad5afc89
AE
11319 if (IS_PF(bp)) {
11320 other_load_status = bnx2x_get_load_status(bp, other_engine);
11321 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11322 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11323 bnx2x_chk_parity_attn(bp, &global, true)) {
11324 do {
11325 /* If there are attentions and they are in a
11326 * global blocks, set the GLOBAL_RESET bit
11327 * regardless whether it will be this function
11328 * that will complete the recovery or not.
11329 */
11330 if (global)
11331 bnx2x_set_reset_global(bp);
72fd0718 11332
ad5afc89
AE
11333 /* Only the first function on the current
11334 * engine should try to recover in open. In case
11335 * of attentions in global blocks only the first
11336 * in the chip should try to recover.
11337 */
11338 if ((!load_status &&
11339 (!global || !other_load_status)) &&
11340 bnx2x_trylock_leader_lock(bp) &&
11341 !bnx2x_leader_reset(bp)) {
11342 netdev_info(bp->dev,
11343 "Recovered in open\n");
11344 break;
11345 }
72fd0718 11346
ad5afc89
AE
11347 /* recovery has failed... */
11348 bnx2x_set_power_state(bp, PCI_D3hot);
11349 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11350
ad5afc89
AE
11351 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11352 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718 11353
ad5afc89
AE
11354 return -EAGAIN;
11355 } while (0);
11356 }
11357 }
72fd0718
VZ
11358
11359 bp->recovery_state = BNX2X_RECOVERY_DONE;
bb2a0f7a 11360 return bnx2x_nic_load(bp, LOAD_OPEN);
a2fbb9ea
ET
11361}
11362
bb2a0f7a 11363/* called with rtnl_lock */
56ad3152 11364static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11365{
a2fbb9ea
ET
11366 struct bnx2x *bp = netdev_priv(dev);
11367
11368 /* Unload the driver, release IRQs */
5d07d868 11369 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206
VZ
11370
11371 /* Power off */
d3dbfee0 11372 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
11373
11374 return 0;
11375}
11376
1191cb83
ED
11377static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11378 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11379{
619c5cb6
VZ
11380 int mc_count = netdev_mc_count(bp->dev);
11381 struct bnx2x_mcast_list_elem *mc_mac =
11382 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11383 struct netdev_hw_addr *ha;
6e30dd4e 11384
619c5cb6
VZ
11385 if (!mc_mac)
11386 return -ENOMEM;
6e30dd4e 11387
619c5cb6 11388 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11389
619c5cb6
VZ
11390 netdev_for_each_mc_addr(ha, bp->dev) {
11391 mc_mac->mac = bnx2x_mc_addr(ha);
11392 list_add_tail(&mc_mac->link, &p->mcast_list);
11393 mc_mac++;
6e30dd4e 11394 }
619c5cb6
VZ
11395
11396 p->mcast_list_len = mc_count;
11397
11398 return 0;
6e30dd4e
VZ
11399}
11400
1191cb83 11401static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11402 struct bnx2x_mcast_ramrod_params *p)
11403{
11404 struct bnx2x_mcast_list_elem *mc_mac =
11405 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11406 link);
11407
11408 WARN_ON(!mc_mac);
11409 kfree(mc_mac);
11410}
11411
11412/**
11413 * bnx2x_set_uc_list - configure a new unicast MACs list.
11414 *
11415 * @bp: driver handle
6e30dd4e 11416 *
619c5cb6 11417 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11418 */
1191cb83 11419static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11420{
619c5cb6 11421 int rc;
6e30dd4e 11422 struct net_device *dev = bp->dev;
6e30dd4e 11423 struct netdev_hw_addr *ha;
15192a8c 11424 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11425 unsigned long ramrod_flags = 0;
6e30dd4e 11426
619c5cb6
VZ
11427 /* First schedule a cleanup up of old configuration */
11428 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11429 if (rc < 0) {
11430 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11431 return rc;
11432 }
6e30dd4e
VZ
11433
11434 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11435 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11436 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11437 if (rc == -EEXIST) {
11438 DP(BNX2X_MSG_SP,
11439 "Failed to schedule ADD operations: %d\n", rc);
11440 /* do not treat adding same MAC as error */
11441 rc = 0;
11442
11443 } else if (rc < 0) {
11444
619c5cb6
VZ
11445 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11446 rc);
11447 return rc;
6e30dd4e
VZ
11448 }
11449 }
11450
619c5cb6
VZ
11451 /* Execute the pending commands */
11452 __set_bit(RAMROD_CONT, &ramrod_flags);
11453 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11454 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11455}
11456
1191cb83 11457static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11458{
619c5cb6 11459 struct net_device *dev = bp->dev;
3b603066 11460 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11461 int rc = 0;
6e30dd4e 11462
619c5cb6 11463 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11464
619c5cb6
VZ
11465 /* first, clear all configured multicast MACs */
11466 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11467 if (rc < 0) {
51c1a580 11468 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11469 return rc;
11470 }
6e30dd4e 11471
619c5cb6
VZ
11472 /* then, configure a new MACs list */
11473 if (netdev_mc_count(dev)) {
11474 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11475 if (rc) {
51c1a580
MS
11476 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11477 rc);
619c5cb6
VZ
11478 return rc;
11479 }
6e30dd4e 11480
619c5cb6
VZ
11481 /* Now add the new MACs */
11482 rc = bnx2x_config_mcast(bp, &rparam,
11483 BNX2X_MCAST_CMD_ADD);
11484 if (rc < 0)
51c1a580
MS
11485 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11486 rc);
6e30dd4e 11487
619c5cb6
VZ
11488 bnx2x_free_mcast_macs_list(&rparam);
11489 }
6e30dd4e 11490
619c5cb6 11491 return rc;
6e30dd4e
VZ
11492}
11493
6e30dd4e 11494
619c5cb6 11495/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11496void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11497{
11498 struct bnx2x *bp = netdev_priv(dev);
11499 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11500
11501 if (bp->state != BNX2X_STATE_OPEN) {
11502 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11503 return;
11504 }
11505
619c5cb6 11506 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11507
11508 if (dev->flags & IFF_PROMISC)
11509 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11510 else if ((dev->flags & IFF_ALLMULTI) ||
11511 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11512 CHIP_IS_E1(bp)))
34f80b04 11513 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e 11514 else {
381ac16b
AE
11515 if (IS_PF(bp)) {
11516 /* some multicasts */
11517 if (bnx2x_set_mc_list(bp) < 0)
11518 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11519
381ac16b
AE
11520 if (bnx2x_set_uc_list(bp) < 0)
11521 rx_mode = BNX2X_RX_MODE_PROMISC;
11522 } else {
11523 /* configuring mcast to a vf involves sleeping (when we
11524 * wait for the pf's response). Since this function is
11525 * called from non sleepable context we must schedule
11526 * a work item for this purpose
11527 */
11528 smp_mb__before_clear_bit();
11529 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
11530 &bp->sp_rtnl_state);
11531 smp_mb__after_clear_bit();
11532 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11533 }
34f80b04
EG
11534 }
11535
11536 bp->rx_mode = rx_mode;
614c76df
DK
11537 /* handle ISCSI SD mode */
11538 if (IS_MF_ISCSI_SD(bp))
11539 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11540
11541 /* Schedule the rx_mode command */
11542 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11543 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11544 return;
11545 }
11546
381ac16b
AE
11547 if (IS_PF(bp)) {
11548 bnx2x_set_storm_rx_mode(bp);
11549 } else {
11550 /* configuring rx mode to storms in a vf involves sleeping (when
11551 * we wait for the pf's response). Since this function is
11552 * called from non sleepable context we must schedule
11553 * a work item for this purpose
11554 */
11555 smp_mb__before_clear_bit();
11556 set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
11557 &bp->sp_rtnl_state);
11558 smp_mb__after_clear_bit();
11559 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11560 }
34f80b04
EG
11561}
11562
c18487ee 11563/* called with rtnl_lock */
01cd4528
EG
11564static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11565 int devad, u16 addr)
a2fbb9ea 11566{
01cd4528
EG
11567 struct bnx2x *bp = netdev_priv(netdev);
11568 u16 value;
11569 int rc;
a2fbb9ea 11570
01cd4528
EG
11571 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11572 prtad, devad, addr);
a2fbb9ea 11573
01cd4528
EG
11574 /* The HW expects different devad if CL22 is used */
11575 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11576
01cd4528 11577 bnx2x_acquire_phy_lock(bp);
e10bc84d 11578 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11579 bnx2x_release_phy_lock(bp);
11580 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11581
01cd4528
EG
11582 if (!rc)
11583 rc = value;
11584 return rc;
11585}
a2fbb9ea 11586
01cd4528
EG
11587/* called with rtnl_lock */
11588static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11589 u16 addr, u16 value)
11590{
11591 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11592 int rc;
11593
51c1a580
MS
11594 DP(NETIF_MSG_LINK,
11595 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11596 prtad, devad, addr, value);
01cd4528 11597
01cd4528
EG
11598 /* The HW expects different devad if CL22 is used */
11599 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11600
01cd4528 11601 bnx2x_acquire_phy_lock(bp);
e10bc84d 11602 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11603 bnx2x_release_phy_lock(bp);
11604 return rc;
11605}
c18487ee 11606
01cd4528
EG
11607/* called with rtnl_lock */
11608static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11609{
11610 struct bnx2x *bp = netdev_priv(dev);
11611 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11612
01cd4528
EG
11613 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11614 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11615
01cd4528
EG
11616 if (!netif_running(dev))
11617 return -EAGAIN;
11618
11619 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11620}
11621
257ddbda 11622#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11623static void poll_bnx2x(struct net_device *dev)
11624{
11625 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11626 int i;
a2fbb9ea 11627
14a15d61
MS
11628 for_each_eth_queue(bp, i) {
11629 struct bnx2x_fastpath *fp = &bp->fp[i];
11630 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11631 }
a2fbb9ea
ET
11632}
11633#endif
11634
614c76df
DK
11635static int bnx2x_validate_addr(struct net_device *dev)
11636{
11637 struct bnx2x *bp = netdev_priv(dev);
11638
51c1a580
MS
11639 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11640 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11641 return -EADDRNOTAVAIL;
51c1a580 11642 }
614c76df
DK
11643 return 0;
11644}
11645
c64213cd
SH
11646static const struct net_device_ops bnx2x_netdev_ops = {
11647 .ndo_open = bnx2x_open,
11648 .ndo_stop = bnx2x_close,
11649 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11650 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11651 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11652 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11653 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11654 .ndo_do_ioctl = bnx2x_ioctl,
11655 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11656 .ndo_fix_features = bnx2x_fix_features,
11657 .ndo_set_features = bnx2x_set_features,
c64213cd 11658 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11659#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11660 .ndo_poll_controller = poll_bnx2x,
11661#endif
6383c0b3
AE
11662 .ndo_setup_tc = bnx2x_setup_tc,
11663
55c11941 11664#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11665 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11666#endif
c64213cd
SH
11667};
11668
1191cb83 11669static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11670{
11671 struct device *dev = &bp->pdev->dev;
11672
11673 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11674 bp->flags |= USING_DAC_FLAG;
11675 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11676 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11677 return -EIO;
11678 }
11679 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11680 dev_err(dev, "System does not support DMA, aborting\n");
11681 return -EIO;
11682 }
11683
11684 return 0;
11685}
11686
1ab4434c
AE
11687static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
11688 struct net_device *dev, unsigned long board_type)
a2fbb9ea 11689{
a2fbb9ea 11690 int rc;
c22610d0 11691 u32 pci_cfg_dword;
65087cfe
AE
11692 bool chip_is_e1x = (board_type == BCM57710 ||
11693 board_type == BCM57711 ||
11694 board_type == BCM57711E);
a2fbb9ea
ET
11695
11696 SET_NETDEV_DEV(dev, &pdev->dev);
a2fbb9ea 11697
34f80b04
EG
11698 bp->dev = dev;
11699 bp->pdev = pdev;
a2fbb9ea
ET
11700
11701 rc = pci_enable_device(pdev);
11702 if (rc) {
cdaa7cb8
VZ
11703 dev_err(&bp->pdev->dev,
11704 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11705 goto err_out;
11706 }
11707
11708 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11709 dev_err(&bp->pdev->dev,
11710 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11711 rc = -ENODEV;
11712 goto err_out_disable;
11713 }
11714
1ab4434c
AE
11715 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11716 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
a2fbb9ea
ET
11717 rc = -ENODEV;
11718 goto err_out_disable;
11719 }
11720
092a5fc9
YR
11721 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
11722 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
11723 PCICFG_REVESION_ID_ERROR_VAL) {
11724 pr_err("PCI device error, probably due to fan failure, aborting\n");
11725 rc = -ENODEV;
11726 goto err_out_disable;
11727 }
11728
34f80b04
EG
11729 if (atomic_read(&pdev->enable_cnt) == 1) {
11730 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11731 if (rc) {
cdaa7cb8
VZ
11732 dev_err(&bp->pdev->dev,
11733 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11734 goto err_out_disable;
11735 }
a2fbb9ea 11736
34f80b04
EG
11737 pci_set_master(pdev);
11738 pci_save_state(pdev);
11739 }
a2fbb9ea 11740
1ab4434c
AE
11741 if (IS_PF(bp)) {
11742 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11743 if (bp->pm_cap == 0) {
11744 dev_err(&bp->pdev->dev,
11745 "Cannot find power management capability, aborting\n");
11746 rc = -EIO;
11747 goto err_out_release;
11748 }
a2fbb9ea
ET
11749 }
11750
77c98e6a 11751 if (!pci_is_pcie(pdev)) {
51c1a580 11752 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11753 rc = -EIO;
11754 goto err_out_release;
11755 }
11756
619c5cb6
VZ
11757 rc = bnx2x_set_coherency_mask(bp);
11758 if (rc)
a2fbb9ea 11759 goto err_out_release;
a2fbb9ea 11760
34f80b04
EG
11761 dev->mem_start = pci_resource_start(pdev, 0);
11762 dev->base_addr = dev->mem_start;
11763 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11764
11765 dev->irq = pdev->irq;
11766
275f165f 11767 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11768 if (!bp->regview) {
cdaa7cb8
VZ
11769 dev_err(&bp->pdev->dev,
11770 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11771 rc = -ENOMEM;
11772 goto err_out_release;
11773 }
11774
c22610d0
AE
11775 /* In E1/E1H use pci device function given by kernel.
11776 * In E2/E3 read physical function from ME register since these chips
11777 * support Physical Device Assignment where kernel BDF maybe arbitrary
11778 * (depending on hypervisor).
11779 */
11780 if (chip_is_e1x)
11781 bp->pf_num = PCI_FUNC(pdev->devfn);
11782 else {/* chip is E2/3*/
11783 pci_read_config_dword(bp->pdev,
11784 PCICFG_ME_REGISTER, &pci_cfg_dword);
11785 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
11786 ME_REG_ABS_PF_NUM_SHIFT);
11787 }
51c1a580 11788 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 11789
a2fbb9ea
ET
11790 bnx2x_set_power_state(bp, PCI_D0);
11791
34f80b04
EG
11792 /* clean indirect addresses */
11793 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11794 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
11795 /*
11796 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
11797 * is not used by the driver.
11798 */
1ab4434c
AE
11799 if (IS_PF(bp)) {
11800 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11801 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11802 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11803 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
11804
11805 if (chip_is_e1x) {
11806 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11807 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11808 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11809 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11810 }
a5c53dbc 11811
1ab4434c
AE
11812 /* Enable internal target-read (in case we are probed after PF
11813 * FLR). Must be done prior to any BAR read access. Only for
11814 * 57712 and up
11815 */
11816 if (!chip_is_e1x)
11817 REG_WR(bp,
11818 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
a5c53dbc 11819 }
a2fbb9ea 11820
34f80b04 11821 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 11822
c64213cd 11823 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 11824 bnx2x_set_ethtool_ops(dev);
5316bc0b 11825
01789349
JP
11826 dev->priv_flags |= IFF_UNICAST_FLT;
11827
66371c44 11828 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
11829 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11830 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11831 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
11832
11833 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11834 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11835
11836 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 11837 if (bp->flags & USING_DAC_FLAG)
66371c44 11838 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 11839
538dd2e3
MB
11840 /* Add Loopback capability to the device */
11841 dev->hw_features |= NETIF_F_LOOPBACK;
11842
98507672 11843#ifdef BCM_DCBNL
785b9b1a
SR
11844 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11845#endif
11846
01cd4528
EG
11847 /* get_port_hwinfo() will set prtad and mmds properly */
11848 bp->mdio.prtad = MDIO_PRTAD_NONE;
11849 bp->mdio.mmds = 0;
11850 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11851 bp->mdio.dev = dev;
11852 bp->mdio.mdio_read = bnx2x_mdio_read;
11853 bp->mdio.mdio_write = bnx2x_mdio_write;
11854
a2fbb9ea
ET
11855 return 0;
11856
a2fbb9ea 11857err_out_release:
34f80b04
EG
11858 if (atomic_read(&pdev->enable_cnt) == 1)
11859 pci_release_regions(pdev);
a2fbb9ea
ET
11860
11861err_out_disable:
11862 pci_disable_device(pdev);
11863 pci_set_drvdata(pdev, NULL);
11864
11865err_out:
11866 return rc;
11867}
11868
1dd06ae8 11869static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
25047950 11870{
1ab4434c 11871 u32 val = 0;
25047950 11872
1ab4434c 11873 pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
37f9ce62 11874 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 11875
37f9ce62
EG
11876 /* return value of 1=2.5GHz 2=5GHz */
11877 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 11878}
37f9ce62 11879
6891dd25 11880static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 11881{
37f9ce62 11882 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
11883 struct bnx2x_fw_file_hdr *fw_hdr;
11884 struct bnx2x_fw_file_section *sections;
94a78b79 11885 u32 offset, len, num_ops;
37f9ce62 11886 u16 *ops_offsets;
94a78b79 11887 int i;
37f9ce62 11888 const u8 *fw_ver;
94a78b79 11889
51c1a580
MS
11890 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
11891 BNX2X_ERR("Wrong FW size\n");
94a78b79 11892 return -EINVAL;
51c1a580 11893 }
94a78b79
VZ
11894
11895 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
11896 sections = (struct bnx2x_fw_file_section *)fw_hdr;
11897
11898 /* Make sure none of the offsets and sizes make us read beyond
11899 * the end of the firmware data */
11900 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
11901 offset = be32_to_cpu(sections[i].offset);
11902 len = be32_to_cpu(sections[i].len);
11903 if (offset + len > firmware->size) {
51c1a580 11904 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
11905 return -EINVAL;
11906 }
11907 }
11908
11909 /* Likewise for the init_ops offsets */
11910 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
11911 ops_offsets = (u16 *)(firmware->data + offset);
11912 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
11913
11914 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
11915 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 11916 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
11917 return -EINVAL;
11918 }
11919 }
11920
11921 /* Check FW version */
11922 offset = be32_to_cpu(fw_hdr->fw_version.offset);
11923 fw_ver = firmware->data + offset;
11924 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
11925 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
11926 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
11927 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
11928 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11929 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
11930 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
11931 BCM_5710_FW_MINOR_VERSION,
11932 BCM_5710_FW_REVISION_VERSION,
11933 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 11934 return -EINVAL;
94a78b79
VZ
11935 }
11936
11937 return 0;
11938}
11939
1191cb83 11940static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11941{
ab6ad5a4
EG
11942 const __be32 *source = (const __be32 *)_source;
11943 u32 *target = (u32 *)_target;
94a78b79 11944 u32 i;
94a78b79
VZ
11945
11946 for (i = 0; i < n/4; i++)
11947 target[i] = be32_to_cpu(source[i]);
11948}
11949
11950/*
11951 Ops array is stored in the following format:
11952 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11953 */
1191cb83 11954static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 11955{
ab6ad5a4
EG
11956 const __be32 *source = (const __be32 *)_source;
11957 struct raw_op *target = (struct raw_op *)_target;
94a78b79 11958 u32 i, j, tmp;
94a78b79 11959
ab6ad5a4 11960 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
11961 tmp = be32_to_cpu(source[j]);
11962 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
11963 target[i].offset = tmp & 0xffffff;
11964 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
11965 }
11966}
ab6ad5a4 11967
1aa8b471 11968/* IRO array is stored in the following format:
523224a3
DK
11969 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11970 */
1191cb83 11971static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
11972{
11973 const __be32 *source = (const __be32 *)_source;
11974 struct iro *target = (struct iro *)_target;
11975 u32 i, j, tmp;
11976
11977 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11978 target[i].base = be32_to_cpu(source[j]);
11979 j++;
11980 tmp = be32_to_cpu(source[j]);
11981 target[i].m1 = (tmp >> 16) & 0xffff;
11982 target[i].m2 = tmp & 0xffff;
11983 j++;
11984 tmp = be32_to_cpu(source[j]);
11985 target[i].m3 = (tmp >> 16) & 0xffff;
11986 target[i].size = tmp & 0xffff;
11987 j++;
11988 }
11989}
11990
1191cb83 11991static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 11992{
ab6ad5a4
EG
11993 const __be16 *source = (const __be16 *)_source;
11994 u16 *target = (u16 *)_target;
94a78b79 11995 u32 i;
94a78b79
VZ
11996
11997 for (i = 0; i < n/2; i++)
11998 target[i] = be16_to_cpu(source[i]);
11999}
12000
7995c64e
JP
12001#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12002do { \
12003 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12004 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 12005 if (!bp->arr) \
7995c64e 12006 goto lbl; \
7995c64e
JP
12007 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12008 (u8 *)bp->arr, len); \
12009} while (0)
94a78b79 12010
3b603066 12011static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 12012{
c0ea452e 12013 const char *fw_file_name;
94a78b79 12014 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 12015 int rc;
94a78b79 12016
c0ea452e
MS
12017 if (bp->firmware)
12018 return 0;
94a78b79 12019
c0ea452e
MS
12020 if (CHIP_IS_E1(bp))
12021 fw_file_name = FW_FILE_NAME_E1;
12022 else if (CHIP_IS_E1H(bp))
12023 fw_file_name = FW_FILE_NAME_E1H;
12024 else if (!CHIP_IS_E1x(bp))
12025 fw_file_name = FW_FILE_NAME_E2;
12026 else {
12027 BNX2X_ERR("Unsupported chip revision\n");
12028 return -EINVAL;
12029 }
12030 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 12031
c0ea452e
MS
12032 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12033 if (rc) {
12034 BNX2X_ERR("Can't load firmware file %s\n",
12035 fw_file_name);
12036 goto request_firmware_exit;
12037 }
eb2afd4a 12038
c0ea452e
MS
12039 rc = bnx2x_check_firmware(bp);
12040 if (rc) {
12041 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12042 goto request_firmware_exit;
94a78b79
VZ
12043 }
12044
12045 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12046
12047 /* Initialize the pointers to the init arrays */
12048 /* Blob */
12049 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12050
12051 /* Opcodes */
12052 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12053
12054 /* Offsets */
ab6ad5a4
EG
12055 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12056 be16_to_cpu_n);
94a78b79
VZ
12057
12058 /* STORMs firmware */
573f2035
EG
12059 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12060 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12061 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12062 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12063 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12064 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12065 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12066 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12067 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12068 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12069 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12070 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12071 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12072 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12073 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12074 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
12075 /* IRO */
12076 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
12077
12078 return 0;
ab6ad5a4 12079
523224a3
DK
12080iro_alloc_err:
12081 kfree(bp->init_ops_offsets);
94a78b79
VZ
12082init_offsets_alloc_err:
12083 kfree(bp->init_ops);
12084init_ops_alloc_err:
12085 kfree(bp->init_data);
12086request_firmware_exit:
12087 release_firmware(bp->firmware);
127d0a19 12088 bp->firmware = NULL;
94a78b79
VZ
12089
12090 return rc;
12091}
12092
619c5cb6
VZ
12093static void bnx2x_release_firmware(struct bnx2x *bp)
12094{
12095 kfree(bp->init_ops_offsets);
12096 kfree(bp->init_ops);
12097 kfree(bp->init_data);
12098 release_firmware(bp->firmware);
eb2afd4a 12099 bp->firmware = NULL;
619c5cb6
VZ
12100}
12101
12102
12103static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12104 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12105 .init_hw_cmn = bnx2x_init_hw_common,
12106 .init_hw_port = bnx2x_init_hw_port,
12107 .init_hw_func = bnx2x_init_hw_func,
12108
12109 .reset_hw_cmn = bnx2x_reset_common,
12110 .reset_hw_port = bnx2x_reset_port,
12111 .reset_hw_func = bnx2x_reset_func,
12112
12113 .gunzip_init = bnx2x_gunzip_init,
12114 .gunzip_end = bnx2x_gunzip_end,
12115
12116 .init_fw = bnx2x_init_firmware,
12117 .release_fw = bnx2x_release_firmware,
12118};
12119
12120void bnx2x__init_func_obj(struct bnx2x *bp)
12121{
12122 /* Prepare DMAE related driver resources */
12123 bnx2x_setup_dmae(bp);
12124
12125 bnx2x_init_func_obj(bp, &bp->func_obj,
12126 bnx2x_sp(bp, func_rdata),
12127 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
12128 bnx2x_sp(bp, func_afex_rdata),
12129 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
12130 &bnx2x_func_sp_drv);
12131}
12132
12133/* must be called after sriov-enable */
1191cb83 12134static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 12135{
37ae41a9 12136 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 12137
290ca2bb
AE
12138 if (IS_SRIOV(bp))
12139 cid_count += BNX2X_VF_CIDS;
12140
55c11941
MS
12141 if (CNIC_SUPPORT(bp))
12142 cid_count += CNIC_CID_MAX;
290ca2bb 12143
523224a3
DK
12144 return roundup(cid_count, QM_CID_ROUND);
12145}
f85582f8 12146
619c5cb6 12147/**
6383c0b3 12148 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
12149 *
12150 * @dev: pci device
12151 *
12152 */
55c11941 12153static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
1ab4434c 12154 int cnic_cnt, bool is_vf)
619c5cb6 12155{
1ab4434c
AE
12156 int pos, index;
12157 u16 control = 0;
619c5cb6
VZ
12158
12159 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
12160
12161 /*
12162 * If MSI-X is not supported - return number of SBs needed to support
12163 * one fast path queue: one FP queue + SB for CNIC
12164 */
1ab4434c
AE
12165 if (!pos) {
12166 dev_info(&pdev->dev, "no msix capability found\n");
55c11941 12167 return 1 + cnic_cnt;
1ab4434c
AE
12168 }
12169 dev_info(&pdev->dev, "msix capability found\n");
619c5cb6 12170
6383c0b3
AE
12171 /*
12172 * The value in the PCI configuration space is the index of the last
12173 * entry, namely one less than the actual size of the table, which is
12174 * exactly what we want to return from this function: number of all SBs
12175 * without the default SB.
1ab4434c 12176 * For VFs there is no default SB, then we return (index+1).
6383c0b3 12177 */
619c5cb6 12178 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
619c5cb6 12179
1ab4434c 12180 index = control & PCI_MSIX_FLAGS_QSIZE;
4bd9b0ff 12181
1ab4434c
AE
12182 return is_vf ? index + 1 : index;
12183}
523224a3 12184
1ab4434c
AE
12185static int set_max_cos_est(int chip_id)
12186{
12187 switch (chip_id) {
f2e0899f
DK
12188 case BCM57710:
12189 case BCM57711:
12190 case BCM57711E:
1ab4434c 12191 return BNX2X_MULTI_TX_COS_E1X;
f2e0899f 12192 case BCM57712:
619c5cb6 12193 case BCM57712_MF:
1ab4434c
AE
12194 case BCM57712_VF:
12195 return BNX2X_MULTI_TX_COS_E2_E3A0;
619c5cb6
VZ
12196 case BCM57800:
12197 case BCM57800_MF:
1ab4434c 12198 case BCM57800_VF:
619c5cb6
VZ
12199 case BCM57810:
12200 case BCM57810_MF:
c3def943
YM
12201 case BCM57840_4_10:
12202 case BCM57840_2_20:
1ab4434c 12203 case BCM57840_O:
c3def943 12204 case BCM57840_MFO:
1ab4434c 12205 case BCM57810_VF:
619c5cb6 12206 case BCM57840_MF:
1ab4434c 12207 case BCM57840_VF:
7e8e02df
BW
12208 case BCM57811:
12209 case BCM57811_MF:
1ab4434c
AE
12210 case BCM57811_VF:
12211 return BNX2X_MULTI_TX_COS_E3B0;
12212 return 1;
f2e0899f 12213 default:
1ab4434c 12214 pr_err("Unknown board_type (%d), aborting\n", chip_id);
870634b0 12215 return -ENODEV;
f2e0899f 12216 }
1ab4434c 12217}
f2e0899f 12218
1ab4434c
AE
12219static int set_is_vf(int chip_id)
12220{
12221 switch (chip_id) {
12222 case BCM57712_VF:
12223 case BCM57800_VF:
12224 case BCM57810_VF:
12225 case BCM57840_VF:
12226 case BCM57811_VF:
12227 return true;
12228 default:
12229 return false;
12230 }
12231}
6383c0b3 12232
1ab4434c
AE
12233struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12234
12235static int bnx2x_init_one(struct pci_dev *pdev,
12236 const struct pci_device_id *ent)
12237{
12238 struct net_device *dev = NULL;
12239 struct bnx2x *bp;
12240 int pcie_width, pcie_speed;
12241 int rc, max_non_def_sbs;
12242 int rx_count, tx_count, rss_count, doorbell_size;
12243 int max_cos_est;
12244 bool is_vf;
12245 int cnic_cnt;
12246
12247 /* An estimated maximum supported CoS number according to the chip
12248 * version.
12249 * We will try to roughly estimate the maximum number of CoSes this chip
12250 * may support in order to minimize the memory allocated for Tx
12251 * netdev_queue's. This number will be accurately calculated during the
12252 * initialization of bp->max_cos based on the chip versions AND chip
12253 * revision in the bnx2x_init_bp().
12254 */
12255 max_cos_est = set_max_cos_est(ent->driver_data);
12256 if (max_cos_est < 0)
12257 return max_cos_est;
12258 is_vf = set_is_vf(ent->driver_data);
12259 cnic_cnt = is_vf ? 0 : 1;
12260
12261 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
6383c0b3
AE
12262
12263 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
1ab4434c
AE
12264 rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
12265
12266 if (rss_count < 1)
12267 return -EINVAL;
6383c0b3
AE
12268
12269 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12270 rx_count = rss_count + cnic_cnt;
6383c0b3 12271
1ab4434c 12272 /* Maximum number of netdev Tx queues:
37ae41a9 12273 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12274 */
55c11941 12275 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12276
a2fbb9ea 12277 /* dev zeroed in init_etherdev */
6383c0b3 12278 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12279 if (!dev)
a2fbb9ea
ET
12280 return -ENOMEM;
12281
a2fbb9ea 12282 bp = netdev_priv(dev);
a2fbb9ea 12283
1ab4434c
AE
12284 bp->flags = 0;
12285 if (is_vf)
12286 bp->flags |= IS_VF_FLAG;
12287
6383c0b3 12288 bp->igu_sb_cnt = max_non_def_sbs;
1ab4434c 12289 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
6383c0b3 12290 bp->msg_enable = debug;
55c11941 12291 bp->cnic_support = cnic_cnt;
4bd9b0ff 12292 bp->cnic_probe = bnx2x_cnic_probe;
55c11941 12293
6383c0b3 12294 pci_set_drvdata(pdev, dev);
523224a3 12295
1ab4434c 12296 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
a2fbb9ea
ET
12297 if (rc < 0) {
12298 free_netdev(dev);
12299 return rc;
12300 }
12301
1ab4434c
AE
12302 BNX2X_DEV_INFO("This is a %s function\n",
12303 IS_PF(bp) ? "physical" : "virtual");
55c11941 12304 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
1ab4434c 12305 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
60aa0509
MS
12306 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
12307 tx_count, rx_count);
12308
34f80b04 12309 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12310 if (rc)
12311 goto init_one_exit;
12312
1ab4434c
AE
12313 /* Map doorbells here as we need the real value of bp->max_cos which
12314 * is initialized in bnx2x_init_bp() to determine the number of
12315 * l2 connections.
6383c0b3 12316 */
1ab4434c
AE
12317 if (IS_VF(bp)) {
12318 /* vf doorbells are embedded within the regview */
12319 bp->doorbells = bp->regview + PXP_VF_ADDR_DB_START;
12320
12321 /* allocate vf2pf mailbox for vf to pf channel */
12322 BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
12323 sizeof(struct bnx2x_vf_mbx_msg));
12324 } else {
12325 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12326 if (doorbell_size > pci_resource_len(pdev, 2)) {
12327 dev_err(&bp->pdev->dev,
12328 "Cannot map doorbells, bar size too small, aborting\n");
12329 rc = -ENOMEM;
12330 goto init_one_exit;
12331 }
12332 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12333 doorbell_size);
37ae41a9 12334 }
6383c0b3
AE
12335 if (!bp->doorbells) {
12336 dev_err(&bp->pdev->dev,
12337 "Cannot map doorbell space, aborting\n");
12338 rc = -ENOMEM;
12339 goto init_one_exit;
12340 }
12341
be1f1ffa
AE
12342 if (IS_VF(bp)) {
12343 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12344 if (rc)
12345 goto init_one_exit;
12346 }
12347
290ca2bb
AE
12348 /* Enable SRIOV if capability found in configuration space.
12349 * Once the generic SR-IOV framework makes it in from the
12350 * pci tree this will be revised, to allow dynamic control
12351 * over the number of VFs. Right now, change the num of vfs
12352 * param below to enable SR-IOV.
12353 */
12354 rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
12355 if (rc)
12356 goto init_one_exit;
12357
523224a3 12358 /* calc qm_cid_count */
6383c0b3 12359 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
1ab4434c 12360 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
523224a3 12361
55c11941 12362 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12363 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12364 bp->flags |= NO_FCOE_FLAG;
12365
477864dd
DK
12366 /* disable FCOE for 57840 device, until FW supports it */
12367 switch (ent->driver_data) {
12368 case BCM57840_O:
12369 case BCM57840_4_10:
12370 case BCM57840_2_20:
12371 case BCM57840_MFO:
12372 case BCM57840_MF:
12373 bp->flags |= NO_FCOE_FLAG;
12374 }
0e8d2ec5
MS
12375
12376 /* Set bp->num_queues for MSI-X mode*/
12377 bnx2x_set_num_queues(bp);
12378
25985edc 12379 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12380 * needed.
d6214d7a 12381 */
1ab4434c
AE
12382 rc = bnx2x_set_int_mode(bp);
12383 if (rc) {
12384 dev_err(&pdev->dev, "Cannot set interrupts\n");
12385 goto init_one_exit;
12386 }
d6214d7a 12387
1ab4434c 12388 /* register the net device */
b340007f
VZ
12389 rc = register_netdev(dev);
12390 if (rc) {
12391 dev_err(&pdev->dev, "Cannot register net device\n");
12392 goto init_one_exit;
12393 }
1ab4434c 12394 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
b340007f 12395
55c11941 12396
ec6ba945
VZ
12397 if (!NO_FCOE(bp)) {
12398 /* Add storage MAC address */
12399 rtnl_lock();
12400 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12401 rtnl_unlock();
12402 }
ec6ba945 12403
37f9ce62 12404 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
1ab4434c
AE
12405 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12406 pcie_width, pcie_speed);
d6214d7a 12407
51c1a580
MS
12408 BNX2X_DEV_INFO(
12409 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
12410 board_info[ent->driver_data].name,
12411 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12412 pcie_width,
12413 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
12414 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
12415 "5GHz (Gen2)" : "2.5GHz",
12416 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12417
a2fbb9ea 12418 return 0;
34f80b04 12419
1ab4434c
AE
12420alloc_mem_err:
12421 BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
12422 sizeof(struct bnx2x_vf_mbx_msg));
12423 rc = -ENOMEM;
12424
34f80b04
EG
12425init_one_exit:
12426 if (bp->regview)
12427 iounmap(bp->regview);
12428
1ab4434c 12429 if (IS_PF(bp) && bp->doorbells)
34f80b04
EG
12430 iounmap(bp->doorbells);
12431
12432 free_netdev(dev);
12433
12434 if (atomic_read(&pdev->enable_cnt) == 1)
12435 pci_release_regions(pdev);
12436
12437 pci_disable_device(pdev);
12438 pci_set_drvdata(pdev, NULL);
12439
12440 return rc;
a2fbb9ea
ET
12441}
12442
0329aba1 12443static void bnx2x_remove_one(struct pci_dev *pdev)
a2fbb9ea
ET
12444{
12445 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
12446 struct bnx2x *bp;
12447
12448 if (!dev) {
cdaa7cb8 12449 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
12450 return;
12451 }
228241eb 12452 bp = netdev_priv(dev);
a2fbb9ea 12453
ec6ba945
VZ
12454 /* Delete storage MAC address */
12455 if (!NO_FCOE(bp)) {
12456 rtnl_lock();
12457 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12458 rtnl_unlock();
12459 }
ec6ba945 12460
98507672
SR
12461#ifdef BCM_DCBNL
12462 /* Delete app tlvs from dcbnl */
12463 bnx2x_dcbnl_update_applist(bp, true);
12464#endif
12465
a2fbb9ea
ET
12466 unregister_netdev(dev);
12467
084d6cbb 12468 /* Power on: we can't let PCI layer write to us while we are in D3 */
1ab4434c
AE
12469 if (IS_PF(bp))
12470 bnx2x_set_power_state(bp, PCI_D0);
084d6cbb 12471
d6214d7a
DK
12472 /* Disable MSI/MSI-X */
12473 bnx2x_disable_msi(bp);
f85582f8 12474
084d6cbb 12475 /* Power off */
1ab4434c
AE
12476 if (IS_PF(bp))
12477 bnx2x_set_power_state(bp, PCI_D3hot);
084d6cbb 12478
72fd0718 12479 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12480 cancel_delayed_work_sync(&bp->sp_rtnl_task);
290ca2bb
AE
12481
12482 bnx2x_iov_remove_one(bp);
12483
4513f925
AE
12484 /* send message via vfpf channel to release the resources of this vf */
12485 if (IS_VF(bp))
12486 bnx2x_vfpf_release(bp);
72fd0718 12487
a2fbb9ea
ET
12488 if (bp->regview)
12489 iounmap(bp->regview);
12490
1ab4434c
AE
12491 /* for vf doorbells are part of the regview and were unmapped along with
12492 * it. FW is only loaded by PF.
12493 */
12494 if (IS_PF(bp)) {
12495 if (bp->doorbells)
12496 iounmap(bp->doorbells);
eb2afd4a 12497
1ab4434c
AE
12498 bnx2x_release_firmware(bp);
12499 }
523224a3
DK
12500 bnx2x_free_mem_bp(bp);
12501
a2fbb9ea 12502 free_netdev(dev);
34f80b04
EG
12503
12504 if (atomic_read(&pdev->enable_cnt) == 1)
12505 pci_release_regions(pdev);
12506
a2fbb9ea
ET
12507 pci_disable_device(pdev);
12508 pci_set_drvdata(pdev, NULL);
12509}
12510
f8ef6e44
YG
12511static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12512{
12513 int i;
12514
12515 bp->state = BNX2X_STATE_ERROR;
12516
12517 bp->rx_mode = BNX2X_RX_MODE_NONE;
12518
55c11941
MS
12519 if (CNIC_LOADED(bp))
12520 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12521
619c5cb6
VZ
12522 /* Stop Tx */
12523 bnx2x_tx_disable(bp);
12524
f8ef6e44 12525 bnx2x_netif_stop(bp, 0);
26614ba5
MS
12526 /* Delete all NAPI objects */
12527 bnx2x_del_all_napi(bp);
55c11941
MS
12528 if (CNIC_LOADED(bp))
12529 bnx2x_del_all_napi_cnic(bp);
f8ef6e44
YG
12530
12531 del_timer_sync(&bp->timer);
619c5cb6
VZ
12532
12533 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
12534
12535 /* Release IRQs */
d6214d7a 12536 bnx2x_free_irq(bp);
f8ef6e44 12537
f8ef6e44
YG
12538 /* Free SKBs, SGEs, TPA pool and driver internals */
12539 bnx2x_free_skbs(bp);
523224a3 12540
ec6ba945 12541 for_each_rx_queue(bp, i)
f8ef6e44 12542 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 12543
f8ef6e44
YG
12544 bnx2x_free_mem(bp);
12545
12546 bp->state = BNX2X_STATE_CLOSED;
12547
619c5cb6
VZ
12548 netif_carrier_off(bp->dev);
12549
f8ef6e44
YG
12550 return 0;
12551}
12552
12553static void bnx2x_eeh_recover(struct bnx2x *bp)
12554{
12555 u32 val;
12556
12557 mutex_init(&bp->port.phy_mutex);
12558
f8ef6e44
YG
12559
12560 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12561 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12562 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12563 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
12564}
12565
493adb1f
WX
12566/**
12567 * bnx2x_io_error_detected - called when PCI error is detected
12568 * @pdev: Pointer to PCI device
12569 * @state: The current pci connection state
12570 *
12571 * This function is called after a PCI bus error affecting
12572 * this device has been detected.
12573 */
12574static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12575 pci_channel_state_t state)
12576{
12577 struct net_device *dev = pci_get_drvdata(pdev);
12578 struct bnx2x *bp = netdev_priv(dev);
12579
12580 rtnl_lock();
12581
12582 netif_device_detach(dev);
12583
07ce50e4
DN
12584 if (state == pci_channel_io_perm_failure) {
12585 rtnl_unlock();
12586 return PCI_ERS_RESULT_DISCONNECT;
12587 }
12588
493adb1f 12589 if (netif_running(dev))
f8ef6e44 12590 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
12591
12592 pci_disable_device(pdev);
12593
12594 rtnl_unlock();
12595
12596 /* Request a slot reset */
12597 return PCI_ERS_RESULT_NEED_RESET;
12598}
12599
12600/**
12601 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12602 * @pdev: Pointer to PCI device
12603 *
12604 * Restart the card from scratch, as if from a cold-boot.
12605 */
12606static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12607{
12608 struct net_device *dev = pci_get_drvdata(pdev);
12609 struct bnx2x *bp = netdev_priv(dev);
12610
12611 rtnl_lock();
12612
12613 if (pci_enable_device(pdev)) {
12614 dev_err(&pdev->dev,
12615 "Cannot re-enable PCI device after reset\n");
12616 rtnl_unlock();
12617 return PCI_ERS_RESULT_DISCONNECT;
12618 }
12619
12620 pci_set_master(pdev);
12621 pci_restore_state(pdev);
12622
12623 if (netif_running(dev))
12624 bnx2x_set_power_state(bp, PCI_D0);
12625
12626 rtnl_unlock();
12627
12628 return PCI_ERS_RESULT_RECOVERED;
12629}
12630
12631/**
12632 * bnx2x_io_resume - called when traffic can start flowing again
12633 * @pdev: Pointer to PCI device
12634 *
12635 * This callback is called when the error recovery driver tells us that
12636 * its OK to resume normal operation.
12637 */
12638static void bnx2x_io_resume(struct pci_dev *pdev)
12639{
12640 struct net_device *dev = pci_get_drvdata(pdev);
12641 struct bnx2x *bp = netdev_priv(dev);
12642
72fd0718 12643 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12644 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12645 return;
12646 }
12647
493adb1f
WX
12648 rtnl_lock();
12649
f8ef6e44
YG
12650 bnx2x_eeh_recover(bp);
12651
493adb1f 12652 if (netif_running(dev))
f8ef6e44 12653 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12654
12655 netif_device_attach(dev);
12656
12657 rtnl_unlock();
12658}
12659
3646f0e5 12660static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12661 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12662 .slot_reset = bnx2x_io_slot_reset,
12663 .resume = bnx2x_io_resume,
493adb1f
WX
12664};
12665
a2fbb9ea 12666static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12667 .name = DRV_MODULE_NAME,
12668 .id_table = bnx2x_pci_tbl,
12669 .probe = bnx2x_init_one,
0329aba1 12670 .remove = bnx2x_remove_one,
493adb1f
WX
12671 .suspend = bnx2x_suspend,
12672 .resume = bnx2x_resume,
12673 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
12674};
12675
12676static int __init bnx2x_init(void)
12677{
dd21ca6d
SG
12678 int ret;
12679
7995c64e 12680 pr_info("%s", version);
938cf541 12681
1cf167f2
EG
12682 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12683 if (bnx2x_wq == NULL) {
7995c64e 12684 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12685 return -ENOMEM;
12686 }
12687
dd21ca6d
SG
12688 ret = pci_register_driver(&bnx2x_pci_driver);
12689 if (ret) {
7995c64e 12690 pr_err("Cannot register driver\n");
dd21ca6d
SG
12691 destroy_workqueue(bnx2x_wq);
12692 }
12693 return ret;
a2fbb9ea
ET
12694}
12695
12696static void __exit bnx2x_cleanup(void)
12697{
452427b0 12698 struct list_head *pos, *q;
a2fbb9ea 12699 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12700
12701 destroy_workqueue(bnx2x_wq);
452427b0
YM
12702
12703 /* Free globablly allocated resources */
12704 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12705 struct bnx2x_prev_path_list *tmp =
12706 list_entry(pos, struct bnx2x_prev_path_list, list);
12707 list_del(pos);
12708 kfree(tmp);
12709 }
a2fbb9ea
ET
12710}
12711
3deb8167
YR
12712void bnx2x_notify_link_changed(struct bnx2x *bp)
12713{
12714 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12715}
12716
a2fbb9ea
ET
12717module_init(bnx2x_init);
12718module_exit(bnx2x_cleanup);
12719
619c5cb6
VZ
12720/**
12721 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12722 *
12723 * @bp: driver handle
12724 * @set: set or clear the CAM entry
12725 *
12726 * This function will wait until the ramdord completion returns.
12727 * Return 0 if success, -ENODEV if ramrod doesn't return.
12728 */
1191cb83 12729static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
12730{
12731 unsigned long ramrod_flags = 0;
12732
12733 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12734 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12735 &bp->iscsi_l2_mac_obj, true,
12736 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12737}
993ac7b5
MC
12738
12739/* count denotes the number of new completions we have seen */
12740static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12741{
12742 struct eth_spe *spe;
a052997e 12743 int cxt_index, cxt_offset;
993ac7b5
MC
12744
12745#ifdef BNX2X_STOP_ON_ERROR
12746 if (unlikely(bp->panic))
12747 return;
12748#endif
12749
12750 spin_lock_bh(&bp->spq_lock);
c2bff63f 12751 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
12752 bp->cnic_spq_pending -= count;
12753
993ac7b5 12754
c2bff63f
DK
12755 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12756 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12757 & SPE_HDR_CONN_TYPE) >>
12758 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
12759 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12760 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
12761
12762 /* Set validation for iSCSI L2 client before sending SETUP
12763 * ramrod
12764 */
12765 if (type == ETH_CONNECTION_TYPE) {
a052997e 12766 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 12767 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 12768 ILT_PAGE_CIDS;
37ae41a9 12769 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
12770 (cxt_index * ILT_PAGE_CIDS);
12771 bnx2x_set_ctx_validation(bp,
12772 &bp->context[cxt_index].
12773 vcxt[cxt_offset].eth,
37ae41a9 12774 BNX2X_ISCSI_ETH_CID(bp));
a052997e 12775 }
c2bff63f
DK
12776 }
12777
619c5cb6
VZ
12778 /*
12779 * There may be not more than 8 L2, not more than 8 L5 SPEs
12780 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
12781 * COMMON ramrods is not more than the EQ and SPQ can
12782 * accommodate.
c2bff63f 12783 */
6e30dd4e
VZ
12784 if (type == ETH_CONNECTION_TYPE) {
12785 if (!atomic_read(&bp->cq_spq_left))
12786 break;
12787 else
12788 atomic_dec(&bp->cq_spq_left);
12789 } else if (type == NONE_CONNECTION_TYPE) {
12790 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
12791 break;
12792 else
6e30dd4e 12793 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
12794 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12795 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
12796 if (bp->cnic_spq_pending >=
12797 bp->cnic_eth_dev.max_kwqe_pending)
12798 break;
12799 else
12800 bp->cnic_spq_pending++;
12801 } else {
12802 BNX2X_ERR("Unknown SPE type: %d\n", type);
12803 bnx2x_panic();
993ac7b5 12804 break;
c2bff63f 12805 }
993ac7b5
MC
12806
12807 spe = bnx2x_sp_get_next(bp);
12808 *spe = *bp->cnic_kwq_cons;
12809
51c1a580 12810 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
12811 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12812
12813 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12814 bp->cnic_kwq_cons = bp->cnic_kwq;
12815 else
12816 bp->cnic_kwq_cons++;
12817 }
12818 bnx2x_sp_prod_update(bp);
12819 spin_unlock_bh(&bp->spq_lock);
12820}
12821
12822static int bnx2x_cnic_sp_queue(struct net_device *dev,
12823 struct kwqe_16 *kwqes[], u32 count)
12824{
12825 struct bnx2x *bp = netdev_priv(dev);
12826 int i;
12827
12828#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
12829 if (unlikely(bp->panic)) {
12830 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 12831 return -EIO;
51c1a580 12832 }
993ac7b5
MC
12833#endif
12834
95c6c616
AE
12835 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12836 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 12837 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
12838 return -EAGAIN;
12839 }
12840
993ac7b5
MC
12841 spin_lock_bh(&bp->spq_lock);
12842
12843 for (i = 0; i < count; i++) {
12844 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12845
12846 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12847 break;
12848
12849 *bp->cnic_kwq_prod = *spe;
12850
12851 bp->cnic_kwq_pending++;
12852
51c1a580 12853 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 12854 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
12855 spe->data.update_data_addr.hi,
12856 spe->data.update_data_addr.lo,
993ac7b5
MC
12857 bp->cnic_kwq_pending);
12858
12859 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12860 bp->cnic_kwq_prod = bp->cnic_kwq;
12861 else
12862 bp->cnic_kwq_prod++;
12863 }
12864
12865 spin_unlock_bh(&bp->spq_lock);
12866
12867 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12868 bnx2x_cnic_sp_post(bp, 0);
12869
12870 return i;
12871}
12872
12873static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12874{
12875 struct cnic_ops *c_ops;
12876 int rc = 0;
12877
12878 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
12879 c_ops = rcu_dereference_protected(bp->cnic_ops,
12880 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
12881 if (c_ops)
12882 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12883 mutex_unlock(&bp->cnic_mutex);
12884
12885 return rc;
12886}
12887
12888static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12889{
12890 struct cnic_ops *c_ops;
12891 int rc = 0;
12892
12893 rcu_read_lock();
12894 c_ops = rcu_dereference(bp->cnic_ops);
12895 if (c_ops)
12896 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12897 rcu_read_unlock();
12898
12899 return rc;
12900}
12901
12902/*
12903 * for commands that have no data
12904 */
9f6c9258 12905int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
12906{
12907 struct cnic_ctl_info ctl = {0};
12908
12909 ctl.cmd = cmd;
12910
12911 return bnx2x_cnic_ctl_send(bp, &ctl);
12912}
12913
619c5cb6 12914static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 12915{
619c5cb6 12916 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
12917
12918 /* first we tell CNIC and only then we count this as a completion */
12919 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
12920 ctl.data.comp.cid = cid;
619c5cb6 12921 ctl.data.comp.error = err;
993ac7b5
MC
12922
12923 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 12924 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
12925}
12926
619c5cb6
VZ
12927
12928/* Called with netif_addr_lock_bh() taken.
12929 * Sets an rx_mode config for an iSCSI ETH client.
12930 * Doesn't block.
12931 * Completion should be checked outside.
12932 */
12933static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
12934{
12935 unsigned long accept_flags = 0, ramrod_flags = 0;
12936 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12937 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
12938
12939 if (start) {
12940 /* Start accepting on iSCSI L2 ring. Accept all multicasts
12941 * because it's the only way for UIO Queue to accept
12942 * multicasts (in non-promiscuous mode only one Queue per
12943 * function will receive multicast packets (leading in our
12944 * case).
12945 */
12946 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
12947 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
12948 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
12949 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
12950
12951 /* Clear STOP_PENDING bit if START is requested */
12952 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
12953
12954 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
12955 } else
12956 /* Clear START_PENDING bit if STOP is requested */
12957 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
12958
12959 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
12960 set_bit(sched_state, &bp->sp_state);
12961 else {
12962 __set_bit(RAMROD_RX, &ramrod_flags);
12963 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
12964 ramrod_flags);
12965 }
12966}
12967
12968
993ac7b5
MC
12969static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
12970{
12971 struct bnx2x *bp = netdev_priv(dev);
12972 int rc = 0;
12973
12974 switch (ctl->cmd) {
12975 case DRV_CTL_CTXTBL_WR_CMD: {
12976 u32 index = ctl->data.io.offset;
12977 dma_addr_t addr = ctl->data.io.dma_addr;
12978
12979 bnx2x_ilt_wr(bp, index, addr);
12980 break;
12981 }
12982
c2bff63f
DK
12983 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
12984 int count = ctl->data.credit.credit_count;
993ac7b5
MC
12985
12986 bnx2x_cnic_sp_post(bp, count);
12987 break;
12988 }
12989
12990 /* rtnl_lock is held. */
12991 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
12992 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12993 unsigned long sp_bits = 0;
12994
12995 /* Configure the iSCSI classification object */
12996 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
12997 cp->iscsi_l2_client_id,
12998 cp->iscsi_l2_cid, BP_FUNC(bp),
12999 bnx2x_sp(bp, mac_rdata),
13000 bnx2x_sp_mapping(bp, mac_rdata),
13001 BNX2X_FILTER_MAC_PENDING,
13002 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13003 &bp->macs_pool);
ec6ba945 13004
523224a3 13005 /* Set iSCSI MAC address */
619c5cb6
VZ
13006 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13007 if (rc)
13008 break;
523224a3
DK
13009
13010 mmiowb();
13011 barrier();
13012
619c5cb6
VZ
13013 /* Start accepting on iSCSI L2 ring */
13014
13015 netif_addr_lock_bh(dev);
13016 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13017 netif_addr_unlock_bh(dev);
13018
13019 /* bits to wait on */
13020 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13021 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13022
13023 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13024 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 13025
993ac7b5
MC
13026 break;
13027 }
13028
13029 /* rtnl_lock is held. */
13030 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 13031 unsigned long sp_bits = 0;
993ac7b5 13032
523224a3 13033 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
13034 netif_addr_lock_bh(dev);
13035 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13036 netif_addr_unlock_bh(dev);
13037
13038 /* bits to wait on */
13039 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13040 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13041
13042 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13043 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
13044
13045 mmiowb();
13046 barrier();
13047
13048 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
13049 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13050 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
13051 break;
13052 }
c2bff63f
DK
13053 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13054 int count = ctl->data.credit.credit_count;
13055
13056 smp_mb__before_atomic_inc();
6e30dd4e 13057 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
13058 smp_mb__after_atomic_inc();
13059 break;
13060 }
1d187b34 13061 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 13062 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
13063
13064 if (CHIP_IS_E3(bp)) {
13065 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
13066 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13067 int path = BP_PATH(bp);
13068 int port = BP_PORT(bp);
13069 int i;
13070 u32 scratch_offset;
13071 u32 *host_addr;
1d187b34 13072
2e499d3c 13073 /* first write capability to shmem2 */
1d187b34
BW
13074 if (ulp_type == CNIC_ULP_ISCSI)
13075 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13076 else if (ulp_type == CNIC_ULP_FCOE)
13077 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13078 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
13079
13080 if ((ulp_type != CNIC_ULP_FCOE) ||
13081 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13082 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13083 break;
13084
13085 /* if reached here - should write fcoe capabilities */
13086 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13087 if (!scratch_offset)
13088 break;
13089 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13090 fcoe_features[path][port]);
13091 host_addr = (u32 *) &(ctl->data.register_data.
13092 fcoe_features);
13093 for (i = 0; i < sizeof(struct fcoe_capabilities);
13094 i += 4)
13095 REG_WR(bp, scratch_offset + i,
13096 *(host_addr + i/4));
1d187b34
BW
13097 }
13098 break;
13099 }
2e499d3c 13100
1d187b34
BW
13101 case DRV_CTL_ULP_UNREGISTER_CMD: {
13102 int ulp_type = ctl->data.ulp_type;
13103
13104 if (CHIP_IS_E3(bp)) {
13105 int idx = BP_FW_MB_IDX(bp);
13106 u32 cap;
13107
13108 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13109 if (ulp_type == CNIC_ULP_ISCSI)
13110 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13111 else if (ulp_type == CNIC_ULP_FCOE)
13112 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13113 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13114 }
13115 break;
13116 }
993ac7b5
MC
13117
13118 default:
13119 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13120 rc = -EINVAL;
13121 }
13122
13123 return rc;
13124}
13125
9f6c9258 13126void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
13127{
13128 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13129
13130 if (bp->flags & USING_MSIX_FLAG) {
13131 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13132 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13133 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13134 } else {
13135 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13136 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13137 }
619c5cb6 13138 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
13139 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13140 else
13141 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13142
619c5cb6
VZ
13143 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13144 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
13145 cp->irq_arr[1].status_blk = bp->def_status_blk;
13146 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 13147 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
13148
13149 cp->num_irq = 2;
13150}
13151
37ae41a9
MS
13152void bnx2x_setup_cnic_info(struct bnx2x *bp)
13153{
13154 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13155
13156
13157 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13158 bnx2x_cid_ilt_lines(bp);
13159 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13160 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13161 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13162
13163 if (NO_ISCSI_OOO(bp))
13164 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13165}
13166
993ac7b5
MC
13167static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13168 void *data)
13169{
13170 struct bnx2x *bp = netdev_priv(dev);
13171 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
13172 int rc;
13173
13174 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 13175
51c1a580
MS
13176 if (ops == NULL) {
13177 BNX2X_ERR("NULL ops received\n");
993ac7b5 13178 return -EINVAL;
51c1a580 13179 }
993ac7b5 13180
55c11941
MS
13181 if (!CNIC_SUPPORT(bp)) {
13182 BNX2X_ERR("Can't register CNIC when not supported\n");
13183 return -EOPNOTSUPP;
13184 }
13185
13186 if (!CNIC_LOADED(bp)) {
13187 rc = bnx2x_load_cnic(bp);
13188 if (rc) {
13189 BNX2X_ERR("CNIC-related load failed\n");
13190 return rc;
13191 }
13192
13193 }
13194
13195 bp->cnic_enabled = true;
13196
993ac7b5
MC
13197 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13198 if (!bp->cnic_kwq)
13199 return -ENOMEM;
13200
13201 bp->cnic_kwq_cons = bp->cnic_kwq;
13202 bp->cnic_kwq_prod = bp->cnic_kwq;
13203 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13204
13205 bp->cnic_spq_pending = 0;
13206 bp->cnic_kwq_pending = 0;
13207
13208 bp->cnic_data = data;
13209
13210 cp->num_irq = 0;
619c5cb6 13211 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 13212 cp->iro_arr = bp->iro_arr;
993ac7b5 13213
993ac7b5 13214 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 13215
993ac7b5
MC
13216 rcu_assign_pointer(bp->cnic_ops, ops);
13217
13218 return 0;
13219}
13220
13221static int bnx2x_unregister_cnic(struct net_device *dev)
13222{
13223 struct bnx2x *bp = netdev_priv(dev);
13224 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13225
13226 mutex_lock(&bp->cnic_mutex);
993ac7b5 13227 cp->drv_state = 0;
2cfa5a04 13228 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
13229 mutex_unlock(&bp->cnic_mutex);
13230 synchronize_rcu();
13231 kfree(bp->cnic_kwq);
13232 bp->cnic_kwq = NULL;
13233
13234 return 0;
13235}
13236
13237struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13238{
13239 struct bnx2x *bp = netdev_priv(dev);
13240 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13241
2ba45142
VZ
13242 /* If both iSCSI and FCoE are disabled - return NULL in
13243 * order to indicate CNIC that it should not try to work
13244 * with this device.
13245 */
13246 if (NO_ISCSI(bp) && NO_FCOE(bp))
13247 return NULL;
13248
993ac7b5
MC
13249 cp->drv_owner = THIS_MODULE;
13250 cp->chip_id = CHIP_ID(bp);
13251 cp->pdev = bp->pdev;
13252 cp->io_base = bp->regview;
13253 cp->io_base2 = bp->doorbells;
13254 cp->max_kwqe_pending = 8;
523224a3 13255 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
13256 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13257 bnx2x_cid_ilt_lines(bp);
993ac7b5 13258 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 13259 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
13260 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13261 cp->drv_ctl = bnx2x_drv_ctl;
13262 cp->drv_register_cnic = bnx2x_register_cnic;
13263 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 13264 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
13265 cp->iscsi_l2_client_id =
13266 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 13267 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 13268
2ba45142
VZ
13269 if (NO_ISCSI_OOO(bp))
13270 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13271
13272 if (NO_ISCSI(bp))
13273 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13274
13275 if (NO_FCOE(bp))
13276 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13277
51c1a580
MS
13278 BNX2X_DEV_INFO(
13279 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13280 cp->ctx_blk_size,
13281 cp->ctx_tbl_offset,
13282 cp->ctx_tbl_len,
13283 cp->starting_cid);
993ac7b5
MC
13284 return cp;
13285}
993ac7b5 13286
be1f1ffa
AE
13287int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
13288{
13289 struct cstorm_vf_zone_data __iomem *zone_data =
13290 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
13291 int tout = 600, interval = 100; /* wait for 60 seconds */
13292
13293 if (*done) {
13294 BNX2X_ERR("done was non zero before message to pf was sent\n");
13295 WARN_ON(true);
13296 return -EINVAL;
13297 }
13298
13299 /* Write message address */
13300 writel(U64_LO(msg_mapping),
13301 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
13302 writel(U64_HI(msg_mapping),
13303 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
13304
13305 /* make sure the address is written before FW accesses it */
13306 wmb();
13307
13308 /* Trigger the PF FW */
13309 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
13310
13311 /* Wait for PF to complete */
13312 while ((tout >= 0) && (!*done)) {
13313 msleep(interval);
13314 tout -= 1;
13315
13316 /* progress indicator - HV can take its own sweet time in
13317 * answering VFs...
13318 */
13319 DP_CONT(BNX2X_MSG_IOV, ".");
13320 }
13321
13322 if (!*done) {
13323 BNX2X_ERR("PF response has timed out\n");
13324 return -EAGAIN;
13325 }
13326 DP(BNX2X_MSG_SP, "Got a response from PF\n");
13327 return 0;
13328}
13329
13330int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
13331{
13332 u32 me_reg;
13333 int tout = 10, interval = 100; /* Wait for 1 sec */
13334
13335 do {
13336 /* pxp traps vf read of doorbells and returns me reg value */
13337 me_reg = readl(bp->doorbells);
13338 if (GOOD_ME_REG(me_reg))
13339 break;
13340
13341 msleep(interval);
13342
13343 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
13344 me_reg);
13345 } while (tout-- > 0);
13346
13347 if (!GOOD_ME_REG(me_reg)) {
13348 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
13349 return -EINVAL;
13350 }
13351
13352 BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
13353
13354 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
94a78b79 13355
be1f1ffa
AE
13356 return 0;
13357}
13358
13359int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
13360{
13361 int rc = 0, attempts = 0;
13362 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
13363 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
13364 u32 vf_id;
13365 bool resources_acquired = false;
13366
13367 /* clear mailbox and prep first tlv */
13368 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
13369
13370 if (bnx2x_get_vf_id(bp, &vf_id))
13371 return -EAGAIN;
13372
13373 req->vfdev_info.vf_id = vf_id;
13374 req->vfdev_info.vf_os = 0;
13375
13376 req->resc_request.num_rxqs = rx_count;
13377 req->resc_request.num_txqs = tx_count;
13378 req->resc_request.num_sbs = bp->igu_sb_cnt;
13379 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
13380 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
13381
13382 /* add list termination tlv */
13383 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13384 sizeof(struct channel_list_end_tlv));
13385
13386 /* output tlvs list */
13387 bnx2x_dp_tlv_list(bp, req);
13388
13389 while (!resources_acquired) {
13390 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
13391
13392 /* send acquire request */
13393 rc = bnx2x_send_msg2pf(bp,
13394 &resp->hdr.status,
13395 bp->vf2pf_mbox_mapping);
13396
13397 /* PF timeout */
13398 if (rc)
13399 return rc;
13400
13401 /* copy acquire response from buffer to bp */
13402 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
13403
13404 attempts++;
13405
13406 /* test whether the PF accepted our request. If not, humble the
13407 * the request and try again.
13408 */
13409 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
13410 DP(BNX2X_MSG_SP, "resources acquired\n");
13411 resources_acquired = true;
13412 } else if (bp->acquire_resp.hdr.status ==
13413 PFVF_STATUS_NO_RESOURCE &&
13414 attempts < VF_ACQUIRE_THRESH) {
13415 DP(BNX2X_MSG_SP,
13416 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
13417
13418 /* humble our request */
13419 req->resc_request.num_txqs =
13420 bp->acquire_resp.resc.num_txqs;
13421 req->resc_request.num_rxqs =
13422 bp->acquire_resp.resc.num_rxqs;
13423 req->resc_request.num_sbs =
13424 bp->acquire_resp.resc.num_sbs;
13425 req->resc_request.num_mac_filters =
13426 bp->acquire_resp.resc.num_mac_filters;
13427 req->resc_request.num_vlan_filters =
13428 bp->acquire_resp.resc.num_vlan_filters;
13429 req->resc_request.num_mc_filters =
13430 bp->acquire_resp.resc.num_mc_filters;
13431
13432 /* Clear response buffer */
13433 memset(&bp->vf2pf_mbox->resp, 0,
13434 sizeof(union pfvf_tlvs));
13435 } else {
13436 /* PF reports error */
13437 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
13438 bp->acquire_resp.hdr.status);
13439 return -EAGAIN;
13440 }
13441 }
13442
13443 /* get HW info */
13444 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
13445 bp->link_params.chip_id = bp->common.chip_id;
13446 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
13447 bp->common.int_block = INT_BLOCK_IGU;
13448 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
13449 bp->igu_dsb_id = -1;
13450 bp->mf_ov = 0;
13451 bp->mf_mode = 0;
13452 bp->common.flash_size = 0;
13453 bp->flags |=
13454 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
13455 bp->igu_sb_cnt = 1;
13456 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
13457 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
13458 sizeof(bp->fw_ver));
13459
13460 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
13461 memcpy(bp->dev->dev_addr,
13462 bp->acquire_resp.resc.current_mac_addr,
13463 ETH_ALEN);
13464
13465 return 0;
13466}
4513f925
AE
13467
13468int bnx2x_vfpf_release(struct bnx2x *bp)
13469{
13470 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
13471 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13472 u32 rc = 0, vf_id;
13473
13474 /* clear mailbox and prep first tlv */
13475 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
13476
13477 if (bnx2x_get_vf_id(bp, &vf_id))
13478 return -EAGAIN;
13479
13480 req->vf_id = vf_id;
13481
13482 /* add list termination tlv */
13483 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13484 sizeof(struct channel_list_end_tlv));
13485
13486 /* output tlvs list */
13487 bnx2x_dp_tlv_list(bp, req);
13488
13489 /* send release request */
13490 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13491
13492 if (rc)
13493 /* PF timeout */
13494 return rc;
13495 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
13496 /* PF released us */
13497 DP(BNX2X_MSG_SP, "vf released\n");
13498 } else {
13499 /* PF reports error */
13500 BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
13501 resp->hdr.status);
13502 return -EAGAIN;
13503 }
13504
13505 return 0;
13506}
8d9ac297
AE
13507
13508/* Tell PF about SB addresses */
13509int bnx2x_vfpf_init(struct bnx2x *bp)
13510{
13511 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
13512 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13513 int rc, i;
13514
13515 /* clear mailbox and prep first tlv */
13516 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
13517
13518 /* status blocks */
13519 for_each_eth_queue(bp, i)
13520 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
13521 status_blk_mapping);
13522
13523 /* statistics - requests only supports single queue for now */
13524 req->stats_addr = bp->fw_stats_data_mapping +
13525 offsetof(struct bnx2x_fw_stats_data, queue_stats);
13526
13527 /* add list termination tlv */
13528 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13529 sizeof(struct channel_list_end_tlv));
13530
13531 /* output tlvs list */
13532 bnx2x_dp_tlv_list(bp, req);
13533
13534 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13535 if (rc)
13536 return rc;
13537
13538 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13539 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
13540 resp->hdr.status);
13541 return -EAGAIN;
13542 }
13543
13544 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
13545 return 0;
13546}
13547
9b176b6b
AE
13548/* CLOSE VF - opposite to INIT_VF */
13549void bnx2x_vfpf_close_vf(struct bnx2x *bp)
13550{
13551 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
13552 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13553 int i, rc;
13554 u32 vf_id;
13555
13556 /* If we haven't got a valid VF id, there is no sense to
13557 * continue with sending messages
13558 */
13559 if (bnx2x_get_vf_id(bp, &vf_id))
13560 goto free_irq;
13561
13562 /* Close the queues */
13563 for_each_queue(bp, i)
13564 bnx2x_vfpf_teardown_queue(bp, i);
13565
13566 /* clear mailbox and prep first tlv */
13567 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
13568
13569 req->vf_id = vf_id;
13570
13571 /* add list termination tlv */
13572 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13573 sizeof(struct channel_list_end_tlv));
13574
13575 /* output tlvs list */
13576 bnx2x_dp_tlv_list(bp, req);
13577
13578 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13579
13580 if (rc)
13581 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
13582
13583 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
13584 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
13585 resp->hdr.status);
13586
13587free_irq:
13588 /* Disable HW interrupts, NAPI */
13589 bnx2x_netif_stop(bp, 0);
13590 /* Delete all NAPI objects */
13591 bnx2x_del_all_napi(bp);
13592
13593 /* Release IRQs */
13594 bnx2x_free_irq(bp);
13595}
13596
8d9ac297
AE
13597/* ask the pf to open a queue for the vf */
13598int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
13599{
13600 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
13601 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13602 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
13603 u16 tpa_agg_size = 0, flags = 0;
13604 int rc;
13605
13606 /* clear mailbox and prep first tlv */
13607 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
13608
13609 /* select tpa mode to request */
13610 if (!fp->disable_tpa) {
13611 flags |= VFPF_QUEUE_FLG_TPA;
13612 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
13613 if (fp->mode == TPA_MODE_GRO)
13614 flags |= VFPF_QUEUE_FLG_TPA_GRO;
13615 tpa_agg_size = TPA_AGG_SIZE;
13616 }
13617
13618 /* calculate queue flags */
13619 flags |= VFPF_QUEUE_FLG_STATS;
13620 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
13621 flags |= IS_MF_SD(bp) ? VFPF_QUEUE_FLG_OV : 0;
13622 flags |= VFPF_QUEUE_FLG_VLAN;
13623 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
13624
13625 /* Common */
13626 req->vf_qid = fp_idx;
13627 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
13628
13629 /* Rx */
13630 req->rxq.rcq_addr = fp->rx_comp_mapping;
13631 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
13632 req->rxq.rxq_addr = fp->rx_desc_mapping;
13633 req->rxq.sge_addr = fp->rx_sge_mapping;
13634 req->rxq.vf_sb = fp_idx;
13635 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
13636 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
13637 req->rxq.mtu = bp->dev->mtu;
13638 req->rxq.buf_sz = fp->rx_buf_size;
13639 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
13640 req->rxq.tpa_agg_sz = tpa_agg_size;
13641 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
13642 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
13643 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
13644 req->rxq.flags = flags;
13645 req->rxq.drop_flags = 0;
13646 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
13647 req->rxq.stat_id = -1; /* No stats at the moment */
13648
13649 /* Tx */
13650 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
13651 req->txq.vf_sb = fp_idx;
13652 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
13653 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
13654 req->txq.flags = flags;
13655 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
13656
13657 /* add list termination tlv */
13658 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13659 sizeof(struct channel_list_end_tlv));
13660
13661 /* output tlvs list */
13662 bnx2x_dp_tlv_list(bp, req);
13663
13664 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13665 if (rc)
13666 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
13667 fp_idx);
13668
13669 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13670 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
13671 fp_idx, resp->hdr.status);
13672 return -EINVAL;
13673 }
13674 return rc;
13675}
13676
9b176b6b
AE
13677int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
13678{
13679 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
13680 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13681 int rc;
13682
13683 /* clear mailbox and prep first tlv */
13684 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
13685 sizeof(*req));
13686
13687 req->vf_qid = qidx;
13688
13689 /* add list termination tlv */
13690 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13691 sizeof(struct channel_list_end_tlv));
13692
13693 /* output tlvs list */
13694 bnx2x_dp_tlv_list(bp, req);
13695
13696 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13697
13698 if (rc) {
13699 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
13700 rc);
13701 return rc;
13702 }
13703
13704 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13705 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
13706 resp->hdr.status);
13707 return -EINVAL;
13708 }
13709
13710 return 0;
13711}
13712
8d9ac297
AE
13713/* request pf to add a mac for the vf */
13714int bnx2x_vfpf_set_mac(struct bnx2x *bp)
13715{
13716 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
13717 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13718 int rc;
13719
13720 /* clear mailbox and prep first tlv */
13721 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
13722 sizeof(*req));
13723
13724 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
13725 req->vf_qid = 0;
13726 req->n_mac_vlan_filters = 1;
13727 req->filters[0].flags =
13728 VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
13729
13730 /* copy mac from device to request */
13731 memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
13732
13733 /* add list termination tlv */
13734 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13735 sizeof(struct channel_list_end_tlv));
13736
13737 /* output tlvs list */
13738 bnx2x_dp_tlv_list(bp, req);
13739
13740 /* send message to pf */
13741 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13742 if (rc) {
13743 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
13744 return rc;
13745 }
13746
13747 /* PF failed the transaction */
13748 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13749 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
13750 return -EINVAL;
13751 }
13752
13753 return 0;
13754}
381ac16b
AE
13755
13756int bnx2x_vfpf_set_mcast(struct net_device *dev)
13757{
13758 struct bnx2x *bp = netdev_priv(dev);
13759 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
13760 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13761 int rc, i = 0;
13762 struct netdev_hw_addr *ha;
13763
13764 if (bp->state != BNX2X_STATE_OPEN) {
13765 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
13766 return -EINVAL;
13767 }
13768
13769 /* clear mailbox and prep first tlv */
13770 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
13771 sizeof(*req));
13772
13773 /* Get Rx mode requested */
13774 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
13775
13776 netdev_for_each_mc_addr(ha, dev) {
13777 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
13778 bnx2x_mc_addr(ha));
13779 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
13780 i++;
13781 }
13782
13783 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
13784 * addresses tops
13785 */
13786 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
13787 DP(NETIF_MSG_IFUP,
13788 "VF supports not more than %d multicast MAC addresses\n",
13789 PFVF_MAX_MULTICAST_PER_VF);
13790 return -EINVAL;
13791 }
13792
13793 req->n_multicast = i;
13794 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
13795 req->vf_qid = 0;
13796
13797 /* add list termination tlv */
13798 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13799 sizeof(struct channel_list_end_tlv));
13800
13801 /* output tlvs list */
13802 bnx2x_dp_tlv_list(bp, req);
13803
13804 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13805 if (rc) {
13806 BNX2X_ERR("Sending a message failed: %d\n", rc);
13807 return rc;
13808 }
13809
13810 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13811 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
13812 resp->hdr.status);
13813 return -EINVAL;
13814 }
13815
13816 return 0;
13817}
13818
13819int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
13820{
13821 int mode = bp->rx_mode;
13822 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
13823 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
13824 int rc;
13825
13826 /* clear mailbox and prep first tlv */
13827 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
13828 sizeof(*req));
13829
13830 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
13831
13832 switch (mode) {
13833 case BNX2X_RX_MODE_NONE: /* no Rx */
13834 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
13835 break;
13836 case BNX2X_RX_MODE_NORMAL:
13837 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
13838 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
13839 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
13840 break;
13841 case BNX2X_RX_MODE_ALLMULTI:
13842 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
13843 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
13844 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
13845 break;
13846 case BNX2X_RX_MODE_PROMISC:
13847 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
13848 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
13849 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
13850 break;
13851 default:
13852 BNX2X_ERR("BAD rx mode (%d)\n", mode);
13853 return -EINVAL;
13854 }
13855
13856 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
13857 req->vf_qid = 0;
13858
13859 /* add list termination tlv */
13860 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
13861 sizeof(struct channel_list_end_tlv));
13862
13863 /* output tlvs list */
13864 bnx2x_dp_tlv_list(bp, req);
13865
13866 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
13867 if (rc)
13868 BNX2X_ERR("Sending a message failed: %d\n", rc);
13869
13870 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
13871 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
13872 return -EINVAL;
13873 }
13874
13875 return rc;
13876}