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