]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
vmxnet3: use initialized skb pointer to set hash
[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 *
247fa82b 3 * Copyright (c) 2007-2013 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>
33d8e6a5 30#include <linux/aer.h>
a2fbb9ea
ET
31#include <linux/init.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/skbuff.h>
35#include <linux/dma-mapping.h>
36#include <linux/bitops.h>
37#include <linux/irq.h>
38#include <linux/delay.h>
39#include <asm/byteorder.h>
40#include <linux/time.h>
41#include <linux/ethtool.h>
42#include <linux/mii.h>
0c6671b0 43#include <linux/if_vlan.h>
a2fbb9ea 44#include <net/ip.h>
619c5cb6 45#include <net/ipv6.h>
a2fbb9ea
ET
46#include <net/tcp.h>
47#include <net/checksum.h>
34f80b04 48#include <net/ip6_checksum.h>
a2fbb9ea
ET
49#include <linux/workqueue.h>
50#include <linux/crc32.h>
34f80b04 51#include <linux/crc32c.h>
a2fbb9ea
ET
52#include <linux/prefetch.h>
53#include <linux/zlib.h>
a2fbb9ea 54#include <linux/io.h>
452427b0 55#include <linux/semaphore.h>
45229b42 56#include <linux/stringify.h>
7ab24bfd 57#include <linux/vmalloc.h>
a2fbb9ea 58
a2fbb9ea
ET
59#include "bnx2x.h"
60#include "bnx2x_init.h"
94a78b79 61#include "bnx2x_init_ops.h"
9f6c9258 62#include "bnx2x_cmn.h"
1ab4434c 63#include "bnx2x_vfpf.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
34f80b04
EG
79/* Time in jiffies before concluding the transmitter is hung */
80#define TX_TIMEOUT (5*HZ)
a2fbb9ea 81
0329aba1 82static char version[] =
619c5cb6 83 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
84 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
85
24e3fcef 86MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 87MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
88 "BCM57710/57711/57711E/"
89 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
90 "57840/57840_MF Driver");
a2fbb9ea
ET
91MODULE_LICENSE("GPL");
92MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
93MODULE_FIRMWARE(FW_FILE_NAME_E1);
94MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 95MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 96
d6214d7a 97int num_queues;
54b9ddaa 98module_param(num_queues, int, 0);
96305234
DK
99MODULE_PARM_DESC(num_queues,
100 " Set number of queues (default is as a number of CPUs)");
555f6c78 101
19680c48 102static int disable_tpa;
19680c48 103module_param(disable_tpa, int, 0);
9898f86d 104MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 105
0e8d2ec5 106int int_mode;
8badd27a 107module_param(int_mode, int, 0);
619c5cb6 108MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 109 "(1 INT#x; 2 MSI)");
8badd27a 110
a18f5128
EG
111static int dropless_fc;
112module_param(dropless_fc, int, 0);
113MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
114
8d5726c4
EG
115static int mrrs = -1;
116module_param(mrrs, int, 0);
117MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
118
9898f86d 119static int debug;
a2fbb9ea 120module_param(debug, int, 0);
9898f86d
EG
121MODULE_PARM_DESC(debug, " Default debug msglevel");
122
619c5cb6 123struct workqueue_struct *bnx2x_wq;
ec6ba945 124
1ef1d45a
BW
125struct bnx2x_mac_vals {
126 u32 xmac_addr;
127 u32 xmac_val;
128 u32 emac_addr;
129 u32 emac_val;
130 u32 umac_addr;
131 u32 umac_val;
132 u32 bmac_addr;
133 u32 bmac_val[2];
134};
135
a2fbb9ea
ET
136enum bnx2x_board_type {
137 BCM57710 = 0,
619c5cb6
VZ
138 BCM57711,
139 BCM57711E,
140 BCM57712,
141 BCM57712_MF,
1ab4434c 142 BCM57712_VF,
619c5cb6
VZ
143 BCM57800,
144 BCM57800_MF,
1ab4434c 145 BCM57800_VF,
619c5cb6
VZ
146 BCM57810,
147 BCM57810_MF,
1ab4434c 148 BCM57810_VF,
c3def943
YM
149 BCM57840_4_10,
150 BCM57840_2_20,
7e8e02df 151 BCM57840_MF,
1ab4434c 152 BCM57840_VF,
7e8e02df 153 BCM57811,
1ab4434c
AE
154 BCM57811_MF,
155 BCM57840_O,
156 BCM57840_MFO,
157 BCM57811_VF
a2fbb9ea
ET
158};
159
34f80b04 160/* indexed by board_type, above */
53a10565 161static struct {
a2fbb9ea 162 char *name;
0329aba1 163} board_info[] = {
1ab4434c
AE
164 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
165 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
166 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
167 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
168 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
169 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
170 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
171 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
172 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
173 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
174 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
175 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
176 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
177 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
178 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
179 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
180 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
181 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
182 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
183 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
184 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
a2fbb9ea
ET
185};
186
619c5cb6
VZ
187#ifndef PCI_DEVICE_ID_NX2_57710
188#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
189#endif
190#ifndef PCI_DEVICE_ID_NX2_57711
191#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
192#endif
193#ifndef PCI_DEVICE_ID_NX2_57711E
194#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
195#endif
196#ifndef PCI_DEVICE_ID_NX2_57712
197#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
198#endif
199#ifndef PCI_DEVICE_ID_NX2_57712_MF
200#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
201#endif
8395be5e
AE
202#ifndef PCI_DEVICE_ID_NX2_57712_VF
203#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
204#endif
619c5cb6
VZ
205#ifndef PCI_DEVICE_ID_NX2_57800
206#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
207#endif
208#ifndef PCI_DEVICE_ID_NX2_57800_MF
209#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
210#endif
8395be5e
AE
211#ifndef PCI_DEVICE_ID_NX2_57800_VF
212#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
213#endif
619c5cb6
VZ
214#ifndef PCI_DEVICE_ID_NX2_57810
215#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
216#endif
217#ifndef PCI_DEVICE_ID_NX2_57810_MF
218#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
219#endif
c3def943
YM
220#ifndef PCI_DEVICE_ID_NX2_57840_O
221#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
222#endif
8395be5e
AE
223#ifndef PCI_DEVICE_ID_NX2_57810_VF
224#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
225#endif
c3def943
YM
226#ifndef PCI_DEVICE_ID_NX2_57840_4_10
227#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
228#endif
229#ifndef PCI_DEVICE_ID_NX2_57840_2_20
230#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
231#endif
232#ifndef PCI_DEVICE_ID_NX2_57840_MFO
233#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
619c5cb6
VZ
234#endif
235#ifndef PCI_DEVICE_ID_NX2_57840_MF
236#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
237#endif
8395be5e
AE
238#ifndef PCI_DEVICE_ID_NX2_57840_VF
239#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
240#endif
7e8e02df
BW
241#ifndef PCI_DEVICE_ID_NX2_57811
242#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
243#endif
244#ifndef PCI_DEVICE_ID_NX2_57811_MF
245#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
246#endif
8395be5e
AE
247#ifndef PCI_DEVICE_ID_NX2_57811_VF
248#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
249#endif
250
a3aa1884 251static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
252 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6 256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
8395be5e 257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
619c5cb6
VZ
258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
8395be5e 260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
619c5cb6
VZ
261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
c3def943
YM
263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
8395be5e 266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
c3def943 267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
619c5cb6 268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
8395be5e 269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
7e8e02df
BW
270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
8395be5e 272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
a2fbb9ea
ET
273 { 0 }
274};
275
276MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
277
452427b0
YM
278/* Global resources for unloading a previously loaded device */
279#define BNX2X_PREV_WAIT_NEEDED 1
280static DEFINE_SEMAPHORE(bnx2x_prev_sem);
281static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
282/****************************************************************************
283* General service functions
284****************************************************************************/
285
1191cb83 286static void __storm_memset_dma_mapping(struct bnx2x *bp,
619c5cb6
VZ
287 u32 addr, dma_addr_t mapping)
288{
289 REG_WR(bp, addr, U64_LO(mapping));
290 REG_WR(bp, addr + 4, U64_HI(mapping));
291}
292
1191cb83
ED
293static void storm_memset_spq_addr(struct bnx2x *bp,
294 dma_addr_t mapping, u16 abs_fid)
619c5cb6
VZ
295{
296 u32 addr = XSEM_REG_FAST_MEMORY +
297 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
298
299 __storm_memset_dma_mapping(bp, addr, mapping);
300}
301
1191cb83
ED
302static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
303 u16 pf_id)
523224a3 304{
619c5cb6
VZ
305 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
306 pf_id);
307 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
308 pf_id);
309 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
310 pf_id);
311 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
312 pf_id);
523224a3
DK
313}
314
1191cb83
ED
315static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
316 u8 enable)
619c5cb6
VZ
317{
318 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
319 enable);
320 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
321 enable);
322 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
323 enable);
324 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
325 enable);
326}
523224a3 327
1191cb83
ED
328static void storm_memset_eq_data(struct bnx2x *bp,
329 struct event_ring_data *eq_data,
523224a3
DK
330 u16 pfid)
331{
332 size_t size = sizeof(struct event_ring_data);
333
334 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
335
336 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
337}
338
1191cb83
ED
339static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
340 u16 pfid)
523224a3
DK
341{
342 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
343 REG_WR16(bp, addr, eq_prod);
344}
345
a2fbb9ea
ET
346/* used only at init
347 * locking is done by mcp
348 */
8d96286a 349static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
350{
351 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
352 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
353 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
354 PCICFG_VENDOR_ID_OFFSET);
355}
356
a2fbb9ea
ET
357static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
358{
359 u32 val;
360
361 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
362 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
363 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
364 PCICFG_VENDOR_ID_OFFSET);
365
366 return val;
367}
a2fbb9ea 368
f2e0899f
DK
369#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
370#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
371#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
372#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
373#define DMAE_DP_DST_NONE "dst_addr [none]"
374
6bf07b8e
YM
375static void bnx2x_dp_dmae(struct bnx2x *bp,
376 struct dmae_command *dmae, int msglvl)
fd1fc79d
AE
377{
378 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
6bf07b8e 379 int i;
fd1fc79d
AE
380
381 switch (dmae->opcode & DMAE_COMMAND_DST) {
382 case DMAE_CMD_DST_PCI:
383 if (src_type == DMAE_CMD_SRC_PCI)
384 DP(msglvl, "DMAE: opcode 0x%08x\n"
385 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
386 "comp_addr [%x:%08x], comp_val 0x%08x\n",
387 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
388 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
389 dmae->comp_addr_hi, dmae->comp_addr_lo,
390 dmae->comp_val);
391 else
392 DP(msglvl, "DMAE: opcode 0x%08x\n"
393 "src [%08x], len [%d*4], dst [%x:%08x]\n"
394 "comp_addr [%x:%08x], comp_val 0x%08x\n",
395 dmae->opcode, dmae->src_addr_lo >> 2,
396 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
397 dmae->comp_addr_hi, dmae->comp_addr_lo,
398 dmae->comp_val);
399 break;
400 case DMAE_CMD_DST_GRC:
401 if (src_type == DMAE_CMD_SRC_PCI)
402 DP(msglvl, "DMAE: opcode 0x%08x\n"
403 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
404 "comp_addr [%x:%08x], comp_val 0x%08x\n",
405 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
406 dmae->len, dmae->dst_addr_lo >> 2,
407 dmae->comp_addr_hi, dmae->comp_addr_lo,
408 dmae->comp_val);
409 else
410 DP(msglvl, "DMAE: opcode 0x%08x\n"
411 "src [%08x], len [%d*4], dst [%08x]\n"
412 "comp_addr [%x:%08x], comp_val 0x%08x\n",
413 dmae->opcode, dmae->src_addr_lo >> 2,
414 dmae->len, dmae->dst_addr_lo >> 2,
415 dmae->comp_addr_hi, dmae->comp_addr_lo,
416 dmae->comp_val);
417 break;
418 default:
419 if (src_type == DMAE_CMD_SRC_PCI)
420 DP(msglvl, "DMAE: opcode 0x%08x\n"
421 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
422 "comp_addr [%x:%08x] comp_val 0x%08x\n",
423 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
424 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
425 dmae->comp_val);
426 else
427 DP(msglvl, "DMAE: opcode 0x%08x\n"
428 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
429 "comp_addr [%x:%08x] comp_val 0x%08x\n",
430 dmae->opcode, dmae->src_addr_lo >> 2,
431 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
432 dmae->comp_val);
433 break;
434 }
6bf07b8e
YM
435
436 for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
437 DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
438 i, *(((u32 *)dmae) + i));
fd1fc79d 439}
f2e0899f 440
a2fbb9ea 441/* copy command into DMAE command memory and set DMAE command go */
6c719d00 442void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
443{
444 u32 cmd_offset;
445 int i;
446
447 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
448 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
449 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
450 }
451 REG_WR(bp, dmae_reg_go_c[idx], 1);
452}
453
f2e0899f 454u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 455{
f2e0899f
DK
456 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
457 DMAE_CMD_C_ENABLE);
458}
ad8d3948 459
f2e0899f
DK
460u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
461{
462 return opcode & ~DMAE_CMD_SRC_RESET;
463}
ad8d3948 464
f2e0899f
DK
465u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
466 bool with_comp, u8 comp_type)
467{
468 u32 opcode = 0;
469
470 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
471 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 472
f2e0899f
DK
473 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
474
475 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
476 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
477 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 478 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 479
a2fbb9ea 480#ifdef __BIG_ENDIAN
f2e0899f 481 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 482#else
f2e0899f 483 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 484#endif
f2e0899f
DK
485 if (with_comp)
486 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
487 return opcode;
488}
489
fd1fc79d 490void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
8d96286a 491 struct dmae_command *dmae,
492 u8 src_type, u8 dst_type)
f2e0899f
DK
493{
494 memset(dmae, 0, sizeof(struct dmae_command));
495
496 /* set the opcode */
497 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
498 true, DMAE_COMP_PCI);
499
500 /* fill in the completion parameters */
501 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
502 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
503 dmae->comp_val = DMAE_COMP_VAL;
504}
505
fd1fc79d 506/* issue a dmae command over the init-channel and wait for completion */
32316a46
AE
507int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
508 u32 *comp)
f2e0899f 509{
5e374b5a 510 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
511 int rc = 0;
512
6bf07b8e
YM
513 bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
514
515 /* Lock the dmae channel. Disable BHs to prevent a dead-lock
619c5cb6
VZ
516 * as long as this code is called both from syscall context and
517 * from ndo_set_rx_mode() flow that may be called from BH.
518 */
6e30dd4e 519 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 520
f2e0899f 521 /* reset completion */
32316a46 522 *comp = 0;
a2fbb9ea 523
f2e0899f
DK
524 /* post the command on the channel used for initializations */
525 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 526
f2e0899f 527 /* wait for completion */
a2fbb9ea 528 udelay(5);
32316a46 529 while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 530
95c6c616
AE
531 if (!cnt ||
532 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
533 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 534 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
535 rc = DMAE_TIMEOUT;
536 goto unlock;
a2fbb9ea 537 }
ad8d3948 538 cnt--;
f2e0899f 539 udelay(50);
a2fbb9ea 540 }
32316a46 541 if (*comp & DMAE_PCI_ERR_FLAG) {
f2e0899f
DK
542 BNX2X_ERR("DMAE PCI error!\n");
543 rc = DMAE_PCI_ERROR;
544 }
545
f2e0899f 546unlock:
6e30dd4e 547 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
548 return rc;
549}
550
551void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
552 u32 len32)
553{
6bf07b8e 554 int rc;
f2e0899f
DK
555 struct dmae_command dmae;
556
557 if (!bp->dmae_ready) {
558 u32 *data = bnx2x_sp(bp, wb_data[0]);
559
127a425e
AE
560 if (CHIP_IS_E1(bp))
561 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
562 else
563 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
564 return;
565 }
566
567 /* set opcode and fixed command fields */
568 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
569
570 /* fill in addresses and len */
571 dmae.src_addr_lo = U64_LO(dma_addr);
572 dmae.src_addr_hi = U64_HI(dma_addr);
573 dmae.dst_addr_lo = dst_addr >> 2;
574 dmae.dst_addr_hi = 0;
575 dmae.len = len32;
576
f2e0899f 577 /* issue the command and wait for completion */
32316a46 578 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
6bf07b8e
YM
579 if (rc) {
580 BNX2X_ERR("DMAE returned failure %d\n", rc);
9dcd9acd 581#ifdef BNX2X_STOP_ON_ERROR
6bf07b8e 582 bnx2x_panic();
9dcd9acd 583#endif
6bf07b8e 584 }
a2fbb9ea
ET
585}
586
c18487ee 587void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 588{
6bf07b8e 589 int rc;
5ff7b6d4 590 struct dmae_command dmae;
ad8d3948
EG
591
592 if (!bp->dmae_ready) {
593 u32 *data = bnx2x_sp(bp, wb_data[0]);
594 int i;
595
51c1a580 596 if (CHIP_IS_E1(bp))
127a425e
AE
597 for (i = 0; i < len32; i++)
598 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 599 else
127a425e
AE
600 for (i = 0; i < len32; i++)
601 data[i] = REG_RD(bp, src_addr + i*4);
602
ad8d3948
EG
603 return;
604 }
605
f2e0899f
DK
606 /* set opcode and fixed command fields */
607 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 608
f2e0899f 609 /* fill in addresses and len */
5ff7b6d4
EG
610 dmae.src_addr_lo = src_addr >> 2;
611 dmae.src_addr_hi = 0;
612 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
613 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
614 dmae.len = len32;
ad8d3948 615
f2e0899f 616 /* issue the command and wait for completion */
32316a46 617 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
6bf07b8e
YM
618 if (rc) {
619 BNX2X_ERR("DMAE returned failure %d\n", rc);
9dcd9acd 620#ifdef BNX2X_STOP_ON_ERROR
6bf07b8e 621 bnx2x_panic();
9dcd9acd 622#endif
c957d09f 623 }
ad8d3948
EG
624}
625
8d96286a 626static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
627 u32 addr, u32 len)
573f2035 628{
02e3c6cb 629 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
630 int offset = 0;
631
02e3c6cb 632 while (len > dmae_wr_max) {
573f2035 633 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
634 addr + offset, dmae_wr_max);
635 offset += dmae_wr_max * 4;
636 len -= dmae_wr_max;
573f2035
EG
637 }
638
639 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
640}
641
a2fbb9ea
ET
642static int bnx2x_mc_assert(struct bnx2x *bp)
643{
a2fbb9ea 644 char last_idx;
34f80b04
EG
645 int i, rc = 0;
646 u32 row0, row1, row2, row3;
647
648 /* XSTORM */
649 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
650 XSTORM_ASSERT_LIST_INDEX_OFFSET);
651 if (last_idx)
652 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
653
654 /* print the asserts */
655 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
656
657 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
658 XSTORM_ASSERT_LIST_OFFSET(i));
659 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
660 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
661 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
662 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
663 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
664 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
665
666 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 667 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
668 i, row3, row2, row1, row0);
669 rc++;
670 } else {
671 break;
672 }
673 }
674
675 /* TSTORM */
676 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
677 TSTORM_ASSERT_LIST_INDEX_OFFSET);
678 if (last_idx)
679 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
680
681 /* print the asserts */
682 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
683
684 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
685 TSTORM_ASSERT_LIST_OFFSET(i));
686 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
687 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
688 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
689 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
690 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
691 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
692
693 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 694 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
695 i, row3, row2, row1, row0);
696 rc++;
697 } else {
698 break;
699 }
700 }
701
702 /* CSTORM */
703 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
704 CSTORM_ASSERT_LIST_INDEX_OFFSET);
705 if (last_idx)
706 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
707
708 /* print the asserts */
709 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
710
711 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
712 CSTORM_ASSERT_LIST_OFFSET(i));
713 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
714 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
715 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
716 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
717 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
718 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
719
720 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 721 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
722 i, row3, row2, row1, row0);
723 rc++;
724 } else {
725 break;
726 }
727 }
728
729 /* USTORM */
730 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
731 USTORM_ASSERT_LIST_INDEX_OFFSET);
732 if (last_idx)
733 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
734
735 /* print the asserts */
736 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
737
738 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
739 USTORM_ASSERT_LIST_OFFSET(i));
740 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
741 USTORM_ASSERT_LIST_OFFSET(i) + 4);
742 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
743 USTORM_ASSERT_LIST_OFFSET(i) + 8);
744 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
745 USTORM_ASSERT_LIST_OFFSET(i) + 12);
746
747 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 748 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
749 i, row3, row2, row1, row0);
750 rc++;
751 } else {
752 break;
a2fbb9ea
ET
753 }
754 }
34f80b04 755
a2fbb9ea
ET
756 return rc;
757}
c14423fe 758
1a6974b2
YM
759#define MCPR_TRACE_BUFFER_SIZE (0x800)
760#define SCRATCH_BUFFER_SIZE(bp) \
761 (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
762
7a25cc73 763void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 764{
7a25cc73 765 u32 addr, val;
a2fbb9ea 766 u32 mark, offset;
4781bfad 767 __be32 data[9];
a2fbb9ea 768 int word;
f2e0899f 769 u32 trace_shmem_base;
2145a920
VZ
770 if (BP_NOMCP(bp)) {
771 BNX2X_ERR("NO MCP - can not dump\n");
772 return;
773 }
7a25cc73
DK
774 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
775 (bp->common.bc_ver & 0xff0000) >> 16,
776 (bp->common.bc_ver & 0xff00) >> 8,
777 (bp->common.bc_ver & 0xff));
778
779 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
780 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 781 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 782
f2e0899f
DK
783 if (BP_PATH(bp) == 0)
784 trace_shmem_base = bp->common.shmem_base;
785 else
786 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
1a6974b2
YM
787
788 /* sanity */
789 if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
790 trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
791 SCRATCH_BUFFER_SIZE(bp)) {
792 BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
793 trace_shmem_base);
794 return;
795 }
796
797 addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
de128804
DK
798
799 /* validate TRCB signature */
800 mark = REG_RD(bp, addr);
801 if (mark != MFW_TRACE_SIGNATURE) {
802 BNX2X_ERR("Trace buffer signature is missing.");
803 return ;
804 }
805
806 /* read cyclic buffer pointer */
807 addr += 4;
cdaa7cb8 808 mark = REG_RD(bp, addr);
1a6974b2
YM
809 mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
810 if (mark >= trace_shmem_base || mark < addr + 4) {
811 BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
812 return;
813 }
7a25cc73 814 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 815
7a25cc73 816 printk("%s", lvl);
2de67439
YM
817
818 /* dump buffer after the mark */
1a6974b2 819 for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 820 for (word = 0; word < 8; word++)
cdaa7cb8 821 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 822 data[8] = 0x0;
7995c64e 823 pr_cont("%s", (char *)data);
a2fbb9ea 824 }
2de67439
YM
825
826 /* dump buffer before the mark */
cdaa7cb8 827 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 828 for (word = 0; word < 8; word++)
cdaa7cb8 829 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 830 data[8] = 0x0;
7995c64e 831 pr_cont("%s", (char *)data);
a2fbb9ea 832 }
7a25cc73
DK
833 printk("%s" "end of fw dump\n", lvl);
834}
835
1191cb83 836static void bnx2x_fw_dump(struct bnx2x *bp)
7a25cc73
DK
837{
838 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
839}
840
823e1d90
YM
841static void bnx2x_hc_int_disable(struct bnx2x *bp)
842{
843 int port = BP_PORT(bp);
844 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
845 u32 val = REG_RD(bp, addr);
846
847 /* in E1 we must use only PCI configuration space to disable
16a5fd92
YM
848 * MSI/MSIX capability
849 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
823e1d90
YM
850 */
851 if (CHIP_IS_E1(bp)) {
852 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
853 * Use mask register to prevent from HC sending interrupts
854 * after we exit the function
855 */
856 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
857
858 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
859 HC_CONFIG_0_REG_INT_LINE_EN_0 |
860 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
861 } else
862 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
863 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
864 HC_CONFIG_0_REG_INT_LINE_EN_0 |
865 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
866
867 DP(NETIF_MSG_IFDOWN,
868 "write %x to HC %d (addr 0x%x)\n",
869 val, port, addr);
870
871 /* flush all outstanding writes */
872 mmiowb();
873
874 REG_WR(bp, addr, val);
875 if (REG_RD(bp, addr) != val)
6bf07b8e 876 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
823e1d90
YM
877}
878
879static void bnx2x_igu_int_disable(struct bnx2x *bp)
880{
881 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
882
883 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
884 IGU_PF_CONF_INT_LINE_EN |
885 IGU_PF_CONF_ATTN_BIT_EN);
886
887 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
888
889 /* flush all outstanding writes */
890 mmiowb();
891
892 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
893 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
6bf07b8e 894 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
823e1d90
YM
895}
896
897static void bnx2x_int_disable(struct bnx2x *bp)
898{
899 if (bp->common.int_block == INT_BLOCK_HC)
900 bnx2x_hc_int_disable(bp);
901 else
902 bnx2x_igu_int_disable(bp);
903}
904
905void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
a2fbb9ea
ET
906{
907 int i;
523224a3
DK
908 u16 j;
909 struct hc_sp_status_block_data sp_sb_data;
910 int func = BP_FUNC(bp);
911#ifdef BNX2X_STOP_ON_ERROR
912 u16 start = 0, end = 0;
6383c0b3 913 u8 cos;
523224a3 914#endif
823e1d90
YM
915 if (disable_int)
916 bnx2x_int_disable(bp);
a2fbb9ea 917
66e855f3 918 bp->stats_state = STATS_STATE_DISABLED;
7a752993 919 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
920 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
921
a2fbb9ea
ET
922 BNX2X_ERR("begin crash dump -----------------\n");
923
8440d2b6
EG
924 /* Indices */
925 /* Common */
51c1a580 926 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
927 bp->def_idx, bp->def_att_idx, bp->attn_state,
928 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
929 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
930 bp->def_status_blk->atten_status_block.attn_bits,
931 bp->def_status_blk->atten_status_block.attn_bits_ack,
932 bp->def_status_blk->atten_status_block.status_block_id,
933 bp->def_status_blk->atten_status_block.attn_bits_index);
934 BNX2X_ERR(" def (");
935 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
936 pr_cont("0x%x%s",
f1deab50
JP
937 bp->def_status_blk->sp_sb.index_values[i],
938 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
939
940 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
941 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
942 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
943 i*sizeof(u32));
944
f1deab50 945 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
946 sp_sb_data.igu_sb_id,
947 sp_sb_data.igu_seg_id,
948 sp_sb_data.p_func.pf_id,
949 sp_sb_data.p_func.vnic_id,
950 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
951 sp_sb_data.p_func.vf_valid,
952 sp_sb_data.state);
523224a3 953
ec6ba945 954 for_each_eth_queue(bp, i) {
a2fbb9ea 955 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 956 int loop;
f2e0899f 957 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
958 struct hc_status_block_data_e1x sb_data_e1x;
959 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
960 CHIP_IS_E1x(bp) ?
961 sb_data_e1x.common.state_machine :
962 sb_data_e2.common.state_machine;
523224a3 963 struct hc_index_data *hc_index_p =
619c5cb6
VZ
964 CHIP_IS_E1x(bp) ?
965 sb_data_e1x.index_data :
966 sb_data_e2.index_data;
6383c0b3 967 u8 data_size, cos;
523224a3 968 u32 *sb_data_p;
6383c0b3 969 struct bnx2x_fp_txdata txdata;
523224a3
DK
970
971 /* Rx */
51c1a580 972 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 973 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 974 fp->rx_comp_prod,
66e855f3 975 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 976 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 977 fp->rx_sge_prod, fp->last_max_sge,
523224a3 978 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 979
523224a3 980 /* Tx */
6383c0b3
AE
981 for_each_cos_in_tx_queue(fp, cos)
982 {
65565884 983 txdata = *fp->txdata_ptr[cos];
51c1a580 984 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
985 i, txdata.tx_pkt_prod,
986 txdata.tx_pkt_cons, txdata.tx_bd_prod,
987 txdata.tx_bd_cons,
988 le16_to_cpu(*txdata.tx_cons_sb));
989 }
523224a3 990
619c5cb6
VZ
991 loop = CHIP_IS_E1x(bp) ?
992 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
993
994 /* host sb data */
995
ec6ba945
VZ
996 if (IS_FCOE_FP(fp))
997 continue;
55c11941 998
523224a3
DK
999 BNX2X_ERR(" run indexes (");
1000 for (j = 0; j < HC_SB_MAX_SM; j++)
1001 pr_cont("0x%x%s",
1002 fp->sb_running_index[j],
1003 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
1004
1005 BNX2X_ERR(" indexes (");
1006 for (j = 0; j < loop; j++)
1007 pr_cont("0x%x%s",
1008 fp->sb_index_values[j],
1009 (j == loop - 1) ? ")" : " ");
1010 /* fw sb data */
619c5cb6
VZ
1011 data_size = CHIP_IS_E1x(bp) ?
1012 sizeof(struct hc_status_block_data_e1x) :
1013 sizeof(struct hc_status_block_data_e2);
523224a3 1014 data_size /= sizeof(u32);
619c5cb6
VZ
1015 sb_data_p = CHIP_IS_E1x(bp) ?
1016 (u32 *)&sb_data_e1x :
1017 (u32 *)&sb_data_e2;
523224a3
DK
1018 /* copy sb data in here */
1019 for (j = 0; j < data_size; j++)
1020 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
1021 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
1022 j * sizeof(u32));
1023
619c5cb6 1024 if (!CHIP_IS_E1x(bp)) {
51c1a580 1025 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
1026 sb_data_e2.common.p_func.pf_id,
1027 sb_data_e2.common.p_func.vf_id,
1028 sb_data_e2.common.p_func.vf_valid,
1029 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
1030 sb_data_e2.common.same_igu_sb_1b,
1031 sb_data_e2.common.state);
f2e0899f 1032 } else {
51c1a580 1033 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
1034 sb_data_e1x.common.p_func.pf_id,
1035 sb_data_e1x.common.p_func.vf_id,
1036 sb_data_e1x.common.p_func.vf_valid,
1037 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
1038 sb_data_e1x.common.same_igu_sb_1b,
1039 sb_data_e1x.common.state);
f2e0899f 1040 }
523224a3
DK
1041
1042 /* SB_SMs data */
1043 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
1044 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",
1045 j, hc_sm_p[j].__flags,
1046 hc_sm_p[j].igu_sb_id,
1047 hc_sm_p[j].igu_seg_id,
1048 hc_sm_p[j].time_to_expire,
1049 hc_sm_p[j].timer_value);
523224a3
DK
1050 }
1051
16a5fd92 1052 /* Indices data */
523224a3 1053 for (j = 0; j < loop; j++) {
51c1a580 1054 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
1055 hc_index_p[j].flags,
1056 hc_index_p[j].timeout);
1057 }
8440d2b6 1058 }
a2fbb9ea 1059
523224a3 1060#ifdef BNX2X_STOP_ON_ERROR
04c46736
YM
1061
1062 /* event queue */
6bf07b8e 1063 BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
04c46736
YM
1064 for (i = 0; i < NUM_EQ_DESC; i++) {
1065 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
1066
1067 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1068 i, bp->eq_ring[i].message.opcode,
1069 bp->eq_ring[i].message.error);
1070 BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
1071 }
1072
8440d2b6
EG
1073 /* Rings */
1074 /* Rx */
55c11941 1075 for_each_valid_rx_queue(bp, i) {
8440d2b6 1076 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
1077
1078 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1079 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 1080 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
1081 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1082 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1083
c3eefaf6 1084 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 1085 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
1086 }
1087
3196a88a
EG
1088 start = RX_SGE(fp->rx_sge_prod);
1089 end = RX_SGE(fp->last_max_sge);
8440d2b6 1090 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
1091 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1092 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1093
c3eefaf6
EG
1094 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1095 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
1096 }
1097
a2fbb9ea
ET
1098 start = RCQ_BD(fp->rx_comp_cons - 10);
1099 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 1100 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
1101 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1102
c3eefaf6
EG
1103 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1104 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
1105 }
1106 }
1107
8440d2b6 1108 /* Tx */
55c11941 1109 for_each_valid_tx_queue(bp, i) {
8440d2b6 1110 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3 1111 for_each_cos_in_tx_queue(fp, cos) {
65565884 1112 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
6383c0b3
AE
1113
1114 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1115 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1116 for (j = start; j != end; j = TX_BD(j + 1)) {
1117 struct sw_tx_bd *sw_bd =
1118 &txdata->tx_buf_ring[j];
1119
51c1a580 1120 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
1121 i, cos, j, sw_bd->skb,
1122 sw_bd->first_bd);
1123 }
8440d2b6 1124
6383c0b3
AE
1125 start = TX_BD(txdata->tx_bd_cons - 10);
1126 end = TX_BD(txdata->tx_bd_cons + 254);
1127 for (j = start; j != end; j = TX_BD(j + 1)) {
1128 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 1129
51c1a580 1130 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
1131 i, cos, j, tx_bd[0], tx_bd[1],
1132 tx_bd[2], tx_bd[3]);
1133 }
8440d2b6
EG
1134 }
1135 }
523224a3 1136#endif
34f80b04 1137 bnx2x_fw_dump(bp);
a2fbb9ea
ET
1138 bnx2x_mc_assert(bp);
1139 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
1140}
1141
619c5cb6
VZ
1142/*
1143 * FLR Support for E2
1144 *
1145 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1146 * initialization.
1147 */
16a5fd92 1148#define FLR_WAIT_USEC 10000 /* 10 milliseconds */
89db4ad8
AE
1149#define FLR_WAIT_INTERVAL 50 /* usec */
1150#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
1151
1152struct pbf_pN_buf_regs {
1153 int pN;
1154 u32 init_crd;
1155 u32 crd;
1156 u32 crd_freed;
1157};
1158
1159struct pbf_pN_cmd_regs {
1160 int pN;
1161 u32 lines_occup;
1162 u32 lines_freed;
1163};
1164
1165static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1166 struct pbf_pN_buf_regs *regs,
1167 u32 poll_count)
1168{
1169 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1170 u32 cur_cnt = poll_count;
1171
1172 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1173 crd = crd_start = REG_RD(bp, regs->crd);
1174 init_crd = REG_RD(bp, regs->init_crd);
1175
1176 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1177 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1178 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1179
1180 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1181 (init_crd - crd_start))) {
1182 if (cur_cnt--) {
89db4ad8 1183 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1184 crd = REG_RD(bp, regs->crd);
1185 crd_freed = REG_RD(bp, regs->crd_freed);
1186 } else {
1187 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1188 regs->pN);
1189 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1190 regs->pN, crd);
1191 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1192 regs->pN, crd_freed);
1193 break;
1194 }
1195 }
1196 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 1197 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1198}
1199
1200static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1201 struct pbf_pN_cmd_regs *regs,
1202 u32 poll_count)
1203{
1204 u32 occup, to_free, freed, freed_start;
1205 u32 cur_cnt = poll_count;
1206
1207 occup = to_free = REG_RD(bp, regs->lines_occup);
1208 freed = freed_start = REG_RD(bp, regs->lines_freed);
1209
1210 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1211 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1212
1213 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1214 if (cur_cnt--) {
89db4ad8 1215 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1216 occup = REG_RD(bp, regs->lines_occup);
1217 freed = REG_RD(bp, regs->lines_freed);
1218 } else {
1219 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1220 regs->pN);
1221 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1222 regs->pN, occup);
1223 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1224 regs->pN, freed);
1225 break;
1226 }
1227 }
1228 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 1229 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1230}
1231
1191cb83
ED
1232static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1233 u32 expected, u32 poll_count)
619c5cb6
VZ
1234{
1235 u32 cur_cnt = poll_count;
1236 u32 val;
1237
1238 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 1239 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1240
1241 return val;
1242}
1243
d16132ce
AE
1244int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1245 char *msg, u32 poll_cnt)
619c5cb6
VZ
1246{
1247 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1248 if (val != 0) {
1249 BNX2X_ERR("%s usage count=%d\n", msg, val);
1250 return 1;
1251 }
1252 return 0;
1253}
1254
d16132ce
AE
1255/* Common routines with VF FLR cleanup */
1256u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
619c5cb6
VZ
1257{
1258 /* adjust polling timeout */
1259 if (CHIP_REV_IS_EMUL(bp))
1260 return FLR_POLL_CNT * 2000;
1261
1262 if (CHIP_REV_IS_FPGA(bp))
1263 return FLR_POLL_CNT * 120;
1264
1265 return FLR_POLL_CNT;
1266}
1267
d16132ce 1268void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
619c5cb6
VZ
1269{
1270 struct pbf_pN_cmd_regs cmd_regs[] = {
1271 {0, (CHIP_IS_E3B0(bp)) ?
1272 PBF_REG_TQ_OCCUPANCY_Q0 :
1273 PBF_REG_P0_TQ_OCCUPANCY,
1274 (CHIP_IS_E3B0(bp)) ?
1275 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1276 PBF_REG_P0_TQ_LINES_FREED_CNT},
1277 {1, (CHIP_IS_E3B0(bp)) ?
1278 PBF_REG_TQ_OCCUPANCY_Q1 :
1279 PBF_REG_P1_TQ_OCCUPANCY,
1280 (CHIP_IS_E3B0(bp)) ?
1281 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1282 PBF_REG_P1_TQ_LINES_FREED_CNT},
1283 {4, (CHIP_IS_E3B0(bp)) ?
1284 PBF_REG_TQ_OCCUPANCY_LB_Q :
1285 PBF_REG_P4_TQ_OCCUPANCY,
1286 (CHIP_IS_E3B0(bp)) ?
1287 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1288 PBF_REG_P4_TQ_LINES_FREED_CNT}
1289 };
1290
1291 struct pbf_pN_buf_regs buf_regs[] = {
1292 {0, (CHIP_IS_E3B0(bp)) ?
1293 PBF_REG_INIT_CRD_Q0 :
1294 PBF_REG_P0_INIT_CRD ,
1295 (CHIP_IS_E3B0(bp)) ?
1296 PBF_REG_CREDIT_Q0 :
1297 PBF_REG_P0_CREDIT,
1298 (CHIP_IS_E3B0(bp)) ?
1299 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1300 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1301 {1, (CHIP_IS_E3B0(bp)) ?
1302 PBF_REG_INIT_CRD_Q1 :
1303 PBF_REG_P1_INIT_CRD,
1304 (CHIP_IS_E3B0(bp)) ?
1305 PBF_REG_CREDIT_Q1 :
1306 PBF_REG_P1_CREDIT,
1307 (CHIP_IS_E3B0(bp)) ?
1308 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1309 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1310 {4, (CHIP_IS_E3B0(bp)) ?
1311 PBF_REG_INIT_CRD_LB_Q :
1312 PBF_REG_P4_INIT_CRD,
1313 (CHIP_IS_E3B0(bp)) ?
1314 PBF_REG_CREDIT_LB_Q :
1315 PBF_REG_P4_CREDIT,
1316 (CHIP_IS_E3B0(bp)) ?
1317 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1318 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1319 };
1320
1321 int i;
1322
1323 /* Verify the command queues are flushed P0, P1, P4 */
1324 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1325 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1326
619c5cb6
VZ
1327 /* Verify the transmission buffers are flushed P0, P1, P4 */
1328 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1329 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1330}
1331
1332#define OP_GEN_PARAM(param) \
1333 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1334
1335#define OP_GEN_TYPE(type) \
1336 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1337
1338#define OP_GEN_AGG_VECT(index) \
1339 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1340
d16132ce 1341int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
619c5cb6 1342{
86564c3f 1343 u32 op_gen_command = 0;
619c5cb6
VZ
1344 u32 comp_addr = BAR_CSTRORM_INTMEM +
1345 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1346 int ret = 0;
1347
1348 if (REG_RD(bp, comp_addr)) {
89db4ad8 1349 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1350 return 1;
1351 }
1352
86564c3f
YM
1353 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1354 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1355 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1356 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
619c5cb6 1357
89db4ad8 1358 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
86564c3f 1359 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
619c5cb6
VZ
1360
1361 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1362 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1363 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1364 (REG_RD(bp, comp_addr)));
d16132ce
AE
1365 bnx2x_panic();
1366 return 1;
619c5cb6 1367 }
16a5fd92 1368 /* Zero completion for next FLR */
619c5cb6
VZ
1369 REG_WR(bp, comp_addr, 0);
1370
1371 return ret;
1372}
1373
b56e9670 1374u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
619c5cb6 1375{
619c5cb6
VZ
1376 u16 status;
1377
2a80eebc 1378 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
619c5cb6
VZ
1379 return status & PCI_EXP_DEVSTA_TRPND;
1380}
1381
1382/* PF FLR specific routines
1383*/
1384static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1385{
619c5cb6
VZ
1386 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1387 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1388 CFC_REG_NUM_LCIDS_INSIDE_PF,
1389 "CFC PF usage counter timed out",
1390 poll_cnt))
1391 return 1;
1392
619c5cb6
VZ
1393 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1394 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1395 DORQ_REG_PF_USAGE_CNT,
1396 "DQ PF usage counter timed out",
1397 poll_cnt))
1398 return 1;
1399
1400 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1401 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1402 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1403 "QM PF usage counter timed out",
1404 poll_cnt))
1405 return 1;
1406
1407 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1408 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1409 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1410 "Timers VNIC usage counter timed out",
1411 poll_cnt))
1412 return 1;
1413 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1414 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1415 "Timers NUM_SCANS usage counter timed out",
1416 poll_cnt))
1417 return 1;
1418
1419 /* Wait DMAE PF usage counter to zero */
1420 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1421 dmae_reg_go_c[INIT_DMAE_C(bp)],
6bf07b8e 1422 "DMAE command register timed out",
619c5cb6
VZ
1423 poll_cnt))
1424 return 1;
1425
1426 return 0;
1427}
1428
1429static void bnx2x_hw_enable_status(struct bnx2x *bp)
1430{
1431 u32 val;
1432
1433 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1434 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1435
1436 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1437 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1438
1439 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1440 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1441
1442 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1443 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1444
1445 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1446 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1447
1448 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1449 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1450
1451 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1452 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1453
1454 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1455 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1456 val);
1457}
1458
1459static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1460{
1461 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1462
1463 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1464
1465 /* Re-enable PF target read access */
1466 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1467
1468 /* Poll HW usage counters */
89db4ad8 1469 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1470 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1471 return -EBUSY;
1472
1473 /* Zero the igu 'trailing edge' and 'leading edge' */
1474
1475 /* Send the FW cleanup command */
1476 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1477 return -EBUSY;
1478
1479 /* ATC cleanup */
1480
1481 /* Verify TX hw is flushed */
1482 bnx2x_tx_hw_flushed(bp, poll_cnt);
1483
1484 /* Wait 100ms (not adjusted according to platform) */
1485 msleep(100);
1486
1487 /* Verify no pending pci transactions */
1488 if (bnx2x_is_pcie_pending(bp->pdev))
1489 BNX2X_ERR("PCIE Transactions still pending\n");
1490
1491 /* Debug */
1492 bnx2x_hw_enable_status(bp);
1493
1494 /*
1495 * Master enable - Due to WB DMAE writes performed before this
1496 * register is re-initialized as part of the regular function init
1497 */
1498 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1499
1500 return 0;
1501}
1502
f2e0899f 1503static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1504{
34f80b04 1505 int port = BP_PORT(bp);
a2fbb9ea
ET
1506 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1507 u32 val = REG_RD(bp, addr);
69c326b3
DK
1508 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1509 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1510 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
a2fbb9ea
ET
1511
1512 if (msix) {
8badd27a
EG
1513 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1514 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1515 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1516 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
69c326b3
DK
1517 if (single_msix)
1518 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
8badd27a
EG
1519 } else if (msi) {
1520 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
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_ATTN_BIT_EN_0);
a2fbb9ea
ET
1524 } else {
1525 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1526 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1527 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1528 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1529
a0fd065c 1530 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1531 DP(NETIF_MSG_IFUP,
1532 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1533
a0fd065c 1534 REG_WR(bp, addr, val);
615f8fd9 1535
a0fd065c
DK
1536 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1537 }
a2fbb9ea
ET
1538 }
1539
a0fd065c
DK
1540 if (CHIP_IS_E1(bp))
1541 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1542
51c1a580
MS
1543 DP(NETIF_MSG_IFUP,
1544 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1545 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1546
1547 REG_WR(bp, addr, val);
37dbbf32
EG
1548 /*
1549 * Ensure that HC_CONFIG is written before leading/trailing edge config
1550 */
1551 mmiowb();
1552 barrier();
34f80b04 1553
f2e0899f 1554 if (!CHIP_IS_E1(bp)) {
34f80b04 1555 /* init leading/trailing edge */
fb3bff17 1556 if (IS_MF(bp)) {
3395a033 1557 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1558 if (bp->port.pmf)
4acac6a5
EG
1559 /* enable nig and gpio3 attention */
1560 val |= 0x1100;
34f80b04
EG
1561 } else
1562 val = 0xffff;
1563
1564 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1565 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1566 }
37dbbf32
EG
1567
1568 /* Make sure that interrupts are indeed enabled from here on */
1569 mmiowb();
a2fbb9ea
ET
1570}
1571
f2e0899f
DK
1572static void bnx2x_igu_int_enable(struct bnx2x *bp)
1573{
1574 u32 val;
30a5de77
DK
1575 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1576 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1577 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
f2e0899f
DK
1578
1579 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1580
1581 if (msix) {
1582 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1583 IGU_PF_CONF_SINGLE_ISR_EN);
ebe61d80 1584 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f 1585 IGU_PF_CONF_ATTN_BIT_EN);
30a5de77
DK
1586
1587 if (single_msix)
1588 val |= IGU_PF_CONF_SINGLE_ISR_EN;
f2e0899f
DK
1589 } else if (msi) {
1590 val &= ~IGU_PF_CONF_INT_LINE_EN;
ebe61d80 1591 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f
DK
1592 IGU_PF_CONF_ATTN_BIT_EN |
1593 IGU_PF_CONF_SINGLE_ISR_EN);
1594 } else {
1595 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
ebe61d80 1596 val |= (IGU_PF_CONF_INT_LINE_EN |
f2e0899f
DK
1597 IGU_PF_CONF_ATTN_BIT_EN |
1598 IGU_PF_CONF_SINGLE_ISR_EN);
1599 }
1600
ebe61d80
YM
1601 /* Clean previous status - need to configure igu prior to ack*/
1602 if ((!msix) || single_msix) {
1603 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1604 bnx2x_ack_int(bp);
1605 }
1606
1607 val |= IGU_PF_CONF_FUNC_EN;
1608
51c1a580 1609 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1610 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1611
1612 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1613
79a8557a
YM
1614 if (val & IGU_PF_CONF_INT_LINE_EN)
1615 pci_intx(bp->pdev, true);
1616
f2e0899f
DK
1617 barrier();
1618
1619 /* init leading/trailing edge */
1620 if (IS_MF(bp)) {
3395a033 1621 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1622 if (bp->port.pmf)
1623 /* enable nig and gpio3 attention */
1624 val |= 0x1100;
1625 } else
1626 val = 0xffff;
1627
1628 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1629 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1630
1631 /* Make sure that interrupts are indeed enabled from here on */
1632 mmiowb();
1633}
1634
1635void bnx2x_int_enable(struct bnx2x *bp)
1636{
1637 if (bp->common.int_block == INT_BLOCK_HC)
1638 bnx2x_hc_int_enable(bp);
1639 else
1640 bnx2x_igu_int_enable(bp);
1641}
1642
9f6c9258 1643void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1644{
a2fbb9ea 1645 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1646 int i, offset;
a2fbb9ea 1647
f8ef6e44
YG
1648 if (disable_hw)
1649 /* prevent the HW from sending interrupts */
1650 bnx2x_int_disable(bp);
a2fbb9ea
ET
1651
1652 /* make sure all ISRs are done */
1653 if (msix) {
8badd27a
EG
1654 synchronize_irq(bp->msix_table[0].vector);
1655 offset = 1;
55c11941
MS
1656 if (CNIC_SUPPORT(bp))
1657 offset++;
ec6ba945 1658 for_each_eth_queue(bp, i)
754a2f52 1659 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1660 } else
1661 synchronize_irq(bp->pdev->irq);
1662
1663 /* make sure sp_task is not running */
1cf167f2 1664 cancel_delayed_work(&bp->sp_task);
3deb8167 1665 cancel_delayed_work(&bp->period_task);
1cf167f2 1666 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1667}
1668
34f80b04 1669/* fast path */
a2fbb9ea
ET
1670
1671/*
34f80b04 1672 * General service functions
a2fbb9ea
ET
1673 */
1674
72fd0718
VZ
1675/* Return true if succeeded to acquire the lock */
1676static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1677{
1678 u32 lock_status;
1679 u32 resource_bit = (1 << resource);
1680 int func = BP_FUNC(bp);
1681 u32 hw_lock_control_reg;
1682
51c1a580
MS
1683 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1684 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1685
1686 /* Validating that the resource is within range */
1687 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1688 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1689 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1690 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1691 return false;
72fd0718
VZ
1692 }
1693
1694 if (func <= 5)
1695 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1696 else
1697 hw_lock_control_reg =
1698 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1699
1700 /* Try to acquire the lock */
1701 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1702 lock_status = REG_RD(bp, hw_lock_control_reg);
1703 if (lock_status & resource_bit)
1704 return true;
1705
51c1a580
MS
1706 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1707 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1708 return false;
1709}
1710
c9ee9206
VZ
1711/**
1712 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1713 *
1714 * @bp: driver handle
1715 *
1716 * Returns the recovery leader resource id according to the engine this function
1717 * belongs to. Currently only only 2 engines is supported.
1718 */
1191cb83 1719static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
c9ee9206
VZ
1720{
1721 if (BP_PATH(bp))
1722 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1723 else
1724 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1725}
1726
1727/**
2de67439 1728 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
c9ee9206
VZ
1729 *
1730 * @bp: driver handle
1731 *
2de67439 1732 * Tries to acquire a leader lock for current engine.
c9ee9206 1733 */
1191cb83 1734static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
c9ee9206
VZ
1735{
1736 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1737}
1738
619c5cb6 1739static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
55c11941 1740
fd1fc79d
AE
1741/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1742static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1743{
1744 /* Set the interrupt occurred bit for the sp-task to recognize it
1745 * must ack the interrupt and transition according to the IGU
1746 * state machine.
1747 */
1748 atomic_set(&bp->interrupt_occurred, 1);
1749
1750 /* The sp_task must execute only after this bit
1751 * is set, otherwise we will get out of sync and miss all
1752 * further interrupts. Hence, the barrier.
1753 */
1754 smp_wmb();
1755
1756 /* schedule sp_task to workqueue */
1757 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1758}
3196a88a 1759
619c5cb6 1760void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1761{
1762 struct bnx2x *bp = fp->bp;
1763 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1764 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6 1765 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
15192a8c 1766 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a2fbb9ea 1767
34f80b04 1768 DP(BNX2X_MSG_SP,
a2fbb9ea 1769 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1770 fp->index, cid, command, bp->state,
34f80b04 1771 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1772
fd1fc79d
AE
1773 /* If cid is within VF range, replace the slowpath object with the
1774 * one corresponding to this VF
1775 */
1776 if (cid >= BNX2X_FIRST_VF_CID &&
1777 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1778 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1779
619c5cb6
VZ
1780 switch (command) {
1781 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1782 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1783 drv_cmd = BNX2X_Q_CMD_UPDATE;
1784 break;
d6cae238 1785
619c5cb6 1786 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1787 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1788 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1789 break;
1790
6383c0b3 1791 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1792 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1793 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1794 break;
1795
619c5cb6 1796 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1797 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1798 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1799 break;
1800
619c5cb6 1801 case (RAMROD_CMD_ID_ETH_TERMINATE):
6bf07b8e 1802 DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
619c5cb6 1803 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1804 break;
1805
619c5cb6 1806 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1807 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1808 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1809 break;
619c5cb6
VZ
1810
1811 default:
1812 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1813 command, fp->index);
1814 return;
523224a3 1815 }
3196a88a 1816
619c5cb6
VZ
1817 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1818 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1819 /* q_obj->complete_cmd() failure means that this was
1820 * an unexpected completion.
1821 *
1822 * In this case we don't want to increase the bp->spq_left
1823 * because apparently we haven't sent this command the first
1824 * place.
1825 */
1826#ifdef BNX2X_STOP_ON_ERROR
1827 bnx2x_panic();
1828#else
1829 return;
1830#endif
fd1fc79d
AE
1831 /* SRIOV: reschedule any 'in_progress' operations */
1832 bnx2x_iov_sp_event(bp, cid, true);
619c5cb6 1833
8fe23fbd 1834 smp_mb__before_atomic_inc();
6e30dd4e 1835 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1836 /* push the change in bp->spq_left and towards the memory */
1837 smp_mb__after_atomic_inc();
49d66772 1838
d6cae238
VZ
1839 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1840
a3348722
BW
1841 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1842 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1843 /* if Q update ramrod is completed for last Q in AFEX vif set
1844 * flow, then ACK MCP at the end
1845 *
1846 * mark pending ACK to MCP bit.
1847 * prevent case that both bits are cleared.
1848 * At the end of load/unload driver checks that
2de67439 1849 * sp_state is cleared, and this order prevents
a3348722
BW
1850 * races
1851 */
1852 smp_mb__before_clear_bit();
1853 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1854 wmb();
1855 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1856 smp_mb__after_clear_bit();
1857
fd1fc79d
AE
1858 /* schedule the sp task as mcp ack is required */
1859 bnx2x_schedule_sp_task(bp);
a3348722
BW
1860 }
1861
523224a3 1862 return;
a2fbb9ea
ET
1863}
1864
9f6c9258 1865irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1866{
555f6c78 1867 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1868 u16 status = bnx2x_ack_int(bp);
34f80b04 1869 u16 mask;
ca00392c 1870 int i;
6383c0b3 1871 u8 cos;
a2fbb9ea 1872
34f80b04 1873 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1874 if (unlikely(status == 0)) {
1875 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1876 return IRQ_NONE;
1877 }
f5372251 1878 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1879
3196a88a
EG
1880#ifdef BNX2X_STOP_ON_ERROR
1881 if (unlikely(bp->panic))
1882 return IRQ_HANDLED;
1883#endif
1884
ec6ba945 1885 for_each_eth_queue(bp, i) {
ca00392c 1886 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1887
55c11941 1888 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
ca00392c 1889 if (status & mask) {
619c5cb6 1890 /* Handle Rx or Tx according to SB id */
6383c0b3 1891 for_each_cos_in_tx_queue(fp, cos)
65565884 1892 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
523224a3 1893 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1894 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1895 status &= ~mask;
1896 }
a2fbb9ea
ET
1897 }
1898
55c11941
MS
1899 if (CNIC_SUPPORT(bp)) {
1900 mask = 0x2;
1901 if (status & (mask | 0x1)) {
1902 struct cnic_ops *c_ops = NULL;
993ac7b5 1903
ad9b4359
MC
1904 rcu_read_lock();
1905 c_ops = rcu_dereference(bp->cnic_ops);
1906 if (c_ops && (bp->cnic_eth_dev.drv_state &
1907 CNIC_DRV_STATE_HANDLES_IRQ))
1908 c_ops->cnic_handler(bp->cnic_data, NULL);
1909 rcu_read_unlock();
993ac7b5 1910
55c11941
MS
1911 status &= ~mask;
1912 }
993ac7b5 1913 }
a2fbb9ea 1914
34f80b04 1915 if (unlikely(status & 0x1)) {
fd1fc79d
AE
1916
1917 /* schedule sp task to perform default status block work, ack
1918 * attentions and enable interrupts.
1919 */
1920 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
1921
1922 status &= ~0x1;
1923 if (!status)
1924 return IRQ_HANDLED;
1925 }
1926
cdaa7cb8
VZ
1927 if (unlikely(status))
1928 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1929 status);
a2fbb9ea 1930
c18487ee 1931 return IRQ_HANDLED;
a2fbb9ea
ET
1932}
1933
c18487ee
YR
1934/* Link */
1935
1936/*
1937 * General service functions
1938 */
a2fbb9ea 1939
9f6c9258 1940int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1941{
1942 u32 lock_status;
1943 u32 resource_bit = (1 << resource);
4a37fb66
YG
1944 int func = BP_FUNC(bp);
1945 u32 hw_lock_control_reg;
c18487ee 1946 int cnt;
a2fbb9ea 1947
c18487ee
YR
1948 /* Validating that the resource is within range */
1949 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1950 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1951 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1952 return -EINVAL;
1953 }
a2fbb9ea 1954
4a37fb66
YG
1955 if (func <= 5) {
1956 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1957 } else {
1958 hw_lock_control_reg =
1959 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1960 }
1961
c18487ee 1962 /* Validating that the resource is not already taken */
4a37fb66 1963 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1964 if (lock_status & resource_bit) {
51c1a580 1965 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
c18487ee
YR
1966 lock_status, resource_bit);
1967 return -EEXIST;
1968 }
a2fbb9ea 1969
46230476
EG
1970 /* Try for 5 second every 5ms */
1971 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1972 /* Try to acquire the lock */
4a37fb66
YG
1973 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1974 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1975 if (lock_status & resource_bit)
1976 return 0;
a2fbb9ea 1977
639d65b8 1978 usleep_range(5000, 10000);
a2fbb9ea 1979 }
51c1a580 1980 BNX2X_ERR("Timeout\n");
c18487ee
YR
1981 return -EAGAIN;
1982}
a2fbb9ea 1983
c9ee9206
VZ
1984int bnx2x_release_leader_lock(struct bnx2x *bp)
1985{
1986 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1987}
1988
9f6c9258 1989int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1990{
1991 u32 lock_status;
1992 u32 resource_bit = (1 << resource);
4a37fb66
YG
1993 int func = BP_FUNC(bp);
1994 u32 hw_lock_control_reg;
a2fbb9ea 1995
c18487ee
YR
1996 /* Validating that the resource is within range */
1997 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1998 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1999 resource, HW_LOCK_MAX_RESOURCE_VALUE);
2000 return -EINVAL;
2001 }
2002
4a37fb66
YG
2003 if (func <= 5) {
2004 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
2005 } else {
2006 hw_lock_control_reg =
2007 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
2008 }
2009
c18487ee 2010 /* Validating that the resource is currently taken */
4a37fb66 2011 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 2012 if (!(lock_status & resource_bit)) {
6bf07b8e
YM
2013 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
2014 lock_status, resource_bit);
c18487ee 2015 return -EFAULT;
a2fbb9ea
ET
2016 }
2017
9f6c9258
DK
2018 REG_WR(bp, hw_lock_control_reg, resource_bit);
2019 return 0;
c18487ee 2020}
a2fbb9ea 2021
4acac6a5
EG
2022int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2023{
2024 /* The GPIO should be swapped if swap register is set and active */
2025 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2026 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2027 int gpio_shift = gpio_num +
2028 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2029 u32 gpio_mask = (1 << gpio_shift);
2030 u32 gpio_reg;
2031 int value;
2032
2033 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2034 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2035 return -EINVAL;
2036 }
2037
2038 /* read GPIO value */
2039 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2040
2041 /* get the requested pin value */
2042 if ((gpio_reg & gpio_mask) == gpio_mask)
2043 value = 1;
2044 else
2045 value = 0;
2046
2047 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2048
2049 return value;
2050}
2051
17de50b7 2052int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
2053{
2054 /* The GPIO should be swapped if swap register is set and active */
2055 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 2056 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
2057 int gpio_shift = gpio_num +
2058 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2059 u32 gpio_mask = (1 << gpio_shift);
2060 u32 gpio_reg;
a2fbb9ea 2061
c18487ee
YR
2062 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2063 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2064 return -EINVAL;
2065 }
a2fbb9ea 2066
4a37fb66 2067 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
2068 /* read GPIO and mask except the float bits */
2069 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 2070
c18487ee
YR
2071 switch (mode) {
2072 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
2073 DP(NETIF_MSG_LINK,
2074 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
2075 gpio_num, gpio_shift);
2076 /* clear FLOAT and set CLR */
2077 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2078 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2079 break;
a2fbb9ea 2080
c18487ee 2081 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
2082 DP(NETIF_MSG_LINK,
2083 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
2084 gpio_num, gpio_shift);
2085 /* clear FLOAT and set SET */
2086 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2087 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2088 break;
a2fbb9ea 2089
17de50b7 2090 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
2091 DP(NETIF_MSG_LINK,
2092 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
2093 gpio_num, gpio_shift);
2094 /* set FLOAT */
2095 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2096 break;
a2fbb9ea 2097
c18487ee
YR
2098 default:
2099 break;
a2fbb9ea
ET
2100 }
2101
c18487ee 2102 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 2103 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 2104
c18487ee 2105 return 0;
a2fbb9ea
ET
2106}
2107
0d40f0d4
YR
2108int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2109{
2110 u32 gpio_reg = 0;
2111 int rc = 0;
2112
2113 /* Any port swapping should be handled by caller. */
2114
2115 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2116 /* read GPIO and mask except the float bits */
2117 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2118 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2119 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2120 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2121
2122 switch (mode) {
2123 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2124 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2125 /* set CLR */
2126 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2127 break;
2128
2129 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2130 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2131 /* set SET */
2132 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2133 break;
2134
2135 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2136 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2137 /* set FLOAT */
2138 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2139 break;
2140
2141 default:
2142 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2143 rc = -EINVAL;
2144 break;
2145 }
2146
2147 if (rc == 0)
2148 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2149
2150 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2151
2152 return rc;
2153}
2154
4acac6a5
EG
2155int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2156{
2157 /* The GPIO should be swapped if swap register is set and active */
2158 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2159 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2160 int gpio_shift = gpio_num +
2161 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2162 u32 gpio_mask = (1 << gpio_shift);
2163 u32 gpio_reg;
2164
2165 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2166 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2167 return -EINVAL;
2168 }
2169
2170 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2171 /* read GPIO int */
2172 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2173
2174 switch (mode) {
2175 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
2176 DP(NETIF_MSG_LINK,
2177 "Clear GPIO INT %d (shift %d) -> output low\n",
2178 gpio_num, gpio_shift);
4acac6a5
EG
2179 /* clear SET and set CLR */
2180 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2181 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2182 break;
2183
2184 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
2185 DP(NETIF_MSG_LINK,
2186 "Set GPIO INT %d (shift %d) -> output high\n",
2187 gpio_num, gpio_shift);
4acac6a5
EG
2188 /* clear CLR and set SET */
2189 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2190 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2191 break;
2192
2193 default:
2194 break;
2195 }
2196
2197 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2198 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2199
2200 return 0;
2201}
2202
d6d99a3f 2203static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
a2fbb9ea 2204{
c18487ee 2205 u32 spio_reg;
a2fbb9ea 2206
d6d99a3f
YM
2207 /* Only 2 SPIOs are configurable */
2208 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2209 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
c18487ee 2210 return -EINVAL;
a2fbb9ea
ET
2211 }
2212
4a37fb66 2213 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2214 /* read SPIO and mask except the float bits */
d6d99a3f 2215 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
a2fbb9ea 2216
c18487ee 2217 switch (mode) {
d6d99a3f
YM
2218 case MISC_SPIO_OUTPUT_LOW:
2219 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
c18487ee 2220 /* clear FLOAT and set CLR */
d6d99a3f
YM
2221 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2222 spio_reg |= (spio << MISC_SPIO_CLR_POS);
c18487ee 2223 break;
a2fbb9ea 2224
d6d99a3f
YM
2225 case MISC_SPIO_OUTPUT_HIGH:
2226 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
c18487ee 2227 /* clear FLOAT and set SET */
d6d99a3f
YM
2228 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2229 spio_reg |= (spio << MISC_SPIO_SET_POS);
c18487ee 2230 break;
a2fbb9ea 2231
d6d99a3f
YM
2232 case MISC_SPIO_INPUT_HI_Z:
2233 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
c18487ee 2234 /* set FLOAT */
d6d99a3f 2235 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
c18487ee 2236 break;
a2fbb9ea 2237
c18487ee
YR
2238 default:
2239 break;
a2fbb9ea
ET
2240 }
2241
c18487ee 2242 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2243 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2244
a2fbb9ea
ET
2245 return 0;
2246}
2247
9f6c9258 2248void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2249{
a22f0788 2250 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2251 switch (bp->link_vars.ieee_fc &
2252 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2253 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2254 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2255 ADVERTISED_Pause);
c18487ee 2256 break;
356e2385 2257
c18487ee 2258 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2259 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2260 ADVERTISED_Pause);
c18487ee 2261 break;
356e2385 2262
c18487ee 2263 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2264 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2265 break;
356e2385 2266
c18487ee 2267 default:
a22f0788 2268 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2269 ADVERTISED_Pause);
c18487ee
YR
2270 break;
2271 }
2272}
f1410647 2273
cd1dfce2 2274static void bnx2x_set_requested_fc(struct bnx2x *bp)
c18487ee 2275{
cd1dfce2
YM
2276 /* Initialize link parameters structure variables
2277 * It is recommended to turn off RX FC for jumbo frames
2278 * for better performance
2279 */
2280 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2281 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2282 else
2283 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2284}
a2fbb9ea 2285
9156b30b
DK
2286static void bnx2x_init_dropless_fc(struct bnx2x *bp)
2287{
2288 u32 pause_enabled = 0;
2289
2290 if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
2291 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2292 pause_enabled = 1;
2293
2294 REG_WR(bp, BAR_USTRORM_INTMEM +
2295 USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
2296 pause_enabled);
2297 }
2298
2299 DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
2300 pause_enabled ? "enabled" : "disabled");
2301}
2302
cd1dfce2
YM
2303int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2304{
2305 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2306 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2307
2308 if (!BP_NOMCP(bp)) {
2309 bnx2x_set_requested_fc(bp);
4a37fb66 2310 bnx2x_acquire_phy_lock(bp);
b5bf9068 2311
a22f0788 2312 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2313 struct link_params *lp = &bp->link_params;
2314 lp->loopback_mode = LOOPBACK_XGXS;
2315 /* do PHY loopback at 10G speed, if possible */
2316 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2317 if (lp->speed_cap_mask[cfx_idx] &
2318 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2319 lp->req_line_speed[cfx_idx] =
2320 SPEED_10000;
2321 else
2322 lp->req_line_speed[cfx_idx] =
2323 SPEED_1000;
2324 }
a22f0788 2325 }
b5bf9068 2326
8970b2e4
MS
2327 if (load_mode == LOAD_LOOPBACK_EXT) {
2328 struct link_params *lp = &bp->link_params;
2329 lp->loopback_mode = LOOPBACK_EXT;
2330 }
2331
19680c48 2332 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2333
4a37fb66 2334 bnx2x_release_phy_lock(bp);
a2fbb9ea 2335
9156b30b
DK
2336 bnx2x_init_dropless_fc(bp);
2337
3c96c68b
EG
2338 bnx2x_calc_fc_adv(bp);
2339
cd1dfce2 2340 if (bp->link_vars.link_up) {
b5bf9068 2341 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2342 bnx2x_link_report(bp);
cd1dfce2
YM
2343 }
2344 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2345 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2346 return rc;
2347 }
f5372251 2348 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2349 return -EINVAL;
a2fbb9ea
ET
2350}
2351
9f6c9258 2352void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2353{
19680c48 2354 if (!BP_NOMCP(bp)) {
4a37fb66 2355 bnx2x_acquire_phy_lock(bp);
19680c48 2356 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2357 bnx2x_release_phy_lock(bp);
a2fbb9ea 2358
9156b30b
DK
2359 bnx2x_init_dropless_fc(bp);
2360
19680c48
EG
2361 bnx2x_calc_fc_adv(bp);
2362 } else
f5372251 2363 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2364}
a2fbb9ea 2365
c18487ee
YR
2366static void bnx2x__link_reset(struct bnx2x *bp)
2367{
19680c48 2368 if (!BP_NOMCP(bp)) {
4a37fb66 2369 bnx2x_acquire_phy_lock(bp);
5d07d868 2370 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2371 bnx2x_release_phy_lock(bp);
19680c48 2372 } else
f5372251 2373 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2374}
a2fbb9ea 2375
5d07d868
YM
2376void bnx2x_force_link_reset(struct bnx2x *bp)
2377{
2378 bnx2x_acquire_phy_lock(bp);
2379 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2380 bnx2x_release_phy_lock(bp);
2381}
2382
a22f0788 2383u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2384{
2145a920 2385 u8 rc = 0;
a2fbb9ea 2386
2145a920
VZ
2387 if (!BP_NOMCP(bp)) {
2388 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2389 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2390 is_serdes);
2145a920
VZ
2391 bnx2x_release_phy_lock(bp);
2392 } else
2393 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2394
c18487ee
YR
2395 return rc;
2396}
a2fbb9ea 2397
2691d51d
EG
2398/* Calculates the sum of vn_min_rates.
2399 It's needed for further normalizing of the min_rates.
2400 Returns:
2401 sum of vn_min_rates.
2402 or
2403 0 - if all the min_rates are 0.
16a5fd92 2404 In the later case fairness algorithm should be deactivated.
2691d51d
EG
2405 If not all min_rates are zero then those that are zeroes will be set to 1.
2406 */
b475d78f
YM
2407static void bnx2x_calc_vn_min(struct bnx2x *bp,
2408 struct cmng_init_input *input)
2691d51d
EG
2409{
2410 int all_zero = 1;
2691d51d
EG
2411 int vn;
2412
3395a033 2413 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2414 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2415 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2416 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2417
2418 /* Skip hidden vns */
2419 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2420 vn_min_rate = 0;
2691d51d 2421 /* If min rate is zero - set it to 1 */
b475d78f 2422 else if (!vn_min_rate)
2691d51d
EG
2423 vn_min_rate = DEF_MIN_RATE;
2424 else
2425 all_zero = 0;
2426
b475d78f 2427 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2428 }
2429
30ae438b
DK
2430 /* if ETS or all min rates are zeros - disable fairness */
2431 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2432 input->flags.cmng_enables &=
30ae438b
DK
2433 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2434 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2435 } else if (all_zero) {
b475d78f 2436 input->flags.cmng_enables &=
b015e3d1 2437 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2438 DP(NETIF_MSG_IFUP,
2439 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2440 } else
b475d78f 2441 input->flags.cmng_enables |=
b015e3d1 2442 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2443}
2444
b475d78f
YM
2445static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2446 struct cmng_init_input *input)
34f80b04 2447{
b475d78f 2448 u16 vn_max_rate;
f2e0899f 2449 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2450
b475d78f 2451 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2452 vn_max_rate = 0;
b475d78f 2453 else {
faa6fcbb
DK
2454 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2455
b475d78f 2456 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2457 /* maxCfg in percents of linkspeed */
2458 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2459 } else /* SD modes */
faa6fcbb
DK
2460 /* maxCfg is absolute in 100Mb units */
2461 vn_max_rate = maxCfg * 100;
34f80b04 2462 }
f85582f8 2463
b475d78f 2464 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2465
b475d78f 2466 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2467}
f85582f8 2468
523224a3
DK
2469static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2470{
2471 if (CHIP_REV_IS_SLOW(bp))
2472 return CMNG_FNS_NONE;
fb3bff17 2473 if (IS_MF(bp))
523224a3
DK
2474 return CMNG_FNS_MINMAX;
2475
2476 return CMNG_FNS_NONE;
2477}
2478
2ae17f66 2479void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2480{
0793f83f 2481 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2482
2483 if (BP_NOMCP(bp))
16a5fd92 2484 return; /* what should be the default value in this case */
523224a3 2485
0793f83f
DK
2486 /* For 2 port configuration the absolute function number formula
2487 * is:
2488 * abs_func = 2 * vn + BP_PORT + BP_PATH
2489 *
2490 * and there are 4 functions per port
2491 *
2492 * For 4 port configuration it is
2493 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2494 *
2495 * and there are 2 functions per port
2496 */
3395a033 2497 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2498 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2499
2500 if (func >= E1H_FUNC_MAX)
2501 break;
2502
f2e0899f 2503 bp->mf_config[vn] =
523224a3
DK
2504 MF_CFG_RD(bp, func_mf_config[func].config);
2505 }
a3348722
BW
2506 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2507 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2508 bp->flags |= MF_FUNC_DIS;
2509 } else {
2510 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2511 bp->flags &= ~MF_FUNC_DIS;
2512 }
523224a3
DK
2513}
2514
2515static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2516{
b475d78f
YM
2517 struct cmng_init_input input;
2518 memset(&input, 0, sizeof(struct cmng_init_input));
2519
2520 input.port_rate = bp->link_vars.line_speed;
523224a3 2521
568e2426 2522 if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
523224a3
DK
2523 int vn;
2524
523224a3
DK
2525 /* read mf conf from shmem */
2526 if (read_cfg)
2527 bnx2x_read_mf_cfg(bp);
2528
523224a3 2529 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2530 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2531
2532 /* calculate and set min-max rate for each vn */
c4154f25 2533 if (bp->port.pmf)
3395a033 2534 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2535 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2536
2537 /* always enable rate shaping and fairness */
b475d78f 2538 input.flags.cmng_enables |=
523224a3 2539 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2540
2541 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2542 return;
2543 }
2544
2545 /* rate shaping and fairness are disabled */
2546 DP(NETIF_MSG_IFUP,
2547 "rate shaping and fairness are disabled\n");
2548}
34f80b04 2549
1191cb83
ED
2550static void storm_memset_cmng(struct bnx2x *bp,
2551 struct cmng_init *cmng,
2552 u8 port)
2553{
2554 int vn;
2555 size_t size = sizeof(struct cmng_struct_per_port);
2556
2557 u32 addr = BAR_XSTRORM_INTMEM +
2558 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2559
2560 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2561
2562 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2563 int func = func_by_vn(bp, vn);
2564
2565 addr = BAR_XSTRORM_INTMEM +
2566 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2567 size = sizeof(struct rate_shaping_vars_per_vn);
2568 __storm_memset_struct(bp, addr, size,
2569 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2570
2571 addr = BAR_XSTRORM_INTMEM +
2572 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2573 size = sizeof(struct fairness_vars_per_vn);
2574 __storm_memset_struct(bp, addr, size,
2575 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2576 }
2577}
2578
568e2426
DK
2579/* init cmng mode in HW according to local configuration */
2580void bnx2x_set_local_cmng(struct bnx2x *bp)
2581{
2582 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2583
2584 if (cmng_fns != CMNG_FNS_NONE) {
2585 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2586 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2587 } else {
2588 /* rate shaping and fairness are disabled */
2589 DP(NETIF_MSG_IFUP,
2590 "single function mode without fairness\n");
2591 }
2592}
2593
c18487ee
YR
2594/* This function is called upon link interrupt */
2595static void bnx2x_link_attn(struct bnx2x *bp)
2596{
bb2a0f7a
YG
2597 /* Make sure that we are synced with the current statistics */
2598 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2599
c18487ee 2600 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2601
9156b30b 2602 bnx2x_init_dropless_fc(bp);
1c06328c 2603
9156b30b 2604 if (bp->link_vars.link_up) {
1c06328c 2605
619c5cb6 2606 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2607 struct host_port_stats *pstats;
2608
2609 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2610 /* reset old mac stats */
bb2a0f7a
YG
2611 memset(&(pstats->mac_stx[0]), 0,
2612 sizeof(struct mac_stx));
2613 }
f34d28ea 2614 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2615 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2616 }
2617
568e2426
DK
2618 if (bp->link_vars.link_up && bp->link_vars.line_speed)
2619 bnx2x_set_local_cmng(bp);
9fdc3e95 2620
2ae17f66
VZ
2621 __bnx2x_link_report(bp);
2622
9fdc3e95
DK
2623 if (IS_MF(bp))
2624 bnx2x_link_sync_notify(bp);
c18487ee 2625}
a2fbb9ea 2626
9f6c9258 2627void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2628{
2ae17f66 2629 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2630 return;
a2fbb9ea 2631
00253a8c 2632 /* read updated dcb configuration */
ad5afc89
AE
2633 if (IS_PF(bp)) {
2634 bnx2x_dcbx_pmf_update(bp);
2635 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2636 if (bp->link_vars.link_up)
2637 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2638 else
2639 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2640 /* indicate link status */
2641 bnx2x_link_report(bp);
a2fbb9ea 2642
ad5afc89
AE
2643 } else { /* VF */
2644 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2645 SUPPORTED_10baseT_Full |
2646 SUPPORTED_100baseT_Half |
2647 SUPPORTED_100baseT_Full |
2648 SUPPORTED_1000baseT_Full |
2649 SUPPORTED_2500baseX_Full |
2650 SUPPORTED_10000baseT_Full |
2651 SUPPORTED_TP |
2652 SUPPORTED_FIBRE |
2653 SUPPORTED_Autoneg |
2654 SUPPORTED_Pause |
2655 SUPPORTED_Asym_Pause);
2656 bp->port.advertising[0] = bp->port.supported[0];
2657
2658 bp->link_params.bp = bp;
2659 bp->link_params.port = BP_PORT(bp);
2660 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2661 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2662 bp->link_params.req_line_speed[0] = SPEED_10000;
2663 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2664 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2665 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2666 bp->link_vars.line_speed = SPEED_10000;
2667 bp->link_vars.link_status =
2668 (LINK_STATUS_LINK_UP |
2669 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2670 bp->link_vars.link_up = 1;
2671 bp->link_vars.duplex = DUPLEX_FULL;
2672 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2673 __bnx2x_link_report(bp);
bb2a0f7a 2674 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
ad5afc89 2675 }
a2fbb9ea 2676}
a2fbb9ea 2677
a3348722
BW
2678static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2679 u16 vlan_val, u8 allowed_prio)
2680{
86564c3f 2681 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2682 struct bnx2x_func_afex_update_params *f_update_params =
2683 &func_params.params.afex_update;
2684
2685 func_params.f_obj = &bp->func_obj;
2686 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2687
2688 /* no need to wait for RAMROD completion, so don't
2689 * set RAMROD_COMP_WAIT flag
2690 */
2691
2692 f_update_params->vif_id = vifid;
2693 f_update_params->afex_default_vlan = vlan_val;
2694 f_update_params->allowed_priorities = allowed_prio;
2695
2696 /* if ramrod can not be sent, response to MCP immediately */
2697 if (bnx2x_func_state_change(bp, &func_params) < 0)
2698 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2699
2700 return 0;
2701}
2702
2703static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2704 u16 vif_index, u8 func_bit_map)
2705{
86564c3f 2706 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2707 struct bnx2x_func_afex_viflists_params *update_params =
2708 &func_params.params.afex_viflists;
2709 int rc;
2710 u32 drv_msg_code;
2711
2712 /* validate only LIST_SET and LIST_GET are received from switch */
2713 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2714 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2715 cmd_type);
2716
2717 func_params.f_obj = &bp->func_obj;
2718 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2719
2720 /* set parameters according to cmd_type */
2721 update_params->afex_vif_list_command = cmd_type;
86564c3f 2722 update_params->vif_list_index = vif_index;
a3348722
BW
2723 update_params->func_bit_map =
2724 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2725 update_params->func_to_clear = 0;
2726 drv_msg_code =
2727 (cmd_type == VIF_LIST_RULE_GET) ?
2728 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2729 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2730
2731 /* if ramrod can not be sent, respond to MCP immediately for
2732 * SET and GET requests (other are not triggered from MCP)
2733 */
2734 rc = bnx2x_func_state_change(bp, &func_params);
2735 if (rc < 0)
2736 bnx2x_fw_command(bp, drv_msg_code, 0);
2737
2738 return 0;
2739}
2740
2741static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2742{
2743 struct afex_stats afex_stats;
2744 u32 func = BP_ABS_FUNC(bp);
2745 u32 mf_config;
2746 u16 vlan_val;
2747 u32 vlan_prio;
2748 u16 vif_id;
2749 u8 allowed_prio;
2750 u8 vlan_mode;
2751 u32 addr_to_write, vifid, addrs, stats_type, i;
2752
2753 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2754 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2755 DP(BNX2X_MSG_MCP,
2756 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2757 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2758 }
2759
2760 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2761 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2762 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2763 DP(BNX2X_MSG_MCP,
2764 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2765 vifid, addrs);
2766 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2767 addrs);
2768 }
2769
2770 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2771 addr_to_write = SHMEM2_RD(bp,
2772 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2773 stats_type = SHMEM2_RD(bp,
2774 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2775
2776 DP(BNX2X_MSG_MCP,
2777 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2778 addr_to_write);
2779
2780 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2781
2782 /* write response to scratchpad, for MCP */
2783 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2784 REG_WR(bp, addr_to_write + i*sizeof(u32),
2785 *(((u32 *)(&afex_stats))+i));
2786
2787 /* send ack message to MCP */
2788 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2789 }
2790
2791 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2792 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2793 bp->mf_config[BP_VN(bp)] = mf_config;
2794 DP(BNX2X_MSG_MCP,
2795 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2796 mf_config);
2797
2798 /* if VIF_SET is "enabled" */
2799 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2800 /* set rate limit directly to internal RAM */
2801 struct cmng_init_input cmng_input;
2802 struct rate_shaping_vars_per_vn m_rs_vn;
2803 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2804 u32 addr = BAR_XSTRORM_INTMEM +
2805 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2806
2807 bp->mf_config[BP_VN(bp)] = mf_config;
2808
2809 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2810 m_rs_vn.vn_counter.rate =
2811 cmng_input.vnic_max_rate[BP_VN(bp)];
2812 m_rs_vn.vn_counter.quota =
2813 (m_rs_vn.vn_counter.rate *
2814 RS_PERIODIC_TIMEOUT_USEC) / 8;
2815
2816 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2817
2818 /* read relevant values from mf_cfg struct in shmem */
2819 vif_id =
2820 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2821 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2822 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2823 vlan_val =
2824 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2825 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2826 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2827 vlan_prio = (mf_config &
2828 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2829 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2830 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2831 vlan_mode =
2832 (MF_CFG_RD(bp,
2833 func_mf_config[func].afex_config) &
2834 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2835 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2836 allowed_prio =
2837 (MF_CFG_RD(bp,
2838 func_mf_config[func].afex_config) &
2839 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2840 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2841
2842 /* send ramrod to FW, return in case of failure */
2843 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2844 allowed_prio))
2845 return;
2846
2847 bp->afex_def_vlan_tag = vlan_val;
2848 bp->afex_vlan_mode = vlan_mode;
2849 } else {
2850 /* notify link down because BP->flags is disabled */
2851 bnx2x_link_report(bp);
2852
2853 /* send INVALID VIF ramrod to FW */
2854 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2855
2856 /* Reset the default afex VLAN */
2857 bp->afex_def_vlan_tag = -1;
2858 }
2859 }
2860}
2861
34f80b04
EG
2862static void bnx2x_pmf_update(struct bnx2x *bp)
2863{
2864 int port = BP_PORT(bp);
2865 u32 val;
2866
2867 bp->port.pmf = 1;
51c1a580 2868 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2869
3deb8167
YR
2870 /*
2871 * We need the mb() to ensure the ordering between the writing to
2872 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2873 */
2874 smp_mb();
2875
2876 /* queue a periodic task */
2877 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2878
ef01854e
DK
2879 bnx2x_dcbx_pmf_update(bp);
2880
34f80b04 2881 /* enable nig attention */
3395a033 2882 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2883 if (bp->common.int_block == INT_BLOCK_HC) {
2884 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2885 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2886 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2887 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2888 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2889 }
bb2a0f7a
YG
2890
2891 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2892}
2893
c18487ee 2894/* end of Link */
a2fbb9ea
ET
2895
2896/* slow path */
2897
2898/*
2899 * General service functions
2900 */
2901
2691d51d 2902/* send the MCP a request, block until there is a reply */
a22f0788 2903u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2904{
f2e0899f 2905 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2906 u32 seq;
2691d51d
EG
2907 u32 rc = 0;
2908 u32 cnt = 1;
2909 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2910
c4ff7cbf 2911 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2912 seq = ++bp->fw_seq;
f2e0899f
DK
2913 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2914 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2915
754a2f52
DK
2916 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2917 (command | seq), param);
2691d51d
EG
2918
2919 do {
2920 /* let the FW do it's magic ... */
2921 msleep(delay);
2922
f2e0899f 2923 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2924
c4ff7cbf
EG
2925 /* Give the FW up to 5 second (500*10ms) */
2926 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2927
2928 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2929 cnt*delay, rc, seq);
2930
2931 /* is this a reply to our command? */
2932 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2933 rc &= FW_MSG_CODE_MASK;
2934 else {
2935 /* FW BUG! */
2936 BNX2X_ERR("FW failed to respond!\n");
2937 bnx2x_fw_dump(bp);
2938 rc = 0;
2939 }
c4ff7cbf 2940 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2941
2942 return rc;
2943}
2944
1191cb83
ED
2945static void storm_memset_func_cfg(struct bnx2x *bp,
2946 struct tstorm_eth_function_common_config *tcfg,
2947 u16 abs_fid)
2948{
2949 size_t size = sizeof(struct tstorm_eth_function_common_config);
2950
2951 u32 addr = BAR_TSTRORM_INTMEM +
2952 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2953
2954 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2955}
2956
619c5cb6
VZ
2957void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2958{
2959 if (CHIP_IS_E1x(bp)) {
2960 struct tstorm_eth_function_common_config tcfg = {0};
2961
2962 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2963 }
2964
2965 /* Enable the function in the FW */
2966 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2967 storm_memset_func_en(bp, p->func_id, 1);
2968
2969 /* spq */
2970 if (p->func_flgs & FUNC_FLG_SPQ) {
2971 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2972 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2973 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2974 }
2975}
2976
6383c0b3 2977/**
16a5fd92 2978 * bnx2x_get_common_flags - Return common flags
6383c0b3
AE
2979 *
2980 * @bp device handle
2981 * @fp queue handle
2982 * @zero_stats TRUE if statistics zeroing is needed
2983 *
2984 * Return the flags that are common for the Tx-only and not normal connections.
2985 */
1191cb83
ED
2986static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2987 struct bnx2x_fastpath *fp,
2988 bool zero_stats)
28912902 2989{
619c5cb6
VZ
2990 unsigned long flags = 0;
2991
2992 /* PF driver will always initialize the Queue to an ACTIVE state */
2993 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2994
6383c0b3 2995 /* tx only connections collect statistics (on the same index as the
91226790
DK
2996 * parent connection). The statistics are zeroed when the parent
2997 * connection is initialized.
6383c0b3 2998 */
50f0a562
BW
2999
3000 __set_bit(BNX2X_Q_FLG_STATS, &flags);
3001 if (zero_stats)
3002 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
3003
91226790 3004 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
e287a75c 3005 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
6383c0b3 3006
823e1d90
YM
3007#ifdef BNX2X_STOP_ON_ERROR
3008 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
3009#endif
3010
6383c0b3
AE
3011 return flags;
3012}
3013
1191cb83
ED
3014static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
3015 struct bnx2x_fastpath *fp,
3016 bool leading)
6383c0b3
AE
3017{
3018 unsigned long flags = 0;
3019
619c5cb6
VZ
3020 /* calculate other queue flags */
3021 if (IS_MF_SD(bp))
3022 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 3023
a3348722 3024 if (IS_FCOE_FP(fp)) {
619c5cb6 3025 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
3026 /* For FCoE - force usage of default priority (for afex) */
3027 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
3028 }
523224a3 3029
f5219d8e 3030 if (!fp->disable_tpa) {
619c5cb6 3031 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 3032 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
3033 if (fp->mode == TPA_MODE_GRO)
3034 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 3035 }
619c5cb6 3036
619c5cb6
VZ
3037 if (leading) {
3038 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3039 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3040 }
523224a3 3041
619c5cb6
VZ
3042 /* Always set HW VLAN stripping */
3043 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 3044
a3348722
BW
3045 /* configure silent vlan removal */
3046 if (IS_MF_AFEX(bp))
3047 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3048
6383c0b3 3049 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
3050}
3051
619c5cb6 3052static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
3053 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3054 u8 cos)
619c5cb6
VZ
3055{
3056 gen_init->stat_id = bnx2x_stats_id(fp);
3057 gen_init->spcl_id = fp->cl_id;
3058
3059 /* Always use mini-jumbo MTU for FCoE L2 ring */
3060 if (IS_FCOE_FP(fp))
3061 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3062 else
3063 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
3064
3065 gen_init->cos = cos;
619c5cb6
VZ
3066}
3067
3068static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 3069 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 3070 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 3071{
619c5cb6 3072 u8 max_sge = 0;
523224a3
DK
3073 u16 sge_sz = 0;
3074 u16 tpa_agg_size = 0;
3075
523224a3 3076 if (!fp->disable_tpa) {
dfacf138
DK
3077 pause->sge_th_lo = SGE_TH_LO(bp);
3078 pause->sge_th_hi = SGE_TH_HI(bp);
3079
3080 /* validate SGE ring has enough to cross high threshold */
3081 WARN_ON(bp->dropless_fc &&
3082 pause->sge_th_hi + FW_PREFETCH_CNT >
3083 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3084
924d75ab 3085 tpa_agg_size = TPA_AGG_SIZE;
523224a3
DK
3086 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3087 SGE_PAGE_SHIFT;
3088 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3089 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
924d75ab 3090 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
523224a3
DK
3091 }
3092
3093 /* pause - not for e1 */
3094 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
3095 pause->bd_th_lo = BD_TH_LO(bp);
3096 pause->bd_th_hi = BD_TH_HI(bp);
3097
3098 pause->rcq_th_lo = RCQ_TH_LO(bp);
3099 pause->rcq_th_hi = RCQ_TH_HI(bp);
3100 /*
3101 * validate that rings have enough entries to cross
3102 * high thresholds
3103 */
3104 WARN_ON(bp->dropless_fc &&
3105 pause->bd_th_hi + FW_PREFETCH_CNT >
3106 bp->rx_ring_size);
3107 WARN_ON(bp->dropless_fc &&
3108 pause->rcq_th_hi + FW_PREFETCH_CNT >
3109 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 3110
523224a3
DK
3111 pause->pri_map = 1;
3112 }
3113
3114 /* rxq setup */
523224a3
DK
3115 rxq_init->dscr_map = fp->rx_desc_mapping;
3116 rxq_init->sge_map = fp->rx_sge_mapping;
3117 rxq_init->rcq_map = fp->rx_comp_mapping;
3118 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 3119
619c5cb6
VZ
3120 /* This should be a maximum number of data bytes that may be
3121 * placed on the BD (not including paddings).
3122 */
e52fcb24 3123 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
3cdeec22 3124 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 3125
523224a3 3126 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
3127 rxq_init->tpa_agg_sz = tpa_agg_size;
3128 rxq_init->sge_buf_sz = sge_sz;
3129 rxq_init->max_sges_pkt = max_sge;
619c5cb6 3130 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 3131 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
3132
3133 /* Maximum number or simultaneous TPA aggregation for this Queue.
3134 *
2de67439 3135 * For PF Clients it should be the maximum available number.
619c5cb6
VZ
3136 * VF driver(s) may want to define it to a smaller value.
3137 */
dfacf138 3138 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 3139
523224a3
DK
3140 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3141 rxq_init->fw_sb_id = fp->fw_sb_id;
3142
ec6ba945
VZ
3143 if (IS_FCOE_FP(fp))
3144 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3145 else
6383c0b3 3146 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
3147 /* configure silent vlan removal
3148 * if multi function mode is afex, then mask default vlan
3149 */
3150 if (IS_MF_AFEX(bp)) {
3151 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3152 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3153 }
523224a3
DK
3154}
3155
619c5cb6 3156static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
3157 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3158 u8 cos)
523224a3 3159{
65565884 3160 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 3161 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
3162 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3163 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 3164
619c5cb6 3165 /*
16a5fd92 3166 * set the tss leading client id for TX classification ==
619c5cb6
VZ
3167 * leading RSS client id
3168 */
3169 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3170
ec6ba945
VZ
3171 if (IS_FCOE_FP(fp)) {
3172 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3173 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3174 }
523224a3
DK
3175}
3176
8d96286a 3177static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
3178{
3179 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
3180 struct event_ring_data eq_data = { {0} };
3181 u16 flags;
3182
619c5cb6 3183 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3184 /* reset IGU PF statistics: MSIX + ATTN */
3185 /* PF */
3186 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3187 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3188 (CHIP_MODE_IS_4_PORT(bp) ?
3189 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3190 /* ATTN */
3191 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3192 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3193 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3194 (CHIP_MODE_IS_4_PORT(bp) ?
3195 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3196 }
3197
523224a3
DK
3198 /* function setup flags */
3199 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3200
619c5cb6
VZ
3201 /* This flag is relevant for E1x only.
3202 * E2 doesn't have a TPA configuration in a function level.
523224a3 3203 */
619c5cb6 3204 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
3205
3206 func_init.func_flgs = flags;
3207 func_init.pf_id = BP_FUNC(bp);
3208 func_init.func_id = BP_FUNC(bp);
523224a3
DK
3209 func_init.spq_map = bp->spq_mapping;
3210 func_init.spq_prod = bp->spq_prod_idx;
3211
3212 bnx2x_func_init(bp, &func_init);
3213
3214 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3215
3216 /*
619c5cb6
VZ
3217 * Congestion management values depend on the link rate
3218 * There is no active link so initial link rate is set to 10 Gbps.
3219 * When the link comes up The congestion management values are
3220 * re-calculated according to the actual link rate.
3221 */
523224a3
DK
3222 bp->link_vars.line_speed = SPEED_10000;
3223 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3224
3225 /* Only the PMF sets the HW */
3226 if (bp->port.pmf)
3227 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3228
86564c3f 3229 /* init Event Queue - PCI bus guarantees correct endianity*/
523224a3
DK
3230 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3231 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3232 eq_data.producer = bp->eq_prod;
3233 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3234 eq_data.sb_id = DEF_SB_ID;
3235 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3236}
3237
523224a3
DK
3238static void bnx2x_e1h_disable(struct bnx2x *bp)
3239{
3240 int port = BP_PORT(bp);
3241
619c5cb6 3242 bnx2x_tx_disable(bp);
523224a3
DK
3243
3244 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3245}
3246
3247static void bnx2x_e1h_enable(struct bnx2x *bp)
3248{
3249 int port = BP_PORT(bp);
3250
3251 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3252
16a5fd92 3253 /* Tx queue should be only re-enabled */
523224a3
DK
3254 netif_tx_wake_all_queues(bp->dev);
3255
3256 /*
3257 * Should not call netif_carrier_on since it will be called if the link
3258 * is up when checking for link state
3259 */
3260}
3261
1d187b34
BW
3262#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3263
3264static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3265{
3266 struct eth_stats_info *ether_stat =
3267 &bp->slowpath->drv_info_to_mcp.ether_stat;
3ec9f9ca
AE
3268 struct bnx2x_vlan_mac_obj *mac_obj =
3269 &bp->sp_objs->mac_obj;
3270 int i;
1d187b34 3271
786fdf0b
DC
3272 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3273 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3274
3ec9f9ca
AE
3275 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3276 * mac_local field in ether_stat struct. The base address is offset by 2
3277 * bytes to account for the field being 8 bytes but a mac address is
3278 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3279 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3280 * allocated by the ether_stat struct, so the macs will land in their
3281 * proper positions.
3282 */
3283 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3284 memset(ether_stat->mac_local + i, 0,
3285 sizeof(ether_stat->mac_local[0]));
3286 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3287 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3288 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3289 ETH_ALEN);
1d187b34 3290 ether_stat->mtu_size = bp->dev->mtu;
1d187b34
BW
3291 if (bp->dev->features & NETIF_F_RXCSUM)
3292 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3293 if (bp->dev->features & NETIF_F_TSO)
3294 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3295 ether_stat->feature_flags |= bp->common.boot_mode;
3296
3297 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3298
3299 ether_stat->txq_size = bp->tx_ring_size;
3300 ether_stat->rxq_size = bp->rx_ring_size;
0c757dee
YM
3301
3302 ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
1d187b34
BW
3303}
3304
3305static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3306{
3307 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3308 struct fcoe_stats_info *fcoe_stat =
3309 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3310
55c11941
MS
3311 if (!CNIC_LOADED(bp))
3312 return;
3313
3ec9f9ca 3314 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
1d187b34
BW
3315
3316 fcoe_stat->qos_priority =
3317 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3318
3319 /* insert FCoE stats from ramrod response */
3320 if (!NO_FCOE(bp)) {
3321 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3322 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3323 tstorm_queue_statistics;
3324
3325 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3326 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3327 xstorm_queue_statistics;
3328
3329 struct fcoe_statistics_params *fw_fcoe_stat =
3330 &bp->fw_stats_data->fcoe;
3331
86564c3f
YM
3332 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3333 fcoe_stat->rx_bytes_lo,
3334 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
1d187b34 3335
86564c3f
YM
3336 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3337 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3338 fcoe_stat->rx_bytes_lo,
3339 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
1d187b34 3340
86564c3f
YM
3341 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3342 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3343 fcoe_stat->rx_bytes_lo,
3344 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
1d187b34 3345
86564c3f
YM
3346 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3347 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3348 fcoe_stat->rx_bytes_lo,
3349 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
1d187b34 3350
86564c3f
YM
3351 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3352 fcoe_stat->rx_frames_lo,
3353 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
1d187b34 3354
86564c3f
YM
3355 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3356 fcoe_stat->rx_frames_lo,
3357 fcoe_q_tstorm_stats->rcv_ucast_pkts);
1d187b34 3358
86564c3f
YM
3359 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3360 fcoe_stat->rx_frames_lo,
3361 fcoe_q_tstorm_stats->rcv_bcast_pkts);
1d187b34 3362
86564c3f
YM
3363 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3364 fcoe_stat->rx_frames_lo,
3365 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34 3366
86564c3f
YM
3367 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3368 fcoe_stat->tx_bytes_lo,
3369 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
1d187b34 3370
86564c3f
YM
3371 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3372 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3373 fcoe_stat->tx_bytes_lo,
3374 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
1d187b34 3375
86564c3f
YM
3376 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3377 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3378 fcoe_stat->tx_bytes_lo,
3379 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
1d187b34 3380
86564c3f
YM
3381 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3382 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3383 fcoe_stat->tx_bytes_lo,
3384 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
1d187b34 3385
86564c3f
YM
3386 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3387 fcoe_stat->tx_frames_lo,
3388 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
1d187b34 3389
86564c3f
YM
3390 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3391 fcoe_stat->tx_frames_lo,
3392 fcoe_q_xstorm_stats->ucast_pkts_sent);
1d187b34 3393
86564c3f
YM
3394 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3395 fcoe_stat->tx_frames_lo,
3396 fcoe_q_xstorm_stats->bcast_pkts_sent);
1d187b34 3397
86564c3f
YM
3398 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3399 fcoe_stat->tx_frames_lo,
3400 fcoe_q_xstorm_stats->mcast_pkts_sent);
1d187b34
BW
3401 }
3402
1d187b34
BW
3403 /* ask L5 driver to add data to the struct */
3404 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3405}
3406
3407static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3408{
3409 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3410 struct iscsi_stats_info *iscsi_stat =
3411 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3412
55c11941
MS
3413 if (!CNIC_LOADED(bp))
3414 return;
3415
3ec9f9ca
AE
3416 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3417 ETH_ALEN);
1d187b34
BW
3418
3419 iscsi_stat->qos_priority =
3420 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3421
1d187b34
BW
3422 /* ask L5 driver to add data to the struct */
3423 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3424}
3425
0793f83f
DK
3426/* called due to MCP event (on pmf):
3427 * reread new bandwidth configuration
3428 * configure FW
3429 * notify others function about the change
3430 */
1191cb83 3431static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3432{
3433 if (bp->link_vars.link_up) {
3434 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3435 bnx2x_link_sync_notify(bp);
3436 }
3437 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3438}
3439
1191cb83 3440static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3441{
3442 bnx2x_config_mf_bw(bp);
3443 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3444}
3445
c8c60d88
YM
3446static void bnx2x_handle_eee_event(struct bnx2x *bp)
3447{
3448 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3449 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3450}
3451
1d187b34
BW
3452static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3453{
3454 enum drv_info_opcode op_code;
3455 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3456
3457 /* if drv_info version supported by MFW doesn't match - send NACK */
3458 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3459 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3460 return;
3461 }
3462
3463 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3464 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3465
3466 memset(&bp->slowpath->drv_info_to_mcp, 0,
3467 sizeof(union drv_info_to_mcp));
3468
3469 switch (op_code) {
3470 case ETH_STATS_OPCODE:
3471 bnx2x_drv_info_ether_stat(bp);
3472 break;
3473 case FCOE_STATS_OPCODE:
3474 bnx2x_drv_info_fcoe_stat(bp);
3475 break;
3476 case ISCSI_STATS_OPCODE:
3477 bnx2x_drv_info_iscsi_stat(bp);
3478 break;
3479 default:
3480 /* if op code isn't supported - send NACK */
3481 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3482 return;
3483 }
3484
3485 /* if we got drv_info attn from MFW then these fields are defined in
3486 * shmem2 for sure
3487 */
3488 SHMEM2_WR(bp, drv_info_host_addr_lo,
3489 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3490 SHMEM2_WR(bp, drv_info_host_addr_hi,
3491 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3492
3493 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3494}
3495
523224a3
DK
3496static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3497{
3498 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3499
3500 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3501
3502 /*
3503 * This is the only place besides the function initialization
3504 * where the bp->flags can change so it is done without any
3505 * locks
3506 */
f2e0899f 3507 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3508 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3509 bp->flags |= MF_FUNC_DIS;
3510
3511 bnx2x_e1h_disable(bp);
3512 } else {
51c1a580 3513 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3514 bp->flags &= ~MF_FUNC_DIS;
3515
3516 bnx2x_e1h_enable(bp);
3517 }
3518 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3519 }
3520 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3521 bnx2x_config_mf_bw(bp);
523224a3
DK
3522 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3523 }
3524
3525 /* Report results to MCP */
3526 if (dcc_event)
3527 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3528 else
3529 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3530}
3531
3532/* must be called under the spq lock */
1191cb83 3533static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3534{
3535 struct eth_spe *next_spe = bp->spq_prod_bd;
3536
3537 if (bp->spq_prod_bd == bp->spq_last_bd) {
3538 bp->spq_prod_bd = bp->spq;
3539 bp->spq_prod_idx = 0;
51c1a580 3540 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3541 } else {
3542 bp->spq_prod_bd++;
3543 bp->spq_prod_idx++;
3544 }
3545 return next_spe;
3546}
3547
3548/* must be called under the spq lock */
1191cb83 3549static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3550{
3551 int func = BP_FUNC(bp);
3552
53e51e2f
VZ
3553 /*
3554 * Make sure that BD data is updated before writing the producer:
3555 * BD data is written to the memory, the producer is read from the
3556 * memory, thus we need a full memory barrier to ensure the ordering.
3557 */
3558 mb();
28912902 3559
523224a3 3560 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3561 bp->spq_prod_idx);
28912902
MC
3562 mmiowb();
3563}
3564
619c5cb6
VZ
3565/**
3566 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3567 *
3568 * @cmd: command to check
3569 * @cmd_type: command type
3570 */
1191cb83 3571static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3572{
3573 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3574 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3575 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3576 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3577 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3578 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3579 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3580 return true;
3581 else
3582 return false;
619c5cb6
VZ
3583}
3584
619c5cb6
VZ
3585/**
3586 * bnx2x_sp_post - place a single command on an SP ring
3587 *
3588 * @bp: driver handle
3589 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3590 * @cid: SW CID the command is related to
3591 * @data_hi: command private data address (high 32 bits)
3592 * @data_lo: command private data address (low 32 bits)
3593 * @cmd_type: command type (e.g. NONE, ETH)
3594 *
3595 * SP data is handled as if it's always an address pair, thus data fields are
3596 * not swapped to little endian in upper functions. Instead this function swaps
3597 * data as if it's two u32 fields.
3598 */
9f6c9258 3599int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3600 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3601{
28912902 3602 struct eth_spe *spe;
523224a3 3603 u16 type;
619c5cb6 3604 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3605
a2fbb9ea 3606#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3607 if (unlikely(bp->panic)) {
3608 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3609 return -EIO;
51c1a580 3610 }
a2fbb9ea
ET
3611#endif
3612
34f80b04 3613 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3614
6e30dd4e
VZ
3615 if (common) {
3616 if (!atomic_read(&bp->eq_spq_left)) {
3617 BNX2X_ERR("BUG! EQ ring full!\n");
3618 spin_unlock_bh(&bp->spq_lock);
3619 bnx2x_panic();
3620 return -EBUSY;
3621 }
3622 } else if (!atomic_read(&bp->cq_spq_left)) {
3623 BNX2X_ERR("BUG! SPQ ring full!\n");
3624 spin_unlock_bh(&bp->spq_lock);
3625 bnx2x_panic();
3626 return -EBUSY;
a2fbb9ea 3627 }
f1410647 3628
28912902
MC
3629 spe = bnx2x_sp_get_next(bp);
3630
a2fbb9ea 3631 /* CID needs port number to be encoded int it */
28912902 3632 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3633 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3634 HW_CID(bp, cid));
523224a3 3635
619c5cb6 3636 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3637
523224a3
DK
3638 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3639 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3640
523224a3
DK
3641 spe->hdr.type = cpu_to_le16(type);
3642
3643 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3644 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3645
d6cae238
VZ
3646 /*
3647 * It's ok if the actual decrement is issued towards the memory
3648 * somewhere between the spin_lock and spin_unlock. Thus no
16a5fd92 3649 * more explicit memory barrier is needed.
d6cae238
VZ
3650 */
3651 if (common)
3652 atomic_dec(&bp->eq_spq_left);
3653 else
3654 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3655
51c1a580
MS
3656 DP(BNX2X_MSG_SP,
3657 "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
3658 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3659 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3660 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3661 HW_CID(bp, cid), data_hi, data_lo, type,
3662 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3663
28912902 3664 bnx2x_sp_prod_update(bp);
34f80b04 3665 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3666 return 0;
3667}
3668
3669/* acquire split MCP access lock register */
4a37fb66 3670static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3671{
72fd0718 3672 u32 j, val;
34f80b04 3673 int rc = 0;
a2fbb9ea
ET
3674
3675 might_sleep();
72fd0718 3676 for (j = 0; j < 1000; j++) {
3cdeec22
YM
3677 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
3678 val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
3679 if (val & MCPR_ACCESS_LOCK_LOCK)
a2fbb9ea
ET
3680 break;
3681
639d65b8 3682 usleep_range(5000, 10000);
a2fbb9ea 3683 }
3cdeec22 3684 if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
19680c48 3685 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3686 rc = -EBUSY;
3687 }
3688
3689 return rc;
3690}
3691
4a37fb66
YG
3692/* release split MCP access lock register */
3693static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3694{
3cdeec22 3695 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
a2fbb9ea
ET
3696}
3697
523224a3
DK
3698#define BNX2X_DEF_SB_ATT_IDX 0x0001
3699#define BNX2X_DEF_SB_IDX 0x0002
3700
1191cb83 3701static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3702{
523224a3 3703 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3704 u16 rc = 0;
3705
3706 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3707 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3708 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3709 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3710 }
523224a3
DK
3711
3712 if (bp->def_idx != def_sb->sp_sb.running_index) {
3713 bp->def_idx = def_sb->sp_sb.running_index;
3714 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3715 }
523224a3 3716
16a5fd92 3717 /* Do not reorder: indices reading should complete before handling */
523224a3 3718 barrier();
a2fbb9ea
ET
3719 return rc;
3720}
3721
3722/*
3723 * slow path service functions
3724 */
3725
3726static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3727{
34f80b04 3728 int port = BP_PORT(bp);
a2fbb9ea
ET
3729 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3730 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3731 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3732 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3733 u32 aeu_mask;
87942b46 3734 u32 nig_mask = 0;
f2e0899f 3735 u32 reg_addr;
a2fbb9ea 3736
a2fbb9ea
ET
3737 if (bp->attn_state & asserted)
3738 BNX2X_ERR("IGU ERROR\n");
3739
3fcaf2e5
EG
3740 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3741 aeu_mask = REG_RD(bp, aeu_addr);
3742
a2fbb9ea 3743 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3744 aeu_mask, asserted);
72fd0718 3745 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3746 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3747
3fcaf2e5
EG
3748 REG_WR(bp, aeu_addr, aeu_mask);
3749 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3750
3fcaf2e5 3751 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3752 bp->attn_state |= asserted;
3fcaf2e5 3753 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3754
3755 if (asserted & ATTN_HARD_WIRED_MASK) {
3756 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3757
a5e9a7cf
EG
3758 bnx2x_acquire_phy_lock(bp);
3759
877e9aa4 3760 /* save nig interrupt mask */
87942b46 3761 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3762
361c391e
YR
3763 /* If nig_mask is not set, no need to call the update
3764 * function.
3765 */
3766 if (nig_mask) {
3767 REG_WR(bp, nig_int_mask_addr, 0);
3768
3769 bnx2x_link_attn(bp);
3770 }
a2fbb9ea
ET
3771
3772 /* handle unicore attn? */
3773 }
3774 if (asserted & ATTN_SW_TIMER_4_FUNC)
3775 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3776
3777 if (asserted & GPIO_2_FUNC)
3778 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3779
3780 if (asserted & GPIO_3_FUNC)
3781 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3782
3783 if (asserted & GPIO_4_FUNC)
3784 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3785
3786 if (port == 0) {
3787 if (asserted & ATTN_GENERAL_ATTN_1) {
3788 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3789 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3790 }
3791 if (asserted & ATTN_GENERAL_ATTN_2) {
3792 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3793 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3794 }
3795 if (asserted & ATTN_GENERAL_ATTN_3) {
3796 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3797 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3798 }
3799 } else {
3800 if (asserted & ATTN_GENERAL_ATTN_4) {
3801 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3802 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3803 }
3804 if (asserted & ATTN_GENERAL_ATTN_5) {
3805 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3806 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3807 }
3808 if (asserted & ATTN_GENERAL_ATTN_6) {
3809 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3810 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3811 }
3812 }
3813
3814 } /* if hardwired */
3815
f2e0899f
DK
3816 if (bp->common.int_block == INT_BLOCK_HC)
3817 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3818 COMMAND_REG_ATTN_BITS_SET);
3819 else
3820 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3821
3822 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3823 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3824 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3825
3826 /* now set back the mask */
a5e9a7cf 3827 if (asserted & ATTN_NIG_FOR_FUNC) {
27c1151c
YR
3828 /* Verify that IGU ack through BAR was written before restoring
3829 * NIG mask. This loop should exit after 2-3 iterations max.
3830 */
3831 if (bp->common.int_block != INT_BLOCK_HC) {
3832 u32 cnt = 0, igu_acked;
3833 do {
3834 igu_acked = REG_RD(bp,
3835 IGU_REG_ATTENTION_ACK_BITS);
3836 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3837 (++cnt < MAX_IGU_ATTN_ACK_TO));
3838 if (!igu_acked)
3839 DP(NETIF_MSG_HW,
3840 "Failed to verify IGU ack on time\n");
3841 barrier();
3842 }
87942b46 3843 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3844 bnx2x_release_phy_lock(bp);
3845 }
a2fbb9ea
ET
3846}
3847
1191cb83 3848static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3849{
3850 int port = BP_PORT(bp);
b7737c9b 3851 u32 ext_phy_config;
fd4ef40d 3852 /* mark the failure */
b7737c9b
YR
3853 ext_phy_config =
3854 SHMEM_RD(bp,
3855 dev_info.port_hw_config[port].external_phy_config);
3856
3857 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3858 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3859 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3860 ext_phy_config);
fd4ef40d
EG
3861
3862 /* log the failure */
51c1a580
MS
3863 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3864 "Please contact OEM Support for assistance\n");
8304859a 3865
16a5fd92 3866 /* Schedule device reset (unload)
8304859a
AE
3867 * This is due to some boards consuming sufficient power when driver is
3868 * up to overheat if fan fails.
3869 */
3870 smp_mb__before_clear_bit();
3871 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3872 smp_mb__after_clear_bit();
3873 schedule_delayed_work(&bp->sp_rtnl_task, 0);
fd4ef40d 3874}
ab6ad5a4 3875
1191cb83 3876static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3877{
34f80b04 3878 int port = BP_PORT(bp);
877e9aa4 3879 int reg_offset;
d90d96ba 3880 u32 val;
877e9aa4 3881
34f80b04
EG
3882 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3883 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3884
34f80b04 3885 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3886
3887 val = REG_RD(bp, reg_offset);
3888 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3889 REG_WR(bp, reg_offset, val);
3890
3891 BNX2X_ERR("SPIO5 hw attention\n");
3892
fd4ef40d 3893 /* Fan failure attention */
d90d96ba 3894 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3895 bnx2x_fan_failure(bp);
877e9aa4 3896 }
34f80b04 3897
3deb8167 3898 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3899 bnx2x_acquire_phy_lock(bp);
3900 bnx2x_handle_module_detect_int(&bp->link_params);
3901 bnx2x_release_phy_lock(bp);
3902 }
3903
34f80b04
EG
3904 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3905
3906 val = REG_RD(bp, reg_offset);
3907 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3908 REG_WR(bp, reg_offset, val);
3909
3910 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3911 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3912 bnx2x_panic();
3913 }
877e9aa4
ET
3914}
3915
1191cb83 3916static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3917{
3918 u32 val;
3919
0626b899 3920 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3921
3922 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3923 BNX2X_ERR("DB hw attention 0x%x\n", val);
3924 /* DORQ discard attention */
3925 if (val & 0x2)
3926 BNX2X_ERR("FATAL error from DORQ\n");
3927 }
34f80b04
EG
3928
3929 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3930
3931 int port = BP_PORT(bp);
3932 int reg_offset;
3933
3934 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3935 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3936
3937 val = REG_RD(bp, reg_offset);
3938 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3939 REG_WR(bp, reg_offset, val);
3940
3941 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3942 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3943 bnx2x_panic();
3944 }
877e9aa4
ET
3945}
3946
1191cb83 3947static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3948{
3949 u32 val;
3950
3951 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3952
3953 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3954 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3955 /* CFC error attention */
3956 if (val & 0x2)
3957 BNX2X_ERR("FATAL error from CFC\n");
3958 }
3959
3960 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3961 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3962 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3963 /* RQ_USDMDP_FIFO_OVERFLOW */
3964 if (val & 0x18000)
3965 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3966
3967 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3968 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3969 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3970 }
877e9aa4 3971 }
34f80b04
EG
3972
3973 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3974
3975 int port = BP_PORT(bp);
3976 int reg_offset;
3977
3978 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3979 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3980
3981 val = REG_RD(bp, reg_offset);
3982 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3983 REG_WR(bp, reg_offset, val);
3984
3985 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3986 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3987 bnx2x_panic();
3988 }
877e9aa4
ET
3989}
3990
1191cb83 3991static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3992{
34f80b04
EG
3993 u32 val;
3994
877e9aa4
ET
3995 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3996
34f80b04
EG
3997 if (attn & BNX2X_PMF_LINK_ASSERT) {
3998 int func = BP_FUNC(bp);
3999
4000 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 4001 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
4002 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
4003 func_mf_config[BP_ABS_FUNC(bp)].config);
4004 val = SHMEM_RD(bp,
4005 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
4006 if (val & DRV_STATUS_DCC_EVENT_MASK)
4007 bnx2x_dcc_event(bp,
4008 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
4009
4010 if (val & DRV_STATUS_SET_MF_BW)
4011 bnx2x_set_mf_bw(bp);
4012
1d187b34
BW
4013 if (val & DRV_STATUS_DRV_INFO_REQ)
4014 bnx2x_handle_drv_info_req(bp);
d16132ce
AE
4015
4016 if (val & DRV_STATUS_VF_DISABLED)
4017 bnx2x_vf_handle_flr_event(bp);
4018
2691d51d 4019 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
4020 bnx2x_pmf_update(bp);
4021
e4901dde 4022 if (bp->port.pmf &&
785b9b1a
SR
4023 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
4024 bp->dcbx_enabled > 0)
e4901dde
VZ
4025 /* start dcbx state machine */
4026 bnx2x_dcbx_set_params(bp,
4027 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
4028 if (val & DRV_STATUS_AFEX_EVENT_MASK)
4029 bnx2x_handle_afex_cmd(bp,
4030 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
4031 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
4032 bnx2x_handle_eee_event(bp);
3deb8167
YR
4033 if (bp->link_vars.periodic_flags &
4034 PERIODIC_FLAGS_LINK_EVENT) {
4035 /* sync with link */
4036 bnx2x_acquire_phy_lock(bp);
4037 bp->link_vars.periodic_flags &=
4038 ~PERIODIC_FLAGS_LINK_EVENT;
4039 bnx2x_release_phy_lock(bp);
4040 if (IS_MF(bp))
4041 bnx2x_link_sync_notify(bp);
4042 bnx2x_link_report(bp);
4043 }
4044 /* Always call it here: bnx2x_link_report() will
4045 * prevent the link indication duplication.
4046 */
4047 bnx2x__link_status_update(bp);
34f80b04 4048 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
4049
4050 BNX2X_ERR("MC assert!\n");
d6cae238 4051 bnx2x_mc_assert(bp);
877e9aa4
ET
4052 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4053 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4054 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4055 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4056 bnx2x_panic();
4057
4058 } else if (attn & BNX2X_MCP_ASSERT) {
4059
4060 BNX2X_ERR("MCP assert!\n");
4061 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 4062 bnx2x_fw_dump(bp);
877e9aa4
ET
4063
4064 } else
4065 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4066 }
4067
4068 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
4069 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4070 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
4071 val = CHIP_IS_E1(bp) ? 0 :
4072 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
4073 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4074 }
4075 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
4076 val = CHIP_IS_E1(bp) ? 0 :
4077 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
4078 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4079 }
877e9aa4 4080 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
4081 }
4082}
4083
c9ee9206
VZ
4084/*
4085 * Bits map:
4086 * 0-7 - Engine0 load counter.
4087 * 8-15 - Engine1 load counter.
4088 * 16 - Engine0 RESET_IN_PROGRESS bit.
4089 * 17 - Engine1 RESET_IN_PROGRESS bit.
4090 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4091 * on the engine
4092 * 19 - Engine1 ONE_IS_LOADED.
4093 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4094 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4095 * just the one belonging to its engine).
4096 *
4097 */
4098#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4099
4100#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4101#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4102#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4103#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4104#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4105#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4106#define BNX2X_GLOBAL_RESET_BIT 0x00040000
4107
4108/*
4109 * Set the GLOBAL_RESET bit.
4110 *
4111 * Should be run under rtnl lock
4112 */
4113void bnx2x_set_reset_global(struct bnx2x *bp)
4114{
f16da43b
AE
4115 u32 val;
4116 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4117 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4118 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 4119 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
4120}
4121
4122/*
4123 * Clear the GLOBAL_RESET bit.
4124 *
4125 * Should be run under rtnl lock
4126 */
1191cb83 4127static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 4128{
f16da43b
AE
4129 u32 val;
4130 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4131 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4132 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 4133 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 4134}
f85582f8 4135
72fd0718 4136/*
c9ee9206
VZ
4137 * Checks the GLOBAL_RESET bit.
4138 *
72fd0718
VZ
4139 * should be run under rtnl lock
4140 */
1191cb83 4141static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206 4142{
3cdeec22 4143 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4144
4145 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4146 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4147}
4148
4149/*
4150 * Clear RESET_IN_PROGRESS bit for the current engine.
4151 *
4152 * Should be run under rtnl lock
4153 */
1191cb83 4154static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 4155{
f16da43b 4156 u32 val;
c9ee9206
VZ
4157 u32 bit = BP_PATH(bp) ?
4158 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4159 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4160 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4161
4162 /* Clear the bit */
4163 val &= ~bit;
4164 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4165
4166 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4167}
4168
4169/*
c9ee9206
VZ
4170 * Set RESET_IN_PROGRESS for the current engine.
4171 *
72fd0718
VZ
4172 * should be run under rtnl lock
4173 */
c9ee9206 4174void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 4175{
f16da43b 4176 u32 val;
c9ee9206
VZ
4177 u32 bit = BP_PATH(bp) ?
4178 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4179 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4180 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4181
4182 /* Set the bit */
4183 val |= bit;
4184 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4185 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4186}
4187
4188/*
c9ee9206 4189 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
4190 * should be run under rtnl lock
4191 */
c9ee9206 4192bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 4193{
3cdeec22 4194 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4195 u32 bit = engine ?
4196 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4197
4198 /* return false if bit is set */
4199 return (val & bit) ? false : true;
72fd0718
VZ
4200}
4201
4202/*
889b9af3 4203 * set pf load for the current pf.
c9ee9206 4204 *
72fd0718
VZ
4205 * should be run under rtnl lock
4206 */
889b9af3 4207void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 4208{
f16da43b 4209 u32 val1, val;
c9ee9206
VZ
4210 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4211 BNX2X_PATH0_LOAD_CNT_MASK;
4212 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4213 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4214
f16da43b
AE
4215 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4216 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4217
51c1a580 4218 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4219
c9ee9206
VZ
4220 /* get the current counter value */
4221 val1 = (val & mask) >> shift;
4222
889b9af3
AE
4223 /* set bit of that PF */
4224 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
4225
4226 /* clear the old value */
4227 val &= ~mask;
4228
4229 /* set the new one */
4230 val |= ((val1 << shift) & mask);
4231
4232 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4233 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4234}
4235
c9ee9206 4236/**
889b9af3 4237 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
4238 *
4239 * @bp: driver handle
4240 *
4241 * Should be run under rtnl lock.
4242 * Decrements the load counter for the current engine. Returns
889b9af3 4243 * whether other functions are still loaded
72fd0718 4244 */
889b9af3 4245bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 4246{
f16da43b 4247 u32 val1, val;
c9ee9206
VZ
4248 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4249 BNX2X_PATH0_LOAD_CNT_MASK;
4250 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4251 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4252
f16da43b
AE
4253 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4254 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4255 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4256
c9ee9206
VZ
4257 /* get the current counter value */
4258 val1 = (val & mask) >> shift;
4259
889b9af3
AE
4260 /* clear bit of that PF */
4261 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4262
4263 /* clear the old value */
4264 val &= ~mask;
4265
4266 /* set the new one */
4267 val |= ((val1 << shift) & mask);
4268
4269 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4270 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4271 return val1 != 0;
72fd0718
VZ
4272}
4273
4274/*
889b9af3 4275 * Read the load status for the current engine.
c9ee9206 4276 *
72fd0718
VZ
4277 * should be run under rtnl lock
4278 */
1191cb83 4279static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4280{
c9ee9206
VZ
4281 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4282 BNX2X_PATH0_LOAD_CNT_MASK);
4283 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4284 BNX2X_PATH0_LOAD_CNT_SHIFT);
4285 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4286
51c1a580 4287 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4288
4289 val = (val & mask) >> shift;
4290
51c1a580
MS
4291 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4292 engine, val);
c9ee9206 4293
889b9af3 4294 return val != 0;
72fd0718
VZ
4295}
4296
6bf07b8e
YM
4297static void _print_parity(struct bnx2x *bp, u32 reg)
4298{
4299 pr_cont(" [0x%08x] ", REG_RD(bp, reg));
4300}
4301
1191cb83 4302static void _print_next_block(int idx, const char *blk)
72fd0718 4303{
f1deab50 4304 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4305}
4306
4293b9f5
DK
4307static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4308 int *par_num, bool print)
72fd0718 4309{
4293b9f5
DK
4310 u32 cur_bit;
4311 bool res;
4312 int i;
4313
4314 res = false;
4315
72fd0718 4316 for (i = 0; sig; i++) {
4293b9f5 4317 cur_bit = (0x1UL << i);
72fd0718 4318 if (sig & cur_bit) {
4293b9f5
DK
4319 res |= true; /* Each bit is real error! */
4320
4321 if (print) {
4322 switch (cur_bit) {
4323 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4324 _print_next_block((*par_num)++, "BRB");
6bf07b8e
YM
4325 _print_parity(bp,
4326 BRB1_REG_BRB1_PRTY_STS);
4293b9f5
DK
4327 break;
4328 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4329 _print_next_block((*par_num)++,
4330 "PARSER");
6bf07b8e 4331 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
4293b9f5
DK
4332 break;
4333 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4334 _print_next_block((*par_num)++, "TSDM");
6bf07b8e
YM
4335 _print_parity(bp,
4336 TSDM_REG_TSDM_PRTY_STS);
4293b9f5
DK
4337 break;
4338 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4339 _print_next_block((*par_num)++,
c9ee9206 4340 "SEARCHER");
6bf07b8e 4341 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
4293b9f5
DK
4342 break;
4343 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4344 _print_next_block((*par_num)++, "TCM");
4345 _print_parity(bp, TCM_REG_TCM_PRTY_STS);
4346 break;
4347 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4348 _print_next_block((*par_num)++,
4349 "TSEMI");
6bf07b8e
YM
4350 _print_parity(bp,
4351 TSEM_REG_TSEM_PRTY_STS_0);
4352 _print_parity(bp,
4353 TSEM_REG_TSEM_PRTY_STS_1);
4293b9f5
DK
4354 break;
4355 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4356 _print_next_block((*par_num)++, "XPB");
6bf07b8e
YM
4357 _print_parity(bp, GRCBASE_XPB +
4358 PB_REG_PB_PRTY_STS);
4293b9f5 4359 break;
6bf07b8e 4360 }
72fd0718
VZ
4361 }
4362
4363 /* Clear the bit */
4364 sig &= ~cur_bit;
4365 }
4366 }
4367
4293b9f5 4368 return res;
72fd0718
VZ
4369}
4370
4293b9f5
DK
4371static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4372 int *par_num, bool *global,
6bf07b8e 4373 bool print)
72fd0718 4374{
4293b9f5
DK
4375 u32 cur_bit;
4376 bool res;
4377 int i;
4378
4379 res = false;
4380
72fd0718 4381 for (i = 0; sig; i++) {
4293b9f5 4382 cur_bit = (0x1UL << i);
72fd0718 4383 if (sig & cur_bit) {
4293b9f5 4384 res |= true; /* Each bit is real error! */
72fd0718 4385 switch (cur_bit) {
c9ee9206 4386 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
6bf07b8e 4387 if (print) {
4293b9f5 4388 _print_next_block((*par_num)++, "PBF");
6bf07b8e
YM
4389 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4390 }
72fd0718
VZ
4391 break;
4392 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
6bf07b8e 4393 if (print) {
4293b9f5 4394 _print_next_block((*par_num)++, "QM");
6bf07b8e
YM
4395 _print_parity(bp, QM_REG_QM_PRTY_STS);
4396 }
c9ee9206
VZ
4397 break;
4398 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
6bf07b8e 4399 if (print) {
4293b9f5 4400 _print_next_block((*par_num)++, "TM");
6bf07b8e
YM
4401 _print_parity(bp, TM_REG_TM_PRTY_STS);
4402 }
72fd0718
VZ
4403 break;
4404 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
6bf07b8e 4405 if (print) {
4293b9f5 4406 _print_next_block((*par_num)++, "XSDM");
6bf07b8e
YM
4407 _print_parity(bp,
4408 XSDM_REG_XSDM_PRTY_STS);
4409 }
c9ee9206
VZ
4410 break;
4411 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
6bf07b8e 4412 if (print) {
4293b9f5 4413 _print_next_block((*par_num)++, "XCM");
6bf07b8e
YM
4414 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4415 }
72fd0718
VZ
4416 break;
4417 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
6bf07b8e 4418 if (print) {
4293b9f5
DK
4419 _print_next_block((*par_num)++,
4420 "XSEMI");
6bf07b8e
YM
4421 _print_parity(bp,
4422 XSEM_REG_XSEM_PRTY_STS_0);
4423 _print_parity(bp,
4424 XSEM_REG_XSEM_PRTY_STS_1);
4425 }
72fd0718
VZ
4426 break;
4427 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
6bf07b8e 4428 if (print) {
4293b9f5 4429 _print_next_block((*par_num)++,
c9ee9206 4430 "DOORBELLQ");
6bf07b8e
YM
4431 _print_parity(bp,
4432 DORQ_REG_DORQ_PRTY_STS);
4433 }
c9ee9206
VZ
4434 break;
4435 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
6bf07b8e 4436 if (print) {
4293b9f5 4437 _print_next_block((*par_num)++, "NIG");
6bf07b8e
YM
4438 if (CHIP_IS_E1x(bp)) {
4439 _print_parity(bp,
4440 NIG_REG_NIG_PRTY_STS);
4441 } else {
4442 _print_parity(bp,
4443 NIG_REG_NIG_PRTY_STS_0);
4444 _print_parity(bp,
4445 NIG_REG_NIG_PRTY_STS_1);
4446 }
4447 }
72fd0718
VZ
4448 break;
4449 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206 4450 if (print)
4293b9f5 4451 _print_next_block((*par_num)++,
c9ee9206
VZ
4452 "VAUX PCI CORE");
4453 *global = true;
72fd0718
VZ
4454 break;
4455 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
6bf07b8e 4456 if (print) {
4293b9f5
DK
4457 _print_next_block((*par_num)++,
4458 "DEBUG");
6bf07b8e
YM
4459 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4460 }
72fd0718
VZ
4461 break;
4462 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
6bf07b8e 4463 if (print) {
4293b9f5 4464 _print_next_block((*par_num)++, "USDM");
6bf07b8e
YM
4465 _print_parity(bp,
4466 USDM_REG_USDM_PRTY_STS);
4467 }
72fd0718 4468 break;
8736c826 4469 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
6bf07b8e 4470 if (print) {
4293b9f5 4471 _print_next_block((*par_num)++, "UCM");
6bf07b8e
YM
4472 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4473 }
8736c826 4474 break;
72fd0718 4475 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
6bf07b8e 4476 if (print) {
4293b9f5
DK
4477 _print_next_block((*par_num)++,
4478 "USEMI");
6bf07b8e
YM
4479 _print_parity(bp,
4480 USEM_REG_USEM_PRTY_STS_0);
4481 _print_parity(bp,
4482 USEM_REG_USEM_PRTY_STS_1);
4483 }
72fd0718
VZ
4484 break;
4485 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
6bf07b8e 4486 if (print) {
4293b9f5 4487 _print_next_block((*par_num)++, "UPB");
6bf07b8e
YM
4488 _print_parity(bp, GRCBASE_UPB +
4489 PB_REG_PB_PRTY_STS);
4490 }
72fd0718
VZ
4491 break;
4492 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
6bf07b8e 4493 if (print) {
4293b9f5 4494 _print_next_block((*par_num)++, "CSDM");
6bf07b8e
YM
4495 _print_parity(bp,
4496 CSDM_REG_CSDM_PRTY_STS);
4497 }
72fd0718 4498 break;
8736c826 4499 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
6bf07b8e 4500 if (print) {
4293b9f5 4501 _print_next_block((*par_num)++, "CCM");
6bf07b8e
YM
4502 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4503 }
8736c826 4504 break;
72fd0718
VZ
4505 }
4506
4507 /* Clear the bit */
4508 sig &= ~cur_bit;
4509 }
4510 }
4511
4293b9f5 4512 return res;
72fd0718
VZ
4513}
4514
4293b9f5
DK
4515static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4516 int *par_num, bool print)
72fd0718 4517{
4293b9f5
DK
4518 u32 cur_bit;
4519 bool res;
4520 int i;
4521
4522 res = false;
4523
72fd0718 4524 for (i = 0; sig; i++) {
4293b9f5 4525 cur_bit = (0x1UL << i);
72fd0718 4526 if (sig & cur_bit) {
4293b9f5
DK
4527 res |= true; /* Each bit is real error! */
4528 if (print) {
4529 switch (cur_bit) {
4530 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4531 _print_next_block((*par_num)++,
4532 "CSEMI");
6bf07b8e
YM
4533 _print_parity(bp,
4534 CSEM_REG_CSEM_PRTY_STS_0);
4535 _print_parity(bp,
4536 CSEM_REG_CSEM_PRTY_STS_1);
4293b9f5
DK
4537 break;
4538 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4539 _print_next_block((*par_num)++, "PXP");
6bf07b8e
YM
4540 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4541 _print_parity(bp,
4542 PXP2_REG_PXP2_PRTY_STS_0);
4543 _print_parity(bp,
4544 PXP2_REG_PXP2_PRTY_STS_1);
4293b9f5
DK
4545 break;
4546 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4547 _print_next_block((*par_num)++,
4548 "PXPPCICLOCKCLIENT");
4549 break;
4550 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4551 _print_next_block((*par_num)++, "CFC");
6bf07b8e
YM
4552 _print_parity(bp,
4553 CFC_REG_CFC_PRTY_STS);
4293b9f5
DK
4554 break;
4555 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4556 _print_next_block((*par_num)++, "CDU");
6bf07b8e 4557 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
4293b9f5
DK
4558 break;
4559 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4560 _print_next_block((*par_num)++, "DMAE");
6bf07b8e
YM
4561 _print_parity(bp,
4562 DMAE_REG_DMAE_PRTY_STS);
4293b9f5
DK
4563 break;
4564 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4565 _print_next_block((*par_num)++, "IGU");
6bf07b8e
YM
4566 if (CHIP_IS_E1x(bp))
4567 _print_parity(bp,
4568 HC_REG_HC_PRTY_STS);
4569 else
4570 _print_parity(bp,
4571 IGU_REG_IGU_PRTY_STS);
4293b9f5
DK
4572 break;
4573 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4574 _print_next_block((*par_num)++, "MISC");
6bf07b8e
YM
4575 _print_parity(bp,
4576 MISC_REG_MISC_PRTY_STS);
4293b9f5 4577 break;
6bf07b8e 4578 }
72fd0718
VZ
4579 }
4580
4581 /* Clear the bit */
4582 sig &= ~cur_bit;
4583 }
4584 }
4585
4293b9f5 4586 return res;
72fd0718
VZ
4587}
4588
4293b9f5
DK
4589static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
4590 int *par_num, bool *global,
4591 bool print)
72fd0718 4592{
4293b9f5
DK
4593 bool res = false;
4594 u32 cur_bit;
4595 int i;
4596
72fd0718 4597 for (i = 0; sig; i++) {
4293b9f5 4598 cur_bit = (0x1UL << i);
72fd0718
VZ
4599 if (sig & cur_bit) {
4600 switch (cur_bit) {
4601 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206 4602 if (print)
4293b9f5
DK
4603 _print_next_block((*par_num)++,
4604 "MCP ROM");
c9ee9206 4605 *global = true;
4293b9f5 4606 res |= true;
72fd0718
VZ
4607 break;
4608 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206 4609 if (print)
4293b9f5 4610 _print_next_block((*par_num)++,
c9ee9206
VZ
4611 "MCP UMP RX");
4612 *global = true;
4293b9f5 4613 res |= true;
72fd0718
VZ
4614 break;
4615 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206 4616 if (print)
4293b9f5 4617 _print_next_block((*par_num)++,
c9ee9206
VZ
4618 "MCP UMP TX");
4619 *global = true;
4293b9f5 4620 res |= true;
72fd0718
VZ
4621 break;
4622 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206 4623 if (print)
4293b9f5 4624 _print_next_block((*par_num)++,
c9ee9206 4625 "MCP SCPAD");
4293b9f5
DK
4626 /* clear latched SCPAD PATIRY from MCP */
4627 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
4628 1UL << 10);
72fd0718
VZ
4629 break;
4630 }
4631
4632 /* Clear the bit */
4633 sig &= ~cur_bit;
4634 }
4635 }
4636
4293b9f5 4637 return res;
72fd0718
VZ
4638}
4639
4293b9f5
DK
4640static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4641 int *par_num, bool print)
8736c826 4642{
4293b9f5
DK
4643 u32 cur_bit;
4644 bool res;
4645 int i;
4646
4647 res = false;
4648
8736c826 4649 for (i = 0; sig; i++) {
4293b9f5 4650 cur_bit = (0x1UL << i);
8736c826 4651 if (sig & cur_bit) {
4293b9f5
DK
4652 res |= true; /* Each bit is real error! */
4653 if (print) {
4654 switch (cur_bit) {
4655 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4656 _print_next_block((*par_num)++,
4657 "PGLUE_B");
6bf07b8e 4658 _print_parity(bp,
4293b9f5
DK
4659 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4660 break;
4661 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4662 _print_next_block((*par_num)++, "ATC");
6bf07b8e
YM
4663 _print_parity(bp,
4664 ATC_REG_ATC_PRTY_STS);
4293b9f5 4665 break;
6bf07b8e 4666 }
8736c826 4667 }
8736c826
VZ
4668 /* Clear the bit */
4669 sig &= ~cur_bit;
4670 }
4671 }
4672
4293b9f5 4673 return res;
8736c826
VZ
4674}
4675
1191cb83
ED
4676static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4677 u32 *sig)
72fd0718 4678{
4293b9f5
DK
4679 bool res = false;
4680
8736c826
VZ
4681 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4682 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4683 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4684 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4685 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4686 int par_num = 0;
51c1a580
MS
4687 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4688 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4689 sig[0] & HW_PRTY_ASSERT_SET_0,
4690 sig[1] & HW_PRTY_ASSERT_SET_1,
4691 sig[2] & HW_PRTY_ASSERT_SET_2,
4692 sig[3] & HW_PRTY_ASSERT_SET_3,
4693 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4694 if (print)
4695 netdev_err(bp->dev,
4696 "Parity errors detected in blocks: ");
4293b9f5
DK
4697 res |= bnx2x_check_blocks_with_parity0(bp,
4698 sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
4699 res |= bnx2x_check_blocks_with_parity1(bp,
4700 sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
4701 res |= bnx2x_check_blocks_with_parity2(bp,
4702 sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
4703 res |= bnx2x_check_blocks_with_parity3(bp,
4704 sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
4705 res |= bnx2x_check_blocks_with_parity4(bp,
4706 sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
8736c826 4707
c9ee9206
VZ
4708 if (print)
4709 pr_cont("\n");
4293b9f5 4710 }
8736c826 4711
4293b9f5 4712 return res;
72fd0718
VZ
4713}
4714
c9ee9206
VZ
4715/**
4716 * bnx2x_chk_parity_attn - checks for parity attentions.
4717 *
4718 * @bp: driver handle
4719 * @global: true if there was a global attention
4720 * @print: show parity attention in syslog
4721 */
4722bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4723{
8736c826 4724 struct attn_route attn = { {0} };
72fd0718
VZ
4725 int port = BP_PORT(bp);
4726
4727 attn.sig[0] = REG_RD(bp,
4728 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4729 port*4);
4730 attn.sig[1] = REG_RD(bp,
4731 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4732 port*4);
4733 attn.sig[2] = REG_RD(bp,
4734 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4735 port*4);
4736 attn.sig[3] = REG_RD(bp,
4737 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4738 port*4);
0a5ccb75
YM
4739 /* Since MCP attentions can't be disabled inside the block, we need to
4740 * read AEU registers to see whether they're currently disabled
4741 */
4742 attn.sig[3] &= ((REG_RD(bp,
4743 !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
4744 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
4745 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
4746 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
72fd0718 4747
8736c826
VZ
4748 if (!CHIP_IS_E1x(bp))
4749 attn.sig[4] = REG_RD(bp,
4750 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4751 port*4);
4752
4753 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4754}
4755
1191cb83 4756static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4757{
4758 u32 val;
4759 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4760
4761 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4762 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4763 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4764 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4765 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4766 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4767 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4768 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4769 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4770 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4771 if (val &
4772 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4773 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4774 if (val &
4775 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4776 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4777 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4778 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4779 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4780 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4781 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4782 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4783 }
4784 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4785 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4786 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4787 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4788 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4789 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4790 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4791 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4792 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4793 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4794 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4795 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4796 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4797 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4798 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4799 }
4800
4801 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4802 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4803 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4804 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4805 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4806 }
f2e0899f
DK
4807}
4808
72fd0718
VZ
4809static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4810{
4811 struct attn_route attn, *group_mask;
34f80b04 4812 int port = BP_PORT(bp);
877e9aa4 4813 int index;
a2fbb9ea
ET
4814 u32 reg_addr;
4815 u32 val;
3fcaf2e5 4816 u32 aeu_mask;
c9ee9206 4817 bool global = false;
a2fbb9ea
ET
4818
4819 /* need to take HW lock because MCP or other port might also
4820 try to handle this event */
4a37fb66 4821 bnx2x_acquire_alr(bp);
a2fbb9ea 4822
c9ee9206
VZ
4823 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4824#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4825 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4826 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4827 /* Disable HW interrupts */
4828 bnx2x_int_disable(bp);
72fd0718
VZ
4829 /* In case of parity errors don't handle attentions so that
4830 * other function would "see" parity errors.
4831 */
c9ee9206
VZ
4832#else
4833 bnx2x_panic();
4834#endif
4835 bnx2x_release_alr(bp);
72fd0718
VZ
4836 return;
4837 }
4838
a2fbb9ea
ET
4839 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4840 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4841 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4842 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4843 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4844 attn.sig[4] =
4845 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4846 else
4847 attn.sig[4] = 0;
4848
4849 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4850 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4851
4852 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4853 if (deasserted & (1 << index)) {
72fd0718 4854 group_mask = &bp->attn_group[index];
a2fbb9ea 4855
51c1a580 4856 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4857 index,
4858 group_mask->sig[0], group_mask->sig[1],
4859 group_mask->sig[2], group_mask->sig[3],
4860 group_mask->sig[4]);
a2fbb9ea 4861
f2e0899f
DK
4862 bnx2x_attn_int_deasserted4(bp,
4863 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4864 bnx2x_attn_int_deasserted3(bp,
72fd0718 4865 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4866 bnx2x_attn_int_deasserted1(bp,
72fd0718 4867 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4868 bnx2x_attn_int_deasserted2(bp,
72fd0718 4869 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4870 bnx2x_attn_int_deasserted0(bp,
72fd0718 4871 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4872 }
4873 }
4874
4a37fb66 4875 bnx2x_release_alr(bp);
a2fbb9ea 4876
f2e0899f
DK
4877 if (bp->common.int_block == INT_BLOCK_HC)
4878 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4879 COMMAND_REG_ATTN_BITS_CLR);
4880 else
4881 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4882
4883 val = ~deasserted;
f2e0899f
DK
4884 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4885 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4886 REG_WR(bp, reg_addr, val);
a2fbb9ea 4887
a2fbb9ea 4888 if (~bp->attn_state & deasserted)
3fcaf2e5 4889 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4890
4891 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4892 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4893
3fcaf2e5
EG
4894 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4895 aeu_mask = REG_RD(bp, reg_addr);
4896
4897 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4898 aeu_mask, deasserted);
72fd0718 4899 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4900 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4901
3fcaf2e5
EG
4902 REG_WR(bp, reg_addr, aeu_mask);
4903 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4904
4905 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4906 bp->attn_state &= ~deasserted;
4907 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4908}
4909
4910static void bnx2x_attn_int(struct bnx2x *bp)
4911{
4912 /* read local copy of bits */
68d59484
EG
4913 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4914 attn_bits);
4915 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4916 attn_bits_ack);
a2fbb9ea
ET
4917 u32 attn_state = bp->attn_state;
4918
4919 /* look for changed bits */
4920 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4921 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4922
4923 DP(NETIF_MSG_HW,
4924 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4925 attn_bits, attn_ack, asserted, deasserted);
4926
4927 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4928 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4929
4930 /* handle bits that were raised */
4931 if (asserted)
4932 bnx2x_attn_int_asserted(bp, asserted);
4933
4934 if (deasserted)
4935 bnx2x_attn_int_deasserted(bp, deasserted);
4936}
4937
619c5cb6
VZ
4938void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4939 u16 index, u8 op, u8 update)
4940{
dc1ba591
AE
4941 u32 igu_addr = bp->igu_base_addr;
4942 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
619c5cb6
VZ
4943 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4944 igu_addr);
4945}
4946
1191cb83 4947static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4948{
4949 /* No memory barriers */
4950 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4951 mmiowb(); /* keep prod updates ordered */
4952}
4953
523224a3
DK
4954static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4955 union event_ring_elem *elem)
4956{
619c5cb6
VZ
4957 u8 err = elem->message.error;
4958
523224a3 4959 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4960 (cid < bp->cnic_eth_dev.starting_cid &&
4961 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4962 return 1;
4963
4964 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4965
619c5cb6
VZ
4966 if (unlikely(err)) {
4967
523224a3
DK
4968 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4969 cid);
823e1d90 4970 bnx2x_panic_dump(bp, false);
523224a3 4971 }
619c5cb6 4972 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4973 return 0;
4974}
523224a3 4975
1191cb83 4976static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4977{
4978 struct bnx2x_mcast_ramrod_params rparam;
4979 int rc;
4980
4981 memset(&rparam, 0, sizeof(rparam));
4982
4983 rparam.mcast_obj = &bp->mcast_obj;
4984
4985 netif_addr_lock_bh(bp->dev);
4986
4987 /* Clear pending state for the last command */
4988 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4989
4990 /* If there are pending mcast commands - send them */
4991 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4992 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4993 if (rc < 0)
4994 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4995 rc);
4996 }
4997
4998 netif_addr_unlock_bh(bp->dev);
4999}
5000
1191cb83
ED
5001static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
5002 union event_ring_elem *elem)
619c5cb6
VZ
5003{
5004 unsigned long ramrod_flags = 0;
5005 int rc = 0;
5006 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
5007 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
5008
5009 /* Always push next commands out, don't wait here */
5010 __set_bit(RAMROD_CONT, &ramrod_flags);
5011
86564c3f
YM
5012 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
5013 >> BNX2X_SWCID_SHIFT) {
619c5cb6 5014 case BNX2X_FILTER_MAC_PENDING:
51c1a580 5015 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 5016 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
5017 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
5018 else
15192a8c 5019 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
5020
5021 break;
619c5cb6 5022 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 5023 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
5024 /* This is only relevant for 57710 where multicast MACs are
5025 * configured as unicast MACs using the same ramrod.
5026 */
5027 bnx2x_handle_mcast_eqe(bp);
5028 return;
5029 default:
5030 BNX2X_ERR("Unsupported classification command: %d\n",
5031 elem->message.data.eth_event.echo);
5032 return;
5033 }
5034
5035 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
5036
5037 if (rc < 0)
5038 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
5039 else if (rc > 0)
5040 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
619c5cb6
VZ
5041}
5042
619c5cb6 5043static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 5044
1191cb83 5045static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
5046{
5047 netif_addr_lock_bh(bp->dev);
5048
5049 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5050
5051 /* Send rx_mode command again if was requested */
5052 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
5053 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
5054 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
5055 &bp->sp_state))
5056 bnx2x_set_iscsi_eth_rx_mode(bp, true);
5057 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
5058 &bp->sp_state))
5059 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
5060
5061 netif_addr_unlock_bh(bp->dev);
5062}
5063
1191cb83 5064static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
5065 union event_ring_elem *elem)
5066{
5067 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
5068 DP(BNX2X_MSG_SP,
5069 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
5070 elem->message.data.vif_list_event.func_bit_map);
5071 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
5072 elem->message.data.vif_list_event.func_bit_map);
5073 } else if (elem->message.data.vif_list_event.echo ==
5074 VIF_LIST_RULE_SET) {
5075 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
5076 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
5077 }
5078}
5079
5080/* called with rtnl_lock */
1191cb83 5081static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
5082{
5083 int q, rc;
5084 struct bnx2x_fastpath *fp;
5085 struct bnx2x_queue_state_params queue_params = {NULL};
5086 struct bnx2x_queue_update_params *q_update_params =
5087 &queue_params.params.update;
5088
2de67439 5089 /* Send Q update command with afex vlan removal values for all Qs */
a3348722
BW
5090 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
5091
5092 /* set silent vlan removal values according to vlan mode */
5093 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
5094 &q_update_params->update_flags);
5095 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
5096 &q_update_params->update_flags);
5097 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5098
5099 /* in access mode mark mask and value are 0 to strip all vlans */
5100 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
5101 q_update_params->silent_removal_value = 0;
5102 q_update_params->silent_removal_mask = 0;
5103 } else {
5104 q_update_params->silent_removal_value =
5105 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
5106 q_update_params->silent_removal_mask = VLAN_VID_MASK;
5107 }
5108
5109 for_each_eth_queue(bp, q) {
5110 /* Set the appropriate Queue object */
5111 fp = &bp->fp[q];
15192a8c 5112 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
5113
5114 /* send the ramrod */
5115 rc = bnx2x_queue_state_change(bp, &queue_params);
5116 if (rc < 0)
5117 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5118 q);
5119 }
5120
fea75645 5121 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
65565884 5122 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 5123 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
5124
5125 /* clear pending completion bit */
5126 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5127
5128 /* mark latest Q bit */
5129 smp_mb__before_clear_bit();
5130 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
5131 smp_mb__after_clear_bit();
5132
5133 /* send Q update ramrod for FCoE Q */
5134 rc = bnx2x_queue_state_change(bp, &queue_params);
5135 if (rc < 0)
5136 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5137 q);
5138 } else {
5139 /* If no FCoE ring - ACK MCP now */
5140 bnx2x_link_report(bp);
5141 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5142 }
a3348722
BW
5143}
5144
1191cb83 5145static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
5146 struct bnx2x *bp, u32 cid)
5147{
94f05b0f 5148 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
5149
5150 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 5151 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 5152 else
15192a8c 5153 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
5154}
5155
523224a3
DK
5156static void bnx2x_eq_int(struct bnx2x *bp)
5157{
5158 u16 hw_cons, sw_cons, sw_prod;
5159 union event_ring_elem *elem;
55c11941 5160 u8 echo;
523224a3
DK
5161 u32 cid;
5162 u8 opcode;
fd1fc79d 5163 int rc, spqe_cnt = 0;
619c5cb6
VZ
5164 struct bnx2x_queue_sp_obj *q_obj;
5165 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
5166 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
5167
5168 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5169
5170 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
16a5fd92 5171 * when we get the next-page we need to adjust so the loop
523224a3
DK
5172 * condition below will be met. The next element is the size of a
5173 * regular element and hence incrementing by 1
5174 */
5175 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5176 hw_cons++;
5177
25985edc 5178 /* This function may never run in parallel with itself for a
523224a3
DK
5179 * specific bp, thus there is no need in "paired" read memory
5180 * barrier here.
5181 */
5182 sw_cons = bp->eq_cons;
5183 sw_prod = bp->eq_prod;
5184
d6cae238 5185 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 5186 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
5187
5188 for (; sw_cons != hw_cons;
5189 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5190
523224a3
DK
5191 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5192
fd1fc79d
AE
5193 rc = bnx2x_iov_eq_sp_event(bp, elem);
5194 if (!rc) {
5195 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5196 rc);
5197 goto next_spqe;
5198 }
523224a3 5199
86564c3f
YM
5200 /* elem CID originates from FW; actually LE */
5201 cid = SW_CID((__force __le32)
5202 elem->message.data.cfc_del_event.cid);
5203 opcode = elem->message.opcode;
523224a3
DK
5204
5205 /* handle eq element */
5206 switch (opcode) {
fd1fc79d
AE
5207 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5208 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
5209 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
5210 continue;
5211
523224a3 5212 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
5213 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
5214 "got statistics comp event %d\n",
619c5cb6 5215 bp->stats_comp++);
523224a3 5216 /* nothing to do with stats comp */
d6cae238 5217 goto next_spqe;
523224a3
DK
5218
5219 case EVENT_RING_OPCODE_CFC_DEL:
5220 /* handle according to cid range */
5221 /*
5222 * we may want to verify here that the bp state is
5223 * HALTING
5224 */
d6cae238 5225 DP(BNX2X_MSG_SP,
523224a3 5226 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
5227
5228 if (CNIC_LOADED(bp) &&
5229 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 5230 goto next_spqe;
55c11941 5231
619c5cb6
VZ
5232 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5233
5234 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5235 break;
5236
523224a3 5237 goto next_spqe;
e4901dde
VZ
5238
5239 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 5240 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6ffa39f2 5241 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
6debea87
DK
5242 if (f_obj->complete_cmd(bp, f_obj,
5243 BNX2X_F_CMD_TX_STOP))
5244 break;
e4901dde 5245 goto next_spqe;
619c5cb6 5246
e4901dde 5247 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 5248 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6ffa39f2 5249 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
6debea87
DK
5250 if (f_obj->complete_cmd(bp, f_obj,
5251 BNX2X_F_CMD_TX_START))
5252 break;
e4901dde 5253 goto next_spqe;
55c11941 5254
a3348722 5255 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
5256 echo = elem->message.data.function_update_event.echo;
5257 if (echo == SWITCH_UPDATE) {
5258 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5259 "got FUNC_SWITCH_UPDATE ramrod\n");
5260 if (f_obj->complete_cmd(
5261 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5262 break;
a3348722 5263
55c11941
MS
5264 } else {
5265 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5266 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5267 f_obj->complete_cmd(bp, f_obj,
5268 BNX2X_F_CMD_AFEX_UPDATE);
5269
5270 /* We will perform the Queues update from
5271 * sp_rtnl task as all Queue SP operations
5272 * should run under rtnl_lock.
5273 */
5274 smp_mb__before_clear_bit();
5275 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5276 &bp->sp_rtnl_state);
5277 smp_mb__after_clear_bit();
5278
5279 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5280 }
a3348722 5281
a3348722
BW
5282 goto next_spqe;
5283
5284 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5285 f_obj->complete_cmd(bp, f_obj,
5286 BNX2X_F_CMD_AFEX_VIFLISTS);
5287 bnx2x_after_afex_vif_lists(bp, elem);
5288 goto next_spqe;
619c5cb6 5289 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
5290 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5291 "got FUNC_START ramrod\n");
619c5cb6
VZ
5292 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5293 break;
5294
5295 goto next_spqe;
5296
5297 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
5298 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5299 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
5300 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5301 break;
5302
5303 goto next_spqe;
523224a3
DK
5304 }
5305
5306 switch (opcode | bp->state) {
619c5cb6
VZ
5307 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5308 BNX2X_STATE_OPEN):
5309 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 5310 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
5311 cid = elem->message.data.eth_event.echo &
5312 BNX2X_SWCID_MASK;
d6cae238 5313 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
5314 cid);
5315 rss_raw->clear_pending(rss_raw);
523224a3
DK
5316 break;
5317
619c5cb6
VZ
5318 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5319 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
5320 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 5321 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
5322 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5323 BNX2X_STATE_OPEN):
5324 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5325 BNX2X_STATE_DIAG):
5326 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5327 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5328 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 5329 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
5330 break;
5331
619c5cb6
VZ
5332 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5333 BNX2X_STATE_OPEN):
5334 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5335 BNX2X_STATE_DIAG):
5336 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5337 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5338 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 5339 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
5340 break;
5341
619c5cb6
VZ
5342 case (EVENT_RING_OPCODE_FILTERS_RULES |
5343 BNX2X_STATE_OPEN):
5344 case (EVENT_RING_OPCODE_FILTERS_RULES |
5345 BNX2X_STATE_DIAG):
5346 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 5347 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5348 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 5349 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
5350 break;
5351 default:
5352 /* unknown event log error and continue */
619c5cb6
VZ
5353 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5354 elem->message.opcode, bp->state);
523224a3
DK
5355 }
5356next_spqe:
5357 spqe_cnt++;
5358 } /* for */
5359
8fe23fbd 5360 smp_mb__before_atomic_inc();
6e30dd4e 5361 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
5362
5363 bp->eq_cons = sw_cons;
5364 bp->eq_prod = sw_prod;
5365 /* Make sure that above mem writes were issued towards the memory */
5366 smp_wmb();
5367
5368 /* update producer */
5369 bnx2x_update_eq_prod(bp, bp->eq_prod);
5370}
5371
a2fbb9ea
ET
5372static void bnx2x_sp_task(struct work_struct *work)
5373{
1cf167f2 5374 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea 5375
fd1fc79d 5376 DP(BNX2X_MSG_SP, "sp task invoked\n");
a2fbb9ea 5377
16a5fd92 5378 /* make sure the atomic interrupt_occurred has been written */
fd1fc79d
AE
5379 smp_rmb();
5380 if (atomic_read(&bp->interrupt_occurred)) {
a2fbb9ea 5381
fd1fc79d
AE
5382 /* what work needs to be performed? */
5383 u16 status = bnx2x_update_dsb_idx(bp);
cdaa7cb8 5384
fd1fc79d
AE
5385 DP(BNX2X_MSG_SP, "status %x\n", status);
5386 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5387 atomic_set(&bp->interrupt_occurred, 0);
5388
5389 /* HW attentions */
5390 if (status & BNX2X_DEF_SB_ATT_IDX) {
5391 bnx2x_attn_int(bp);
5392 status &= ~BNX2X_DEF_SB_ATT_IDX;
5393 }
5394
5395 /* SP events: STAT_QUERY and others */
5396 if (status & BNX2X_DEF_SB_IDX) {
5397 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5398
55c11941 5399 if (FCOE_INIT(bp) &&
fd1fc79d
AE
5400 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5401 /* Prevent local bottom-halves from running as
5402 * we are going to change the local NAPI list.
5403 */
5404 local_bh_disable();
5405 napi_schedule(&bnx2x_fcoe(bp, napi));
5406 local_bh_enable();
5407 }
5408
5409 /* Handle EQ completions */
5410 bnx2x_eq_int(bp);
5411 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5412 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5413
5414 status &= ~BNX2X_DEF_SB_IDX;
019dbb4c 5415 }
55c11941 5416
fd1fc79d
AE
5417 /* if status is non zero then perhaps something went wrong */
5418 if (unlikely(status))
5419 DP(BNX2X_MSG_SP,
5420 "got an unknown interrupt! (status 0x%x)\n", status);
523224a3 5421
fd1fc79d
AE
5422 /* ack status block only if something was actually handled */
5423 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5424 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
cdaa7cb8
VZ
5425 }
5426
fd1fc79d
AE
5427 /* must be called after the EQ processing (since eq leads to sriov
5428 * ramrod completion flows).
5429 * This flow may have been scheduled by the arrival of a ramrod
5430 * completion, or by the sriov code rescheduling itself.
5431 */
5432 bnx2x_iov_sp_task(bp);
a3348722
BW
5433
5434 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5435 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5436 &bp->sp_state)) {
5437 bnx2x_link_report(bp);
5438 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5439 }
a2fbb9ea
ET
5440}
5441
9f6c9258 5442irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5443{
5444 struct net_device *dev = dev_instance;
5445 struct bnx2x *bp = netdev_priv(dev);
5446
523224a3
DK
5447 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5448 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5449
5450#ifdef BNX2X_STOP_ON_ERROR
5451 if (unlikely(bp->panic))
5452 return IRQ_HANDLED;
5453#endif
5454
55c11941 5455 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5456 struct cnic_ops *c_ops;
5457
5458 rcu_read_lock();
5459 c_ops = rcu_dereference(bp->cnic_ops);
5460 if (c_ops)
5461 c_ops->cnic_handler(bp->cnic_data, NULL);
5462 rcu_read_unlock();
5463 }
55c11941 5464
fd1fc79d
AE
5465 /* schedule sp task to perform default status block work, ack
5466 * attentions and enable interrupts.
5467 */
5468 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
5469
5470 return IRQ_HANDLED;
5471}
5472
5473/* end of slow path */
5474
619c5cb6
VZ
5475void bnx2x_drv_pulse(struct bnx2x *bp)
5476{
5477 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5478 bp->fw_drv_pulse_wr_seq);
5479}
5480
a2fbb9ea
ET
5481static void bnx2x_timer(unsigned long data)
5482{
5483 struct bnx2x *bp = (struct bnx2x *) data;
5484
5485 if (!netif_running(bp->dev))
5486 return;
5487
67c431a5
AE
5488 if (IS_PF(bp) &&
5489 !BP_NOMCP(bp)) {
f2e0899f 5490 int mb_idx = BP_FW_MB_IDX(bp);
4c868664
EG
5491 u16 drv_pulse;
5492 u16 mcp_pulse;
a2fbb9ea
ET
5493
5494 ++bp->fw_drv_pulse_wr_seq;
5495 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
a2fbb9ea 5496 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5497 bnx2x_drv_pulse(bp);
a2fbb9ea 5498
f2e0899f 5499 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5500 MCP_PULSE_SEQ_MASK);
5501 /* The delta between driver pulse and mcp response
4c868664
EG
5502 * should not get too big. If the MFW is more than 5 pulses
5503 * behind, we should worry about it enough to generate an error
5504 * log.
a2fbb9ea 5505 */
4c868664
EG
5506 if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
5507 BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
a2fbb9ea 5508 drv_pulse, mcp_pulse);
a2fbb9ea
ET
5509 }
5510
f34d28ea 5511 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5512 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5513
abc5a021 5514 /* sample pf vf bulletin board for new posts from pf */
37173488
YM
5515 if (IS_VF(bp))
5516 bnx2x_timer_sriov(bp);
78c3bcc5 5517
a2fbb9ea
ET
5518 mod_timer(&bp->timer, jiffies + bp->current_interval);
5519}
5520
5521/* end of Statistics */
5522
5523/* nic init */
5524
5525/*
5526 * nic init service functions
5527 */
5528
1191cb83 5529static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5530{
523224a3
DK
5531 u32 i;
5532 if (!(len%4) && !(addr%4))
5533 for (i = 0; i < len; i += 4)
5534 REG_WR(bp, addr + i, fill);
5535 else
5536 for (i = 0; i < len; i++)
5537 REG_WR8(bp, addr + i, fill);
34f80b04
EG
5538}
5539
523224a3 5540/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5541static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5542 int fw_sb_id,
5543 u32 *sb_data_p,
5544 u32 data_size)
34f80b04 5545{
a2fbb9ea 5546 int index;
523224a3
DK
5547 for (index = 0; index < data_size; index++)
5548 REG_WR(bp, BAR_CSTRORM_INTMEM +
5549 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5550 sizeof(u32)*index,
5551 *(sb_data_p + index));
5552}
a2fbb9ea 5553
1191cb83 5554static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5555{
5556 u32 *sb_data_p;
5557 u32 data_size = 0;
f2e0899f 5558 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5559 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5560
523224a3 5561 /* disable the function first */
619c5cb6 5562 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5563 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5564 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5565 sb_data_e2.common.p_func.vf_valid = false;
5566 sb_data_p = (u32 *)&sb_data_e2;
5567 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5568 } else {
5569 memset(&sb_data_e1x, 0,
5570 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5571 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5572 sb_data_e1x.common.p_func.vf_valid = false;
5573 sb_data_p = (u32 *)&sb_data_e1x;
5574 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5575 }
523224a3 5576 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5577
523224a3
DK
5578 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5579 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5580 CSTORM_STATUS_BLOCK_SIZE);
5581 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5582 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5583 CSTORM_SYNC_BLOCK_SIZE);
5584}
34f80b04 5585
523224a3 5586/* helper: writes SP SB data to FW */
1191cb83 5587static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5588 struct hc_sp_status_block_data *sp_sb_data)
5589{
5590 int func = BP_FUNC(bp);
5591 int i;
5592 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5593 REG_WR(bp, BAR_CSTRORM_INTMEM +
5594 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5595 i*sizeof(u32),
5596 *((u32 *)sp_sb_data + i));
34f80b04
EG
5597}
5598
1191cb83 5599static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5600{
5601 int func = BP_FUNC(bp);
523224a3
DK
5602 struct hc_sp_status_block_data sp_sb_data;
5603 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5604
619c5cb6 5605 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5606 sp_sb_data.p_func.vf_valid = false;
5607
5608 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5609
5610 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5611 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5612 CSTORM_SP_STATUS_BLOCK_SIZE);
5613 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5614 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5615 CSTORM_SP_SYNC_BLOCK_SIZE);
523224a3
DK
5616}
5617
1191cb83 5618static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5619 int igu_sb_id, int igu_seg_id)
5620{
5621 hc_sm->igu_sb_id = igu_sb_id;
5622 hc_sm->igu_seg_id = igu_seg_id;
5623 hc_sm->timer_value = 0xFF;
5624 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5625}
5626
150966ad 5627/* allocates state machine ids. */
1191cb83 5628static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5629{
5630 /* zero out state machine indices */
5631 /* rx indices */
5632 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5633
5634 /* tx indices */
5635 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5636 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5637 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5638 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5639
5640 /* map indices */
5641 /* rx indices */
5642 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5643 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5644
5645 /* tx indices */
5646 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5647 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5648 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5649 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5650 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5651 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5652 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5653 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5654}
5655
b93288d5 5656void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5657 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5658{
523224a3
DK
5659 int igu_seg_id;
5660
f2e0899f 5661 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5662 struct hc_status_block_data_e1x sb_data_e1x;
5663 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5664 int data_size;
5665 u32 *sb_data_p;
5666
f2e0899f
DK
5667 if (CHIP_INT_MODE_IS_BC(bp))
5668 igu_seg_id = HC_SEG_ACCESS_NORM;
5669 else
5670 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5671
5672 bnx2x_zero_fp_sb(bp, fw_sb_id);
5673
619c5cb6 5674 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5675 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5676 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5677 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5678 sb_data_e2.common.p_func.vf_id = vfid;
5679 sb_data_e2.common.p_func.vf_valid = vf_valid;
5680 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5681 sb_data_e2.common.same_igu_sb_1b = true;
5682 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5683 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5684 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5685 sb_data_p = (u32 *)&sb_data_e2;
5686 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5687 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5688 } else {
5689 memset(&sb_data_e1x, 0,
5690 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5691 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5692 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5693 sb_data_e1x.common.p_func.vf_id = 0xff;
5694 sb_data_e1x.common.p_func.vf_valid = false;
5695 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5696 sb_data_e1x.common.same_igu_sb_1b = true;
5697 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5698 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5699 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5700 sb_data_p = (u32 *)&sb_data_e1x;
5701 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5702 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5703 }
523224a3
DK
5704
5705 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5706 igu_sb_id, igu_seg_id);
5707 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5708 igu_sb_id, igu_seg_id);
5709
51c1a580 5710 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3 5711
86564c3f 5712 /* write indices to HW - PCI guarantees endianity of regpairs */
523224a3
DK
5713 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5714}
5715
619c5cb6 5716static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5717 u16 tx_usec, u16 rx_usec)
5718{
6383c0b3 5719 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5720 false, rx_usec);
6383c0b3
AE
5721 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5722 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5723 tx_usec);
5724 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5725 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5726 tx_usec);
5727 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5728 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5729 tx_usec);
523224a3 5730}
f2e0899f 5731
523224a3
DK
5732static void bnx2x_init_def_sb(struct bnx2x *bp)
5733{
5734 struct host_sp_status_block *def_sb = bp->def_status_blk;
5735 dma_addr_t mapping = bp->def_status_blk_mapping;
5736 int igu_sp_sb_index;
5737 int igu_seg_id;
34f80b04
EG
5738 int port = BP_PORT(bp);
5739 int func = BP_FUNC(bp);
f2eaeb58 5740 int reg_offset, reg_offset_en5;
a2fbb9ea 5741 u64 section;
523224a3
DK
5742 int index;
5743 struct hc_sp_status_block_data sp_sb_data;
5744 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5745
f2e0899f
DK
5746 if (CHIP_INT_MODE_IS_BC(bp)) {
5747 igu_sp_sb_index = DEF_SB_IGU_ID;
5748 igu_seg_id = HC_SEG_ACCESS_DEF;
5749 } else {
5750 igu_sp_sb_index = bp->igu_dsb_id;
5751 igu_seg_id = IGU_SEG_ACCESS_DEF;
5752 }
a2fbb9ea
ET
5753
5754 /* ATTN */
523224a3 5755 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5756 atten_status_block);
523224a3 5757 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5758
49d66772
ET
5759 bp->attn_state = 0;
5760
a2fbb9ea
ET
5761 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5762 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5763 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5764 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5765 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5766 int sindex;
5767 /* take care of sig[0]..sig[4] */
5768 for (sindex = 0; sindex < 4; sindex++)
5769 bp->attn_group[index].sig[sindex] =
5770 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5771
619c5cb6 5772 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5773 /*
5774 * enable5 is separate from the rest of the registers,
5775 * and therefore the address skip is 4
5776 * and not 16 between the different groups
5777 */
5778 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5779 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5780 else
5781 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5782 }
5783
f2e0899f
DK
5784 if (bp->common.int_block == INT_BLOCK_HC) {
5785 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5786 HC_REG_ATTN_MSG0_ADDR_L);
5787
5788 REG_WR(bp, reg_offset, U64_LO(section));
5789 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5790 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5791 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5792 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5793 }
a2fbb9ea 5794
523224a3
DK
5795 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5796 sp_sb);
a2fbb9ea 5797
523224a3 5798 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5799
86564c3f 5800 /* PCI guarantees endianity of regpairs */
619c5cb6 5801 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5802 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5803 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5804 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5805 sp_sb_data.igu_seg_id = igu_seg_id;
5806 sp_sb_data.p_func.pf_id = func;
f2e0899f 5807 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5808 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5809
523224a3 5810 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5811
523224a3 5812 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5813}
5814
9f6c9258 5815void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5816{
a2fbb9ea
ET
5817 int i;
5818
ec6ba945 5819 for_each_eth_queue(bp, i)
523224a3 5820 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5821 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5822}
5823
a2fbb9ea
ET
5824static void bnx2x_init_sp_ring(struct bnx2x *bp)
5825{
a2fbb9ea 5826 spin_lock_init(&bp->spq_lock);
6e30dd4e 5827 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5828
a2fbb9ea 5829 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5830 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5831 bp->spq_prod_bd = bp->spq;
5832 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5833}
5834
523224a3 5835static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5836{
5837 int i;
523224a3
DK
5838 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5839 union event_ring_elem *elem =
5840 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5841
523224a3
DK
5842 elem->next_page.addr.hi =
5843 cpu_to_le32(U64_HI(bp->eq_mapping +
5844 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5845 elem->next_page.addr.lo =
5846 cpu_to_le32(U64_LO(bp->eq_mapping +
5847 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5848 }
523224a3
DK
5849 bp->eq_cons = 0;
5850 bp->eq_prod = NUM_EQ_DESC;
5851 bp->eq_cons_sb = BNX2X_EQ_INDEX;
16a5fd92 5852 /* we want a warning message before it gets wrought... */
6e30dd4e
VZ
5853 atomic_set(&bp->eq_spq_left,
5854 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5855}
5856
619c5cb6 5857/* called with netif_addr_lock_bh() */
924d75ab
YM
5858int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5859 unsigned long rx_mode_flags,
5860 unsigned long rx_accept_flags,
5861 unsigned long tx_accept_flags,
5862 unsigned long ramrod_flags)
ab532cf3 5863{
619c5cb6
VZ
5864 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5865 int rc;
5866
5867 memset(&ramrod_param, 0, sizeof(ramrod_param));
5868
5869 /* Prepare ramrod parameters */
5870 ramrod_param.cid = 0;
5871 ramrod_param.cl_id = cl_id;
5872 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5873 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5874
619c5cb6
VZ
5875 ramrod_param.pstate = &bp->sp_state;
5876 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5877
619c5cb6
VZ
5878 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5879 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5880
5881 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5882
5883 ramrod_param.ramrod_flags = ramrod_flags;
5884 ramrod_param.rx_mode_flags = rx_mode_flags;
5885
5886 ramrod_param.rx_accept_flags = rx_accept_flags;
5887 ramrod_param.tx_accept_flags = tx_accept_flags;
5888
5889 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5890 if (rc < 0) {
5891 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
924d75ab 5892 return rc;
619c5cb6 5893 }
924d75ab
YM
5894
5895 return 0;
a2fbb9ea
ET
5896}
5897
86564c3f
YM
5898static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
5899 unsigned long *rx_accept_flags,
5900 unsigned long *tx_accept_flags)
471de716 5901{
924d75ab
YM
5902 /* Clear the flags first */
5903 *rx_accept_flags = 0;
5904 *tx_accept_flags = 0;
619c5cb6 5905
924d75ab 5906 switch (rx_mode) {
619c5cb6
VZ
5907 case BNX2X_RX_MODE_NONE:
5908 /*
5909 * 'drop all' supersedes any accept flags that may have been
5910 * passed to the function.
5911 */
5912 break;
5913 case BNX2X_RX_MODE_NORMAL:
924d75ab
YM
5914 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5915 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
5916 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5917
5918 /* internal switching mode */
924d75ab
YM
5919 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5920 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
5921 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5922
5923 break;
5924 case BNX2X_RX_MODE_ALLMULTI:
924d75ab
YM
5925 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5926 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5927 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5928
5929 /* internal switching mode */
924d75ab
YM
5930 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5931 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5932 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5933
5934 break;
5935 case BNX2X_RX_MODE_PROMISC:
16a5fd92 5936 /* According to definition of SI mode, iface in promisc mode
619c5cb6
VZ
5937 * should receive matched and unmatched (in resolution of port)
5938 * unicast packets.
5939 */
924d75ab
YM
5940 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
5941 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5942 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5943 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5944
5945 /* internal switching mode */
924d75ab
YM
5946 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5947 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5948
5949 if (IS_MF_SI(bp))
924d75ab 5950 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
619c5cb6 5951 else
924d75ab 5952 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
619c5cb6
VZ
5953
5954 break;
5955 default:
924d75ab
YM
5956 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
5957 return -EINVAL;
619c5cb6 5958 }
de832a55 5959
924d75ab 5960 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
619c5cb6 5961 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
924d75ab
YM
5962 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
5963 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
34f80b04
EG
5964 }
5965
924d75ab
YM
5966 return 0;
5967}
5968
5969/* called with netif_addr_lock_bh() */
5970int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5971{
5972 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5973 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5974 int rc;
5975
5976 if (!NO_FCOE(bp))
5977 /* Configure rx_mode of FCoE Queue */
5978 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5979
5980 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
5981 &tx_accept_flags);
5982 if (rc)
5983 return rc;
5984
619c5cb6
VZ
5985 __set_bit(RAMROD_RX, &ramrod_flags);
5986 __set_bit(RAMROD_TX, &ramrod_flags);
5987
924d75ab
YM
5988 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
5989 rx_accept_flags, tx_accept_flags,
5990 ramrod_flags);
619c5cb6
VZ
5991}
5992
5993static void bnx2x_init_internal_common(struct bnx2x *bp)
5994{
5995 int i;
5996
0793f83f
DK
5997 if (IS_MF_SI(bp))
5998 /*
5999 * In switch independent mode, the TSTORM needs to accept
6000 * packets that failed classification, since approximate match
6001 * mac addresses aren't written to NIG LLH
6002 */
6003 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6004 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
6005 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
6006 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6007 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 6008
523224a3
DK
6009 /* Zero this manually as its initialization is
6010 currently missing in the initTool */
6011 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 6012 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 6013 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 6014 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6015 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
6016 CHIP_INT_MODE_IS_BC(bp) ?
6017 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
6018 }
523224a3 6019}
8a1c38d1 6020
471de716
EG
6021static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
6022{
6023 switch (load_code) {
6024 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 6025 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
6026 bnx2x_init_internal_common(bp);
6027 /* no break */
6028
6029 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 6030 /* nothing to do */
471de716
EG
6031 /* no break */
6032
6033 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
6034 /* internal memory per function is
6035 initialized inside bnx2x_pf_init */
471de716
EG
6036 break;
6037
6038 default:
6039 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6040 break;
6041 }
6042}
6043
619c5cb6 6044static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 6045{
55c11941 6046 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 6047}
523224a3 6048
619c5cb6
VZ
6049static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
6050{
55c11941 6051 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
6052}
6053
1191cb83 6054static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
6055{
6056 if (CHIP_IS_E1x(fp->bp))
6057 return BP_L_ID(fp->bp) + fp->index;
6058 else /* We want Client ID to be the same as IGU SB ID for 57712 */
6059 return bnx2x_fp_igu_sb_id(fp);
6060}
6061
6383c0b3 6062static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
6063{
6064 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 6065 u8 cos;
619c5cb6 6066 unsigned long q_type = 0;
6383c0b3 6067 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 6068 fp->rx_queue = fp_idx;
b3b83c3f 6069 fp->cid = fp_idx;
619c5cb6
VZ
6070 fp->cl_id = bnx2x_fp_cl_id(fp);
6071 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
6072 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 6073 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
6074 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
6075
523224a3 6076 /* init shortcut */
619c5cb6 6077 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 6078
16a5fd92 6079 /* Setup SB indices */
523224a3 6080 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 6081
619c5cb6
VZ
6082 /* Configure Queue State object */
6083 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6084 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
6085
6086 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
6087
6088 /* init tx data */
6089 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
6090 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
6091 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
6092 FP_COS_TO_TXQ(fp, cos, bp),
6093 BNX2X_TX_SB_INDEX_BASE + cos, fp);
6094 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
6095 }
6096
ad5afc89
AE
6097 /* nothing more for vf to do here */
6098 if (IS_VF(bp))
6099 return;
6100
6101 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
6102 fp->fw_sb_id, fp->igu_sb_id);
6103 bnx2x_update_fpsb_idx(fp);
15192a8c
BW
6104 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
6105 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 6106 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
6107
6108 /**
6109 * Configure classification DBs: Always enable Tx switching
6110 */
6111 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
6112
ad5afc89
AE
6113 DP(NETIF_MSG_IFUP,
6114 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6115 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6116 fp->igu_sb_id);
523224a3
DK
6117}
6118
1191cb83
ED
6119static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
6120{
6121 int i;
6122
6123 for (i = 1; i <= NUM_TX_RINGS; i++) {
6124 struct eth_tx_next_bd *tx_next_bd =
6125 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
6126
6127 tx_next_bd->addr_hi =
6128 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
6129 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6130 tx_next_bd->addr_lo =
6131 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
6132 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6133 }
6134
639d65b8
YM
6135 *txdata->tx_cons_sb = cpu_to_le16(0);
6136
1191cb83
ED
6137 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
6138 txdata->tx_db.data.zero_fill1 = 0;
6139 txdata->tx_db.data.prod = 0;
6140
6141 txdata->tx_pkt_prod = 0;
6142 txdata->tx_pkt_cons = 0;
6143 txdata->tx_bd_prod = 0;
6144 txdata->tx_bd_cons = 0;
6145 txdata->tx_pkt = 0;
6146}
6147
55c11941
MS
6148static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
6149{
6150 int i;
6151
6152 for_each_tx_queue_cnic(bp, i)
6153 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
6154}
d76a6111 6155
1191cb83
ED
6156static void bnx2x_init_tx_rings(struct bnx2x *bp)
6157{
6158 int i;
6159 u8 cos;
6160
55c11941 6161 for_each_eth_queue(bp, i)
1191cb83 6162 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 6163 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
6164}
6165
55c11941 6166void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 6167{
ec6ba945
VZ
6168 if (!NO_FCOE(bp))
6169 bnx2x_init_fcoe_fp(bp);
523224a3
DK
6170
6171 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6172 BNX2X_VF_ID_INVALID, false,
619c5cb6 6173 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 6174
55c11941
MS
6175 /* ensure status block indices were read */
6176 rmb();
6177 bnx2x_init_rx_rings_cnic(bp);
6178 bnx2x_init_tx_rings_cnic(bp);
6179
6180 /* flush all */
6181 mb();
6182 mmiowb();
6183}
a2fbb9ea 6184
ecf01c22 6185void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
55c11941
MS
6186{
6187 int i;
6188
ecf01c22 6189 /* Setup NIC internals and enable interrupts */
55c11941
MS
6190 for_each_eth_queue(bp, i)
6191 bnx2x_init_eth_fp(bp, i);
ad5afc89
AE
6192
6193 /* ensure status block indices were read */
6194 rmb();
6195 bnx2x_init_rx_rings(bp);
6196 bnx2x_init_tx_rings(bp);
6197
ecf01c22
YM
6198 if (IS_PF(bp)) {
6199 /* Initialize MOD_ABS interrupts */
6200 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6201 bp->common.shmem_base,
6202 bp->common.shmem2_base, BP_PORT(bp));
ad5afc89 6203
ecf01c22
YM
6204 /* initialize the default status block and sp ring */
6205 bnx2x_init_def_sb(bp);
6206 bnx2x_update_dsb_idx(bp);
6207 bnx2x_init_sp_ring(bp);
3cdeec22
YM
6208 } else {
6209 bnx2x_memset_stats(bp);
ecf01c22
YM
6210 }
6211}
16119785 6212
ecf01c22
YM
6213void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6214{
523224a3 6215 bnx2x_init_eq_ring(bp);
471de716 6216 bnx2x_init_internal(bp, load_code);
523224a3 6217 bnx2x_pf_init(bp);
0ef00459
EG
6218 bnx2x_stats_init(bp);
6219
0ef00459
EG
6220 /* flush all before enabling interrupts */
6221 mb();
6222 mmiowb();
6223
615f8fd9 6224 bnx2x_int_enable(bp);
eb8da205
EG
6225
6226 /* Check for SPIO5 */
6227 bnx2x_attn_int_deasserted0(bp,
6228 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6229 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
6230}
6231
ecf01c22 6232/* gzip service functions */
a2fbb9ea
ET
6233static int bnx2x_gunzip_init(struct bnx2x *bp)
6234{
1a983142
FT
6235 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6236 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
6237 if (bp->gunzip_buf == NULL)
6238 goto gunzip_nomem1;
6239
6240 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6241 if (bp->strm == NULL)
6242 goto gunzip_nomem2;
6243
7ab24bfd 6244 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
6245 if (bp->strm->workspace == NULL)
6246 goto gunzip_nomem3;
6247
6248 return 0;
6249
6250gunzip_nomem3:
6251 kfree(bp->strm);
6252 bp->strm = NULL;
6253
6254gunzip_nomem2:
1a983142
FT
6255 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6256 bp->gunzip_mapping);
a2fbb9ea
ET
6257 bp->gunzip_buf = NULL;
6258
6259gunzip_nomem1:
51c1a580 6260 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
6261 return -ENOMEM;
6262}
6263
6264static void bnx2x_gunzip_end(struct bnx2x *bp)
6265{
b3b83c3f 6266 if (bp->strm) {
7ab24bfd 6267 vfree(bp->strm->workspace);
b3b83c3f
DK
6268 kfree(bp->strm);
6269 bp->strm = NULL;
6270 }
a2fbb9ea
ET
6271
6272 if (bp->gunzip_buf) {
1a983142
FT
6273 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6274 bp->gunzip_mapping);
a2fbb9ea
ET
6275 bp->gunzip_buf = NULL;
6276 }
6277}
6278
94a78b79 6279static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
6280{
6281 int n, rc;
6282
6283 /* check gzip header */
94a78b79
VZ
6284 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6285 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 6286 return -EINVAL;
94a78b79 6287 }
a2fbb9ea
ET
6288
6289 n = 10;
6290
34f80b04 6291#define FNAME 0x8
a2fbb9ea
ET
6292
6293 if (zbuf[3] & FNAME)
6294 while ((zbuf[n++] != 0) && (n < len));
6295
94a78b79 6296 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
6297 bp->strm->avail_in = len - n;
6298 bp->strm->next_out = bp->gunzip_buf;
6299 bp->strm->avail_out = FW_BUF_SIZE;
6300
6301 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6302 if (rc != Z_OK)
6303 return rc;
6304
6305 rc = zlib_inflate(bp->strm, Z_FINISH);
6306 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
6307 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6308 bp->strm->msg);
a2fbb9ea
ET
6309
6310 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6311 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
6312 netdev_err(bp->dev,
6313 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 6314 bp->gunzip_outlen);
a2fbb9ea
ET
6315 bp->gunzip_outlen >>= 2;
6316
6317 zlib_inflateEnd(bp->strm);
6318
6319 if (rc == Z_STREAM_END)
6320 return 0;
6321
6322 return rc;
6323}
6324
6325/* nic load/unload */
6326
6327/*
34f80b04 6328 * General service functions
a2fbb9ea
ET
6329 */
6330
6331/* send a NIG loopback debug packet */
6332static void bnx2x_lb_pckt(struct bnx2x *bp)
6333{
a2fbb9ea 6334 u32 wb_write[3];
a2fbb9ea
ET
6335
6336 /* Ethernet source and destination addresses */
a2fbb9ea
ET
6337 wb_write[0] = 0x55555555;
6338 wb_write[1] = 0x55555555;
34f80b04 6339 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 6340 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6341
6342 /* NON-IP protocol */
a2fbb9ea
ET
6343 wb_write[0] = 0x09000000;
6344 wb_write[1] = 0x55555555;
34f80b04 6345 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 6346 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6347}
6348
6349/* some of the internal memories
6350 * are not directly readable from the driver
6351 * to test them we send debug packets
6352 */
6353static int bnx2x_int_mem_test(struct bnx2x *bp)
6354{
6355 int factor;
6356 int count, i;
6357 u32 val = 0;
6358
ad8d3948 6359 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 6360 factor = 120;
ad8d3948
EG
6361 else if (CHIP_REV_IS_EMUL(bp))
6362 factor = 200;
6363 else
a2fbb9ea 6364 factor = 1;
a2fbb9ea 6365
a2fbb9ea
ET
6366 /* Disable inputs of parser neighbor blocks */
6367 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6368 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6369 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6370 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6371
6372 /* Write 0 to parser credits for CFC search request */
6373 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6374
6375 /* send Ethernet packet */
6376 bnx2x_lb_pckt(bp);
6377
6378 /* TODO do i reset NIG statistic? */
6379 /* Wait until NIG register shows 1 packet of size 0x10 */
6380 count = 1000 * factor;
6381 while (count) {
34f80b04 6382
a2fbb9ea
ET
6383 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6384 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6385 if (val == 0x10)
6386 break;
6387
639d65b8 6388 usleep_range(10000, 20000);
a2fbb9ea
ET
6389 count--;
6390 }
6391 if (val != 0x10) {
6392 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6393 return -1;
6394 }
6395
6396 /* Wait until PRS register shows 1 packet */
6397 count = 1000 * factor;
6398 while (count) {
6399 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
6400 if (val == 1)
6401 break;
6402
639d65b8 6403 usleep_range(10000, 20000);
a2fbb9ea
ET
6404 count--;
6405 }
6406 if (val != 0x1) {
6407 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6408 return -2;
6409 }
6410
6411 /* Reset and init BRB, PRS */
34f80b04 6412 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 6413 msleep(50);
34f80b04 6414 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 6415 msleep(50);
619c5cb6
VZ
6416 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6417 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
6418
6419 DP(NETIF_MSG_HW, "part2\n");
6420
6421 /* Disable inputs of parser neighbor blocks */
6422 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6423 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6424 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6425 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6426
6427 /* Write 0 to parser credits for CFC search request */
6428 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6429
6430 /* send 10 Ethernet packets */
6431 for (i = 0; i < 10; i++)
6432 bnx2x_lb_pckt(bp);
6433
6434 /* Wait until NIG register shows 10 + 1
6435 packets of size 11*0x10 = 0xb0 */
6436 count = 1000 * factor;
6437 while (count) {
34f80b04 6438
a2fbb9ea
ET
6439 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6440 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6441 if (val == 0xb0)
6442 break;
6443
639d65b8 6444 usleep_range(10000, 20000);
a2fbb9ea
ET
6445 count--;
6446 }
6447 if (val != 0xb0) {
6448 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6449 return -3;
6450 }
6451
6452 /* Wait until PRS register shows 2 packets */
6453 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6454 if (val != 2)
6455 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6456
6457 /* Write 1 to parser credits for CFC search request */
6458 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6459
6460 /* Wait until PRS register shows 3 packets */
6461 msleep(10 * factor);
6462 /* Wait until NIG register shows 1 packet of size 0x10 */
6463 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6464 if (val != 3)
6465 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6466
6467 /* clear NIG EOP FIFO */
6468 for (i = 0; i < 11; i++)
6469 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6470 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6471 if (val != 1) {
6472 BNX2X_ERR("clear of NIG failed\n");
6473 return -4;
6474 }
6475
6476 /* Reset and init BRB, PRS, NIG */
6477 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6478 msleep(50);
6479 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6480 msleep(50);
619c5cb6
VZ
6481 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6482 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6483 if (!CNIC_SUPPORT(bp))
6484 /* set NIC mode */
6485 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6486
6487 /* Enable inputs of parser neighbor blocks */
6488 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6489 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6490 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6491 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6492
6493 DP(NETIF_MSG_HW, "done\n");
6494
6495 return 0; /* OK */
6496}
6497
4a33bc03 6498static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea 6499{
b343d002
YM
6500 u32 val;
6501
a2fbb9ea 6502 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6503 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6504 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6505 else
6506 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6507 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6508 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6509 /*
6510 * mask read length error interrupts in brb for parser
6511 * (parsing unit and 'checksum and crc' unit)
6512 * these errors are legal (PU reads fixed length and CAC can cause
6513 * read length error on truncated packets)
6514 */
6515 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6516 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6517 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6518 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6519 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6520 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6521/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6522/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6523 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6524 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6525 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6526/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6527/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6528 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6529 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6530 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6531 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6532/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6533/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6534
b343d002
YM
6535 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6536 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6537 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6538 if (!CHIP_IS_E1x(bp))
6539 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6540 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6541 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6542
a2fbb9ea
ET
6543 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6544 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6545 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6546/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6547
6548 if (!CHIP_IS_E1x(bp))
6549 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6550 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6551
a2fbb9ea
ET
6552 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6553 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6554/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6555 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6556}
6557
81f75bbf
EG
6558static void bnx2x_reset_common(struct bnx2x *bp)
6559{
619c5cb6
VZ
6560 u32 val = 0x1400;
6561
81f75bbf
EG
6562 /* reset_common */
6563 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6564 0xd3ffff7f);
619c5cb6
VZ
6565
6566 if (CHIP_IS_E3(bp)) {
6567 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6568 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6569 }
6570
6571 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6572}
6573
6574static void bnx2x_setup_dmae(struct bnx2x *bp)
6575{
6576 bp->dmae_ready = 0;
6577 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6578}
6579
573f2035
EG
6580static void bnx2x_init_pxp(struct bnx2x *bp)
6581{
6582 u16 devctl;
6583 int r_order, w_order;
6584
2a80eebc 6585 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6586 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6587 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6588 if (bp->mrrs == -1)
6589 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6590 else {
6591 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6592 r_order = bp->mrrs;
6593 }
6594
6595 bnx2x_init_pxp_arb(bp, r_order, w_order);
6596}
fd4ef40d
EG
6597
6598static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6599{
2145a920 6600 int is_required;
fd4ef40d 6601 u32 val;
2145a920 6602 int port;
fd4ef40d 6603
2145a920
VZ
6604 if (BP_NOMCP(bp))
6605 return;
6606
6607 is_required = 0;
fd4ef40d
EG
6608 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6609 SHARED_HW_CFG_FAN_FAILURE_MASK;
6610
6611 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6612 is_required = 1;
6613
6614 /*
6615 * The fan failure mechanism is usually related to the PHY type since
6616 * the power consumption of the board is affected by the PHY. Currently,
6617 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6618 */
6619 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6620 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6621 is_required |=
d90d96ba
YR
6622 bnx2x_fan_failure_det_req(
6623 bp,
6624 bp->common.shmem_base,
a22f0788 6625 bp->common.shmem2_base,
d90d96ba 6626 port);
fd4ef40d
EG
6627 }
6628
6629 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6630
6631 if (is_required == 0)
6632 return;
6633
6634 /* Fan failure is indicated by SPIO 5 */
d6d99a3f 6635 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
fd4ef40d
EG
6636
6637 /* set to active low mode */
6638 val = REG_RD(bp, MISC_REG_SPIO_INT);
d6d99a3f 6639 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6640 REG_WR(bp, MISC_REG_SPIO_INT, val);
6641
6642 /* enable interrupt to signal the IGU */
6643 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6644 val |= MISC_SPIO_SPIO5;
fd4ef40d
EG
6645 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6646}
6647
c9ee9206 6648void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6649{
6650 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6651 val &= ~IGU_PF_CONF_FUNC_EN;
6652
6653 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6654 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6655 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6656}
6657
1191cb83 6658static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6659{
6660 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6661 /* Avoid common init in case MFW supports LFA */
6662 if (SHMEM2_RD(bp, size) >
6663 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6664 return;
619c5cb6
VZ
6665 shmem_base[0] = bp->common.shmem_base;
6666 shmem2_base[0] = bp->common.shmem2_base;
6667 if (!CHIP_IS_E1x(bp)) {
6668 shmem_base[1] =
6669 SHMEM2_RD(bp, other_shmem_base_addr);
6670 shmem2_base[1] =
6671 SHMEM2_RD(bp, other_shmem2_base_addr);
6672 }
6673 bnx2x_acquire_phy_lock(bp);
6674 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6675 bp->common.chip_id);
6676 bnx2x_release_phy_lock(bp);
6677}
6678
6679/**
6680 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6681 *
6682 * @bp: driver handle
6683 */
6684static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6685{
619c5cb6 6686 u32 val;
a2fbb9ea 6687
51c1a580 6688 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6689
2031bd3a 6690 /*
2de67439 6691 * take the RESET lock to protect undi_unload flow from accessing
2031bd3a
DK
6692 * registers while we're resetting the chip
6693 */
7a06a122 6694 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6695
81f75bbf 6696 bnx2x_reset_common(bp);
34f80b04 6697 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6698
619c5cb6
VZ
6699 val = 0xfffc;
6700 if (CHIP_IS_E3(bp)) {
6701 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6702 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6703 }
6704 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6705
7a06a122 6706 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6707
619c5cb6 6708 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6709
619c5cb6
VZ
6710 if (!CHIP_IS_E1x(bp)) {
6711 u8 abs_func_id;
f2e0899f
DK
6712
6713 /**
6714 * 4-port mode or 2-port mode we need to turn of master-enable
6715 * for everyone, after that, turn it back on for self.
6716 * so, we disregard multi-function or not, and always disable
6717 * for all functions on the given path, this means 0,2,4,6 for
6718 * path 0 and 1,3,5,7 for path 1
6719 */
619c5cb6
VZ
6720 for (abs_func_id = BP_PATH(bp);
6721 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6722 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6723 REG_WR(bp,
6724 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6725 1);
6726 continue;
6727 }
6728
619c5cb6 6729 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6730 /* clear pf enable */
6731 bnx2x_pf_disable(bp);
6732 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6733 }
6734 }
a2fbb9ea 6735
619c5cb6 6736 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6737 if (CHIP_IS_E1(bp)) {
6738 /* enable HW interrupt from PXP on USDM overflow
6739 bit 16 on INT_MASK_0 */
6740 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6741 }
a2fbb9ea 6742
619c5cb6 6743 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6744 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6745
6746#ifdef __BIG_ENDIAN
34f80b04
EG
6747 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6748 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6749 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6750 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6751 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6752 /* make sure this value is 0 */
6753 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6754
6755/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6756 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6757 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6758 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6759 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6760#endif
6761
523224a3
DK
6762 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6763
34f80b04
EG
6764 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6765 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6766
34f80b04
EG
6767 /* let the HW do it's magic ... */
6768 msleep(100);
6769 /* finish PXP init */
6770 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6771 if (val != 1) {
6772 BNX2X_ERR("PXP2 CFG failed\n");
6773 return -EBUSY;
6774 }
6775 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6776 if (val != 1) {
6777 BNX2X_ERR("PXP2 RD_INIT failed\n");
6778 return -EBUSY;
6779 }
a2fbb9ea 6780
f2e0899f
DK
6781 /* Timers bug workaround E2 only. We need to set the entire ILT to
6782 * have entries with value "0" and valid bit on.
6783 * This needs to be done by the first PF that is loaded in a path
6784 * (i.e. common phase)
6785 */
619c5cb6
VZ
6786 if (!CHIP_IS_E1x(bp)) {
6787/* In E2 there is a bug in the timers block that can cause function 6 / 7
6788 * (i.e. vnic3) to start even if it is marked as "scan-off".
6789 * This occurs when a different function (func2,3) is being marked
6790 * as "scan-off". Real-life scenario for example: if a driver is being
6791 * load-unloaded while func6,7 are down. This will cause the timer to access
6792 * the ilt, translate to a logical address and send a request to read/write.
6793 * Since the ilt for the function that is down is not valid, this will cause
6794 * a translation error which is unrecoverable.
6795 * The Workaround is intended to make sure that when this happens nothing fatal
6796 * will occur. The workaround:
6797 * 1. First PF driver which loads on a path will:
6798 * a. After taking the chip out of reset, by using pretend,
6799 * it will write "0" to the following registers of
6800 * the other vnics.
6801 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6802 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6803 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6804 * And for itself it will write '1' to
6805 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6806 * dmae-operations (writing to pram for example.)
6807 * note: can be done for only function 6,7 but cleaner this
6808 * way.
6809 * b. Write zero+valid to the entire ILT.
6810 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6811 * VNIC3 (of that port). The range allocated will be the
6812 * entire ILT. This is needed to prevent ILT range error.
6813 * 2. Any PF driver load flow:
6814 * a. ILT update with the physical addresses of the allocated
6815 * logical pages.
6816 * b. Wait 20msec. - note that this timeout is needed to make
6817 * sure there are no requests in one of the PXP internal
6818 * queues with "old" ILT addresses.
6819 * c. PF enable in the PGLC.
6820 * d. Clear the was_error of the PF in the PGLC. (could have
2de67439 6821 * occurred while driver was down)
619c5cb6
VZ
6822 * e. PF enable in the CFC (WEAK + STRONG)
6823 * f. Timers scan enable
6824 * 3. PF driver unload flow:
6825 * a. Clear the Timers scan_en.
6826 * b. Polling for scan_on=0 for that PF.
6827 * c. Clear the PF enable bit in the PXP.
6828 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6829 * e. Write zero+valid to all ILT entries (The valid bit must
6830 * stay set)
6831 * f. If this is VNIC 3 of a port then also init
6832 * first_timers_ilt_entry to zero and last_timers_ilt_entry
16a5fd92 6833 * to the last entry in the ILT.
619c5cb6
VZ
6834 *
6835 * Notes:
6836 * Currently the PF error in the PGLC is non recoverable.
6837 * In the future the there will be a recovery routine for this error.
6838 * Currently attention is masked.
6839 * Having an MCP lock on the load/unload process does not guarantee that
6840 * there is no Timer disable during Func6/7 enable. This is because the
6841 * Timers scan is currently being cleared by the MCP on FLR.
6842 * Step 2.d can be done only for PF6/7 and the driver can also check if
6843 * there is error before clearing it. But the flow above is simpler and
6844 * more general.
6845 * All ILT entries are written by zero+valid and not just PF6/7
6846 * ILT entries since in the future the ILT entries allocation for
6847 * PF-s might be dynamic.
6848 */
f2e0899f
DK
6849 struct ilt_client_info ilt_cli;
6850 struct bnx2x_ilt ilt;
6851 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6852 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6853
b595076a 6854 /* initialize dummy TM client */
f2e0899f
DK
6855 ilt_cli.start = 0;
6856 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6857 ilt_cli.client_num = ILT_CLIENT_TM;
6858
6859 /* Step 1: set zeroes to all ilt page entries with valid bit on
6860 * Step 2: set the timers first/last ilt entry to point
6861 * to the entire range to prevent ILT range error for 3rd/4th
2de67439 6862 * vnic (this code assumes existence of the vnic)
f2e0899f
DK
6863 *
6864 * both steps performed by call to bnx2x_ilt_client_init_op()
6865 * with dummy TM client
6866 *
6867 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6868 * and his brother are split registers
6869 */
6870 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6871 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6872 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6873
6874 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6875 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6876 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6877 }
6878
34f80b04
EG
6879 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6880 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6881
619c5cb6 6882 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6883 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6884 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6885 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6886
619c5cb6 6887 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6888
6889 /* let the HW do it's magic ... */
6890 do {
6891 msleep(200);
6892 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6893 } while (factor-- && (val != 1));
6894
6895 if (val != 1) {
6896 BNX2X_ERR("ATC_INIT failed\n");
6897 return -EBUSY;
6898 }
6899 }
6900
619c5cb6 6901 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6902
b56e9670
AE
6903 bnx2x_iov_init_dmae(bp);
6904
34f80b04
EG
6905 /* clean the DMAE memory */
6906 bp->dmae_ready = 1;
619c5cb6
VZ
6907 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6908
6909 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6910
6911 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6912
6913 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6914
619c5cb6 6915 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6916
34f80b04
EG
6917 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6918 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6919 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6920 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6921
619c5cb6 6922 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6923
523224a3
DK
6924 /* QM queues pointers table */
6925 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6926
34f80b04
EG
6927 /* soft reset pulse */
6928 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6929 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6930
55c11941
MS
6931 if (CNIC_SUPPORT(bp))
6932 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6933
619c5cb6 6934 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
b9871bcf 6935
619c5cb6 6936 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6937 /* enable hw interrupt from doorbell Q */
6938 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6939
619c5cb6 6940 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6941
619c5cb6 6942 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6943 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6944
f2e0899f 6945 if (!CHIP_IS_E1(bp))
619c5cb6 6946 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6947
a3348722
BW
6948 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6949 if (IS_MF_AFEX(bp)) {
6950 /* configure that VNTag and VLAN headers must be
6951 * received in afex mode
6952 */
6953 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6954 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6955 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6956 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6957 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6958 } else {
6959 /* Bit-map indicating which L2 hdrs may appear
6960 * after the basic Ethernet header
6961 */
6962 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6963 bp->path_has_ovlan ? 7 : 6);
6964 }
6965 }
a2fbb9ea 6966
619c5cb6
VZ
6967 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6968 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6969 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6970 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6971
619c5cb6
VZ
6972 if (!CHIP_IS_E1x(bp)) {
6973 /* reset VFC memories */
6974 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6975 VFC_MEMORIES_RST_REG_CAM_RST |
6976 VFC_MEMORIES_RST_REG_RAM_RST);
6977 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6978 VFC_MEMORIES_RST_REG_CAM_RST |
6979 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6980
619c5cb6
VZ
6981 msleep(20);
6982 }
a2fbb9ea 6983
619c5cb6
VZ
6984 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6985 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6986 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6987 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6988
34f80b04
EG
6989 /* sync semi rtc */
6990 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6991 0x80000000);
6992 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6993 0x80000000);
a2fbb9ea 6994
619c5cb6
VZ
6995 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6996 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6997 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6998
a3348722
BW
6999 if (!CHIP_IS_E1x(bp)) {
7000 if (IS_MF_AFEX(bp)) {
7001 /* configure that VNTag and VLAN headers must be
7002 * sent in afex mode
7003 */
7004 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
7005 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
7006 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
7007 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
7008 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
7009 } else {
7010 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
7011 bp->path_has_ovlan ? 7 : 6);
7012 }
7013 }
f2e0899f 7014
34f80b04 7015 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 7016
619c5cb6
VZ
7017 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
7018
55c11941
MS
7019 if (CNIC_SUPPORT(bp)) {
7020 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
7021 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
7022 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
7023 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
7024 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
7025 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
7026 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
7027 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
7028 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
7029 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
7030 }
34f80b04 7031 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 7032
34f80b04
EG
7033 if (sizeof(union cdu_context) != 1024)
7034 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
7035 dev_alert(&bp->pdev->dev,
7036 "please adjust the size of cdu_context(%ld)\n",
7037 (long)sizeof(union cdu_context));
a2fbb9ea 7038
619c5cb6 7039 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
7040 val = (4 << 24) + (0 << 12) + 1024;
7041 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 7042
619c5cb6 7043 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 7044 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
7045 /* enable context validation interrupt from CFC */
7046 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
7047
7048 /* set the thresholds to prevent CFC/CDU race */
7049 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 7050
619c5cb6 7051 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 7052
619c5cb6 7053 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
7054 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
7055
619c5cb6
VZ
7056 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
7057 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 7058
34f80b04
EG
7059 /* Reset PCIE errors for debug */
7060 REG_WR(bp, 0x2814, 0xffffffff);
7061 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 7062
619c5cb6 7063 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7064 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
7065 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
7066 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
7067 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
7068 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
7069 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
7070 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
7071 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
7072 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
7073 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
7074 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
7075 }
7076
619c5cb6 7077 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 7078 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
7079 /* in E3 this done in per-port section */
7080 if (!CHIP_IS_E3(bp))
7081 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 7082 }
619c5cb6
VZ
7083 if (CHIP_IS_E1H(bp))
7084 /* not applicable for E2 (and above ...) */
7085 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
7086
7087 if (CHIP_REV_IS_SLOW(bp))
7088 msleep(200);
7089
7090 /* finish CFC init */
7091 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
7092 if (val != 1) {
7093 BNX2X_ERR("CFC LL_INIT failed\n");
7094 return -EBUSY;
7095 }
7096 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
7097 if (val != 1) {
7098 BNX2X_ERR("CFC AC_INIT failed\n");
7099 return -EBUSY;
7100 }
7101 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
7102 if (val != 1) {
7103 BNX2X_ERR("CFC CAM_INIT failed\n");
7104 return -EBUSY;
7105 }
7106 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 7107
f2e0899f
DK
7108 if (CHIP_IS_E1(bp)) {
7109 /* read NIG statistic
7110 to see if this is our first up since powerup */
7111 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
7112 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 7113
f2e0899f
DK
7114 /* do internal memory self test */
7115 if ((val == 0) && bnx2x_int_mem_test(bp)) {
7116 BNX2X_ERR("internal mem self test failed\n");
7117 return -EBUSY;
7118 }
34f80b04
EG
7119 }
7120
fd4ef40d
EG
7121 bnx2x_setup_fan_failure_detection(bp);
7122
34f80b04
EG
7123 /* clear PXP2 attentions */
7124 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 7125
4a33bc03 7126 bnx2x_enable_blocks_attention(bp);
c9ee9206 7127 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 7128
6bbca910 7129 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
7130 if (CHIP_IS_E1x(bp))
7131 bnx2x__common_init_phy(bp);
6bbca910
YR
7132 } else
7133 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
7134
34f80b04
EG
7135 return 0;
7136}
a2fbb9ea 7137
619c5cb6
VZ
7138/**
7139 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
7140 *
7141 * @bp: driver handle
7142 */
7143static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
7144{
7145 int rc = bnx2x_init_hw_common(bp);
7146
7147 if (rc)
7148 return rc;
7149
7150 /* In E2 2-PORT mode, same ext phy is used for the two paths */
7151 if (!BP_NOMCP(bp))
7152 bnx2x__common_init_phy(bp);
7153
7154 return 0;
7155}
7156
523224a3 7157static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
7158{
7159 int port = BP_PORT(bp);
619c5cb6 7160 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 7161 u32 low, high;
4293b9f5 7162 u32 val, reg;
a2fbb9ea 7163
51c1a580 7164 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
7165
7166 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 7167
619c5cb6
VZ
7168 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7169 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7170 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 7171
f2e0899f
DK
7172 /* Timers bug workaround: disables the pf_master bit in pglue at
7173 * common phase, we need to enable it here before any dmae access are
7174 * attempted. Therefore we manually added the enable-master to the
7175 * port phase (it also happens in the function phase)
7176 */
619c5cb6 7177 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7178 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7179
619c5cb6
VZ
7180 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7181 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7182 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7183 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7184
7185 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7186 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7187 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7188 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 7189
523224a3
DK
7190 /* QM cid (connection) count */
7191 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 7192
55c11941
MS
7193 if (CNIC_SUPPORT(bp)) {
7194 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7195 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7196 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7197 }
cdaa7cb8 7198
619c5cb6 7199 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 7200
2b674047
DK
7201 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7202
f2e0899f 7203 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
7204
7205 if (IS_MF(bp))
7206 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7207 else if (bp->dev->mtu > 4096) {
7208 if (bp->flags & ONE_PORT_FLAG)
7209 low = 160;
7210 else {
7211 val = bp->dev->mtu;
7212 /* (24*1024 + val*4)/256 */
7213 low = 96 + (val/64) +
7214 ((val % 64) ? 1 : 0);
7215 }
7216 } else
7217 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7218 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
7219 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7220 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 7221 }
1c06328c 7222
619c5cb6
VZ
7223 if (CHIP_MODE_IS_4_PORT(bp))
7224 REG_WR(bp, (BP_PORT(bp) ?
7225 BRB1_REG_MAC_GUARANTIED_1 :
7226 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 7227
619c5cb6 7228 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
7229 if (CHIP_IS_E3B0(bp)) {
7230 if (IS_MF_AFEX(bp)) {
7231 /* configure headers for AFEX mode */
7232 REG_WR(bp, BP_PORT(bp) ?
7233 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7234 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7235 REG_WR(bp, BP_PORT(bp) ?
7236 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7237 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7238 REG_WR(bp, BP_PORT(bp) ?
7239 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7240 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7241 } else {
7242 /* Ovlan exists only if we are in multi-function +
7243 * switch-dependent mode, in switch-independent there
7244 * is no ovlan headers
7245 */
7246 REG_WR(bp, BP_PORT(bp) ?
7247 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7248 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7249 (bp->path_has_ovlan ? 7 : 6));
7250 }
7251 }
356e2385 7252
619c5cb6
VZ
7253 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7254 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7255 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7256 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 7257
619c5cb6
VZ
7258 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7259 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7260 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7261 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 7262
619c5cb6
VZ
7263 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7264 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 7265
619c5cb6
VZ
7266 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7267
7268 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
7269 /* configure PBF to work without PAUSE mtu 9000 */
7270 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 7271
f2e0899f
DK
7272 /* update threshold */
7273 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7274 /* update init credit */
7275 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 7276
f2e0899f
DK
7277 /* probe changes */
7278 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7279 udelay(50);
7280 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7281 }
a2fbb9ea 7282
55c11941
MS
7283 if (CNIC_SUPPORT(bp))
7284 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7285
619c5cb6
VZ
7286 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7287 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
7288
7289 if (CHIP_IS_E1(bp)) {
7290 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7291 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7292 }
619c5cb6 7293 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 7294
619c5cb6 7295 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7296
619c5cb6 7297 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04 7298 /* init aeu_mask_attn_func_0/1:
16a5fd92
YM
7299 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7300 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
34f80b04 7301 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
7302 val = IS_MF(bp) ? 0xF7 : 0x7;
7303 /* Enable DCBX attention for all but E1 */
7304 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7305 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 7306
4293b9f5
DK
7307 /* SCPAD_PARITY should NOT trigger close the gates */
7308 reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
7309 REG_WR(bp, reg,
7310 REG_RD(bp, reg) &
7311 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7312
7313 reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
7314 REG_WR(bp, reg,
7315 REG_RD(bp, reg) &
7316 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7317
619c5cb6
VZ
7318 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7319
7320 if (!CHIP_IS_E1x(bp)) {
7321 /* Bit-map indicating which L2 hdrs may appear after the
7322 * basic Ethernet header
7323 */
a3348722
BW
7324 if (IS_MF_AFEX(bp))
7325 REG_WR(bp, BP_PORT(bp) ?
7326 NIG_REG_P1_HDRS_AFTER_BASIC :
7327 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7328 else
7329 REG_WR(bp, BP_PORT(bp) ?
7330 NIG_REG_P1_HDRS_AFTER_BASIC :
7331 NIG_REG_P0_HDRS_AFTER_BASIC,
7332 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
7333
7334 if (CHIP_IS_E3(bp))
7335 REG_WR(bp, BP_PORT(bp) ?
7336 NIG_REG_LLH1_MF_MODE :
7337 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7338 }
7339 if (!CHIP_IS_E3(bp))
7340 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 7341
f2e0899f 7342 if (!CHIP_IS_E1(bp)) {
fb3bff17 7343 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 7344 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 7345 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 7346
619c5cb6 7347 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7348 val = 0;
7349 switch (bp->mf_mode) {
7350 case MULTI_FUNCTION_SD:
7351 val = 1;
7352 break;
7353 case MULTI_FUNCTION_SI:
a3348722 7354 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
7355 val = 2;
7356 break;
7357 }
7358
7359 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7360 NIG_REG_LLH0_CLS_TYPE), val);
7361 }
1c06328c
EG
7362 {
7363 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7364 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7365 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7366 }
34f80b04
EG
7367 }
7368
619c5cb6
VZ
7369 /* If SPIO5 is set to generate interrupts, enable it for this port */
7370 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 7371 if (val & MISC_SPIO_SPIO5) {
4d295db0
EG
7372 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7373 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7374 val = REG_RD(bp, reg_addr);
f1410647 7375 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 7376 REG_WR(bp, reg_addr, val);
f1410647 7377 }
a2fbb9ea 7378
34f80b04
EG
7379 return 0;
7380}
7381
34f80b04
EG
7382static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7383{
7384 int reg;
32d68de1 7385 u32 wb_write[2];
34f80b04 7386
f2e0899f 7387 if (CHIP_IS_E1(bp))
34f80b04 7388 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
7389 else
7390 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 7391
32d68de1
YM
7392 wb_write[0] = ONCHIP_ADDR1(addr);
7393 wb_write[1] = ONCHIP_ADDR2(addr);
7394 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
7395}
7396
b56e9670 7397void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
1191cb83
ED
7398{
7399 u32 data, ctl, cnt = 100;
7400 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7401 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7402 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7403 u32 sb_bit = 1 << (idu_sb_id%32);
b56e9670 7404 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
1191cb83
ED
7405 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7406
7407 /* Not supported in BC mode */
7408 if (CHIP_INT_MODE_IS_BC(bp))
7409 return;
7410
7411 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7412 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7413 IGU_REGULAR_CLEANUP_SET |
7414 IGU_REGULAR_BCLEANUP;
7415
7416 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7417 func_encode << IGU_CTRL_REG_FID_SHIFT |
7418 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7419
7420 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7421 data, igu_addr_data);
7422 REG_WR(bp, igu_addr_data, data);
7423 mmiowb();
7424 barrier();
7425 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7426 ctl, igu_addr_ctl);
7427 REG_WR(bp, igu_addr_ctl, ctl);
7428 mmiowb();
7429 barrier();
7430
7431 /* wait for clean up to finish */
7432 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7433 msleep(20);
7434
1191cb83
ED
7435 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7436 DP(NETIF_MSG_HW,
7437 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7438 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7439 }
7440}
7441
7442static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7443{
619c5cb6 7444 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7445}
7446
1191cb83 7447static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7448{
7449 u32 i, base = FUNC_ILT_BASE(func);
7450 for (i = base; i < base + ILT_PER_FUNC; i++)
7451 bnx2x_ilt_wr(bp, i, 0);
7452}
7453
910cc727 7454static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7455{
7456 int port = BP_PORT(bp);
7457 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7458 /* T1 hash bits value determines the T1 number of entries */
7459 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7460}
7461
7462static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7463{
7464 int rc;
7465 struct bnx2x_func_state_params func_params = {NULL};
7466 struct bnx2x_func_switch_update_params *switch_update_params =
7467 &func_params.params.switch_update;
7468
7469 /* Prepare parameters for function state transitions */
7470 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7471 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7472
7473 func_params.f_obj = &bp->func_obj;
7474 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7475
7476 /* Function parameters */
7477 switch_update_params->suspend = suspend;
7478
7479 rc = bnx2x_func_state_change(bp, &func_params);
7480
7481 return rc;
7482}
7483
910cc727 7484static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7485{
7486 int rc, i, port = BP_PORT(bp);
7487 int vlan_en = 0, mac_en[NUM_MACS];
7488
55c11941
MS
7489 /* Close input from network */
7490 if (bp->mf_mode == SINGLE_FUNCTION) {
7491 bnx2x_set_rx_filter(&bp->link_params, 0);
7492 } else {
7493 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7494 NIG_REG_LLH0_FUNC_EN);
7495 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7496 NIG_REG_LLH0_FUNC_EN, 0);
7497 for (i = 0; i < NUM_MACS; i++) {
7498 mac_en[i] = REG_RD(bp, port ?
7499 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7500 4 * i) :
7501 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7502 4 * i));
7503 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7504 4 * i) :
7505 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7506 }
7507 }
7508
7509 /* Close BMC to host */
7510 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7511 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7512
7513 /* Suspend Tx switching to the PF. Completion of this ramrod
7514 * further guarantees that all the packets of that PF / child
7515 * VFs in BRB were processed by the Parser, so it is safe to
7516 * change the NIC_MODE register.
7517 */
7518 rc = bnx2x_func_switch_update(bp, 1);
7519 if (rc) {
7520 BNX2X_ERR("Can't suspend tx-switching!\n");
7521 return rc;
7522 }
7523
7524 /* Change NIC_MODE register */
7525 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7526
7527 /* Open input from network */
7528 if (bp->mf_mode == SINGLE_FUNCTION) {
7529 bnx2x_set_rx_filter(&bp->link_params, 1);
7530 } else {
7531 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7532 NIG_REG_LLH0_FUNC_EN, vlan_en);
7533 for (i = 0; i < NUM_MACS; i++) {
7534 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7535 4 * i) :
7536 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7537 mac_en[i]);
7538 }
7539 }
7540
7541 /* Enable BMC to host */
7542 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7543 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7544
7545 /* Resume Tx switching to the PF */
7546 rc = bnx2x_func_switch_update(bp, 0);
7547 if (rc) {
7548 BNX2X_ERR("Can't resume tx-switching!\n");
7549 return rc;
7550 }
7551
7552 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7553 return 0;
7554}
7555
7556int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7557{
7558 int rc;
7559
7560 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7561
7562 if (CONFIGURE_NIC_MODE(bp)) {
16a5fd92 7563 /* Configure searcher as part of function hw init */
55c11941
MS
7564 bnx2x_init_searcher(bp);
7565
7566 /* Reset NIC mode */
7567 rc = bnx2x_reset_nic_mode(bp);
7568 if (rc)
7569 BNX2X_ERR("Can't change NIC mode!\n");
7570 return rc;
7571 }
7572
7573 return 0;
7574}
7575
523224a3 7576static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7577{
7578 int port = BP_PORT(bp);
7579 int func = BP_FUNC(bp);
619c5cb6 7580 int init_phase = PHASE_PF0 + func;
523224a3
DK
7581 struct bnx2x_ilt *ilt = BP_ILT(bp);
7582 u16 cdu_ilt_start;
8badd27a 7583 u32 addr, val;
f4a66897 7584 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7585 int i, main_mem_width, rc;
34f80b04 7586
51c1a580 7587 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7588
619c5cb6 7589 /* FLR cleanup - hmmm */
89db4ad8
AE
7590 if (!CHIP_IS_E1x(bp)) {
7591 rc = bnx2x_pf_flr_clnup(bp);
04c46736
YM
7592 if (rc) {
7593 bnx2x_fw_dump(bp);
89db4ad8 7594 return rc;
04c46736 7595 }
89db4ad8 7596 }
619c5cb6 7597
8badd27a 7598 /* set MSI reconfigure capability */
f2e0899f
DK
7599 if (bp->common.int_block == INT_BLOCK_HC) {
7600 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7601 val = REG_RD(bp, addr);
7602 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7603 REG_WR(bp, addr, val);
7604 }
8badd27a 7605
619c5cb6
VZ
7606 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7607 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7608
523224a3
DK
7609 ilt = BP_ILT(bp);
7610 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7611
290ca2bb
AE
7612 if (IS_SRIOV(bp))
7613 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7614 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7615
7616 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7617 * those of the VFs, so start line should be reset
7618 */
7619 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
523224a3 7620 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7621 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7622 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7623 bp->context[i].cxt_mapping;
7624 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7625 }
290ca2bb 7626
523224a3 7627 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7628
55c11941
MS
7629 if (!CONFIGURE_NIC_MODE(bp)) {
7630 bnx2x_init_searcher(bp);
7631 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7632 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7633 } else {
7634 /* Set NIC mode */
7635 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6bf07b8e 7636 DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
55c11941 7637 }
37b091ba 7638
619c5cb6 7639 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7640 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7641
7642 /* Turn on a single ISR mode in IGU if driver is going to use
7643 * INT#x or MSI
7644 */
7645 if (!(bp->flags & USING_MSIX_FLAG))
7646 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7647 /*
7648 * Timers workaround bug: function init part.
7649 * Need to wait 20msec after initializing ILT,
7650 * needed to make sure there are no requests in
7651 * one of the PXP internal queues with "old" ILT addresses
7652 */
7653 msleep(20);
7654 /*
7655 * Master enable - Due to WB DMAE writes performed before this
7656 * register is re-initialized as part of the regular function
7657 * init
7658 */
7659 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7660 /* Enable the function in IGU */
7661 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7662 }
7663
523224a3 7664 bp->dmae_ready = 1;
34f80b04 7665
619c5cb6 7666 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7667
619c5cb6 7668 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7669 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7670
619c5cb6
VZ
7671 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7672 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7673 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7674 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7675 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7676 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7677 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7678 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7679 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7680 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7681 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7682 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7683 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7684
7685 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7686 REG_WR(bp, QM_REG_PF_EN, 1);
7687
619c5cb6
VZ
7688 if (!CHIP_IS_E1x(bp)) {
7689 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7690 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7691 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7692 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7693 }
7694 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7695
7696 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7697 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
c19d65c9 7698 REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
b56e9670
AE
7699
7700 bnx2x_iov_init_dq(bp);
7701
619c5cb6
VZ
7702 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7703 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7704 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7705 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7706 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7707 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7708 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7709 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7710 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7711 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7712 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7713
619c5cb6 7714 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7715
619c5cb6 7716 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7717
619c5cb6 7718 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7719 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7720
fb3bff17 7721 if (IS_MF(bp)) {
34f80b04 7722 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7723 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7724 }
7725
619c5cb6 7726 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7727
34f80b04 7728 /* HC init per function */
f2e0899f
DK
7729 if (bp->common.int_block == INT_BLOCK_HC) {
7730 if (CHIP_IS_E1H(bp)) {
7731 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7732
7733 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7734 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7735 }
619c5cb6 7736 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7737
7738 } else {
7739 int num_segs, sb_idx, prod_offset;
7740
34f80b04
EG
7741 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7742
619c5cb6 7743 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7744 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7745 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7746 }
7747
619c5cb6 7748 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7749
619c5cb6 7750 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7751 int dsb_idx = 0;
7752 /**
7753 * Producer memory:
7754 * E2 mode: address 0-135 match to the mapping memory;
7755 * 136 - PF0 default prod; 137 - PF1 default prod;
7756 * 138 - PF2 default prod; 139 - PF3 default prod;
7757 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7758 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7759 * 144-147 reserved.
7760 *
7761 * E1.5 mode - In backward compatible mode;
7762 * for non default SB; each even line in the memory
7763 * holds the U producer and each odd line hold
7764 * the C producer. The first 128 producers are for
7765 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7766 * producers are for the DSB for each PF.
7767 * Each PF has five segments: (the order inside each
7768 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7769 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7770 * 144-147 attn prods;
7771 */
7772 /* non-default-status-blocks */
7773 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7774 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7775 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7776 prod_offset = (bp->igu_base_sb + sb_idx) *
7777 num_segs;
7778
7779 for (i = 0; i < num_segs; i++) {
7780 addr = IGU_REG_PROD_CONS_MEMORY +
7781 (prod_offset + i) * 4;
7782 REG_WR(bp, addr, 0);
7783 }
7784 /* send consumer update with value 0 */
7785 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7786 USTORM_ID, 0, IGU_INT_NOP, 1);
7787 bnx2x_igu_clear_sb(bp,
7788 bp->igu_base_sb + sb_idx);
7789 }
7790
7791 /* default-status-blocks */
7792 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7793 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7794
7795 if (CHIP_MODE_IS_4_PORT(bp))
7796 dsb_idx = BP_FUNC(bp);
7797 else
3395a033 7798 dsb_idx = BP_VN(bp);
f2e0899f
DK
7799
7800 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7801 IGU_BC_BASE_DSB_PROD + dsb_idx :
7802 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7803
3395a033
DK
7804 /*
7805 * igu prods come in chunks of E1HVN_MAX (4) -
7806 * does not matters what is the current chip mode
7807 */
f2e0899f
DK
7808 for (i = 0; i < (num_segs * E1HVN_MAX);
7809 i += E1HVN_MAX) {
7810 addr = IGU_REG_PROD_CONS_MEMORY +
7811 (prod_offset + i)*4;
7812 REG_WR(bp, addr, 0);
7813 }
7814 /* send consumer update with 0 */
7815 if (CHIP_INT_MODE_IS_BC(bp)) {
7816 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7817 USTORM_ID, 0, IGU_INT_NOP, 1);
7818 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7819 CSTORM_ID, 0, IGU_INT_NOP, 1);
7820 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7821 XSTORM_ID, 0, IGU_INT_NOP, 1);
7822 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7823 TSTORM_ID, 0, IGU_INT_NOP, 1);
7824 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7825 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7826 } else {
7827 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7828 USTORM_ID, 0, IGU_INT_NOP, 1);
7829 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7830 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7831 }
7832 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7833
16a5fd92 7834 /* !!! These should become driver const once
f2e0899f
DK
7835 rf-tool supports split-68 const */
7836 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7837 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7838 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7839 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7840 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7841 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7842 }
34f80b04 7843 }
34f80b04 7844
c14423fe 7845 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7846 REG_WR(bp, 0x2114, 0xffffffff);
7847 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7848
f4a66897
VZ
7849 if (CHIP_IS_E1x(bp)) {
7850 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7851 main_mem_base = HC_REG_MAIN_MEMORY +
7852 BP_PORT(bp) * (main_mem_size * 4);
7853 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7854 main_mem_width = 8;
7855
7856 val = REG_RD(bp, main_mem_prty_clr);
7857 if (val)
51c1a580
MS
7858 DP(NETIF_MSG_HW,
7859 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7860 val);
f4a66897
VZ
7861
7862 /* Clear "false" parity errors in MSI-X table */
7863 for (i = main_mem_base;
7864 i < main_mem_base + main_mem_size * 4;
7865 i += main_mem_width) {
7866 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7867 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7868 i, main_mem_width / 4);
7869 }
7870 /* Clear HC parity attention */
7871 REG_RD(bp, main_mem_prty_clr);
7872 }
7873
619c5cb6
VZ
7874#ifdef BNX2X_STOP_ON_ERROR
7875 /* Enable STORMs SP logging */
7876 REG_WR8(bp, BAR_USTRORM_INTMEM +
7877 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7878 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7879 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7880 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7881 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7882 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7883 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7884#endif
7885
b7737c9b 7886 bnx2x_phy_probe(&bp->link_params);
f85582f8 7887
34f80b04
EG
7888 return 0;
7889}
7890
55c11941
MS
7891void bnx2x_free_mem_cnic(struct bnx2x *bp)
7892{
7893 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7894
7895 if (!CHIP_IS_E1x(bp))
7896 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7897 sizeof(struct host_hc_status_block_e2));
7898 else
7899 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7900 sizeof(struct host_hc_status_block_e1x));
7901
7902 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7903}
7904
9f6c9258 7905void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7906{
a052997e
MS
7907 int i;
7908
619c5cb6
VZ
7909 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7910 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7911
b4cddbd6
AE
7912 if (IS_VF(bp))
7913 return;
7914
7915 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
7916 sizeof(struct host_sp_status_block));
7917
a2fbb9ea 7918 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7919 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7920
a052997e
MS
7921 for (i = 0; i < L2_ILT_LINES(bp); i++)
7922 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7923 bp->context[i].size);
523224a3
DK
7924 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7925
7926 BNX2X_FREE(bp->ilt->lines);
f85582f8 7927
7a9b2557 7928 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7929
523224a3
DK
7930 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7931 BCM_PAGE_SIZE * NUM_EQ_PAGES);
580d9d08 7932
05952246
YM
7933 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7934
580d9d08 7935 bnx2x_iov_free_mem(bp);
619c5cb6
VZ
7936}
7937
55c11941 7938int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7939{
619c5cb6
VZ
7940 if (!CHIP_IS_E1x(bp))
7941 /* size = the status block + ramrod buffers */
f2e0899f
DK
7942 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7943 sizeof(struct host_hc_status_block_e2));
7944 else
55c11941
MS
7945 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7946 &bp->cnic_sb_mapping,
7947 sizeof(struct
7948 host_hc_status_block_e1x));
8badd27a 7949
2f7a3122 7950 if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
16a5fd92 7951 /* allocate searcher T2 table, as it wasn't allocated before */
55c11941
MS
7952 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7953
7954 /* write address to which L5 should insert its values */
7955 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7956 &bp->slowpath->drv_info_to_mcp;
7957
7958 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7959 goto alloc_mem_err;
7960
7961 return 0;
7962
7963alloc_mem_err:
7964 bnx2x_free_mem_cnic(bp);
7965 BNX2X_ERR("Can't allocate memory\n");
7966 return -ENOMEM;
7967}
7968
7969int bnx2x_alloc_mem(struct bnx2x *bp)
7970{
7971 int i, allocated, context_size;
a2fbb9ea 7972
2f7a3122 7973 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
55c11941
MS
7974 /* allocate searcher T2 table */
7975 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7976
523224a3
DK
7977 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7978 sizeof(struct host_sp_status_block));
a2fbb9ea 7979
523224a3
DK
7980 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7981 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7982
a052997e
MS
7983 /* Allocate memory for CDU context:
7984 * This memory is allocated separately and not in the generic ILT
7985 * functions because CDU differs in few aspects:
7986 * 1. There are multiple entities allocating memory for context -
7987 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7988 * its own ILT lines.
7989 * 2. Since CDU page-size is not a single 4KB page (which is the case
7990 * for the other ILT clients), to be efficient we want to support
7991 * allocation of sub-page-size in the last entry.
7992 * 3. Context pointers are used by the driver to pass to FW / update
7993 * the context (for the other ILT clients the pointers are used just to
7994 * free the memory during unload).
7995 */
7996 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7997
a052997e
MS
7998 for (i = 0, allocated = 0; allocated < context_size; i++) {
7999 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
8000 (context_size - allocated));
8001 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
8002 &bp->context[i].cxt_mapping,
8003 bp->context[i].size);
8004 allocated += bp->context[i].size;
8005 }
523224a3 8006 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 8007
523224a3
DK
8008 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
8009 goto alloc_mem_err;
65abd74d 8010
67c431a5
AE
8011 if (bnx2x_iov_alloc_mem(bp))
8012 goto alloc_mem_err;
8013
9f6c9258
DK
8014 /* Slow path ring */
8015 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 8016
523224a3
DK
8017 /* EQ */
8018 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
8019 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 8020
9f6c9258 8021 return 0;
e1510706 8022
9f6c9258
DK
8023alloc_mem_err:
8024 bnx2x_free_mem(bp);
51c1a580 8025 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 8026 return -ENOMEM;
65abd74d
YG
8027}
8028
a2fbb9ea
ET
8029/*
8030 * Init service functions
8031 */
a2fbb9ea 8032
619c5cb6
VZ
8033int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
8034 struct bnx2x_vlan_mac_obj *obj, bool set,
8035 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 8036{
619c5cb6
VZ
8037 int rc;
8038 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 8039
619c5cb6 8040 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 8041
619c5cb6
VZ
8042 /* Fill general parameters */
8043 ramrod_param.vlan_mac_obj = obj;
8044 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 8045
619c5cb6
VZ
8046 /* Fill a user request section if needed */
8047 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
8048 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 8049
619c5cb6 8050 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 8051
619c5cb6
VZ
8052 /* Set the command: ADD or DEL */
8053 if (set)
8054 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
8055 else
8056 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
8057 }
8058
619c5cb6 8059 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
8060
8061 if (rc == -EEXIST) {
8062 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
8063 /* do not treat adding same MAC as error */
8064 rc = 0;
8065 } else if (rc < 0)
619c5cb6 8066 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 8067
619c5cb6 8068 return rc;
a2fbb9ea
ET
8069}
8070
619c5cb6
VZ
8071int bnx2x_del_all_macs(struct bnx2x *bp,
8072 struct bnx2x_vlan_mac_obj *mac_obj,
8073 int mac_type, bool wait_for_comp)
e665bfda 8074{
619c5cb6
VZ
8075 int rc;
8076 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 8077
619c5cb6
VZ
8078 /* Wait for completion of requested */
8079 if (wait_for_comp)
8080 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 8081
619c5cb6
VZ
8082 /* Set the mac type of addresses we want to clear */
8083 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 8084
619c5cb6
VZ
8085 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
8086 if (rc < 0)
8087 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 8088
619c5cb6 8089 return rc;
0793f83f
DK
8090}
8091
619c5cb6 8092int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 8093{
a3348722
BW
8094 if (is_zero_ether_addr(bp->dev->dev_addr) &&
8095 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
8096 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
8097 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
8098 return 0;
8099 }
614c76df 8100
f8f4f61a
DK
8101 if (IS_PF(bp)) {
8102 unsigned long ramrod_flags = 0;
0793f83f 8103
f8f4f61a
DK
8104 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
8105 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8106 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
8107 &bp->sp_objs->mac_obj, set,
8108 BNX2X_ETH_MAC, &ramrod_flags);
8109 } else { /* vf */
8110 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
8111 bp->fp->index, true);
8112 }
e665bfda 8113}
6e30dd4e 8114
619c5cb6 8115int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 8116{
60cad4e6
AE
8117 if (IS_PF(bp))
8118 return bnx2x_setup_queue(bp, &bp->fp[0], true);
8119 else /* VF */
8120 return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
993ac7b5 8121}
a2fbb9ea 8122
d6214d7a 8123/**
e8920674 8124 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 8125 *
e8920674 8126 * @bp: driver handle
d6214d7a 8127 *
e8920674 8128 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 8129 */
1ab4434c 8130int bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 8131{
1ab4434c
AE
8132 int rc = 0;
8133
60cad4e6
AE
8134 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
8135 BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
1ab4434c 8136 return -EINVAL;
60cad4e6 8137 }
1ab4434c 8138
9ee3d37b 8139 switch (int_mode) {
1ab4434c
AE
8140 case BNX2X_INT_MODE_MSIX:
8141 /* attempt to enable msix */
8142 rc = bnx2x_enable_msix(bp);
8143
8144 /* msix attained */
8145 if (!rc)
8146 return 0;
8147
8148 /* vfs use only msix */
8149 if (rc && IS_VF(bp))
8150 return rc;
8151
8152 /* failed to enable multiple MSI-X */
8153 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
8154 bp->num_queues,
8155 1 + bp->num_cnic_queues);
8156
8157 /* falling through... */
8158 case BNX2X_INT_MODE_MSI:
d6214d7a 8159 bnx2x_enable_msi(bp);
1ab4434c 8160
d6214d7a 8161 /* falling through... */
1ab4434c 8162 case BNX2X_INT_MODE_INTX:
55c11941
MS
8163 bp->num_ethernet_queues = 1;
8164 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 8165 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 8166 break;
d6214d7a 8167 default:
1ab4434c
AE
8168 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
8169 return -EINVAL;
9f6c9258 8170 }
1ab4434c 8171 return 0;
a2fbb9ea
ET
8172}
8173
1ab4434c 8174/* must be called prior to any HW initializations */
c2bff63f
DK
8175static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
8176{
290ca2bb
AE
8177 if (IS_SRIOV(bp))
8178 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
c2bff63f
DK
8179 return L2_ILT_LINES(bp);
8180}
8181
523224a3
DK
8182void bnx2x_ilt_set_info(struct bnx2x *bp)
8183{
8184 struct ilt_client_info *ilt_client;
8185 struct bnx2x_ilt *ilt = BP_ILT(bp);
8186 u16 line = 0;
8187
8188 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8189 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8190
8191 /* CDU */
8192 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8193 ilt_client->client_num = ILT_CLIENT_CDU;
8194 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8195 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8196 ilt_client->start = line;
619c5cb6 8197 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
8198
8199 if (CNIC_SUPPORT(bp))
8200 line += CNIC_ILT_LINES;
523224a3
DK
8201 ilt_client->end = line - 1;
8202
51c1a580 8203 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8204 ilt_client->start,
8205 ilt_client->end,
8206 ilt_client->page_size,
8207 ilt_client->flags,
8208 ilog2(ilt_client->page_size >> 12));
8209
8210 /* QM */
8211 if (QM_INIT(bp->qm_cid_count)) {
8212 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8213 ilt_client->client_num = ILT_CLIENT_QM;
8214 ilt_client->page_size = QM_ILT_PAGE_SZ;
8215 ilt_client->flags = 0;
8216 ilt_client->start = line;
8217
8218 /* 4 bytes for each cid */
8219 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8220 QM_ILT_PAGE_SZ);
8221
8222 ilt_client->end = line - 1;
8223
51c1a580
MS
8224 DP(NETIF_MSG_IFUP,
8225 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8226 ilt_client->start,
8227 ilt_client->end,
8228 ilt_client->page_size,
8229 ilt_client->flags,
8230 ilog2(ilt_client->page_size >> 12));
523224a3 8231 }
523224a3 8232
55c11941
MS
8233 if (CNIC_SUPPORT(bp)) {
8234 /* SRC */
8235 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8236 ilt_client->client_num = ILT_CLIENT_SRC;
8237 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8238 ilt_client->flags = 0;
8239 ilt_client->start = line;
8240 line += SRC_ILT_LINES;
8241 ilt_client->end = line - 1;
523224a3 8242
55c11941
MS
8243 DP(NETIF_MSG_IFUP,
8244 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8245 ilt_client->start,
8246 ilt_client->end,
8247 ilt_client->page_size,
8248 ilt_client->flags,
8249 ilog2(ilt_client->page_size >> 12));
9f6c9258 8250
55c11941
MS
8251 /* TM */
8252 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8253 ilt_client->client_num = ILT_CLIENT_TM;
8254 ilt_client->page_size = TM_ILT_PAGE_SZ;
8255 ilt_client->flags = 0;
8256 ilt_client->start = line;
8257 line += TM_ILT_LINES;
8258 ilt_client->end = line - 1;
523224a3 8259
55c11941
MS
8260 DP(NETIF_MSG_IFUP,
8261 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8262 ilt_client->start,
8263 ilt_client->end,
8264 ilt_client->page_size,
8265 ilt_client->flags,
8266 ilog2(ilt_client->page_size >> 12));
8267 }
9f6c9258 8268
619c5cb6 8269 BUG_ON(line > ILT_MAX_LINES);
523224a3 8270}
f85582f8 8271
619c5cb6
VZ
8272/**
8273 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8274 *
8275 * @bp: driver handle
8276 * @fp: pointer to fastpath
8277 * @init_params: pointer to parameters structure
8278 *
8279 * parameters configured:
8280 * - HC configuration
8281 * - Queue's CDU context
8282 */
1191cb83 8283static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 8284 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 8285{
6383c0b3 8286 u8 cos;
a052997e
MS
8287 int cxt_index, cxt_offset;
8288
619c5cb6
VZ
8289 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8290 if (!IS_FCOE_FP(fp)) {
8291 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8292 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8293
16a5fd92 8294 /* If HC is supported, enable host coalescing in the transition
619c5cb6
VZ
8295 * to INIT state.
8296 */
8297 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8298 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8299
8300 /* HC rate */
8301 init_params->rx.hc_rate = bp->rx_ticks ?
8302 (1000000 / bp->rx_ticks) : 0;
8303 init_params->tx.hc_rate = bp->tx_ticks ?
8304 (1000000 / bp->tx_ticks) : 0;
8305
8306 /* FW SB ID */
8307 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8308 fp->fw_sb_id;
8309
8310 /*
8311 * CQ index among the SB indices: FCoE clients uses the default
8312 * SB, therefore it's different.
8313 */
6383c0b3
AE
8314 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8315 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
8316 }
8317
6383c0b3
AE
8318 /* set maximum number of COSs supported by this queue */
8319 init_params->max_cos = fp->max_cos;
8320
51c1a580 8321 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
8322 fp->index, init_params->max_cos);
8323
8324 /* set the context pointers queue object */
a052997e 8325 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
8326 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8327 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 8328 ILT_PAGE_CIDS);
6383c0b3 8329 init_params->cxts[cos] =
a052997e
MS
8330 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8331 }
619c5cb6
VZ
8332}
8333
910cc727 8334static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
8335 struct bnx2x_queue_state_params *q_params,
8336 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8337 int tx_index, bool leading)
8338{
8339 memset(tx_only_params, 0, sizeof(*tx_only_params));
8340
8341 /* Set the command */
8342 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8343
8344 /* Set tx-only QUEUE flags: don't zero statistics */
8345 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8346
8347 /* choose the index of the cid to send the slow path on */
8348 tx_only_params->cid_index = tx_index;
8349
8350 /* Set general TX_ONLY_SETUP parameters */
8351 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8352
8353 /* Set Tx TX_ONLY_SETUP parameters */
8354 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8355
51c1a580
MS
8356 DP(NETIF_MSG_IFUP,
8357 "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
8358 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8359 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8360 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8361
8362 /* send the ramrod */
8363 return bnx2x_queue_state_change(bp, q_params);
8364}
8365
619c5cb6
VZ
8366/**
8367 * bnx2x_setup_queue - setup queue
8368 *
8369 * @bp: driver handle
8370 * @fp: pointer to fastpath
8371 * @leading: is leading
8372 *
8373 * This function performs 2 steps in a Queue state machine
8374 * actually: 1) RESET->INIT 2) INIT->SETUP
8375 */
8376
8377int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8378 bool leading)
8379{
3b603066 8380 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8381 struct bnx2x_queue_setup_params *setup_params =
8382 &q_params.params.setup;
6383c0b3
AE
8383 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8384 &q_params.params.tx_only;
a2fbb9ea 8385 int rc;
6383c0b3
AE
8386 u8 tx_index;
8387
51c1a580 8388 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8389
ec6ba945
VZ
8390 /* reset IGU state skip FCoE L2 queue */
8391 if (!IS_FCOE_FP(fp))
8392 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8393 IGU_INT_ENABLE, 0);
a2fbb9ea 8394
15192a8c 8395 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8396 /* We want to wait for completion in this context */
8397 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8398
619c5cb6
VZ
8399 /* Prepare the INIT parameters */
8400 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8401
619c5cb6
VZ
8402 /* Set the command */
8403 q_params.cmd = BNX2X_Q_CMD_INIT;
8404
8405 /* Change the state to INIT */
8406 rc = bnx2x_queue_state_change(bp, &q_params);
8407 if (rc) {
6383c0b3 8408 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8409 return rc;
8410 }
ec6ba945 8411
51c1a580 8412 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3 8413
619c5cb6
VZ
8414 /* Now move the Queue to the SETUP state... */
8415 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8416
619c5cb6
VZ
8417 /* Set QUEUE flags */
8418 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8419
619c5cb6 8420 /* Set general SETUP parameters */
6383c0b3
AE
8421 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8422 FIRST_TX_COS_INDEX);
619c5cb6 8423
6383c0b3 8424 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8425 &setup_params->rxq_params);
8426
6383c0b3
AE
8427 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8428 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8429
8430 /* Set the command */
8431 q_params.cmd = BNX2X_Q_CMD_SETUP;
8432
55c11941
MS
8433 if (IS_FCOE_FP(fp))
8434 bp->fcoe_init = true;
8435
619c5cb6
VZ
8436 /* Change the state to SETUP */
8437 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8438 if (rc) {
8439 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8440 return rc;
8441 }
8442
8443 /* loop through the relevant tx-only indices */
8444 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8445 tx_index < fp->max_cos;
8446 tx_index++) {
8447
8448 /* prepare and send tx-only ramrod*/
8449 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8450 tx_only_params, tx_index, leading);
8451 if (rc) {
8452 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8453 fp->index, tx_index);
8454 return rc;
8455 }
8456 }
523224a3 8457
34f80b04 8458 return rc;
a2fbb9ea
ET
8459}
8460
619c5cb6 8461static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8462{
619c5cb6 8463 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8464 struct bnx2x_fp_txdata *txdata;
3b603066 8465 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8466 int rc, tx_index;
8467
51c1a580 8468 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8469
15192a8c 8470 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8471 /* We want to wait for completion in this context */
8472 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8473
6383c0b3
AE
8474 /* close tx-only connections */
8475 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8476 tx_index < fp->max_cos;
8477 tx_index++){
8478
8479 /* ascertain this is a normal queue*/
65565884 8480 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8481
51c1a580 8482 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8483 txdata->txq_index);
8484
8485 /* send halt terminate on tx-only connection */
8486 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8487 memset(&q_params.params.terminate, 0,
8488 sizeof(q_params.params.terminate));
8489 q_params.params.terminate.cid_index = tx_index;
8490
8491 rc = bnx2x_queue_state_change(bp, &q_params);
8492 if (rc)
8493 return rc;
8494
8495 /* send halt terminate on tx-only connection */
8496 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8497 memset(&q_params.params.cfc_del, 0,
8498 sizeof(q_params.params.cfc_del));
8499 q_params.params.cfc_del.cid_index = tx_index;
8500 rc = bnx2x_queue_state_change(bp, &q_params);
8501 if (rc)
8502 return rc;
8503 }
8504 /* Stop the primary connection: */
8505 /* ...halt the connection */
619c5cb6
VZ
8506 q_params.cmd = BNX2X_Q_CMD_HALT;
8507 rc = bnx2x_queue_state_change(bp, &q_params);
8508 if (rc)
da5a662a 8509 return rc;
a2fbb9ea 8510
6383c0b3 8511 /* ...terminate the connection */
619c5cb6 8512 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8513 memset(&q_params.params.terminate, 0,
8514 sizeof(q_params.params.terminate));
8515 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8516 rc = bnx2x_queue_state_change(bp, &q_params);
8517 if (rc)
523224a3 8518 return rc;
6383c0b3 8519 /* ...delete cfc entry */
619c5cb6 8520 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8521 memset(&q_params.params.cfc_del, 0,
8522 sizeof(q_params.params.cfc_del));
8523 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8524 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8525}
8526
34f80b04
EG
8527static void bnx2x_reset_func(struct bnx2x *bp)
8528{
8529 int port = BP_PORT(bp);
8530 int func = BP_FUNC(bp);
f2e0899f 8531 int i;
523224a3
DK
8532
8533 /* Disable the function in the FW */
8534 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8535 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8536 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8537 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8538
8539 /* FP SBs */
ec6ba945 8540 for_each_eth_queue(bp, i) {
523224a3 8541 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8542 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8543 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8544 SB_DISABLED);
523224a3
DK
8545 }
8546
55c11941
MS
8547 if (CNIC_LOADED(bp))
8548 /* CNIC SB */
8549 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8550 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8551 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8552
523224a3 8553 /* SP SB */
619c5cb6 8554 REG_WR8(bp, BAR_CSTRORM_INTMEM +
2de67439
YM
8555 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8556 SB_DISABLED);
523224a3
DK
8557
8558 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8559 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8560 0);
34f80b04
EG
8561
8562 /* Configure IGU */
f2e0899f
DK
8563 if (bp->common.int_block == INT_BLOCK_HC) {
8564 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8565 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8566 } else {
8567 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8568 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8569 }
34f80b04 8570
55c11941
MS
8571 if (CNIC_LOADED(bp)) {
8572 /* Disable Timer scan */
8573 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8574 /*
8575 * Wait for at least 10ms and up to 2 second for the timers
8576 * scan to complete
8577 */
8578 for (i = 0; i < 200; i++) {
639d65b8 8579 usleep_range(10000, 20000);
55c11941
MS
8580 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8581 break;
8582 }
37b091ba 8583 }
34f80b04 8584 /* Clear ILT */
f2e0899f
DK
8585 bnx2x_clear_func_ilt(bp, func);
8586
8587 /* Timers workaround bug for E2: if this is vnic-3,
8588 * we need to set the entire ilt range for this timers.
8589 */
619c5cb6 8590 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8591 struct ilt_client_info ilt_cli;
8592 /* use dummy TM client */
8593 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8594 ilt_cli.start = 0;
8595 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8596 ilt_cli.client_num = ILT_CLIENT_TM;
8597
8598 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8599 }
8600
8601 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8602 if (!CHIP_IS_E1x(bp))
f2e0899f 8603 bnx2x_pf_disable(bp);
523224a3
DK
8604
8605 bp->dmae_ready = 0;
34f80b04
EG
8606}
8607
8608static void bnx2x_reset_port(struct bnx2x *bp)
8609{
8610 int port = BP_PORT(bp);
8611 u32 val;
8612
619c5cb6
VZ
8613 /* Reset physical Link */
8614 bnx2x__link_reset(bp);
8615
34f80b04
EG
8616 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8617
8618 /* Do not rcv packets to BRB */
8619 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8620 /* Do not direct rcv packets that are not for MCP to the BRB */
8621 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8622 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8623
8624 /* Configure AEU */
8625 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8626
8627 msleep(100);
8628 /* Check for BRB port occupancy */
8629 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8630 if (val)
8631 DP(NETIF_MSG_IFDOWN,
33471629 8632 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8633
8634 /* TODO: Close Doorbell port? */
8635}
8636
1191cb83 8637static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8638{
3b603066 8639 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8640
619c5cb6
VZ
8641 /* Prepare parameters for function state transitions */
8642 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8643
619c5cb6
VZ
8644 func_params.f_obj = &bp->func_obj;
8645 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8646
619c5cb6 8647 func_params.params.hw_init.load_phase = load_code;
49d66772 8648
619c5cb6 8649 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8650}
8651
1191cb83 8652static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8653{
3b603066 8654 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8655 int rc;
228241eb 8656
619c5cb6
VZ
8657 /* Prepare parameters for function state transitions */
8658 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8659 func_params.f_obj = &bp->func_obj;
8660 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8661
619c5cb6
VZ
8662 /*
8663 * Try to stop the function the 'good way'. If fails (in case
8664 * of a parity error during bnx2x_chip_cleanup()) and we are
8665 * not in a debug mode, perform a state transaction in order to
8666 * enable further HW_RESET transaction.
8667 */
8668 rc = bnx2x_func_state_change(bp, &func_params);
8669 if (rc) {
34f80b04 8670#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8671 return rc;
34f80b04 8672#else
51c1a580 8673 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8674 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8675 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8676#endif
228241eb 8677 }
a2fbb9ea 8678
619c5cb6
VZ
8679 return 0;
8680}
523224a3 8681
619c5cb6
VZ
8682/**
8683 * bnx2x_send_unload_req - request unload mode from the MCP.
8684 *
8685 * @bp: driver handle
8686 * @unload_mode: requested function's unload mode
8687 *
8688 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8689 */
8690u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8691{
8692 u32 reset_code = 0;
8693 int port = BP_PORT(bp);
3101c2bc 8694
619c5cb6 8695 /* Select the UNLOAD request mode */
65abd74d
YG
8696 if (unload_mode == UNLOAD_NORMAL)
8697 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8698
7d0446c2 8699 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8700 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8701
7d0446c2 8702 else if (bp->wol) {
65abd74d
YG
8703 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8704 u8 *mac_addr = bp->dev->dev_addr;
29ed74c3 8705 struct pci_dev *pdev = bp->pdev;
65abd74d 8706 u32 val;
f9977903
DK
8707 u16 pmc;
8708
65abd74d 8709 /* The mac address is written to entries 1-4 to
f9977903
DK
8710 * preserve entry 0 which is used by the PMF
8711 */
3395a033 8712 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8713
8714 val = (mac_addr[0] << 8) | mac_addr[1];
8715 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8716
8717 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8718 (mac_addr[4] << 8) | mac_addr[5];
8719 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8720
f9977903 8721 /* Enable the PME and clear the status */
29ed74c3 8722 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
f9977903 8723 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
29ed74c3 8724 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
f9977903 8725
65abd74d
YG
8726 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8727
8728 } else
8729 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8730
619c5cb6
VZ
8731 /* Send the request to the MCP */
8732 if (!BP_NOMCP(bp))
8733 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8734 else {
8735 int path = BP_PATH(bp);
8736
51c1a580 8737 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8738 path, load_count[path][0], load_count[path][1],
8739 load_count[path][2]);
8740 load_count[path][0]--;
8741 load_count[path][1 + port]--;
51c1a580 8742 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8743 path, load_count[path][0], load_count[path][1],
8744 load_count[path][2]);
8745 if (load_count[path][0] == 0)
8746 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8747 else if (load_count[path][1 + port] == 0)
8748 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8749 else
8750 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8751 }
8752
8753 return reset_code;
8754}
8755
8756/**
8757 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8758 *
8759 * @bp: driver handle
5d07d868 8760 * @keep_link: true iff link should be kept up
619c5cb6 8761 */
5d07d868 8762void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8763{
5d07d868
YM
8764 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8765
619c5cb6
VZ
8766 /* Report UNLOAD_DONE to MCP */
8767 if (!BP_NOMCP(bp))
5d07d868 8768 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8769}
8770
1191cb83 8771static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8772{
8773 int tout = 50;
8774 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8775
8776 if (!bp->port.pmf)
8777 return 0;
8778
8779 /*
8780 * (assumption: No Attention from MCP at this stage)
16a5fd92 8781 * PMF probably in the middle of TX disable/enable transaction
6debea87 8782 * 1. Sync IRS for default SB
16a5fd92
YM
8783 * 2. Sync SP queue - this guarantees us that attention handling started
8784 * 3. Wait, that TX disable/enable transaction completes
6debea87 8785 *
16a5fd92
YM
8786 * 1+2 guarantee that if DCBx attention was scheduled it already changed
8787 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
8788 * received completion for the transaction the state is TX_STOPPED.
6debea87
DK
8789 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8790 * transaction.
8791 */
8792
8793 /* make sure default SB ISR is done */
8794 if (msix)
8795 synchronize_irq(bp->msix_table[0].vector);
8796 else
8797 synchronize_irq(bp->pdev->irq);
8798
8799 flush_workqueue(bnx2x_wq);
8800
8801 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8802 BNX2X_F_STATE_STARTED && tout--)
8803 msleep(20);
8804
8805 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8806 BNX2X_F_STATE_STARTED) {
8807#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8808 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8809 return -EBUSY;
8810#else
8811 /*
8812 * Failed to complete the transaction in a "good way"
8813 * Force both transactions with CLR bit
8814 */
3b603066 8815 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8816
51c1a580 8817 DP(NETIF_MSG_IFDOWN,
6bf07b8e 8818 "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8819
8820 func_params.f_obj = &bp->func_obj;
8821 __set_bit(RAMROD_DRV_CLR_ONLY,
8822 &func_params.ramrod_flags);
8823
8824 /* STARTED-->TX_ST0PPED */
8825 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8826 bnx2x_func_state_change(bp, &func_params);
8827
8828 /* TX_ST0PPED-->STARTED */
8829 func_params.cmd = BNX2X_F_CMD_TX_START;
8830 return bnx2x_func_state_change(bp, &func_params);
8831#endif
8832 }
8833
8834 return 0;
8835}
8836
5d07d868 8837void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8838{
8839 int port = BP_PORT(bp);
6383c0b3
AE
8840 int i, rc = 0;
8841 u8 cos;
3b603066 8842 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8843 u32 reset_code;
8844
8845 /* Wait until tx fastpath tasks complete */
8846 for_each_tx_queue(bp, i) {
8847 struct bnx2x_fastpath *fp = &bp->fp[i];
8848
6383c0b3 8849 for_each_cos_in_tx_queue(fp, cos)
65565884 8850 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8851#ifdef BNX2X_STOP_ON_ERROR
8852 if (rc)
8853 return;
8854#endif
8855 }
8856
8857 /* Give HW time to discard old tx messages */
0926d499 8858 usleep_range(1000, 2000);
619c5cb6
VZ
8859
8860 /* Clean all ETH MACs */
15192a8c
BW
8861 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8862 false);
619c5cb6
VZ
8863 if (rc < 0)
8864 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8865
8866 /* Clean up UC list */
15192a8c 8867 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8868 true);
8869 if (rc < 0)
51c1a580
MS
8870 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8871 rc);
619c5cb6
VZ
8872
8873 /* Disable LLH */
8874 if (!CHIP_IS_E1(bp))
8875 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8876
8877 /* Set "drop all" (stop Rx).
8878 * We need to take a netif_addr_lock() here in order to prevent
8879 * a race between the completion code and this code.
8880 */
8881 netif_addr_lock_bh(bp->dev);
8882 /* Schedule the rx_mode command */
8883 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8884 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8885 else
8886 bnx2x_set_storm_rx_mode(bp);
8887
8888 /* Cleanup multicast configuration */
8889 rparam.mcast_obj = &bp->mcast_obj;
8890 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8891 if (rc < 0)
8892 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8893
8894 netif_addr_unlock_bh(bp->dev);
8895
f1929b01 8896 bnx2x_iov_chip_cleanup(bp);
619c5cb6 8897
6debea87
DK
8898 /*
8899 * Send the UNLOAD_REQUEST to the MCP. This will return if
8900 * this function should perform FUNC, PORT or COMMON HW
8901 * reset.
8902 */
8903 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8904
8905 /*
8906 * (assumption: No Attention from MCP at this stage)
16a5fd92 8907 * PMF probably in the middle of TX disable/enable transaction
6debea87
DK
8908 */
8909 rc = bnx2x_func_wait_started(bp);
8910 if (rc) {
8911 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8912#ifdef BNX2X_STOP_ON_ERROR
8913 return;
8914#endif
8915 }
8916
34f80b04 8917 /* Close multi and leading connections
619c5cb6
VZ
8918 * Completions for ramrods are collected in a synchronous way
8919 */
55c11941 8920 for_each_eth_queue(bp, i)
619c5cb6 8921 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8922#ifdef BNX2X_STOP_ON_ERROR
8923 return;
8924#else
228241eb 8925 goto unload_error;
523224a3 8926#endif
55c11941
MS
8927
8928 if (CNIC_LOADED(bp)) {
8929 for_each_cnic_queue(bp, i)
8930 if (bnx2x_stop_queue(bp, i))
8931#ifdef BNX2X_STOP_ON_ERROR
8932 return;
8933#else
8934 goto unload_error;
8935#endif
8936 }
8937
619c5cb6
VZ
8938 /* If SP settings didn't get completed so far - something
8939 * very wrong has happen.
8940 */
8941 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8942 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8943
619c5cb6
VZ
8944#ifndef BNX2X_STOP_ON_ERROR
8945unload_error:
8946#endif
523224a3 8947 rc = bnx2x_func_stop(bp);
da5a662a 8948 if (rc) {
523224a3 8949 BNX2X_ERR("Function stop failed!\n");
da5a662a 8950#ifdef BNX2X_STOP_ON_ERROR
523224a3 8951 return;
523224a3 8952#endif
34f80b04 8953 }
a2fbb9ea 8954
523224a3
DK
8955 /* Disable HW interrupts, NAPI */
8956 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8957 /* Delete all NAPI objects */
8958 bnx2x_del_all_napi(bp);
55c11941
MS
8959 if (CNIC_LOADED(bp))
8960 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8961
8962 /* Release IRQs */
d6214d7a 8963 bnx2x_free_irq(bp);
523224a3 8964
a2fbb9ea 8965 /* Reset the chip */
619c5cb6
VZ
8966 rc = bnx2x_reset_hw(bp, reset_code);
8967 if (rc)
8968 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8969
619c5cb6 8970 /* Report UNLOAD_DONE to MCP */
5d07d868 8971 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8972}
8973
9f6c9258 8974void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8975{
8976 u32 val;
8977
51c1a580 8978 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8979
8980 if (CHIP_IS_E1(bp)) {
8981 int port = BP_PORT(bp);
8982 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8983 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8984
8985 val = REG_RD(bp, addr);
8986 val &= ~(0x300);
8987 REG_WR(bp, addr, val);
619c5cb6 8988 } else {
72fd0718
VZ
8989 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8990 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8991 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8992 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8993 }
8994}
8995
72fd0718
VZ
8996/* Close gates #2, #3 and #4: */
8997static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8998{
c9ee9206 8999 u32 val;
72fd0718
VZ
9000
9001 /* Gates #2 and #4a are closed/opened for "not E1" only */
9002 if (!CHIP_IS_E1(bp)) {
9003 /* #4 */
c9ee9206 9004 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 9005 /* #2 */
c9ee9206 9006 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
9007 }
9008
9009 /* #3 */
c9ee9206
VZ
9010 if (CHIP_IS_E1x(bp)) {
9011 /* Prevent interrupts from HC on both ports */
9012 val = REG_RD(bp, HC_REG_CONFIG_1);
9013 REG_WR(bp, HC_REG_CONFIG_1,
9014 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
9015 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
9016
9017 val = REG_RD(bp, HC_REG_CONFIG_0);
9018 REG_WR(bp, HC_REG_CONFIG_0,
9019 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
9020 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
9021 } else {
d82603c6 9022 /* Prevent incoming interrupts in IGU */
c9ee9206
VZ
9023 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9024
9025 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
9026 (!close) ?
9027 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
9028 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
9029 }
72fd0718 9030
51c1a580 9031 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
9032 close ? "closing" : "opening");
9033 mmiowb();
9034}
9035
9036#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
9037
9038static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
9039{
9040 /* Do some magic... */
9041 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9042 *magic_val = val & SHARED_MF_CLP_MAGIC;
9043 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
9044}
9045
e8920674
DK
9046/**
9047 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 9048 *
e8920674
DK
9049 * @bp: driver handle
9050 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
9051 */
9052static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
9053{
9054 /* Restore the `magic' bit value... */
72fd0718
VZ
9055 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9056 MF_CFG_WR(bp, shared_mf_config.clp_mb,
9057 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
9058}
9059
f85582f8 9060/**
e8920674 9061 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 9062 *
e8920674
DK
9063 * @bp: driver handle
9064 * @magic_val: old value of 'magic' bit.
9065 *
9066 * Takes care of CLP configurations.
72fd0718
VZ
9067 */
9068static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
9069{
9070 u32 shmem;
9071 u32 validity_offset;
9072
51c1a580 9073 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
9074
9075 /* Set `magic' bit in order to save MF config */
9076 if (!CHIP_IS_E1(bp))
9077 bnx2x_clp_reset_prep(bp, magic_val);
9078
9079 /* Get shmem offset */
9080 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
9081 validity_offset =
9082 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
9083
9084 /* Clear validity map flags */
9085 if (shmem > 0)
9086 REG_WR(bp, shmem + validity_offset, 0);
9087}
9088
9089#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
9090#define MCP_ONE_TIMEOUT 100 /* 100 ms */
9091
e8920674
DK
9092/**
9093 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 9094 *
e8920674 9095 * @bp: driver handle
72fd0718 9096 */
1191cb83 9097static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
9098{
9099 /* special handling for emulation and FPGA,
9100 wait 10 times longer */
9101 if (CHIP_REV_IS_SLOW(bp))
9102 msleep(MCP_ONE_TIMEOUT*10);
9103 else
9104 msleep(MCP_ONE_TIMEOUT);
9105}
9106
1b6e2ceb
DK
9107/*
9108 * initializes bp->common.shmem_base and waits for validity signature to appear
9109 */
9110static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 9111{
1b6e2ceb
DK
9112 int cnt = 0;
9113 u32 val = 0;
72fd0718 9114
1b6e2ceb
DK
9115 do {
9116 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9117 if (bp->common.shmem_base) {
9118 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
9119 if (val & SHR_MEM_VALIDITY_MB)
9120 return 0;
9121 }
72fd0718 9122
1b6e2ceb 9123 bnx2x_mcp_wait_one(bp);
72fd0718 9124
1b6e2ceb 9125 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 9126
1b6e2ceb 9127 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 9128
1b6e2ceb
DK
9129 return -ENODEV;
9130}
72fd0718 9131
1b6e2ceb
DK
9132static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
9133{
9134 int rc = bnx2x_init_shmem(bp);
72fd0718 9135
72fd0718
VZ
9136 /* Restore the `magic' bit value */
9137 if (!CHIP_IS_E1(bp))
9138 bnx2x_clp_reset_done(bp, magic_val);
9139
9140 return rc;
9141}
9142
9143static void bnx2x_pxp_prep(struct bnx2x *bp)
9144{
9145 if (!CHIP_IS_E1(bp)) {
9146 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
9147 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
9148 mmiowb();
9149 }
9150}
9151
9152/*
9153 * Reset the whole chip except for:
9154 * - PCIE core
9155 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
9156 * one reset bit)
9157 * - IGU
9158 * - MISC (including AEU)
9159 * - GRC
9160 * - RBCN, RBCP
9161 */
c9ee9206 9162static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
9163{
9164 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 9165 u32 global_bits2, stay_reset2;
c9ee9206
VZ
9166
9167 /*
9168 * Bits that have to be set in reset_mask2 if we want to reset 'global'
9169 * (per chip) blocks.
9170 */
9171 global_bits2 =
9172 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9173 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 9174
c55e771b
BW
9175 /* Don't reset the following blocks.
9176 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9177 * reset, as in 4 port device they might still be owned
9178 * by the MCP (there is only one leader per path).
9179 */
72fd0718
VZ
9180 not_reset_mask1 =
9181 MISC_REGISTERS_RESET_REG_1_RST_HC |
9182 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9183 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9184
9185 not_reset_mask2 =
c9ee9206 9186 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
9187 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9188 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9189 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9190 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9191 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9192 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
9193 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9194 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
9195 MISC_REGISTERS_RESET_REG_2_PGLC |
9196 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9197 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9198 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9199 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9200 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9201 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 9202
8736c826
VZ
9203 /*
9204 * Keep the following blocks in reset:
9205 * - all xxMACs are handled by the bnx2x_link code.
9206 */
9207 stay_reset2 =
8736c826
VZ
9208 MISC_REGISTERS_RESET_REG_2_XMAC |
9209 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9210
9211 /* Full reset masks according to the chip */
72fd0718
VZ
9212 reset_mask1 = 0xffffffff;
9213
9214 if (CHIP_IS_E1(bp))
9215 reset_mask2 = 0xffff;
8736c826 9216 else if (CHIP_IS_E1H(bp))
72fd0718 9217 reset_mask2 = 0x1ffff;
8736c826
VZ
9218 else if (CHIP_IS_E2(bp))
9219 reset_mask2 = 0xfffff;
9220 else /* CHIP_IS_E3 */
9221 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
9222
9223 /* Don't reset global blocks unless we need to */
9224 if (!global)
9225 reset_mask2 &= ~global_bits2;
9226
9227 /*
9228 * In case of attention in the QM, we need to reset PXP
9229 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9230 * because otherwise QM reset would release 'close the gates' shortly
9231 * before resetting the PXP, then the PSWRQ would send a write
9232 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9233 * read the payload data from PSWWR, but PSWWR would not
9234 * respond. The write queue in PGLUE would stuck, dmae commands
9235 * would not return. Therefore it's important to reset the second
9236 * reset register (containing the
9237 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9238 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9239 * bit).
9240 */
72fd0718
VZ
9241 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9242 reset_mask2 & (~not_reset_mask2));
9243
c9ee9206
VZ
9244 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9245 reset_mask1 & (~not_reset_mask1));
9246
72fd0718
VZ
9247 barrier();
9248 mmiowb();
9249
8736c826
VZ
9250 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9251 reset_mask2 & (~stay_reset2));
9252
9253 barrier();
9254 mmiowb();
9255
c9ee9206 9256 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
9257 mmiowb();
9258}
9259
c9ee9206
VZ
9260/**
9261 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9262 * It should get cleared in no more than 1s.
9263 *
9264 * @bp: driver handle
9265 *
9266 * It should get cleared in no more than 1s. Returns 0 if
9267 * pending writes bit gets cleared.
9268 */
9269static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9270{
9271 u32 cnt = 1000;
9272 u32 pend_bits = 0;
9273
9274 do {
9275 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9276
9277 if (pend_bits == 0)
9278 break;
9279
0926d499 9280 usleep_range(1000, 2000);
c9ee9206
VZ
9281 } while (cnt-- > 0);
9282
9283 if (cnt <= 0) {
9284 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9285 pend_bits);
9286 return -EBUSY;
9287 }
9288
9289 return 0;
9290}
9291
9292static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
9293{
9294 int cnt = 1000;
9295 u32 val = 0;
9296 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
2de67439 9297 u32 tags_63_32 = 0;
72fd0718
VZ
9298
9299 /* Empty the Tetris buffer, wait for 1s */
9300 do {
9301 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9302 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9303 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9304 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9305 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
9306 if (CHIP_IS_E3(bp))
9307 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9308
72fd0718
VZ
9309 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9310 ((port_is_idle_0 & 0x1) == 0x1) &&
9311 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
9312 (pgl_exp_rom2 == 0xffffffff) &&
9313 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 9314 break;
0926d499 9315 usleep_range(1000, 2000);
72fd0718
VZ
9316 } while (cnt-- > 0);
9317
9318 if (cnt <= 0) {
51c1a580
MS
9319 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9320 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
9321 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9322 pgl_exp_rom2);
9323 return -EAGAIN;
9324 }
9325
9326 barrier();
9327
9328 /* Close gates #2, #3 and #4 */
9329 bnx2x_set_234_gates(bp, true);
9330
c9ee9206
VZ
9331 /* Poll for IGU VQs for 57712 and newer chips */
9332 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9333 return -EAGAIN;
9334
72fd0718
VZ
9335 /* TBD: Indicate that "process kill" is in progress to MCP */
9336
9337 /* Clear "unprepared" bit */
9338 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9339 barrier();
9340
9341 /* Make sure all is written to the chip before the reset */
9342 mmiowb();
9343
9344 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9345 * PSWHST, GRC and PSWRD Tetris buffer.
9346 */
0926d499 9347 usleep_range(1000, 2000);
72fd0718
VZ
9348
9349 /* Prepare to chip reset: */
9350 /* MCP */
c9ee9206
VZ
9351 if (global)
9352 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
9353
9354 /* PXP */
9355 bnx2x_pxp_prep(bp);
9356 barrier();
9357
9358 /* reset the chip */
c9ee9206 9359 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9360 barrier();
9361
9dcd9acd
DK
9362 /* clear errors in PGB */
9363 if (!CHIP_IS_E1x(bp))
9364 REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
9365
72fd0718
VZ
9366 /* Recover after reset: */
9367 /* MCP */
c9ee9206 9368 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9369 return -EAGAIN;
9370
c9ee9206
VZ
9371 /* TBD: Add resetting the NO_MCP mode DB here */
9372
72fd0718
VZ
9373 /* Open the gates #2, #3 and #4 */
9374 bnx2x_set_234_gates(bp, false);
9375
9376 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9377 * reset state, re-enable attentions. */
9378
a2fbb9ea
ET
9379 return 0;
9380}
9381
910cc727 9382static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9383{
9384 int rc = 0;
c9ee9206 9385 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9386 u32 load_code;
9387
9388 /* if not going to reset MCP - load "fake" driver to reset HW while
9389 * driver is owner of the HW
9390 */
9391 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9392 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9393 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9394 if (!load_code) {
9395 BNX2X_ERR("MCP response failure, aborting\n");
9396 rc = -EAGAIN;
9397 goto exit_leader_reset;
9398 }
9399 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9400 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9401 BNX2X_ERR("MCP unexpected resp, aborting\n");
9402 rc = -EAGAIN;
9403 goto exit_leader_reset2;
9404 }
9405 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9406 if (!load_code) {
9407 BNX2X_ERR("MCP response failure, aborting\n");
9408 rc = -EAGAIN;
9409 goto exit_leader_reset2;
9410 }
9411 }
c9ee9206 9412
72fd0718 9413 /* Try to recover after the failure */
c9ee9206 9414 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9415 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9416 BP_PATH(bp));
72fd0718 9417 rc = -EAGAIN;
95c6c616 9418 goto exit_leader_reset2;
72fd0718
VZ
9419 }
9420
c9ee9206
VZ
9421 /*
9422 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9423 * state.
9424 */
72fd0718 9425 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9426 if (global)
9427 bnx2x_clear_reset_global(bp);
72fd0718 9428
95c6c616
AE
9429exit_leader_reset2:
9430 /* unload "fake driver" if it was loaded */
9431 if (!global && !BP_NOMCP(bp)) {
9432 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9433 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9434 }
72fd0718
VZ
9435exit_leader_reset:
9436 bp->is_leader = 0;
c9ee9206
VZ
9437 bnx2x_release_leader_lock(bp);
9438 smp_mb();
72fd0718
VZ
9439 return rc;
9440}
9441
1191cb83 9442static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9443{
9444 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9445
9446 /* Disconnect this device */
9447 netif_device_detach(bp->dev);
9448
9449 /*
9450 * Block ifup for all function on this engine until "process kill"
9451 * or power cycle.
9452 */
9453 bnx2x_set_reset_in_progress(bp);
9454
9455 /* Shut down the power */
9456 bnx2x_set_power_state(bp, PCI_D3hot);
9457
9458 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9459
9460 smp_mb();
9461}
9462
9463/*
9464 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9465 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9466 * will never be called when netif_running(bp->dev) is false.
9467 */
9468static void bnx2x_parity_recover(struct bnx2x *bp)
9469{
c9ee9206 9470 bool global = false;
7a752993 9471 u32 error_recovered, error_unrecovered;
95c6c616 9472 bool is_parity;
c9ee9206 9473
72fd0718
VZ
9474 DP(NETIF_MSG_HW, "Handling parity\n");
9475 while (1) {
9476 switch (bp->recovery_state) {
9477 case BNX2X_RECOVERY_INIT:
9478 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9479 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9480 WARN_ON(!is_parity);
c9ee9206 9481
72fd0718 9482 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9483 if (bnx2x_trylock_leader_lock(bp)) {
9484 bnx2x_set_reset_in_progress(bp);
9485 /*
9486 * Check if there is a global attention and if
9487 * there was a global attention, set the global
9488 * reset bit.
9489 */
9490
9491 if (global)
9492 bnx2x_set_reset_global(bp);
9493
72fd0718 9494 bp->is_leader = 1;
c9ee9206 9495 }
72fd0718
VZ
9496
9497 /* Stop the driver */
9498 /* If interface has been removed - break */
5d07d868 9499 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9500 return;
9501
9502 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9503
c9ee9206
VZ
9504 /* Ensure "is_leader", MCP command sequence and
9505 * "recovery_state" update values are seen on other
9506 * CPUs.
72fd0718 9507 */
c9ee9206 9508 smp_mb();
72fd0718
VZ
9509 break;
9510
9511 case BNX2X_RECOVERY_WAIT:
9512 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9513 if (bp->is_leader) {
c9ee9206 9514 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9515 bool other_load_status =
9516 bnx2x_get_load_status(bp, other_engine);
9517 bool load_status =
9518 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9519 global = bnx2x_reset_is_global(bp);
9520
9521 /*
9522 * In case of a parity in a global block, let
9523 * the first leader that performs a
9524 * leader_reset() reset the global blocks in
9525 * order to clear global attentions. Otherwise
16a5fd92 9526 * the gates will remain closed for that
c9ee9206
VZ
9527 * engine.
9528 */
889b9af3
AE
9529 if (load_status ||
9530 (global && other_load_status)) {
72fd0718
VZ
9531 /* Wait until all other functions get
9532 * down.
9533 */
7be08a72 9534 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9535 HZ/10);
9536 return;
9537 } else {
9538 /* If all other functions got down -
9539 * try to bring the chip back to
9540 * normal. In any case it's an exit
9541 * point for a leader.
9542 */
c9ee9206
VZ
9543 if (bnx2x_leader_reset(bp)) {
9544 bnx2x_recovery_failed(bp);
72fd0718
VZ
9545 return;
9546 }
9547
c9ee9206
VZ
9548 /* If we are here, means that the
9549 * leader has succeeded and doesn't
9550 * want to be a leader any more. Try
9551 * to continue as a none-leader.
9552 */
9553 break;
72fd0718
VZ
9554 }
9555 } else { /* non-leader */
c9ee9206 9556 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9557 /* Try to get a LEADER_LOCK HW lock as
9558 * long as a former leader may have
9559 * been unloaded by the user or
9560 * released a leadership by another
9561 * reason.
9562 */
c9ee9206 9563 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9564 /* I'm a leader now! Restart a
9565 * switch case.
9566 */
9567 bp->is_leader = 1;
9568 break;
9569 }
9570
7be08a72 9571 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9572 HZ/10);
9573 return;
9574
c9ee9206
VZ
9575 } else {
9576 /*
9577 * If there was a global attention, wait
9578 * for it to be cleared.
9579 */
9580 if (bnx2x_reset_is_global(bp)) {
9581 schedule_delayed_work(
7be08a72
AE
9582 &bp->sp_rtnl_task,
9583 HZ/10);
c9ee9206
VZ
9584 return;
9585 }
9586
7a752993
AE
9587 error_recovered =
9588 bp->eth_stats.recoverable_error;
9589 error_unrecovered =
9590 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9591 bp->recovery_state =
9592 BNX2X_RECOVERY_NIC_LOADING;
9593 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9594 error_unrecovered++;
95c6c616 9595 netdev_err(bp->dev,
51c1a580 9596 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9597 /* Disconnect this device */
9598 netif_device_detach(bp->dev);
9599 /* Shut down the power */
9600 bnx2x_set_power_state(
9601 bp, PCI_D3hot);
9602 smp_mb();
9603 } else {
c9ee9206
VZ
9604 bp->recovery_state =
9605 BNX2X_RECOVERY_DONE;
7a752993 9606 error_recovered++;
c9ee9206
VZ
9607 smp_mb();
9608 }
7a752993
AE
9609 bp->eth_stats.recoverable_error =
9610 error_recovered;
9611 bp->eth_stats.unrecoverable_error =
9612 error_unrecovered;
c9ee9206 9613
72fd0718
VZ
9614 return;
9615 }
9616 }
9617 default:
9618 return;
9619 }
9620 }
9621}
9622
56ad3152
MS
9623static int bnx2x_close(struct net_device *dev);
9624
72fd0718
VZ
9625/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9626 * scheduled on a general queue in order to prevent a dead lock.
9627 */
7be08a72 9628static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9629{
7be08a72 9630 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9631
9632 rtnl_lock();
9633
8395be5e
AE
9634 if (!netif_running(bp->dev)) {
9635 rtnl_unlock();
9636 return;
9637 }
7be08a72 9638
6bf07b8e 9639 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
7be08a72 9640#ifdef BNX2X_STOP_ON_ERROR
6bf07b8e
YM
9641 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9642 "you will need to reboot when done\n");
9643 goto sp_rtnl_not_reset;
7be08a72 9644#endif
7be08a72 9645 /*
b1fb8740
VZ
9646 * Clear all pending SP commands as we are going to reset the
9647 * function anyway.
7be08a72 9648 */
b1fb8740
VZ
9649 bp->sp_rtnl_state = 0;
9650 smp_mb();
9651
72fd0718 9652 bnx2x_parity_recover(bp);
b1fb8740 9653
8395be5e
AE
9654 rtnl_unlock();
9655 return;
b1fb8740
VZ
9656 }
9657
9658 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
6bf07b8e
YM
9659#ifdef BNX2X_STOP_ON_ERROR
9660 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9661 "you will need to reboot when done\n");
9662 goto sp_rtnl_not_reset;
9663#endif
9664
b1fb8740
VZ
9665 /*
9666 * Clear all pending SP commands as we are going to reset the
9667 * function anyway.
9668 */
9669 bp->sp_rtnl_state = 0;
9670 smp_mb();
9671
5d07d868 9672 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9673 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740 9674
8395be5e
AE
9675 rtnl_unlock();
9676 return;
72fd0718 9677 }
b1fb8740
VZ
9678#ifdef BNX2X_STOP_ON_ERROR
9679sp_rtnl_not_reset:
9680#endif
9681 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9682 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9683 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9684 bnx2x_after_function_update(bp);
8304859a
AE
9685 /*
9686 * in case of fan failure we need to reset id if the "stop on error"
9687 * debug flag is set, since we trying to prevent permanent overheating
9688 * damage
9689 */
9690 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9691 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9692 netif_device_detach(bp->dev);
9693 bnx2x_close(bp->dev);
8395be5e
AE
9694 rtnl_unlock();
9695 return;
8304859a
AE
9696 }
9697
381ac16b
AE
9698 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9699 DP(BNX2X_MSG_SP,
9700 "sending set mcast vf pf channel message from rtnl sp-task\n");
9701 bnx2x_vfpf_set_mcast(bp->dev);
9702 }
78c3bcc5
AE
9703 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
9704 &bp->sp_rtnl_state)){
9705 if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
9706 bnx2x_tx_disable(bp);
9707 BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
9708 }
9709 }
381ac16b 9710
8b09be5f
YM
9711 if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
9712 DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
9713 bnx2x_set_rx_mode_inner(bp);
381ac16b
AE
9714 }
9715
3ec9f9ca
AE
9716 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9717 &bp->sp_rtnl_state))
9718 bnx2x_pf_set_vfs_vlan(bp);
9719
6ffa39f2 9720 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
07b4eb3b 9721 bnx2x_dcbx_stop_hw_tx(bp);
07b4eb3b 9722 bnx2x_dcbx_resume_hw_tx(bp);
6ffa39f2 9723 }
07b4eb3b 9724
8395be5e
AE
9725 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9726 * can be called from other contexts as well)
9727 */
34f80b04 9728 rtnl_unlock();
8395be5e 9729
6411280a 9730 /* enable SR-IOV if applicable */
8395be5e 9731 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
3c76feff
AE
9732 &bp->sp_rtnl_state)) {
9733 bnx2x_disable_sriov(bp);
6411280a 9734 bnx2x_enable_sriov(bp);
3c76feff 9735 }
34f80b04
EG
9736}
9737
3deb8167
YR
9738static void bnx2x_period_task(struct work_struct *work)
9739{
9740 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9741
9742 if (!netif_running(bp->dev))
9743 goto period_task_exit;
9744
9745 if (CHIP_REV_IS_SLOW(bp)) {
9746 BNX2X_ERR("period task called on emulation, ignoring\n");
9747 goto period_task_exit;
9748 }
9749
9750 bnx2x_acquire_phy_lock(bp);
9751 /*
9752 * The barrier is needed to ensure the ordering between the writing to
9753 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9754 * the reading here.
9755 */
9756 smp_mb();
9757 if (bp->port.pmf) {
9758 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9759
9760 /* Re-queue task in 1 sec */
9761 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9762 }
9763
9764 bnx2x_release_phy_lock(bp);
9765period_task_exit:
9766 return;
9767}
9768
a2fbb9ea
ET
9769/*
9770 * Init service functions
9771 */
9772
b56e9670 9773u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9774{
9775 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9776 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9777 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9778}
9779
1ef1d45a
BW
9780static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9781 struct bnx2x_mac_vals *vals)
34f80b04 9782{
452427b0
YM
9783 u32 val, base_addr, offset, mask, reset_reg;
9784 bool mac_stopped = false;
9785 u8 port = BP_PORT(bp);
34f80b04 9786
1ef1d45a
BW
9787 /* reset addresses as they also mark which values were changed */
9788 vals->bmac_addr = 0;
9789 vals->umac_addr = 0;
9790 vals->xmac_addr = 0;
9791 vals->emac_addr = 0;
9792
452427b0 9793 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9794
452427b0
YM
9795 if (!CHIP_IS_E3(bp)) {
9796 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9797 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9798 if ((mask & reset_reg) && val) {
9799 u32 wb_data[2];
9800 BNX2X_DEV_INFO("Disable bmac Rx\n");
9801 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9802 : NIG_REG_INGRESS_BMAC0_MEM;
9803 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9804 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9805
452427b0
YM
9806 /*
9807 * use rd/wr since we cannot use dmae. This is safe
9808 * since MCP won't access the bus due to the request
9809 * to unload, and no function on the path can be
9810 * loaded at this time.
9811 */
9812 wb_data[0] = REG_RD(bp, base_addr + offset);
9813 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
1ef1d45a
BW
9814 vals->bmac_addr = base_addr + offset;
9815 vals->bmac_val[0] = wb_data[0];
9816 vals->bmac_val[1] = wb_data[1];
452427b0 9817 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1ef1d45a
BW
9818 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9819 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
452427b0
YM
9820 }
9821 BNX2X_DEV_INFO("Disable emac Rx\n");
1ef1d45a
BW
9822 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9823 vals->emac_val = REG_RD(bp, vals->emac_addr);
9824 REG_WR(bp, vals->emac_addr, 0);
452427b0
YM
9825 mac_stopped = true;
9826 } else {
9827 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9828 BNX2X_DEV_INFO("Disable xmac Rx\n");
9829 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9830 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9831 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9832 val & ~(1 << 1));
9833 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9834 val | (1 << 1));
1ef1d45a
BW
9835 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9836 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9837 REG_WR(bp, vals->xmac_addr, 0);
452427b0
YM
9838 mac_stopped = true;
9839 }
9840 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9841 if (mask & reset_reg) {
9842 BNX2X_DEV_INFO("Disable umac Rx\n");
9843 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1ef1d45a
BW
9844 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9845 vals->umac_val = REG_RD(bp, vals->umac_addr);
9846 REG_WR(bp, vals->umac_addr, 0);
452427b0
YM
9847 mac_stopped = true;
9848 }
9849 }
9850
9851 if (mac_stopped)
9852 msleep(20);
452427b0
YM
9853}
9854
9855#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9856#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9857#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9858#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9859
91ebb929
YM
9860#define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
9861#define BCM_5710_UNDI_FW_MF_MINOR (0x08)
9862#define BCM_5710_UNDI_FW_MF_VERS (0x05)
9863#define BNX2X_PREV_UNDI_MF_PORT(p) (0x1a150c + ((p) << 4))
9864#define BNX2X_PREV_UNDI_MF_FUNC(f) (0x1a184c + ((f) << 4))
9865static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
9866{
9867 u8 major, minor, version;
9868 u32 fw;
9869
9870 /* Must check that FW is loaded */
9871 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
9872 MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
9873 BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
9874 return false;
9875 }
9876
9877 /* Read Currently loaded FW version */
9878 fw = REG_RD(bp, XSEM_REG_PRAM);
9879 major = fw & 0xff;
9880 minor = (fw >> 0x8) & 0xff;
9881 version = (fw >> 0x10) & 0xff;
9882 BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
9883 fw, major, minor, version);
9884
9885 if (major > BCM_5710_UNDI_FW_MF_MAJOR)
9886 return true;
9887
9888 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
9889 (minor > BCM_5710_UNDI_FW_MF_MINOR))
9890 return true;
9891
9892 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
9893 (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
9894 (version >= BCM_5710_UNDI_FW_MF_VERS))
9895 return true;
9896
9897 return false;
9898}
9899
9900static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
9901{
9902 int i;
9903
9904 /* Due to legacy (FW) code, the first function on each engine has a
9905 * different offset macro from the rest of the functions.
9906 * Setting this for all 8 functions is harmless regardless of whether
9907 * this is actually a multi-function device.
9908 */
9909 for (i = 0; i < 2; i++)
9910 REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
9911
9912 for (i = 2; i < 8; i++)
9913 REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
9914
9915 BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
9916}
9917
1dd06ae8 9918static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
452427b0
YM
9919{
9920 u16 rcq, bd;
9921 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9922
9923 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9924 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9925
9926 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9927 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9928
9929 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9930 port, bd, rcq);
9931}
9932
0329aba1 9933static int bnx2x_prev_mcp_done(struct bnx2x *bp)
452427b0 9934{
5d07d868
YM
9935 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9936 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9937 if (!rc) {
9938 BNX2X_ERR("MCP response failure, aborting\n");
9939 return -EBUSY;
9940 }
9941
9942 return 0;
9943}
9944
c63da990
BW
9945static struct bnx2x_prev_path_list *
9946 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9947{
9948 struct bnx2x_prev_path_list *tmp_list;
9949
9950 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9951 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9952 bp->pdev->bus->number == tmp_list->bus &&
9953 BP_PATH(bp) == tmp_list->path)
9954 return tmp_list;
9955
9956 return NULL;
9957}
9958
7fa6f340
YM
9959static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
9960{
9961 struct bnx2x_prev_path_list *tmp_list;
9962 int rc;
9963
9964 rc = down_interruptible(&bnx2x_prev_sem);
9965 if (rc) {
9966 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9967 return rc;
9968 }
9969
9970 tmp_list = bnx2x_prev_path_get_entry(bp);
9971 if (tmp_list) {
9972 tmp_list->aer = 1;
9973 rc = 0;
9974 } else {
9975 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
9976 BP_PATH(bp));
9977 }
9978
9979 up(&bnx2x_prev_sem);
9980
9981 return rc;
9982}
9983
0329aba1 9984static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
452427b0
YM
9985{
9986 struct bnx2x_prev_path_list *tmp_list;
b85d717c 9987 bool rc = false;
452427b0
YM
9988
9989 if (down_trylock(&bnx2x_prev_sem))
9990 return false;
9991
7fa6f340
YM
9992 tmp_list = bnx2x_prev_path_get_entry(bp);
9993 if (tmp_list) {
9994 if (tmp_list->aer) {
9995 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
9996 BP_PATH(bp));
9997 } else {
452427b0
YM
9998 rc = true;
9999 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
10000 BP_PATH(bp));
452427b0
YM
10001 }
10002 }
10003
10004 up(&bnx2x_prev_sem);
10005
10006 return rc;
10007}
10008
178135c1
DK
10009bool bnx2x_port_after_undi(struct bnx2x *bp)
10010{
10011 struct bnx2x_prev_path_list *entry;
10012 bool val;
10013
10014 down(&bnx2x_prev_sem);
10015
10016 entry = bnx2x_prev_path_get_entry(bp);
10017 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
10018
10019 up(&bnx2x_prev_sem);
10020
10021 return val;
10022}
10023
c63da990 10024static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
452427b0
YM
10025{
10026 struct bnx2x_prev_path_list *tmp_list;
10027 int rc;
10028
7fa6f340
YM
10029 rc = down_interruptible(&bnx2x_prev_sem);
10030 if (rc) {
10031 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10032 return rc;
10033 }
10034
10035 /* Check whether the entry for this path already exists */
10036 tmp_list = bnx2x_prev_path_get_entry(bp);
10037 if (tmp_list) {
10038 if (!tmp_list->aer) {
10039 BNX2X_ERR("Re-Marking the path.\n");
10040 } else {
10041 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
10042 BP_PATH(bp));
10043 tmp_list->aer = 0;
10044 }
10045 up(&bnx2x_prev_sem);
10046 return 0;
10047 }
10048 up(&bnx2x_prev_sem);
10049
10050 /* Create an entry for this path and add it */
ea4b3857 10051 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
10052 if (!tmp_list) {
10053 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
10054 return -ENOMEM;
10055 }
10056
10057 tmp_list->bus = bp->pdev->bus->number;
10058 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
10059 tmp_list->path = BP_PATH(bp);
7fa6f340 10060 tmp_list->aer = 0;
c63da990 10061 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
452427b0
YM
10062
10063 rc = down_interruptible(&bnx2x_prev_sem);
10064 if (rc) {
10065 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10066 kfree(tmp_list);
10067 } else {
7fa6f340
YM
10068 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
10069 BP_PATH(bp));
452427b0
YM
10070 list_add(&tmp_list->list, &bnx2x_prev_list);
10071 up(&bnx2x_prev_sem);
10072 }
10073
10074 return rc;
10075}
10076
0329aba1 10077static int bnx2x_do_flr(struct bnx2x *bp)
452427b0 10078{
452427b0
YM
10079 struct pci_dev *dev = bp->pdev;
10080
8eee694c
YM
10081 if (CHIP_IS_E1x(bp)) {
10082 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
10083 return -EINVAL;
10084 }
10085
10086 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
10087 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
10088 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
10089 bp->common.bc_ver);
10090 return -EINVAL;
10091 }
452427b0 10092
8903b9eb
CL
10093 if (!pci_wait_for_pending_transaction(dev))
10094 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
452427b0 10095
8eee694c 10096 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
10097 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
10098
10099 return 0;
10100}
10101
0329aba1 10102static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
452427b0
YM
10103{
10104 int rc;
10105
10106 BNX2X_DEV_INFO("Uncommon unload Flow\n");
10107
10108 /* Test if previous unload process was already finished for this path */
10109 if (bnx2x_prev_is_path_marked(bp))
10110 return bnx2x_prev_mcp_done(bp);
10111
04c46736
YM
10112 BNX2X_DEV_INFO("Path is unmarked\n");
10113
452427b0
YM
10114 /* If function has FLR capabilities, and existing FW version matches
10115 * the one required, then FLR will be sufficient to clean any residue
10116 * left by previous driver
10117 */
91ebb929 10118 rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
8eee694c
YM
10119
10120 if (!rc) {
10121 /* fw version is good */
10122 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
10123 rc = bnx2x_do_flr(bp);
10124 }
10125
10126 if (!rc) {
10127 /* FLR was performed */
10128 BNX2X_DEV_INFO("FLR successful\n");
10129 return 0;
10130 }
10131
10132 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
10133
10134 /* Close the MCP request, return failure*/
10135 rc = bnx2x_prev_mcp_done(bp);
10136 if (!rc)
10137 rc = BNX2X_PREV_WAIT_NEEDED;
10138
10139 return rc;
10140}
10141
0329aba1 10142static int bnx2x_prev_unload_common(struct bnx2x *bp)
452427b0
YM
10143{
10144 u32 reset_reg, tmp_reg = 0, rc;
c63da990 10145 bool prev_undi = false;
1ef1d45a
BW
10146 struct bnx2x_mac_vals mac_vals;
10147
452427b0
YM
10148 /* It is possible a previous function received 'common' answer,
10149 * but hasn't loaded yet, therefore creating a scenario of
10150 * multiple functions receiving 'common' on the same path.
10151 */
10152 BNX2X_DEV_INFO("Common unload Flow\n");
10153
1ef1d45a
BW
10154 memset(&mac_vals, 0, sizeof(mac_vals));
10155
452427b0
YM
10156 if (bnx2x_prev_is_path_marked(bp))
10157 return bnx2x_prev_mcp_done(bp);
10158
10159 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
10160
10161 /* Reset should be performed after BRB is emptied */
10162 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
10163 u32 timer_count = 1000;
452427b0
YM
10164
10165 /* Close the MAC Rx to prevent BRB from filling up */
1ef1d45a
BW
10166 bnx2x_prev_unload_close_mac(bp, &mac_vals);
10167
10168 /* close LLH filters towards the BRB */
10169 bnx2x_set_rx_filter(&bp->link_params, 0);
452427b0
YM
10170
10171 /* Check if the UNDI driver was previously loaded
34f80b04
EG
10172 * UNDI driver initializes CID offset for normal bell to 0x7
10173 */
452427b0
YM
10174 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
10175 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
10176 if (tmp_reg == 0x7) {
10177 BNX2X_DEV_INFO("UNDI previously loaded\n");
10178 prev_undi = true;
10179 /* clear the UNDI indication */
10180 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
a74801c5
YM
10181 /* clear possible idle check errors */
10182 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
34f80b04 10183 }
452427b0 10184 }
d46f7c4d
DK
10185 if (!CHIP_IS_E1x(bp))
10186 /* block FW from writing to host */
10187 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10188
452427b0
YM
10189 /* wait until BRB is empty */
10190 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10191 while (timer_count) {
10192 u32 prev_brb = tmp_reg;
34f80b04 10193
452427b0
YM
10194 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10195 if (!tmp_reg)
10196 break;
619c5cb6 10197
452427b0 10198 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 10199
452427b0
YM
10200 /* reset timer as long as BRB actually gets emptied */
10201 if (prev_brb > tmp_reg)
10202 timer_count = 1000;
10203 else
10204 timer_count--;
da5a662a 10205
91ebb929
YM
10206 /* New UNDI FW supports MF and contains better
10207 * cleaning methods - might be redundant but harmless.
10208 */
10209 if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
10210 bnx2x_prev_unload_undi_mf(bp);
10211 } else if (prev_undi) {
10212 /* If UNDI resides in memory,
10213 * manually increment it
10214 */
452427b0 10215 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
91ebb929 10216 }
452427b0 10217 udelay(10);
7a06a122 10218 }
452427b0
YM
10219
10220 if (!timer_count)
10221 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
34f80b04 10222 }
f16da43b 10223
452427b0
YM
10224 /* No packets are in the pipeline, path is ready for reset */
10225 bnx2x_reset_common(bp);
10226
1ef1d45a
BW
10227 if (mac_vals.xmac_addr)
10228 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
10229 if (mac_vals.umac_addr)
10230 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
10231 if (mac_vals.emac_addr)
10232 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
10233 if (mac_vals.bmac_addr) {
10234 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
10235 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
10236 }
10237
c63da990 10238 rc = bnx2x_prev_mark_path(bp, prev_undi);
452427b0
YM
10239 if (rc) {
10240 bnx2x_prev_mcp_done(bp);
10241 return rc;
10242 }
10243
10244 return bnx2x_prev_mcp_done(bp);
10245}
10246
24f06716
AE
10247/* previous driver DMAE transaction may have occurred when pre-boot stage ended
10248 * and boot began, or when kdump kernel was loaded. Either case would invalidate
10249 * the addresses of the transaction, resulting in was-error bit set in the pci
10250 * causing all hw-to-host pcie transactions to timeout. If this happened we want
10251 * to clear the interrupt which detected this from the pglueb and the was done
10252 * bit
10253 */
0329aba1 10254static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
24f06716 10255{
4a25417c
AE
10256 if (!CHIP_IS_E1x(bp)) {
10257 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
10258 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
04c46736
YM
10259 DP(BNX2X_MSG_SP,
10260 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
4a25417c
AE
10261 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
10262 1 << BP_FUNC(bp));
10263 }
24f06716
AE
10264 }
10265}
10266
0329aba1 10267static int bnx2x_prev_unload(struct bnx2x *bp)
452427b0
YM
10268{
10269 int time_counter = 10;
10270 u32 rc, fw, hw_lock_reg, hw_lock_val;
10271 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10272
24f06716
AE
10273 /* clear hw from errors which may have resulted from an interrupted
10274 * dmae transaction.
10275 */
10276 bnx2x_prev_interrupted_dmae(bp);
10277
10278 /* Release previously held locks */
452427b0
YM
10279 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10280 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10281 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10282
3cdeec22 10283 hw_lock_val = REG_RD(bp, hw_lock_reg);
452427b0
YM
10284 if (hw_lock_val) {
10285 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10286 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10287 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10288 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10289 }
10290
10291 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10292 REG_WR(bp, hw_lock_reg, 0xffffffff);
10293 } else
10294 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10295
10296 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10297 BNX2X_DEV_INFO("Release previously held alr\n");
3cdeec22 10298 bnx2x_release_alr(bp);
452427b0
YM
10299 }
10300
452427b0 10301 do {
7fa6f340 10302 int aer = 0;
452427b0
YM
10303 /* Lock MCP using an unload request */
10304 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10305 if (!fw) {
10306 BNX2X_ERR("MCP response failure, aborting\n");
10307 rc = -EBUSY;
10308 break;
10309 }
10310
7fa6f340
YM
10311 rc = down_interruptible(&bnx2x_prev_sem);
10312 if (rc) {
10313 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10314 rc);
10315 } else {
10316 /* If Path is marked by EEH, ignore unload status */
10317 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10318 bnx2x_prev_path_get_entry(bp)->aer);
60cde81f 10319 up(&bnx2x_prev_sem);
7fa6f340 10320 }
7fa6f340
YM
10321
10322 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
452427b0
YM
10323 rc = bnx2x_prev_unload_common(bp);
10324 break;
10325 }
10326
16a5fd92 10327 /* non-common reply from MCP might require looping */
452427b0
YM
10328 rc = bnx2x_prev_unload_uncommon(bp);
10329 if (rc != BNX2X_PREV_WAIT_NEEDED)
10330 break;
10331
10332 msleep(20);
10333 } while (--time_counter);
10334
10335 if (!time_counter || rc) {
91ebb929
YM
10336 BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
10337 rc = -EPROBE_DEFER;
452427b0
YM
10338 }
10339
c63da990 10340 /* Mark function if its port was used to boot from SAN */
178135c1 10341 if (bnx2x_port_after_undi(bp))
c63da990
BW
10342 bp->link_params.feature_config_flags |=
10343 FEATURE_CONFIG_BOOT_FROM_SAN;
10344
452427b0
YM
10345 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10346
10347 return rc;
34f80b04
EG
10348}
10349
0329aba1 10350static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
34f80b04 10351{
1d187b34 10352 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 10353 u16 pmc;
34f80b04
EG
10354
10355 /* Get the chip revision id and number. */
10356 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10357 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10358 id = ((val & 0xffff) << 16);
10359 val = REG_RD(bp, MISC_REG_CHIP_REV);
10360 id |= ((val & 0xf) << 12);
f22fdf25
YM
10361
10362 /* Metal is read from PCI regs, but we can't access >=0x400 from
10363 * the configuration space (so we need to reg_rd)
10364 */
10365 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10366 id |= (((val >> 24) & 0xf) << 4);
5a40e08e 10367 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
10368 id |= (val & 0xf);
10369 bp->common.chip_id = id;
523224a3 10370
7e8e02df
BW
10371 /* force 57811 according to MISC register */
10372 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10373 if (CHIP_IS_57810(bp))
10374 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10375 (bp->common.chip_id & 0x0000FFFF);
10376 else if (CHIP_IS_57810_MF(bp))
10377 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10378 (bp->common.chip_id & 0x0000FFFF);
10379 bp->common.chip_id |= 0x1;
10380 }
10381
523224a3
DK
10382 /* Set doorbell size */
10383 bp->db_size = (1 << BNX2X_DB_SHIFT);
10384
619c5cb6 10385 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
10386 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10387 if ((val & 1) == 0)
10388 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10389 else
10390 val = (val >> 1) & 1;
10391 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10392 "2_PORT_MODE");
10393 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10394 CHIP_2_PORT_MODE;
10395
10396 if (CHIP_MODE_IS_4_PORT(bp))
10397 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10398 else
10399 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10400 } else {
10401 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10402 bp->pfid = bp->pf_num; /* 0..7 */
10403 }
10404
51c1a580
MS
10405 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10406
f2e0899f
DK
10407 bp->link_params.chip_id = bp->common.chip_id;
10408 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 10409
1c06328c
EG
10410 val = (REG_RD(bp, 0x2874) & 0x55);
10411 if ((bp->common.chip_id & 0x1) ||
10412 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10413 bp->flags |= ONE_PORT_FLAG;
10414 BNX2X_DEV_INFO("single port device\n");
10415 }
10416
34f80b04 10417 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 10418 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
10419 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10420 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10421 bp->common.flash_size, bp->common.flash_size);
10422
1b6e2ceb
DK
10423 bnx2x_init_shmem(bp);
10424
f2e0899f
DK
10425 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10426 MISC_REG_GENERIC_CR_1 :
10427 MISC_REG_GENERIC_CR_0));
1b6e2ceb 10428
34f80b04 10429 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 10430 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
10431 if (SHMEM2_RD(bp, size) >
10432 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10433 bp->link_params.lfa_base =
10434 REG_RD(bp, bp->common.shmem2_base +
10435 (u32)offsetof(struct shmem2_region,
10436 lfa_host_addr[BP_PORT(bp)]));
10437 else
10438 bp->link_params.lfa_base = 0;
2691d51d
EG
10439 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10440 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 10441
f2e0899f 10442 if (!bp->common.shmem_base) {
34f80b04
EG
10443 BNX2X_DEV_INFO("MCP not active\n");
10444 bp->flags |= NO_MCP_FLAG;
10445 return;
10446 }
10447
34f80b04 10448 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 10449 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
10450
10451 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10452 SHARED_HW_CFG_LED_MODE_MASK) >>
10453 SHARED_HW_CFG_LED_MODE_SHIFT);
10454
c2c8b03e
EG
10455 bp->link_params.feature_config_flags = 0;
10456 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10457 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10458 bp->link_params.feature_config_flags |=
10459 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10460 else
10461 bp->link_params.feature_config_flags &=
10462 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10463
34f80b04
EG
10464 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10465 bp->common.bc_ver = val;
10466 BNX2X_DEV_INFO("bc_ver %X\n", val);
10467 if (val < BNX2X_BC_VER) {
10468 /* for now only warn
10469 * later we might need to enforce this */
51c1a580
MS
10470 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10471 BNX2X_BC_VER, val);
34f80b04 10472 }
4d295db0 10473 bp->link_params.feature_config_flags |=
a22f0788 10474 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
10475 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10476
a22f0788
YR
10477 bp->link_params.feature_config_flags |=
10478 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10479 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
10480 bp->link_params.feature_config_flags |=
10481 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10482 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
10483 bp->link_params.feature_config_flags |=
10484 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10485 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
10486
10487 bp->link_params.feature_config_flags |=
10488 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10489 FEATURE_CONFIG_MT_SUPPORT : 0;
10490
0e898dd7
BW
10491 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10492 BC_SUPPORTS_PFC_STATS : 0;
85242eea 10493
2e499d3c
BW
10494 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10495 BC_SUPPORTS_FCOE_FEATURES : 0;
10496
9876879f
BW
10497 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10498 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
a6d3a5ba
BW
10499
10500 bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
10501 BC_SUPPORTS_RMMOD_CMD : 0;
10502
1d187b34
BW
10503 boot_mode = SHMEM_RD(bp,
10504 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10505 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10506 switch (boot_mode) {
10507 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10508 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10509 break;
10510 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10511 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10512 break;
10513 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10514 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10515 break;
10516 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10517 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10518 break;
10519 }
10520
29ed74c3 10521 pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
f9a3ebbe
DK
10522 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10523
72ce58c3 10524 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 10525 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
10526
10527 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10528 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10529 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10530 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10531
cdaa7cb8
VZ
10532 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10533 val, val2, val3, val4);
34f80b04
EG
10534}
10535
f2e0899f
DK
10536#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10537#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10538
0329aba1 10539static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
10540{
10541 int pfid = BP_FUNC(bp);
f2e0899f
DK
10542 int igu_sb_id;
10543 u32 val;
6383c0b3 10544 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
10545
10546 bp->igu_base_sb = 0xff;
f2e0899f 10547 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 10548 int vn = BP_VN(bp);
6383c0b3 10549 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
10550 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10551 FP_SB_MAX_E1x;
10552
10553 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10554 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10555
9b341bb1 10556 return 0;
f2e0899f
DK
10557 }
10558
10559 /* IGU in normal mode - read CAM */
10560 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10561 igu_sb_id++) {
10562 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10563 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10564 continue;
10565 fid = IGU_FID(val);
10566 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10567 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10568 continue;
10569 if (IGU_VEC(val) == 0)
10570 /* default status block */
10571 bp->igu_dsb_id = igu_sb_id;
10572 else {
10573 if (bp->igu_base_sb == 0xff)
10574 bp->igu_base_sb = igu_sb_id;
6383c0b3 10575 igu_sb_cnt++;
f2e0899f
DK
10576 }
10577 }
10578 }
619c5cb6 10579
6383c0b3 10580#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10581 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10582 * optional that number of CAM entries will not be equal to the value
10583 * advertised in PCI.
10584 * Driver should use the minimal value of both as the actual status
10585 * block count
619c5cb6 10586 */
185d4c8b 10587 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10588#endif
619c5cb6 10589
9b341bb1 10590 if (igu_sb_cnt == 0) {
f2e0899f 10591 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10592 return -EINVAL;
10593 }
10594
10595 return 0;
f2e0899f
DK
10596}
10597
1dd06ae8 10598static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
a2fbb9ea 10599{
a22f0788
YR
10600 int cfg_size = 0, idx, port = BP_PORT(bp);
10601
10602 /* Aggregation of supported attributes of all external phys */
10603 bp->port.supported[0] = 0;
10604 bp->port.supported[1] = 0;
b7737c9b
YR
10605 switch (bp->link_params.num_phys) {
10606 case 1:
a22f0788
YR
10607 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10608 cfg_size = 1;
10609 break;
b7737c9b 10610 case 2:
a22f0788
YR
10611 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10612 cfg_size = 1;
10613 break;
10614 case 3:
10615 if (bp->link_params.multi_phy_config &
10616 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10617 bp->port.supported[1] =
10618 bp->link_params.phy[EXT_PHY1].supported;
10619 bp->port.supported[0] =
10620 bp->link_params.phy[EXT_PHY2].supported;
10621 } else {
10622 bp->port.supported[0] =
10623 bp->link_params.phy[EXT_PHY1].supported;
10624 bp->port.supported[1] =
10625 bp->link_params.phy[EXT_PHY2].supported;
10626 }
10627 cfg_size = 2;
10628 break;
b7737c9b 10629 }
a2fbb9ea 10630
a22f0788 10631 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10632 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10633 SHMEM_RD(bp,
a22f0788
YR
10634 dev_info.port_hw_config[port].external_phy_config),
10635 SHMEM_RD(bp,
10636 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10637 return;
f85582f8 10638 }
a2fbb9ea 10639
619c5cb6
VZ
10640 if (CHIP_IS_E3(bp))
10641 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10642 else {
10643 switch (switch_cfg) {
10644 case SWITCH_CFG_1G:
10645 bp->port.phy_addr = REG_RD(
10646 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10647 break;
10648 case SWITCH_CFG_10G:
10649 bp->port.phy_addr = REG_RD(
10650 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10651 break;
10652 default:
10653 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10654 bp->port.link_config[0]);
10655 return;
10656 }
a2fbb9ea 10657 }
619c5cb6 10658 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10659 /* mask what we support according to speed_cap_mask per configuration */
10660 for (idx = 0; idx < cfg_size; idx++) {
10661 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10662 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10663 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10664
a22f0788 10665 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10666 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10667 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10668
a22f0788 10669 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10670 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10671 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10672
a22f0788 10673 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10674 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10675 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10676
a22f0788 10677 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10678 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10679 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10680 SUPPORTED_1000baseT_Full);
a2fbb9ea 10681
a22f0788 10682 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10683 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10684 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10685
a22f0788 10686 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10687 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788 10688 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
b8e0d884
YR
10689
10690 if (!(bp->link_params.speed_cap_mask[idx] &
10691 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
10692 bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
a22f0788 10693 }
a2fbb9ea 10694
a22f0788
YR
10695 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10696 bp->port.supported[1]);
a2fbb9ea
ET
10697}
10698
0329aba1 10699static void bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10700{
a22f0788
YR
10701 u32 link_config, idx, cfg_size = 0;
10702 bp->port.advertising[0] = 0;
10703 bp->port.advertising[1] = 0;
10704 switch (bp->link_params.num_phys) {
10705 case 1:
10706 case 2:
10707 cfg_size = 1;
10708 break;
10709 case 3:
10710 cfg_size = 2;
10711 break;
10712 }
10713 for (idx = 0; idx < cfg_size; idx++) {
10714 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10715 link_config = bp->port.link_config[idx];
10716 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10717 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10718 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10719 bp->link_params.req_line_speed[idx] =
10720 SPEED_AUTO_NEG;
10721 bp->port.advertising[idx] |=
10722 bp->port.supported[idx];
10bd1f24
MY
10723 if (bp->link_params.phy[EXT_PHY1].type ==
10724 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10725 bp->port.advertising[idx] |=
10726 (SUPPORTED_100baseT_Half |
10727 SUPPORTED_100baseT_Full);
f85582f8
DK
10728 } else {
10729 /* force 10G, no AN */
a22f0788
YR
10730 bp->link_params.req_line_speed[idx] =
10731 SPEED_10000;
10732 bp->port.advertising[idx] |=
10733 (ADVERTISED_10000baseT_Full |
f85582f8 10734 ADVERTISED_FIBRE);
a22f0788 10735 continue;
f85582f8
DK
10736 }
10737 break;
a2fbb9ea 10738
f85582f8 10739 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10740 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10741 bp->link_params.req_line_speed[idx] =
10742 SPEED_10;
10743 bp->port.advertising[idx] |=
10744 (ADVERTISED_10baseT_Full |
f85582f8
DK
10745 ADVERTISED_TP);
10746 } else {
51c1a580 10747 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10748 link_config,
a22f0788 10749 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10750 return;
10751 }
10752 break;
a2fbb9ea 10753
f85582f8 10754 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10755 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10756 bp->link_params.req_line_speed[idx] =
10757 SPEED_10;
10758 bp->link_params.req_duplex[idx] =
10759 DUPLEX_HALF;
10760 bp->port.advertising[idx] |=
10761 (ADVERTISED_10baseT_Half |
f85582f8
DK
10762 ADVERTISED_TP);
10763 } else {
51c1a580 10764 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10765 link_config,
10766 bp->link_params.speed_cap_mask[idx]);
10767 return;
10768 }
10769 break;
a2fbb9ea 10770
f85582f8
DK
10771 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10772 if (bp->port.supported[idx] &
10773 SUPPORTED_100baseT_Full) {
a22f0788
YR
10774 bp->link_params.req_line_speed[idx] =
10775 SPEED_100;
10776 bp->port.advertising[idx] |=
10777 (ADVERTISED_100baseT_Full |
f85582f8
DK
10778 ADVERTISED_TP);
10779 } else {
51c1a580 10780 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10781 link_config,
10782 bp->link_params.speed_cap_mask[idx]);
10783 return;
10784 }
10785 break;
a2fbb9ea 10786
f85582f8
DK
10787 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10788 if (bp->port.supported[idx] &
10789 SUPPORTED_100baseT_Half) {
10790 bp->link_params.req_line_speed[idx] =
10791 SPEED_100;
10792 bp->link_params.req_duplex[idx] =
10793 DUPLEX_HALF;
a22f0788
YR
10794 bp->port.advertising[idx] |=
10795 (ADVERTISED_100baseT_Half |
f85582f8
DK
10796 ADVERTISED_TP);
10797 } else {
51c1a580 10798 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10799 link_config,
10800 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10801 return;
10802 }
10803 break;
a2fbb9ea 10804
f85582f8 10805 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10806 if (bp->port.supported[idx] &
10807 SUPPORTED_1000baseT_Full) {
10808 bp->link_params.req_line_speed[idx] =
10809 SPEED_1000;
10810 bp->port.advertising[idx] |=
10811 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10812 ADVERTISED_TP);
10813 } else {
51c1a580 10814 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10815 link_config,
10816 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10817 return;
10818 }
10819 break;
a2fbb9ea 10820
f85582f8 10821 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10822 if (bp->port.supported[idx] &
10823 SUPPORTED_2500baseX_Full) {
10824 bp->link_params.req_line_speed[idx] =
10825 SPEED_2500;
10826 bp->port.advertising[idx] |=
10827 (ADVERTISED_2500baseX_Full |
34f80b04 10828 ADVERTISED_TP);
f85582f8 10829 } else {
51c1a580 10830 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10831 link_config,
f85582f8
DK
10832 bp->link_params.speed_cap_mask[idx]);
10833 return;
10834 }
10835 break;
a2fbb9ea 10836
f85582f8 10837 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10838 if (bp->port.supported[idx] &
10839 SUPPORTED_10000baseT_Full) {
10840 bp->link_params.req_line_speed[idx] =
10841 SPEED_10000;
10842 bp->port.advertising[idx] |=
10843 (ADVERTISED_10000baseT_Full |
34f80b04 10844 ADVERTISED_FIBRE);
f85582f8 10845 } else {
51c1a580 10846 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10847 link_config,
f85582f8
DK
10848 bp->link_params.speed_cap_mask[idx]);
10849 return;
10850 }
10851 break;
3c9ada22
YR
10852 case PORT_FEATURE_LINK_SPEED_20G:
10853 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10854
3c9ada22 10855 break;
f85582f8 10856 default:
51c1a580 10857 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10858 link_config);
f85582f8
DK
10859 bp->link_params.req_line_speed[idx] =
10860 SPEED_AUTO_NEG;
10861 bp->port.advertising[idx] =
10862 bp->port.supported[idx];
10863 break;
10864 }
a2fbb9ea 10865
a22f0788 10866 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10867 PORT_FEATURE_FLOW_CONTROL_MASK);
cd1dfce2
YM
10868 if (bp->link_params.req_flow_ctrl[idx] ==
10869 BNX2X_FLOW_CTRL_AUTO) {
10870 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10871 bp->link_params.req_flow_ctrl[idx] =
10872 BNX2X_FLOW_CTRL_NONE;
10873 else
10874 bnx2x_set_requested_fc(bp);
a22f0788 10875 }
a2fbb9ea 10876
51c1a580 10877 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10878 bp->link_params.req_line_speed[idx],
10879 bp->link_params.req_duplex[idx],
10880 bp->link_params.req_flow_ctrl[idx],
10881 bp->port.advertising[idx]);
10882 }
a2fbb9ea
ET
10883}
10884
0329aba1 10885static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
e665bfda 10886{
86564c3f
YM
10887 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10888 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10889 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10890 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
e665bfda
MC
10891}
10892
0329aba1 10893static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10894{
34f80b04 10895 int port = BP_PORT(bp);
589abe3a 10896 u32 config;
c8c60d88 10897 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10898
c18487ee 10899 bp->link_params.bp = bp;
34f80b04 10900 bp->link_params.port = port;
c18487ee 10901
c18487ee 10902 bp->link_params.lane_config =
a2fbb9ea 10903 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10904
a22f0788 10905 bp->link_params.speed_cap_mask[0] =
a2fbb9ea 10906 SHMEM_RD(bp,
b0261926
YR
10907 dev_info.port_hw_config[port].speed_capability_mask) &
10908 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
a22f0788
YR
10909 bp->link_params.speed_cap_mask[1] =
10910 SHMEM_RD(bp,
b0261926
YR
10911 dev_info.port_hw_config[port].speed_capability_mask2) &
10912 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
a22f0788 10913 bp->port.link_config[0] =
a2fbb9ea
ET
10914 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10915
a22f0788
YR
10916 bp->port.link_config[1] =
10917 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10918
a22f0788
YR
10919 bp->link_params.multi_phy_config =
10920 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10921 /* If the device is capable of WoL, set the default state according
10922 * to the HW
10923 */
4d295db0 10924 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10925 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10926 (config & PORT_FEATURE_WOL_ENABLED));
10927
4ba7699b
YM
10928 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10929 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
10930 bp->flags |= NO_ISCSI_FLAG;
10931 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10932 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
10933 bp->flags |= NO_FCOE_FLAG;
10934
51c1a580 10935 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10936 bp->link_params.lane_config,
a22f0788
YR
10937 bp->link_params.speed_cap_mask[0],
10938 bp->port.link_config[0]);
a2fbb9ea 10939
a22f0788 10940 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10941 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10942 bnx2x_phy_probe(&bp->link_params);
c18487ee 10943 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10944
10945 bnx2x_link_settings_requested(bp);
10946
01cd4528
EG
10947 /*
10948 * If connected directly, work with the internal PHY, otherwise, work
10949 * with the external PHY
10950 */
b7737c9b
YR
10951 ext_phy_config =
10952 SHMEM_RD(bp,
10953 dev_info.port_hw_config[port].external_phy_config);
10954 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10955 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10956 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10957
10958 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10959 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10960 bp->mdio.prtad =
b7737c9b 10961 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10962
c8c60d88
YM
10963 /* Configure link feature according to nvram value */
10964 eee_mode = (((SHMEM_RD(bp, dev_info.
10965 port_feature_config[port].eee_power_mode)) &
10966 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10967 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10968 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10969 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10970 EEE_MODE_ENABLE_LPI |
10971 EEE_MODE_OUTPUT_TIME;
10972 } else {
10973 bp->link_params.eee_mode = 0;
10974 }
0793f83f 10975}
01cd4528 10976
b306f5ed 10977void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10978{
9e62e912 10979 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10980 int port = BP_PORT(bp);
2ba45142 10981 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10982 drv_lic_key[port].max_iscsi_conn);
2ba45142 10983
55c11941
MS
10984 if (!CNIC_SUPPORT(bp)) {
10985 bp->flags |= no_flags;
10986 return;
10987 }
10988
b306f5ed 10989 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10990 bp->cnic_eth_dev.max_iscsi_conn =
10991 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10992 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10993
b306f5ed
DK
10994 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10995 bp->cnic_eth_dev.max_iscsi_conn);
10996
10997 /*
10998 * If maximum allowed number of connections is zero -
10999 * disable the feature.
11000 */
11001 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 11002 bp->flags |= no_flags;
b306f5ed
DK
11003}
11004
0329aba1 11005static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9e62e912
DK
11006{
11007 /* Port info */
11008 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11009 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
11010 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11011 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
11012
11013 /* Node info */
11014 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11015 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
11016 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11017 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
11018}
86800194
DK
11019
11020static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
11021{
11022 u8 count = 0;
11023
11024 if (IS_MF(bp)) {
11025 u8 fid;
11026
11027 /* iterate over absolute function ids for this path: */
11028 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
11029 if (IS_MF_SD(bp)) {
11030 u32 cfg = MF_CFG_RD(bp,
11031 func_mf_config[fid].config);
11032
11033 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
11034 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
11035 FUNC_MF_CFG_PROTOCOL_FCOE))
11036 count++;
11037 } else {
11038 u32 cfg = MF_CFG_RD(bp,
11039 func_ext_config[fid].
11040 func_cfg);
11041
11042 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
11043 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
11044 count++;
11045 }
11046 }
11047 } else { /* SF */
11048 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
11049
11050 for (port = 0; port < port_cnt; port++) {
11051 u32 lic = SHMEM_RD(bp,
11052 drv_lic_key[port].max_fcoe_conn) ^
11053 FW_ENCODE_32BIT_PATTERN;
11054 if (lic)
11055 count++;
11056 }
11057 }
11058
11059 return count;
11060}
11061
0329aba1 11062static void bnx2x_get_fcoe_info(struct bnx2x *bp)
b306f5ed
DK
11063{
11064 int port = BP_PORT(bp);
11065 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
11066 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
11067 drv_lic_key[port].max_fcoe_conn);
86800194 11068 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
b306f5ed 11069
55c11941
MS
11070 if (!CNIC_SUPPORT(bp)) {
11071 bp->flags |= NO_FCOE_FLAG;
11072 return;
11073 }
11074
b306f5ed 11075 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
11076 bp->cnic_eth_dev.max_fcoe_conn =
11077 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
11078 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
11079
0eb43b4b
BPG
11080 /* Calculate the number of maximum allowed FCoE tasks */
11081 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
86800194
DK
11082
11083 /* check if FCoE resources must be shared between different functions */
11084 if (num_fcoe_func)
11085 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
0eb43b4b 11086
bf61ee14
VZ
11087 /* Read the WWN: */
11088 if (!IS_MF(bp)) {
11089 /* Port info */
11090 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11091 SHMEM_RD(bp,
2de67439 11092 dev_info.port_hw_config[port].
bf61ee14
VZ
11093 fcoe_wwn_port_name_upper);
11094 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11095 SHMEM_RD(bp,
2de67439 11096 dev_info.port_hw_config[port].
bf61ee14
VZ
11097 fcoe_wwn_port_name_lower);
11098
11099 /* Node info */
11100 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11101 SHMEM_RD(bp,
2de67439 11102 dev_info.port_hw_config[port].
bf61ee14
VZ
11103 fcoe_wwn_node_name_upper);
11104 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11105 SHMEM_RD(bp,
2de67439 11106 dev_info.port_hw_config[port].
bf61ee14
VZ
11107 fcoe_wwn_node_name_lower);
11108 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
11109 /*
11110 * Read the WWN info only if the FCoE feature is enabled for
11111 * this function.
11112 */
7b5342d9 11113 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
11114 bnx2x_get_ext_wwn_info(bp, func);
11115
382e513a 11116 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 11117 bnx2x_get_ext_wwn_info(bp, func);
382e513a 11118 }
bf61ee14 11119
b306f5ed 11120 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 11121
bf61ee14
VZ
11122 /*
11123 * If maximum allowed number of connections is zero -
2ba45142
VZ
11124 * disable the feature.
11125 */
2ba45142
VZ
11126 if (!bp->cnic_eth_dev.max_fcoe_conn)
11127 bp->flags |= NO_FCOE_FLAG;
11128}
b306f5ed 11129
0329aba1 11130static void bnx2x_get_cnic_info(struct bnx2x *bp)
b306f5ed
DK
11131{
11132 /*
11133 * iSCSI may be dynamically disabled but reading
11134 * info here we will decrease memory usage by driver
11135 * if the feature is disabled for good
11136 */
11137 bnx2x_get_iscsi_info(bp);
11138 bnx2x_get_fcoe_info(bp);
11139}
2ba45142 11140
0329aba1 11141static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
11142{
11143 u32 val, val2;
11144 int func = BP_ABS_FUNC(bp);
11145 int port = BP_PORT(bp);
2ba45142
VZ
11146 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
11147 u8 *fip_mac = bp->fip_mac;
0793f83f 11148
55c11941
MS
11149 if (IS_MF(bp)) {
11150 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 11151 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
11152 * In non SD mode features configuration comes from struct
11153 * func_ext_config.
2ba45142 11154 */
55c11941 11155 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
11156 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
11157 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
11158 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 11159 iscsi_mac_addr_upper);
0793f83f 11160 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 11161 iscsi_mac_addr_lower);
2ba45142 11162 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
11163 BNX2X_DEV_INFO
11164 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11165 } else {
2ba45142 11166 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 11167 }
2ba45142
VZ
11168
11169 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
11170 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 11171 fcoe_mac_addr_upper);
2ba45142 11172 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 11173 fcoe_mac_addr_lower);
2ba45142 11174 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
11175 BNX2X_DEV_INFO
11176 ("Read FCoE L2 MAC: %pM\n", fip_mac);
11177 } else {
2ba45142 11178 bp->flags |= NO_FCOE_FLAG;
55c11941 11179 }
a3348722
BW
11180
11181 bp->mf_ext_config = cfg;
11182
9e62e912 11183 } else { /* SD MODE */
55c11941
MS
11184 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
11185 /* use primary mac as iscsi mac */
11186 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
11187
11188 BNX2X_DEV_INFO("SD ISCSI MODE\n");
11189 BNX2X_DEV_INFO
11190 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11191 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
11192 /* use primary mac as fip mac */
11193 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
11194 BNX2X_DEV_INFO("SD FCoE MODE\n");
11195 BNX2X_DEV_INFO
11196 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 11197 }
0793f83f 11198 }
a3348722 11199
82594f8f
YM
11200 /* If this is a storage-only interface, use SAN mac as
11201 * primary MAC. Notice that for SD this is already the case,
11202 * as the SAN mac was copied from the primary MAC.
11203 */
11204 if (IS_MF_FCOE_AFEX(bp))
a3348722 11205 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
0793f83f 11206 } else {
0793f83f 11207 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 11208 iscsi_mac_upper);
0793f83f 11209 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 11210 iscsi_mac_lower);
2ba45142 11211 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
11212
11213 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 11214 fcoe_fip_mac_upper);
c03bd39c 11215 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 11216 fcoe_fip_mac_lower);
c03bd39c 11217 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
11218 }
11219
55c11941 11220 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 11221 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 11222 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
11223 memset(iscsi_mac, 0, ETH_ALEN);
11224 }
11225
55c11941 11226 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
11227 if (!is_valid_ether_addr(fip_mac)) {
11228 bp->flags |= NO_FCOE_FLAG;
11229 memset(bp->fip_mac, 0, ETH_ALEN);
11230 }
55c11941
MS
11231}
11232
0329aba1 11233static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
55c11941
MS
11234{
11235 u32 val, val2;
11236 int func = BP_ABS_FUNC(bp);
11237 int port = BP_PORT(bp);
11238
11239 /* Zero primary MAC configuration */
11240 memset(bp->dev->dev_addr, 0, ETH_ALEN);
11241
11242 if (BP_NOMCP(bp)) {
11243 BNX2X_ERROR("warning: random MAC workaround active\n");
11244 eth_hw_addr_random(bp->dev);
11245 } else if (IS_MF(bp)) {
11246 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
11247 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
11248 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11249 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11250 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11251
11252 if (CNIC_SUPPORT(bp))
11253 bnx2x_get_cnic_mac_hwinfo(bp);
11254 } else {
11255 /* in SF read MACs from port configuration */
11256 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11257 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11258 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11259
11260 if (CNIC_SUPPORT(bp))
11261 bnx2x_get_cnic_mac_hwinfo(bp);
11262 }
11263
3d7d562c
YM
11264 if (!BP_NOMCP(bp)) {
11265 /* Read physical port identifier from shmem */
11266 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11267 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11268 bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
11269 bp->flags |= HAS_PHYS_PORT_ID;
11270 }
11271
55c11941 11272 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 11273
614c76df 11274 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 11275 dev_err(&bp->pdev->dev,
51c1a580
MS
11276 "bad Ethernet MAC address configuration: %pM\n"
11277 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 11278 bp->dev->dev_addr);
7964211d 11279}
51c1a580 11280
0329aba1 11281static bool bnx2x_get_dropless_info(struct bnx2x *bp)
7964211d
YM
11282{
11283 int tmp;
11284 u32 cfg;
51c1a580 11285
aeeddb8b
YM
11286 if (IS_VF(bp))
11287 return 0;
11288
7964211d
YM
11289 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11290 /* Take function: tmp = func */
11291 tmp = BP_ABS_FUNC(bp);
11292 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11293 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11294 } else {
11295 /* Take port: tmp = port */
11296 tmp = BP_PORT(bp);
11297 cfg = SHMEM_RD(bp,
11298 dev_info.port_hw_config[tmp].generic_features);
11299 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11300 }
11301 return cfg;
34f80b04
EG
11302}
11303
0329aba1 11304static int bnx2x_get_hwinfo(struct bnx2x *bp)
34f80b04 11305{
0793f83f 11306 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 11307 int vn;
0793f83f 11308 u32 val = 0;
34f80b04 11309 int rc = 0;
a2fbb9ea 11310
34f80b04 11311 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 11312
6383c0b3
AE
11313 /*
11314 * initialize IGU parameters
11315 */
f2e0899f
DK
11316 if (CHIP_IS_E1x(bp)) {
11317 bp->common.int_block = INT_BLOCK_HC;
11318
11319 bp->igu_dsb_id = DEF_SB_IGU_ID;
11320 bp->igu_base_sb = 0;
f2e0899f
DK
11321 } else {
11322 bp->common.int_block = INT_BLOCK_IGU;
7a06a122 11323
16a5fd92 11324 /* do not allow device reset during IGU info processing */
7a06a122
DK
11325 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11326
f2e0899f 11327 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
11328
11329 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11330 int tout = 5000;
11331
11332 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11333
11334 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11335 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11336 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11337
11338 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11339 tout--;
0926d499 11340 usleep_range(1000, 2000);
619c5cb6
VZ
11341 }
11342
11343 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11344 dev_err(&bp->pdev->dev,
11345 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
11346 bnx2x_release_hw_lock(bp,
11347 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
11348 return -EPERM;
11349 }
11350 }
11351
f2e0899f 11352 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 11353 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
11354 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11355 } else
619c5cb6 11356 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 11357
9b341bb1 11358 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 11359 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
11360 if (rc)
11361 return rc;
f2e0899f 11362 }
619c5cb6
VZ
11363
11364 /*
11365 * set base FW non-default (fast path) status block id, this value is
11366 * used to initialize the fw_sb_id saved on the fp/queue structure to
11367 * determine the id used by the FW.
11368 */
11369 if (CHIP_IS_E1x(bp))
11370 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11371 else /*
11372 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11373 * the same queue are indicated on the same IGU SB). So we prefer
11374 * FW and IGU SBs to be the same value.
11375 */
11376 bp->base_fw_ndsb = bp->igu_base_sb;
11377
11378 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11379 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11380 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
11381
11382 /*
11383 * Initialize MF configuration
11384 */
523224a3 11385
fb3bff17
DK
11386 bp->mf_ov = 0;
11387 bp->mf_mode = 0;
3395a033 11388 vn = BP_VN(bp);
0793f83f 11389
f2e0899f 11390 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
11391 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11392 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11393 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11394
f2e0899f
DK
11395 if (SHMEM2_HAS(bp, mf_cfg_addr))
11396 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11397 else
11398 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
11399 offsetof(struct shmem_region, func_mb) +
11400 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
11401 /*
11402 * get mf configuration:
16a5fd92 11403 * 1. Existence of MF configuration
0793f83f
DK
11404 * 2. MAC address must be legal (check only upper bytes)
11405 * for Switch-Independent mode;
11406 * OVLAN must be legal for Switch-Dependent mode
11407 * 3. SF_MODE configures specific MF mode
11408 */
11409 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11410 /* get mf configuration */
11411 val = SHMEM_RD(bp,
11412 dev_info.shared_feature_config.config);
11413 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
11414
11415 switch (val) {
11416 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11417 val = MF_CFG_RD(bp, func_mf_config[func].
11418 mac_upper);
11419 /* check for legal mac (upper bytes)*/
11420 if (val != 0xffff) {
11421 bp->mf_mode = MULTI_FUNCTION_SI;
11422 bp->mf_config[vn] = MF_CFG_RD(bp,
11423 func_mf_config[func].config);
11424 } else
51c1a580 11425 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 11426 break;
a3348722
BW
11427 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11428 if ((!CHIP_IS_E1x(bp)) &&
11429 (MF_CFG_RD(bp, func_mf_config[func].
11430 mac_upper) != 0xffff) &&
11431 (SHMEM2_HAS(bp,
11432 afex_driver_support))) {
11433 bp->mf_mode = MULTI_FUNCTION_AFEX;
11434 bp->mf_config[vn] = MF_CFG_RD(bp,
11435 func_mf_config[func].config);
11436 } else {
11437 BNX2X_DEV_INFO("can not configure afex mode\n");
11438 }
11439 break;
0793f83f
DK
11440 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11441 /* get OV configuration */
11442 val = MF_CFG_RD(bp,
11443 func_mf_config[FUNC_0].e1hov_tag);
11444 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11445
11446 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11447 bp->mf_mode = MULTI_FUNCTION_SD;
11448 bp->mf_config[vn] = MF_CFG_RD(bp,
11449 func_mf_config[func].config);
11450 } else
754a2f52 11451 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f 11452 break;
3786b942
AE
11453 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11454 bp->mf_config[vn] = 0;
11455 break;
0793f83f
DK
11456 default:
11457 /* Unknown configuration: reset mf_config */
11458 bp->mf_config[vn] = 0;
51c1a580 11459 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
11460 }
11461 }
a2fbb9ea 11462
2691d51d 11463 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 11464 IS_MF(bp) ? "multi" : "single");
2691d51d 11465
0793f83f
DK
11466 switch (bp->mf_mode) {
11467 case MULTI_FUNCTION_SD:
11468 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11469 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 11470 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 11471 bp->mf_ov = val;
619c5cb6
VZ
11472 bp->path_has_ovlan = true;
11473
51c1a580
MS
11474 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11475 func, bp->mf_ov, bp->mf_ov);
2691d51d 11476 } else {
619c5cb6 11477 dev_err(&bp->pdev->dev,
51c1a580
MS
11478 "No valid MF OV for func %d, aborting\n",
11479 func);
619c5cb6 11480 return -EPERM;
34f80b04 11481 }
0793f83f 11482 break;
a3348722
BW
11483 case MULTI_FUNCTION_AFEX:
11484 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11485 break;
0793f83f 11486 case MULTI_FUNCTION_SI:
51c1a580
MS
11487 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11488 func);
0793f83f
DK
11489 break;
11490 default:
11491 if (vn) {
619c5cb6 11492 dev_err(&bp->pdev->dev,
51c1a580
MS
11493 "VN %d is in a single function mode, aborting\n",
11494 vn);
619c5cb6 11495 return -EPERM;
2691d51d 11496 }
0793f83f 11497 break;
34f80b04 11498 }
0793f83f 11499
619c5cb6
VZ
11500 /* check if other port on the path needs ovlan:
11501 * Since MF configuration is shared between ports
11502 * Possible mixed modes are only
11503 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11504 */
11505 if (CHIP_MODE_IS_4_PORT(bp) &&
11506 !bp->path_has_ovlan &&
11507 !IS_MF(bp) &&
11508 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11509 u8 other_port = !BP_PORT(bp);
11510 u8 other_func = BP_PATH(bp) + 2*other_port;
11511 val = MF_CFG_RD(bp,
11512 func_mf_config[other_func].e1hov_tag);
11513 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11514 bp->path_has_ovlan = true;
11515 }
34f80b04 11516 }
a2fbb9ea 11517
f2e0899f
DK
11518 /* adjust igu_sb_cnt to MF for E1x */
11519 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
11520 bp->igu_sb_cnt /= E1HVN_MAX;
11521
619c5cb6
VZ
11522 /* port info */
11523 bnx2x_get_port_hwinfo(bp);
f2e0899f 11524
0793f83f
DK
11525 /* Get MAC addresses */
11526 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 11527
2ba45142 11528 bnx2x_get_cnic_info(bp);
2ba45142 11529
34f80b04
EG
11530 return rc;
11531}
11532
0329aba1 11533static void bnx2x_read_fwinfo(struct bnx2x *bp)
34f24c7f
VZ
11534{
11535 int cnt, i, block_end, rodi;
fcdf95cb 11536 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
11537 char str_id_reg[VENDOR_ID_LEN+1];
11538 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
11539 char *vpd_data;
11540 char *vpd_extended_data = NULL;
34f24c7f
VZ
11541 u8 len;
11542
fcdf95cb 11543 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
11544 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11545
11546 if (cnt < BNX2X_VPD_LEN)
11547 goto out_not_found;
11548
fcdf95cb
BW
11549 /* VPD RO tag should be first tag after identifier string, hence
11550 * we should be able to find it in first BNX2X_VPD_LEN chars
11551 */
11552 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
11553 PCI_VPD_LRDT_RO_DATA);
11554 if (i < 0)
11555 goto out_not_found;
11556
34f24c7f 11557 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 11558 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
11559
11560 i += PCI_VPD_LRDT_TAG_SIZE;
11561
fcdf95cb
BW
11562 if (block_end > BNX2X_VPD_LEN) {
11563 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11564 if (vpd_extended_data == NULL)
11565 goto out_not_found;
11566
11567 /* read rest of vpd image into vpd_extended_data */
11568 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11569 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11570 block_end - BNX2X_VPD_LEN,
11571 vpd_extended_data + BNX2X_VPD_LEN);
11572 if (cnt < (block_end - BNX2X_VPD_LEN))
11573 goto out_not_found;
11574 vpd_data = vpd_extended_data;
11575 } else
11576 vpd_data = vpd_start;
11577
11578 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
11579
11580 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11581 PCI_VPD_RO_KEYWORD_MFR_ID);
11582 if (rodi < 0)
11583 goto out_not_found;
11584
11585 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11586
11587 if (len != VENDOR_ID_LEN)
11588 goto out_not_found;
11589
11590 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11591
11592 /* vendor specific info */
11593 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11594 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11595 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11596 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11597
11598 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11599 PCI_VPD_RO_KEYWORD_VENDOR0);
11600 if (rodi >= 0) {
11601 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11602
11603 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11604
11605 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11606 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11607 bp->fw_ver[len] = ' ';
11608 }
11609 }
fcdf95cb 11610 kfree(vpd_extended_data);
34f24c7f
VZ
11611 return;
11612 }
11613out_not_found:
fcdf95cb 11614 kfree(vpd_extended_data);
34f24c7f
VZ
11615 return;
11616}
11617
0329aba1 11618static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
619c5cb6
VZ
11619{
11620 u32 flags = 0;
11621
11622 if (CHIP_REV_IS_FPGA(bp))
11623 SET_FLAGS(flags, MODE_FPGA);
11624 else if (CHIP_REV_IS_EMUL(bp))
11625 SET_FLAGS(flags, MODE_EMUL);
11626 else
11627 SET_FLAGS(flags, MODE_ASIC);
11628
11629 if (CHIP_MODE_IS_4_PORT(bp))
11630 SET_FLAGS(flags, MODE_PORT4);
11631 else
11632 SET_FLAGS(flags, MODE_PORT2);
11633
11634 if (CHIP_IS_E2(bp))
11635 SET_FLAGS(flags, MODE_E2);
11636 else if (CHIP_IS_E3(bp)) {
11637 SET_FLAGS(flags, MODE_E3);
11638 if (CHIP_REV(bp) == CHIP_REV_Ax)
11639 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11640 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11641 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11642 }
11643
11644 if (IS_MF(bp)) {
11645 SET_FLAGS(flags, MODE_MF);
11646 switch (bp->mf_mode) {
11647 case MULTI_FUNCTION_SD:
11648 SET_FLAGS(flags, MODE_MF_SD);
11649 break;
11650 case MULTI_FUNCTION_SI:
11651 SET_FLAGS(flags, MODE_MF_SI);
11652 break;
a3348722
BW
11653 case MULTI_FUNCTION_AFEX:
11654 SET_FLAGS(flags, MODE_MF_AFEX);
11655 break;
619c5cb6
VZ
11656 }
11657 } else
11658 SET_FLAGS(flags, MODE_SF);
11659
11660#if defined(__LITTLE_ENDIAN)
11661 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11662#else /*(__BIG_ENDIAN)*/
11663 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11664#endif
11665 INIT_MODE_FLAGS(bp) = flags;
11666}
11667
0329aba1 11668static int bnx2x_init_bp(struct bnx2x *bp)
34f80b04 11669{
f2e0899f 11670 int func;
34f80b04
EG
11671 int rc;
11672
34f80b04 11673 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11674 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11675 spin_lock_init(&bp->stats_lock);
507393eb 11676 sema_init(&bp->stats_sema, 1);
55c11941 11677
1cf167f2 11678 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11679 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11680 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
1ab4434c
AE
11681 if (IS_PF(bp)) {
11682 rc = bnx2x_get_hwinfo(bp);
11683 if (rc)
11684 return rc;
11685 } else {
e09b74d0 11686 eth_zero_addr(bp->dev->dev_addr);
1ab4434c 11687 }
34f80b04 11688
619c5cb6
VZ
11689 bnx2x_set_modes_bitmap(bp);
11690
11691 rc = bnx2x_alloc_mem_bp(bp);
11692 if (rc)
11693 return rc;
523224a3 11694
34f24c7f 11695 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11696
11697 func = BP_FUNC(bp);
11698
34f80b04 11699 /* need to reset chip if undi was active */
1ab4434c 11700 if (IS_PF(bp) && !BP_NOMCP(bp)) {
452427b0
YM
11701 /* init fw_seq */
11702 bp->fw_seq =
11703 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11704 DRV_MSG_SEQ_NUMBER_MASK;
11705 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11706
91ebb929
YM
11707 rc = bnx2x_prev_unload(bp);
11708 if (rc) {
11709 bnx2x_free_mem_bp(bp);
11710 return rc;
11711 }
452427b0
YM
11712 }
11713
34f80b04 11714 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11715 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11716
11717 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11718 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11719
614c76df 11720 bp->disable_tpa = disable_tpa;
a3348722 11721 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11722
7a9b2557 11723 /* Set TPA flags */
614c76df 11724 if (bp->disable_tpa) {
621b4d66 11725 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11726 bp->dev->features &= ~NETIF_F_LRO;
11727 } else {
621b4d66 11728 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11729 bp->dev->features |= NETIF_F_LRO;
11730 }
11731
a18f5128
EG
11732 if (CHIP_IS_E1(bp))
11733 bp->dropless_fc = 0;
11734 else
7964211d 11735 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11736
8d5726c4 11737 bp->mrrs = mrrs;
7a9b2557 11738
a3348722 11739 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1ab4434c
AE
11740 if (IS_VF(bp))
11741 bp->rx_ring_size = MAX_RX_AVAIL;
34f80b04 11742
7d323bfd 11743 /* make sure that the numbers are in the right granularity */
523224a3
DK
11744 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11745 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11746
fc543637 11747 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11748
11749 init_timer(&bp->timer);
11750 bp->timer.expires = jiffies + bp->current_interval;
11751 bp->timer.data = (unsigned long) bp;
11752 bp->timer.function = bnx2x_timer;
11753
0370cf90
BW
11754 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11755 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11756 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11757 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11758 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11759 bnx2x_dcbx_init_params(bp);
11760 } else {
11761 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11762 }
e4901dde 11763
619c5cb6
VZ
11764 if (CHIP_IS_E1x(bp))
11765 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11766 else
11767 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11768
6383c0b3 11769 /* multiple tx priority */
1ab4434c
AE
11770 if (IS_VF(bp))
11771 bp->max_cos = 1;
11772 else if (CHIP_IS_E1x(bp))
6383c0b3 11773 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
1ab4434c 11774 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
6383c0b3 11775 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
1ab4434c 11776 else if (CHIP_IS_E3B0(bp))
6383c0b3 11777 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
1ab4434c
AE
11778 else
11779 BNX2X_ERR("unknown chip %x revision %x\n",
11780 CHIP_NUM(bp), CHIP_REV(bp));
11781 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
6383c0b3 11782
55c11941
MS
11783 /* We need at least one default status block for slow-path events,
11784 * second status block for the L2 queue, and a third status block for
16a5fd92 11785 * CNIC if supported.
55c11941 11786 */
60cad4e6
AE
11787 if (IS_VF(bp))
11788 bp->min_msix_vec_cnt = 1;
11789 else if (CNIC_SUPPORT(bp))
55c11941 11790 bp->min_msix_vec_cnt = 3;
60cad4e6 11791 else /* PF w/o cnic */
55c11941
MS
11792 bp->min_msix_vec_cnt = 2;
11793 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11794
5bb680d6
MS
11795 bp->dump_preset_idx = 1;
11796
34f80b04 11797 return rc;
a2fbb9ea
ET
11798}
11799
de0c62db
DK
11800/****************************************************************************
11801* General service functions
11802****************************************************************************/
a2fbb9ea 11803
619c5cb6
VZ
11804/*
11805 * net_device service functions
11806 */
11807
bb2a0f7a 11808/* called with rtnl_lock */
a2fbb9ea
ET
11809static int bnx2x_open(struct net_device *dev)
11810{
11811 struct bnx2x *bp = netdev_priv(dev);
8395be5e 11812 int rc;
a2fbb9ea 11813
1355b704
MY
11814 bp->stats_init = true;
11815
6eccabb3
EG
11816 netif_carrier_off(dev);
11817
a2fbb9ea
ET
11818 bnx2x_set_power_state(bp, PCI_D0);
11819
ad5afc89 11820 /* If parity had happen during the unload, then attentions
c9ee9206
VZ
11821 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11822 * want the first function loaded on the current engine to
11823 * complete the recovery.
ad5afc89 11824 * Parity recovery is only relevant for PF driver.
c9ee9206 11825 */
ad5afc89 11826 if (IS_PF(bp)) {
1a6974b2
YM
11827 int other_engine = BP_PATH(bp) ? 0 : 1;
11828 bool other_load_status, load_status;
11829 bool global = false;
11830
ad5afc89
AE
11831 other_load_status = bnx2x_get_load_status(bp, other_engine);
11832 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11833 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11834 bnx2x_chk_parity_attn(bp, &global, true)) {
11835 do {
11836 /* If there are attentions and they are in a
11837 * global blocks, set the GLOBAL_RESET bit
11838 * regardless whether it will be this function
11839 * that will complete the recovery or not.
11840 */
11841 if (global)
11842 bnx2x_set_reset_global(bp);
72fd0718 11843
ad5afc89
AE
11844 /* Only the first function on the current
11845 * engine should try to recover in open. In case
11846 * of attentions in global blocks only the first
11847 * in the chip should try to recover.
11848 */
11849 if ((!load_status &&
11850 (!global || !other_load_status)) &&
11851 bnx2x_trylock_leader_lock(bp) &&
11852 !bnx2x_leader_reset(bp)) {
11853 netdev_info(bp->dev,
11854 "Recovered in open\n");
11855 break;
11856 }
72fd0718 11857
ad5afc89
AE
11858 /* recovery has failed... */
11859 bnx2x_set_power_state(bp, PCI_D3hot);
11860 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11861
ad5afc89
AE
11862 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11863 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718 11864
ad5afc89
AE
11865 return -EAGAIN;
11866 } while (0);
11867 }
11868 }
72fd0718
VZ
11869
11870 bp->recovery_state = BNX2X_RECOVERY_DONE;
8395be5e
AE
11871 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11872 if (rc)
11873 return rc;
9a8130bc 11874 return 0;
a2fbb9ea
ET
11875}
11876
bb2a0f7a 11877/* called with rtnl_lock */
56ad3152 11878static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11879{
a2fbb9ea
ET
11880 struct bnx2x *bp = netdev_priv(dev);
11881
11882 /* Unload the driver, release IRQs */
5d07d868 11883 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206 11884
a2fbb9ea
ET
11885 return 0;
11886}
11887
1191cb83
ED
11888static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11889 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11890{
619c5cb6
VZ
11891 int mc_count = netdev_mc_count(bp->dev);
11892 struct bnx2x_mcast_list_elem *mc_mac =
11893 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11894 struct netdev_hw_addr *ha;
6e30dd4e 11895
619c5cb6
VZ
11896 if (!mc_mac)
11897 return -ENOMEM;
6e30dd4e 11898
619c5cb6 11899 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11900
619c5cb6
VZ
11901 netdev_for_each_mc_addr(ha, bp->dev) {
11902 mc_mac->mac = bnx2x_mc_addr(ha);
11903 list_add_tail(&mc_mac->link, &p->mcast_list);
11904 mc_mac++;
6e30dd4e 11905 }
619c5cb6
VZ
11906
11907 p->mcast_list_len = mc_count;
11908
11909 return 0;
6e30dd4e
VZ
11910}
11911
1191cb83 11912static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11913 struct bnx2x_mcast_ramrod_params *p)
11914{
11915 struct bnx2x_mcast_list_elem *mc_mac =
11916 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11917 link);
11918
11919 WARN_ON(!mc_mac);
11920 kfree(mc_mac);
11921}
11922
11923/**
11924 * bnx2x_set_uc_list - configure a new unicast MACs list.
11925 *
11926 * @bp: driver handle
6e30dd4e 11927 *
619c5cb6 11928 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11929 */
1191cb83 11930static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11931{
619c5cb6 11932 int rc;
6e30dd4e 11933 struct net_device *dev = bp->dev;
6e30dd4e 11934 struct netdev_hw_addr *ha;
15192a8c 11935 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11936 unsigned long ramrod_flags = 0;
6e30dd4e 11937
619c5cb6
VZ
11938 /* First schedule a cleanup up of old configuration */
11939 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11940 if (rc < 0) {
11941 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11942 return rc;
11943 }
6e30dd4e
VZ
11944
11945 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11946 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11947 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11948 if (rc == -EEXIST) {
11949 DP(BNX2X_MSG_SP,
11950 "Failed to schedule ADD operations: %d\n", rc);
11951 /* do not treat adding same MAC as error */
11952 rc = 0;
11953
11954 } else if (rc < 0) {
11955
619c5cb6
VZ
11956 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11957 rc);
11958 return rc;
6e30dd4e
VZ
11959 }
11960 }
11961
619c5cb6
VZ
11962 /* Execute the pending commands */
11963 __set_bit(RAMROD_CONT, &ramrod_flags);
11964 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11965 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11966}
11967
1191cb83 11968static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11969{
619c5cb6 11970 struct net_device *dev = bp->dev;
3b603066 11971 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11972 int rc = 0;
6e30dd4e 11973
619c5cb6 11974 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11975
619c5cb6
VZ
11976 /* first, clear all configured multicast MACs */
11977 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11978 if (rc < 0) {
51c1a580 11979 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11980 return rc;
11981 }
6e30dd4e 11982
619c5cb6
VZ
11983 /* then, configure a new MACs list */
11984 if (netdev_mc_count(dev)) {
11985 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11986 if (rc) {
51c1a580
MS
11987 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11988 rc);
619c5cb6
VZ
11989 return rc;
11990 }
6e30dd4e 11991
619c5cb6
VZ
11992 /* Now add the new MACs */
11993 rc = bnx2x_config_mcast(bp, &rparam,
11994 BNX2X_MCAST_CMD_ADD);
11995 if (rc < 0)
51c1a580
MS
11996 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11997 rc);
6e30dd4e 11998
619c5cb6
VZ
11999 bnx2x_free_mcast_macs_list(&rparam);
12000 }
6e30dd4e 12001
619c5cb6 12002 return rc;
6e30dd4e
VZ
12003}
12004
619c5cb6 12005/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 12006void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
12007{
12008 struct bnx2x *bp = netdev_priv(dev);
34f80b04
EG
12009
12010 if (bp->state != BNX2X_STATE_OPEN) {
12011 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
12012 return;
8b09be5f
YM
12013 } else {
12014 /* Schedule an SP task to handle rest of change */
12015 DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
12016 smp_mb__before_clear_bit();
12017 set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
12018 smp_mb__after_clear_bit();
12019 schedule_delayed_work(&bp->sp_rtnl_task, 0);
34f80b04 12020 }
8b09be5f
YM
12021}
12022
12023void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
12024{
12025 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04 12026
619c5cb6 12027 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04 12028
8b09be5f
YM
12029 netif_addr_lock_bh(bp->dev);
12030
12031 if (bp->dev->flags & IFF_PROMISC) {
34f80b04 12032 rx_mode = BNX2X_RX_MODE_PROMISC;
8b09be5f
YM
12033 } else if ((bp->dev->flags & IFF_ALLMULTI) ||
12034 ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
12035 CHIP_IS_E1(bp))) {
34f80b04 12036 rx_mode = BNX2X_RX_MODE_ALLMULTI;
8b09be5f 12037 } else {
381ac16b
AE
12038 if (IS_PF(bp)) {
12039 /* some multicasts */
12040 if (bnx2x_set_mc_list(bp) < 0)
12041 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 12042
8b09be5f
YM
12043 /* release bh lock, as bnx2x_set_uc_list might sleep */
12044 netif_addr_unlock_bh(bp->dev);
381ac16b
AE
12045 if (bnx2x_set_uc_list(bp) < 0)
12046 rx_mode = BNX2X_RX_MODE_PROMISC;
8b09be5f 12047 netif_addr_lock_bh(bp->dev);
381ac16b
AE
12048 } else {
12049 /* configuring mcast to a vf involves sleeping (when we
8b09be5f 12050 * wait for the pf's response).
381ac16b
AE
12051 */
12052 smp_mb__before_clear_bit();
12053 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
12054 &bp->sp_rtnl_state);
12055 smp_mb__after_clear_bit();
12056 schedule_delayed_work(&bp->sp_rtnl_task, 0);
12057 }
34f80b04
EG
12058 }
12059
12060 bp->rx_mode = rx_mode;
614c76df
DK
12061 /* handle ISCSI SD mode */
12062 if (IS_MF_ISCSI_SD(bp))
12063 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
12064
12065 /* Schedule the rx_mode command */
12066 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
12067 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8b09be5f 12068 netif_addr_unlock_bh(bp->dev);
619c5cb6
VZ
12069 return;
12070 }
12071
381ac16b
AE
12072 if (IS_PF(bp)) {
12073 bnx2x_set_storm_rx_mode(bp);
8b09be5f 12074 netif_addr_unlock_bh(bp->dev);
381ac16b 12075 } else {
8b09be5f
YM
12076 /* VF will need to request the PF to make this change, and so
12077 * the VF needs to release the bottom-half lock prior to the
12078 * request (as it will likely require sleep on the VF side)
381ac16b 12079 */
8b09be5f
YM
12080 netif_addr_unlock_bh(bp->dev);
12081 bnx2x_vfpf_storm_rx_mode(bp);
381ac16b 12082 }
34f80b04
EG
12083}
12084
c18487ee 12085/* called with rtnl_lock */
01cd4528
EG
12086static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
12087 int devad, u16 addr)
a2fbb9ea 12088{
01cd4528
EG
12089 struct bnx2x *bp = netdev_priv(netdev);
12090 u16 value;
12091 int rc;
a2fbb9ea 12092
01cd4528
EG
12093 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
12094 prtad, devad, addr);
a2fbb9ea 12095
01cd4528
EG
12096 /* The HW expects different devad if CL22 is used */
12097 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 12098
01cd4528 12099 bnx2x_acquire_phy_lock(bp);
e10bc84d 12100 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
12101 bnx2x_release_phy_lock(bp);
12102 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 12103
01cd4528
EG
12104 if (!rc)
12105 rc = value;
12106 return rc;
12107}
a2fbb9ea 12108
01cd4528
EG
12109/* called with rtnl_lock */
12110static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
12111 u16 addr, u16 value)
12112{
12113 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
12114 int rc;
12115
51c1a580
MS
12116 DP(NETIF_MSG_LINK,
12117 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
12118 prtad, devad, addr, value);
01cd4528 12119
01cd4528
EG
12120 /* The HW expects different devad if CL22 is used */
12121 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 12122
01cd4528 12123 bnx2x_acquire_phy_lock(bp);
e10bc84d 12124 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
12125 bnx2x_release_phy_lock(bp);
12126 return rc;
12127}
c18487ee 12128
01cd4528
EG
12129/* called with rtnl_lock */
12130static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
12131{
12132 struct bnx2x *bp = netdev_priv(dev);
12133 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 12134
01cd4528
EG
12135 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
12136 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 12137
01cd4528
EG
12138 if (!netif_running(dev))
12139 return -EAGAIN;
12140
12141 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
12142}
12143
257ddbda 12144#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
12145static void poll_bnx2x(struct net_device *dev)
12146{
12147 struct bnx2x *bp = netdev_priv(dev);
14a15d61 12148 int i;
a2fbb9ea 12149
14a15d61
MS
12150 for_each_eth_queue(bp, i) {
12151 struct bnx2x_fastpath *fp = &bp->fp[i];
12152 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
12153 }
a2fbb9ea
ET
12154}
12155#endif
12156
614c76df
DK
12157static int bnx2x_validate_addr(struct net_device *dev)
12158{
12159 struct bnx2x *bp = netdev_priv(dev);
12160
e09b74d0
AE
12161 /* query the bulletin board for mac address configured by the PF */
12162 if (IS_VF(bp))
12163 bnx2x_sample_bulletin(bp);
12164
51c1a580
MS
12165 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
12166 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 12167 return -EADDRNOTAVAIL;
51c1a580 12168 }
614c76df
DK
12169 return 0;
12170}
12171
3d7d562c
YM
12172static int bnx2x_get_phys_port_id(struct net_device *netdev,
12173 struct netdev_phys_port_id *ppid)
12174{
12175 struct bnx2x *bp = netdev_priv(netdev);
12176
12177 if (!(bp->flags & HAS_PHYS_PORT_ID))
12178 return -EOPNOTSUPP;
12179
12180 ppid->id_len = sizeof(bp->phys_port_id);
12181 memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
12182
12183 return 0;
12184}
12185
c64213cd
SH
12186static const struct net_device_ops bnx2x_netdev_ops = {
12187 .ndo_open = bnx2x_open,
12188 .ndo_stop = bnx2x_close,
12189 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 12190 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 12191 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 12192 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 12193 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
12194 .ndo_do_ioctl = bnx2x_ioctl,
12195 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
12196 .ndo_fix_features = bnx2x_fix_features,
12197 .ndo_set_features = bnx2x_set_features,
c64213cd 12198 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 12199#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
12200 .ndo_poll_controller = poll_bnx2x,
12201#endif
6383c0b3 12202 .ndo_setup_tc = bnx2x_setup_tc,
6411280a 12203#ifdef CONFIG_BNX2X_SRIOV
abc5a021 12204 .ndo_set_vf_mac = bnx2x_set_vf_mac,
3cdeec22 12205 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
3ec9f9ca 12206 .ndo_get_vf_config = bnx2x_get_vf_config,
6411280a 12207#endif
55c11941 12208#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
12209 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
12210#endif
8f20aa57 12211
e0d1095a 12212#ifdef CONFIG_NET_RX_BUSY_POLL
8b80cda5 12213 .ndo_busy_poll = bnx2x_low_latency_recv,
8f20aa57 12214#endif
3d7d562c 12215 .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
c64213cd
SH
12216};
12217
1191cb83 12218static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
12219{
12220 struct device *dev = &bp->pdev->dev;
12221
8ceafbfa
LT
12222 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
12223 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
619c5cb6
VZ
12224 dev_err(dev, "System does not support DMA, aborting\n");
12225 return -EIO;
12226 }
12227
12228 return 0;
12229}
12230
33d8e6a5
YM
12231static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
12232{
12233 if (bp->flags & AER_ENABLED) {
12234 pci_disable_pcie_error_reporting(bp->pdev);
12235 bp->flags &= ~AER_ENABLED;
12236 }
12237}
12238
1ab4434c
AE
12239static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12240 struct net_device *dev, unsigned long board_type)
a2fbb9ea 12241{
a2fbb9ea 12242 int rc;
c22610d0 12243 u32 pci_cfg_dword;
65087cfe
AE
12244 bool chip_is_e1x = (board_type == BCM57710 ||
12245 board_type == BCM57711 ||
12246 board_type == BCM57711E);
a2fbb9ea
ET
12247
12248 SET_NETDEV_DEV(dev, &pdev->dev);
a2fbb9ea 12249
34f80b04
EG
12250 bp->dev = dev;
12251 bp->pdev = pdev;
a2fbb9ea
ET
12252
12253 rc = pci_enable_device(pdev);
12254 if (rc) {
cdaa7cb8
VZ
12255 dev_err(&bp->pdev->dev,
12256 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
12257 goto err_out;
12258 }
12259
12260 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
12261 dev_err(&bp->pdev->dev,
12262 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
12263 rc = -ENODEV;
12264 goto err_out_disable;
12265 }
12266
1ab4434c
AE
12267 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
12268 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
a2fbb9ea
ET
12269 rc = -ENODEV;
12270 goto err_out_disable;
12271 }
12272
092a5fc9
YR
12273 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
12274 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
12275 PCICFG_REVESION_ID_ERROR_VAL) {
12276 pr_err("PCI device error, probably due to fan failure, aborting\n");
12277 rc = -ENODEV;
12278 goto err_out_disable;
12279 }
12280
34f80b04
EG
12281 if (atomic_read(&pdev->enable_cnt) == 1) {
12282 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
12283 if (rc) {
cdaa7cb8
VZ
12284 dev_err(&bp->pdev->dev,
12285 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
12286 goto err_out_disable;
12287 }
a2fbb9ea 12288
34f80b04
EG
12289 pci_set_master(pdev);
12290 pci_save_state(pdev);
12291 }
a2fbb9ea 12292
1ab4434c 12293 if (IS_PF(bp)) {
29ed74c3 12294 if (!pdev->pm_cap) {
1ab4434c
AE
12295 dev_err(&bp->pdev->dev,
12296 "Cannot find power management capability, aborting\n");
12297 rc = -EIO;
12298 goto err_out_release;
12299 }
a2fbb9ea
ET
12300 }
12301
77c98e6a 12302 if (!pci_is_pcie(pdev)) {
51c1a580 12303 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
12304 rc = -EIO;
12305 goto err_out_release;
12306 }
12307
619c5cb6
VZ
12308 rc = bnx2x_set_coherency_mask(bp);
12309 if (rc)
a2fbb9ea 12310 goto err_out_release;
a2fbb9ea 12311
34f80b04
EG
12312 dev->mem_start = pci_resource_start(pdev, 0);
12313 dev->base_addr = dev->mem_start;
12314 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
12315
12316 dev->irq = pdev->irq;
12317
275f165f 12318 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 12319 if (!bp->regview) {
cdaa7cb8
VZ
12320 dev_err(&bp->pdev->dev,
12321 "Cannot map register space, aborting\n");
a2fbb9ea
ET
12322 rc = -ENOMEM;
12323 goto err_out_release;
12324 }
12325
c22610d0
AE
12326 /* In E1/E1H use pci device function given by kernel.
12327 * In E2/E3 read physical function from ME register since these chips
12328 * support Physical Device Assignment where kernel BDF maybe arbitrary
12329 * (depending on hypervisor).
12330 */
2de67439 12331 if (chip_is_e1x) {
c22610d0 12332 bp->pf_num = PCI_FUNC(pdev->devfn);
2de67439
YM
12333 } else {
12334 /* chip is E2/3*/
c22610d0
AE
12335 pci_read_config_dword(bp->pdev,
12336 PCICFG_ME_REGISTER, &pci_cfg_dword);
12337 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
2de67439 12338 ME_REG_ABS_PF_NUM_SHIFT);
c22610d0 12339 }
51c1a580 12340 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 12341
34f80b04
EG
12342 /* clean indirect addresses */
12343 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12344 PCICFG_VENDOR_ID_OFFSET);
33d8e6a5
YM
12345
12346 /* AER (Advanced Error reporting) configuration */
12347 rc = pci_enable_pcie_error_reporting(pdev);
12348 if (!rc)
12349 bp->flags |= AER_ENABLED;
12350 else
12351 BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
12352
a5c53dbc
DK
12353 /*
12354 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
12355 * is not used by the driver.
12356 */
1ab4434c
AE
12357 if (IS_PF(bp)) {
12358 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12359 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12360 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12361 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
12362
12363 if (chip_is_e1x) {
12364 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12365 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12366 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12367 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12368 }
a5c53dbc 12369
1ab4434c
AE
12370 /* Enable internal target-read (in case we are probed after PF
12371 * FLR). Must be done prior to any BAR read access. Only for
12372 * 57712 and up
12373 */
12374 if (!chip_is_e1x)
12375 REG_WR(bp,
12376 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
a5c53dbc 12377 }
a2fbb9ea 12378
34f80b04 12379 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 12380
c64213cd 12381 dev->netdev_ops = &bnx2x_netdev_ops;
005a07ba 12382 bnx2x_set_ethtool_ops(bp, dev);
5316bc0b 12383
01789349
JP
12384 dev->priv_flags |= IFF_UNICAST_FLT;
12385
66371c44 12386 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
12387 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12388 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
f646968f 12389 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
a848ade4 12390 if (!CHIP_IS_E1x(bp)) {
117401ee 12391 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
2e3bd6a4 12392 NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
a848ade4
DK
12393 dev->hw_enc_features =
12394 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12395 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
117401ee 12396 NETIF_F_GSO_IPIP |
2e3bd6a4 12397 NETIF_F_GSO_SIT |
65bc0cfe 12398 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
a848ade4 12399 }
66371c44
MM
12400
12401 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12402 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12403
f646968f 12404 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
edd31476 12405 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 12406
538dd2e3
MB
12407 /* Add Loopback capability to the device */
12408 dev->hw_features |= NETIF_F_LOOPBACK;
12409
98507672 12410#ifdef BCM_DCBNL
785b9b1a
SR
12411 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12412#endif
12413
01cd4528
EG
12414 /* get_port_hwinfo() will set prtad and mmds properly */
12415 bp->mdio.prtad = MDIO_PRTAD_NONE;
12416 bp->mdio.mmds = 0;
12417 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12418 bp->mdio.dev = dev;
12419 bp->mdio.mdio_read = bnx2x_mdio_read;
12420 bp->mdio.mdio_write = bnx2x_mdio_write;
12421
a2fbb9ea
ET
12422 return 0;
12423
a2fbb9ea 12424err_out_release:
34f80b04
EG
12425 if (atomic_read(&pdev->enable_cnt) == 1)
12426 pci_release_regions(pdev);
a2fbb9ea
ET
12427
12428err_out_disable:
12429 pci_disable_device(pdev);
a2fbb9ea
ET
12430
12431err_out:
12432 return rc;
12433}
12434
6891dd25 12435static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 12436{
37f9ce62 12437 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
12438 struct bnx2x_fw_file_hdr *fw_hdr;
12439 struct bnx2x_fw_file_section *sections;
94a78b79 12440 u32 offset, len, num_ops;
86564c3f 12441 __be16 *ops_offsets;
94a78b79 12442 int i;
37f9ce62 12443 const u8 *fw_ver;
94a78b79 12444
51c1a580
MS
12445 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12446 BNX2X_ERR("Wrong FW size\n");
94a78b79 12447 return -EINVAL;
51c1a580 12448 }
94a78b79
VZ
12449
12450 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12451 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12452
12453 /* Make sure none of the offsets and sizes make us read beyond
12454 * the end of the firmware data */
12455 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12456 offset = be32_to_cpu(sections[i].offset);
12457 len = be32_to_cpu(sections[i].len);
12458 if (offset + len > firmware->size) {
51c1a580 12459 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
12460 return -EINVAL;
12461 }
12462 }
12463
12464 /* Likewise for the init_ops offsets */
12465 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
86564c3f 12466 ops_offsets = (__force __be16 *)(firmware->data + offset);
94a78b79
VZ
12467 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12468
12469 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12470 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 12471 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
12472 return -EINVAL;
12473 }
12474 }
12475
12476 /* Check FW version */
12477 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12478 fw_ver = firmware->data + offset;
12479 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12480 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12481 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12482 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
12483 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12484 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12485 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
12486 BCM_5710_FW_MINOR_VERSION,
12487 BCM_5710_FW_REVISION_VERSION,
12488 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 12489 return -EINVAL;
94a78b79
VZ
12490 }
12491
12492 return 0;
12493}
12494
1191cb83 12495static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12496{
ab6ad5a4
EG
12497 const __be32 *source = (const __be32 *)_source;
12498 u32 *target = (u32 *)_target;
94a78b79 12499 u32 i;
94a78b79
VZ
12500
12501 for (i = 0; i < n/4; i++)
12502 target[i] = be32_to_cpu(source[i]);
12503}
12504
12505/*
12506 Ops array is stored in the following format:
12507 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12508 */
1191cb83 12509static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 12510{
ab6ad5a4
EG
12511 const __be32 *source = (const __be32 *)_source;
12512 struct raw_op *target = (struct raw_op *)_target;
94a78b79 12513 u32 i, j, tmp;
94a78b79 12514
ab6ad5a4 12515 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
12516 tmp = be32_to_cpu(source[j]);
12517 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
12518 target[i].offset = tmp & 0xffffff;
12519 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
12520 }
12521}
ab6ad5a4 12522
1aa8b471 12523/* IRO array is stored in the following format:
523224a3
DK
12524 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12525 */
1191cb83 12526static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
12527{
12528 const __be32 *source = (const __be32 *)_source;
12529 struct iro *target = (struct iro *)_target;
12530 u32 i, j, tmp;
12531
12532 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12533 target[i].base = be32_to_cpu(source[j]);
12534 j++;
12535 tmp = be32_to_cpu(source[j]);
12536 target[i].m1 = (tmp >> 16) & 0xffff;
12537 target[i].m2 = tmp & 0xffff;
12538 j++;
12539 tmp = be32_to_cpu(source[j]);
12540 target[i].m3 = (tmp >> 16) & 0xffff;
12541 target[i].size = tmp & 0xffff;
12542 j++;
12543 }
12544}
12545
1191cb83 12546static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12547{
ab6ad5a4
EG
12548 const __be16 *source = (const __be16 *)_source;
12549 u16 *target = (u16 *)_target;
94a78b79 12550 u32 i;
94a78b79
VZ
12551
12552 for (i = 0; i < n/2; i++)
12553 target[i] = be16_to_cpu(source[i]);
12554}
12555
7995c64e
JP
12556#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12557do { \
12558 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12559 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 12560 if (!bp->arr) \
7995c64e 12561 goto lbl; \
7995c64e
JP
12562 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12563 (u8 *)bp->arr, len); \
12564} while (0)
94a78b79 12565
3b603066 12566static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 12567{
c0ea452e 12568 const char *fw_file_name;
94a78b79 12569 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 12570 int rc;
94a78b79 12571
c0ea452e
MS
12572 if (bp->firmware)
12573 return 0;
94a78b79 12574
c0ea452e
MS
12575 if (CHIP_IS_E1(bp))
12576 fw_file_name = FW_FILE_NAME_E1;
12577 else if (CHIP_IS_E1H(bp))
12578 fw_file_name = FW_FILE_NAME_E1H;
12579 else if (!CHIP_IS_E1x(bp))
12580 fw_file_name = FW_FILE_NAME_E2;
12581 else {
12582 BNX2X_ERR("Unsupported chip revision\n");
12583 return -EINVAL;
12584 }
12585 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 12586
c0ea452e
MS
12587 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12588 if (rc) {
12589 BNX2X_ERR("Can't load firmware file %s\n",
12590 fw_file_name);
12591 goto request_firmware_exit;
12592 }
eb2afd4a 12593
c0ea452e
MS
12594 rc = bnx2x_check_firmware(bp);
12595 if (rc) {
12596 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12597 goto request_firmware_exit;
94a78b79
VZ
12598 }
12599
12600 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12601
12602 /* Initialize the pointers to the init arrays */
12603 /* Blob */
12604 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12605
12606 /* Opcodes */
12607 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12608
12609 /* Offsets */
ab6ad5a4
EG
12610 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12611 be16_to_cpu_n);
94a78b79
VZ
12612
12613 /* STORMs firmware */
573f2035
EG
12614 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12615 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12616 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12617 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12618 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12619 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12620 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12621 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12622 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12623 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12624 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12625 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12626 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12627 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12628 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12629 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
12630 /* IRO */
12631 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
12632
12633 return 0;
ab6ad5a4 12634
523224a3
DK
12635iro_alloc_err:
12636 kfree(bp->init_ops_offsets);
94a78b79
VZ
12637init_offsets_alloc_err:
12638 kfree(bp->init_ops);
12639init_ops_alloc_err:
12640 kfree(bp->init_data);
12641request_firmware_exit:
12642 release_firmware(bp->firmware);
127d0a19 12643 bp->firmware = NULL;
94a78b79
VZ
12644
12645 return rc;
12646}
12647
619c5cb6
VZ
12648static void bnx2x_release_firmware(struct bnx2x *bp)
12649{
12650 kfree(bp->init_ops_offsets);
12651 kfree(bp->init_ops);
12652 kfree(bp->init_data);
12653 release_firmware(bp->firmware);
eb2afd4a 12654 bp->firmware = NULL;
619c5cb6
VZ
12655}
12656
619c5cb6
VZ
12657static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12658 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12659 .init_hw_cmn = bnx2x_init_hw_common,
12660 .init_hw_port = bnx2x_init_hw_port,
12661 .init_hw_func = bnx2x_init_hw_func,
12662
12663 .reset_hw_cmn = bnx2x_reset_common,
12664 .reset_hw_port = bnx2x_reset_port,
12665 .reset_hw_func = bnx2x_reset_func,
12666
12667 .gunzip_init = bnx2x_gunzip_init,
12668 .gunzip_end = bnx2x_gunzip_end,
12669
12670 .init_fw = bnx2x_init_firmware,
12671 .release_fw = bnx2x_release_firmware,
12672};
12673
12674void bnx2x__init_func_obj(struct bnx2x *bp)
12675{
12676 /* Prepare DMAE related driver resources */
12677 bnx2x_setup_dmae(bp);
12678
12679 bnx2x_init_func_obj(bp, &bp->func_obj,
12680 bnx2x_sp(bp, func_rdata),
12681 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
12682 bnx2x_sp(bp, func_afex_rdata),
12683 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
12684 &bnx2x_func_sp_drv);
12685}
12686
12687/* must be called after sriov-enable */
1191cb83 12688static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 12689{
37ae41a9 12690 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 12691
290ca2bb
AE
12692 if (IS_SRIOV(bp))
12693 cid_count += BNX2X_VF_CIDS;
12694
55c11941
MS
12695 if (CNIC_SUPPORT(bp))
12696 cid_count += CNIC_CID_MAX;
290ca2bb 12697
523224a3
DK
12698 return roundup(cid_count, QM_CID_ROUND);
12699}
f85582f8 12700
619c5cb6 12701/**
6383c0b3 12702 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
12703 *
12704 * @dev: pci device
12705 *
12706 */
60cad4e6 12707static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
619c5cb6 12708{
ae2104be 12709 int index;
1ab4434c 12710 u16 control = 0;
619c5cb6 12711
6383c0b3
AE
12712 /*
12713 * If MSI-X is not supported - return number of SBs needed to support
12714 * one fast path queue: one FP queue + SB for CNIC
12715 */
ae2104be 12716 if (!pdev->msix_cap) {
1ab4434c 12717 dev_info(&pdev->dev, "no msix capability found\n");
55c11941 12718 return 1 + cnic_cnt;
1ab4434c
AE
12719 }
12720 dev_info(&pdev->dev, "msix capability found\n");
619c5cb6 12721
6383c0b3
AE
12722 /*
12723 * The value in the PCI configuration space is the index of the last
12724 * entry, namely one less than the actual size of the table, which is
12725 * exactly what we want to return from this function: number of all SBs
12726 * without the default SB.
1ab4434c 12727 * For VFs there is no default SB, then we return (index+1).
6383c0b3 12728 */
ae2104be 12729 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
619c5cb6 12730
1ab4434c 12731 index = control & PCI_MSIX_FLAGS_QSIZE;
4bd9b0ff 12732
60cad4e6 12733 return index;
1ab4434c 12734}
523224a3 12735
1ab4434c
AE
12736static int set_max_cos_est(int chip_id)
12737{
12738 switch (chip_id) {
f2e0899f
DK
12739 case BCM57710:
12740 case BCM57711:
12741 case BCM57711E:
1ab4434c 12742 return BNX2X_MULTI_TX_COS_E1X;
f2e0899f 12743 case BCM57712:
619c5cb6 12744 case BCM57712_MF:
1ab4434c 12745 return BNX2X_MULTI_TX_COS_E2_E3A0;
619c5cb6
VZ
12746 case BCM57800:
12747 case BCM57800_MF:
12748 case BCM57810:
12749 case BCM57810_MF:
c3def943
YM
12750 case BCM57840_4_10:
12751 case BCM57840_2_20:
1ab4434c 12752 case BCM57840_O:
c3def943 12753 case BCM57840_MFO:
619c5cb6 12754 case BCM57840_MF:
7e8e02df
BW
12755 case BCM57811:
12756 case BCM57811_MF:
1ab4434c 12757 return BNX2X_MULTI_TX_COS_E3B0;
b1239723
YM
12758 case BCM57712_VF:
12759 case BCM57800_VF:
12760 case BCM57810_VF:
12761 case BCM57840_VF:
12762 case BCM57811_VF:
1ab4434c 12763 return 1;
f2e0899f 12764 default:
1ab4434c 12765 pr_err("Unknown board_type (%d), aborting\n", chip_id);
870634b0 12766 return -ENODEV;
f2e0899f 12767 }
1ab4434c 12768}
f2e0899f 12769
1ab4434c
AE
12770static int set_is_vf(int chip_id)
12771{
12772 switch (chip_id) {
12773 case BCM57712_VF:
12774 case BCM57800_VF:
12775 case BCM57810_VF:
12776 case BCM57840_VF:
12777 case BCM57811_VF:
12778 return true;
12779 default:
12780 return false;
12781 }
12782}
6383c0b3 12783
1ab4434c
AE
12784struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12785
12786static int bnx2x_init_one(struct pci_dev *pdev,
12787 const struct pci_device_id *ent)
12788{
12789 struct net_device *dev = NULL;
12790 struct bnx2x *bp;
b91e1a1a
YM
12791 enum pcie_link_width pcie_width;
12792 enum pci_bus_speed pcie_speed;
1ab4434c
AE
12793 int rc, max_non_def_sbs;
12794 int rx_count, tx_count, rss_count, doorbell_size;
12795 int max_cos_est;
12796 bool is_vf;
12797 int cnic_cnt;
12798
12799 /* An estimated maximum supported CoS number according to the chip
12800 * version.
12801 * We will try to roughly estimate the maximum number of CoSes this chip
12802 * may support in order to minimize the memory allocated for Tx
12803 * netdev_queue's. This number will be accurately calculated during the
12804 * initialization of bp->max_cos based on the chip versions AND chip
12805 * revision in the bnx2x_init_bp().
12806 */
12807 max_cos_est = set_max_cos_est(ent->driver_data);
12808 if (max_cos_est < 0)
12809 return max_cos_est;
12810 is_vf = set_is_vf(ent->driver_data);
12811 cnic_cnt = is_vf ? 0 : 1;
12812
60cad4e6
AE
12813 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
12814
12815 /* add another SB for VF as it has no default SB */
12816 max_non_def_sbs += is_vf ? 1 : 0;
6383c0b3
AE
12817
12818 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
60cad4e6 12819 rss_count = max_non_def_sbs - cnic_cnt;
1ab4434c
AE
12820
12821 if (rss_count < 1)
12822 return -EINVAL;
6383c0b3
AE
12823
12824 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12825 rx_count = rss_count + cnic_cnt;
6383c0b3 12826
1ab4434c 12827 /* Maximum number of netdev Tx queues:
37ae41a9 12828 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12829 */
55c11941 12830 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12831
a2fbb9ea 12832 /* dev zeroed in init_etherdev */
6383c0b3 12833 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12834 if (!dev)
a2fbb9ea
ET
12835 return -ENOMEM;
12836
a2fbb9ea 12837 bp = netdev_priv(dev);
a2fbb9ea 12838
1ab4434c
AE
12839 bp->flags = 0;
12840 if (is_vf)
12841 bp->flags |= IS_VF_FLAG;
12842
6383c0b3 12843 bp->igu_sb_cnt = max_non_def_sbs;
1ab4434c 12844 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
6383c0b3 12845 bp->msg_enable = debug;
55c11941 12846 bp->cnic_support = cnic_cnt;
4bd9b0ff 12847 bp->cnic_probe = bnx2x_cnic_probe;
55c11941 12848
6383c0b3 12849 pci_set_drvdata(pdev, dev);
523224a3 12850
1ab4434c 12851 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
a2fbb9ea
ET
12852 if (rc < 0) {
12853 free_netdev(dev);
12854 return rc;
12855 }
12856
1ab4434c
AE
12857 BNX2X_DEV_INFO("This is a %s function\n",
12858 IS_PF(bp) ? "physical" : "virtual");
55c11941 12859 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
1ab4434c 12860 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
60aa0509 12861 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
2de67439 12862 tx_count, rx_count);
60aa0509 12863
34f80b04 12864 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12865 if (rc)
12866 goto init_one_exit;
12867
1ab4434c
AE
12868 /* Map doorbells here as we need the real value of bp->max_cos which
12869 * is initialized in bnx2x_init_bp() to determine the number of
12870 * l2 connections.
6383c0b3 12871 */
1ab4434c 12872 if (IS_VF(bp)) {
1d6f3cd8 12873 bp->doorbells = bnx2x_vf_doorbells(bp);
6411280a
AE
12874 rc = bnx2x_vf_pci_alloc(bp);
12875 if (rc)
12876 goto init_one_exit;
1ab4434c
AE
12877 } else {
12878 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12879 if (doorbell_size > pci_resource_len(pdev, 2)) {
12880 dev_err(&bp->pdev->dev,
12881 "Cannot map doorbells, bar size too small, aborting\n");
12882 rc = -ENOMEM;
12883 goto init_one_exit;
12884 }
12885 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12886 doorbell_size);
37ae41a9 12887 }
6383c0b3
AE
12888 if (!bp->doorbells) {
12889 dev_err(&bp->pdev->dev,
12890 "Cannot map doorbell space, aborting\n");
12891 rc = -ENOMEM;
12892 goto init_one_exit;
12893 }
12894
be1f1ffa
AE
12895 if (IS_VF(bp)) {
12896 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12897 if (rc)
12898 goto init_one_exit;
12899 }
12900
3c76feff
AE
12901 /* Enable SRIOV if capability found in configuration space */
12902 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
290ca2bb
AE
12903 if (rc)
12904 goto init_one_exit;
12905
523224a3 12906 /* calc qm_cid_count */
6383c0b3 12907 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
1ab4434c 12908 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
523224a3 12909
55c11941 12910 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12911 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12912 bp->flags |= NO_FCOE_FLAG;
12913
0e8d2ec5
MS
12914 /* Set bp->num_queues for MSI-X mode*/
12915 bnx2x_set_num_queues(bp);
12916
25985edc 12917 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12918 * needed.
d6214d7a 12919 */
1ab4434c
AE
12920 rc = bnx2x_set_int_mode(bp);
12921 if (rc) {
12922 dev_err(&pdev->dev, "Cannot set interrupts\n");
12923 goto init_one_exit;
12924 }
04c46736 12925 BNX2X_DEV_INFO("set interrupts successfully\n");
d6214d7a 12926
1ab4434c 12927 /* register the net device */
b340007f
VZ
12928 rc = register_netdev(dev);
12929 if (rc) {
12930 dev_err(&pdev->dev, "Cannot register net device\n");
12931 goto init_one_exit;
12932 }
1ab4434c 12933 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
b340007f 12934
ec6ba945
VZ
12935 if (!NO_FCOE(bp)) {
12936 /* Add storage MAC address */
12937 rtnl_lock();
12938 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12939 rtnl_unlock();
12940 }
b91e1a1a
YM
12941 if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
12942 pcie_speed == PCI_SPEED_UNKNOWN ||
12943 pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
12944 BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
12945 else
12946 BNX2X_DEV_INFO(
12947 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
ca1ee4b2
DK
12948 board_info[ent->driver_data].name,
12949 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12950 pcie_width,
b91e1a1a
YM
12951 pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
12952 pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
12953 pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
ca1ee4b2
DK
12954 "Unknown",
12955 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12956
a2fbb9ea 12957 return 0;
34f80b04
EG
12958
12959init_one_exit:
33d8e6a5
YM
12960 bnx2x_disable_pcie_error_reporting(bp);
12961
34f80b04
EG
12962 if (bp->regview)
12963 iounmap(bp->regview);
12964
1ab4434c 12965 if (IS_PF(bp) && bp->doorbells)
34f80b04
EG
12966 iounmap(bp->doorbells);
12967
12968 free_netdev(dev);
12969
12970 if (atomic_read(&pdev->enable_cnt) == 1)
12971 pci_release_regions(pdev);
12972
12973 pci_disable_device(pdev);
34f80b04
EG
12974
12975 return rc;
a2fbb9ea
ET
12976}
12977
b030ed2f
YM
12978static void __bnx2x_remove(struct pci_dev *pdev,
12979 struct net_device *dev,
12980 struct bnx2x *bp,
12981 bool remove_netdev)
a2fbb9ea 12982{
ec6ba945
VZ
12983 /* Delete storage MAC address */
12984 if (!NO_FCOE(bp)) {
12985 rtnl_lock();
12986 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12987 rtnl_unlock();
12988 }
ec6ba945 12989
98507672
SR
12990#ifdef BCM_DCBNL
12991 /* Delete app tlvs from dcbnl */
12992 bnx2x_dcbnl_update_applist(bp, true);
12993#endif
12994
a6d3a5ba
BW
12995 if (IS_PF(bp) &&
12996 !BP_NOMCP(bp) &&
12997 (bp->flags & BC_SUPPORTS_RMMOD_CMD))
12998 bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
12999
b030ed2f
YM
13000 /* Close the interface - either directly or implicitly */
13001 if (remove_netdev) {
13002 unregister_netdev(dev);
13003 } else {
13004 rtnl_lock();
6ef5a92c 13005 dev_close(dev);
b030ed2f
YM
13006 rtnl_unlock();
13007 }
a2fbb9ea 13008
78c3bcc5
AE
13009 bnx2x_iov_remove_one(bp);
13010
084d6cbb 13011 /* Power on: we can't let PCI layer write to us while we are in D3 */
1ab4434c
AE
13012 if (IS_PF(bp))
13013 bnx2x_set_power_state(bp, PCI_D0);
084d6cbb 13014
d6214d7a
DK
13015 /* Disable MSI/MSI-X */
13016 bnx2x_disable_msi(bp);
f85582f8 13017
084d6cbb 13018 /* Power off */
1ab4434c
AE
13019 if (IS_PF(bp))
13020 bnx2x_set_power_state(bp, PCI_D3hot);
084d6cbb 13021
72fd0718 13022 /* Make sure RESET task is not scheduled before continuing */
7be08a72 13023 cancel_delayed_work_sync(&bp->sp_rtnl_task);
290ca2bb 13024
4513f925
AE
13025 /* send message via vfpf channel to release the resources of this vf */
13026 if (IS_VF(bp))
13027 bnx2x_vfpf_release(bp);
72fd0718 13028
b030ed2f
YM
13029 /* Assumes no further PCIe PM changes will occur */
13030 if (system_state == SYSTEM_POWER_OFF) {
13031 pci_wake_from_d3(pdev, bp->wol);
13032 pci_set_power_state(pdev, PCI_D3hot);
13033 }
13034
33d8e6a5
YM
13035 bnx2x_disable_pcie_error_reporting(bp);
13036
a2fbb9ea
ET
13037 if (bp->regview)
13038 iounmap(bp->regview);
13039
1ab4434c
AE
13040 /* for vf doorbells are part of the regview and were unmapped along with
13041 * it. FW is only loaded by PF.
13042 */
13043 if (IS_PF(bp)) {
13044 if (bp->doorbells)
13045 iounmap(bp->doorbells);
eb2afd4a 13046
1ab4434c
AE
13047 bnx2x_release_firmware(bp);
13048 }
523224a3
DK
13049 bnx2x_free_mem_bp(bp);
13050
b030ed2f
YM
13051 if (remove_netdev)
13052 free_netdev(dev);
34f80b04
EG
13053
13054 if (atomic_read(&pdev->enable_cnt) == 1)
13055 pci_release_regions(pdev);
13056
a2fbb9ea 13057 pci_disable_device(pdev);
a2fbb9ea
ET
13058}
13059
b030ed2f
YM
13060static void bnx2x_remove_one(struct pci_dev *pdev)
13061{
13062 struct net_device *dev = pci_get_drvdata(pdev);
13063 struct bnx2x *bp;
13064
13065 if (!dev) {
13066 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
13067 return;
13068 }
13069 bp = netdev_priv(dev);
13070
13071 __bnx2x_remove(pdev, dev, bp, true);
13072}
13073
f8ef6e44
YG
13074static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
13075{
7fa6f340 13076 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
f8ef6e44
YG
13077
13078 bp->rx_mode = BNX2X_RX_MODE_NONE;
13079
55c11941
MS
13080 if (CNIC_LOADED(bp))
13081 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
13082
619c5cb6
VZ
13083 /* Stop Tx */
13084 bnx2x_tx_disable(bp);
26614ba5
MS
13085 /* Delete all NAPI objects */
13086 bnx2x_del_all_napi(bp);
55c11941
MS
13087 if (CNIC_LOADED(bp))
13088 bnx2x_del_all_napi_cnic(bp);
7fa6f340 13089 netdev_reset_tc(bp->dev);
f8ef6e44
YG
13090
13091 del_timer_sync(&bp->timer);
7fa6f340
YM
13092 cancel_delayed_work(&bp->sp_task);
13093 cancel_delayed_work(&bp->period_task);
619c5cb6 13094
7fa6f340
YM
13095 spin_lock_bh(&bp->stats_lock);
13096 bp->stats_state = STATS_STATE_DISABLED;
13097 spin_unlock_bh(&bp->stats_lock);
f8ef6e44 13098
7fa6f340 13099 bnx2x_save_statistics(bp);
f8ef6e44 13100
619c5cb6
VZ
13101 netif_carrier_off(bp->dev);
13102
f8ef6e44
YG
13103 return 0;
13104}
13105
493adb1f
WX
13106/**
13107 * bnx2x_io_error_detected - called when PCI error is detected
13108 * @pdev: Pointer to PCI device
13109 * @state: The current pci connection state
13110 *
13111 * This function is called after a PCI bus error affecting
13112 * this device has been detected.
13113 */
13114static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
13115 pci_channel_state_t state)
13116{
13117 struct net_device *dev = pci_get_drvdata(pdev);
13118 struct bnx2x *bp = netdev_priv(dev);
13119
13120 rtnl_lock();
13121
7fa6f340
YM
13122 BNX2X_ERR("IO error detected\n");
13123
493adb1f
WX
13124 netif_device_detach(dev);
13125
07ce50e4
DN
13126 if (state == pci_channel_io_perm_failure) {
13127 rtnl_unlock();
13128 return PCI_ERS_RESULT_DISCONNECT;
13129 }
13130
493adb1f 13131 if (netif_running(dev))
f8ef6e44 13132 bnx2x_eeh_nic_unload(bp);
493adb1f 13133
7fa6f340
YM
13134 bnx2x_prev_path_mark_eeh(bp);
13135
493adb1f
WX
13136 pci_disable_device(pdev);
13137
13138 rtnl_unlock();
13139
13140 /* Request a slot reset */
13141 return PCI_ERS_RESULT_NEED_RESET;
13142}
13143
13144/**
13145 * bnx2x_io_slot_reset - called after the PCI bus has been reset
13146 * @pdev: Pointer to PCI device
13147 *
13148 * Restart the card from scratch, as if from a cold-boot.
13149 */
13150static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
13151{
13152 struct net_device *dev = pci_get_drvdata(pdev);
13153 struct bnx2x *bp = netdev_priv(dev);
7fa6f340 13154 int i;
493adb1f
WX
13155
13156 rtnl_lock();
7fa6f340 13157 BNX2X_ERR("IO slot reset initializing...\n");
493adb1f
WX
13158 if (pci_enable_device(pdev)) {
13159 dev_err(&pdev->dev,
13160 "Cannot re-enable PCI device after reset\n");
13161 rtnl_unlock();
13162 return PCI_ERS_RESULT_DISCONNECT;
13163 }
13164
13165 pci_set_master(pdev);
13166 pci_restore_state(pdev);
70632d0a 13167 pci_save_state(pdev);
493adb1f
WX
13168
13169 if (netif_running(dev))
13170 bnx2x_set_power_state(bp, PCI_D0);
13171
7fa6f340
YM
13172 if (netif_running(dev)) {
13173 BNX2X_ERR("IO slot reset --> driver unload\n");
e68072ef
YM
13174
13175 /* MCP should have been reset; Need to wait for validity */
13176 bnx2x_init_shmem(bp);
13177
7fa6f340
YM
13178 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
13179 u32 v;
13180
13181 v = SHMEM2_RD(bp,
13182 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
13183 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
13184 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
13185 }
13186 bnx2x_drain_tx_queues(bp);
13187 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
13188 bnx2x_netif_stop(bp, 1);
13189 bnx2x_free_irq(bp);
13190
13191 /* Report UNLOAD_DONE to MCP */
13192 bnx2x_send_unload_done(bp, true);
13193
13194 bp->sp_state = 0;
13195 bp->port.pmf = 0;
13196
13197 bnx2x_prev_unload(bp);
13198
16a5fd92 13199 /* We should have reseted the engine, so It's fair to
7fa6f340
YM
13200 * assume the FW will no longer write to the bnx2x driver.
13201 */
13202 bnx2x_squeeze_objects(bp);
13203 bnx2x_free_skbs(bp);
13204 for_each_rx_queue(bp, i)
13205 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
13206 bnx2x_free_fp_mem(bp);
13207 bnx2x_free_mem(bp);
13208
13209 bp->state = BNX2X_STATE_CLOSED;
13210 }
13211
493adb1f
WX
13212 rtnl_unlock();
13213
33d8e6a5
YM
13214 /* If AER, perform cleanup of the PCIe registers */
13215 if (bp->flags & AER_ENABLED) {
13216 if (pci_cleanup_aer_uncorrect_error_status(pdev))
13217 BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
13218 else
13219 DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
13220 }
13221
493adb1f
WX
13222 return PCI_ERS_RESULT_RECOVERED;
13223}
13224
13225/**
13226 * bnx2x_io_resume - called when traffic can start flowing again
13227 * @pdev: Pointer to PCI device
13228 *
13229 * This callback is called when the error recovery driver tells us that
13230 * its OK to resume normal operation.
13231 */
13232static void bnx2x_io_resume(struct pci_dev *pdev)
13233{
13234 struct net_device *dev = pci_get_drvdata(pdev);
13235 struct bnx2x *bp = netdev_priv(dev);
13236
72fd0718 13237 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 13238 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
13239 return;
13240 }
13241
493adb1f
WX
13242 rtnl_lock();
13243
7fa6f340
YM
13244 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
13245 DRV_MSG_SEQ_NUMBER_MASK;
13246
493adb1f 13247 if (netif_running(dev))
f8ef6e44 13248 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
13249
13250 netif_device_attach(dev);
13251
13252 rtnl_unlock();
13253}
13254
3646f0e5 13255static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 13256 .error_detected = bnx2x_io_error_detected,
356e2385
EG
13257 .slot_reset = bnx2x_io_slot_reset,
13258 .resume = bnx2x_io_resume,
493adb1f
WX
13259};
13260
b030ed2f
YM
13261static void bnx2x_shutdown(struct pci_dev *pdev)
13262{
13263 struct net_device *dev = pci_get_drvdata(pdev);
13264 struct bnx2x *bp;
13265
13266 if (!dev)
13267 return;
13268
13269 bp = netdev_priv(dev);
13270 if (!bp)
13271 return;
13272
13273 rtnl_lock();
13274 netif_device_detach(dev);
13275 rtnl_unlock();
13276
13277 /* Don't remove the netdevice, as there are scenarios which will cause
13278 * the kernel to hang, e.g., when trying to remove bnx2i while the
13279 * rootfs is mounted from SAN.
13280 */
13281 __bnx2x_remove(pdev, dev, bp, false);
13282}
13283
a2fbb9ea 13284static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
13285 .name = DRV_MODULE_NAME,
13286 .id_table = bnx2x_pci_tbl,
13287 .probe = bnx2x_init_one,
0329aba1 13288 .remove = bnx2x_remove_one,
493adb1f
WX
13289 .suspend = bnx2x_suspend,
13290 .resume = bnx2x_resume,
13291 .err_handler = &bnx2x_err_handler,
3c76feff
AE
13292#ifdef CONFIG_BNX2X_SRIOV
13293 .sriov_configure = bnx2x_sriov_configure,
13294#endif
b030ed2f 13295 .shutdown = bnx2x_shutdown,
a2fbb9ea
ET
13296};
13297
13298static int __init bnx2x_init(void)
13299{
dd21ca6d
SG
13300 int ret;
13301
7995c64e 13302 pr_info("%s", version);
938cf541 13303
1cf167f2
EG
13304 bnx2x_wq = create_singlethread_workqueue("bnx2x");
13305 if (bnx2x_wq == NULL) {
7995c64e 13306 pr_err("Cannot create workqueue\n");
1cf167f2
EG
13307 return -ENOMEM;
13308 }
13309
dd21ca6d
SG
13310 ret = pci_register_driver(&bnx2x_pci_driver);
13311 if (ret) {
7995c64e 13312 pr_err("Cannot register driver\n");
dd21ca6d
SG
13313 destroy_workqueue(bnx2x_wq);
13314 }
13315 return ret;
a2fbb9ea
ET
13316}
13317
13318static void __exit bnx2x_cleanup(void)
13319{
452427b0 13320 struct list_head *pos, *q;
d76a6111 13321
a2fbb9ea 13322 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
13323
13324 destroy_workqueue(bnx2x_wq);
452427b0 13325
16a5fd92 13326 /* Free globally allocated resources */
452427b0
YM
13327 list_for_each_safe(pos, q, &bnx2x_prev_list) {
13328 struct bnx2x_prev_path_list *tmp =
13329 list_entry(pos, struct bnx2x_prev_path_list, list);
13330 list_del(pos);
13331 kfree(tmp);
13332 }
a2fbb9ea
ET
13333}
13334
3deb8167
YR
13335void bnx2x_notify_link_changed(struct bnx2x *bp)
13336{
13337 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13338}
13339
a2fbb9ea
ET
13340module_init(bnx2x_init);
13341module_exit(bnx2x_cleanup);
13342
619c5cb6
VZ
13343/**
13344 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13345 *
13346 * @bp: driver handle
13347 * @set: set or clear the CAM entry
13348 *
16a5fd92 13349 * This function will wait until the ramrod completion returns.
619c5cb6
VZ
13350 * Return 0 if success, -ENODEV if ramrod doesn't return.
13351 */
1191cb83 13352static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
13353{
13354 unsigned long ramrod_flags = 0;
13355
13356 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13357 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13358 &bp->iscsi_l2_mac_obj, true,
13359 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13360}
993ac7b5
MC
13361
13362/* count denotes the number of new completions we have seen */
13363static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13364{
13365 struct eth_spe *spe;
a052997e 13366 int cxt_index, cxt_offset;
993ac7b5
MC
13367
13368#ifdef BNX2X_STOP_ON_ERROR
13369 if (unlikely(bp->panic))
13370 return;
13371#endif
13372
13373 spin_lock_bh(&bp->spq_lock);
c2bff63f 13374 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
13375 bp->cnic_spq_pending -= count;
13376
c2bff63f
DK
13377 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13378 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13379 & SPE_HDR_CONN_TYPE) >>
13380 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
13381 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13382 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
13383
13384 /* Set validation for iSCSI L2 client before sending SETUP
13385 * ramrod
13386 */
13387 if (type == ETH_CONNECTION_TYPE) {
a052997e 13388 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 13389 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 13390 ILT_PAGE_CIDS;
37ae41a9 13391 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
13392 (cxt_index * ILT_PAGE_CIDS);
13393 bnx2x_set_ctx_validation(bp,
13394 &bp->context[cxt_index].
13395 vcxt[cxt_offset].eth,
37ae41a9 13396 BNX2X_ISCSI_ETH_CID(bp));
a052997e 13397 }
c2bff63f
DK
13398 }
13399
619c5cb6
VZ
13400 /*
13401 * There may be not more than 8 L2, not more than 8 L5 SPEs
13402 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
13403 * COMMON ramrods is not more than the EQ and SPQ can
13404 * accommodate.
c2bff63f 13405 */
6e30dd4e
VZ
13406 if (type == ETH_CONNECTION_TYPE) {
13407 if (!atomic_read(&bp->cq_spq_left))
13408 break;
13409 else
13410 atomic_dec(&bp->cq_spq_left);
13411 } else if (type == NONE_CONNECTION_TYPE) {
13412 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
13413 break;
13414 else
6e30dd4e 13415 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
13416 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13417 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
13418 if (bp->cnic_spq_pending >=
13419 bp->cnic_eth_dev.max_kwqe_pending)
13420 break;
13421 else
13422 bp->cnic_spq_pending++;
13423 } else {
13424 BNX2X_ERR("Unknown SPE type: %d\n", type);
13425 bnx2x_panic();
993ac7b5 13426 break;
c2bff63f 13427 }
993ac7b5
MC
13428
13429 spe = bnx2x_sp_get_next(bp);
13430 *spe = *bp->cnic_kwq_cons;
13431
51c1a580 13432 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
13433 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13434
13435 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13436 bp->cnic_kwq_cons = bp->cnic_kwq;
13437 else
13438 bp->cnic_kwq_cons++;
13439 }
13440 bnx2x_sp_prod_update(bp);
13441 spin_unlock_bh(&bp->spq_lock);
13442}
13443
13444static int bnx2x_cnic_sp_queue(struct net_device *dev,
13445 struct kwqe_16 *kwqes[], u32 count)
13446{
13447 struct bnx2x *bp = netdev_priv(dev);
13448 int i;
13449
13450#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
13451 if (unlikely(bp->panic)) {
13452 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 13453 return -EIO;
51c1a580 13454 }
993ac7b5
MC
13455#endif
13456
95c6c616
AE
13457 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13458 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 13459 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
13460 return -EAGAIN;
13461 }
13462
993ac7b5
MC
13463 spin_lock_bh(&bp->spq_lock);
13464
13465 for (i = 0; i < count; i++) {
13466 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13467
13468 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13469 break;
13470
13471 *bp->cnic_kwq_prod = *spe;
13472
13473 bp->cnic_kwq_pending++;
13474
51c1a580 13475 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 13476 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
13477 spe->data.update_data_addr.hi,
13478 spe->data.update_data_addr.lo,
993ac7b5
MC
13479 bp->cnic_kwq_pending);
13480
13481 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13482 bp->cnic_kwq_prod = bp->cnic_kwq;
13483 else
13484 bp->cnic_kwq_prod++;
13485 }
13486
13487 spin_unlock_bh(&bp->spq_lock);
13488
13489 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13490 bnx2x_cnic_sp_post(bp, 0);
13491
13492 return i;
13493}
13494
13495static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13496{
13497 struct cnic_ops *c_ops;
13498 int rc = 0;
13499
13500 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
13501 c_ops = rcu_dereference_protected(bp->cnic_ops,
13502 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
13503 if (c_ops)
13504 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13505 mutex_unlock(&bp->cnic_mutex);
13506
13507 return rc;
13508}
13509
13510static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13511{
13512 struct cnic_ops *c_ops;
13513 int rc = 0;
13514
13515 rcu_read_lock();
13516 c_ops = rcu_dereference(bp->cnic_ops);
13517 if (c_ops)
13518 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13519 rcu_read_unlock();
13520
13521 return rc;
13522}
13523
13524/*
13525 * for commands that have no data
13526 */
9f6c9258 13527int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
13528{
13529 struct cnic_ctl_info ctl = {0};
13530
13531 ctl.cmd = cmd;
13532
13533 return bnx2x_cnic_ctl_send(bp, &ctl);
13534}
13535
619c5cb6 13536static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 13537{
619c5cb6 13538 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
13539
13540 /* first we tell CNIC and only then we count this as a completion */
13541 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13542 ctl.data.comp.cid = cid;
619c5cb6 13543 ctl.data.comp.error = err;
993ac7b5
MC
13544
13545 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 13546 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
13547}
13548
619c5cb6
VZ
13549/* Called with netif_addr_lock_bh() taken.
13550 * Sets an rx_mode config for an iSCSI ETH client.
13551 * Doesn't block.
13552 * Completion should be checked outside.
13553 */
13554static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13555{
13556 unsigned long accept_flags = 0, ramrod_flags = 0;
13557 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13558 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13559
13560 if (start) {
13561 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13562 * because it's the only way for UIO Queue to accept
13563 * multicasts (in non-promiscuous mode only one Queue per
13564 * function will receive multicast packets (leading in our
13565 * case).
13566 */
13567 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13568 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13569 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13570 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13571
13572 /* Clear STOP_PENDING bit if START is requested */
13573 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13574
13575 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13576 } else
13577 /* Clear START_PENDING bit if STOP is requested */
13578 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13579
13580 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13581 set_bit(sched_state, &bp->sp_state);
13582 else {
13583 __set_bit(RAMROD_RX, &ramrod_flags);
13584 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13585 ramrod_flags);
13586 }
13587}
13588
993ac7b5
MC
13589static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13590{
13591 struct bnx2x *bp = netdev_priv(dev);
13592 int rc = 0;
13593
13594 switch (ctl->cmd) {
13595 case DRV_CTL_CTXTBL_WR_CMD: {
13596 u32 index = ctl->data.io.offset;
13597 dma_addr_t addr = ctl->data.io.dma_addr;
13598
13599 bnx2x_ilt_wr(bp, index, addr);
13600 break;
13601 }
13602
c2bff63f
DK
13603 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13604 int count = ctl->data.credit.credit_count;
993ac7b5
MC
13605
13606 bnx2x_cnic_sp_post(bp, count);
13607 break;
13608 }
13609
13610 /* rtnl_lock is held. */
13611 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
13612 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13613 unsigned long sp_bits = 0;
13614
13615 /* Configure the iSCSI classification object */
13616 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13617 cp->iscsi_l2_client_id,
13618 cp->iscsi_l2_cid, BP_FUNC(bp),
13619 bnx2x_sp(bp, mac_rdata),
13620 bnx2x_sp_mapping(bp, mac_rdata),
13621 BNX2X_FILTER_MAC_PENDING,
13622 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13623 &bp->macs_pool);
ec6ba945 13624
523224a3 13625 /* Set iSCSI MAC address */
619c5cb6
VZ
13626 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13627 if (rc)
13628 break;
523224a3
DK
13629
13630 mmiowb();
13631 barrier();
13632
619c5cb6
VZ
13633 /* Start accepting on iSCSI L2 ring */
13634
13635 netif_addr_lock_bh(dev);
13636 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13637 netif_addr_unlock_bh(dev);
13638
13639 /* bits to wait on */
13640 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13641 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13642
13643 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13644 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 13645
993ac7b5
MC
13646 break;
13647 }
13648
13649 /* rtnl_lock is held. */
13650 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 13651 unsigned long sp_bits = 0;
993ac7b5 13652
523224a3 13653 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
13654 netif_addr_lock_bh(dev);
13655 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13656 netif_addr_unlock_bh(dev);
13657
13658 /* bits to wait on */
13659 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13660 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13661
13662 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13663 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
13664
13665 mmiowb();
13666 barrier();
13667
13668 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
13669 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13670 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
13671 break;
13672 }
c2bff63f
DK
13673 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13674 int count = ctl->data.credit.credit_count;
13675
13676 smp_mb__before_atomic_inc();
6e30dd4e 13677 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
13678 smp_mb__after_atomic_inc();
13679 break;
13680 }
1d187b34 13681 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 13682 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
13683
13684 if (CHIP_IS_E3(bp)) {
13685 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
13686 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13687 int path = BP_PATH(bp);
13688 int port = BP_PORT(bp);
13689 int i;
13690 u32 scratch_offset;
13691 u32 *host_addr;
1d187b34 13692
2e499d3c 13693 /* first write capability to shmem2 */
1d187b34
BW
13694 if (ulp_type == CNIC_ULP_ISCSI)
13695 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13696 else if (ulp_type == CNIC_ULP_FCOE)
13697 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13698 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
13699
13700 if ((ulp_type != CNIC_ULP_FCOE) ||
13701 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13702 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13703 break;
13704
13705 /* if reached here - should write fcoe capabilities */
13706 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13707 if (!scratch_offset)
13708 break;
13709 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13710 fcoe_features[path][port]);
13711 host_addr = (u32 *) &(ctl->data.register_data.
13712 fcoe_features);
13713 for (i = 0; i < sizeof(struct fcoe_capabilities);
13714 i += 4)
13715 REG_WR(bp, scratch_offset + i,
13716 *(host_addr + i/4));
1d187b34
BW
13717 }
13718 break;
13719 }
2e499d3c 13720
1d187b34
BW
13721 case DRV_CTL_ULP_UNREGISTER_CMD: {
13722 int ulp_type = ctl->data.ulp_type;
13723
13724 if (CHIP_IS_E3(bp)) {
13725 int idx = BP_FW_MB_IDX(bp);
13726 u32 cap;
13727
13728 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13729 if (ulp_type == CNIC_ULP_ISCSI)
13730 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13731 else if (ulp_type == CNIC_ULP_FCOE)
13732 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13733 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13734 }
13735 break;
13736 }
993ac7b5
MC
13737
13738 default:
13739 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13740 rc = -EINVAL;
13741 }
13742
13743 return rc;
13744}
13745
9f6c9258 13746void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
13747{
13748 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13749
13750 if (bp->flags & USING_MSIX_FLAG) {
13751 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13752 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13753 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13754 } else {
13755 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13756 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13757 }
619c5cb6 13758 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
13759 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13760 else
13761 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13762
619c5cb6
VZ
13763 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13764 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
13765 cp->irq_arr[1].status_blk = bp->def_status_blk;
13766 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 13767 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
13768
13769 cp->num_irq = 2;
13770}
13771
37ae41a9
MS
13772void bnx2x_setup_cnic_info(struct bnx2x *bp)
13773{
13774 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13775
37ae41a9
MS
13776 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13777 bnx2x_cid_ilt_lines(bp);
13778 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13779 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13780 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13781
f78afb35
MC
13782 DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
13783 BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
13784 cp->iscsi_l2_cid);
13785
37ae41a9
MS
13786 if (NO_ISCSI_OOO(bp))
13787 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13788}
13789
993ac7b5
MC
13790static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13791 void *data)
13792{
13793 struct bnx2x *bp = netdev_priv(dev);
13794 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
13795 int rc;
13796
13797 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 13798
51c1a580
MS
13799 if (ops == NULL) {
13800 BNX2X_ERR("NULL ops received\n");
993ac7b5 13801 return -EINVAL;
51c1a580 13802 }
993ac7b5 13803
55c11941
MS
13804 if (!CNIC_SUPPORT(bp)) {
13805 BNX2X_ERR("Can't register CNIC when not supported\n");
13806 return -EOPNOTSUPP;
13807 }
13808
13809 if (!CNIC_LOADED(bp)) {
13810 rc = bnx2x_load_cnic(bp);
13811 if (rc) {
13812 BNX2X_ERR("CNIC-related load failed\n");
13813 return rc;
13814 }
55c11941
MS
13815 }
13816
13817 bp->cnic_enabled = true;
13818
993ac7b5
MC
13819 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13820 if (!bp->cnic_kwq)
13821 return -ENOMEM;
13822
13823 bp->cnic_kwq_cons = bp->cnic_kwq;
13824 bp->cnic_kwq_prod = bp->cnic_kwq;
13825 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13826
13827 bp->cnic_spq_pending = 0;
13828 bp->cnic_kwq_pending = 0;
13829
13830 bp->cnic_data = data;
13831
13832 cp->num_irq = 0;
619c5cb6 13833 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 13834 cp->iro_arr = bp->iro_arr;
993ac7b5 13835
993ac7b5 13836 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 13837
993ac7b5
MC
13838 rcu_assign_pointer(bp->cnic_ops, ops);
13839
13840 return 0;
13841}
13842
13843static int bnx2x_unregister_cnic(struct net_device *dev)
13844{
13845 struct bnx2x *bp = netdev_priv(dev);
13846 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13847
13848 mutex_lock(&bp->cnic_mutex);
993ac7b5 13849 cp->drv_state = 0;
2cfa5a04 13850 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
13851 mutex_unlock(&bp->cnic_mutex);
13852 synchronize_rcu();
fea75645 13853 bp->cnic_enabled = false;
993ac7b5
MC
13854 kfree(bp->cnic_kwq);
13855 bp->cnic_kwq = NULL;
13856
13857 return 0;
13858}
13859
13860struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13861{
13862 struct bnx2x *bp = netdev_priv(dev);
13863 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13864
2ba45142
VZ
13865 /* If both iSCSI and FCoE are disabled - return NULL in
13866 * order to indicate CNIC that it should not try to work
13867 * with this device.
13868 */
13869 if (NO_ISCSI(bp) && NO_FCOE(bp))
13870 return NULL;
13871
993ac7b5
MC
13872 cp->drv_owner = THIS_MODULE;
13873 cp->chip_id = CHIP_ID(bp);
13874 cp->pdev = bp->pdev;
13875 cp->io_base = bp->regview;
13876 cp->io_base2 = bp->doorbells;
13877 cp->max_kwqe_pending = 8;
523224a3 13878 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
13879 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13880 bnx2x_cid_ilt_lines(bp);
993ac7b5 13881 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 13882 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
13883 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13884 cp->drv_ctl = bnx2x_drv_ctl;
13885 cp->drv_register_cnic = bnx2x_register_cnic;
13886 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 13887 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
13888 cp->iscsi_l2_client_id =
13889 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 13890 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 13891
2ba45142
VZ
13892 if (NO_ISCSI_OOO(bp))
13893 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13894
13895 if (NO_ISCSI(bp))
13896 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13897
13898 if (NO_FCOE(bp))
13899 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13900
51c1a580
MS
13901 BNX2X_DEV_INFO(
13902 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13903 cp->ctx_blk_size,
13904 cp->ctx_tbl_offset,
13905 cp->ctx_tbl_len,
13906 cp->starting_cid);
993ac7b5
MC
13907 return cp;
13908}
993ac7b5 13909
6411280a 13910u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
9b176b6b 13911{
6411280a
AE
13912 struct bnx2x *bp = fp->bp;
13913 u32 offset = BAR_USTRORM_INTMEM;
abc5a021 13914
6411280a
AE
13915 if (IS_VF(bp))
13916 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13917 else if (!CHIP_IS_E1x(bp))
13918 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13919 else
13920 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
8d9ac297 13921
6411280a 13922 return offset;
8d9ac297 13923}
381ac16b 13924
6411280a
AE
13925/* called only on E1H or E2.
13926 * When pretending to be PF, the pretend value is the function number 0...7
13927 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13928 * combination
13929 */
13930int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
381ac16b 13931{
6411280a 13932 u32 pretend_reg;
381ac16b 13933
23826850 13934 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
6411280a 13935 return -1;
381ac16b 13936
6411280a
AE
13937 /* get my own pretend register */
13938 pretend_reg = bnx2x_get_pretend_reg(bp);
13939 REG_WR(bp, pretend_reg, pretend_func_val);
13940 REG_RD(bp, pretend_reg);
381ac16b
AE
13941 return 0;
13942}