]> git.ipfire.org Git - thirdparty/linux.git/blame - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
bnx2x: Revise comments and alignment
[thirdparty/linux.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>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/dma-mapping.h>
35#include <linux/bitops.h>
36#include <linux/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
0c6671b0 42#include <linux/if_vlan.h>
a2fbb9ea 43#include <net/ip.h>
619c5cb6 44#include <net/ipv6.h>
a2fbb9ea
ET
45#include <net/tcp.h>
46#include <net/checksum.h>
34f80b04 47#include <net/ip6_checksum.h>
a2fbb9ea
ET
48#include <linux/workqueue.h>
49#include <linux/crc32.h>
34f80b04 50#include <linux/crc32c.h>
a2fbb9ea
ET
51#include <linux/prefetch.h>
52#include <linux/zlib.h>
a2fbb9ea 53#include <linux/io.h>
452427b0 54#include <linux/semaphore.h>
45229b42 55#include <linux/stringify.h>
7ab24bfd 56#include <linux/vmalloc.h>
a2fbb9ea 57
a2fbb9ea
ET
58#include "bnx2x.h"
59#include "bnx2x_init.h"
94a78b79 60#include "bnx2x_init_ops.h"
9f6c9258 61#include "bnx2x_cmn.h"
1ab4434c 62#include "bnx2x_vfpf.h"
e4901dde 63#include "bnx2x_dcb.h"
042181f5 64#include "bnx2x_sp.h"
a2fbb9ea 65
94a78b79
VZ
66#include <linux/firmware.h>
67#include "bnx2x_fw_file_hdr.h"
68/* FW files */
45229b42
BH
69#define FW_FILE_VERSION \
70 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
71 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
72 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
73 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
560131f3
DK
74#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
75#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
f2e0899f 76#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
94a78b79 77
34f80b04
EG
78/* Time in jiffies before concluding the transmitter is hung */
79#define TX_TIMEOUT (5*HZ)
a2fbb9ea 80
0329aba1 81static char version[] =
619c5cb6 82 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
83 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
84
24e3fcef 85MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 86MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
87 "BCM57710/57711/57711E/"
88 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
89 "57840/57840_MF Driver");
a2fbb9ea
ET
90MODULE_LICENSE("GPL");
91MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
92MODULE_FIRMWARE(FW_FILE_NAME_E1);
93MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 94MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 95
d6214d7a 96int num_queues;
54b9ddaa 97module_param(num_queues, int, 0);
96305234
DK
98MODULE_PARM_DESC(num_queues,
99 " Set number of queues (default is as a number of CPUs)");
555f6c78 100
19680c48 101static int disable_tpa;
19680c48 102module_param(disable_tpa, int, 0);
9898f86d 103MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 104
9ee3d37b
DK
105#define INT_MODE_INTx 1
106#define INT_MODE_MSI 2
0e8d2ec5 107int int_mode;
8badd27a 108module_param(int_mode, int, 0);
619c5cb6 109MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 110 "(1 INT#x; 2 MSI)");
8badd27a 111
a18f5128
EG
112static int dropless_fc;
113module_param(dropless_fc, int, 0);
114MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
115
8d5726c4
EG
116static int mrrs = -1;
117module_param(mrrs, int, 0);
118MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
119
9898f86d 120static int debug;
a2fbb9ea 121module_param(debug, int, 0);
9898f86d
EG
122MODULE_PARM_DESC(debug, " Default debug msglevel");
123
619c5cb6 124struct workqueue_struct *bnx2x_wq;
ec6ba945 125
1ef1d45a
BW
126struct bnx2x_mac_vals {
127 u32 xmac_addr;
128 u32 xmac_val;
129 u32 emac_addr;
130 u32 emac_val;
131 u32 umac_addr;
132 u32 umac_val;
133 u32 bmac_addr;
134 u32 bmac_val[2];
135};
136
a2fbb9ea
ET
137enum bnx2x_board_type {
138 BCM57710 = 0,
619c5cb6
VZ
139 BCM57711,
140 BCM57711E,
141 BCM57712,
142 BCM57712_MF,
1ab4434c 143 BCM57712_VF,
619c5cb6
VZ
144 BCM57800,
145 BCM57800_MF,
1ab4434c 146 BCM57800_VF,
619c5cb6
VZ
147 BCM57810,
148 BCM57810_MF,
1ab4434c 149 BCM57810_VF,
c3def943
YM
150 BCM57840_4_10,
151 BCM57840_2_20,
7e8e02df 152 BCM57840_MF,
1ab4434c 153 BCM57840_VF,
7e8e02df 154 BCM57811,
1ab4434c
AE
155 BCM57811_MF,
156 BCM57840_O,
157 BCM57840_MFO,
158 BCM57811_VF
a2fbb9ea
ET
159};
160
34f80b04 161/* indexed by board_type, above */
53a10565 162static struct {
a2fbb9ea 163 char *name;
0329aba1 164} board_info[] = {
1ab4434c
AE
165 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
166 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
167 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
168 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
169 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
170 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
171 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
172 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
173 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
174 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
175 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
176 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
177 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
178 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
179 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
180 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
181 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
182 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
183 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
184 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
185 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
a2fbb9ea
ET
186};
187
619c5cb6
VZ
188#ifndef PCI_DEVICE_ID_NX2_57710
189#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
190#endif
191#ifndef PCI_DEVICE_ID_NX2_57711
192#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
193#endif
194#ifndef PCI_DEVICE_ID_NX2_57711E
195#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
196#endif
197#ifndef PCI_DEVICE_ID_NX2_57712
198#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
199#endif
200#ifndef PCI_DEVICE_ID_NX2_57712_MF
201#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
202#endif
8395be5e
AE
203#ifndef PCI_DEVICE_ID_NX2_57712_VF
204#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
205#endif
619c5cb6
VZ
206#ifndef PCI_DEVICE_ID_NX2_57800
207#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
208#endif
209#ifndef PCI_DEVICE_ID_NX2_57800_MF
210#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
211#endif
8395be5e
AE
212#ifndef PCI_DEVICE_ID_NX2_57800_VF
213#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
214#endif
619c5cb6
VZ
215#ifndef PCI_DEVICE_ID_NX2_57810
216#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
217#endif
218#ifndef PCI_DEVICE_ID_NX2_57810_MF
219#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
220#endif
c3def943
YM
221#ifndef PCI_DEVICE_ID_NX2_57840_O
222#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
223#endif
8395be5e
AE
224#ifndef PCI_DEVICE_ID_NX2_57810_VF
225#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
226#endif
c3def943
YM
227#ifndef PCI_DEVICE_ID_NX2_57840_4_10
228#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
229#endif
230#ifndef PCI_DEVICE_ID_NX2_57840_2_20
231#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
232#endif
233#ifndef PCI_DEVICE_ID_NX2_57840_MFO
234#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
619c5cb6
VZ
235#endif
236#ifndef PCI_DEVICE_ID_NX2_57840_MF
237#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
238#endif
8395be5e
AE
239#ifndef PCI_DEVICE_ID_NX2_57840_VF
240#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
241#endif
7e8e02df
BW
242#ifndef PCI_DEVICE_ID_NX2_57811
243#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
244#endif
245#ifndef PCI_DEVICE_ID_NX2_57811_MF
246#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
247#endif
8395be5e
AE
248#ifndef PCI_DEVICE_ID_NX2_57811_VF
249#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
250#endif
251
a3aa1884 252static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6 257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
8395be5e 258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
619c5cb6
VZ
259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
8395be5e 261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
619c5cb6
VZ
262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
c3def943
YM
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
8395be5e 267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
c3def943 268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
619c5cb6 269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
8395be5e 270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
7e8e02df
BW
271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
8395be5e 273 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
a2fbb9ea
ET
274 { 0 }
275};
276
277MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
278
452427b0
YM
279/* Global resources for unloading a previously loaded device */
280#define BNX2X_PREV_WAIT_NEEDED 1
281static DEFINE_SEMAPHORE(bnx2x_prev_sem);
282static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
283/****************************************************************************
284* General service functions
285****************************************************************************/
286
1191cb83 287static void __storm_memset_dma_mapping(struct bnx2x *bp,
619c5cb6
VZ
288 u32 addr, dma_addr_t mapping)
289{
290 REG_WR(bp, addr, U64_LO(mapping));
291 REG_WR(bp, addr + 4, U64_HI(mapping));
292}
293
1191cb83
ED
294static void storm_memset_spq_addr(struct bnx2x *bp,
295 dma_addr_t mapping, u16 abs_fid)
619c5cb6
VZ
296{
297 u32 addr = XSEM_REG_FAST_MEMORY +
298 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
299
300 __storm_memset_dma_mapping(bp, addr, mapping);
301}
302
1191cb83
ED
303static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
304 u16 pf_id)
523224a3 305{
619c5cb6
VZ
306 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
307 pf_id);
308 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
309 pf_id);
310 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
311 pf_id);
312 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
313 pf_id);
523224a3
DK
314}
315
1191cb83
ED
316static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
317 u8 enable)
619c5cb6
VZ
318{
319 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
320 enable);
321 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
322 enable);
323 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
324 enable);
325 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
326 enable);
327}
523224a3 328
1191cb83
ED
329static void storm_memset_eq_data(struct bnx2x *bp,
330 struct event_ring_data *eq_data,
523224a3
DK
331 u16 pfid)
332{
333 size_t size = sizeof(struct event_ring_data);
334
335 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
336
337 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
338}
339
1191cb83
ED
340static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
341 u16 pfid)
523224a3
DK
342{
343 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
344 REG_WR16(bp, addr, eq_prod);
345}
346
a2fbb9ea
ET
347/* used only at init
348 * locking is done by mcp
349 */
8d96286a 350static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
351{
352 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
353 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
354 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
355 PCICFG_VENDOR_ID_OFFSET);
356}
357
a2fbb9ea
ET
358static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
359{
360 u32 val;
361
362 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
363 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
364 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
365 PCICFG_VENDOR_ID_OFFSET);
366
367 return val;
368}
a2fbb9ea 369
f2e0899f
DK
370#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
371#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
372#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
373#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
374#define DMAE_DP_DST_NONE "dst_addr [none]"
375
fd1fc79d
AE
376void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
377{
378 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
379
380 switch (dmae->opcode & DMAE_COMMAND_DST) {
381 case DMAE_CMD_DST_PCI:
382 if (src_type == DMAE_CMD_SRC_PCI)
383 DP(msglvl, "DMAE: opcode 0x%08x\n"
384 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
385 "comp_addr [%x:%08x], comp_val 0x%08x\n",
386 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
387 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
388 dmae->comp_addr_hi, dmae->comp_addr_lo,
389 dmae->comp_val);
390 else
391 DP(msglvl, "DMAE: opcode 0x%08x\n"
392 "src [%08x], len [%d*4], dst [%x:%08x]\n"
393 "comp_addr [%x:%08x], comp_val 0x%08x\n",
394 dmae->opcode, dmae->src_addr_lo >> 2,
395 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
396 dmae->comp_addr_hi, dmae->comp_addr_lo,
397 dmae->comp_val);
398 break;
399 case DMAE_CMD_DST_GRC:
400 if (src_type == DMAE_CMD_SRC_PCI)
401 DP(msglvl, "DMAE: opcode 0x%08x\n"
402 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
403 "comp_addr [%x:%08x], comp_val 0x%08x\n",
404 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
405 dmae->len, dmae->dst_addr_lo >> 2,
406 dmae->comp_addr_hi, dmae->comp_addr_lo,
407 dmae->comp_val);
408 else
409 DP(msglvl, "DMAE: opcode 0x%08x\n"
410 "src [%08x], len [%d*4], dst [%08x]\n"
411 "comp_addr [%x:%08x], comp_val 0x%08x\n",
412 dmae->opcode, dmae->src_addr_lo >> 2,
413 dmae->len, dmae->dst_addr_lo >> 2,
414 dmae->comp_addr_hi, dmae->comp_addr_lo,
415 dmae->comp_val);
416 break;
417 default:
418 if (src_type == DMAE_CMD_SRC_PCI)
419 DP(msglvl, "DMAE: opcode 0x%08x\n"
420 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
421 "comp_addr [%x:%08x] comp_val 0x%08x\n",
422 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
423 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
424 dmae->comp_val);
425 else
426 DP(msglvl, "DMAE: opcode 0x%08x\n"
427 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
428 "comp_addr [%x:%08x] comp_val 0x%08x\n",
429 dmae->opcode, dmae->src_addr_lo >> 2,
430 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
431 dmae->comp_val);
432 break;
433 }
434}
f2e0899f 435
a2fbb9ea 436/* copy command into DMAE command memory and set DMAE command go */
6c719d00 437void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
438{
439 u32 cmd_offset;
440 int i;
441
442 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
443 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
444 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
445 }
446 REG_WR(bp, dmae_reg_go_c[idx], 1);
447}
448
f2e0899f 449u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 450{
f2e0899f
DK
451 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
452 DMAE_CMD_C_ENABLE);
453}
ad8d3948 454
f2e0899f
DK
455u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
456{
457 return opcode & ~DMAE_CMD_SRC_RESET;
458}
ad8d3948 459
f2e0899f
DK
460u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
461 bool with_comp, u8 comp_type)
462{
463 u32 opcode = 0;
464
465 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
466 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 467
f2e0899f
DK
468 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
469
470 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
471 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
472 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 473 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 474
a2fbb9ea 475#ifdef __BIG_ENDIAN
f2e0899f 476 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 477#else
f2e0899f 478 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 479#endif
f2e0899f
DK
480 if (with_comp)
481 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
482 return opcode;
483}
484
fd1fc79d 485void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
8d96286a 486 struct dmae_command *dmae,
487 u8 src_type, u8 dst_type)
f2e0899f
DK
488{
489 memset(dmae, 0, sizeof(struct dmae_command));
490
491 /* set the opcode */
492 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
493 true, DMAE_COMP_PCI);
494
495 /* fill in the completion parameters */
496 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
497 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
498 dmae->comp_val = DMAE_COMP_VAL;
499}
500
fd1fc79d
AE
501/* issue a dmae command over the init-channel and wait for completion */
502int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
f2e0899f
DK
503{
504 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
5e374b5a 505 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
506 int rc = 0;
507
619c5cb6
VZ
508 /*
509 * Lock the dmae channel. Disable BHs to prevent a dead-lock
510 * as long as this code is called both from syscall context and
511 * from ndo_set_rx_mode() flow that may be called from BH.
512 */
6e30dd4e 513 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 514
f2e0899f 515 /* reset completion */
a2fbb9ea
ET
516 *wb_comp = 0;
517
f2e0899f
DK
518 /* post the command on the channel used for initializations */
519 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 520
f2e0899f 521 /* wait for completion */
a2fbb9ea 522 udelay(5);
f2e0899f 523 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 524
95c6c616
AE
525 if (!cnt ||
526 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
527 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 528 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
529 rc = DMAE_TIMEOUT;
530 goto unlock;
a2fbb9ea 531 }
ad8d3948 532 cnt--;
f2e0899f 533 udelay(50);
a2fbb9ea 534 }
f2e0899f
DK
535 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
536 BNX2X_ERR("DMAE PCI error!\n");
537 rc = DMAE_PCI_ERROR;
538 }
539
f2e0899f 540unlock:
6e30dd4e 541 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
542 return rc;
543}
544
545void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
546 u32 len32)
547{
548 struct dmae_command dmae;
549
550 if (!bp->dmae_ready) {
551 u32 *data = bnx2x_sp(bp, wb_data[0]);
552
127a425e
AE
553 if (CHIP_IS_E1(bp))
554 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
555 else
556 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
557 return;
558 }
559
560 /* set opcode and fixed command fields */
561 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
562
563 /* fill in addresses and len */
564 dmae.src_addr_lo = U64_LO(dma_addr);
565 dmae.src_addr_hi = U64_HI(dma_addr);
566 dmae.dst_addr_lo = dst_addr >> 2;
567 dmae.dst_addr_hi = 0;
568 dmae.len = len32;
569
f2e0899f
DK
570 /* issue the command and wait for completion */
571 bnx2x_issue_dmae_with_comp(bp, &dmae);
a2fbb9ea
ET
572}
573
c18487ee 574void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 575{
5ff7b6d4 576 struct dmae_command dmae;
ad8d3948
EG
577
578 if (!bp->dmae_ready) {
579 u32 *data = bnx2x_sp(bp, wb_data[0]);
580 int i;
581
51c1a580 582 if (CHIP_IS_E1(bp))
127a425e
AE
583 for (i = 0; i < len32; i++)
584 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 585 else
127a425e
AE
586 for (i = 0; i < len32; i++)
587 data[i] = REG_RD(bp, src_addr + i*4);
588
ad8d3948
EG
589 return;
590 }
591
f2e0899f
DK
592 /* set opcode and fixed command fields */
593 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 594
f2e0899f 595 /* fill in addresses and len */
5ff7b6d4
EG
596 dmae.src_addr_lo = src_addr >> 2;
597 dmae.src_addr_hi = 0;
598 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
599 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
600 dmae.len = len32;
ad8d3948 601
f2e0899f
DK
602 /* issue the command and wait for completion */
603 bnx2x_issue_dmae_with_comp(bp, &dmae);
ad8d3948
EG
604}
605
8d96286a 606static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
607 u32 addr, u32 len)
573f2035 608{
02e3c6cb 609 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
610 int offset = 0;
611
02e3c6cb 612 while (len > dmae_wr_max) {
573f2035 613 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
614 addr + offset, dmae_wr_max);
615 offset += dmae_wr_max * 4;
616 len -= dmae_wr_max;
573f2035
EG
617 }
618
619 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
620}
621
a2fbb9ea
ET
622static int bnx2x_mc_assert(struct bnx2x *bp)
623{
a2fbb9ea 624 char last_idx;
34f80b04
EG
625 int i, rc = 0;
626 u32 row0, row1, row2, row3;
627
628 /* XSTORM */
629 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
630 XSTORM_ASSERT_LIST_INDEX_OFFSET);
631 if (last_idx)
632 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
633
634 /* print the asserts */
635 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
636
637 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
638 XSTORM_ASSERT_LIST_OFFSET(i));
639 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
640 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
641 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
642 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
643 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
644 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
645
646 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 647 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
648 i, row3, row2, row1, row0);
649 rc++;
650 } else {
651 break;
652 }
653 }
654
655 /* TSTORM */
656 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
657 TSTORM_ASSERT_LIST_INDEX_OFFSET);
658 if (last_idx)
659 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
660
661 /* print the asserts */
662 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
663
664 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
665 TSTORM_ASSERT_LIST_OFFSET(i));
666 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
667 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
668 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
669 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
670 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
671 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
672
673 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 674 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
675 i, row3, row2, row1, row0);
676 rc++;
677 } else {
678 break;
679 }
680 }
681
682 /* CSTORM */
683 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
684 CSTORM_ASSERT_LIST_INDEX_OFFSET);
685 if (last_idx)
686 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
687
688 /* print the asserts */
689 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
690
691 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
692 CSTORM_ASSERT_LIST_OFFSET(i));
693 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
694 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
695 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
696 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
697 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
698 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
699
700 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 701 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
702 i, row3, row2, row1, row0);
703 rc++;
704 } else {
705 break;
706 }
707 }
708
709 /* USTORM */
710 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
711 USTORM_ASSERT_LIST_INDEX_OFFSET);
712 if (last_idx)
713 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
714
715 /* print the asserts */
716 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
717
718 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
719 USTORM_ASSERT_LIST_OFFSET(i));
720 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
721 USTORM_ASSERT_LIST_OFFSET(i) + 4);
722 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
723 USTORM_ASSERT_LIST_OFFSET(i) + 8);
724 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
725 USTORM_ASSERT_LIST_OFFSET(i) + 12);
726
727 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 728 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
729 i, row3, row2, row1, row0);
730 rc++;
731 } else {
732 break;
a2fbb9ea
ET
733 }
734 }
34f80b04 735
a2fbb9ea
ET
736 return rc;
737}
c14423fe 738
7a25cc73 739void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 740{
7a25cc73 741 u32 addr, val;
a2fbb9ea 742 u32 mark, offset;
4781bfad 743 __be32 data[9];
a2fbb9ea 744 int word;
f2e0899f 745 u32 trace_shmem_base;
2145a920
VZ
746 if (BP_NOMCP(bp)) {
747 BNX2X_ERR("NO MCP - can not dump\n");
748 return;
749 }
7a25cc73
DK
750 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
751 (bp->common.bc_ver & 0xff0000) >> 16,
752 (bp->common.bc_ver & 0xff00) >> 8,
753 (bp->common.bc_ver & 0xff));
754
755 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
756 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 757 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 758
f2e0899f
DK
759 if (BP_PATH(bp) == 0)
760 trace_shmem_base = bp->common.shmem_base;
761 else
762 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
de128804
DK
763 addr = trace_shmem_base - 0x800;
764
765 /* validate TRCB signature */
766 mark = REG_RD(bp, addr);
767 if (mark != MFW_TRACE_SIGNATURE) {
768 BNX2X_ERR("Trace buffer signature is missing.");
769 return ;
770 }
771
772 /* read cyclic buffer pointer */
773 addr += 4;
cdaa7cb8 774 mark = REG_RD(bp, addr);
f2e0899f
DK
775 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
776 + ((mark + 0x3) & ~0x3) - 0x08000000;
7a25cc73 777 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 778
7a25cc73 779 printk("%s", lvl);
2de67439
YM
780
781 /* dump buffer after the mark */
f2e0899f 782 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 783 for (word = 0; word < 8; word++)
cdaa7cb8 784 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 785 data[8] = 0x0;
7995c64e 786 pr_cont("%s", (char *)data);
a2fbb9ea 787 }
2de67439
YM
788
789 /* dump buffer before the mark */
cdaa7cb8 790 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 791 for (word = 0; word < 8; word++)
cdaa7cb8 792 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 793 data[8] = 0x0;
7995c64e 794 pr_cont("%s", (char *)data);
a2fbb9ea 795 }
7a25cc73
DK
796 printk("%s" "end of fw dump\n", lvl);
797}
798
1191cb83 799static void bnx2x_fw_dump(struct bnx2x *bp)
7a25cc73
DK
800{
801 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
802}
803
823e1d90
YM
804static void bnx2x_hc_int_disable(struct bnx2x *bp)
805{
806 int port = BP_PORT(bp);
807 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
808 u32 val = REG_RD(bp, addr);
809
810 /* in E1 we must use only PCI configuration space to disable
16a5fd92
YM
811 * MSI/MSIX capability
812 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
823e1d90
YM
813 */
814 if (CHIP_IS_E1(bp)) {
815 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
816 * Use mask register to prevent from HC sending interrupts
817 * after we exit the function
818 */
819 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
820
821 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
822 HC_CONFIG_0_REG_INT_LINE_EN_0 |
823 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
824 } else
825 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
826 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
827 HC_CONFIG_0_REG_INT_LINE_EN_0 |
828 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
829
830 DP(NETIF_MSG_IFDOWN,
831 "write %x to HC %d (addr 0x%x)\n",
832 val, port, addr);
833
834 /* flush all outstanding writes */
835 mmiowb();
836
837 REG_WR(bp, addr, val);
838 if (REG_RD(bp, addr) != val)
839 BNX2X_ERR("BUG! proper val not read from IGU!\n");
840}
841
842static void bnx2x_igu_int_disable(struct bnx2x *bp)
843{
844 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
845
846 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
847 IGU_PF_CONF_INT_LINE_EN |
848 IGU_PF_CONF_ATTN_BIT_EN);
849
850 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
851
852 /* flush all outstanding writes */
853 mmiowb();
854
855 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
856 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
857 BNX2X_ERR("BUG! proper val not read from IGU!\n");
858}
859
860static void bnx2x_int_disable(struct bnx2x *bp)
861{
862 if (bp->common.int_block == INT_BLOCK_HC)
863 bnx2x_hc_int_disable(bp);
864 else
865 bnx2x_igu_int_disable(bp);
866}
867
868void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
a2fbb9ea
ET
869{
870 int i;
523224a3
DK
871 u16 j;
872 struct hc_sp_status_block_data sp_sb_data;
873 int func = BP_FUNC(bp);
874#ifdef BNX2X_STOP_ON_ERROR
875 u16 start = 0, end = 0;
6383c0b3 876 u8 cos;
523224a3 877#endif
823e1d90
YM
878 if (disable_int)
879 bnx2x_int_disable(bp);
a2fbb9ea 880
66e855f3 881 bp->stats_state = STATS_STATE_DISABLED;
7a752993 882 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
883 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
884
a2fbb9ea
ET
885 BNX2X_ERR("begin crash dump -----------------\n");
886
8440d2b6
EG
887 /* Indices */
888 /* Common */
51c1a580 889 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
890 bp->def_idx, bp->def_att_idx, bp->attn_state,
891 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
892 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
893 bp->def_status_blk->atten_status_block.attn_bits,
894 bp->def_status_blk->atten_status_block.attn_bits_ack,
895 bp->def_status_blk->atten_status_block.status_block_id,
896 bp->def_status_blk->atten_status_block.attn_bits_index);
897 BNX2X_ERR(" def (");
898 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
899 pr_cont("0x%x%s",
f1deab50
JP
900 bp->def_status_blk->sp_sb.index_values[i],
901 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
902
903 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
904 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
905 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
906 i*sizeof(u32));
907
f1deab50 908 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
909 sp_sb_data.igu_sb_id,
910 sp_sb_data.igu_seg_id,
911 sp_sb_data.p_func.pf_id,
912 sp_sb_data.p_func.vnic_id,
913 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
914 sp_sb_data.p_func.vf_valid,
915 sp_sb_data.state);
523224a3 916
ec6ba945 917 for_each_eth_queue(bp, i) {
a2fbb9ea 918 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 919 int loop;
f2e0899f 920 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
921 struct hc_status_block_data_e1x sb_data_e1x;
922 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
923 CHIP_IS_E1x(bp) ?
924 sb_data_e1x.common.state_machine :
925 sb_data_e2.common.state_machine;
523224a3 926 struct hc_index_data *hc_index_p =
619c5cb6
VZ
927 CHIP_IS_E1x(bp) ?
928 sb_data_e1x.index_data :
929 sb_data_e2.index_data;
6383c0b3 930 u8 data_size, cos;
523224a3 931 u32 *sb_data_p;
6383c0b3 932 struct bnx2x_fp_txdata txdata;
523224a3
DK
933
934 /* Rx */
51c1a580 935 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 936 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 937 fp->rx_comp_prod,
66e855f3 938 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 939 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 940 fp->rx_sge_prod, fp->last_max_sge,
523224a3 941 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 942
523224a3 943 /* Tx */
6383c0b3
AE
944 for_each_cos_in_tx_queue(fp, cos)
945 {
65565884 946 txdata = *fp->txdata_ptr[cos];
51c1a580 947 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
948 i, txdata.tx_pkt_prod,
949 txdata.tx_pkt_cons, txdata.tx_bd_prod,
950 txdata.tx_bd_cons,
951 le16_to_cpu(*txdata.tx_cons_sb));
952 }
523224a3 953
619c5cb6
VZ
954 loop = CHIP_IS_E1x(bp) ?
955 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
956
957 /* host sb data */
958
ec6ba945
VZ
959 if (IS_FCOE_FP(fp))
960 continue;
55c11941 961
523224a3
DK
962 BNX2X_ERR(" run indexes (");
963 for (j = 0; j < HC_SB_MAX_SM; j++)
964 pr_cont("0x%x%s",
965 fp->sb_running_index[j],
966 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
967
968 BNX2X_ERR(" indexes (");
969 for (j = 0; j < loop; j++)
970 pr_cont("0x%x%s",
971 fp->sb_index_values[j],
972 (j == loop - 1) ? ")" : " ");
973 /* fw sb data */
619c5cb6
VZ
974 data_size = CHIP_IS_E1x(bp) ?
975 sizeof(struct hc_status_block_data_e1x) :
976 sizeof(struct hc_status_block_data_e2);
523224a3 977 data_size /= sizeof(u32);
619c5cb6
VZ
978 sb_data_p = CHIP_IS_E1x(bp) ?
979 (u32 *)&sb_data_e1x :
980 (u32 *)&sb_data_e2;
523224a3
DK
981 /* copy sb data in here */
982 for (j = 0; j < data_size; j++)
983 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
984 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
985 j * sizeof(u32));
986
619c5cb6 987 if (!CHIP_IS_E1x(bp)) {
51c1a580 988 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
989 sb_data_e2.common.p_func.pf_id,
990 sb_data_e2.common.p_func.vf_id,
991 sb_data_e2.common.p_func.vf_valid,
992 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
993 sb_data_e2.common.same_igu_sb_1b,
994 sb_data_e2.common.state);
f2e0899f 995 } else {
51c1a580 996 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
997 sb_data_e1x.common.p_func.pf_id,
998 sb_data_e1x.common.p_func.vf_id,
999 sb_data_e1x.common.p_func.vf_valid,
1000 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
1001 sb_data_e1x.common.same_igu_sb_1b,
1002 sb_data_e1x.common.state);
f2e0899f 1003 }
523224a3
DK
1004
1005 /* SB_SMs data */
1006 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
1007 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",
1008 j, hc_sm_p[j].__flags,
1009 hc_sm_p[j].igu_sb_id,
1010 hc_sm_p[j].igu_seg_id,
1011 hc_sm_p[j].time_to_expire,
1012 hc_sm_p[j].timer_value);
523224a3
DK
1013 }
1014
16a5fd92 1015 /* Indices data */
523224a3 1016 for (j = 0; j < loop; j++) {
51c1a580 1017 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
1018 hc_index_p[j].flags,
1019 hc_index_p[j].timeout);
1020 }
8440d2b6 1021 }
a2fbb9ea 1022
523224a3 1023#ifdef BNX2X_STOP_ON_ERROR
04c46736
YM
1024
1025 /* event queue */
1026 for (i = 0; i < NUM_EQ_DESC; i++) {
1027 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
1028
1029 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1030 i, bp->eq_ring[i].message.opcode,
1031 bp->eq_ring[i].message.error);
1032 BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
1033 }
1034
8440d2b6
EG
1035 /* Rings */
1036 /* Rx */
55c11941 1037 for_each_valid_rx_queue(bp, i) {
8440d2b6 1038 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
1039
1040 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1041 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 1042 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
1043 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1044 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1045
c3eefaf6 1046 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 1047 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
1048 }
1049
3196a88a
EG
1050 start = RX_SGE(fp->rx_sge_prod);
1051 end = RX_SGE(fp->last_max_sge);
8440d2b6 1052 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
1053 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1054 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1055
c3eefaf6
EG
1056 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1057 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
1058 }
1059
a2fbb9ea
ET
1060 start = RCQ_BD(fp->rx_comp_cons - 10);
1061 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 1062 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
1063 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1064
c3eefaf6
EG
1065 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1066 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
1067 }
1068 }
1069
8440d2b6 1070 /* Tx */
55c11941 1071 for_each_valid_tx_queue(bp, i) {
8440d2b6 1072 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3 1073 for_each_cos_in_tx_queue(fp, cos) {
65565884 1074 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
6383c0b3
AE
1075
1076 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1077 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1078 for (j = start; j != end; j = TX_BD(j + 1)) {
1079 struct sw_tx_bd *sw_bd =
1080 &txdata->tx_buf_ring[j];
1081
51c1a580 1082 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
1083 i, cos, j, sw_bd->skb,
1084 sw_bd->first_bd);
1085 }
8440d2b6 1086
6383c0b3
AE
1087 start = TX_BD(txdata->tx_bd_cons - 10);
1088 end = TX_BD(txdata->tx_bd_cons + 254);
1089 for (j = start; j != end; j = TX_BD(j + 1)) {
1090 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 1091
51c1a580 1092 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
1093 i, cos, j, tx_bd[0], tx_bd[1],
1094 tx_bd[2], tx_bd[3]);
1095 }
8440d2b6
EG
1096 }
1097 }
523224a3 1098#endif
34f80b04 1099 bnx2x_fw_dump(bp);
a2fbb9ea
ET
1100 bnx2x_mc_assert(bp);
1101 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
1102}
1103
619c5cb6
VZ
1104/*
1105 * FLR Support for E2
1106 *
1107 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1108 * initialization.
1109 */
16a5fd92 1110#define FLR_WAIT_USEC 10000 /* 10 milliseconds */
89db4ad8
AE
1111#define FLR_WAIT_INTERVAL 50 /* usec */
1112#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
1113
1114struct pbf_pN_buf_regs {
1115 int pN;
1116 u32 init_crd;
1117 u32 crd;
1118 u32 crd_freed;
1119};
1120
1121struct pbf_pN_cmd_regs {
1122 int pN;
1123 u32 lines_occup;
1124 u32 lines_freed;
1125};
1126
1127static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1128 struct pbf_pN_buf_regs *regs,
1129 u32 poll_count)
1130{
1131 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1132 u32 cur_cnt = poll_count;
1133
1134 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1135 crd = crd_start = REG_RD(bp, regs->crd);
1136 init_crd = REG_RD(bp, regs->init_crd);
1137
1138 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1139 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1140 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1141
1142 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1143 (init_crd - crd_start))) {
1144 if (cur_cnt--) {
89db4ad8 1145 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1146 crd = REG_RD(bp, regs->crd);
1147 crd_freed = REG_RD(bp, regs->crd_freed);
1148 } else {
1149 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1150 regs->pN);
1151 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1152 regs->pN, crd);
1153 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1154 regs->pN, crd_freed);
1155 break;
1156 }
1157 }
1158 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 1159 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1160}
1161
1162static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1163 struct pbf_pN_cmd_regs *regs,
1164 u32 poll_count)
1165{
1166 u32 occup, to_free, freed, freed_start;
1167 u32 cur_cnt = poll_count;
1168
1169 occup = to_free = REG_RD(bp, regs->lines_occup);
1170 freed = freed_start = REG_RD(bp, regs->lines_freed);
1171
1172 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1173 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1174
1175 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1176 if (cur_cnt--) {
89db4ad8 1177 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1178 occup = REG_RD(bp, regs->lines_occup);
1179 freed = REG_RD(bp, regs->lines_freed);
1180 } else {
1181 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1182 regs->pN);
1183 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1184 regs->pN, occup);
1185 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1186 regs->pN, freed);
1187 break;
1188 }
1189 }
1190 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 1191 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1192}
1193
1191cb83
ED
1194static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1195 u32 expected, u32 poll_count)
619c5cb6
VZ
1196{
1197 u32 cur_cnt = poll_count;
1198 u32 val;
1199
1200 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 1201 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1202
1203 return val;
1204}
1205
d16132ce
AE
1206int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1207 char *msg, u32 poll_cnt)
619c5cb6
VZ
1208{
1209 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1210 if (val != 0) {
1211 BNX2X_ERR("%s usage count=%d\n", msg, val);
1212 return 1;
1213 }
1214 return 0;
1215}
1216
d16132ce
AE
1217/* Common routines with VF FLR cleanup */
1218u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
619c5cb6
VZ
1219{
1220 /* adjust polling timeout */
1221 if (CHIP_REV_IS_EMUL(bp))
1222 return FLR_POLL_CNT * 2000;
1223
1224 if (CHIP_REV_IS_FPGA(bp))
1225 return FLR_POLL_CNT * 120;
1226
1227 return FLR_POLL_CNT;
1228}
1229
d16132ce 1230void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
619c5cb6
VZ
1231{
1232 struct pbf_pN_cmd_regs cmd_regs[] = {
1233 {0, (CHIP_IS_E3B0(bp)) ?
1234 PBF_REG_TQ_OCCUPANCY_Q0 :
1235 PBF_REG_P0_TQ_OCCUPANCY,
1236 (CHIP_IS_E3B0(bp)) ?
1237 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1238 PBF_REG_P0_TQ_LINES_FREED_CNT},
1239 {1, (CHIP_IS_E3B0(bp)) ?
1240 PBF_REG_TQ_OCCUPANCY_Q1 :
1241 PBF_REG_P1_TQ_OCCUPANCY,
1242 (CHIP_IS_E3B0(bp)) ?
1243 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1244 PBF_REG_P1_TQ_LINES_FREED_CNT},
1245 {4, (CHIP_IS_E3B0(bp)) ?
1246 PBF_REG_TQ_OCCUPANCY_LB_Q :
1247 PBF_REG_P4_TQ_OCCUPANCY,
1248 (CHIP_IS_E3B0(bp)) ?
1249 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1250 PBF_REG_P4_TQ_LINES_FREED_CNT}
1251 };
1252
1253 struct pbf_pN_buf_regs buf_regs[] = {
1254 {0, (CHIP_IS_E3B0(bp)) ?
1255 PBF_REG_INIT_CRD_Q0 :
1256 PBF_REG_P0_INIT_CRD ,
1257 (CHIP_IS_E3B0(bp)) ?
1258 PBF_REG_CREDIT_Q0 :
1259 PBF_REG_P0_CREDIT,
1260 (CHIP_IS_E3B0(bp)) ?
1261 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1262 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1263 {1, (CHIP_IS_E3B0(bp)) ?
1264 PBF_REG_INIT_CRD_Q1 :
1265 PBF_REG_P1_INIT_CRD,
1266 (CHIP_IS_E3B0(bp)) ?
1267 PBF_REG_CREDIT_Q1 :
1268 PBF_REG_P1_CREDIT,
1269 (CHIP_IS_E3B0(bp)) ?
1270 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1271 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1272 {4, (CHIP_IS_E3B0(bp)) ?
1273 PBF_REG_INIT_CRD_LB_Q :
1274 PBF_REG_P4_INIT_CRD,
1275 (CHIP_IS_E3B0(bp)) ?
1276 PBF_REG_CREDIT_LB_Q :
1277 PBF_REG_P4_CREDIT,
1278 (CHIP_IS_E3B0(bp)) ?
1279 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1280 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1281 };
1282
1283 int i;
1284
1285 /* Verify the command queues are flushed P0, P1, P4 */
1286 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1287 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1288
619c5cb6
VZ
1289 /* Verify the transmission buffers are flushed P0, P1, P4 */
1290 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1291 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1292}
1293
1294#define OP_GEN_PARAM(param) \
1295 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1296
1297#define OP_GEN_TYPE(type) \
1298 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1299
1300#define OP_GEN_AGG_VECT(index) \
1301 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1302
d16132ce 1303int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
619c5cb6 1304{
86564c3f 1305 u32 op_gen_command = 0;
619c5cb6
VZ
1306 u32 comp_addr = BAR_CSTRORM_INTMEM +
1307 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1308 int ret = 0;
1309
1310 if (REG_RD(bp, comp_addr)) {
89db4ad8 1311 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1312 return 1;
1313 }
1314
86564c3f
YM
1315 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1316 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1317 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1318 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
619c5cb6 1319
89db4ad8 1320 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
86564c3f 1321 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
619c5cb6
VZ
1322
1323 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1324 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1325 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1326 (REG_RD(bp, comp_addr)));
d16132ce
AE
1327 bnx2x_panic();
1328 return 1;
619c5cb6 1329 }
16a5fd92 1330 /* Zero completion for next FLR */
619c5cb6
VZ
1331 REG_WR(bp, comp_addr, 0);
1332
1333 return ret;
1334}
1335
b56e9670 1336u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
619c5cb6 1337{
619c5cb6
VZ
1338 u16 status;
1339
2a80eebc 1340 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
619c5cb6
VZ
1341 return status & PCI_EXP_DEVSTA_TRPND;
1342}
1343
1344/* PF FLR specific routines
1345*/
1346static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1347{
619c5cb6
VZ
1348 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1349 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1350 CFC_REG_NUM_LCIDS_INSIDE_PF,
1351 "CFC PF usage counter timed out",
1352 poll_cnt))
1353 return 1;
1354
619c5cb6
VZ
1355 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1356 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1357 DORQ_REG_PF_USAGE_CNT,
1358 "DQ PF usage counter timed out",
1359 poll_cnt))
1360 return 1;
1361
1362 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1363 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1364 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1365 "QM PF usage counter timed out",
1366 poll_cnt))
1367 return 1;
1368
1369 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1370 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1371 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1372 "Timers VNIC usage counter timed out",
1373 poll_cnt))
1374 return 1;
1375 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1376 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1377 "Timers NUM_SCANS usage counter timed out",
1378 poll_cnt))
1379 return 1;
1380
1381 /* Wait DMAE PF usage counter to zero */
1382 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1383 dmae_reg_go_c[INIT_DMAE_C(bp)],
1384 "DMAE dommand register timed out",
1385 poll_cnt))
1386 return 1;
1387
1388 return 0;
1389}
1390
1391static void bnx2x_hw_enable_status(struct bnx2x *bp)
1392{
1393 u32 val;
1394
1395 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1396 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1397
1398 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1399 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1400
1401 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1402 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1403
1404 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1405 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1406
1407 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1408 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1409
1410 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1411 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1412
1413 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1414 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1415
1416 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1417 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1418 val);
1419}
1420
1421static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1422{
1423 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1424
1425 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1426
1427 /* Re-enable PF target read access */
1428 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1429
1430 /* Poll HW usage counters */
89db4ad8 1431 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1432 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1433 return -EBUSY;
1434
1435 /* Zero the igu 'trailing edge' and 'leading edge' */
1436
1437 /* Send the FW cleanup command */
1438 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1439 return -EBUSY;
1440
1441 /* ATC cleanup */
1442
1443 /* Verify TX hw is flushed */
1444 bnx2x_tx_hw_flushed(bp, poll_cnt);
1445
1446 /* Wait 100ms (not adjusted according to platform) */
1447 msleep(100);
1448
1449 /* Verify no pending pci transactions */
1450 if (bnx2x_is_pcie_pending(bp->pdev))
1451 BNX2X_ERR("PCIE Transactions still pending\n");
1452
1453 /* Debug */
1454 bnx2x_hw_enable_status(bp);
1455
1456 /*
1457 * Master enable - Due to WB DMAE writes performed before this
1458 * register is re-initialized as part of the regular function init
1459 */
1460 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1461
1462 return 0;
1463}
1464
f2e0899f 1465static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1466{
34f80b04 1467 int port = BP_PORT(bp);
a2fbb9ea
ET
1468 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1469 u32 val = REG_RD(bp, addr);
69c326b3
DK
1470 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1471 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1472 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
a2fbb9ea
ET
1473
1474 if (msix) {
8badd27a
EG
1475 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1476 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1477 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1478 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
69c326b3
DK
1479 if (single_msix)
1480 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
8badd27a
EG
1481 } else if (msi) {
1482 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1483 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1484 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1485 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea
ET
1486 } else {
1487 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1488 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1489 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1490 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1491
a0fd065c 1492 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1493 DP(NETIF_MSG_IFUP,
1494 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1495
a0fd065c 1496 REG_WR(bp, addr, val);
615f8fd9 1497
a0fd065c
DK
1498 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1499 }
a2fbb9ea
ET
1500 }
1501
a0fd065c
DK
1502 if (CHIP_IS_E1(bp))
1503 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1504
51c1a580
MS
1505 DP(NETIF_MSG_IFUP,
1506 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1507 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1508
1509 REG_WR(bp, addr, val);
37dbbf32
EG
1510 /*
1511 * Ensure that HC_CONFIG is written before leading/trailing edge config
1512 */
1513 mmiowb();
1514 barrier();
34f80b04 1515
f2e0899f 1516 if (!CHIP_IS_E1(bp)) {
34f80b04 1517 /* init leading/trailing edge */
fb3bff17 1518 if (IS_MF(bp)) {
3395a033 1519 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1520 if (bp->port.pmf)
4acac6a5
EG
1521 /* enable nig and gpio3 attention */
1522 val |= 0x1100;
34f80b04
EG
1523 } else
1524 val = 0xffff;
1525
1526 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1527 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1528 }
37dbbf32
EG
1529
1530 /* Make sure that interrupts are indeed enabled from here on */
1531 mmiowb();
a2fbb9ea
ET
1532}
1533
f2e0899f
DK
1534static void bnx2x_igu_int_enable(struct bnx2x *bp)
1535{
1536 u32 val;
30a5de77
DK
1537 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1538 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1539 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
f2e0899f
DK
1540
1541 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1542
1543 if (msix) {
1544 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1545 IGU_PF_CONF_SINGLE_ISR_EN);
ebe61d80 1546 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f 1547 IGU_PF_CONF_ATTN_BIT_EN);
30a5de77
DK
1548
1549 if (single_msix)
1550 val |= IGU_PF_CONF_SINGLE_ISR_EN;
f2e0899f
DK
1551 } else if (msi) {
1552 val &= ~IGU_PF_CONF_INT_LINE_EN;
ebe61d80 1553 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f
DK
1554 IGU_PF_CONF_ATTN_BIT_EN |
1555 IGU_PF_CONF_SINGLE_ISR_EN);
1556 } else {
1557 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
ebe61d80 1558 val |= (IGU_PF_CONF_INT_LINE_EN |
f2e0899f
DK
1559 IGU_PF_CONF_ATTN_BIT_EN |
1560 IGU_PF_CONF_SINGLE_ISR_EN);
1561 }
1562
ebe61d80
YM
1563 /* Clean previous status - need to configure igu prior to ack*/
1564 if ((!msix) || single_msix) {
1565 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1566 bnx2x_ack_int(bp);
1567 }
1568
1569 val |= IGU_PF_CONF_FUNC_EN;
1570
51c1a580 1571 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1572 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1573
1574 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1575
79a8557a
YM
1576 if (val & IGU_PF_CONF_INT_LINE_EN)
1577 pci_intx(bp->pdev, true);
1578
f2e0899f
DK
1579 barrier();
1580
1581 /* init leading/trailing edge */
1582 if (IS_MF(bp)) {
3395a033 1583 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1584 if (bp->port.pmf)
1585 /* enable nig and gpio3 attention */
1586 val |= 0x1100;
1587 } else
1588 val = 0xffff;
1589
1590 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1591 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1592
1593 /* Make sure that interrupts are indeed enabled from here on */
1594 mmiowb();
1595}
1596
1597void bnx2x_int_enable(struct bnx2x *bp)
1598{
1599 if (bp->common.int_block == INT_BLOCK_HC)
1600 bnx2x_hc_int_enable(bp);
1601 else
1602 bnx2x_igu_int_enable(bp);
1603}
1604
9f6c9258 1605void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1606{
a2fbb9ea 1607 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1608 int i, offset;
a2fbb9ea 1609
f8ef6e44
YG
1610 if (disable_hw)
1611 /* prevent the HW from sending interrupts */
1612 bnx2x_int_disable(bp);
a2fbb9ea
ET
1613
1614 /* make sure all ISRs are done */
1615 if (msix) {
8badd27a
EG
1616 synchronize_irq(bp->msix_table[0].vector);
1617 offset = 1;
55c11941
MS
1618 if (CNIC_SUPPORT(bp))
1619 offset++;
ec6ba945 1620 for_each_eth_queue(bp, i)
754a2f52 1621 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1622 } else
1623 synchronize_irq(bp->pdev->irq);
1624
1625 /* make sure sp_task is not running */
1cf167f2 1626 cancel_delayed_work(&bp->sp_task);
3deb8167 1627 cancel_delayed_work(&bp->period_task);
1cf167f2 1628 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1629}
1630
34f80b04 1631/* fast path */
a2fbb9ea
ET
1632
1633/*
34f80b04 1634 * General service functions
a2fbb9ea
ET
1635 */
1636
72fd0718
VZ
1637/* Return true if succeeded to acquire the lock */
1638static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1639{
1640 u32 lock_status;
1641 u32 resource_bit = (1 << resource);
1642 int func = BP_FUNC(bp);
1643 u32 hw_lock_control_reg;
1644
51c1a580
MS
1645 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1646 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1647
1648 /* Validating that the resource is within range */
1649 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1650 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1651 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1652 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1653 return false;
72fd0718
VZ
1654 }
1655
1656 if (func <= 5)
1657 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1658 else
1659 hw_lock_control_reg =
1660 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1661
1662 /* Try to acquire the lock */
1663 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1664 lock_status = REG_RD(bp, hw_lock_control_reg);
1665 if (lock_status & resource_bit)
1666 return true;
1667
51c1a580
MS
1668 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1669 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1670 return false;
1671}
1672
c9ee9206
VZ
1673/**
1674 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1675 *
1676 * @bp: driver handle
1677 *
1678 * Returns the recovery leader resource id according to the engine this function
1679 * belongs to. Currently only only 2 engines is supported.
1680 */
1191cb83 1681static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
c9ee9206
VZ
1682{
1683 if (BP_PATH(bp))
1684 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1685 else
1686 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1687}
1688
1689/**
2de67439 1690 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
c9ee9206
VZ
1691 *
1692 * @bp: driver handle
1693 *
2de67439 1694 * Tries to acquire a leader lock for current engine.
c9ee9206 1695 */
1191cb83 1696static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
c9ee9206
VZ
1697{
1698 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1699}
1700
619c5cb6 1701static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
55c11941 1702
fd1fc79d
AE
1703/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1704static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1705{
1706 /* Set the interrupt occurred bit for the sp-task to recognize it
1707 * must ack the interrupt and transition according to the IGU
1708 * state machine.
1709 */
1710 atomic_set(&bp->interrupt_occurred, 1);
1711
1712 /* The sp_task must execute only after this bit
1713 * is set, otherwise we will get out of sync and miss all
1714 * further interrupts. Hence, the barrier.
1715 */
1716 smp_wmb();
1717
1718 /* schedule sp_task to workqueue */
1719 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1720}
3196a88a 1721
619c5cb6 1722void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1723{
1724 struct bnx2x *bp = fp->bp;
1725 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1726 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6 1727 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
15192a8c 1728 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a2fbb9ea 1729
34f80b04 1730 DP(BNX2X_MSG_SP,
a2fbb9ea 1731 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1732 fp->index, cid, command, bp->state,
34f80b04 1733 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1734
fd1fc79d
AE
1735 /* If cid is within VF range, replace the slowpath object with the
1736 * one corresponding to this VF
1737 */
1738 if (cid >= BNX2X_FIRST_VF_CID &&
1739 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1740 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1741
619c5cb6
VZ
1742 switch (command) {
1743 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1744 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1745 drv_cmd = BNX2X_Q_CMD_UPDATE;
1746 break;
d6cae238 1747
619c5cb6 1748 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1749 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1750 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1751 break;
1752
6383c0b3 1753 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1754 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1755 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1756 break;
1757
619c5cb6 1758 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1759 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1760 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1761 break;
1762
619c5cb6 1763 case (RAMROD_CMD_ID_ETH_TERMINATE):
d6cae238 1764 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
619c5cb6 1765 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1766 break;
1767
619c5cb6 1768 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1769 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1770 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1771 break;
619c5cb6
VZ
1772
1773 default:
1774 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1775 command, fp->index);
1776 return;
523224a3 1777 }
3196a88a 1778
619c5cb6
VZ
1779 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1780 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1781 /* q_obj->complete_cmd() failure means that this was
1782 * an unexpected completion.
1783 *
1784 * In this case we don't want to increase the bp->spq_left
1785 * because apparently we haven't sent this command the first
1786 * place.
1787 */
1788#ifdef BNX2X_STOP_ON_ERROR
1789 bnx2x_panic();
1790#else
1791 return;
1792#endif
fd1fc79d
AE
1793 /* SRIOV: reschedule any 'in_progress' operations */
1794 bnx2x_iov_sp_event(bp, cid, true);
619c5cb6 1795
8fe23fbd 1796 smp_mb__before_atomic_inc();
6e30dd4e 1797 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1798 /* push the change in bp->spq_left and towards the memory */
1799 smp_mb__after_atomic_inc();
49d66772 1800
d6cae238
VZ
1801 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1802
a3348722
BW
1803 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1804 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1805 /* if Q update ramrod is completed for last Q in AFEX vif set
1806 * flow, then ACK MCP at the end
1807 *
1808 * mark pending ACK to MCP bit.
1809 * prevent case that both bits are cleared.
1810 * At the end of load/unload driver checks that
2de67439 1811 * sp_state is cleared, and this order prevents
a3348722
BW
1812 * races
1813 */
1814 smp_mb__before_clear_bit();
1815 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1816 wmb();
1817 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1818 smp_mb__after_clear_bit();
1819
fd1fc79d
AE
1820 /* schedule the sp task as mcp ack is required */
1821 bnx2x_schedule_sp_task(bp);
a3348722
BW
1822 }
1823
523224a3 1824 return;
a2fbb9ea
ET
1825}
1826
9f6c9258 1827irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1828{
555f6c78 1829 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1830 u16 status = bnx2x_ack_int(bp);
34f80b04 1831 u16 mask;
ca00392c 1832 int i;
6383c0b3 1833 u8 cos;
a2fbb9ea 1834
34f80b04 1835 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1836 if (unlikely(status == 0)) {
1837 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1838 return IRQ_NONE;
1839 }
f5372251 1840 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1841
3196a88a
EG
1842#ifdef BNX2X_STOP_ON_ERROR
1843 if (unlikely(bp->panic))
1844 return IRQ_HANDLED;
1845#endif
1846
ec6ba945 1847 for_each_eth_queue(bp, i) {
ca00392c 1848 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1849
55c11941 1850 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
ca00392c 1851 if (status & mask) {
619c5cb6 1852 /* Handle Rx or Tx according to SB id */
54b9ddaa 1853 prefetch(fp->rx_cons_sb);
6383c0b3 1854 for_each_cos_in_tx_queue(fp, cos)
65565884 1855 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
523224a3 1856 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1857 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1858 status &= ~mask;
1859 }
a2fbb9ea
ET
1860 }
1861
55c11941
MS
1862 if (CNIC_SUPPORT(bp)) {
1863 mask = 0x2;
1864 if (status & (mask | 0x1)) {
1865 struct cnic_ops *c_ops = NULL;
993ac7b5 1866
ad9b4359
MC
1867 rcu_read_lock();
1868 c_ops = rcu_dereference(bp->cnic_ops);
1869 if (c_ops && (bp->cnic_eth_dev.drv_state &
1870 CNIC_DRV_STATE_HANDLES_IRQ))
1871 c_ops->cnic_handler(bp->cnic_data, NULL);
1872 rcu_read_unlock();
993ac7b5 1873
55c11941
MS
1874 status &= ~mask;
1875 }
993ac7b5 1876 }
a2fbb9ea 1877
34f80b04 1878 if (unlikely(status & 0x1)) {
fd1fc79d
AE
1879
1880 /* schedule sp task to perform default status block work, ack
1881 * attentions and enable interrupts.
1882 */
1883 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
1884
1885 status &= ~0x1;
1886 if (!status)
1887 return IRQ_HANDLED;
1888 }
1889
cdaa7cb8
VZ
1890 if (unlikely(status))
1891 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1892 status);
a2fbb9ea 1893
c18487ee 1894 return IRQ_HANDLED;
a2fbb9ea
ET
1895}
1896
c18487ee
YR
1897/* Link */
1898
1899/*
1900 * General service functions
1901 */
a2fbb9ea 1902
9f6c9258 1903int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1904{
1905 u32 lock_status;
1906 u32 resource_bit = (1 << resource);
4a37fb66
YG
1907 int func = BP_FUNC(bp);
1908 u32 hw_lock_control_reg;
c18487ee 1909 int cnt;
a2fbb9ea 1910
c18487ee
YR
1911 /* Validating that the resource is within range */
1912 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1913 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1914 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1915 return -EINVAL;
1916 }
a2fbb9ea 1917
4a37fb66
YG
1918 if (func <= 5) {
1919 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1920 } else {
1921 hw_lock_control_reg =
1922 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1923 }
1924
c18487ee 1925 /* Validating that the resource is not already taken */
4a37fb66 1926 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1927 if (lock_status & resource_bit) {
51c1a580 1928 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
c18487ee
YR
1929 lock_status, resource_bit);
1930 return -EEXIST;
1931 }
a2fbb9ea 1932
46230476
EG
1933 /* Try for 5 second every 5ms */
1934 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1935 /* Try to acquire the lock */
4a37fb66
YG
1936 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1937 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1938 if (lock_status & resource_bit)
1939 return 0;
a2fbb9ea 1940
c18487ee 1941 msleep(5);
a2fbb9ea 1942 }
51c1a580 1943 BNX2X_ERR("Timeout\n");
c18487ee
YR
1944 return -EAGAIN;
1945}
a2fbb9ea 1946
c9ee9206
VZ
1947int bnx2x_release_leader_lock(struct bnx2x *bp)
1948{
1949 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1950}
1951
9f6c9258 1952int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1953{
1954 u32 lock_status;
1955 u32 resource_bit = (1 << resource);
4a37fb66
YG
1956 int func = BP_FUNC(bp);
1957 u32 hw_lock_control_reg;
a2fbb9ea 1958
c18487ee
YR
1959 /* Validating that the resource is within range */
1960 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1961 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1962 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1963 return -EINVAL;
1964 }
1965
4a37fb66
YG
1966 if (func <= 5) {
1967 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1968 } else {
1969 hw_lock_control_reg =
1970 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1971 }
1972
c18487ee 1973 /* Validating that the resource is currently taken */
4a37fb66 1974 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1975 if (!(lock_status & resource_bit)) {
51c1a580 1976 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
c18487ee
YR
1977 lock_status, resource_bit);
1978 return -EFAULT;
a2fbb9ea
ET
1979 }
1980
9f6c9258
DK
1981 REG_WR(bp, hw_lock_control_reg, resource_bit);
1982 return 0;
c18487ee 1983}
a2fbb9ea 1984
4acac6a5
EG
1985int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1986{
1987 /* The GPIO should be swapped if swap register is set and active */
1988 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1989 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1990 int gpio_shift = gpio_num +
1991 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1992 u32 gpio_mask = (1 << gpio_shift);
1993 u32 gpio_reg;
1994 int value;
1995
1996 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1997 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1998 return -EINVAL;
1999 }
2000
2001 /* read GPIO value */
2002 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2003
2004 /* get the requested pin value */
2005 if ((gpio_reg & gpio_mask) == gpio_mask)
2006 value = 1;
2007 else
2008 value = 0;
2009
2010 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2011
2012 return value;
2013}
2014
17de50b7 2015int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
2016{
2017 /* The GPIO should be swapped if swap register is set and active */
2018 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 2019 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
2020 int gpio_shift = gpio_num +
2021 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2022 u32 gpio_mask = (1 << gpio_shift);
2023 u32 gpio_reg;
a2fbb9ea 2024
c18487ee
YR
2025 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2026 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2027 return -EINVAL;
2028 }
a2fbb9ea 2029
4a37fb66 2030 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
2031 /* read GPIO and mask except the float bits */
2032 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 2033
c18487ee
YR
2034 switch (mode) {
2035 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
2036 DP(NETIF_MSG_LINK,
2037 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
2038 gpio_num, gpio_shift);
2039 /* clear FLOAT and set CLR */
2040 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2041 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2042 break;
a2fbb9ea 2043
c18487ee 2044 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
2045 DP(NETIF_MSG_LINK,
2046 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
2047 gpio_num, gpio_shift);
2048 /* clear FLOAT and set SET */
2049 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2050 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2051 break;
a2fbb9ea 2052
17de50b7 2053 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
2054 DP(NETIF_MSG_LINK,
2055 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
2056 gpio_num, gpio_shift);
2057 /* set FLOAT */
2058 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2059 break;
a2fbb9ea 2060
c18487ee
YR
2061 default:
2062 break;
a2fbb9ea
ET
2063 }
2064
c18487ee 2065 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 2066 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 2067
c18487ee 2068 return 0;
a2fbb9ea
ET
2069}
2070
0d40f0d4
YR
2071int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2072{
2073 u32 gpio_reg = 0;
2074 int rc = 0;
2075
2076 /* Any port swapping should be handled by caller. */
2077
2078 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2079 /* read GPIO and mask except the float bits */
2080 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2081 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2082 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2083 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2084
2085 switch (mode) {
2086 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2087 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2088 /* set CLR */
2089 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2090 break;
2091
2092 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2093 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2094 /* set SET */
2095 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2096 break;
2097
2098 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2099 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2100 /* set FLOAT */
2101 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2102 break;
2103
2104 default:
2105 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2106 rc = -EINVAL;
2107 break;
2108 }
2109
2110 if (rc == 0)
2111 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2112
2113 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2114
2115 return rc;
2116}
2117
4acac6a5
EG
2118int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2119{
2120 /* The GPIO should be swapped if swap register is set and active */
2121 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2122 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2123 int gpio_shift = gpio_num +
2124 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2125 u32 gpio_mask = (1 << gpio_shift);
2126 u32 gpio_reg;
2127
2128 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2129 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2130 return -EINVAL;
2131 }
2132
2133 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2134 /* read GPIO int */
2135 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2136
2137 switch (mode) {
2138 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
2139 DP(NETIF_MSG_LINK,
2140 "Clear GPIO INT %d (shift %d) -> output low\n",
2141 gpio_num, gpio_shift);
4acac6a5
EG
2142 /* clear SET and set CLR */
2143 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2144 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2145 break;
2146
2147 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
2148 DP(NETIF_MSG_LINK,
2149 "Set GPIO INT %d (shift %d) -> output high\n",
2150 gpio_num, gpio_shift);
4acac6a5
EG
2151 /* clear CLR and set SET */
2152 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2153 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2154 break;
2155
2156 default:
2157 break;
2158 }
2159
2160 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2161 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2162
2163 return 0;
2164}
2165
d6d99a3f 2166static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
a2fbb9ea 2167{
c18487ee 2168 u32 spio_reg;
a2fbb9ea 2169
d6d99a3f
YM
2170 /* Only 2 SPIOs are configurable */
2171 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2172 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
c18487ee 2173 return -EINVAL;
a2fbb9ea
ET
2174 }
2175
4a37fb66 2176 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2177 /* read SPIO and mask except the float bits */
d6d99a3f 2178 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
a2fbb9ea 2179
c18487ee 2180 switch (mode) {
d6d99a3f
YM
2181 case MISC_SPIO_OUTPUT_LOW:
2182 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
c18487ee 2183 /* clear FLOAT and set CLR */
d6d99a3f
YM
2184 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2185 spio_reg |= (spio << MISC_SPIO_CLR_POS);
c18487ee 2186 break;
a2fbb9ea 2187
d6d99a3f
YM
2188 case MISC_SPIO_OUTPUT_HIGH:
2189 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
c18487ee 2190 /* clear FLOAT and set SET */
d6d99a3f
YM
2191 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2192 spio_reg |= (spio << MISC_SPIO_SET_POS);
c18487ee 2193 break;
a2fbb9ea 2194
d6d99a3f
YM
2195 case MISC_SPIO_INPUT_HI_Z:
2196 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
c18487ee 2197 /* set FLOAT */
d6d99a3f 2198 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
c18487ee 2199 break;
a2fbb9ea 2200
c18487ee
YR
2201 default:
2202 break;
a2fbb9ea
ET
2203 }
2204
c18487ee 2205 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2206 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2207
a2fbb9ea
ET
2208 return 0;
2209}
2210
9f6c9258 2211void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2212{
a22f0788 2213 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2214 switch (bp->link_vars.ieee_fc &
2215 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2216 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2217 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2218 ADVERTISED_Pause);
c18487ee 2219 break;
356e2385 2220
c18487ee 2221 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2222 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2223 ADVERTISED_Pause);
c18487ee 2224 break;
356e2385 2225
c18487ee 2226 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2227 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2228 break;
356e2385 2229
c18487ee 2230 default:
a22f0788 2231 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2232 ADVERTISED_Pause);
c18487ee
YR
2233 break;
2234 }
2235}
f1410647 2236
cd1dfce2 2237static void bnx2x_set_requested_fc(struct bnx2x *bp)
c18487ee 2238{
cd1dfce2
YM
2239 /* Initialize link parameters structure variables
2240 * It is recommended to turn off RX FC for jumbo frames
2241 * for better performance
2242 */
2243 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2244 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2245 else
2246 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2247}
a2fbb9ea 2248
cd1dfce2
YM
2249int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2250{
2251 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2252 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2253
2254 if (!BP_NOMCP(bp)) {
2255 bnx2x_set_requested_fc(bp);
4a37fb66 2256 bnx2x_acquire_phy_lock(bp);
b5bf9068 2257
a22f0788 2258 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2259 struct link_params *lp = &bp->link_params;
2260 lp->loopback_mode = LOOPBACK_XGXS;
2261 /* do PHY loopback at 10G speed, if possible */
2262 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2263 if (lp->speed_cap_mask[cfx_idx] &
2264 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2265 lp->req_line_speed[cfx_idx] =
2266 SPEED_10000;
2267 else
2268 lp->req_line_speed[cfx_idx] =
2269 SPEED_1000;
2270 }
a22f0788 2271 }
b5bf9068 2272
8970b2e4
MS
2273 if (load_mode == LOAD_LOOPBACK_EXT) {
2274 struct link_params *lp = &bp->link_params;
2275 lp->loopback_mode = LOOPBACK_EXT;
2276 }
2277
19680c48 2278 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2279
4a37fb66 2280 bnx2x_release_phy_lock(bp);
a2fbb9ea 2281
3c96c68b
EG
2282 bnx2x_calc_fc_adv(bp);
2283
cd1dfce2 2284 if (bp->link_vars.link_up) {
b5bf9068 2285 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2286 bnx2x_link_report(bp);
cd1dfce2
YM
2287 }
2288 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2289 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2290 return rc;
2291 }
f5372251 2292 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2293 return -EINVAL;
a2fbb9ea
ET
2294}
2295
9f6c9258 2296void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2297{
19680c48 2298 if (!BP_NOMCP(bp)) {
4a37fb66 2299 bnx2x_acquire_phy_lock(bp);
19680c48 2300 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2301 bnx2x_release_phy_lock(bp);
a2fbb9ea 2302
19680c48
EG
2303 bnx2x_calc_fc_adv(bp);
2304 } else
f5372251 2305 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2306}
a2fbb9ea 2307
c18487ee
YR
2308static void bnx2x__link_reset(struct bnx2x *bp)
2309{
19680c48 2310 if (!BP_NOMCP(bp)) {
4a37fb66 2311 bnx2x_acquire_phy_lock(bp);
5d07d868 2312 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2313 bnx2x_release_phy_lock(bp);
19680c48 2314 } else
f5372251 2315 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2316}
a2fbb9ea 2317
5d07d868
YM
2318void bnx2x_force_link_reset(struct bnx2x *bp)
2319{
2320 bnx2x_acquire_phy_lock(bp);
2321 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2322 bnx2x_release_phy_lock(bp);
2323}
2324
a22f0788 2325u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2326{
2145a920 2327 u8 rc = 0;
a2fbb9ea 2328
2145a920
VZ
2329 if (!BP_NOMCP(bp)) {
2330 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2331 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2332 is_serdes);
2145a920
VZ
2333 bnx2x_release_phy_lock(bp);
2334 } else
2335 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2336
c18487ee
YR
2337 return rc;
2338}
a2fbb9ea 2339
2691d51d
EG
2340/* Calculates the sum of vn_min_rates.
2341 It's needed for further normalizing of the min_rates.
2342 Returns:
2343 sum of vn_min_rates.
2344 or
2345 0 - if all the min_rates are 0.
16a5fd92 2346 In the later case fairness algorithm should be deactivated.
2691d51d
EG
2347 If not all min_rates are zero then those that are zeroes will be set to 1.
2348 */
b475d78f
YM
2349static void bnx2x_calc_vn_min(struct bnx2x *bp,
2350 struct cmng_init_input *input)
2691d51d
EG
2351{
2352 int all_zero = 1;
2691d51d
EG
2353 int vn;
2354
3395a033 2355 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2356 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2357 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2358 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2359
2360 /* Skip hidden vns */
2361 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2362 vn_min_rate = 0;
2691d51d 2363 /* If min rate is zero - set it to 1 */
b475d78f 2364 else if (!vn_min_rate)
2691d51d
EG
2365 vn_min_rate = DEF_MIN_RATE;
2366 else
2367 all_zero = 0;
2368
b475d78f 2369 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2370 }
2371
30ae438b
DK
2372 /* if ETS or all min rates are zeros - disable fairness */
2373 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2374 input->flags.cmng_enables &=
30ae438b
DK
2375 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2376 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2377 } else if (all_zero) {
b475d78f 2378 input->flags.cmng_enables &=
b015e3d1 2379 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2380 DP(NETIF_MSG_IFUP,
2381 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2382 } else
b475d78f 2383 input->flags.cmng_enables |=
b015e3d1 2384 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2385}
2386
b475d78f
YM
2387static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2388 struct cmng_init_input *input)
34f80b04 2389{
b475d78f 2390 u16 vn_max_rate;
f2e0899f 2391 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2392
b475d78f 2393 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2394 vn_max_rate = 0;
b475d78f 2395 else {
faa6fcbb
DK
2396 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2397
b475d78f 2398 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2399 /* maxCfg in percents of linkspeed */
2400 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2401 } else /* SD modes */
faa6fcbb
DK
2402 /* maxCfg is absolute in 100Mb units */
2403 vn_max_rate = maxCfg * 100;
34f80b04 2404 }
f85582f8 2405
b475d78f 2406 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2407
b475d78f 2408 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2409}
f85582f8 2410
523224a3
DK
2411static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2412{
2413 if (CHIP_REV_IS_SLOW(bp))
2414 return CMNG_FNS_NONE;
fb3bff17 2415 if (IS_MF(bp))
523224a3
DK
2416 return CMNG_FNS_MINMAX;
2417
2418 return CMNG_FNS_NONE;
2419}
2420
2ae17f66 2421void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2422{
0793f83f 2423 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2424
2425 if (BP_NOMCP(bp))
16a5fd92 2426 return; /* what should be the default value in this case */
523224a3 2427
0793f83f
DK
2428 /* For 2 port configuration the absolute function number formula
2429 * is:
2430 * abs_func = 2 * vn + BP_PORT + BP_PATH
2431 *
2432 * and there are 4 functions per port
2433 *
2434 * For 4 port configuration it is
2435 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2436 *
2437 * and there are 2 functions per port
2438 */
3395a033 2439 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2440 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2441
2442 if (func >= E1H_FUNC_MAX)
2443 break;
2444
f2e0899f 2445 bp->mf_config[vn] =
523224a3
DK
2446 MF_CFG_RD(bp, func_mf_config[func].config);
2447 }
a3348722
BW
2448 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2449 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2450 bp->flags |= MF_FUNC_DIS;
2451 } else {
2452 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2453 bp->flags &= ~MF_FUNC_DIS;
2454 }
523224a3
DK
2455}
2456
2457static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2458{
b475d78f
YM
2459 struct cmng_init_input input;
2460 memset(&input, 0, sizeof(struct cmng_init_input));
2461
2462 input.port_rate = bp->link_vars.line_speed;
523224a3
DK
2463
2464 if (cmng_type == CMNG_FNS_MINMAX) {
2465 int vn;
2466
523224a3
DK
2467 /* read mf conf from shmem */
2468 if (read_cfg)
2469 bnx2x_read_mf_cfg(bp);
2470
523224a3 2471 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2472 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2473
2474 /* calculate and set min-max rate for each vn */
c4154f25 2475 if (bp->port.pmf)
3395a033 2476 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2477 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2478
2479 /* always enable rate shaping and fairness */
b475d78f 2480 input.flags.cmng_enables |=
523224a3 2481 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2482
2483 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2484 return;
2485 }
2486
2487 /* rate shaping and fairness are disabled */
2488 DP(NETIF_MSG_IFUP,
2489 "rate shaping and fairness are disabled\n");
2490}
34f80b04 2491
1191cb83
ED
2492static void storm_memset_cmng(struct bnx2x *bp,
2493 struct cmng_init *cmng,
2494 u8 port)
2495{
2496 int vn;
2497 size_t size = sizeof(struct cmng_struct_per_port);
2498
2499 u32 addr = BAR_XSTRORM_INTMEM +
2500 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2501
2502 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2503
2504 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2505 int func = func_by_vn(bp, vn);
2506
2507 addr = BAR_XSTRORM_INTMEM +
2508 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2509 size = sizeof(struct rate_shaping_vars_per_vn);
2510 __storm_memset_struct(bp, addr, size,
2511 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2512
2513 addr = BAR_XSTRORM_INTMEM +
2514 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2515 size = sizeof(struct fairness_vars_per_vn);
2516 __storm_memset_struct(bp, addr, size,
2517 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2518 }
2519}
2520
c18487ee
YR
2521/* This function is called upon link interrupt */
2522static void bnx2x_link_attn(struct bnx2x *bp)
2523{
bb2a0f7a
YG
2524 /* Make sure that we are synced with the current statistics */
2525 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2526
c18487ee 2527 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2528
bb2a0f7a
YG
2529 if (bp->link_vars.link_up) {
2530
1c06328c 2531 /* dropless flow control */
f2e0899f 2532 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2533 int port = BP_PORT(bp);
2534 u32 pause_enabled = 0;
2535
2536 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2537 pause_enabled = 1;
2538
2539 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2540 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2541 pause_enabled);
2542 }
2543
619c5cb6 2544 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2545 struct host_port_stats *pstats;
2546
2547 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2548 /* reset old mac stats */
bb2a0f7a
YG
2549 memset(&(pstats->mac_stx[0]), 0,
2550 sizeof(struct mac_stx));
2551 }
f34d28ea 2552 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2553 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2554 }
2555
f2e0899f
DK
2556 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2557 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2558
f2e0899f
DK
2559 if (cmng_fns != CMNG_FNS_NONE) {
2560 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2561 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2562 } else
2563 /* rate shaping and fairness are disabled */
2564 DP(NETIF_MSG_IFUP,
2565 "single function mode without fairness\n");
34f80b04 2566 }
9fdc3e95 2567
2ae17f66
VZ
2568 __bnx2x_link_report(bp);
2569
9fdc3e95
DK
2570 if (IS_MF(bp))
2571 bnx2x_link_sync_notify(bp);
c18487ee 2572}
a2fbb9ea 2573
9f6c9258 2574void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2575{
2ae17f66 2576 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2577 return;
a2fbb9ea 2578
00253a8c 2579 /* read updated dcb configuration */
ad5afc89
AE
2580 if (IS_PF(bp)) {
2581 bnx2x_dcbx_pmf_update(bp);
2582 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2583 if (bp->link_vars.link_up)
2584 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2585 else
2586 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2587 /* indicate link status */
2588 bnx2x_link_report(bp);
a2fbb9ea 2589
ad5afc89
AE
2590 } else { /* VF */
2591 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2592 SUPPORTED_10baseT_Full |
2593 SUPPORTED_100baseT_Half |
2594 SUPPORTED_100baseT_Full |
2595 SUPPORTED_1000baseT_Full |
2596 SUPPORTED_2500baseX_Full |
2597 SUPPORTED_10000baseT_Full |
2598 SUPPORTED_TP |
2599 SUPPORTED_FIBRE |
2600 SUPPORTED_Autoneg |
2601 SUPPORTED_Pause |
2602 SUPPORTED_Asym_Pause);
2603 bp->port.advertising[0] = bp->port.supported[0];
2604
2605 bp->link_params.bp = bp;
2606 bp->link_params.port = BP_PORT(bp);
2607 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2608 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2609 bp->link_params.req_line_speed[0] = SPEED_10000;
2610 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2611 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2612 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2613 bp->link_vars.line_speed = SPEED_10000;
2614 bp->link_vars.link_status =
2615 (LINK_STATUS_LINK_UP |
2616 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2617 bp->link_vars.link_up = 1;
2618 bp->link_vars.duplex = DUPLEX_FULL;
2619 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2620 __bnx2x_link_report(bp);
bb2a0f7a 2621 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
ad5afc89 2622 }
a2fbb9ea 2623}
a2fbb9ea 2624
a3348722
BW
2625static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2626 u16 vlan_val, u8 allowed_prio)
2627{
86564c3f 2628 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2629 struct bnx2x_func_afex_update_params *f_update_params =
2630 &func_params.params.afex_update;
2631
2632 func_params.f_obj = &bp->func_obj;
2633 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2634
2635 /* no need to wait for RAMROD completion, so don't
2636 * set RAMROD_COMP_WAIT flag
2637 */
2638
2639 f_update_params->vif_id = vifid;
2640 f_update_params->afex_default_vlan = vlan_val;
2641 f_update_params->allowed_priorities = allowed_prio;
2642
2643 /* if ramrod can not be sent, response to MCP immediately */
2644 if (bnx2x_func_state_change(bp, &func_params) < 0)
2645 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2646
2647 return 0;
2648}
2649
2650static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2651 u16 vif_index, u8 func_bit_map)
2652{
86564c3f 2653 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2654 struct bnx2x_func_afex_viflists_params *update_params =
2655 &func_params.params.afex_viflists;
2656 int rc;
2657 u32 drv_msg_code;
2658
2659 /* validate only LIST_SET and LIST_GET are received from switch */
2660 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2661 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2662 cmd_type);
2663
2664 func_params.f_obj = &bp->func_obj;
2665 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2666
2667 /* set parameters according to cmd_type */
2668 update_params->afex_vif_list_command = cmd_type;
86564c3f 2669 update_params->vif_list_index = vif_index;
a3348722
BW
2670 update_params->func_bit_map =
2671 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2672 update_params->func_to_clear = 0;
2673 drv_msg_code =
2674 (cmd_type == VIF_LIST_RULE_GET) ?
2675 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2676 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2677
2678 /* if ramrod can not be sent, respond to MCP immediately for
2679 * SET and GET requests (other are not triggered from MCP)
2680 */
2681 rc = bnx2x_func_state_change(bp, &func_params);
2682 if (rc < 0)
2683 bnx2x_fw_command(bp, drv_msg_code, 0);
2684
2685 return 0;
2686}
2687
2688static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2689{
2690 struct afex_stats afex_stats;
2691 u32 func = BP_ABS_FUNC(bp);
2692 u32 mf_config;
2693 u16 vlan_val;
2694 u32 vlan_prio;
2695 u16 vif_id;
2696 u8 allowed_prio;
2697 u8 vlan_mode;
2698 u32 addr_to_write, vifid, addrs, stats_type, i;
2699
2700 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2701 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2702 DP(BNX2X_MSG_MCP,
2703 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2704 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2705 }
2706
2707 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2708 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2709 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2710 DP(BNX2X_MSG_MCP,
2711 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2712 vifid, addrs);
2713 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2714 addrs);
2715 }
2716
2717 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2718 addr_to_write = SHMEM2_RD(bp,
2719 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2720 stats_type = SHMEM2_RD(bp,
2721 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2722
2723 DP(BNX2X_MSG_MCP,
2724 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2725 addr_to_write);
2726
2727 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2728
2729 /* write response to scratchpad, for MCP */
2730 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2731 REG_WR(bp, addr_to_write + i*sizeof(u32),
2732 *(((u32 *)(&afex_stats))+i));
2733
2734 /* send ack message to MCP */
2735 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2736 }
2737
2738 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2739 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2740 bp->mf_config[BP_VN(bp)] = mf_config;
2741 DP(BNX2X_MSG_MCP,
2742 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2743 mf_config);
2744
2745 /* if VIF_SET is "enabled" */
2746 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2747 /* set rate limit directly to internal RAM */
2748 struct cmng_init_input cmng_input;
2749 struct rate_shaping_vars_per_vn m_rs_vn;
2750 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2751 u32 addr = BAR_XSTRORM_INTMEM +
2752 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2753
2754 bp->mf_config[BP_VN(bp)] = mf_config;
2755
2756 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2757 m_rs_vn.vn_counter.rate =
2758 cmng_input.vnic_max_rate[BP_VN(bp)];
2759 m_rs_vn.vn_counter.quota =
2760 (m_rs_vn.vn_counter.rate *
2761 RS_PERIODIC_TIMEOUT_USEC) / 8;
2762
2763 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2764
2765 /* read relevant values from mf_cfg struct in shmem */
2766 vif_id =
2767 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2768 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2769 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2770 vlan_val =
2771 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2772 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2773 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2774 vlan_prio = (mf_config &
2775 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2776 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2777 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2778 vlan_mode =
2779 (MF_CFG_RD(bp,
2780 func_mf_config[func].afex_config) &
2781 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2782 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2783 allowed_prio =
2784 (MF_CFG_RD(bp,
2785 func_mf_config[func].afex_config) &
2786 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2787 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2788
2789 /* send ramrod to FW, return in case of failure */
2790 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2791 allowed_prio))
2792 return;
2793
2794 bp->afex_def_vlan_tag = vlan_val;
2795 bp->afex_vlan_mode = vlan_mode;
2796 } else {
2797 /* notify link down because BP->flags is disabled */
2798 bnx2x_link_report(bp);
2799
2800 /* send INVALID VIF ramrod to FW */
2801 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2802
2803 /* Reset the default afex VLAN */
2804 bp->afex_def_vlan_tag = -1;
2805 }
2806 }
2807}
2808
34f80b04
EG
2809static void bnx2x_pmf_update(struct bnx2x *bp)
2810{
2811 int port = BP_PORT(bp);
2812 u32 val;
2813
2814 bp->port.pmf = 1;
51c1a580 2815 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2816
3deb8167
YR
2817 /*
2818 * We need the mb() to ensure the ordering between the writing to
2819 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2820 */
2821 smp_mb();
2822
2823 /* queue a periodic task */
2824 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2825
ef01854e
DK
2826 bnx2x_dcbx_pmf_update(bp);
2827
34f80b04 2828 /* enable nig attention */
3395a033 2829 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2830 if (bp->common.int_block == INT_BLOCK_HC) {
2831 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2832 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2833 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2834 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2835 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2836 }
bb2a0f7a
YG
2837
2838 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2839}
2840
c18487ee 2841/* end of Link */
a2fbb9ea
ET
2842
2843/* slow path */
2844
2845/*
2846 * General service functions
2847 */
2848
2691d51d 2849/* send the MCP a request, block until there is a reply */
a22f0788 2850u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2851{
f2e0899f 2852 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2853 u32 seq;
2691d51d
EG
2854 u32 rc = 0;
2855 u32 cnt = 1;
2856 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2857
c4ff7cbf 2858 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2859 seq = ++bp->fw_seq;
f2e0899f
DK
2860 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2861 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2862
754a2f52
DK
2863 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2864 (command | seq), param);
2691d51d
EG
2865
2866 do {
2867 /* let the FW do it's magic ... */
2868 msleep(delay);
2869
f2e0899f 2870 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2871
c4ff7cbf
EG
2872 /* Give the FW up to 5 second (500*10ms) */
2873 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2874
2875 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2876 cnt*delay, rc, seq);
2877
2878 /* is this a reply to our command? */
2879 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2880 rc &= FW_MSG_CODE_MASK;
2881 else {
2882 /* FW BUG! */
2883 BNX2X_ERR("FW failed to respond!\n");
2884 bnx2x_fw_dump(bp);
2885 rc = 0;
2886 }
c4ff7cbf 2887 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2888
2889 return rc;
2890}
2891
1191cb83
ED
2892static void storm_memset_func_cfg(struct bnx2x *bp,
2893 struct tstorm_eth_function_common_config *tcfg,
2894 u16 abs_fid)
2895{
2896 size_t size = sizeof(struct tstorm_eth_function_common_config);
2897
2898 u32 addr = BAR_TSTRORM_INTMEM +
2899 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2900
2901 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2902}
2903
619c5cb6
VZ
2904void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2905{
2906 if (CHIP_IS_E1x(bp)) {
2907 struct tstorm_eth_function_common_config tcfg = {0};
2908
2909 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2910 }
2911
2912 /* Enable the function in the FW */
2913 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2914 storm_memset_func_en(bp, p->func_id, 1);
2915
2916 /* spq */
2917 if (p->func_flgs & FUNC_FLG_SPQ) {
2918 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2919 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2920 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2921 }
2922}
2923
6383c0b3 2924/**
16a5fd92 2925 * bnx2x_get_common_flags - Return common flags
6383c0b3
AE
2926 *
2927 * @bp device handle
2928 * @fp queue handle
2929 * @zero_stats TRUE if statistics zeroing is needed
2930 *
2931 * Return the flags that are common for the Tx-only and not normal connections.
2932 */
1191cb83
ED
2933static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2934 struct bnx2x_fastpath *fp,
2935 bool zero_stats)
28912902 2936{
619c5cb6
VZ
2937 unsigned long flags = 0;
2938
2939 /* PF driver will always initialize the Queue to an ACTIVE state */
2940 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2941
6383c0b3 2942 /* tx only connections collect statistics (on the same index as the
91226790
DK
2943 * parent connection). The statistics are zeroed when the parent
2944 * connection is initialized.
6383c0b3 2945 */
50f0a562
BW
2946
2947 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2948 if (zero_stats)
2949 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2950
91226790 2951 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
e287a75c 2952 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
6383c0b3 2953
823e1d90
YM
2954#ifdef BNX2X_STOP_ON_ERROR
2955 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
2956#endif
2957
6383c0b3
AE
2958 return flags;
2959}
2960
1191cb83
ED
2961static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2962 struct bnx2x_fastpath *fp,
2963 bool leading)
6383c0b3
AE
2964{
2965 unsigned long flags = 0;
2966
619c5cb6
VZ
2967 /* calculate other queue flags */
2968 if (IS_MF_SD(bp))
2969 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2970
a3348722 2971 if (IS_FCOE_FP(fp)) {
619c5cb6 2972 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
2973 /* For FCoE - force usage of default priority (for afex) */
2974 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2975 }
523224a3 2976
f5219d8e 2977 if (!fp->disable_tpa) {
619c5cb6 2978 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2979 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2980 if (fp->mode == TPA_MODE_GRO)
2981 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2982 }
619c5cb6 2983
619c5cb6
VZ
2984 if (leading) {
2985 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2986 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2987 }
523224a3 2988
619c5cb6
VZ
2989 /* Always set HW VLAN stripping */
2990 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 2991
a3348722
BW
2992 /* configure silent vlan removal */
2993 if (IS_MF_AFEX(bp))
2994 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
2995
6383c0b3 2996 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
2997}
2998
619c5cb6 2999static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
3000 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3001 u8 cos)
619c5cb6
VZ
3002{
3003 gen_init->stat_id = bnx2x_stats_id(fp);
3004 gen_init->spcl_id = fp->cl_id;
3005
3006 /* Always use mini-jumbo MTU for FCoE L2 ring */
3007 if (IS_FCOE_FP(fp))
3008 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3009 else
3010 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
3011
3012 gen_init->cos = cos;
619c5cb6
VZ
3013}
3014
3015static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 3016 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 3017 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 3018{
619c5cb6 3019 u8 max_sge = 0;
523224a3
DK
3020 u16 sge_sz = 0;
3021 u16 tpa_agg_size = 0;
3022
523224a3 3023 if (!fp->disable_tpa) {
dfacf138
DK
3024 pause->sge_th_lo = SGE_TH_LO(bp);
3025 pause->sge_th_hi = SGE_TH_HI(bp);
3026
3027 /* validate SGE ring has enough to cross high threshold */
3028 WARN_ON(bp->dropless_fc &&
3029 pause->sge_th_hi + FW_PREFETCH_CNT >
3030 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3031
924d75ab 3032 tpa_agg_size = TPA_AGG_SIZE;
523224a3
DK
3033 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3034 SGE_PAGE_SHIFT;
3035 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3036 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
924d75ab 3037 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
523224a3
DK
3038 }
3039
3040 /* pause - not for e1 */
3041 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
3042 pause->bd_th_lo = BD_TH_LO(bp);
3043 pause->bd_th_hi = BD_TH_HI(bp);
3044
3045 pause->rcq_th_lo = RCQ_TH_LO(bp);
3046 pause->rcq_th_hi = RCQ_TH_HI(bp);
3047 /*
3048 * validate that rings have enough entries to cross
3049 * high thresholds
3050 */
3051 WARN_ON(bp->dropless_fc &&
3052 pause->bd_th_hi + FW_PREFETCH_CNT >
3053 bp->rx_ring_size);
3054 WARN_ON(bp->dropless_fc &&
3055 pause->rcq_th_hi + FW_PREFETCH_CNT >
3056 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 3057
523224a3
DK
3058 pause->pri_map = 1;
3059 }
3060
3061 /* rxq setup */
523224a3
DK
3062 rxq_init->dscr_map = fp->rx_desc_mapping;
3063 rxq_init->sge_map = fp->rx_sge_mapping;
3064 rxq_init->rcq_map = fp->rx_comp_mapping;
3065 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 3066
619c5cb6
VZ
3067 /* This should be a maximum number of data bytes that may be
3068 * placed on the BD (not including paddings).
3069 */
e52fcb24
ED
3070 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
3071 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 3072
523224a3 3073 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
3074 rxq_init->tpa_agg_sz = tpa_agg_size;
3075 rxq_init->sge_buf_sz = sge_sz;
3076 rxq_init->max_sges_pkt = max_sge;
619c5cb6 3077 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 3078 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
3079
3080 /* Maximum number or simultaneous TPA aggregation for this Queue.
3081 *
2de67439 3082 * For PF Clients it should be the maximum available number.
619c5cb6
VZ
3083 * VF driver(s) may want to define it to a smaller value.
3084 */
dfacf138 3085 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 3086
523224a3
DK
3087 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3088 rxq_init->fw_sb_id = fp->fw_sb_id;
3089
ec6ba945
VZ
3090 if (IS_FCOE_FP(fp))
3091 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3092 else
6383c0b3 3093 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
3094 /* configure silent vlan removal
3095 * if multi function mode is afex, then mask default vlan
3096 */
3097 if (IS_MF_AFEX(bp)) {
3098 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3099 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3100 }
523224a3
DK
3101}
3102
619c5cb6 3103static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
3104 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3105 u8 cos)
523224a3 3106{
65565884 3107 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 3108 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
3109 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3110 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 3111
619c5cb6 3112 /*
16a5fd92 3113 * set the tss leading client id for TX classification ==
619c5cb6
VZ
3114 * leading RSS client id
3115 */
3116 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3117
ec6ba945
VZ
3118 if (IS_FCOE_FP(fp)) {
3119 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3120 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3121 }
523224a3
DK
3122}
3123
8d96286a 3124static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
3125{
3126 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
3127 struct event_ring_data eq_data = { {0} };
3128 u16 flags;
3129
619c5cb6 3130 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3131 /* reset IGU PF statistics: MSIX + ATTN */
3132 /* PF */
3133 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3134 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3135 (CHIP_MODE_IS_4_PORT(bp) ?
3136 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3137 /* ATTN */
3138 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3139 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3140 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3141 (CHIP_MODE_IS_4_PORT(bp) ?
3142 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3143 }
3144
523224a3
DK
3145 /* function setup flags */
3146 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3147
619c5cb6
VZ
3148 /* This flag is relevant for E1x only.
3149 * E2 doesn't have a TPA configuration in a function level.
523224a3 3150 */
619c5cb6 3151 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
3152
3153 func_init.func_flgs = flags;
3154 func_init.pf_id = BP_FUNC(bp);
3155 func_init.func_id = BP_FUNC(bp);
523224a3
DK
3156 func_init.spq_map = bp->spq_mapping;
3157 func_init.spq_prod = bp->spq_prod_idx;
3158
3159 bnx2x_func_init(bp, &func_init);
3160
3161 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3162
3163 /*
619c5cb6
VZ
3164 * Congestion management values depend on the link rate
3165 * There is no active link so initial link rate is set to 10 Gbps.
3166 * When the link comes up The congestion management values are
3167 * re-calculated according to the actual link rate.
3168 */
523224a3
DK
3169 bp->link_vars.line_speed = SPEED_10000;
3170 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3171
3172 /* Only the PMF sets the HW */
3173 if (bp->port.pmf)
3174 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3175
86564c3f 3176 /* init Event Queue - PCI bus guarantees correct endianity*/
523224a3
DK
3177 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3178 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3179 eq_data.producer = bp->eq_prod;
3180 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3181 eq_data.sb_id = DEF_SB_ID;
3182 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3183}
3184
523224a3
DK
3185static void bnx2x_e1h_disable(struct bnx2x *bp)
3186{
3187 int port = BP_PORT(bp);
3188
619c5cb6 3189 bnx2x_tx_disable(bp);
523224a3
DK
3190
3191 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3192}
3193
3194static void bnx2x_e1h_enable(struct bnx2x *bp)
3195{
3196 int port = BP_PORT(bp);
3197
3198 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3199
16a5fd92 3200 /* Tx queue should be only re-enabled */
523224a3
DK
3201 netif_tx_wake_all_queues(bp->dev);
3202
3203 /*
3204 * Should not call netif_carrier_on since it will be called if the link
3205 * is up when checking for link state
3206 */
3207}
3208
1d187b34
BW
3209#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3210
3211static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3212{
3213 struct eth_stats_info *ether_stat =
3214 &bp->slowpath->drv_info_to_mcp.ether_stat;
3ec9f9ca
AE
3215 struct bnx2x_vlan_mac_obj *mac_obj =
3216 &bp->sp_objs->mac_obj;
3217 int i;
1d187b34 3218
786fdf0b
DC
3219 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3220 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3221
3ec9f9ca
AE
3222 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3223 * mac_local field in ether_stat struct. The base address is offset by 2
3224 * bytes to account for the field being 8 bytes but a mac address is
3225 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3226 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3227 * allocated by the ether_stat struct, so the macs will land in their
3228 * proper positions.
3229 */
3230 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3231 memset(ether_stat->mac_local + i, 0,
3232 sizeof(ether_stat->mac_local[0]));
3233 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3234 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3235 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3236 ETH_ALEN);
1d187b34 3237 ether_stat->mtu_size = bp->dev->mtu;
1d187b34
BW
3238 if (bp->dev->features & NETIF_F_RXCSUM)
3239 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3240 if (bp->dev->features & NETIF_F_TSO)
3241 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3242 ether_stat->feature_flags |= bp->common.boot_mode;
3243
3244 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3245
3246 ether_stat->txq_size = bp->tx_ring_size;
3247 ether_stat->rxq_size = bp->rx_ring_size;
3248}
3249
3250static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3251{
3252 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3253 struct fcoe_stats_info *fcoe_stat =
3254 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3255
55c11941
MS
3256 if (!CNIC_LOADED(bp))
3257 return;
3258
3ec9f9ca 3259 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
1d187b34
BW
3260
3261 fcoe_stat->qos_priority =
3262 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3263
3264 /* insert FCoE stats from ramrod response */
3265 if (!NO_FCOE(bp)) {
3266 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3267 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3268 tstorm_queue_statistics;
3269
3270 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3271 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3272 xstorm_queue_statistics;
3273
3274 struct fcoe_statistics_params *fw_fcoe_stat =
3275 &bp->fw_stats_data->fcoe;
3276
86564c3f
YM
3277 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3278 fcoe_stat->rx_bytes_lo,
3279 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
1d187b34 3280
86564c3f
YM
3281 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3282 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3283 fcoe_stat->rx_bytes_lo,
3284 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
1d187b34 3285
86564c3f
YM
3286 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3287 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3288 fcoe_stat->rx_bytes_lo,
3289 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
1d187b34 3290
86564c3f
YM
3291 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3292 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3293 fcoe_stat->rx_bytes_lo,
3294 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
1d187b34 3295
86564c3f
YM
3296 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3297 fcoe_stat->rx_frames_lo,
3298 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
1d187b34 3299
86564c3f
YM
3300 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3301 fcoe_stat->rx_frames_lo,
3302 fcoe_q_tstorm_stats->rcv_ucast_pkts);
1d187b34 3303
86564c3f
YM
3304 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3305 fcoe_stat->rx_frames_lo,
3306 fcoe_q_tstorm_stats->rcv_bcast_pkts);
1d187b34 3307
86564c3f
YM
3308 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3309 fcoe_stat->rx_frames_lo,
3310 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34 3311
86564c3f
YM
3312 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3313 fcoe_stat->tx_bytes_lo,
3314 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
1d187b34 3315
86564c3f
YM
3316 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3317 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3318 fcoe_stat->tx_bytes_lo,
3319 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
1d187b34 3320
86564c3f
YM
3321 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3322 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3323 fcoe_stat->tx_bytes_lo,
3324 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
1d187b34 3325
86564c3f
YM
3326 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3327 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3328 fcoe_stat->tx_bytes_lo,
3329 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
1d187b34 3330
86564c3f
YM
3331 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3332 fcoe_stat->tx_frames_lo,
3333 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
1d187b34 3334
86564c3f
YM
3335 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3336 fcoe_stat->tx_frames_lo,
3337 fcoe_q_xstorm_stats->ucast_pkts_sent);
1d187b34 3338
86564c3f
YM
3339 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3340 fcoe_stat->tx_frames_lo,
3341 fcoe_q_xstorm_stats->bcast_pkts_sent);
1d187b34 3342
86564c3f
YM
3343 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3344 fcoe_stat->tx_frames_lo,
3345 fcoe_q_xstorm_stats->mcast_pkts_sent);
1d187b34
BW
3346 }
3347
1d187b34
BW
3348 /* ask L5 driver to add data to the struct */
3349 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3350}
3351
3352static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3353{
3354 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3355 struct iscsi_stats_info *iscsi_stat =
3356 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3357
55c11941
MS
3358 if (!CNIC_LOADED(bp))
3359 return;
3360
3ec9f9ca
AE
3361 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3362 ETH_ALEN);
1d187b34
BW
3363
3364 iscsi_stat->qos_priority =
3365 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3366
1d187b34
BW
3367 /* ask L5 driver to add data to the struct */
3368 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3369}
3370
0793f83f
DK
3371/* called due to MCP event (on pmf):
3372 * reread new bandwidth configuration
3373 * configure FW
3374 * notify others function about the change
3375 */
1191cb83 3376static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3377{
3378 if (bp->link_vars.link_up) {
3379 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3380 bnx2x_link_sync_notify(bp);
3381 }
3382 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3383}
3384
1191cb83 3385static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3386{
3387 bnx2x_config_mf_bw(bp);
3388 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3389}
3390
c8c60d88
YM
3391static void bnx2x_handle_eee_event(struct bnx2x *bp)
3392{
3393 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3394 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3395}
3396
1d187b34
BW
3397static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3398{
3399 enum drv_info_opcode op_code;
3400 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3401
3402 /* if drv_info version supported by MFW doesn't match - send NACK */
3403 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3404 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3405 return;
3406 }
3407
3408 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3409 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3410
3411 memset(&bp->slowpath->drv_info_to_mcp, 0,
3412 sizeof(union drv_info_to_mcp));
3413
3414 switch (op_code) {
3415 case ETH_STATS_OPCODE:
3416 bnx2x_drv_info_ether_stat(bp);
3417 break;
3418 case FCOE_STATS_OPCODE:
3419 bnx2x_drv_info_fcoe_stat(bp);
3420 break;
3421 case ISCSI_STATS_OPCODE:
3422 bnx2x_drv_info_iscsi_stat(bp);
3423 break;
3424 default:
3425 /* if op code isn't supported - send NACK */
3426 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3427 return;
3428 }
3429
3430 /* if we got drv_info attn from MFW then these fields are defined in
3431 * shmem2 for sure
3432 */
3433 SHMEM2_WR(bp, drv_info_host_addr_lo,
3434 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3435 SHMEM2_WR(bp, drv_info_host_addr_hi,
3436 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3437
3438 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3439}
3440
523224a3
DK
3441static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3442{
3443 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3444
3445 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3446
3447 /*
3448 * This is the only place besides the function initialization
3449 * where the bp->flags can change so it is done without any
3450 * locks
3451 */
f2e0899f 3452 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3453 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3454 bp->flags |= MF_FUNC_DIS;
3455
3456 bnx2x_e1h_disable(bp);
3457 } else {
51c1a580 3458 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3459 bp->flags &= ~MF_FUNC_DIS;
3460
3461 bnx2x_e1h_enable(bp);
3462 }
3463 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3464 }
3465 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3466 bnx2x_config_mf_bw(bp);
523224a3
DK
3467 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3468 }
3469
3470 /* Report results to MCP */
3471 if (dcc_event)
3472 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3473 else
3474 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3475}
3476
3477/* must be called under the spq lock */
1191cb83 3478static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3479{
3480 struct eth_spe *next_spe = bp->spq_prod_bd;
3481
3482 if (bp->spq_prod_bd == bp->spq_last_bd) {
3483 bp->spq_prod_bd = bp->spq;
3484 bp->spq_prod_idx = 0;
51c1a580 3485 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3486 } else {
3487 bp->spq_prod_bd++;
3488 bp->spq_prod_idx++;
3489 }
3490 return next_spe;
3491}
3492
3493/* must be called under the spq lock */
1191cb83 3494static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3495{
3496 int func = BP_FUNC(bp);
3497
53e51e2f
VZ
3498 /*
3499 * Make sure that BD data is updated before writing the producer:
3500 * BD data is written to the memory, the producer is read from the
3501 * memory, thus we need a full memory barrier to ensure the ordering.
3502 */
3503 mb();
28912902 3504
523224a3 3505 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3506 bp->spq_prod_idx);
28912902
MC
3507 mmiowb();
3508}
3509
619c5cb6
VZ
3510/**
3511 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3512 *
3513 * @cmd: command to check
3514 * @cmd_type: command type
3515 */
1191cb83 3516static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3517{
3518 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3519 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3520 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3521 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3522 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3523 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3524 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3525 return true;
3526 else
3527 return false;
619c5cb6
VZ
3528}
3529
619c5cb6
VZ
3530/**
3531 * bnx2x_sp_post - place a single command on an SP ring
3532 *
3533 * @bp: driver handle
3534 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3535 * @cid: SW CID the command is related to
3536 * @data_hi: command private data address (high 32 bits)
3537 * @data_lo: command private data address (low 32 bits)
3538 * @cmd_type: command type (e.g. NONE, ETH)
3539 *
3540 * SP data is handled as if it's always an address pair, thus data fields are
3541 * not swapped to little endian in upper functions. Instead this function swaps
3542 * data as if it's two u32 fields.
3543 */
9f6c9258 3544int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3545 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3546{
28912902 3547 struct eth_spe *spe;
523224a3 3548 u16 type;
619c5cb6 3549 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3550
a2fbb9ea 3551#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3552 if (unlikely(bp->panic)) {
3553 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3554 return -EIO;
51c1a580 3555 }
a2fbb9ea
ET
3556#endif
3557
34f80b04 3558 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3559
6e30dd4e
VZ
3560 if (common) {
3561 if (!atomic_read(&bp->eq_spq_left)) {
3562 BNX2X_ERR("BUG! EQ ring full!\n");
3563 spin_unlock_bh(&bp->spq_lock);
3564 bnx2x_panic();
3565 return -EBUSY;
3566 }
3567 } else if (!atomic_read(&bp->cq_spq_left)) {
3568 BNX2X_ERR("BUG! SPQ ring full!\n");
3569 spin_unlock_bh(&bp->spq_lock);
3570 bnx2x_panic();
3571 return -EBUSY;
a2fbb9ea 3572 }
f1410647 3573
28912902
MC
3574 spe = bnx2x_sp_get_next(bp);
3575
a2fbb9ea 3576 /* CID needs port number to be encoded int it */
28912902 3577 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3578 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3579 HW_CID(bp, cid));
523224a3 3580
619c5cb6 3581 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3582
523224a3
DK
3583 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3584 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3585
523224a3
DK
3586 spe->hdr.type = cpu_to_le16(type);
3587
3588 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3589 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3590
d6cae238
VZ
3591 /*
3592 * It's ok if the actual decrement is issued towards the memory
3593 * somewhere between the spin_lock and spin_unlock. Thus no
16a5fd92 3594 * more explicit memory barrier is needed.
d6cae238
VZ
3595 */
3596 if (common)
3597 atomic_dec(&bp->eq_spq_left);
3598 else
3599 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3600
51c1a580
MS
3601 DP(BNX2X_MSG_SP,
3602 "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
3603 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3604 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3605 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3606 HW_CID(bp, cid), data_hi, data_lo, type,
3607 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3608
28912902 3609 bnx2x_sp_prod_update(bp);
34f80b04 3610 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3611 return 0;
3612}
3613
3614/* acquire split MCP access lock register */
4a37fb66 3615static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3616{
72fd0718 3617 u32 j, val;
34f80b04 3618 int rc = 0;
a2fbb9ea
ET
3619
3620 might_sleep();
72fd0718 3621 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3622 val = (1UL << 31);
3623 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3624 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3625 if (val & (1L << 31))
3626 break;
3627
3628 msleep(5);
3629 }
a2fbb9ea 3630 if (!(val & (1L << 31))) {
19680c48 3631 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3632 rc = -EBUSY;
3633 }
3634
3635 return rc;
3636}
3637
4a37fb66
YG
3638/* release split MCP access lock register */
3639static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3640{
72fd0718 3641 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3642}
3643
523224a3
DK
3644#define BNX2X_DEF_SB_ATT_IDX 0x0001
3645#define BNX2X_DEF_SB_IDX 0x0002
3646
1191cb83 3647static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3648{
523224a3 3649 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3650 u16 rc = 0;
3651
3652 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3653 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3654 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3655 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3656 }
523224a3
DK
3657
3658 if (bp->def_idx != def_sb->sp_sb.running_index) {
3659 bp->def_idx = def_sb->sp_sb.running_index;
3660 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3661 }
523224a3 3662
16a5fd92 3663 /* Do not reorder: indices reading should complete before handling */
523224a3 3664 barrier();
a2fbb9ea
ET
3665 return rc;
3666}
3667
3668/*
3669 * slow path service functions
3670 */
3671
3672static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3673{
34f80b04 3674 int port = BP_PORT(bp);
a2fbb9ea
ET
3675 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3676 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3677 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3678 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3679 u32 aeu_mask;
87942b46 3680 u32 nig_mask = 0;
f2e0899f 3681 u32 reg_addr;
a2fbb9ea 3682
a2fbb9ea
ET
3683 if (bp->attn_state & asserted)
3684 BNX2X_ERR("IGU ERROR\n");
3685
3fcaf2e5
EG
3686 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3687 aeu_mask = REG_RD(bp, aeu_addr);
3688
a2fbb9ea 3689 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3690 aeu_mask, asserted);
72fd0718 3691 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3692 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3693
3fcaf2e5
EG
3694 REG_WR(bp, aeu_addr, aeu_mask);
3695 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3696
3fcaf2e5 3697 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3698 bp->attn_state |= asserted;
3fcaf2e5 3699 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3700
3701 if (asserted & ATTN_HARD_WIRED_MASK) {
3702 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3703
a5e9a7cf
EG
3704 bnx2x_acquire_phy_lock(bp);
3705
877e9aa4 3706 /* save nig interrupt mask */
87942b46 3707 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3708
361c391e
YR
3709 /* If nig_mask is not set, no need to call the update
3710 * function.
3711 */
3712 if (nig_mask) {
3713 REG_WR(bp, nig_int_mask_addr, 0);
3714
3715 bnx2x_link_attn(bp);
3716 }
a2fbb9ea
ET
3717
3718 /* handle unicore attn? */
3719 }
3720 if (asserted & ATTN_SW_TIMER_4_FUNC)
3721 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3722
3723 if (asserted & GPIO_2_FUNC)
3724 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3725
3726 if (asserted & GPIO_3_FUNC)
3727 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3728
3729 if (asserted & GPIO_4_FUNC)
3730 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3731
3732 if (port == 0) {
3733 if (asserted & ATTN_GENERAL_ATTN_1) {
3734 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3735 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3736 }
3737 if (asserted & ATTN_GENERAL_ATTN_2) {
3738 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3739 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3740 }
3741 if (asserted & ATTN_GENERAL_ATTN_3) {
3742 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3743 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3744 }
3745 } else {
3746 if (asserted & ATTN_GENERAL_ATTN_4) {
3747 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3748 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3749 }
3750 if (asserted & ATTN_GENERAL_ATTN_5) {
3751 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3752 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3753 }
3754 if (asserted & ATTN_GENERAL_ATTN_6) {
3755 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3756 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3757 }
3758 }
3759
3760 } /* if hardwired */
3761
f2e0899f
DK
3762 if (bp->common.int_block == INT_BLOCK_HC)
3763 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3764 COMMAND_REG_ATTN_BITS_SET);
3765 else
3766 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3767
3768 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3769 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3770 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3771
3772 /* now set back the mask */
a5e9a7cf 3773 if (asserted & ATTN_NIG_FOR_FUNC) {
27c1151c
YR
3774 /* Verify that IGU ack through BAR was written before restoring
3775 * NIG mask. This loop should exit after 2-3 iterations max.
3776 */
3777 if (bp->common.int_block != INT_BLOCK_HC) {
3778 u32 cnt = 0, igu_acked;
3779 do {
3780 igu_acked = REG_RD(bp,
3781 IGU_REG_ATTENTION_ACK_BITS);
3782 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3783 (++cnt < MAX_IGU_ATTN_ACK_TO));
3784 if (!igu_acked)
3785 DP(NETIF_MSG_HW,
3786 "Failed to verify IGU ack on time\n");
3787 barrier();
3788 }
87942b46 3789 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3790 bnx2x_release_phy_lock(bp);
3791 }
a2fbb9ea
ET
3792}
3793
1191cb83 3794static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3795{
3796 int port = BP_PORT(bp);
b7737c9b 3797 u32 ext_phy_config;
fd4ef40d 3798 /* mark the failure */
b7737c9b
YR
3799 ext_phy_config =
3800 SHMEM_RD(bp,
3801 dev_info.port_hw_config[port].external_phy_config);
3802
3803 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3804 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3805 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3806 ext_phy_config);
fd4ef40d
EG
3807
3808 /* log the failure */
51c1a580
MS
3809 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3810 "Please contact OEM Support for assistance\n");
8304859a 3811
16a5fd92 3812 /* Schedule device reset (unload)
8304859a
AE
3813 * This is due to some boards consuming sufficient power when driver is
3814 * up to overheat if fan fails.
3815 */
3816 smp_mb__before_clear_bit();
3817 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3818 smp_mb__after_clear_bit();
3819 schedule_delayed_work(&bp->sp_rtnl_task, 0);
fd4ef40d 3820}
ab6ad5a4 3821
1191cb83 3822static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3823{
34f80b04 3824 int port = BP_PORT(bp);
877e9aa4 3825 int reg_offset;
d90d96ba 3826 u32 val;
877e9aa4 3827
34f80b04
EG
3828 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3829 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3830
34f80b04 3831 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3832
3833 val = REG_RD(bp, reg_offset);
3834 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3835 REG_WR(bp, reg_offset, val);
3836
3837 BNX2X_ERR("SPIO5 hw attention\n");
3838
fd4ef40d 3839 /* Fan failure attention */
d90d96ba 3840 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3841 bnx2x_fan_failure(bp);
877e9aa4 3842 }
34f80b04 3843
3deb8167 3844 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3845 bnx2x_acquire_phy_lock(bp);
3846 bnx2x_handle_module_detect_int(&bp->link_params);
3847 bnx2x_release_phy_lock(bp);
3848 }
3849
34f80b04
EG
3850 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3851
3852 val = REG_RD(bp, reg_offset);
3853 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3854 REG_WR(bp, reg_offset, val);
3855
3856 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3857 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3858 bnx2x_panic();
3859 }
877e9aa4
ET
3860}
3861
1191cb83 3862static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3863{
3864 u32 val;
3865
0626b899 3866 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3867
3868 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3869 BNX2X_ERR("DB hw attention 0x%x\n", val);
3870 /* DORQ discard attention */
3871 if (val & 0x2)
3872 BNX2X_ERR("FATAL error from DORQ\n");
3873 }
34f80b04
EG
3874
3875 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3876
3877 int port = BP_PORT(bp);
3878 int reg_offset;
3879
3880 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3881 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3882
3883 val = REG_RD(bp, reg_offset);
3884 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3885 REG_WR(bp, reg_offset, val);
3886
3887 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3888 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3889 bnx2x_panic();
3890 }
877e9aa4
ET
3891}
3892
1191cb83 3893static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3894{
3895 u32 val;
3896
3897 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3898
3899 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3900 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3901 /* CFC error attention */
3902 if (val & 0x2)
3903 BNX2X_ERR("FATAL error from CFC\n");
3904 }
3905
3906 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3907 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3908 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3909 /* RQ_USDMDP_FIFO_OVERFLOW */
3910 if (val & 0x18000)
3911 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3912
3913 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3914 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3915 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3916 }
877e9aa4 3917 }
34f80b04
EG
3918
3919 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3920
3921 int port = BP_PORT(bp);
3922 int reg_offset;
3923
3924 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3925 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3926
3927 val = REG_RD(bp, reg_offset);
3928 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3929 REG_WR(bp, reg_offset, val);
3930
3931 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3932 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3933 bnx2x_panic();
3934 }
877e9aa4
ET
3935}
3936
1191cb83 3937static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3938{
34f80b04
EG
3939 u32 val;
3940
877e9aa4
ET
3941 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3942
34f80b04
EG
3943 if (attn & BNX2X_PMF_LINK_ASSERT) {
3944 int func = BP_FUNC(bp);
3945
3946 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 3947 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
3948 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3949 func_mf_config[BP_ABS_FUNC(bp)].config);
3950 val = SHMEM_RD(bp,
3951 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3952 if (val & DRV_STATUS_DCC_EVENT_MASK)
3953 bnx2x_dcc_event(bp,
3954 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3955
3956 if (val & DRV_STATUS_SET_MF_BW)
3957 bnx2x_set_mf_bw(bp);
3958
1d187b34
BW
3959 if (val & DRV_STATUS_DRV_INFO_REQ)
3960 bnx2x_handle_drv_info_req(bp);
d16132ce
AE
3961
3962 if (val & DRV_STATUS_VF_DISABLED)
3963 bnx2x_vf_handle_flr_event(bp);
3964
2691d51d 3965 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3966 bnx2x_pmf_update(bp);
3967
e4901dde 3968 if (bp->port.pmf &&
785b9b1a
SR
3969 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3970 bp->dcbx_enabled > 0)
e4901dde
VZ
3971 /* start dcbx state machine */
3972 bnx2x_dcbx_set_params(bp,
3973 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
3974 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3975 bnx2x_handle_afex_cmd(bp,
3976 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
3977 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3978 bnx2x_handle_eee_event(bp);
3deb8167
YR
3979 if (bp->link_vars.periodic_flags &
3980 PERIODIC_FLAGS_LINK_EVENT) {
3981 /* sync with link */
3982 bnx2x_acquire_phy_lock(bp);
3983 bp->link_vars.periodic_flags &=
3984 ~PERIODIC_FLAGS_LINK_EVENT;
3985 bnx2x_release_phy_lock(bp);
3986 if (IS_MF(bp))
3987 bnx2x_link_sync_notify(bp);
3988 bnx2x_link_report(bp);
3989 }
3990 /* Always call it here: bnx2x_link_report() will
3991 * prevent the link indication duplication.
3992 */
3993 bnx2x__link_status_update(bp);
34f80b04 3994 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
3995
3996 BNX2X_ERR("MC assert!\n");
d6cae238 3997 bnx2x_mc_assert(bp);
877e9aa4
ET
3998 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3999 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4000 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4001 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4002 bnx2x_panic();
4003
4004 } else if (attn & BNX2X_MCP_ASSERT) {
4005
4006 BNX2X_ERR("MCP assert!\n");
4007 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 4008 bnx2x_fw_dump(bp);
877e9aa4
ET
4009
4010 } else
4011 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4012 }
4013
4014 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
4015 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4016 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
4017 val = CHIP_IS_E1(bp) ? 0 :
4018 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
4019 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4020 }
4021 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
4022 val = CHIP_IS_E1(bp) ? 0 :
4023 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
4024 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4025 }
877e9aa4 4026 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
4027 }
4028}
4029
c9ee9206
VZ
4030/*
4031 * Bits map:
4032 * 0-7 - Engine0 load counter.
4033 * 8-15 - Engine1 load counter.
4034 * 16 - Engine0 RESET_IN_PROGRESS bit.
4035 * 17 - Engine1 RESET_IN_PROGRESS bit.
4036 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4037 * on the engine
4038 * 19 - Engine1 ONE_IS_LOADED.
4039 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4040 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4041 * just the one belonging to its engine).
4042 *
4043 */
4044#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4045
4046#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4047#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4048#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4049#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4050#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4051#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4052#define BNX2X_GLOBAL_RESET_BIT 0x00040000
4053
4054/*
4055 * Set the GLOBAL_RESET bit.
4056 *
4057 * Should be run under rtnl lock
4058 */
4059void bnx2x_set_reset_global(struct bnx2x *bp)
4060{
f16da43b
AE
4061 u32 val;
4062 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4063 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4064 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 4065 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
4066}
4067
4068/*
4069 * Clear the GLOBAL_RESET bit.
4070 *
4071 * Should be run under rtnl lock
4072 */
1191cb83 4073static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 4074{
f16da43b
AE
4075 u32 val;
4076 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4077 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4078 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 4079 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 4080}
f85582f8 4081
72fd0718 4082/*
c9ee9206
VZ
4083 * Checks the GLOBAL_RESET bit.
4084 *
72fd0718
VZ
4085 * should be run under rtnl lock
4086 */
1191cb83 4087static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206
VZ
4088{
4089 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4090
4091 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4092 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4093}
4094
4095/*
4096 * Clear RESET_IN_PROGRESS bit for the current engine.
4097 *
4098 * Should be run under rtnl lock
4099 */
1191cb83 4100static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 4101{
f16da43b 4102 u32 val;
c9ee9206
VZ
4103 u32 bit = BP_PATH(bp) ?
4104 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4105 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4106 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4107
4108 /* Clear the bit */
4109 val &= ~bit;
4110 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4111
4112 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4113}
4114
4115/*
c9ee9206
VZ
4116 * Set RESET_IN_PROGRESS for the current engine.
4117 *
72fd0718
VZ
4118 * should be run under rtnl lock
4119 */
c9ee9206 4120void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 4121{
f16da43b 4122 u32 val;
c9ee9206
VZ
4123 u32 bit = BP_PATH(bp) ?
4124 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4125 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4126 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4127
4128 /* Set the bit */
4129 val |= bit;
4130 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4131 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4132}
4133
4134/*
c9ee9206 4135 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
4136 * should be run under rtnl lock
4137 */
c9ee9206 4138bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 4139{
c9ee9206
VZ
4140 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4141 u32 bit = engine ?
4142 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4143
4144 /* return false if bit is set */
4145 return (val & bit) ? false : true;
72fd0718
VZ
4146}
4147
4148/*
889b9af3 4149 * set pf load for the current pf.
c9ee9206 4150 *
72fd0718
VZ
4151 * should be run under rtnl lock
4152 */
889b9af3 4153void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 4154{
f16da43b 4155 u32 val1, val;
c9ee9206
VZ
4156 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4157 BNX2X_PATH0_LOAD_CNT_MASK;
4158 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4159 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4160
f16da43b
AE
4161 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4162 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4163
51c1a580 4164 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4165
c9ee9206
VZ
4166 /* get the current counter value */
4167 val1 = (val & mask) >> shift;
4168
889b9af3
AE
4169 /* set bit of that PF */
4170 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
4171
4172 /* clear the old value */
4173 val &= ~mask;
4174
4175 /* set the new one */
4176 val |= ((val1 << shift) & mask);
4177
4178 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4179 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4180}
4181
c9ee9206 4182/**
889b9af3 4183 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
4184 *
4185 * @bp: driver handle
4186 *
4187 * Should be run under rtnl lock.
4188 * Decrements the load counter for the current engine. Returns
889b9af3 4189 * whether other functions are still loaded
72fd0718 4190 */
889b9af3 4191bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 4192{
f16da43b 4193 u32 val1, val;
c9ee9206
VZ
4194 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4195 BNX2X_PATH0_LOAD_CNT_MASK;
4196 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4197 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4198
f16da43b
AE
4199 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4200 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4201 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4202
c9ee9206
VZ
4203 /* get the current counter value */
4204 val1 = (val & mask) >> shift;
4205
889b9af3
AE
4206 /* clear bit of that PF */
4207 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4208
4209 /* clear the old value */
4210 val &= ~mask;
4211
4212 /* set the new one */
4213 val |= ((val1 << shift) & mask);
4214
4215 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4216 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4217 return val1 != 0;
72fd0718
VZ
4218}
4219
4220/*
889b9af3 4221 * Read the load status for the current engine.
c9ee9206 4222 *
72fd0718
VZ
4223 * should be run under rtnl lock
4224 */
1191cb83 4225static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4226{
c9ee9206
VZ
4227 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4228 BNX2X_PATH0_LOAD_CNT_MASK);
4229 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4230 BNX2X_PATH0_LOAD_CNT_SHIFT);
4231 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4232
51c1a580 4233 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4234
4235 val = (val & mask) >> shift;
4236
51c1a580
MS
4237 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4238 engine, val);
c9ee9206 4239
889b9af3 4240 return val != 0;
72fd0718
VZ
4241}
4242
1191cb83 4243static void _print_next_block(int idx, const char *blk)
72fd0718 4244{
f1deab50 4245 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4246}
4247
1191cb83
ED
4248static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4249 bool print)
72fd0718
VZ
4250{
4251 int i = 0;
4252 u32 cur_bit = 0;
4253 for (i = 0; sig; i++) {
4254 cur_bit = ((u32)0x1 << i);
4255 if (sig & cur_bit) {
4256 switch (cur_bit) {
4257 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
4258 if (print)
4259 _print_next_block(par_num++, "BRB");
72fd0718
VZ
4260 break;
4261 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
4262 if (print)
4263 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
4264 break;
4265 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
4266 if (print)
4267 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
4268 break;
4269 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
4270 if (print)
4271 _print_next_block(par_num++,
4272 "SEARCHER");
4273 break;
4274 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4275 if (print)
4276 _print_next_block(par_num++, "TCM");
72fd0718
VZ
4277 break;
4278 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
4279 if (print)
4280 _print_next_block(par_num++, "TSEMI");
4281 break;
4282 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4283 if (print)
4284 _print_next_block(par_num++, "XPB");
72fd0718
VZ
4285 break;
4286 }
4287
4288 /* Clear the bit */
4289 sig &= ~cur_bit;
4290 }
4291 }
4292
4293 return par_num;
4294}
4295
1191cb83
ED
4296static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4297 bool *global, bool print)
72fd0718
VZ
4298{
4299 int i = 0;
4300 u32 cur_bit = 0;
4301 for (i = 0; sig; i++) {
4302 cur_bit = ((u32)0x1 << i);
4303 if (sig & cur_bit) {
4304 switch (cur_bit) {
c9ee9206
VZ
4305 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4306 if (print)
4307 _print_next_block(par_num++, "PBF");
72fd0718
VZ
4308 break;
4309 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
4310 if (print)
4311 _print_next_block(par_num++, "QM");
4312 break;
4313 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4314 if (print)
4315 _print_next_block(par_num++, "TM");
72fd0718
VZ
4316 break;
4317 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
4318 if (print)
4319 _print_next_block(par_num++, "XSDM");
4320 break;
4321 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4322 if (print)
4323 _print_next_block(par_num++, "XCM");
72fd0718
VZ
4324 break;
4325 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
4326 if (print)
4327 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
4328 break;
4329 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
4330 if (print)
4331 _print_next_block(par_num++,
4332 "DOORBELLQ");
4333 break;
4334 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4335 if (print)
4336 _print_next_block(par_num++, "NIG");
72fd0718
VZ
4337 break;
4338 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
4339 if (print)
4340 _print_next_block(par_num++,
4341 "VAUX PCI CORE");
4342 *global = true;
72fd0718
VZ
4343 break;
4344 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
4345 if (print)
4346 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
4347 break;
4348 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
4349 if (print)
4350 _print_next_block(par_num++, "USDM");
72fd0718 4351 break;
8736c826
VZ
4352 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4353 if (print)
4354 _print_next_block(par_num++, "UCM");
4355 break;
72fd0718 4356 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
4357 if (print)
4358 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
4359 break;
4360 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
4361 if (print)
4362 _print_next_block(par_num++, "UPB");
72fd0718
VZ
4363 break;
4364 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
4365 if (print)
4366 _print_next_block(par_num++, "CSDM");
72fd0718 4367 break;
8736c826
VZ
4368 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4369 if (print)
4370 _print_next_block(par_num++, "CCM");
4371 break;
72fd0718
VZ
4372 }
4373
4374 /* Clear the bit */
4375 sig &= ~cur_bit;
4376 }
4377 }
4378
4379 return par_num;
4380}
4381
1191cb83
ED
4382static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4383 bool print)
72fd0718
VZ
4384{
4385 int i = 0;
4386 u32 cur_bit = 0;
4387 for (i = 0; sig; i++) {
4388 cur_bit = ((u32)0x1 << i);
4389 if (sig & cur_bit) {
4390 switch (cur_bit) {
4391 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
4392 if (print)
4393 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
4394 break;
4395 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
4396 if (print)
4397 _print_next_block(par_num++, "PXP");
72fd0718
VZ
4398 break;
4399 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
4400 if (print)
4401 _print_next_block(par_num++,
72fd0718
VZ
4402 "PXPPCICLOCKCLIENT");
4403 break;
4404 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
4405 if (print)
4406 _print_next_block(par_num++, "CFC");
72fd0718
VZ
4407 break;
4408 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
4409 if (print)
4410 _print_next_block(par_num++, "CDU");
4411 break;
4412 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4413 if (print)
4414 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
4415 break;
4416 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
4417 if (print)
4418 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4419 break;
4420 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4421 if (print)
4422 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4423 break;
4424 }
4425
4426 /* Clear the bit */
4427 sig &= ~cur_bit;
4428 }
4429 }
4430
4431 return par_num;
4432}
4433
1191cb83
ED
4434static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4435 bool *global, bool print)
72fd0718
VZ
4436{
4437 int i = 0;
4438 u32 cur_bit = 0;
4439 for (i = 0; sig; i++) {
4440 cur_bit = ((u32)0x1 << i);
4441 if (sig & cur_bit) {
4442 switch (cur_bit) {
4443 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4444 if (print)
4445 _print_next_block(par_num++, "MCP ROM");
4446 *global = true;
72fd0718
VZ
4447 break;
4448 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4449 if (print)
4450 _print_next_block(par_num++,
4451 "MCP UMP RX");
4452 *global = true;
72fd0718
VZ
4453 break;
4454 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4455 if (print)
4456 _print_next_block(par_num++,
4457 "MCP UMP TX");
4458 *global = true;
72fd0718
VZ
4459 break;
4460 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4461 if (print)
4462 _print_next_block(par_num++,
4463 "MCP SCPAD");
4464 *global = true;
72fd0718
VZ
4465 break;
4466 }
4467
4468 /* Clear the bit */
4469 sig &= ~cur_bit;
4470 }
4471 }
4472
4473 return par_num;
4474}
4475
1191cb83
ED
4476static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4477 bool print)
8736c826
VZ
4478{
4479 int i = 0;
4480 u32 cur_bit = 0;
4481 for (i = 0; sig; i++) {
4482 cur_bit = ((u32)0x1 << i);
4483 if (sig & cur_bit) {
4484 switch (cur_bit) {
4485 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4486 if (print)
4487 _print_next_block(par_num++, "PGLUE_B");
4488 break;
4489 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4490 if (print)
4491 _print_next_block(par_num++, "ATC");
4492 break;
4493 }
4494
4495 /* Clear the bit */
4496 sig &= ~cur_bit;
4497 }
4498 }
4499
4500 return par_num;
4501}
4502
1191cb83
ED
4503static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4504 u32 *sig)
72fd0718 4505{
8736c826
VZ
4506 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4507 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4508 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4509 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4510 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4511 int par_num = 0;
51c1a580
MS
4512 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4513 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4514 sig[0] & HW_PRTY_ASSERT_SET_0,
4515 sig[1] & HW_PRTY_ASSERT_SET_1,
4516 sig[2] & HW_PRTY_ASSERT_SET_2,
4517 sig[3] & HW_PRTY_ASSERT_SET_3,
4518 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4519 if (print)
4520 netdev_err(bp->dev,
4521 "Parity errors detected in blocks: ");
4522 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4523 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4524 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4525 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4526 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4527 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4528 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4529 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4530 par_num = bnx2x_check_blocks_with_parity4(
4531 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4532
c9ee9206
VZ
4533 if (print)
4534 pr_cont("\n");
8736c826 4535
72fd0718
VZ
4536 return true;
4537 } else
4538 return false;
4539}
4540
c9ee9206
VZ
4541/**
4542 * bnx2x_chk_parity_attn - checks for parity attentions.
4543 *
4544 * @bp: driver handle
4545 * @global: true if there was a global attention
4546 * @print: show parity attention in syslog
4547 */
4548bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4549{
8736c826 4550 struct attn_route attn = { {0} };
72fd0718
VZ
4551 int port = BP_PORT(bp);
4552
4553 attn.sig[0] = REG_RD(bp,
4554 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4555 port*4);
4556 attn.sig[1] = REG_RD(bp,
4557 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4558 port*4);
4559 attn.sig[2] = REG_RD(bp,
4560 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4561 port*4);
4562 attn.sig[3] = REG_RD(bp,
4563 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4564 port*4);
4565
8736c826
VZ
4566 if (!CHIP_IS_E1x(bp))
4567 attn.sig[4] = REG_RD(bp,
4568 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4569 port*4);
4570
4571 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4572}
4573
1191cb83 4574static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4575{
4576 u32 val;
4577 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4578
4579 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4580 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4581 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4582 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4583 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4584 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4585 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4586 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4587 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4588 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4589 if (val &
4590 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4591 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4592 if (val &
4593 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4594 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4595 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4596 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4597 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4598 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4599 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4600 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4601 }
4602 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4603 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4604 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4605 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4606 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4607 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4608 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4609 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4610 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4611 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4612 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4613 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4614 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4615 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4616 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4617 }
4618
4619 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4620 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4621 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4622 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4623 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4624 }
f2e0899f
DK
4625}
4626
72fd0718
VZ
4627static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4628{
4629 struct attn_route attn, *group_mask;
34f80b04 4630 int port = BP_PORT(bp);
877e9aa4 4631 int index;
a2fbb9ea
ET
4632 u32 reg_addr;
4633 u32 val;
3fcaf2e5 4634 u32 aeu_mask;
c9ee9206 4635 bool global = false;
a2fbb9ea
ET
4636
4637 /* need to take HW lock because MCP or other port might also
4638 try to handle this event */
4a37fb66 4639 bnx2x_acquire_alr(bp);
a2fbb9ea 4640
c9ee9206
VZ
4641 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4642#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4643 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4644 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4645 /* Disable HW interrupts */
4646 bnx2x_int_disable(bp);
72fd0718
VZ
4647 /* In case of parity errors don't handle attentions so that
4648 * other function would "see" parity errors.
4649 */
c9ee9206
VZ
4650#else
4651 bnx2x_panic();
4652#endif
4653 bnx2x_release_alr(bp);
72fd0718
VZ
4654 return;
4655 }
4656
a2fbb9ea
ET
4657 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4658 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4659 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4660 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4661 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4662 attn.sig[4] =
4663 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4664 else
4665 attn.sig[4] = 0;
4666
4667 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4668 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4669
4670 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4671 if (deasserted & (1 << index)) {
72fd0718 4672 group_mask = &bp->attn_group[index];
a2fbb9ea 4673
51c1a580 4674 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4675 index,
4676 group_mask->sig[0], group_mask->sig[1],
4677 group_mask->sig[2], group_mask->sig[3],
4678 group_mask->sig[4]);
a2fbb9ea 4679
f2e0899f
DK
4680 bnx2x_attn_int_deasserted4(bp,
4681 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4682 bnx2x_attn_int_deasserted3(bp,
72fd0718 4683 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4684 bnx2x_attn_int_deasserted1(bp,
72fd0718 4685 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4686 bnx2x_attn_int_deasserted2(bp,
72fd0718 4687 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4688 bnx2x_attn_int_deasserted0(bp,
72fd0718 4689 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4690 }
4691 }
4692
4a37fb66 4693 bnx2x_release_alr(bp);
a2fbb9ea 4694
f2e0899f
DK
4695 if (bp->common.int_block == INT_BLOCK_HC)
4696 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4697 COMMAND_REG_ATTN_BITS_CLR);
4698 else
4699 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4700
4701 val = ~deasserted;
f2e0899f
DK
4702 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4703 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4704 REG_WR(bp, reg_addr, val);
a2fbb9ea 4705
a2fbb9ea 4706 if (~bp->attn_state & deasserted)
3fcaf2e5 4707 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4708
4709 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4710 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4711
3fcaf2e5
EG
4712 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4713 aeu_mask = REG_RD(bp, reg_addr);
4714
4715 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4716 aeu_mask, deasserted);
72fd0718 4717 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4718 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4719
3fcaf2e5
EG
4720 REG_WR(bp, reg_addr, aeu_mask);
4721 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4722
4723 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4724 bp->attn_state &= ~deasserted;
4725 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4726}
4727
4728static void bnx2x_attn_int(struct bnx2x *bp)
4729{
4730 /* read local copy of bits */
68d59484
EG
4731 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4732 attn_bits);
4733 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4734 attn_bits_ack);
a2fbb9ea
ET
4735 u32 attn_state = bp->attn_state;
4736
4737 /* look for changed bits */
4738 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4739 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4740
4741 DP(NETIF_MSG_HW,
4742 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4743 attn_bits, attn_ack, asserted, deasserted);
4744
4745 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4746 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4747
4748 /* handle bits that were raised */
4749 if (asserted)
4750 bnx2x_attn_int_asserted(bp, asserted);
4751
4752 if (deasserted)
4753 bnx2x_attn_int_deasserted(bp, deasserted);
4754}
4755
619c5cb6
VZ
4756void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4757 u16 index, u8 op, u8 update)
4758{
dc1ba591
AE
4759 u32 igu_addr = bp->igu_base_addr;
4760 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
619c5cb6
VZ
4761 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4762 igu_addr);
4763}
4764
1191cb83 4765static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4766{
4767 /* No memory barriers */
4768 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4769 mmiowb(); /* keep prod updates ordered */
4770}
4771
523224a3
DK
4772static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4773 union event_ring_elem *elem)
4774{
619c5cb6
VZ
4775 u8 err = elem->message.error;
4776
523224a3 4777 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4778 (cid < bp->cnic_eth_dev.starting_cid &&
4779 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4780 return 1;
4781
4782 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4783
619c5cb6
VZ
4784 if (unlikely(err)) {
4785
523224a3
DK
4786 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4787 cid);
823e1d90 4788 bnx2x_panic_dump(bp, false);
523224a3 4789 }
619c5cb6 4790 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4791 return 0;
4792}
523224a3 4793
1191cb83 4794static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4795{
4796 struct bnx2x_mcast_ramrod_params rparam;
4797 int rc;
4798
4799 memset(&rparam, 0, sizeof(rparam));
4800
4801 rparam.mcast_obj = &bp->mcast_obj;
4802
4803 netif_addr_lock_bh(bp->dev);
4804
4805 /* Clear pending state for the last command */
4806 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4807
4808 /* If there are pending mcast commands - send them */
4809 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4810 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4811 if (rc < 0)
4812 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4813 rc);
4814 }
4815
4816 netif_addr_unlock_bh(bp->dev);
4817}
4818
1191cb83
ED
4819static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4820 union event_ring_elem *elem)
619c5cb6
VZ
4821{
4822 unsigned long ramrod_flags = 0;
4823 int rc = 0;
4824 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4825 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4826
4827 /* Always push next commands out, don't wait here */
4828 __set_bit(RAMROD_CONT, &ramrod_flags);
4829
86564c3f
YM
4830 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
4831 >> BNX2X_SWCID_SHIFT) {
619c5cb6 4832 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4833 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 4834 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
4835 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4836 else
15192a8c 4837 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
4838
4839 break;
619c5cb6 4840 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4841 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4842 /* This is only relevant for 57710 where multicast MACs are
4843 * configured as unicast MACs using the same ramrod.
4844 */
4845 bnx2x_handle_mcast_eqe(bp);
4846 return;
4847 default:
4848 BNX2X_ERR("Unsupported classification command: %d\n",
4849 elem->message.data.eth_event.echo);
4850 return;
4851 }
4852
4853 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4854
4855 if (rc < 0)
4856 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4857 else if (rc > 0)
4858 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
619c5cb6
VZ
4859}
4860
619c5cb6 4861static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 4862
1191cb83 4863static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
4864{
4865 netif_addr_lock_bh(bp->dev);
4866
4867 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4868
4869 /* Send rx_mode command again if was requested */
4870 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4871 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
4872 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4873 &bp->sp_state))
4874 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4875 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4876 &bp->sp_state))
4877 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
4878
4879 netif_addr_unlock_bh(bp->dev);
4880}
4881
1191cb83 4882static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
4883 union event_ring_elem *elem)
4884{
4885 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4886 DP(BNX2X_MSG_SP,
4887 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4888 elem->message.data.vif_list_event.func_bit_map);
4889 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4890 elem->message.data.vif_list_event.func_bit_map);
4891 } else if (elem->message.data.vif_list_event.echo ==
4892 VIF_LIST_RULE_SET) {
4893 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4894 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4895 }
4896}
4897
4898/* called with rtnl_lock */
1191cb83 4899static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
4900{
4901 int q, rc;
4902 struct bnx2x_fastpath *fp;
4903 struct bnx2x_queue_state_params queue_params = {NULL};
4904 struct bnx2x_queue_update_params *q_update_params =
4905 &queue_params.params.update;
4906
2de67439 4907 /* Send Q update command with afex vlan removal values for all Qs */
a3348722
BW
4908 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4909
4910 /* set silent vlan removal values according to vlan mode */
4911 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4912 &q_update_params->update_flags);
4913 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4914 &q_update_params->update_flags);
4915 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4916
4917 /* in access mode mark mask and value are 0 to strip all vlans */
4918 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4919 q_update_params->silent_removal_value = 0;
4920 q_update_params->silent_removal_mask = 0;
4921 } else {
4922 q_update_params->silent_removal_value =
4923 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4924 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4925 }
4926
4927 for_each_eth_queue(bp, q) {
4928 /* Set the appropriate Queue object */
4929 fp = &bp->fp[q];
15192a8c 4930 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4931
4932 /* send the ramrod */
4933 rc = bnx2x_queue_state_change(bp, &queue_params);
4934 if (rc < 0)
4935 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4936 q);
4937 }
4938
fea75645 4939 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
65565884 4940 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 4941 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4942
4943 /* clear pending completion bit */
4944 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4945
4946 /* mark latest Q bit */
4947 smp_mb__before_clear_bit();
4948 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4949 smp_mb__after_clear_bit();
4950
4951 /* send Q update ramrod for FCoE Q */
4952 rc = bnx2x_queue_state_change(bp, &queue_params);
4953 if (rc < 0)
4954 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4955 q);
4956 } else {
4957 /* If no FCoE ring - ACK MCP now */
4958 bnx2x_link_report(bp);
4959 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4960 }
a3348722
BW
4961}
4962
1191cb83 4963static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
4964 struct bnx2x *bp, u32 cid)
4965{
94f05b0f 4966 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
4967
4968 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 4969 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 4970 else
15192a8c 4971 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
4972}
4973
523224a3
DK
4974static void bnx2x_eq_int(struct bnx2x *bp)
4975{
4976 u16 hw_cons, sw_cons, sw_prod;
4977 union event_ring_elem *elem;
55c11941 4978 u8 echo;
523224a3
DK
4979 u32 cid;
4980 u8 opcode;
fd1fc79d 4981 int rc, spqe_cnt = 0;
619c5cb6
VZ
4982 struct bnx2x_queue_sp_obj *q_obj;
4983 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4984 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4985
4986 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4987
4988 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
16a5fd92 4989 * when we get the next-page we need to adjust so the loop
523224a3
DK
4990 * condition below will be met. The next element is the size of a
4991 * regular element and hence incrementing by 1
4992 */
4993 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4994 hw_cons++;
4995
25985edc 4996 /* This function may never run in parallel with itself for a
523224a3
DK
4997 * specific bp, thus there is no need in "paired" read memory
4998 * barrier here.
4999 */
5000 sw_cons = bp->eq_cons;
5001 sw_prod = bp->eq_prod;
5002
d6cae238 5003 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 5004 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
5005
5006 for (; sw_cons != hw_cons;
5007 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5008
523224a3
DK
5009 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5010
fd1fc79d
AE
5011 rc = bnx2x_iov_eq_sp_event(bp, elem);
5012 if (!rc) {
5013 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5014 rc);
5015 goto next_spqe;
5016 }
523224a3 5017
86564c3f
YM
5018 /* elem CID originates from FW; actually LE */
5019 cid = SW_CID((__force __le32)
5020 elem->message.data.cfc_del_event.cid);
5021 opcode = elem->message.opcode;
523224a3
DK
5022
5023 /* handle eq element */
5024 switch (opcode) {
fd1fc79d
AE
5025 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5026 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
5027 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
5028 continue;
5029
523224a3 5030 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
5031 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
5032 "got statistics comp event %d\n",
619c5cb6 5033 bp->stats_comp++);
523224a3 5034 /* nothing to do with stats comp */
d6cae238 5035 goto next_spqe;
523224a3
DK
5036
5037 case EVENT_RING_OPCODE_CFC_DEL:
5038 /* handle according to cid range */
5039 /*
5040 * we may want to verify here that the bp state is
5041 * HALTING
5042 */
d6cae238 5043 DP(BNX2X_MSG_SP,
523224a3 5044 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
5045
5046 if (CNIC_LOADED(bp) &&
5047 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 5048 goto next_spqe;
55c11941 5049
619c5cb6
VZ
5050 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5051
5052 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5053 break;
5054
523224a3 5055 goto next_spqe;
e4901dde
VZ
5056
5057 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 5058 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
5059 if (f_obj->complete_cmd(bp, f_obj,
5060 BNX2X_F_CMD_TX_STOP))
5061 break;
e4901dde
VZ
5062 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
5063 goto next_spqe;
619c5cb6 5064
e4901dde 5065 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 5066 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
5067 if (f_obj->complete_cmd(bp, f_obj,
5068 BNX2X_F_CMD_TX_START))
5069 break;
e4901dde
VZ
5070 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
5071 goto next_spqe;
55c11941 5072
a3348722 5073 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
5074 echo = elem->message.data.function_update_event.echo;
5075 if (echo == SWITCH_UPDATE) {
5076 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5077 "got FUNC_SWITCH_UPDATE ramrod\n");
5078 if (f_obj->complete_cmd(
5079 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5080 break;
a3348722 5081
55c11941
MS
5082 } else {
5083 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5084 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5085 f_obj->complete_cmd(bp, f_obj,
5086 BNX2X_F_CMD_AFEX_UPDATE);
5087
5088 /* We will perform the Queues update from
5089 * sp_rtnl task as all Queue SP operations
5090 * should run under rtnl_lock.
5091 */
5092 smp_mb__before_clear_bit();
5093 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5094 &bp->sp_rtnl_state);
5095 smp_mb__after_clear_bit();
5096
5097 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5098 }
a3348722 5099
a3348722
BW
5100 goto next_spqe;
5101
5102 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5103 f_obj->complete_cmd(bp, f_obj,
5104 BNX2X_F_CMD_AFEX_VIFLISTS);
5105 bnx2x_after_afex_vif_lists(bp, elem);
5106 goto next_spqe;
619c5cb6 5107 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
5108 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5109 "got FUNC_START ramrod\n");
619c5cb6
VZ
5110 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5111 break;
5112
5113 goto next_spqe;
5114
5115 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
5116 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5117 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
5118 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5119 break;
5120
5121 goto next_spqe;
523224a3
DK
5122 }
5123
5124 switch (opcode | bp->state) {
619c5cb6
VZ
5125 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5126 BNX2X_STATE_OPEN):
5127 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 5128 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
5129 cid = elem->message.data.eth_event.echo &
5130 BNX2X_SWCID_MASK;
d6cae238 5131 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
5132 cid);
5133 rss_raw->clear_pending(rss_raw);
523224a3
DK
5134 break;
5135
619c5cb6
VZ
5136 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5137 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
5138 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 5139 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
5140 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5141 BNX2X_STATE_OPEN):
5142 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5143 BNX2X_STATE_DIAG):
5144 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5145 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5146 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 5147 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
5148 break;
5149
619c5cb6
VZ
5150 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5151 BNX2X_STATE_OPEN):
5152 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5153 BNX2X_STATE_DIAG):
5154 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5155 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5156 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 5157 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
5158 break;
5159
619c5cb6
VZ
5160 case (EVENT_RING_OPCODE_FILTERS_RULES |
5161 BNX2X_STATE_OPEN):
5162 case (EVENT_RING_OPCODE_FILTERS_RULES |
5163 BNX2X_STATE_DIAG):
5164 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 5165 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5166 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 5167 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
5168 break;
5169 default:
5170 /* unknown event log error and continue */
619c5cb6
VZ
5171 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5172 elem->message.opcode, bp->state);
523224a3
DK
5173 }
5174next_spqe:
5175 spqe_cnt++;
5176 } /* for */
5177
8fe23fbd 5178 smp_mb__before_atomic_inc();
6e30dd4e 5179 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
5180
5181 bp->eq_cons = sw_cons;
5182 bp->eq_prod = sw_prod;
5183 /* Make sure that above mem writes were issued towards the memory */
5184 smp_wmb();
5185
5186 /* update producer */
5187 bnx2x_update_eq_prod(bp, bp->eq_prod);
5188}
5189
a2fbb9ea
ET
5190static void bnx2x_sp_task(struct work_struct *work)
5191{
1cf167f2 5192 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea 5193
fd1fc79d 5194 DP(BNX2X_MSG_SP, "sp task invoked\n");
a2fbb9ea 5195
16a5fd92 5196 /* make sure the atomic interrupt_occurred has been written */
fd1fc79d
AE
5197 smp_rmb();
5198 if (atomic_read(&bp->interrupt_occurred)) {
a2fbb9ea 5199
fd1fc79d
AE
5200 /* what work needs to be performed? */
5201 u16 status = bnx2x_update_dsb_idx(bp);
cdaa7cb8 5202
fd1fc79d
AE
5203 DP(BNX2X_MSG_SP, "status %x\n", status);
5204 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5205 atomic_set(&bp->interrupt_occurred, 0);
5206
5207 /* HW attentions */
5208 if (status & BNX2X_DEF_SB_ATT_IDX) {
5209 bnx2x_attn_int(bp);
5210 status &= ~BNX2X_DEF_SB_ATT_IDX;
5211 }
5212
5213 /* SP events: STAT_QUERY and others */
5214 if (status & BNX2X_DEF_SB_IDX) {
5215 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5216
55c11941 5217 if (FCOE_INIT(bp) &&
fd1fc79d
AE
5218 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5219 /* Prevent local bottom-halves from running as
5220 * we are going to change the local NAPI list.
5221 */
5222 local_bh_disable();
5223 napi_schedule(&bnx2x_fcoe(bp, napi));
5224 local_bh_enable();
5225 }
5226
5227 /* Handle EQ completions */
5228 bnx2x_eq_int(bp);
5229 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5230 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5231
5232 status &= ~BNX2X_DEF_SB_IDX;
019dbb4c 5233 }
55c11941 5234
fd1fc79d
AE
5235 /* if status is non zero then perhaps something went wrong */
5236 if (unlikely(status))
5237 DP(BNX2X_MSG_SP,
5238 "got an unknown interrupt! (status 0x%x)\n", status);
523224a3 5239
fd1fc79d
AE
5240 /* ack status block only if something was actually handled */
5241 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5242 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
cdaa7cb8
VZ
5243 }
5244
fd1fc79d
AE
5245 /* must be called after the EQ processing (since eq leads to sriov
5246 * ramrod completion flows).
5247 * This flow may have been scheduled by the arrival of a ramrod
5248 * completion, or by the sriov code rescheduling itself.
5249 */
5250 bnx2x_iov_sp_task(bp);
a3348722
BW
5251
5252 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5253 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5254 &bp->sp_state)) {
5255 bnx2x_link_report(bp);
5256 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5257 }
a2fbb9ea
ET
5258}
5259
9f6c9258 5260irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5261{
5262 struct net_device *dev = dev_instance;
5263 struct bnx2x *bp = netdev_priv(dev);
5264
523224a3
DK
5265 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5266 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5267
5268#ifdef BNX2X_STOP_ON_ERROR
5269 if (unlikely(bp->panic))
5270 return IRQ_HANDLED;
5271#endif
5272
55c11941 5273 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5274 struct cnic_ops *c_ops;
5275
5276 rcu_read_lock();
5277 c_ops = rcu_dereference(bp->cnic_ops);
5278 if (c_ops)
5279 c_ops->cnic_handler(bp->cnic_data, NULL);
5280 rcu_read_unlock();
5281 }
55c11941 5282
fd1fc79d
AE
5283 /* schedule sp task to perform default status block work, ack
5284 * attentions and enable interrupts.
5285 */
5286 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
5287
5288 return IRQ_HANDLED;
5289}
5290
5291/* end of slow path */
5292
619c5cb6
VZ
5293void bnx2x_drv_pulse(struct bnx2x *bp)
5294{
5295 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5296 bp->fw_drv_pulse_wr_seq);
5297}
5298
a2fbb9ea
ET
5299static void bnx2x_timer(unsigned long data)
5300{
5301 struct bnx2x *bp = (struct bnx2x *) data;
5302
5303 if (!netif_running(bp->dev))
5304 return;
5305
67c431a5
AE
5306 if (IS_PF(bp) &&
5307 !BP_NOMCP(bp)) {
f2e0899f 5308 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
5309 u32 drv_pulse;
5310 u32 mcp_pulse;
5311
5312 ++bp->fw_drv_pulse_wr_seq;
5313 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5314 /* TBD - add SYSTEM_TIME */
5315 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5316 bnx2x_drv_pulse(bp);
a2fbb9ea 5317
f2e0899f 5318 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5319 MCP_PULSE_SEQ_MASK);
5320 /* The delta between driver pulse and mcp response
5321 * should be 1 (before mcp response) or 0 (after mcp response)
5322 */
5323 if ((drv_pulse != mcp_pulse) &&
5324 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5325 /* someone lost a heartbeat... */
5326 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5327 drv_pulse, mcp_pulse);
5328 }
5329 }
5330
f34d28ea 5331 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5332 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5333
abc5a021
AE
5334 /* sample pf vf bulletin board for new posts from pf */
5335 if (IS_VF(bp))
5336 bnx2x_sample_bulletin(bp);
5337
a2fbb9ea
ET
5338 mod_timer(&bp->timer, jiffies + bp->current_interval);
5339}
5340
5341/* end of Statistics */
5342
5343/* nic init */
5344
5345/*
5346 * nic init service functions
5347 */
5348
1191cb83 5349static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5350{
523224a3
DK
5351 u32 i;
5352 if (!(len%4) && !(addr%4))
5353 for (i = 0; i < len; i += 4)
5354 REG_WR(bp, addr + i, fill);
5355 else
5356 for (i = 0; i < len; i++)
5357 REG_WR8(bp, addr + i, fill);
34f80b04
EG
5358}
5359
523224a3 5360/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5361static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5362 int fw_sb_id,
5363 u32 *sb_data_p,
5364 u32 data_size)
34f80b04 5365{
a2fbb9ea 5366 int index;
523224a3
DK
5367 for (index = 0; index < data_size; index++)
5368 REG_WR(bp, BAR_CSTRORM_INTMEM +
5369 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5370 sizeof(u32)*index,
5371 *(sb_data_p + index));
5372}
a2fbb9ea 5373
1191cb83 5374static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5375{
5376 u32 *sb_data_p;
5377 u32 data_size = 0;
f2e0899f 5378 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5379 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5380
523224a3 5381 /* disable the function first */
619c5cb6 5382 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5383 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5384 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5385 sb_data_e2.common.p_func.vf_valid = false;
5386 sb_data_p = (u32 *)&sb_data_e2;
5387 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5388 } else {
5389 memset(&sb_data_e1x, 0,
5390 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5391 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5392 sb_data_e1x.common.p_func.vf_valid = false;
5393 sb_data_p = (u32 *)&sb_data_e1x;
5394 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5395 }
523224a3 5396 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5397
523224a3
DK
5398 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5399 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5400 CSTORM_STATUS_BLOCK_SIZE);
5401 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5402 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5403 CSTORM_SYNC_BLOCK_SIZE);
5404}
34f80b04 5405
523224a3 5406/* helper: writes SP SB data to FW */
1191cb83 5407static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5408 struct hc_sp_status_block_data *sp_sb_data)
5409{
5410 int func = BP_FUNC(bp);
5411 int i;
5412 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5413 REG_WR(bp, BAR_CSTRORM_INTMEM +
5414 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5415 i*sizeof(u32),
5416 *((u32 *)sp_sb_data + i));
34f80b04
EG
5417}
5418
1191cb83 5419static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5420{
5421 int func = BP_FUNC(bp);
523224a3
DK
5422 struct hc_sp_status_block_data sp_sb_data;
5423 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5424
619c5cb6 5425 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5426 sp_sb_data.p_func.vf_valid = false;
5427
5428 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5429
5430 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5431 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5432 CSTORM_SP_STATUS_BLOCK_SIZE);
5433 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5434 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5435 CSTORM_SP_SYNC_BLOCK_SIZE);
523224a3
DK
5436}
5437
1191cb83 5438static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5439 int igu_sb_id, int igu_seg_id)
5440{
5441 hc_sm->igu_sb_id = igu_sb_id;
5442 hc_sm->igu_seg_id = igu_seg_id;
5443 hc_sm->timer_value = 0xFF;
5444 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5445}
5446
150966ad 5447/* allocates state machine ids. */
1191cb83 5448static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5449{
5450 /* zero out state machine indices */
5451 /* rx indices */
5452 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5453
5454 /* tx indices */
5455 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5456 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5457 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5458 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5459
5460 /* map indices */
5461 /* rx indices */
5462 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5463 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5464
5465 /* tx indices */
5466 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5467 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5468 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5469 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5470 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5471 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5472 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5473 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5474}
5475
b93288d5 5476void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5477 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5478{
523224a3
DK
5479 int igu_seg_id;
5480
f2e0899f 5481 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5482 struct hc_status_block_data_e1x sb_data_e1x;
5483 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5484 int data_size;
5485 u32 *sb_data_p;
5486
f2e0899f
DK
5487 if (CHIP_INT_MODE_IS_BC(bp))
5488 igu_seg_id = HC_SEG_ACCESS_NORM;
5489 else
5490 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5491
5492 bnx2x_zero_fp_sb(bp, fw_sb_id);
5493
619c5cb6 5494 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5495 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5496 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5497 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5498 sb_data_e2.common.p_func.vf_id = vfid;
5499 sb_data_e2.common.p_func.vf_valid = vf_valid;
5500 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5501 sb_data_e2.common.same_igu_sb_1b = true;
5502 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5503 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5504 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5505 sb_data_p = (u32 *)&sb_data_e2;
5506 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5507 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5508 } else {
5509 memset(&sb_data_e1x, 0,
5510 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5511 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5512 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5513 sb_data_e1x.common.p_func.vf_id = 0xff;
5514 sb_data_e1x.common.p_func.vf_valid = false;
5515 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5516 sb_data_e1x.common.same_igu_sb_1b = true;
5517 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5518 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5519 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5520 sb_data_p = (u32 *)&sb_data_e1x;
5521 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5522 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5523 }
523224a3
DK
5524
5525 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5526 igu_sb_id, igu_seg_id);
5527 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5528 igu_sb_id, igu_seg_id);
5529
51c1a580 5530 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3 5531
86564c3f 5532 /* write indices to HW - PCI guarantees endianity of regpairs */
523224a3
DK
5533 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5534}
5535
619c5cb6 5536static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5537 u16 tx_usec, u16 rx_usec)
5538{
6383c0b3 5539 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5540 false, rx_usec);
6383c0b3
AE
5541 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5542 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5543 tx_usec);
5544 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5545 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5546 tx_usec);
5547 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5548 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5549 tx_usec);
523224a3 5550}
f2e0899f 5551
523224a3
DK
5552static void bnx2x_init_def_sb(struct bnx2x *bp)
5553{
5554 struct host_sp_status_block *def_sb = bp->def_status_blk;
5555 dma_addr_t mapping = bp->def_status_blk_mapping;
5556 int igu_sp_sb_index;
5557 int igu_seg_id;
34f80b04
EG
5558 int port = BP_PORT(bp);
5559 int func = BP_FUNC(bp);
f2eaeb58 5560 int reg_offset, reg_offset_en5;
a2fbb9ea 5561 u64 section;
523224a3
DK
5562 int index;
5563 struct hc_sp_status_block_data sp_sb_data;
5564 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5565
f2e0899f
DK
5566 if (CHIP_INT_MODE_IS_BC(bp)) {
5567 igu_sp_sb_index = DEF_SB_IGU_ID;
5568 igu_seg_id = HC_SEG_ACCESS_DEF;
5569 } else {
5570 igu_sp_sb_index = bp->igu_dsb_id;
5571 igu_seg_id = IGU_SEG_ACCESS_DEF;
5572 }
a2fbb9ea
ET
5573
5574 /* ATTN */
523224a3 5575 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5576 atten_status_block);
523224a3 5577 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5578
49d66772
ET
5579 bp->attn_state = 0;
5580
a2fbb9ea
ET
5581 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5582 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5583 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5584 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5585 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5586 int sindex;
5587 /* take care of sig[0]..sig[4] */
5588 for (sindex = 0; sindex < 4; sindex++)
5589 bp->attn_group[index].sig[sindex] =
5590 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5591
619c5cb6 5592 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5593 /*
5594 * enable5 is separate from the rest of the registers,
5595 * and therefore the address skip is 4
5596 * and not 16 between the different groups
5597 */
5598 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5599 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5600 else
5601 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5602 }
5603
f2e0899f
DK
5604 if (bp->common.int_block == INT_BLOCK_HC) {
5605 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5606 HC_REG_ATTN_MSG0_ADDR_L);
5607
5608 REG_WR(bp, reg_offset, U64_LO(section));
5609 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5610 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5611 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5612 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5613 }
a2fbb9ea 5614
523224a3
DK
5615 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5616 sp_sb);
a2fbb9ea 5617
523224a3 5618 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5619
86564c3f 5620 /* PCI guarantees endianity of regpairs */
619c5cb6 5621 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5622 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5623 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5624 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5625 sp_sb_data.igu_seg_id = igu_seg_id;
5626 sp_sb_data.p_func.pf_id = func;
f2e0899f 5627 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5628 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5629
523224a3 5630 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5631
523224a3 5632 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5633}
5634
9f6c9258 5635void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5636{
a2fbb9ea
ET
5637 int i;
5638
ec6ba945 5639 for_each_eth_queue(bp, i)
523224a3 5640 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5641 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5642}
5643
a2fbb9ea
ET
5644static void bnx2x_init_sp_ring(struct bnx2x *bp)
5645{
a2fbb9ea 5646 spin_lock_init(&bp->spq_lock);
6e30dd4e 5647 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5648
a2fbb9ea 5649 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5650 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5651 bp->spq_prod_bd = bp->spq;
5652 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5653}
5654
523224a3 5655static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5656{
5657 int i;
523224a3
DK
5658 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5659 union event_ring_elem *elem =
5660 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5661
523224a3
DK
5662 elem->next_page.addr.hi =
5663 cpu_to_le32(U64_HI(bp->eq_mapping +
5664 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5665 elem->next_page.addr.lo =
5666 cpu_to_le32(U64_LO(bp->eq_mapping +
5667 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5668 }
523224a3
DK
5669 bp->eq_cons = 0;
5670 bp->eq_prod = NUM_EQ_DESC;
5671 bp->eq_cons_sb = BNX2X_EQ_INDEX;
16a5fd92 5672 /* we want a warning message before it gets wrought... */
6e30dd4e
VZ
5673 atomic_set(&bp->eq_spq_left,
5674 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5675}
5676
619c5cb6 5677/* called with netif_addr_lock_bh() */
924d75ab
YM
5678int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5679 unsigned long rx_mode_flags,
5680 unsigned long rx_accept_flags,
5681 unsigned long tx_accept_flags,
5682 unsigned long ramrod_flags)
ab532cf3 5683{
619c5cb6
VZ
5684 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5685 int rc;
5686
5687 memset(&ramrod_param, 0, sizeof(ramrod_param));
5688
5689 /* Prepare ramrod parameters */
5690 ramrod_param.cid = 0;
5691 ramrod_param.cl_id = cl_id;
5692 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5693 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5694
619c5cb6
VZ
5695 ramrod_param.pstate = &bp->sp_state;
5696 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5697
619c5cb6
VZ
5698 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5699 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5700
5701 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5702
5703 ramrod_param.ramrod_flags = ramrod_flags;
5704 ramrod_param.rx_mode_flags = rx_mode_flags;
5705
5706 ramrod_param.rx_accept_flags = rx_accept_flags;
5707 ramrod_param.tx_accept_flags = tx_accept_flags;
5708
5709 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5710 if (rc < 0) {
5711 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
924d75ab 5712 return rc;
619c5cb6 5713 }
924d75ab
YM
5714
5715 return 0;
a2fbb9ea
ET
5716}
5717
86564c3f
YM
5718static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
5719 unsigned long *rx_accept_flags,
5720 unsigned long *tx_accept_flags)
471de716 5721{
924d75ab
YM
5722 /* Clear the flags first */
5723 *rx_accept_flags = 0;
5724 *tx_accept_flags = 0;
619c5cb6 5725
924d75ab 5726 switch (rx_mode) {
619c5cb6
VZ
5727 case BNX2X_RX_MODE_NONE:
5728 /*
5729 * 'drop all' supersedes any accept flags that may have been
5730 * passed to the function.
5731 */
5732 break;
5733 case BNX2X_RX_MODE_NORMAL:
924d75ab
YM
5734 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5735 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
5736 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5737
5738 /* internal switching mode */
924d75ab
YM
5739 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5740 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
5741 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5742
5743 break;
5744 case BNX2X_RX_MODE_ALLMULTI:
924d75ab
YM
5745 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5746 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5747 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5748
5749 /* internal switching mode */
924d75ab
YM
5750 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5751 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5752 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5753
5754 break;
5755 case BNX2X_RX_MODE_PROMISC:
16a5fd92 5756 /* According to definition of SI mode, iface in promisc mode
619c5cb6
VZ
5757 * should receive matched and unmatched (in resolution of port)
5758 * unicast packets.
5759 */
924d75ab
YM
5760 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
5761 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5762 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5763 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5764
5765 /* internal switching mode */
924d75ab
YM
5766 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5767 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5768
5769 if (IS_MF_SI(bp))
924d75ab 5770 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
619c5cb6 5771 else
924d75ab 5772 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
619c5cb6
VZ
5773
5774 break;
5775 default:
924d75ab
YM
5776 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
5777 return -EINVAL;
619c5cb6 5778 }
de832a55 5779
924d75ab 5780 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
619c5cb6 5781 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
924d75ab
YM
5782 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
5783 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
34f80b04
EG
5784 }
5785
924d75ab
YM
5786 return 0;
5787}
5788
5789/* called with netif_addr_lock_bh() */
5790int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5791{
5792 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5793 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5794 int rc;
5795
5796 if (!NO_FCOE(bp))
5797 /* Configure rx_mode of FCoE Queue */
5798 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5799
5800 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
5801 &tx_accept_flags);
5802 if (rc)
5803 return rc;
5804
619c5cb6
VZ
5805 __set_bit(RAMROD_RX, &ramrod_flags);
5806 __set_bit(RAMROD_TX, &ramrod_flags);
5807
924d75ab
YM
5808 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
5809 rx_accept_flags, tx_accept_flags,
5810 ramrod_flags);
619c5cb6
VZ
5811}
5812
5813static void bnx2x_init_internal_common(struct bnx2x *bp)
5814{
5815 int i;
5816
0793f83f
DK
5817 if (IS_MF_SI(bp))
5818 /*
5819 * In switch independent mode, the TSTORM needs to accept
5820 * packets that failed classification, since approximate match
5821 * mac addresses aren't written to NIG LLH
5822 */
5823 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5824 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5825 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5826 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5827 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5828
523224a3
DK
5829 /* Zero this manually as its initialization is
5830 currently missing in the initTool */
5831 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5832 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5833 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5834 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5835 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5836 CHIP_INT_MODE_IS_BC(bp) ?
5837 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5838 }
523224a3 5839}
8a1c38d1 5840
471de716
EG
5841static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5842{
5843 switch (load_code) {
5844 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5845 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5846 bnx2x_init_internal_common(bp);
5847 /* no break */
5848
5849 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5850 /* nothing to do */
471de716
EG
5851 /* no break */
5852
5853 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5854 /* internal memory per function is
5855 initialized inside bnx2x_pf_init */
471de716
EG
5856 break;
5857
5858 default:
5859 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5860 break;
5861 }
5862}
5863
619c5cb6 5864static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5865{
55c11941 5866 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 5867}
523224a3 5868
619c5cb6
VZ
5869static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5870{
55c11941 5871 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
5872}
5873
1191cb83 5874static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
5875{
5876 if (CHIP_IS_E1x(fp->bp))
5877 return BP_L_ID(fp->bp) + fp->index;
5878 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5879 return bnx2x_fp_igu_sb_id(fp);
5880}
5881
6383c0b3 5882static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5883{
5884 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5885 u8 cos;
619c5cb6 5886 unsigned long q_type = 0;
6383c0b3 5887 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5888 fp->rx_queue = fp_idx;
b3b83c3f 5889 fp->cid = fp_idx;
619c5cb6
VZ
5890 fp->cl_id = bnx2x_fp_cl_id(fp);
5891 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5892 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5893 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5894 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5895
523224a3 5896 /* init shortcut */
619c5cb6 5897 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5898
16a5fd92 5899 /* Setup SB indices */
523224a3 5900 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5901
619c5cb6
VZ
5902 /* Configure Queue State object */
5903 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5904 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5905
5906 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5907
5908 /* init tx data */
5909 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
5910 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5911 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5912 FP_COS_TO_TXQ(fp, cos, bp),
5913 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5914 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
5915 }
5916
ad5afc89
AE
5917 /* nothing more for vf to do here */
5918 if (IS_VF(bp))
5919 return;
5920
5921 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5922 fp->fw_sb_id, fp->igu_sb_id);
5923 bnx2x_update_fpsb_idx(fp);
15192a8c
BW
5924 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5925 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 5926 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5927
5928 /**
5929 * Configure classification DBs: Always enable Tx switching
5930 */
5931 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5932
ad5afc89
AE
5933 DP(NETIF_MSG_IFUP,
5934 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5935 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5936 fp->igu_sb_id);
523224a3
DK
5937}
5938
1191cb83
ED
5939static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5940{
5941 int i;
5942
5943 for (i = 1; i <= NUM_TX_RINGS; i++) {
5944 struct eth_tx_next_bd *tx_next_bd =
5945 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5946
5947 tx_next_bd->addr_hi =
5948 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5949 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5950 tx_next_bd->addr_lo =
5951 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5952 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5953 }
5954
5955 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5956 txdata->tx_db.data.zero_fill1 = 0;
5957 txdata->tx_db.data.prod = 0;
5958
5959 txdata->tx_pkt_prod = 0;
5960 txdata->tx_pkt_cons = 0;
5961 txdata->tx_bd_prod = 0;
5962 txdata->tx_bd_cons = 0;
5963 txdata->tx_pkt = 0;
5964}
5965
55c11941
MS
5966static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
5967{
5968 int i;
5969
5970 for_each_tx_queue_cnic(bp, i)
5971 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
5972}
d76a6111 5973
1191cb83
ED
5974static void bnx2x_init_tx_rings(struct bnx2x *bp)
5975{
5976 int i;
5977 u8 cos;
5978
55c11941 5979 for_each_eth_queue(bp, i)
1191cb83 5980 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 5981 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
5982}
5983
55c11941 5984void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 5985{
ec6ba945
VZ
5986 if (!NO_FCOE(bp))
5987 bnx2x_init_fcoe_fp(bp);
523224a3
DK
5988
5989 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5990 BNX2X_VF_ID_INVALID, false,
619c5cb6 5991 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 5992
55c11941
MS
5993 /* ensure status block indices were read */
5994 rmb();
5995 bnx2x_init_rx_rings_cnic(bp);
5996 bnx2x_init_tx_rings_cnic(bp);
5997
5998 /* flush all */
5999 mb();
6000 mmiowb();
6001}
a2fbb9ea 6002
ecf01c22 6003void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
55c11941
MS
6004{
6005 int i;
6006
ecf01c22 6007 /* Setup NIC internals and enable interrupts */
55c11941
MS
6008 for_each_eth_queue(bp, i)
6009 bnx2x_init_eth_fp(bp, i);
ad5afc89
AE
6010
6011 /* ensure status block indices were read */
6012 rmb();
6013 bnx2x_init_rx_rings(bp);
6014 bnx2x_init_tx_rings(bp);
6015
5b0752c8
AE
6016 if (IS_VF(bp)) {
6017 bnx2x_memset_stats(bp);
ad5afc89 6018 return;
5b0752c8 6019 }
ad5afc89 6020
ecf01c22
YM
6021 if (IS_PF(bp)) {
6022 /* Initialize MOD_ABS interrupts */
6023 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6024 bp->common.shmem_base,
6025 bp->common.shmem2_base, BP_PORT(bp));
ad5afc89 6026
ecf01c22
YM
6027 /* initialize the default status block and sp ring */
6028 bnx2x_init_def_sb(bp);
6029 bnx2x_update_dsb_idx(bp);
6030 bnx2x_init_sp_ring(bp);
6031 }
6032}
16119785 6033
ecf01c22
YM
6034void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6035{
523224a3 6036 bnx2x_init_eq_ring(bp);
471de716 6037 bnx2x_init_internal(bp, load_code);
523224a3 6038 bnx2x_pf_init(bp);
0ef00459
EG
6039 bnx2x_stats_init(bp);
6040
0ef00459
EG
6041 /* flush all before enabling interrupts */
6042 mb();
6043 mmiowb();
6044
615f8fd9 6045 bnx2x_int_enable(bp);
eb8da205
EG
6046
6047 /* Check for SPIO5 */
6048 bnx2x_attn_int_deasserted0(bp,
6049 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6050 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
6051}
6052
ecf01c22 6053/* gzip service functions */
a2fbb9ea
ET
6054static int bnx2x_gunzip_init(struct bnx2x *bp)
6055{
1a983142
FT
6056 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6057 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
6058 if (bp->gunzip_buf == NULL)
6059 goto gunzip_nomem1;
6060
6061 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6062 if (bp->strm == NULL)
6063 goto gunzip_nomem2;
6064
7ab24bfd 6065 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
6066 if (bp->strm->workspace == NULL)
6067 goto gunzip_nomem3;
6068
6069 return 0;
6070
6071gunzip_nomem3:
6072 kfree(bp->strm);
6073 bp->strm = NULL;
6074
6075gunzip_nomem2:
1a983142
FT
6076 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6077 bp->gunzip_mapping);
a2fbb9ea
ET
6078 bp->gunzip_buf = NULL;
6079
6080gunzip_nomem1:
51c1a580 6081 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
6082 return -ENOMEM;
6083}
6084
6085static void bnx2x_gunzip_end(struct bnx2x *bp)
6086{
b3b83c3f 6087 if (bp->strm) {
7ab24bfd 6088 vfree(bp->strm->workspace);
b3b83c3f
DK
6089 kfree(bp->strm);
6090 bp->strm = NULL;
6091 }
a2fbb9ea
ET
6092
6093 if (bp->gunzip_buf) {
1a983142
FT
6094 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6095 bp->gunzip_mapping);
a2fbb9ea
ET
6096 bp->gunzip_buf = NULL;
6097 }
6098}
6099
94a78b79 6100static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
6101{
6102 int n, rc;
6103
6104 /* check gzip header */
94a78b79
VZ
6105 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6106 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 6107 return -EINVAL;
94a78b79 6108 }
a2fbb9ea
ET
6109
6110 n = 10;
6111
34f80b04 6112#define FNAME 0x8
a2fbb9ea
ET
6113
6114 if (zbuf[3] & FNAME)
6115 while ((zbuf[n++] != 0) && (n < len));
6116
94a78b79 6117 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
6118 bp->strm->avail_in = len - n;
6119 bp->strm->next_out = bp->gunzip_buf;
6120 bp->strm->avail_out = FW_BUF_SIZE;
6121
6122 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6123 if (rc != Z_OK)
6124 return rc;
6125
6126 rc = zlib_inflate(bp->strm, Z_FINISH);
6127 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
6128 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6129 bp->strm->msg);
a2fbb9ea
ET
6130
6131 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6132 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
6133 netdev_err(bp->dev,
6134 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 6135 bp->gunzip_outlen);
a2fbb9ea
ET
6136 bp->gunzip_outlen >>= 2;
6137
6138 zlib_inflateEnd(bp->strm);
6139
6140 if (rc == Z_STREAM_END)
6141 return 0;
6142
6143 return rc;
6144}
6145
6146/* nic load/unload */
6147
6148/*
34f80b04 6149 * General service functions
a2fbb9ea
ET
6150 */
6151
6152/* send a NIG loopback debug packet */
6153static void bnx2x_lb_pckt(struct bnx2x *bp)
6154{
a2fbb9ea 6155 u32 wb_write[3];
a2fbb9ea
ET
6156
6157 /* Ethernet source and destination addresses */
a2fbb9ea
ET
6158 wb_write[0] = 0x55555555;
6159 wb_write[1] = 0x55555555;
34f80b04 6160 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 6161 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6162
6163 /* NON-IP protocol */
a2fbb9ea
ET
6164 wb_write[0] = 0x09000000;
6165 wb_write[1] = 0x55555555;
34f80b04 6166 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 6167 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6168}
6169
6170/* some of the internal memories
6171 * are not directly readable from the driver
6172 * to test them we send debug packets
6173 */
6174static int bnx2x_int_mem_test(struct bnx2x *bp)
6175{
6176 int factor;
6177 int count, i;
6178 u32 val = 0;
6179
ad8d3948 6180 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 6181 factor = 120;
ad8d3948
EG
6182 else if (CHIP_REV_IS_EMUL(bp))
6183 factor = 200;
6184 else
a2fbb9ea 6185 factor = 1;
a2fbb9ea 6186
a2fbb9ea
ET
6187 /* Disable inputs of parser neighbor blocks */
6188 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6189 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6190 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6191 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6192
6193 /* Write 0 to parser credits for CFC search request */
6194 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6195
6196 /* send Ethernet packet */
6197 bnx2x_lb_pckt(bp);
6198
6199 /* TODO do i reset NIG statistic? */
6200 /* Wait until NIG register shows 1 packet of size 0x10 */
6201 count = 1000 * factor;
6202 while (count) {
34f80b04 6203
a2fbb9ea
ET
6204 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6205 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6206 if (val == 0x10)
6207 break;
6208
6209 msleep(10);
6210 count--;
6211 }
6212 if (val != 0x10) {
6213 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6214 return -1;
6215 }
6216
6217 /* Wait until PRS register shows 1 packet */
6218 count = 1000 * factor;
6219 while (count) {
6220 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
6221 if (val == 1)
6222 break;
6223
6224 msleep(10);
6225 count--;
6226 }
6227 if (val != 0x1) {
6228 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6229 return -2;
6230 }
6231
6232 /* Reset and init BRB, PRS */
34f80b04 6233 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 6234 msleep(50);
34f80b04 6235 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 6236 msleep(50);
619c5cb6
VZ
6237 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6238 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
6239
6240 DP(NETIF_MSG_HW, "part2\n");
6241
6242 /* Disable inputs of parser neighbor blocks */
6243 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6244 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6245 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6246 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6247
6248 /* Write 0 to parser credits for CFC search request */
6249 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6250
6251 /* send 10 Ethernet packets */
6252 for (i = 0; i < 10; i++)
6253 bnx2x_lb_pckt(bp);
6254
6255 /* Wait until NIG register shows 10 + 1
6256 packets of size 11*0x10 = 0xb0 */
6257 count = 1000 * factor;
6258 while (count) {
34f80b04 6259
a2fbb9ea
ET
6260 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6261 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6262 if (val == 0xb0)
6263 break;
6264
6265 msleep(10);
6266 count--;
6267 }
6268 if (val != 0xb0) {
6269 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6270 return -3;
6271 }
6272
6273 /* Wait until PRS register shows 2 packets */
6274 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6275 if (val != 2)
6276 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6277
6278 /* Write 1 to parser credits for CFC search request */
6279 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6280
6281 /* Wait until PRS register shows 3 packets */
6282 msleep(10 * factor);
6283 /* Wait until NIG register shows 1 packet of size 0x10 */
6284 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6285 if (val != 3)
6286 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6287
6288 /* clear NIG EOP FIFO */
6289 for (i = 0; i < 11; i++)
6290 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6291 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6292 if (val != 1) {
6293 BNX2X_ERR("clear of NIG failed\n");
6294 return -4;
6295 }
6296
6297 /* Reset and init BRB, PRS, NIG */
6298 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6299 msleep(50);
6300 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6301 msleep(50);
619c5cb6
VZ
6302 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6303 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6304 if (!CNIC_SUPPORT(bp))
6305 /* set NIC mode */
6306 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6307
6308 /* Enable inputs of parser neighbor blocks */
6309 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6310 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6311 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6312 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6313
6314 DP(NETIF_MSG_HW, "done\n");
6315
6316 return 0; /* OK */
6317}
6318
4a33bc03 6319static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea 6320{
b343d002
YM
6321 u32 val;
6322
a2fbb9ea 6323 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6324 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6325 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6326 else
6327 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6328 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6329 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6330 /*
6331 * mask read length error interrupts in brb for parser
6332 * (parsing unit and 'checksum and crc' unit)
6333 * these errors are legal (PU reads fixed length and CAC can cause
6334 * read length error on truncated packets)
6335 */
6336 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6337 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6338 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6339 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6340 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6341 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6342/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6343/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6344 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6345 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6346 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6347/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6348/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6349 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6350 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6351 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6352 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6353/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6354/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6355
b343d002
YM
6356 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6357 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6358 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6359 if (!CHIP_IS_E1x(bp))
6360 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6361 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6362 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6363
a2fbb9ea
ET
6364 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6365 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6366 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6367/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6368
6369 if (!CHIP_IS_E1x(bp))
6370 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6371 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6372
a2fbb9ea
ET
6373 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6374 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6375/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6376 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6377}
6378
81f75bbf
EG
6379static void bnx2x_reset_common(struct bnx2x *bp)
6380{
619c5cb6
VZ
6381 u32 val = 0x1400;
6382
81f75bbf
EG
6383 /* reset_common */
6384 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6385 0xd3ffff7f);
619c5cb6
VZ
6386
6387 if (CHIP_IS_E3(bp)) {
6388 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6389 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6390 }
6391
6392 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6393}
6394
6395static void bnx2x_setup_dmae(struct bnx2x *bp)
6396{
6397 bp->dmae_ready = 0;
6398 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6399}
6400
573f2035
EG
6401static void bnx2x_init_pxp(struct bnx2x *bp)
6402{
6403 u16 devctl;
6404 int r_order, w_order;
6405
2a80eebc 6406 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6407 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6408 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6409 if (bp->mrrs == -1)
6410 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6411 else {
6412 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6413 r_order = bp->mrrs;
6414 }
6415
6416 bnx2x_init_pxp_arb(bp, r_order, w_order);
6417}
fd4ef40d
EG
6418
6419static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6420{
2145a920 6421 int is_required;
fd4ef40d 6422 u32 val;
2145a920 6423 int port;
fd4ef40d 6424
2145a920
VZ
6425 if (BP_NOMCP(bp))
6426 return;
6427
6428 is_required = 0;
fd4ef40d
EG
6429 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6430 SHARED_HW_CFG_FAN_FAILURE_MASK;
6431
6432 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6433 is_required = 1;
6434
6435 /*
6436 * The fan failure mechanism is usually related to the PHY type since
6437 * the power consumption of the board is affected by the PHY. Currently,
6438 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6439 */
6440 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6441 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6442 is_required |=
d90d96ba
YR
6443 bnx2x_fan_failure_det_req(
6444 bp,
6445 bp->common.shmem_base,
a22f0788 6446 bp->common.shmem2_base,
d90d96ba 6447 port);
fd4ef40d
EG
6448 }
6449
6450 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6451
6452 if (is_required == 0)
6453 return;
6454
6455 /* Fan failure is indicated by SPIO 5 */
d6d99a3f 6456 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
fd4ef40d
EG
6457
6458 /* set to active low mode */
6459 val = REG_RD(bp, MISC_REG_SPIO_INT);
d6d99a3f 6460 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6461 REG_WR(bp, MISC_REG_SPIO_INT, val);
6462
6463 /* enable interrupt to signal the IGU */
6464 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6465 val |= MISC_SPIO_SPIO5;
fd4ef40d
EG
6466 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6467}
6468
c9ee9206 6469void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6470{
6471 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6472 val &= ~IGU_PF_CONF_FUNC_EN;
6473
6474 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6475 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6476 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6477}
6478
1191cb83 6479static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6480{
6481 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6482 /* Avoid common init in case MFW supports LFA */
6483 if (SHMEM2_RD(bp, size) >
6484 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6485 return;
619c5cb6
VZ
6486 shmem_base[0] = bp->common.shmem_base;
6487 shmem2_base[0] = bp->common.shmem2_base;
6488 if (!CHIP_IS_E1x(bp)) {
6489 shmem_base[1] =
6490 SHMEM2_RD(bp, other_shmem_base_addr);
6491 shmem2_base[1] =
6492 SHMEM2_RD(bp, other_shmem2_base_addr);
6493 }
6494 bnx2x_acquire_phy_lock(bp);
6495 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6496 bp->common.chip_id);
6497 bnx2x_release_phy_lock(bp);
6498}
6499
6500/**
6501 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6502 *
6503 * @bp: driver handle
6504 */
6505static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6506{
619c5cb6 6507 u32 val;
a2fbb9ea 6508
51c1a580 6509 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6510
2031bd3a 6511 /*
2de67439 6512 * take the RESET lock to protect undi_unload flow from accessing
2031bd3a
DK
6513 * registers while we're resetting the chip
6514 */
7a06a122 6515 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6516
81f75bbf 6517 bnx2x_reset_common(bp);
34f80b04 6518 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6519
619c5cb6
VZ
6520 val = 0xfffc;
6521 if (CHIP_IS_E3(bp)) {
6522 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6523 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6524 }
6525 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6526
7a06a122 6527 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6528
619c5cb6 6529 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6530
619c5cb6
VZ
6531 if (!CHIP_IS_E1x(bp)) {
6532 u8 abs_func_id;
f2e0899f
DK
6533
6534 /**
6535 * 4-port mode or 2-port mode we need to turn of master-enable
6536 * for everyone, after that, turn it back on for self.
6537 * so, we disregard multi-function or not, and always disable
6538 * for all functions on the given path, this means 0,2,4,6 for
6539 * path 0 and 1,3,5,7 for path 1
6540 */
619c5cb6
VZ
6541 for (abs_func_id = BP_PATH(bp);
6542 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6543 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6544 REG_WR(bp,
6545 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6546 1);
6547 continue;
6548 }
6549
619c5cb6 6550 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6551 /* clear pf enable */
6552 bnx2x_pf_disable(bp);
6553 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6554 }
6555 }
a2fbb9ea 6556
619c5cb6 6557 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6558 if (CHIP_IS_E1(bp)) {
6559 /* enable HW interrupt from PXP on USDM overflow
6560 bit 16 on INT_MASK_0 */
6561 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6562 }
a2fbb9ea 6563
619c5cb6 6564 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6565 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6566
6567#ifdef __BIG_ENDIAN
34f80b04
EG
6568 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6569 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6570 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6571 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6572 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6573 /* make sure this value is 0 */
6574 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6575
6576/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6577 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6578 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6579 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6580 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6581#endif
6582
523224a3
DK
6583 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6584
34f80b04
EG
6585 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6586 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6587
34f80b04
EG
6588 /* let the HW do it's magic ... */
6589 msleep(100);
6590 /* finish PXP init */
6591 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6592 if (val != 1) {
6593 BNX2X_ERR("PXP2 CFG failed\n");
6594 return -EBUSY;
6595 }
6596 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6597 if (val != 1) {
6598 BNX2X_ERR("PXP2 RD_INIT failed\n");
6599 return -EBUSY;
6600 }
a2fbb9ea 6601
f2e0899f
DK
6602 /* Timers bug workaround E2 only. We need to set the entire ILT to
6603 * have entries with value "0" and valid bit on.
6604 * This needs to be done by the first PF that is loaded in a path
6605 * (i.e. common phase)
6606 */
619c5cb6
VZ
6607 if (!CHIP_IS_E1x(bp)) {
6608/* In E2 there is a bug in the timers block that can cause function 6 / 7
6609 * (i.e. vnic3) to start even if it is marked as "scan-off".
6610 * This occurs when a different function (func2,3) is being marked
6611 * as "scan-off". Real-life scenario for example: if a driver is being
6612 * load-unloaded while func6,7 are down. This will cause the timer to access
6613 * the ilt, translate to a logical address and send a request to read/write.
6614 * Since the ilt for the function that is down is not valid, this will cause
6615 * a translation error which is unrecoverable.
6616 * The Workaround is intended to make sure that when this happens nothing fatal
6617 * will occur. The workaround:
6618 * 1. First PF driver which loads on a path will:
6619 * a. After taking the chip out of reset, by using pretend,
6620 * it will write "0" to the following registers of
6621 * the other vnics.
6622 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6623 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6624 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6625 * And for itself it will write '1' to
6626 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6627 * dmae-operations (writing to pram for example.)
6628 * note: can be done for only function 6,7 but cleaner this
6629 * way.
6630 * b. Write zero+valid to the entire ILT.
6631 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6632 * VNIC3 (of that port). The range allocated will be the
6633 * entire ILT. This is needed to prevent ILT range error.
6634 * 2. Any PF driver load flow:
6635 * a. ILT update with the physical addresses of the allocated
6636 * logical pages.
6637 * b. Wait 20msec. - note that this timeout is needed to make
6638 * sure there are no requests in one of the PXP internal
6639 * queues with "old" ILT addresses.
6640 * c. PF enable in the PGLC.
6641 * d. Clear the was_error of the PF in the PGLC. (could have
2de67439 6642 * occurred while driver was down)
619c5cb6
VZ
6643 * e. PF enable in the CFC (WEAK + STRONG)
6644 * f. Timers scan enable
6645 * 3. PF driver unload flow:
6646 * a. Clear the Timers scan_en.
6647 * b. Polling for scan_on=0 for that PF.
6648 * c. Clear the PF enable bit in the PXP.
6649 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6650 * e. Write zero+valid to all ILT entries (The valid bit must
6651 * stay set)
6652 * f. If this is VNIC 3 of a port then also init
6653 * first_timers_ilt_entry to zero and last_timers_ilt_entry
16a5fd92 6654 * to the last entry in the ILT.
619c5cb6
VZ
6655 *
6656 * Notes:
6657 * Currently the PF error in the PGLC is non recoverable.
6658 * In the future the there will be a recovery routine for this error.
6659 * Currently attention is masked.
6660 * Having an MCP lock on the load/unload process does not guarantee that
6661 * there is no Timer disable during Func6/7 enable. This is because the
6662 * Timers scan is currently being cleared by the MCP on FLR.
6663 * Step 2.d can be done only for PF6/7 and the driver can also check if
6664 * there is error before clearing it. But the flow above is simpler and
6665 * more general.
6666 * All ILT entries are written by zero+valid and not just PF6/7
6667 * ILT entries since in the future the ILT entries allocation for
6668 * PF-s might be dynamic.
6669 */
f2e0899f
DK
6670 struct ilt_client_info ilt_cli;
6671 struct bnx2x_ilt ilt;
6672 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6673 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6674
b595076a 6675 /* initialize dummy TM client */
f2e0899f
DK
6676 ilt_cli.start = 0;
6677 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6678 ilt_cli.client_num = ILT_CLIENT_TM;
6679
6680 /* Step 1: set zeroes to all ilt page entries with valid bit on
6681 * Step 2: set the timers first/last ilt entry to point
6682 * to the entire range to prevent ILT range error for 3rd/4th
2de67439 6683 * vnic (this code assumes existence of the vnic)
f2e0899f
DK
6684 *
6685 * both steps performed by call to bnx2x_ilt_client_init_op()
6686 * with dummy TM client
6687 *
6688 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6689 * and his brother are split registers
6690 */
6691 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6692 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6693 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6694
6695 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6696 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6697 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6698 }
6699
34f80b04
EG
6700 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6701 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6702
619c5cb6 6703 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6704 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6705 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6706 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6707
619c5cb6 6708 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6709
6710 /* let the HW do it's magic ... */
6711 do {
6712 msleep(200);
6713 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6714 } while (factor-- && (val != 1));
6715
6716 if (val != 1) {
6717 BNX2X_ERR("ATC_INIT failed\n");
6718 return -EBUSY;
6719 }
6720 }
6721
619c5cb6 6722 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6723
b56e9670
AE
6724 bnx2x_iov_init_dmae(bp);
6725
34f80b04
EG
6726 /* clean the DMAE memory */
6727 bp->dmae_ready = 1;
619c5cb6
VZ
6728 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6729
6730 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6731
6732 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6733
6734 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6735
619c5cb6 6736 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6737
34f80b04
EG
6738 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6739 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6740 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6741 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6742
619c5cb6 6743 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6744
523224a3
DK
6745 /* QM queues pointers table */
6746 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6747
34f80b04
EG
6748 /* soft reset pulse */
6749 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6750 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6751
55c11941
MS
6752 if (CNIC_SUPPORT(bp))
6753 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6754
619c5cb6 6755 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6756 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6757 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6758 /* enable hw interrupt from doorbell Q */
6759 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6760
619c5cb6 6761 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6762
619c5cb6 6763 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6764 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6765
f2e0899f 6766 if (!CHIP_IS_E1(bp))
619c5cb6 6767 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6768
a3348722
BW
6769 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6770 if (IS_MF_AFEX(bp)) {
6771 /* configure that VNTag and VLAN headers must be
6772 * received in afex mode
6773 */
6774 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6775 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6776 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6777 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6778 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6779 } else {
6780 /* Bit-map indicating which L2 hdrs may appear
6781 * after the basic Ethernet header
6782 */
6783 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6784 bp->path_has_ovlan ? 7 : 6);
6785 }
6786 }
a2fbb9ea 6787
619c5cb6
VZ
6788 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6789 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6790 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6791 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6792
619c5cb6
VZ
6793 if (!CHIP_IS_E1x(bp)) {
6794 /* reset VFC memories */
6795 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6796 VFC_MEMORIES_RST_REG_CAM_RST |
6797 VFC_MEMORIES_RST_REG_RAM_RST);
6798 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6799 VFC_MEMORIES_RST_REG_CAM_RST |
6800 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6801
619c5cb6
VZ
6802 msleep(20);
6803 }
a2fbb9ea 6804
619c5cb6
VZ
6805 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6806 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6807 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6808 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6809
34f80b04
EG
6810 /* sync semi rtc */
6811 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6812 0x80000000);
6813 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6814 0x80000000);
a2fbb9ea 6815
619c5cb6
VZ
6816 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6817 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6818 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6819
a3348722
BW
6820 if (!CHIP_IS_E1x(bp)) {
6821 if (IS_MF_AFEX(bp)) {
6822 /* configure that VNTag and VLAN headers must be
6823 * sent in afex mode
6824 */
6825 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6826 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6827 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6828 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6829 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6830 } else {
6831 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6832 bp->path_has_ovlan ? 7 : 6);
6833 }
6834 }
f2e0899f 6835
34f80b04 6836 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6837
619c5cb6
VZ
6838 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6839
55c11941
MS
6840 if (CNIC_SUPPORT(bp)) {
6841 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6842 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6843 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6844 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6845 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6846 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6847 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6848 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6849 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6850 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6851 }
34f80b04 6852 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6853
34f80b04
EG
6854 if (sizeof(union cdu_context) != 1024)
6855 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6856 dev_alert(&bp->pdev->dev,
6857 "please adjust the size of cdu_context(%ld)\n",
6858 (long)sizeof(union cdu_context));
a2fbb9ea 6859
619c5cb6 6860 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6861 val = (4 << 24) + (0 << 12) + 1024;
6862 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6863
619c5cb6 6864 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6865 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6866 /* enable context validation interrupt from CFC */
6867 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6868
6869 /* set the thresholds to prevent CFC/CDU race */
6870 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6871
619c5cb6 6872 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6873
619c5cb6 6874 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6875 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6876
619c5cb6
VZ
6877 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6878 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6879
34f80b04
EG
6880 /* Reset PCIE errors for debug */
6881 REG_WR(bp, 0x2814, 0xffffffff);
6882 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6883
619c5cb6 6884 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6885 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6886 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6887 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6888 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6889 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6890 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6891 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6892 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6893 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6894 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6895 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6896 }
6897
619c5cb6 6898 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6899 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6900 /* in E3 this done in per-port section */
6901 if (!CHIP_IS_E3(bp))
6902 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6903 }
619c5cb6
VZ
6904 if (CHIP_IS_E1H(bp))
6905 /* not applicable for E2 (and above ...) */
6906 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6907
6908 if (CHIP_REV_IS_SLOW(bp))
6909 msleep(200);
6910
6911 /* finish CFC init */
6912 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6913 if (val != 1) {
6914 BNX2X_ERR("CFC LL_INIT failed\n");
6915 return -EBUSY;
6916 }
6917 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6918 if (val != 1) {
6919 BNX2X_ERR("CFC AC_INIT failed\n");
6920 return -EBUSY;
6921 }
6922 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6923 if (val != 1) {
6924 BNX2X_ERR("CFC CAM_INIT failed\n");
6925 return -EBUSY;
6926 }
6927 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6928
f2e0899f
DK
6929 if (CHIP_IS_E1(bp)) {
6930 /* read NIG statistic
6931 to see if this is our first up since powerup */
6932 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6933 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6934
f2e0899f
DK
6935 /* do internal memory self test */
6936 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6937 BNX2X_ERR("internal mem self test failed\n");
6938 return -EBUSY;
6939 }
34f80b04
EG
6940 }
6941
fd4ef40d
EG
6942 bnx2x_setup_fan_failure_detection(bp);
6943
34f80b04
EG
6944 /* clear PXP2 attentions */
6945 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6946
4a33bc03 6947 bnx2x_enable_blocks_attention(bp);
c9ee9206 6948 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6949
6bbca910 6950 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6951 if (CHIP_IS_E1x(bp))
6952 bnx2x__common_init_phy(bp);
6bbca910
YR
6953 } else
6954 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6955
34f80b04
EG
6956 return 0;
6957}
a2fbb9ea 6958
619c5cb6
VZ
6959/**
6960 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6961 *
6962 * @bp: driver handle
6963 */
6964static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6965{
6966 int rc = bnx2x_init_hw_common(bp);
6967
6968 if (rc)
6969 return rc;
6970
6971 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6972 if (!BP_NOMCP(bp))
6973 bnx2x__common_init_phy(bp);
6974
6975 return 0;
6976}
6977
523224a3 6978static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6979{
6980 int port = BP_PORT(bp);
619c5cb6 6981 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6982 u32 low, high;
34f80b04 6983 u32 val;
a2fbb9ea 6984
51c1a580 6985 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
6986
6987 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 6988
619c5cb6
VZ
6989 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6990 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6991 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 6992
f2e0899f
DK
6993 /* Timers bug workaround: disables the pf_master bit in pglue at
6994 * common phase, we need to enable it here before any dmae access are
6995 * attempted. Therefore we manually added the enable-master to the
6996 * port phase (it also happens in the function phase)
6997 */
619c5cb6 6998 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6999 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7000
619c5cb6
VZ
7001 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7002 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7003 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7004 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7005
7006 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7007 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7008 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7009 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 7010
523224a3
DK
7011 /* QM cid (connection) count */
7012 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 7013
55c11941
MS
7014 if (CNIC_SUPPORT(bp)) {
7015 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7016 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7017 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7018 }
cdaa7cb8 7019
619c5cb6 7020 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 7021
2b674047
DK
7022 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7023
f2e0899f 7024 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
7025
7026 if (IS_MF(bp))
7027 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7028 else if (bp->dev->mtu > 4096) {
7029 if (bp->flags & ONE_PORT_FLAG)
7030 low = 160;
7031 else {
7032 val = bp->dev->mtu;
7033 /* (24*1024 + val*4)/256 */
7034 low = 96 + (val/64) +
7035 ((val % 64) ? 1 : 0);
7036 }
7037 } else
7038 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7039 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
7040 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7041 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 7042 }
1c06328c 7043
619c5cb6
VZ
7044 if (CHIP_MODE_IS_4_PORT(bp))
7045 REG_WR(bp, (BP_PORT(bp) ?
7046 BRB1_REG_MAC_GUARANTIED_1 :
7047 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 7048
619c5cb6 7049 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
7050 if (CHIP_IS_E3B0(bp)) {
7051 if (IS_MF_AFEX(bp)) {
7052 /* configure headers for AFEX mode */
7053 REG_WR(bp, BP_PORT(bp) ?
7054 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7055 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7056 REG_WR(bp, BP_PORT(bp) ?
7057 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7058 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7059 REG_WR(bp, BP_PORT(bp) ?
7060 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7061 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7062 } else {
7063 /* Ovlan exists only if we are in multi-function +
7064 * switch-dependent mode, in switch-independent there
7065 * is no ovlan headers
7066 */
7067 REG_WR(bp, BP_PORT(bp) ?
7068 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7069 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7070 (bp->path_has_ovlan ? 7 : 6));
7071 }
7072 }
356e2385 7073
619c5cb6
VZ
7074 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7075 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7076 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7077 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 7078
619c5cb6
VZ
7079 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7080 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7081 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7082 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 7083
619c5cb6
VZ
7084 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7085 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 7086
619c5cb6
VZ
7087 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7088
7089 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
7090 /* configure PBF to work without PAUSE mtu 9000 */
7091 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 7092
f2e0899f
DK
7093 /* update threshold */
7094 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7095 /* update init credit */
7096 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 7097
f2e0899f
DK
7098 /* probe changes */
7099 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7100 udelay(50);
7101 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7102 }
a2fbb9ea 7103
55c11941
MS
7104 if (CNIC_SUPPORT(bp))
7105 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7106
619c5cb6
VZ
7107 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7108 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
7109
7110 if (CHIP_IS_E1(bp)) {
7111 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7112 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7113 }
619c5cb6 7114 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 7115
619c5cb6 7116 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7117
619c5cb6 7118 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04 7119 /* init aeu_mask_attn_func_0/1:
16a5fd92
YM
7120 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7121 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
34f80b04 7122 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
7123 val = IS_MF(bp) ? 0xF7 : 0x7;
7124 /* Enable DCBX attention for all but E1 */
7125 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7126 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 7127
619c5cb6
VZ
7128 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7129
7130 if (!CHIP_IS_E1x(bp)) {
7131 /* Bit-map indicating which L2 hdrs may appear after the
7132 * basic Ethernet header
7133 */
a3348722
BW
7134 if (IS_MF_AFEX(bp))
7135 REG_WR(bp, BP_PORT(bp) ?
7136 NIG_REG_P1_HDRS_AFTER_BASIC :
7137 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7138 else
7139 REG_WR(bp, BP_PORT(bp) ?
7140 NIG_REG_P1_HDRS_AFTER_BASIC :
7141 NIG_REG_P0_HDRS_AFTER_BASIC,
7142 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
7143
7144 if (CHIP_IS_E3(bp))
7145 REG_WR(bp, BP_PORT(bp) ?
7146 NIG_REG_LLH1_MF_MODE :
7147 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7148 }
7149 if (!CHIP_IS_E3(bp))
7150 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 7151
f2e0899f 7152 if (!CHIP_IS_E1(bp)) {
fb3bff17 7153 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 7154 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 7155 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 7156
619c5cb6 7157 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7158 val = 0;
7159 switch (bp->mf_mode) {
7160 case MULTI_FUNCTION_SD:
7161 val = 1;
7162 break;
7163 case MULTI_FUNCTION_SI:
a3348722 7164 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
7165 val = 2;
7166 break;
7167 }
7168
7169 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7170 NIG_REG_LLH0_CLS_TYPE), val);
7171 }
1c06328c
EG
7172 {
7173 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7174 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7175 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7176 }
34f80b04
EG
7177 }
7178
619c5cb6
VZ
7179 /* If SPIO5 is set to generate interrupts, enable it for this port */
7180 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 7181 if (val & MISC_SPIO_SPIO5) {
4d295db0
EG
7182 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7183 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7184 val = REG_RD(bp, reg_addr);
f1410647 7185 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 7186 REG_WR(bp, reg_addr, val);
f1410647 7187 }
a2fbb9ea 7188
34f80b04
EG
7189 return 0;
7190}
7191
34f80b04
EG
7192static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7193{
7194 int reg;
32d68de1 7195 u32 wb_write[2];
34f80b04 7196
f2e0899f 7197 if (CHIP_IS_E1(bp))
34f80b04 7198 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
7199 else
7200 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 7201
32d68de1
YM
7202 wb_write[0] = ONCHIP_ADDR1(addr);
7203 wb_write[1] = ONCHIP_ADDR2(addr);
7204 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
7205}
7206
b56e9670 7207void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
1191cb83
ED
7208{
7209 u32 data, ctl, cnt = 100;
7210 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7211 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7212 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7213 u32 sb_bit = 1 << (idu_sb_id%32);
b56e9670 7214 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
1191cb83
ED
7215 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7216
7217 /* Not supported in BC mode */
7218 if (CHIP_INT_MODE_IS_BC(bp))
7219 return;
7220
7221 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7222 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7223 IGU_REGULAR_CLEANUP_SET |
7224 IGU_REGULAR_BCLEANUP;
7225
7226 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7227 func_encode << IGU_CTRL_REG_FID_SHIFT |
7228 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7229
7230 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7231 data, igu_addr_data);
7232 REG_WR(bp, igu_addr_data, data);
7233 mmiowb();
7234 barrier();
7235 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7236 ctl, igu_addr_ctl);
7237 REG_WR(bp, igu_addr_ctl, ctl);
7238 mmiowb();
7239 barrier();
7240
7241 /* wait for clean up to finish */
7242 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7243 msleep(20);
7244
1191cb83
ED
7245 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7246 DP(NETIF_MSG_HW,
7247 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7248 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7249 }
7250}
7251
7252static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7253{
619c5cb6 7254 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7255}
7256
1191cb83 7257static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7258{
7259 u32 i, base = FUNC_ILT_BASE(func);
7260 for (i = base; i < base + ILT_PER_FUNC; i++)
7261 bnx2x_ilt_wr(bp, i, 0);
7262}
7263
910cc727 7264static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7265{
7266 int port = BP_PORT(bp);
7267 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7268 /* T1 hash bits value determines the T1 number of entries */
7269 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7270}
7271
7272static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7273{
7274 int rc;
7275 struct bnx2x_func_state_params func_params = {NULL};
7276 struct bnx2x_func_switch_update_params *switch_update_params =
7277 &func_params.params.switch_update;
7278
7279 /* Prepare parameters for function state transitions */
7280 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7281 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7282
7283 func_params.f_obj = &bp->func_obj;
7284 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7285
7286 /* Function parameters */
7287 switch_update_params->suspend = suspend;
7288
7289 rc = bnx2x_func_state_change(bp, &func_params);
7290
7291 return rc;
7292}
7293
910cc727 7294static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7295{
7296 int rc, i, port = BP_PORT(bp);
7297 int vlan_en = 0, mac_en[NUM_MACS];
7298
55c11941
MS
7299 /* Close input from network */
7300 if (bp->mf_mode == SINGLE_FUNCTION) {
7301 bnx2x_set_rx_filter(&bp->link_params, 0);
7302 } else {
7303 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7304 NIG_REG_LLH0_FUNC_EN);
7305 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7306 NIG_REG_LLH0_FUNC_EN, 0);
7307 for (i = 0; i < NUM_MACS; i++) {
7308 mac_en[i] = REG_RD(bp, port ?
7309 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7310 4 * i) :
7311 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7312 4 * i));
7313 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7314 4 * i) :
7315 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7316 }
7317 }
7318
7319 /* Close BMC to host */
7320 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7321 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7322
7323 /* Suspend Tx switching to the PF. Completion of this ramrod
7324 * further guarantees that all the packets of that PF / child
7325 * VFs in BRB were processed by the Parser, so it is safe to
7326 * change the NIC_MODE register.
7327 */
7328 rc = bnx2x_func_switch_update(bp, 1);
7329 if (rc) {
7330 BNX2X_ERR("Can't suspend tx-switching!\n");
7331 return rc;
7332 }
7333
7334 /* Change NIC_MODE register */
7335 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7336
7337 /* Open input from network */
7338 if (bp->mf_mode == SINGLE_FUNCTION) {
7339 bnx2x_set_rx_filter(&bp->link_params, 1);
7340 } else {
7341 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7342 NIG_REG_LLH0_FUNC_EN, vlan_en);
7343 for (i = 0; i < NUM_MACS; i++) {
7344 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7345 4 * i) :
7346 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7347 mac_en[i]);
7348 }
7349 }
7350
7351 /* Enable BMC to host */
7352 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7353 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7354
7355 /* Resume Tx switching to the PF */
7356 rc = bnx2x_func_switch_update(bp, 0);
7357 if (rc) {
7358 BNX2X_ERR("Can't resume tx-switching!\n");
7359 return rc;
7360 }
7361
7362 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7363 return 0;
7364}
7365
7366int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7367{
7368 int rc;
7369
7370 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7371
7372 if (CONFIGURE_NIC_MODE(bp)) {
16a5fd92 7373 /* Configure searcher as part of function hw init */
55c11941
MS
7374 bnx2x_init_searcher(bp);
7375
7376 /* Reset NIC mode */
7377 rc = bnx2x_reset_nic_mode(bp);
7378 if (rc)
7379 BNX2X_ERR("Can't change NIC mode!\n");
7380 return rc;
7381 }
7382
7383 return 0;
7384}
7385
523224a3 7386static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7387{
7388 int port = BP_PORT(bp);
7389 int func = BP_FUNC(bp);
619c5cb6 7390 int init_phase = PHASE_PF0 + func;
523224a3
DK
7391 struct bnx2x_ilt *ilt = BP_ILT(bp);
7392 u16 cdu_ilt_start;
8badd27a 7393 u32 addr, val;
f4a66897 7394 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7395 int i, main_mem_width, rc;
34f80b04 7396
51c1a580 7397 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7398
619c5cb6 7399 /* FLR cleanup - hmmm */
89db4ad8
AE
7400 if (!CHIP_IS_E1x(bp)) {
7401 rc = bnx2x_pf_flr_clnup(bp);
04c46736
YM
7402 if (rc) {
7403 bnx2x_fw_dump(bp);
89db4ad8 7404 return rc;
04c46736 7405 }
89db4ad8 7406 }
619c5cb6 7407
8badd27a 7408 /* set MSI reconfigure capability */
f2e0899f
DK
7409 if (bp->common.int_block == INT_BLOCK_HC) {
7410 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7411 val = REG_RD(bp, addr);
7412 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7413 REG_WR(bp, addr, val);
7414 }
8badd27a 7415
619c5cb6
VZ
7416 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7417 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7418
523224a3
DK
7419 ilt = BP_ILT(bp);
7420 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7421
290ca2bb
AE
7422 if (IS_SRIOV(bp))
7423 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7424 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7425
7426 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7427 * those of the VFs, so start line should be reset
7428 */
7429 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
523224a3 7430 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7431 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7432 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7433 bp->context[i].cxt_mapping;
7434 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7435 }
290ca2bb 7436
523224a3 7437 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7438
55c11941
MS
7439 if (!CONFIGURE_NIC_MODE(bp)) {
7440 bnx2x_init_searcher(bp);
7441 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7442 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7443 } else {
7444 /* Set NIC mode */
7445 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7446 DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
55c11941 7447 }
37b091ba 7448
619c5cb6 7449 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7450 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7451
7452 /* Turn on a single ISR mode in IGU if driver is going to use
7453 * INT#x or MSI
7454 */
7455 if (!(bp->flags & USING_MSIX_FLAG))
7456 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7457 /*
7458 * Timers workaround bug: function init part.
7459 * Need to wait 20msec after initializing ILT,
7460 * needed to make sure there are no requests in
7461 * one of the PXP internal queues with "old" ILT addresses
7462 */
7463 msleep(20);
7464 /*
7465 * Master enable - Due to WB DMAE writes performed before this
7466 * register is re-initialized as part of the regular function
7467 * init
7468 */
7469 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7470 /* Enable the function in IGU */
7471 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7472 }
7473
523224a3 7474 bp->dmae_ready = 1;
34f80b04 7475
619c5cb6 7476 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7477
619c5cb6 7478 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7479 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7480
619c5cb6
VZ
7481 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7482 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7483 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7484 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7485 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7486 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7487 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7488 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7489 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7490 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7491 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7492 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7493 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7494
7495 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7496 REG_WR(bp, QM_REG_PF_EN, 1);
7497
619c5cb6
VZ
7498 if (!CHIP_IS_E1x(bp)) {
7499 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7500 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7501 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7502 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7503 }
7504 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7505
7506 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7507 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
b56e9670
AE
7508
7509 bnx2x_iov_init_dq(bp);
7510
619c5cb6
VZ
7511 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7512 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7513 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7514 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7515 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7516 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7517 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7518 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7519 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7520 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7521 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7522
619c5cb6 7523 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7524
619c5cb6 7525 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7526
619c5cb6 7527 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7528 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7529
fb3bff17 7530 if (IS_MF(bp)) {
34f80b04 7531 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7532 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7533 }
7534
619c5cb6 7535 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7536
34f80b04 7537 /* HC init per function */
f2e0899f
DK
7538 if (bp->common.int_block == INT_BLOCK_HC) {
7539 if (CHIP_IS_E1H(bp)) {
7540 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7541
7542 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7543 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7544 }
619c5cb6 7545 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7546
7547 } else {
7548 int num_segs, sb_idx, prod_offset;
7549
34f80b04
EG
7550 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7551
619c5cb6 7552 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7553 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7554 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7555 }
7556
619c5cb6 7557 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7558
619c5cb6 7559 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7560 int dsb_idx = 0;
7561 /**
7562 * Producer memory:
7563 * E2 mode: address 0-135 match to the mapping memory;
7564 * 136 - PF0 default prod; 137 - PF1 default prod;
7565 * 138 - PF2 default prod; 139 - PF3 default prod;
7566 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7567 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7568 * 144-147 reserved.
7569 *
7570 * E1.5 mode - In backward compatible mode;
7571 * for non default SB; each even line in the memory
7572 * holds the U producer and each odd line hold
7573 * the C producer. The first 128 producers are for
7574 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7575 * producers are for the DSB for each PF.
7576 * Each PF has five segments: (the order inside each
7577 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7578 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7579 * 144-147 attn prods;
7580 */
7581 /* non-default-status-blocks */
7582 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7583 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7584 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7585 prod_offset = (bp->igu_base_sb + sb_idx) *
7586 num_segs;
7587
7588 for (i = 0; i < num_segs; i++) {
7589 addr = IGU_REG_PROD_CONS_MEMORY +
7590 (prod_offset + i) * 4;
7591 REG_WR(bp, addr, 0);
7592 }
7593 /* send consumer update with value 0 */
7594 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7595 USTORM_ID, 0, IGU_INT_NOP, 1);
7596 bnx2x_igu_clear_sb(bp,
7597 bp->igu_base_sb + sb_idx);
7598 }
7599
7600 /* default-status-blocks */
7601 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7602 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7603
7604 if (CHIP_MODE_IS_4_PORT(bp))
7605 dsb_idx = BP_FUNC(bp);
7606 else
3395a033 7607 dsb_idx = BP_VN(bp);
f2e0899f
DK
7608
7609 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7610 IGU_BC_BASE_DSB_PROD + dsb_idx :
7611 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7612
3395a033
DK
7613 /*
7614 * igu prods come in chunks of E1HVN_MAX (4) -
7615 * does not matters what is the current chip mode
7616 */
f2e0899f
DK
7617 for (i = 0; i < (num_segs * E1HVN_MAX);
7618 i += E1HVN_MAX) {
7619 addr = IGU_REG_PROD_CONS_MEMORY +
7620 (prod_offset + i)*4;
7621 REG_WR(bp, addr, 0);
7622 }
7623 /* send consumer update with 0 */
7624 if (CHIP_INT_MODE_IS_BC(bp)) {
7625 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7626 USTORM_ID, 0, IGU_INT_NOP, 1);
7627 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7628 CSTORM_ID, 0, IGU_INT_NOP, 1);
7629 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7630 XSTORM_ID, 0, IGU_INT_NOP, 1);
7631 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7632 TSTORM_ID, 0, IGU_INT_NOP, 1);
7633 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7634 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7635 } else {
7636 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7637 USTORM_ID, 0, IGU_INT_NOP, 1);
7638 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7639 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7640 }
7641 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7642
16a5fd92 7643 /* !!! These should become driver const once
f2e0899f
DK
7644 rf-tool supports split-68 const */
7645 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7646 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7647 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7648 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7649 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7650 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7651 }
34f80b04 7652 }
34f80b04 7653
c14423fe 7654 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7655 REG_WR(bp, 0x2114, 0xffffffff);
7656 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7657
f4a66897
VZ
7658 if (CHIP_IS_E1x(bp)) {
7659 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7660 main_mem_base = HC_REG_MAIN_MEMORY +
7661 BP_PORT(bp) * (main_mem_size * 4);
7662 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7663 main_mem_width = 8;
7664
7665 val = REG_RD(bp, main_mem_prty_clr);
7666 if (val)
51c1a580
MS
7667 DP(NETIF_MSG_HW,
7668 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7669 val);
f4a66897
VZ
7670
7671 /* Clear "false" parity errors in MSI-X table */
7672 for (i = main_mem_base;
7673 i < main_mem_base + main_mem_size * 4;
7674 i += main_mem_width) {
7675 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7676 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7677 i, main_mem_width / 4);
7678 }
7679 /* Clear HC parity attention */
7680 REG_RD(bp, main_mem_prty_clr);
7681 }
7682
619c5cb6
VZ
7683#ifdef BNX2X_STOP_ON_ERROR
7684 /* Enable STORMs SP logging */
7685 REG_WR8(bp, BAR_USTRORM_INTMEM +
7686 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7687 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7688 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7689 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7690 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7691 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7692 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7693#endif
7694
b7737c9b 7695 bnx2x_phy_probe(&bp->link_params);
f85582f8 7696
34f80b04
EG
7697 return 0;
7698}
7699
55c11941
MS
7700void bnx2x_free_mem_cnic(struct bnx2x *bp)
7701{
7702 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7703
7704 if (!CHIP_IS_E1x(bp))
7705 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7706 sizeof(struct host_hc_status_block_e2));
7707 else
7708 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7709 sizeof(struct host_hc_status_block_e1x));
7710
7711 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7712}
7713
9f6c9258 7714void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7715{
a052997e
MS
7716 int i;
7717
a2fbb9ea 7718 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7719 sizeof(struct host_sp_status_block));
a2fbb9ea 7720
619c5cb6
VZ
7721 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7722 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7723
a2fbb9ea 7724 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7725 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7726
a052997e
MS
7727 for (i = 0; i < L2_ILT_LINES(bp); i++)
7728 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7729 bp->context[i].size);
523224a3
DK
7730 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7731
7732 BNX2X_FREE(bp->ilt->lines);
f85582f8 7733
7a9b2557 7734 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7735
523224a3
DK
7736 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7737 BCM_PAGE_SIZE * NUM_EQ_PAGES);
580d9d08 7738
05952246
YM
7739 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7740
580d9d08 7741 bnx2x_iov_free_mem(bp);
619c5cb6
VZ
7742}
7743
55c11941 7744int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7745{
619c5cb6
VZ
7746 if (!CHIP_IS_E1x(bp))
7747 /* size = the status block + ramrod buffers */
f2e0899f
DK
7748 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7749 sizeof(struct host_hc_status_block_e2));
7750 else
55c11941
MS
7751 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7752 &bp->cnic_sb_mapping,
7753 sizeof(struct
7754 host_hc_status_block_e1x));
8badd27a 7755
2f7a3122 7756 if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
16a5fd92 7757 /* allocate searcher T2 table, as it wasn't allocated before */
55c11941
MS
7758 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7759
7760 /* write address to which L5 should insert its values */
7761 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7762 &bp->slowpath->drv_info_to_mcp;
7763
7764 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7765 goto alloc_mem_err;
7766
7767 return 0;
7768
7769alloc_mem_err:
7770 bnx2x_free_mem_cnic(bp);
7771 BNX2X_ERR("Can't allocate memory\n");
7772 return -ENOMEM;
7773}
7774
7775int bnx2x_alloc_mem(struct bnx2x *bp)
7776{
7777 int i, allocated, context_size;
a2fbb9ea 7778
2f7a3122 7779 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
55c11941
MS
7780 /* allocate searcher T2 table */
7781 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7782
523224a3
DK
7783 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7784 sizeof(struct host_sp_status_block));
a2fbb9ea 7785
523224a3
DK
7786 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7787 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7788
a052997e
MS
7789 /* Allocate memory for CDU context:
7790 * This memory is allocated separately and not in the generic ILT
7791 * functions because CDU differs in few aspects:
7792 * 1. There are multiple entities allocating memory for context -
7793 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7794 * its own ILT lines.
7795 * 2. Since CDU page-size is not a single 4KB page (which is the case
7796 * for the other ILT clients), to be efficient we want to support
7797 * allocation of sub-page-size in the last entry.
7798 * 3. Context pointers are used by the driver to pass to FW / update
7799 * the context (for the other ILT clients the pointers are used just to
7800 * free the memory during unload).
7801 */
7802 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7803
a052997e
MS
7804 for (i = 0, allocated = 0; allocated < context_size; i++) {
7805 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7806 (context_size - allocated));
7807 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7808 &bp->context[i].cxt_mapping,
7809 bp->context[i].size);
7810 allocated += bp->context[i].size;
7811 }
523224a3 7812 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7813
523224a3
DK
7814 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7815 goto alloc_mem_err;
65abd74d 7816
67c431a5
AE
7817 if (bnx2x_iov_alloc_mem(bp))
7818 goto alloc_mem_err;
7819
9f6c9258
DK
7820 /* Slow path ring */
7821 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7822
523224a3
DK
7823 /* EQ */
7824 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7825 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7826
9f6c9258 7827 return 0;
e1510706 7828
9f6c9258
DK
7829alloc_mem_err:
7830 bnx2x_free_mem(bp);
51c1a580 7831 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7832 return -ENOMEM;
65abd74d
YG
7833}
7834
a2fbb9ea
ET
7835/*
7836 * Init service functions
7837 */
a2fbb9ea 7838
619c5cb6
VZ
7839int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7840 struct bnx2x_vlan_mac_obj *obj, bool set,
7841 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7842{
619c5cb6
VZ
7843 int rc;
7844 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7845
619c5cb6 7846 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7847
619c5cb6
VZ
7848 /* Fill general parameters */
7849 ramrod_param.vlan_mac_obj = obj;
7850 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7851
619c5cb6
VZ
7852 /* Fill a user request section if needed */
7853 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7854 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7855
619c5cb6 7856 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7857
619c5cb6
VZ
7858 /* Set the command: ADD or DEL */
7859 if (set)
7860 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7861 else
7862 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7863 }
7864
619c5cb6 7865 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7866
7867 if (rc == -EEXIST) {
7868 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7869 /* do not treat adding same MAC as error */
7870 rc = 0;
7871 } else if (rc < 0)
619c5cb6 7872 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7873
619c5cb6 7874 return rc;
a2fbb9ea
ET
7875}
7876
619c5cb6
VZ
7877int bnx2x_del_all_macs(struct bnx2x *bp,
7878 struct bnx2x_vlan_mac_obj *mac_obj,
7879 int mac_type, bool wait_for_comp)
e665bfda 7880{
619c5cb6
VZ
7881 int rc;
7882 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7883
619c5cb6
VZ
7884 /* Wait for completion of requested */
7885 if (wait_for_comp)
7886 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7887
619c5cb6
VZ
7888 /* Set the mac type of addresses we want to clear */
7889 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7890
619c5cb6
VZ
7891 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7892 if (rc < 0)
7893 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7894
619c5cb6 7895 return rc;
0793f83f
DK
7896}
7897
619c5cb6 7898int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7899{
a3348722
BW
7900 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7901 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7902 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7903 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7904 return 0;
7905 }
614c76df 7906
f8f4f61a
DK
7907 if (IS_PF(bp)) {
7908 unsigned long ramrod_flags = 0;
0793f83f 7909
f8f4f61a
DK
7910 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
7911 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7912 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
7913 &bp->sp_objs->mac_obj, set,
7914 BNX2X_ETH_MAC, &ramrod_flags);
7915 } else { /* vf */
7916 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
7917 bp->fp->index, true);
7918 }
e665bfda 7919}
6e30dd4e 7920
619c5cb6 7921int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7922{
619c5cb6 7923 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7924}
a2fbb9ea 7925
d6214d7a 7926/**
e8920674 7927 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7928 *
e8920674 7929 * @bp: driver handle
d6214d7a 7930 *
e8920674 7931 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7932 */
1ab4434c 7933int bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7934{
1ab4434c
AE
7935 int rc = 0;
7936
7937 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
7938 return -EINVAL;
7939
9ee3d37b 7940 switch (int_mode) {
1ab4434c
AE
7941 case BNX2X_INT_MODE_MSIX:
7942 /* attempt to enable msix */
7943 rc = bnx2x_enable_msix(bp);
7944
7945 /* msix attained */
7946 if (!rc)
7947 return 0;
7948
7949 /* vfs use only msix */
7950 if (rc && IS_VF(bp))
7951 return rc;
7952
7953 /* failed to enable multiple MSI-X */
7954 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7955 bp->num_queues,
7956 1 + bp->num_cnic_queues);
7957
7958 /* falling through... */
7959 case BNX2X_INT_MODE_MSI:
d6214d7a 7960 bnx2x_enable_msi(bp);
1ab4434c 7961
d6214d7a 7962 /* falling through... */
1ab4434c 7963 case BNX2X_INT_MODE_INTX:
55c11941
MS
7964 bp->num_ethernet_queues = 1;
7965 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7966 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7967 break;
d6214d7a 7968 default:
1ab4434c
AE
7969 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
7970 return -EINVAL;
9f6c9258 7971 }
1ab4434c 7972 return 0;
a2fbb9ea
ET
7973}
7974
1ab4434c 7975/* must be called prior to any HW initializations */
c2bff63f
DK
7976static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7977{
290ca2bb
AE
7978 if (IS_SRIOV(bp))
7979 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
c2bff63f
DK
7980 return L2_ILT_LINES(bp);
7981}
7982
523224a3
DK
7983void bnx2x_ilt_set_info(struct bnx2x *bp)
7984{
7985 struct ilt_client_info *ilt_client;
7986 struct bnx2x_ilt *ilt = BP_ILT(bp);
7987 u16 line = 0;
7988
7989 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7990 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7991
7992 /* CDU */
7993 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7994 ilt_client->client_num = ILT_CLIENT_CDU;
7995 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7996 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7997 ilt_client->start = line;
619c5cb6 7998 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
7999
8000 if (CNIC_SUPPORT(bp))
8001 line += CNIC_ILT_LINES;
523224a3
DK
8002 ilt_client->end = line - 1;
8003
51c1a580 8004 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8005 ilt_client->start,
8006 ilt_client->end,
8007 ilt_client->page_size,
8008 ilt_client->flags,
8009 ilog2(ilt_client->page_size >> 12));
8010
8011 /* QM */
8012 if (QM_INIT(bp->qm_cid_count)) {
8013 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8014 ilt_client->client_num = ILT_CLIENT_QM;
8015 ilt_client->page_size = QM_ILT_PAGE_SZ;
8016 ilt_client->flags = 0;
8017 ilt_client->start = line;
8018
8019 /* 4 bytes for each cid */
8020 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8021 QM_ILT_PAGE_SZ);
8022
8023 ilt_client->end = line - 1;
8024
51c1a580
MS
8025 DP(NETIF_MSG_IFUP,
8026 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8027 ilt_client->start,
8028 ilt_client->end,
8029 ilt_client->page_size,
8030 ilt_client->flags,
8031 ilog2(ilt_client->page_size >> 12));
523224a3 8032 }
523224a3 8033
55c11941
MS
8034 if (CNIC_SUPPORT(bp)) {
8035 /* SRC */
8036 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8037 ilt_client->client_num = ILT_CLIENT_SRC;
8038 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8039 ilt_client->flags = 0;
8040 ilt_client->start = line;
8041 line += SRC_ILT_LINES;
8042 ilt_client->end = line - 1;
523224a3 8043
55c11941
MS
8044 DP(NETIF_MSG_IFUP,
8045 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8046 ilt_client->start,
8047 ilt_client->end,
8048 ilt_client->page_size,
8049 ilt_client->flags,
8050 ilog2(ilt_client->page_size >> 12));
9f6c9258 8051
55c11941
MS
8052 /* TM */
8053 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8054 ilt_client->client_num = ILT_CLIENT_TM;
8055 ilt_client->page_size = TM_ILT_PAGE_SZ;
8056 ilt_client->flags = 0;
8057 ilt_client->start = line;
8058 line += TM_ILT_LINES;
8059 ilt_client->end = line - 1;
523224a3 8060
55c11941
MS
8061 DP(NETIF_MSG_IFUP,
8062 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8063 ilt_client->start,
8064 ilt_client->end,
8065 ilt_client->page_size,
8066 ilt_client->flags,
8067 ilog2(ilt_client->page_size >> 12));
8068 }
9f6c9258 8069
619c5cb6 8070 BUG_ON(line > ILT_MAX_LINES);
523224a3 8071}
f85582f8 8072
619c5cb6
VZ
8073/**
8074 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8075 *
8076 * @bp: driver handle
8077 * @fp: pointer to fastpath
8078 * @init_params: pointer to parameters structure
8079 *
8080 * parameters configured:
8081 * - HC configuration
8082 * - Queue's CDU context
8083 */
1191cb83 8084static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 8085 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 8086{
6383c0b3 8087 u8 cos;
a052997e
MS
8088 int cxt_index, cxt_offset;
8089
619c5cb6
VZ
8090 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8091 if (!IS_FCOE_FP(fp)) {
8092 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8093 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8094
16a5fd92 8095 /* If HC is supported, enable host coalescing in the transition
619c5cb6
VZ
8096 * to INIT state.
8097 */
8098 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8099 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8100
8101 /* HC rate */
8102 init_params->rx.hc_rate = bp->rx_ticks ?
8103 (1000000 / bp->rx_ticks) : 0;
8104 init_params->tx.hc_rate = bp->tx_ticks ?
8105 (1000000 / bp->tx_ticks) : 0;
8106
8107 /* FW SB ID */
8108 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8109 fp->fw_sb_id;
8110
8111 /*
8112 * CQ index among the SB indices: FCoE clients uses the default
8113 * SB, therefore it's different.
8114 */
6383c0b3
AE
8115 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8116 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
8117 }
8118
6383c0b3
AE
8119 /* set maximum number of COSs supported by this queue */
8120 init_params->max_cos = fp->max_cos;
8121
51c1a580 8122 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
8123 fp->index, init_params->max_cos);
8124
8125 /* set the context pointers queue object */
a052997e 8126 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
8127 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8128 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 8129 ILT_PAGE_CIDS);
6383c0b3 8130 init_params->cxts[cos] =
a052997e
MS
8131 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8132 }
619c5cb6
VZ
8133}
8134
910cc727 8135static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
8136 struct bnx2x_queue_state_params *q_params,
8137 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8138 int tx_index, bool leading)
8139{
8140 memset(tx_only_params, 0, sizeof(*tx_only_params));
8141
8142 /* Set the command */
8143 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8144
8145 /* Set tx-only QUEUE flags: don't zero statistics */
8146 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8147
8148 /* choose the index of the cid to send the slow path on */
8149 tx_only_params->cid_index = tx_index;
8150
8151 /* Set general TX_ONLY_SETUP parameters */
8152 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8153
8154 /* Set Tx TX_ONLY_SETUP parameters */
8155 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8156
51c1a580
MS
8157 DP(NETIF_MSG_IFUP,
8158 "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
8159 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8160 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8161 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8162
8163 /* send the ramrod */
8164 return bnx2x_queue_state_change(bp, q_params);
8165}
8166
619c5cb6
VZ
8167/**
8168 * bnx2x_setup_queue - setup queue
8169 *
8170 * @bp: driver handle
8171 * @fp: pointer to fastpath
8172 * @leading: is leading
8173 *
8174 * This function performs 2 steps in a Queue state machine
8175 * actually: 1) RESET->INIT 2) INIT->SETUP
8176 */
8177
8178int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8179 bool leading)
8180{
3b603066 8181 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8182 struct bnx2x_queue_setup_params *setup_params =
8183 &q_params.params.setup;
6383c0b3
AE
8184 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8185 &q_params.params.tx_only;
a2fbb9ea 8186 int rc;
6383c0b3
AE
8187 u8 tx_index;
8188
51c1a580 8189 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8190
ec6ba945
VZ
8191 /* reset IGU state skip FCoE L2 queue */
8192 if (!IS_FCOE_FP(fp))
8193 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8194 IGU_INT_ENABLE, 0);
a2fbb9ea 8195
15192a8c 8196 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8197 /* We want to wait for completion in this context */
8198 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8199
619c5cb6
VZ
8200 /* Prepare the INIT parameters */
8201 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8202
619c5cb6
VZ
8203 /* Set the command */
8204 q_params.cmd = BNX2X_Q_CMD_INIT;
8205
8206 /* Change the state to INIT */
8207 rc = bnx2x_queue_state_change(bp, &q_params);
8208 if (rc) {
6383c0b3 8209 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8210 return rc;
8211 }
ec6ba945 8212
51c1a580 8213 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3 8214
619c5cb6
VZ
8215 /* Now move the Queue to the SETUP state... */
8216 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8217
619c5cb6
VZ
8218 /* Set QUEUE flags */
8219 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8220
619c5cb6 8221 /* Set general SETUP parameters */
6383c0b3
AE
8222 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8223 FIRST_TX_COS_INDEX);
619c5cb6 8224
6383c0b3 8225 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8226 &setup_params->rxq_params);
8227
6383c0b3
AE
8228 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8229 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8230
8231 /* Set the command */
8232 q_params.cmd = BNX2X_Q_CMD_SETUP;
8233
55c11941
MS
8234 if (IS_FCOE_FP(fp))
8235 bp->fcoe_init = true;
8236
619c5cb6
VZ
8237 /* Change the state to SETUP */
8238 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8239 if (rc) {
8240 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8241 return rc;
8242 }
8243
8244 /* loop through the relevant tx-only indices */
8245 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8246 tx_index < fp->max_cos;
8247 tx_index++) {
8248
8249 /* prepare and send tx-only ramrod*/
8250 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8251 tx_only_params, tx_index, leading);
8252 if (rc) {
8253 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8254 fp->index, tx_index);
8255 return rc;
8256 }
8257 }
523224a3 8258
34f80b04 8259 return rc;
a2fbb9ea
ET
8260}
8261
619c5cb6 8262static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8263{
619c5cb6 8264 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8265 struct bnx2x_fp_txdata *txdata;
3b603066 8266 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8267 int rc, tx_index;
8268
51c1a580 8269 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8270
15192a8c 8271 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8272 /* We want to wait for completion in this context */
8273 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8274
6383c0b3
AE
8275 /* close tx-only connections */
8276 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8277 tx_index < fp->max_cos;
8278 tx_index++){
8279
8280 /* ascertain this is a normal queue*/
65565884 8281 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8282
51c1a580 8283 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8284 txdata->txq_index);
8285
8286 /* send halt terminate on tx-only connection */
8287 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8288 memset(&q_params.params.terminate, 0,
8289 sizeof(q_params.params.terminate));
8290 q_params.params.terminate.cid_index = tx_index;
8291
8292 rc = bnx2x_queue_state_change(bp, &q_params);
8293 if (rc)
8294 return rc;
8295
8296 /* send halt terminate on tx-only connection */
8297 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8298 memset(&q_params.params.cfc_del, 0,
8299 sizeof(q_params.params.cfc_del));
8300 q_params.params.cfc_del.cid_index = tx_index;
8301 rc = bnx2x_queue_state_change(bp, &q_params);
8302 if (rc)
8303 return rc;
8304 }
8305 /* Stop the primary connection: */
8306 /* ...halt the connection */
619c5cb6
VZ
8307 q_params.cmd = BNX2X_Q_CMD_HALT;
8308 rc = bnx2x_queue_state_change(bp, &q_params);
8309 if (rc)
da5a662a 8310 return rc;
a2fbb9ea 8311
6383c0b3 8312 /* ...terminate the connection */
619c5cb6 8313 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8314 memset(&q_params.params.terminate, 0,
8315 sizeof(q_params.params.terminate));
8316 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8317 rc = bnx2x_queue_state_change(bp, &q_params);
8318 if (rc)
523224a3 8319 return rc;
6383c0b3 8320 /* ...delete cfc entry */
619c5cb6 8321 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8322 memset(&q_params.params.cfc_del, 0,
8323 sizeof(q_params.params.cfc_del));
8324 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8325 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8326}
8327
34f80b04
EG
8328static void bnx2x_reset_func(struct bnx2x *bp)
8329{
8330 int port = BP_PORT(bp);
8331 int func = BP_FUNC(bp);
f2e0899f 8332 int i;
523224a3
DK
8333
8334 /* Disable the function in the FW */
8335 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8336 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8337 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8338 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8339
8340 /* FP SBs */
ec6ba945 8341 for_each_eth_queue(bp, i) {
523224a3 8342 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8343 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8344 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8345 SB_DISABLED);
523224a3
DK
8346 }
8347
55c11941
MS
8348 if (CNIC_LOADED(bp))
8349 /* CNIC SB */
8350 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8351 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8352 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8353
523224a3 8354 /* SP SB */
619c5cb6 8355 REG_WR8(bp, BAR_CSTRORM_INTMEM +
2de67439
YM
8356 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8357 SB_DISABLED);
523224a3
DK
8358
8359 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8360 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8361 0);
34f80b04
EG
8362
8363 /* Configure IGU */
f2e0899f
DK
8364 if (bp->common.int_block == INT_BLOCK_HC) {
8365 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8366 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8367 } else {
8368 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8369 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8370 }
34f80b04 8371
55c11941
MS
8372 if (CNIC_LOADED(bp)) {
8373 /* Disable Timer scan */
8374 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8375 /*
8376 * Wait for at least 10ms and up to 2 second for the timers
8377 * scan to complete
8378 */
8379 for (i = 0; i < 200; i++) {
8380 msleep(10);
8381 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8382 break;
8383 }
37b091ba 8384 }
34f80b04 8385 /* Clear ILT */
f2e0899f
DK
8386 bnx2x_clear_func_ilt(bp, func);
8387
8388 /* Timers workaround bug for E2: if this is vnic-3,
8389 * we need to set the entire ilt range for this timers.
8390 */
619c5cb6 8391 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8392 struct ilt_client_info ilt_cli;
8393 /* use dummy TM client */
8394 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8395 ilt_cli.start = 0;
8396 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8397 ilt_cli.client_num = ILT_CLIENT_TM;
8398
8399 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8400 }
8401
8402 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8403 if (!CHIP_IS_E1x(bp))
f2e0899f 8404 bnx2x_pf_disable(bp);
523224a3
DK
8405
8406 bp->dmae_ready = 0;
34f80b04
EG
8407}
8408
8409static void bnx2x_reset_port(struct bnx2x *bp)
8410{
8411 int port = BP_PORT(bp);
8412 u32 val;
8413
619c5cb6
VZ
8414 /* Reset physical Link */
8415 bnx2x__link_reset(bp);
8416
34f80b04
EG
8417 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8418
8419 /* Do not rcv packets to BRB */
8420 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8421 /* Do not direct rcv packets that are not for MCP to the BRB */
8422 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8423 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8424
8425 /* Configure AEU */
8426 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8427
8428 msleep(100);
8429 /* Check for BRB port occupancy */
8430 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8431 if (val)
8432 DP(NETIF_MSG_IFDOWN,
33471629 8433 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8434
8435 /* TODO: Close Doorbell port? */
8436}
8437
1191cb83 8438static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8439{
3b603066 8440 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8441
619c5cb6
VZ
8442 /* Prepare parameters for function state transitions */
8443 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8444
619c5cb6
VZ
8445 func_params.f_obj = &bp->func_obj;
8446 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8447
619c5cb6 8448 func_params.params.hw_init.load_phase = load_code;
49d66772 8449
619c5cb6 8450 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8451}
8452
1191cb83 8453static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8454{
3b603066 8455 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8456 int rc;
228241eb 8457
619c5cb6
VZ
8458 /* Prepare parameters for function state transitions */
8459 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8460 func_params.f_obj = &bp->func_obj;
8461 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8462
619c5cb6
VZ
8463 /*
8464 * Try to stop the function the 'good way'. If fails (in case
8465 * of a parity error during bnx2x_chip_cleanup()) and we are
8466 * not in a debug mode, perform a state transaction in order to
8467 * enable further HW_RESET transaction.
8468 */
8469 rc = bnx2x_func_state_change(bp, &func_params);
8470 if (rc) {
34f80b04 8471#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8472 return rc;
34f80b04 8473#else
51c1a580 8474 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8475 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8476 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8477#endif
228241eb 8478 }
a2fbb9ea 8479
619c5cb6
VZ
8480 return 0;
8481}
523224a3 8482
619c5cb6
VZ
8483/**
8484 * bnx2x_send_unload_req - request unload mode from the MCP.
8485 *
8486 * @bp: driver handle
8487 * @unload_mode: requested function's unload mode
8488 *
8489 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8490 */
8491u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8492{
8493 u32 reset_code = 0;
8494 int port = BP_PORT(bp);
3101c2bc 8495
619c5cb6 8496 /* Select the UNLOAD request mode */
65abd74d
YG
8497 if (unload_mode == UNLOAD_NORMAL)
8498 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8499
7d0446c2 8500 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8501 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8502
7d0446c2 8503 else if (bp->wol) {
65abd74d
YG
8504 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8505 u8 *mac_addr = bp->dev->dev_addr;
8506 u32 val;
f9977903
DK
8507 u16 pmc;
8508
65abd74d 8509 /* The mac address is written to entries 1-4 to
f9977903
DK
8510 * preserve entry 0 which is used by the PMF
8511 */
3395a033 8512 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8513
8514 val = (mac_addr[0] << 8) | mac_addr[1];
8515 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8516
8517 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8518 (mac_addr[4] << 8) | mac_addr[5];
8519 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8520
f9977903
DK
8521 /* Enable the PME and clear the status */
8522 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8523 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8524 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8525
65abd74d
YG
8526 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8527
8528 } else
8529 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8530
619c5cb6
VZ
8531 /* Send the request to the MCP */
8532 if (!BP_NOMCP(bp))
8533 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8534 else {
8535 int path = BP_PATH(bp);
8536
51c1a580 8537 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8538 path, load_count[path][0], load_count[path][1],
8539 load_count[path][2]);
8540 load_count[path][0]--;
8541 load_count[path][1 + port]--;
51c1a580 8542 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8543 path, load_count[path][0], load_count[path][1],
8544 load_count[path][2]);
8545 if (load_count[path][0] == 0)
8546 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8547 else if (load_count[path][1 + port] == 0)
8548 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8549 else
8550 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8551 }
8552
8553 return reset_code;
8554}
8555
8556/**
8557 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8558 *
8559 * @bp: driver handle
5d07d868 8560 * @keep_link: true iff link should be kept up
619c5cb6 8561 */
5d07d868 8562void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8563{
5d07d868
YM
8564 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8565
619c5cb6
VZ
8566 /* Report UNLOAD_DONE to MCP */
8567 if (!BP_NOMCP(bp))
5d07d868 8568 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8569}
8570
1191cb83 8571static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8572{
8573 int tout = 50;
8574 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8575
8576 if (!bp->port.pmf)
8577 return 0;
8578
8579 /*
8580 * (assumption: No Attention from MCP at this stage)
16a5fd92 8581 * PMF probably in the middle of TX disable/enable transaction
6debea87 8582 * 1. Sync IRS for default SB
16a5fd92
YM
8583 * 2. Sync SP queue - this guarantees us that attention handling started
8584 * 3. Wait, that TX disable/enable transaction completes
6debea87 8585 *
16a5fd92
YM
8586 * 1+2 guarantee that if DCBx attention was scheduled it already changed
8587 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
8588 * received completion for the transaction the state is TX_STOPPED.
6debea87
DK
8589 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8590 * transaction.
8591 */
8592
8593 /* make sure default SB ISR is done */
8594 if (msix)
8595 synchronize_irq(bp->msix_table[0].vector);
8596 else
8597 synchronize_irq(bp->pdev->irq);
8598
8599 flush_workqueue(bnx2x_wq);
8600
8601 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8602 BNX2X_F_STATE_STARTED && tout--)
8603 msleep(20);
8604
8605 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8606 BNX2X_F_STATE_STARTED) {
8607#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8608 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8609 return -EBUSY;
8610#else
8611 /*
8612 * Failed to complete the transaction in a "good way"
8613 * Force both transactions with CLR bit
8614 */
3b603066 8615 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8616
51c1a580
MS
8617 DP(NETIF_MSG_IFDOWN,
8618 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8619
8620 func_params.f_obj = &bp->func_obj;
8621 __set_bit(RAMROD_DRV_CLR_ONLY,
8622 &func_params.ramrod_flags);
8623
8624 /* STARTED-->TX_ST0PPED */
8625 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8626 bnx2x_func_state_change(bp, &func_params);
8627
8628 /* TX_ST0PPED-->STARTED */
8629 func_params.cmd = BNX2X_F_CMD_TX_START;
8630 return bnx2x_func_state_change(bp, &func_params);
8631#endif
8632 }
8633
8634 return 0;
8635}
8636
5d07d868 8637void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8638{
8639 int port = BP_PORT(bp);
6383c0b3
AE
8640 int i, rc = 0;
8641 u8 cos;
3b603066 8642 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8643 u32 reset_code;
8644
8645 /* Wait until tx fastpath tasks complete */
8646 for_each_tx_queue(bp, i) {
8647 struct bnx2x_fastpath *fp = &bp->fp[i];
8648
6383c0b3 8649 for_each_cos_in_tx_queue(fp, cos)
65565884 8650 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8651#ifdef BNX2X_STOP_ON_ERROR
8652 if (rc)
8653 return;
8654#endif
8655 }
8656
8657 /* Give HW time to discard old tx messages */
0926d499 8658 usleep_range(1000, 2000);
619c5cb6
VZ
8659
8660 /* Clean all ETH MACs */
15192a8c
BW
8661 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8662 false);
619c5cb6
VZ
8663 if (rc < 0)
8664 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8665
8666 /* Clean up UC list */
15192a8c 8667 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8668 true);
8669 if (rc < 0)
51c1a580
MS
8670 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8671 rc);
619c5cb6
VZ
8672
8673 /* Disable LLH */
8674 if (!CHIP_IS_E1(bp))
8675 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8676
8677 /* Set "drop all" (stop Rx).
8678 * We need to take a netif_addr_lock() here in order to prevent
8679 * a race between the completion code and this code.
8680 */
8681 netif_addr_lock_bh(bp->dev);
8682 /* Schedule the rx_mode command */
8683 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8684 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8685 else
8686 bnx2x_set_storm_rx_mode(bp);
8687
8688 /* Cleanup multicast configuration */
8689 rparam.mcast_obj = &bp->mcast_obj;
8690 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8691 if (rc < 0)
8692 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8693
8694 netif_addr_unlock_bh(bp->dev);
8695
f1929b01 8696 bnx2x_iov_chip_cleanup(bp);
619c5cb6 8697
6debea87
DK
8698 /*
8699 * Send the UNLOAD_REQUEST to the MCP. This will return if
8700 * this function should perform FUNC, PORT or COMMON HW
8701 * reset.
8702 */
8703 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8704
8705 /*
8706 * (assumption: No Attention from MCP at this stage)
16a5fd92 8707 * PMF probably in the middle of TX disable/enable transaction
6debea87
DK
8708 */
8709 rc = bnx2x_func_wait_started(bp);
8710 if (rc) {
8711 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8712#ifdef BNX2X_STOP_ON_ERROR
8713 return;
8714#endif
8715 }
8716
34f80b04 8717 /* Close multi and leading connections
619c5cb6
VZ
8718 * Completions for ramrods are collected in a synchronous way
8719 */
55c11941 8720 for_each_eth_queue(bp, i)
619c5cb6 8721 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8722#ifdef BNX2X_STOP_ON_ERROR
8723 return;
8724#else
228241eb 8725 goto unload_error;
523224a3 8726#endif
55c11941
MS
8727
8728 if (CNIC_LOADED(bp)) {
8729 for_each_cnic_queue(bp, i)
8730 if (bnx2x_stop_queue(bp, i))
8731#ifdef BNX2X_STOP_ON_ERROR
8732 return;
8733#else
8734 goto unload_error;
8735#endif
8736 }
8737
619c5cb6
VZ
8738 /* If SP settings didn't get completed so far - something
8739 * very wrong has happen.
8740 */
8741 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8742 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8743
619c5cb6
VZ
8744#ifndef BNX2X_STOP_ON_ERROR
8745unload_error:
8746#endif
523224a3 8747 rc = bnx2x_func_stop(bp);
da5a662a 8748 if (rc) {
523224a3 8749 BNX2X_ERR("Function stop failed!\n");
da5a662a 8750#ifdef BNX2X_STOP_ON_ERROR
523224a3 8751 return;
523224a3 8752#endif
34f80b04 8753 }
a2fbb9ea 8754
523224a3
DK
8755 /* Disable HW interrupts, NAPI */
8756 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8757 /* Delete all NAPI objects */
8758 bnx2x_del_all_napi(bp);
55c11941
MS
8759 if (CNIC_LOADED(bp))
8760 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8761
8762 /* Release IRQs */
d6214d7a 8763 bnx2x_free_irq(bp);
523224a3 8764
a2fbb9ea 8765 /* Reset the chip */
619c5cb6
VZ
8766 rc = bnx2x_reset_hw(bp, reset_code);
8767 if (rc)
8768 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8769
619c5cb6 8770 /* Report UNLOAD_DONE to MCP */
5d07d868 8771 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8772}
8773
9f6c9258 8774void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8775{
8776 u32 val;
8777
51c1a580 8778 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8779
8780 if (CHIP_IS_E1(bp)) {
8781 int port = BP_PORT(bp);
8782 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8783 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8784
8785 val = REG_RD(bp, addr);
8786 val &= ~(0x300);
8787 REG_WR(bp, addr, val);
619c5cb6 8788 } else {
72fd0718
VZ
8789 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8790 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8791 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8792 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8793 }
8794}
8795
72fd0718
VZ
8796/* Close gates #2, #3 and #4: */
8797static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8798{
c9ee9206 8799 u32 val;
72fd0718
VZ
8800
8801 /* Gates #2 and #4a are closed/opened for "not E1" only */
8802 if (!CHIP_IS_E1(bp)) {
8803 /* #4 */
c9ee9206 8804 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8805 /* #2 */
c9ee9206 8806 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8807 }
8808
8809 /* #3 */
c9ee9206
VZ
8810 if (CHIP_IS_E1x(bp)) {
8811 /* Prevent interrupts from HC on both ports */
8812 val = REG_RD(bp, HC_REG_CONFIG_1);
8813 REG_WR(bp, HC_REG_CONFIG_1,
8814 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8815 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8816
8817 val = REG_RD(bp, HC_REG_CONFIG_0);
8818 REG_WR(bp, HC_REG_CONFIG_0,
8819 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8820 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8821 } else {
d82603c6 8822 /* Prevent incoming interrupts in IGU */
c9ee9206
VZ
8823 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8824
8825 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8826 (!close) ?
8827 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8828 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8829 }
72fd0718 8830
51c1a580 8831 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8832 close ? "closing" : "opening");
8833 mmiowb();
8834}
8835
8836#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8837
8838static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8839{
8840 /* Do some magic... */
8841 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8842 *magic_val = val & SHARED_MF_CLP_MAGIC;
8843 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8844}
8845
e8920674
DK
8846/**
8847 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8848 *
e8920674
DK
8849 * @bp: driver handle
8850 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8851 */
8852static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8853{
8854 /* Restore the `magic' bit value... */
72fd0718
VZ
8855 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8856 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8857 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8858}
8859
f85582f8 8860/**
e8920674 8861 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8862 *
e8920674
DK
8863 * @bp: driver handle
8864 * @magic_val: old value of 'magic' bit.
8865 *
8866 * Takes care of CLP configurations.
72fd0718
VZ
8867 */
8868static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8869{
8870 u32 shmem;
8871 u32 validity_offset;
8872
51c1a580 8873 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8874
8875 /* Set `magic' bit in order to save MF config */
8876 if (!CHIP_IS_E1(bp))
8877 bnx2x_clp_reset_prep(bp, magic_val);
8878
8879 /* Get shmem offset */
8880 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
8881 validity_offset =
8882 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
8883
8884 /* Clear validity map flags */
8885 if (shmem > 0)
8886 REG_WR(bp, shmem + validity_offset, 0);
8887}
8888
8889#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8890#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8891
e8920674
DK
8892/**
8893 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8894 *
e8920674 8895 * @bp: driver handle
72fd0718 8896 */
1191cb83 8897static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8898{
8899 /* special handling for emulation and FPGA,
8900 wait 10 times longer */
8901 if (CHIP_REV_IS_SLOW(bp))
8902 msleep(MCP_ONE_TIMEOUT*10);
8903 else
8904 msleep(MCP_ONE_TIMEOUT);
8905}
8906
1b6e2ceb
DK
8907/*
8908 * initializes bp->common.shmem_base and waits for validity signature to appear
8909 */
8910static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8911{
1b6e2ceb
DK
8912 int cnt = 0;
8913 u32 val = 0;
72fd0718 8914
1b6e2ceb
DK
8915 do {
8916 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8917 if (bp->common.shmem_base) {
8918 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8919 if (val & SHR_MEM_VALIDITY_MB)
8920 return 0;
8921 }
72fd0718 8922
1b6e2ceb 8923 bnx2x_mcp_wait_one(bp);
72fd0718 8924
1b6e2ceb 8925 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8926
1b6e2ceb 8927 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8928
1b6e2ceb
DK
8929 return -ENODEV;
8930}
72fd0718 8931
1b6e2ceb
DK
8932static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8933{
8934 int rc = bnx2x_init_shmem(bp);
72fd0718 8935
72fd0718
VZ
8936 /* Restore the `magic' bit value */
8937 if (!CHIP_IS_E1(bp))
8938 bnx2x_clp_reset_done(bp, magic_val);
8939
8940 return rc;
8941}
8942
8943static void bnx2x_pxp_prep(struct bnx2x *bp)
8944{
8945 if (!CHIP_IS_E1(bp)) {
8946 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8947 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8948 mmiowb();
8949 }
8950}
8951
8952/*
8953 * Reset the whole chip except for:
8954 * - PCIE core
8955 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8956 * one reset bit)
8957 * - IGU
8958 * - MISC (including AEU)
8959 * - GRC
8960 * - RBCN, RBCP
8961 */
c9ee9206 8962static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8963{
8964 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8965 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8966
8967 /*
8968 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8969 * (per chip) blocks.
8970 */
8971 global_bits2 =
8972 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8973 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 8974
c55e771b
BW
8975 /* Don't reset the following blocks.
8976 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
8977 * reset, as in 4 port device they might still be owned
8978 * by the MCP (there is only one leader per path).
8979 */
72fd0718
VZ
8980 not_reset_mask1 =
8981 MISC_REGISTERS_RESET_REG_1_RST_HC |
8982 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8983 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8984
8985 not_reset_mask2 =
c9ee9206 8986 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
8987 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8988 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8989 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8990 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8991 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8992 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
8993 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8994 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
8995 MISC_REGISTERS_RESET_REG_2_PGLC |
8996 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8997 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8998 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8999 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9000 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9001 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 9002
8736c826
VZ
9003 /*
9004 * Keep the following blocks in reset:
9005 * - all xxMACs are handled by the bnx2x_link code.
9006 */
9007 stay_reset2 =
8736c826
VZ
9008 MISC_REGISTERS_RESET_REG_2_XMAC |
9009 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9010
9011 /* Full reset masks according to the chip */
72fd0718
VZ
9012 reset_mask1 = 0xffffffff;
9013
9014 if (CHIP_IS_E1(bp))
9015 reset_mask2 = 0xffff;
8736c826 9016 else if (CHIP_IS_E1H(bp))
72fd0718 9017 reset_mask2 = 0x1ffff;
8736c826
VZ
9018 else if (CHIP_IS_E2(bp))
9019 reset_mask2 = 0xfffff;
9020 else /* CHIP_IS_E3 */
9021 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
9022
9023 /* Don't reset global blocks unless we need to */
9024 if (!global)
9025 reset_mask2 &= ~global_bits2;
9026
9027 /*
9028 * In case of attention in the QM, we need to reset PXP
9029 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9030 * because otherwise QM reset would release 'close the gates' shortly
9031 * before resetting the PXP, then the PSWRQ would send a write
9032 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9033 * read the payload data from PSWWR, but PSWWR would not
9034 * respond. The write queue in PGLUE would stuck, dmae commands
9035 * would not return. Therefore it's important to reset the second
9036 * reset register (containing the
9037 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9038 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9039 * bit).
9040 */
72fd0718
VZ
9041 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9042 reset_mask2 & (~not_reset_mask2));
9043
c9ee9206
VZ
9044 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9045 reset_mask1 & (~not_reset_mask1));
9046
72fd0718
VZ
9047 barrier();
9048 mmiowb();
9049
8736c826
VZ
9050 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9051 reset_mask2 & (~stay_reset2));
9052
9053 barrier();
9054 mmiowb();
9055
c9ee9206 9056 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
9057 mmiowb();
9058}
9059
c9ee9206
VZ
9060/**
9061 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9062 * It should get cleared in no more than 1s.
9063 *
9064 * @bp: driver handle
9065 *
9066 * It should get cleared in no more than 1s. Returns 0 if
9067 * pending writes bit gets cleared.
9068 */
9069static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9070{
9071 u32 cnt = 1000;
9072 u32 pend_bits = 0;
9073
9074 do {
9075 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9076
9077 if (pend_bits == 0)
9078 break;
9079
0926d499 9080 usleep_range(1000, 2000);
c9ee9206
VZ
9081 } while (cnt-- > 0);
9082
9083 if (cnt <= 0) {
9084 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9085 pend_bits);
9086 return -EBUSY;
9087 }
9088
9089 return 0;
9090}
9091
9092static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
9093{
9094 int cnt = 1000;
9095 u32 val = 0;
9096 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
2de67439 9097 u32 tags_63_32 = 0;
72fd0718
VZ
9098
9099 /* Empty the Tetris buffer, wait for 1s */
9100 do {
9101 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9102 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9103 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9104 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9105 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
9106 if (CHIP_IS_E3(bp))
9107 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9108
72fd0718
VZ
9109 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9110 ((port_is_idle_0 & 0x1) == 0x1) &&
9111 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
9112 (pgl_exp_rom2 == 0xffffffff) &&
9113 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 9114 break;
0926d499 9115 usleep_range(1000, 2000);
72fd0718
VZ
9116 } while (cnt-- > 0);
9117
9118 if (cnt <= 0) {
51c1a580
MS
9119 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9120 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
9121 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9122 pgl_exp_rom2);
9123 return -EAGAIN;
9124 }
9125
9126 barrier();
9127
9128 /* Close gates #2, #3 and #4 */
9129 bnx2x_set_234_gates(bp, true);
9130
c9ee9206
VZ
9131 /* Poll for IGU VQs for 57712 and newer chips */
9132 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9133 return -EAGAIN;
9134
72fd0718
VZ
9135 /* TBD: Indicate that "process kill" is in progress to MCP */
9136
9137 /* Clear "unprepared" bit */
9138 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9139 barrier();
9140
9141 /* Make sure all is written to the chip before the reset */
9142 mmiowb();
9143
9144 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9145 * PSWHST, GRC and PSWRD Tetris buffer.
9146 */
0926d499 9147 usleep_range(1000, 2000);
72fd0718
VZ
9148
9149 /* Prepare to chip reset: */
9150 /* MCP */
c9ee9206
VZ
9151 if (global)
9152 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
9153
9154 /* PXP */
9155 bnx2x_pxp_prep(bp);
9156 barrier();
9157
9158 /* reset the chip */
c9ee9206 9159 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9160 barrier();
9161
9162 /* Recover after reset: */
9163 /* MCP */
c9ee9206 9164 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9165 return -EAGAIN;
9166
c9ee9206
VZ
9167 /* TBD: Add resetting the NO_MCP mode DB here */
9168
72fd0718
VZ
9169 /* Open the gates #2, #3 and #4 */
9170 bnx2x_set_234_gates(bp, false);
9171
9172 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9173 * reset state, re-enable attentions. */
9174
a2fbb9ea
ET
9175 return 0;
9176}
9177
910cc727 9178static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9179{
9180 int rc = 0;
c9ee9206 9181 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9182 u32 load_code;
9183
9184 /* if not going to reset MCP - load "fake" driver to reset HW while
9185 * driver is owner of the HW
9186 */
9187 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9188 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9189 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9190 if (!load_code) {
9191 BNX2X_ERR("MCP response failure, aborting\n");
9192 rc = -EAGAIN;
9193 goto exit_leader_reset;
9194 }
9195 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9196 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9197 BNX2X_ERR("MCP unexpected resp, aborting\n");
9198 rc = -EAGAIN;
9199 goto exit_leader_reset2;
9200 }
9201 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9202 if (!load_code) {
9203 BNX2X_ERR("MCP response failure, aborting\n");
9204 rc = -EAGAIN;
9205 goto exit_leader_reset2;
9206 }
9207 }
c9ee9206 9208
72fd0718 9209 /* Try to recover after the failure */
c9ee9206 9210 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9211 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9212 BP_PATH(bp));
72fd0718 9213 rc = -EAGAIN;
95c6c616 9214 goto exit_leader_reset2;
72fd0718
VZ
9215 }
9216
c9ee9206
VZ
9217 /*
9218 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9219 * state.
9220 */
72fd0718 9221 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9222 if (global)
9223 bnx2x_clear_reset_global(bp);
72fd0718 9224
95c6c616
AE
9225exit_leader_reset2:
9226 /* unload "fake driver" if it was loaded */
9227 if (!global && !BP_NOMCP(bp)) {
9228 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9229 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9230 }
72fd0718
VZ
9231exit_leader_reset:
9232 bp->is_leader = 0;
c9ee9206
VZ
9233 bnx2x_release_leader_lock(bp);
9234 smp_mb();
72fd0718
VZ
9235 return rc;
9236}
9237
1191cb83 9238static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9239{
9240 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9241
9242 /* Disconnect this device */
9243 netif_device_detach(bp->dev);
9244
9245 /*
9246 * Block ifup for all function on this engine until "process kill"
9247 * or power cycle.
9248 */
9249 bnx2x_set_reset_in_progress(bp);
9250
9251 /* Shut down the power */
9252 bnx2x_set_power_state(bp, PCI_D3hot);
9253
9254 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9255
9256 smp_mb();
9257}
9258
9259/*
9260 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9261 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9262 * will never be called when netif_running(bp->dev) is false.
9263 */
9264static void bnx2x_parity_recover(struct bnx2x *bp)
9265{
c9ee9206 9266 bool global = false;
7a752993 9267 u32 error_recovered, error_unrecovered;
95c6c616 9268 bool is_parity;
c9ee9206 9269
72fd0718
VZ
9270 DP(NETIF_MSG_HW, "Handling parity\n");
9271 while (1) {
9272 switch (bp->recovery_state) {
9273 case BNX2X_RECOVERY_INIT:
9274 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9275 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9276 WARN_ON(!is_parity);
c9ee9206 9277
72fd0718 9278 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9279 if (bnx2x_trylock_leader_lock(bp)) {
9280 bnx2x_set_reset_in_progress(bp);
9281 /*
9282 * Check if there is a global attention and if
9283 * there was a global attention, set the global
9284 * reset bit.
9285 */
9286
9287 if (global)
9288 bnx2x_set_reset_global(bp);
9289
72fd0718 9290 bp->is_leader = 1;
c9ee9206 9291 }
72fd0718
VZ
9292
9293 /* Stop the driver */
9294 /* If interface has been removed - break */
5d07d868 9295 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9296 return;
9297
9298 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9299
c9ee9206
VZ
9300 /* Ensure "is_leader", MCP command sequence and
9301 * "recovery_state" update values are seen on other
9302 * CPUs.
72fd0718 9303 */
c9ee9206 9304 smp_mb();
72fd0718
VZ
9305 break;
9306
9307 case BNX2X_RECOVERY_WAIT:
9308 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9309 if (bp->is_leader) {
c9ee9206 9310 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9311 bool other_load_status =
9312 bnx2x_get_load_status(bp, other_engine);
9313 bool load_status =
9314 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9315 global = bnx2x_reset_is_global(bp);
9316
9317 /*
9318 * In case of a parity in a global block, let
9319 * the first leader that performs a
9320 * leader_reset() reset the global blocks in
9321 * order to clear global attentions. Otherwise
16a5fd92 9322 * the gates will remain closed for that
c9ee9206
VZ
9323 * engine.
9324 */
889b9af3
AE
9325 if (load_status ||
9326 (global && other_load_status)) {
72fd0718
VZ
9327 /* Wait until all other functions get
9328 * down.
9329 */
7be08a72 9330 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9331 HZ/10);
9332 return;
9333 } else {
9334 /* If all other functions got down -
9335 * try to bring the chip back to
9336 * normal. In any case it's an exit
9337 * point for a leader.
9338 */
c9ee9206
VZ
9339 if (bnx2x_leader_reset(bp)) {
9340 bnx2x_recovery_failed(bp);
72fd0718
VZ
9341 return;
9342 }
9343
c9ee9206
VZ
9344 /* If we are here, means that the
9345 * leader has succeeded and doesn't
9346 * want to be a leader any more. Try
9347 * to continue as a none-leader.
9348 */
9349 break;
72fd0718
VZ
9350 }
9351 } else { /* non-leader */
c9ee9206 9352 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9353 /* Try to get a LEADER_LOCK HW lock as
9354 * long as a former leader may have
9355 * been unloaded by the user or
9356 * released a leadership by another
9357 * reason.
9358 */
c9ee9206 9359 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9360 /* I'm a leader now! Restart a
9361 * switch case.
9362 */
9363 bp->is_leader = 1;
9364 break;
9365 }
9366
7be08a72 9367 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9368 HZ/10);
9369 return;
9370
c9ee9206
VZ
9371 } else {
9372 /*
9373 * If there was a global attention, wait
9374 * for it to be cleared.
9375 */
9376 if (bnx2x_reset_is_global(bp)) {
9377 schedule_delayed_work(
7be08a72
AE
9378 &bp->sp_rtnl_task,
9379 HZ/10);
c9ee9206
VZ
9380 return;
9381 }
9382
7a752993
AE
9383 error_recovered =
9384 bp->eth_stats.recoverable_error;
9385 error_unrecovered =
9386 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9387 bp->recovery_state =
9388 BNX2X_RECOVERY_NIC_LOADING;
9389 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9390 error_unrecovered++;
95c6c616 9391 netdev_err(bp->dev,
51c1a580 9392 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9393 /* Disconnect this device */
9394 netif_device_detach(bp->dev);
9395 /* Shut down the power */
9396 bnx2x_set_power_state(
9397 bp, PCI_D3hot);
9398 smp_mb();
9399 } else {
c9ee9206
VZ
9400 bp->recovery_state =
9401 BNX2X_RECOVERY_DONE;
7a752993 9402 error_recovered++;
c9ee9206
VZ
9403 smp_mb();
9404 }
7a752993
AE
9405 bp->eth_stats.recoverable_error =
9406 error_recovered;
9407 bp->eth_stats.unrecoverable_error =
9408 error_unrecovered;
c9ee9206 9409
72fd0718
VZ
9410 return;
9411 }
9412 }
9413 default:
9414 return;
9415 }
9416 }
9417}
9418
56ad3152
MS
9419static int bnx2x_close(struct net_device *dev);
9420
72fd0718
VZ
9421/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9422 * scheduled on a general queue in order to prevent a dead lock.
9423 */
7be08a72 9424static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9425{
7be08a72 9426 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9427
9428 rtnl_lock();
9429
8395be5e
AE
9430 if (!netif_running(bp->dev)) {
9431 rtnl_unlock();
9432 return;
9433 }
7be08a72
AE
9434
9435 /* if stop on error is defined no recovery flows should be executed */
9436#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9437 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9438 "you will need to reboot when done\n");
b1fb8740 9439 goto sp_rtnl_not_reset;
7be08a72 9440#endif
34f80b04 9441
7be08a72
AE
9442 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9443 /*
b1fb8740
VZ
9444 * Clear all pending SP commands as we are going to reset the
9445 * function anyway.
7be08a72 9446 */
b1fb8740
VZ
9447 bp->sp_rtnl_state = 0;
9448 smp_mb();
9449
72fd0718 9450 bnx2x_parity_recover(bp);
b1fb8740 9451
8395be5e
AE
9452 rtnl_unlock();
9453 return;
b1fb8740
VZ
9454 }
9455
9456 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9457 /*
9458 * Clear all pending SP commands as we are going to reset the
9459 * function anyway.
9460 */
9461 bp->sp_rtnl_state = 0;
9462 smp_mb();
9463
5d07d868 9464 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9465 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740 9466
8395be5e
AE
9467 rtnl_unlock();
9468 return;
72fd0718 9469 }
b1fb8740
VZ
9470#ifdef BNX2X_STOP_ON_ERROR
9471sp_rtnl_not_reset:
9472#endif
9473 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9474 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9475 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9476 bnx2x_after_function_update(bp);
8304859a
AE
9477 /*
9478 * in case of fan failure we need to reset id if the "stop on error"
9479 * debug flag is set, since we trying to prevent permanent overheating
9480 * damage
9481 */
9482 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9483 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9484 netif_device_detach(bp->dev);
9485 bnx2x_close(bp->dev);
8395be5e
AE
9486 rtnl_unlock();
9487 return;
8304859a
AE
9488 }
9489
381ac16b
AE
9490 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9491 DP(BNX2X_MSG_SP,
9492 "sending set mcast vf pf channel message from rtnl sp-task\n");
9493 bnx2x_vfpf_set_mcast(bp->dev);
9494 }
9495
9496 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
9497 &bp->sp_rtnl_state)) {
9498 DP(BNX2X_MSG_SP,
9499 "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
9500 bnx2x_vfpf_storm_rx_mode(bp);
9501 }
9502
3ec9f9ca
AE
9503 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9504 &bp->sp_rtnl_state))
9505 bnx2x_pf_set_vfs_vlan(bp);
9506
8395be5e
AE
9507 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9508 * can be called from other contexts as well)
9509 */
34f80b04 9510 rtnl_unlock();
8395be5e 9511
6411280a 9512 /* enable SR-IOV if applicable */
8395be5e 9513 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
3c76feff
AE
9514 &bp->sp_rtnl_state)) {
9515 bnx2x_disable_sriov(bp);
6411280a 9516 bnx2x_enable_sriov(bp);
3c76feff 9517 }
34f80b04
EG
9518}
9519
3deb8167
YR
9520static void bnx2x_period_task(struct work_struct *work)
9521{
9522 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9523
9524 if (!netif_running(bp->dev))
9525 goto period_task_exit;
9526
9527 if (CHIP_REV_IS_SLOW(bp)) {
9528 BNX2X_ERR("period task called on emulation, ignoring\n");
9529 goto period_task_exit;
9530 }
9531
9532 bnx2x_acquire_phy_lock(bp);
9533 /*
9534 * The barrier is needed to ensure the ordering between the writing to
9535 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9536 * the reading here.
9537 */
9538 smp_mb();
9539 if (bp->port.pmf) {
9540 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9541
9542 /* Re-queue task in 1 sec */
9543 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9544 }
9545
9546 bnx2x_release_phy_lock(bp);
9547period_task_exit:
9548 return;
9549}
9550
a2fbb9ea
ET
9551/*
9552 * Init service functions
9553 */
9554
b56e9670 9555u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9556{
9557 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9558 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9559 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9560}
9561
1ef1d45a
BW
9562static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9563 struct bnx2x_mac_vals *vals)
34f80b04 9564{
452427b0
YM
9565 u32 val, base_addr, offset, mask, reset_reg;
9566 bool mac_stopped = false;
9567 u8 port = BP_PORT(bp);
34f80b04 9568
1ef1d45a
BW
9569 /* reset addresses as they also mark which values were changed */
9570 vals->bmac_addr = 0;
9571 vals->umac_addr = 0;
9572 vals->xmac_addr = 0;
9573 vals->emac_addr = 0;
9574
452427b0 9575 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9576
452427b0
YM
9577 if (!CHIP_IS_E3(bp)) {
9578 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9579 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9580 if ((mask & reset_reg) && val) {
9581 u32 wb_data[2];
9582 BNX2X_DEV_INFO("Disable bmac Rx\n");
9583 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9584 : NIG_REG_INGRESS_BMAC0_MEM;
9585 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9586 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9587
452427b0
YM
9588 /*
9589 * use rd/wr since we cannot use dmae. This is safe
9590 * since MCP won't access the bus due to the request
9591 * to unload, and no function on the path can be
9592 * loaded at this time.
9593 */
9594 wb_data[0] = REG_RD(bp, base_addr + offset);
9595 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
1ef1d45a
BW
9596 vals->bmac_addr = base_addr + offset;
9597 vals->bmac_val[0] = wb_data[0];
9598 vals->bmac_val[1] = wb_data[1];
452427b0 9599 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1ef1d45a
BW
9600 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9601 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
452427b0
YM
9602 }
9603 BNX2X_DEV_INFO("Disable emac Rx\n");
1ef1d45a
BW
9604 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9605 vals->emac_val = REG_RD(bp, vals->emac_addr);
9606 REG_WR(bp, vals->emac_addr, 0);
452427b0
YM
9607 mac_stopped = true;
9608 } else {
9609 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9610 BNX2X_DEV_INFO("Disable xmac Rx\n");
9611 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9612 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9613 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9614 val & ~(1 << 1));
9615 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9616 val | (1 << 1));
1ef1d45a
BW
9617 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9618 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9619 REG_WR(bp, vals->xmac_addr, 0);
452427b0
YM
9620 mac_stopped = true;
9621 }
9622 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9623 if (mask & reset_reg) {
9624 BNX2X_DEV_INFO("Disable umac Rx\n");
9625 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1ef1d45a
BW
9626 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9627 vals->umac_val = REG_RD(bp, vals->umac_addr);
9628 REG_WR(bp, vals->umac_addr, 0);
452427b0
YM
9629 mac_stopped = true;
9630 }
9631 }
9632
9633 if (mac_stopped)
9634 msleep(20);
452427b0
YM
9635}
9636
9637#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9638#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9639#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9640#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9641
1dd06ae8 9642static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
452427b0
YM
9643{
9644 u16 rcq, bd;
9645 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9646
9647 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9648 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9649
9650 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9651 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9652
9653 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9654 port, bd, rcq);
9655}
9656
0329aba1 9657static int bnx2x_prev_mcp_done(struct bnx2x *bp)
452427b0 9658{
5d07d868
YM
9659 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9660 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9661 if (!rc) {
9662 BNX2X_ERR("MCP response failure, aborting\n");
9663 return -EBUSY;
9664 }
9665
9666 return 0;
9667}
9668
c63da990
BW
9669static struct bnx2x_prev_path_list *
9670 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9671{
9672 struct bnx2x_prev_path_list *tmp_list;
9673
9674 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9675 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9676 bp->pdev->bus->number == tmp_list->bus &&
9677 BP_PATH(bp) == tmp_list->path)
9678 return tmp_list;
9679
9680 return NULL;
9681}
9682
7fa6f340
YM
9683static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
9684{
9685 struct bnx2x_prev_path_list *tmp_list;
9686 int rc;
9687
9688 rc = down_interruptible(&bnx2x_prev_sem);
9689 if (rc) {
9690 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9691 return rc;
9692 }
9693
9694 tmp_list = bnx2x_prev_path_get_entry(bp);
9695 if (tmp_list) {
9696 tmp_list->aer = 1;
9697 rc = 0;
9698 } else {
9699 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
9700 BP_PATH(bp));
9701 }
9702
9703 up(&bnx2x_prev_sem);
9704
9705 return rc;
9706}
9707
0329aba1 9708static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
452427b0
YM
9709{
9710 struct bnx2x_prev_path_list *tmp_list;
9711 int rc = false;
9712
9713 if (down_trylock(&bnx2x_prev_sem))
9714 return false;
9715
7fa6f340
YM
9716 tmp_list = bnx2x_prev_path_get_entry(bp);
9717 if (tmp_list) {
9718 if (tmp_list->aer) {
9719 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
9720 BP_PATH(bp));
9721 } else {
452427b0
YM
9722 rc = true;
9723 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9724 BP_PATH(bp));
452427b0
YM
9725 }
9726 }
9727
9728 up(&bnx2x_prev_sem);
9729
9730 return rc;
9731}
9732
178135c1
DK
9733bool bnx2x_port_after_undi(struct bnx2x *bp)
9734{
9735 struct bnx2x_prev_path_list *entry;
9736 bool val;
9737
9738 down(&bnx2x_prev_sem);
9739
9740 entry = bnx2x_prev_path_get_entry(bp);
9741 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
9742
9743 up(&bnx2x_prev_sem);
9744
9745 return val;
9746}
9747
c63da990 9748static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
452427b0
YM
9749{
9750 struct bnx2x_prev_path_list *tmp_list;
9751 int rc;
9752
7fa6f340
YM
9753 rc = down_interruptible(&bnx2x_prev_sem);
9754 if (rc) {
9755 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9756 return rc;
9757 }
9758
9759 /* Check whether the entry for this path already exists */
9760 tmp_list = bnx2x_prev_path_get_entry(bp);
9761 if (tmp_list) {
9762 if (!tmp_list->aer) {
9763 BNX2X_ERR("Re-Marking the path.\n");
9764 } else {
9765 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
9766 BP_PATH(bp));
9767 tmp_list->aer = 0;
9768 }
9769 up(&bnx2x_prev_sem);
9770 return 0;
9771 }
9772 up(&bnx2x_prev_sem);
9773
9774 /* Create an entry for this path and add it */
ea4b3857 9775 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9776 if (!tmp_list) {
9777 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9778 return -ENOMEM;
9779 }
9780
9781 tmp_list->bus = bp->pdev->bus->number;
9782 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9783 tmp_list->path = BP_PATH(bp);
7fa6f340 9784 tmp_list->aer = 0;
c63da990 9785 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
452427b0
YM
9786
9787 rc = down_interruptible(&bnx2x_prev_sem);
9788 if (rc) {
9789 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9790 kfree(tmp_list);
9791 } else {
7fa6f340
YM
9792 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
9793 BP_PATH(bp));
452427b0
YM
9794 list_add(&tmp_list->list, &bnx2x_prev_list);
9795 up(&bnx2x_prev_sem);
9796 }
9797
9798 return rc;
9799}
9800
0329aba1 9801static int bnx2x_do_flr(struct bnx2x *bp)
452427b0 9802{
2a80eebc 9803 int i;
452427b0
YM
9804 u16 status;
9805 struct pci_dev *dev = bp->pdev;
9806
8eee694c
YM
9807 if (CHIP_IS_E1x(bp)) {
9808 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9809 return -EINVAL;
9810 }
9811
9812 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9813 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9814 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9815 bp->common.bc_ver);
9816 return -EINVAL;
9817 }
452427b0 9818
452427b0
YM
9819 /* Wait for Transaction Pending bit clean */
9820 for (i = 0; i < 4; i++) {
9821 if (i)
9822 msleep((1 << (i - 1)) * 100);
9823
2a80eebc 9824 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9825 if (!(status & PCI_EXP_DEVSTA_TRPND))
9826 goto clear;
9827 }
9828
9829 dev_err(&dev->dev,
9830 "transaction is not cleared; proceeding with reset anyway\n");
9831
9832clear:
452427b0 9833
8eee694c 9834 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9835 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9836
9837 return 0;
9838}
9839
0329aba1 9840static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
452427b0
YM
9841{
9842 int rc;
9843
9844 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9845
9846 /* Test if previous unload process was already finished for this path */
9847 if (bnx2x_prev_is_path_marked(bp))
9848 return bnx2x_prev_mcp_done(bp);
9849
04c46736
YM
9850 BNX2X_DEV_INFO("Path is unmarked\n");
9851
452427b0
YM
9852 /* If function has FLR capabilities, and existing FW version matches
9853 * the one required, then FLR will be sufficient to clean any residue
9854 * left by previous driver
9855 */
ad5afc89 9856 rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
8eee694c
YM
9857
9858 if (!rc) {
9859 /* fw version is good */
9860 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9861 rc = bnx2x_do_flr(bp);
9862 }
9863
9864 if (!rc) {
9865 /* FLR was performed */
9866 BNX2X_DEV_INFO("FLR successful\n");
9867 return 0;
9868 }
9869
9870 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9871
9872 /* Close the MCP request, return failure*/
9873 rc = bnx2x_prev_mcp_done(bp);
9874 if (!rc)
9875 rc = BNX2X_PREV_WAIT_NEEDED;
9876
9877 return rc;
9878}
9879
0329aba1 9880static int bnx2x_prev_unload_common(struct bnx2x *bp)
452427b0
YM
9881{
9882 u32 reset_reg, tmp_reg = 0, rc;
c63da990 9883 bool prev_undi = false;
1ef1d45a
BW
9884 struct bnx2x_mac_vals mac_vals;
9885
452427b0
YM
9886 /* It is possible a previous function received 'common' answer,
9887 * but hasn't loaded yet, therefore creating a scenario of
9888 * multiple functions receiving 'common' on the same path.
9889 */
9890 BNX2X_DEV_INFO("Common unload Flow\n");
9891
1ef1d45a
BW
9892 memset(&mac_vals, 0, sizeof(mac_vals));
9893
452427b0
YM
9894 if (bnx2x_prev_is_path_marked(bp))
9895 return bnx2x_prev_mcp_done(bp);
9896
9897 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9898
9899 /* Reset should be performed after BRB is emptied */
9900 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9901 u32 timer_count = 1000;
452427b0
YM
9902
9903 /* Close the MAC Rx to prevent BRB from filling up */
1ef1d45a
BW
9904 bnx2x_prev_unload_close_mac(bp, &mac_vals);
9905
9906 /* close LLH filters towards the BRB */
9907 bnx2x_set_rx_filter(&bp->link_params, 0);
452427b0
YM
9908
9909 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9910 * UNDI driver initializes CID offset for normal bell to 0x7
9911 */
452427b0
YM
9912 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9913 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9914 if (tmp_reg == 0x7) {
9915 BNX2X_DEV_INFO("UNDI previously loaded\n");
9916 prev_undi = true;
9917 /* clear the UNDI indication */
9918 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
a74801c5
YM
9919 /* clear possible idle check errors */
9920 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
34f80b04 9921 }
452427b0 9922 }
d46f7c4d
DK
9923 if (!CHIP_IS_E1x(bp))
9924 /* block FW from writing to host */
9925 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
9926
452427b0
YM
9927 /* wait until BRB is empty */
9928 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9929 while (timer_count) {
9930 u32 prev_brb = tmp_reg;
34f80b04 9931
452427b0
YM
9932 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9933 if (!tmp_reg)
9934 break;
619c5cb6 9935
452427b0 9936 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9937
452427b0
YM
9938 /* reset timer as long as BRB actually gets emptied */
9939 if (prev_brb > tmp_reg)
9940 timer_count = 1000;
9941 else
9942 timer_count--;
da5a662a 9943
452427b0
YM
9944 /* If UNDI resides in memory, manually increment it */
9945 if (prev_undi)
9946 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9947
452427b0 9948 udelay(10);
7a06a122 9949 }
452427b0
YM
9950
9951 if (!timer_count)
9952 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
34f80b04 9953 }
f16da43b 9954
452427b0
YM
9955 /* No packets are in the pipeline, path is ready for reset */
9956 bnx2x_reset_common(bp);
9957
1ef1d45a
BW
9958 if (mac_vals.xmac_addr)
9959 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
9960 if (mac_vals.umac_addr)
9961 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
9962 if (mac_vals.emac_addr)
9963 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
9964 if (mac_vals.bmac_addr) {
9965 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
9966 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
9967 }
9968
c63da990 9969 rc = bnx2x_prev_mark_path(bp, prev_undi);
452427b0
YM
9970 if (rc) {
9971 bnx2x_prev_mcp_done(bp);
9972 return rc;
9973 }
9974
9975 return bnx2x_prev_mcp_done(bp);
9976}
9977
24f06716
AE
9978/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9979 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9980 * the addresses of the transaction, resulting in was-error bit set in the pci
9981 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9982 * to clear the interrupt which detected this from the pglueb and the was done
9983 * bit
9984 */
0329aba1 9985static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
24f06716 9986{
4a25417c
AE
9987 if (!CHIP_IS_E1x(bp)) {
9988 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9989 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
04c46736
YM
9990 DP(BNX2X_MSG_SP,
9991 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
4a25417c
AE
9992 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9993 1 << BP_FUNC(bp));
9994 }
24f06716
AE
9995 }
9996}
9997
0329aba1 9998static int bnx2x_prev_unload(struct bnx2x *bp)
452427b0
YM
9999{
10000 int time_counter = 10;
10001 u32 rc, fw, hw_lock_reg, hw_lock_val;
10002 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10003
24f06716
AE
10004 /* clear hw from errors which may have resulted from an interrupted
10005 * dmae transaction.
10006 */
10007 bnx2x_prev_interrupted_dmae(bp);
10008
10009 /* Release previously held locks */
452427b0
YM
10010 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10011 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10012 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10013
10014 hw_lock_val = (REG_RD(bp, hw_lock_reg));
10015 if (hw_lock_val) {
10016 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10017 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10018 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10019 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10020 }
10021
10022 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10023 REG_WR(bp, hw_lock_reg, 0xffffffff);
10024 } else
10025 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10026
10027 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10028 BNX2X_DEV_INFO("Release previously held alr\n");
10029 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
10030 }
10031
452427b0 10032 do {
7fa6f340 10033 int aer = 0;
452427b0
YM
10034 /* Lock MCP using an unload request */
10035 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10036 if (!fw) {
10037 BNX2X_ERR("MCP response failure, aborting\n");
10038 rc = -EBUSY;
10039 break;
10040 }
10041
7fa6f340
YM
10042 rc = down_interruptible(&bnx2x_prev_sem);
10043 if (rc) {
10044 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10045 rc);
10046 } else {
10047 /* If Path is marked by EEH, ignore unload status */
10048 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10049 bnx2x_prev_path_get_entry(bp)->aer);
60cde81f 10050 up(&bnx2x_prev_sem);
7fa6f340 10051 }
7fa6f340
YM
10052
10053 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
452427b0
YM
10054 rc = bnx2x_prev_unload_common(bp);
10055 break;
10056 }
10057
16a5fd92 10058 /* non-common reply from MCP might require looping */
452427b0
YM
10059 rc = bnx2x_prev_unload_uncommon(bp);
10060 if (rc != BNX2X_PREV_WAIT_NEEDED)
10061 break;
10062
10063 msleep(20);
10064 } while (--time_counter);
10065
10066 if (!time_counter || rc) {
10067 BNX2X_ERR("Failed unloading previous driver, aborting\n");
10068 rc = -EBUSY;
10069 }
10070
c63da990 10071 /* Mark function if its port was used to boot from SAN */
178135c1 10072 if (bnx2x_port_after_undi(bp))
c63da990
BW
10073 bp->link_params.feature_config_flags |=
10074 FEATURE_CONFIG_BOOT_FROM_SAN;
10075
452427b0
YM
10076 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10077
10078 return rc;
34f80b04
EG
10079}
10080
0329aba1 10081static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
34f80b04 10082{
1d187b34 10083 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 10084 u16 pmc;
34f80b04
EG
10085
10086 /* Get the chip revision id and number. */
10087 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10088 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10089 id = ((val & 0xffff) << 16);
10090 val = REG_RD(bp, MISC_REG_CHIP_REV);
10091 id |= ((val & 0xf) << 12);
f22fdf25
YM
10092
10093 /* Metal is read from PCI regs, but we can't access >=0x400 from
10094 * the configuration space (so we need to reg_rd)
10095 */
10096 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10097 id |= (((val >> 24) & 0xf) << 4);
5a40e08e 10098 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
10099 id |= (val & 0xf);
10100 bp->common.chip_id = id;
523224a3 10101
7e8e02df
BW
10102 /* force 57811 according to MISC register */
10103 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10104 if (CHIP_IS_57810(bp))
10105 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10106 (bp->common.chip_id & 0x0000FFFF);
10107 else if (CHIP_IS_57810_MF(bp))
10108 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10109 (bp->common.chip_id & 0x0000FFFF);
10110 bp->common.chip_id |= 0x1;
10111 }
10112
523224a3
DK
10113 /* Set doorbell size */
10114 bp->db_size = (1 << BNX2X_DB_SHIFT);
10115
619c5cb6 10116 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
10117 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10118 if ((val & 1) == 0)
10119 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10120 else
10121 val = (val >> 1) & 1;
10122 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10123 "2_PORT_MODE");
10124 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10125 CHIP_2_PORT_MODE;
10126
10127 if (CHIP_MODE_IS_4_PORT(bp))
10128 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10129 else
10130 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10131 } else {
10132 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10133 bp->pfid = bp->pf_num; /* 0..7 */
10134 }
10135
51c1a580
MS
10136 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10137
f2e0899f
DK
10138 bp->link_params.chip_id = bp->common.chip_id;
10139 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 10140
1c06328c
EG
10141 val = (REG_RD(bp, 0x2874) & 0x55);
10142 if ((bp->common.chip_id & 0x1) ||
10143 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10144 bp->flags |= ONE_PORT_FLAG;
10145 BNX2X_DEV_INFO("single port device\n");
10146 }
10147
34f80b04 10148 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 10149 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
10150 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10151 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10152 bp->common.flash_size, bp->common.flash_size);
10153
1b6e2ceb
DK
10154 bnx2x_init_shmem(bp);
10155
f2e0899f
DK
10156 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10157 MISC_REG_GENERIC_CR_1 :
10158 MISC_REG_GENERIC_CR_0));
1b6e2ceb 10159
34f80b04 10160 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 10161 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
10162 if (SHMEM2_RD(bp, size) >
10163 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10164 bp->link_params.lfa_base =
10165 REG_RD(bp, bp->common.shmem2_base +
10166 (u32)offsetof(struct shmem2_region,
10167 lfa_host_addr[BP_PORT(bp)]));
10168 else
10169 bp->link_params.lfa_base = 0;
2691d51d
EG
10170 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10171 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 10172
f2e0899f 10173 if (!bp->common.shmem_base) {
34f80b04
EG
10174 BNX2X_DEV_INFO("MCP not active\n");
10175 bp->flags |= NO_MCP_FLAG;
10176 return;
10177 }
10178
34f80b04 10179 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 10180 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
10181
10182 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10183 SHARED_HW_CFG_LED_MODE_MASK) >>
10184 SHARED_HW_CFG_LED_MODE_SHIFT);
10185
c2c8b03e
EG
10186 bp->link_params.feature_config_flags = 0;
10187 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10188 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10189 bp->link_params.feature_config_flags |=
10190 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10191 else
10192 bp->link_params.feature_config_flags &=
10193 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10194
34f80b04
EG
10195 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10196 bp->common.bc_ver = val;
10197 BNX2X_DEV_INFO("bc_ver %X\n", val);
10198 if (val < BNX2X_BC_VER) {
10199 /* for now only warn
10200 * later we might need to enforce this */
51c1a580
MS
10201 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10202 BNX2X_BC_VER, val);
34f80b04 10203 }
4d295db0 10204 bp->link_params.feature_config_flags |=
a22f0788 10205 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
10206 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10207
a22f0788
YR
10208 bp->link_params.feature_config_flags |=
10209 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10210 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
10211 bp->link_params.feature_config_flags |=
10212 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10213 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
10214 bp->link_params.feature_config_flags |=
10215 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10216 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
10217
10218 bp->link_params.feature_config_flags |=
10219 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10220 FEATURE_CONFIG_MT_SUPPORT : 0;
10221
0e898dd7
BW
10222 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10223 BC_SUPPORTS_PFC_STATS : 0;
85242eea 10224
2e499d3c
BW
10225 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10226 BC_SUPPORTS_FCOE_FEATURES : 0;
10227
9876879f
BW
10228 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10229 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
10230 boot_mode = SHMEM_RD(bp,
10231 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10232 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10233 switch (boot_mode) {
10234 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10235 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10236 break;
10237 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10238 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10239 break;
10240 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10241 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10242 break;
10243 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10244 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10245 break;
10246 }
10247
f9a3ebbe
DK
10248 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
10249 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10250
72ce58c3 10251 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 10252 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
10253
10254 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10255 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10256 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10257 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10258
cdaa7cb8
VZ
10259 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10260 val, val2, val3, val4);
34f80b04
EG
10261}
10262
f2e0899f
DK
10263#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10264#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10265
0329aba1 10266static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
10267{
10268 int pfid = BP_FUNC(bp);
f2e0899f
DK
10269 int igu_sb_id;
10270 u32 val;
6383c0b3 10271 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
10272
10273 bp->igu_base_sb = 0xff;
f2e0899f 10274 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 10275 int vn = BP_VN(bp);
6383c0b3 10276 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
10277 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10278 FP_SB_MAX_E1x;
10279
10280 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10281 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10282
9b341bb1 10283 return 0;
f2e0899f
DK
10284 }
10285
10286 /* IGU in normal mode - read CAM */
10287 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10288 igu_sb_id++) {
10289 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10290 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10291 continue;
10292 fid = IGU_FID(val);
10293 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10294 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10295 continue;
10296 if (IGU_VEC(val) == 0)
10297 /* default status block */
10298 bp->igu_dsb_id = igu_sb_id;
10299 else {
10300 if (bp->igu_base_sb == 0xff)
10301 bp->igu_base_sb = igu_sb_id;
6383c0b3 10302 igu_sb_cnt++;
f2e0899f
DK
10303 }
10304 }
10305 }
619c5cb6 10306
6383c0b3 10307#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10308 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10309 * optional that number of CAM entries will not be equal to the value
10310 * advertised in PCI.
10311 * Driver should use the minimal value of both as the actual status
10312 * block count
619c5cb6 10313 */
185d4c8b 10314 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10315#endif
619c5cb6 10316
9b341bb1 10317 if (igu_sb_cnt == 0) {
f2e0899f 10318 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10319 return -EINVAL;
10320 }
10321
10322 return 0;
f2e0899f
DK
10323}
10324
1dd06ae8 10325static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
a2fbb9ea 10326{
a22f0788
YR
10327 int cfg_size = 0, idx, port = BP_PORT(bp);
10328
10329 /* Aggregation of supported attributes of all external phys */
10330 bp->port.supported[0] = 0;
10331 bp->port.supported[1] = 0;
b7737c9b
YR
10332 switch (bp->link_params.num_phys) {
10333 case 1:
a22f0788
YR
10334 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10335 cfg_size = 1;
10336 break;
b7737c9b 10337 case 2:
a22f0788
YR
10338 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10339 cfg_size = 1;
10340 break;
10341 case 3:
10342 if (bp->link_params.multi_phy_config &
10343 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10344 bp->port.supported[1] =
10345 bp->link_params.phy[EXT_PHY1].supported;
10346 bp->port.supported[0] =
10347 bp->link_params.phy[EXT_PHY2].supported;
10348 } else {
10349 bp->port.supported[0] =
10350 bp->link_params.phy[EXT_PHY1].supported;
10351 bp->port.supported[1] =
10352 bp->link_params.phy[EXT_PHY2].supported;
10353 }
10354 cfg_size = 2;
10355 break;
b7737c9b 10356 }
a2fbb9ea 10357
a22f0788 10358 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10359 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10360 SHMEM_RD(bp,
a22f0788
YR
10361 dev_info.port_hw_config[port].external_phy_config),
10362 SHMEM_RD(bp,
10363 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10364 return;
f85582f8 10365 }
a2fbb9ea 10366
619c5cb6
VZ
10367 if (CHIP_IS_E3(bp))
10368 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10369 else {
10370 switch (switch_cfg) {
10371 case SWITCH_CFG_1G:
10372 bp->port.phy_addr = REG_RD(
10373 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10374 break;
10375 case SWITCH_CFG_10G:
10376 bp->port.phy_addr = REG_RD(
10377 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10378 break;
10379 default:
10380 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10381 bp->port.link_config[0]);
10382 return;
10383 }
a2fbb9ea 10384 }
619c5cb6 10385 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10386 /* mask what we support according to speed_cap_mask per configuration */
10387 for (idx = 0; idx < cfg_size; idx++) {
10388 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10389 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10390 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10391
a22f0788 10392 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10393 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10394 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10395
a22f0788 10396 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10397 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10398 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10399
a22f0788 10400 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10401 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10402 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10403
a22f0788 10404 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10405 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10406 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10407 SUPPORTED_1000baseT_Full);
a2fbb9ea 10408
a22f0788 10409 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10410 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10411 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10412
a22f0788 10413 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10414 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788 10415 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
a22f0788 10416 }
a2fbb9ea 10417
a22f0788
YR
10418 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10419 bp->port.supported[1]);
a2fbb9ea
ET
10420}
10421
0329aba1 10422static void bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10423{
a22f0788
YR
10424 u32 link_config, idx, cfg_size = 0;
10425 bp->port.advertising[0] = 0;
10426 bp->port.advertising[1] = 0;
10427 switch (bp->link_params.num_phys) {
10428 case 1:
10429 case 2:
10430 cfg_size = 1;
10431 break;
10432 case 3:
10433 cfg_size = 2;
10434 break;
10435 }
10436 for (idx = 0; idx < cfg_size; idx++) {
10437 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10438 link_config = bp->port.link_config[idx];
10439 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10440 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10441 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10442 bp->link_params.req_line_speed[idx] =
10443 SPEED_AUTO_NEG;
10444 bp->port.advertising[idx] |=
10445 bp->port.supported[idx];
10bd1f24
MY
10446 if (bp->link_params.phy[EXT_PHY1].type ==
10447 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10448 bp->port.advertising[idx] |=
10449 (SUPPORTED_100baseT_Half |
10450 SUPPORTED_100baseT_Full);
f85582f8
DK
10451 } else {
10452 /* force 10G, no AN */
a22f0788
YR
10453 bp->link_params.req_line_speed[idx] =
10454 SPEED_10000;
10455 bp->port.advertising[idx] |=
10456 (ADVERTISED_10000baseT_Full |
f85582f8 10457 ADVERTISED_FIBRE);
a22f0788 10458 continue;
f85582f8
DK
10459 }
10460 break;
a2fbb9ea 10461
f85582f8 10462 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10463 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10464 bp->link_params.req_line_speed[idx] =
10465 SPEED_10;
10466 bp->port.advertising[idx] |=
10467 (ADVERTISED_10baseT_Full |
f85582f8
DK
10468 ADVERTISED_TP);
10469 } else {
51c1a580 10470 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10471 link_config,
a22f0788 10472 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10473 return;
10474 }
10475 break;
a2fbb9ea 10476
f85582f8 10477 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10478 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10479 bp->link_params.req_line_speed[idx] =
10480 SPEED_10;
10481 bp->link_params.req_duplex[idx] =
10482 DUPLEX_HALF;
10483 bp->port.advertising[idx] |=
10484 (ADVERTISED_10baseT_Half |
f85582f8
DK
10485 ADVERTISED_TP);
10486 } else {
51c1a580 10487 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10488 link_config,
10489 bp->link_params.speed_cap_mask[idx]);
10490 return;
10491 }
10492 break;
a2fbb9ea 10493
f85582f8
DK
10494 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10495 if (bp->port.supported[idx] &
10496 SUPPORTED_100baseT_Full) {
a22f0788
YR
10497 bp->link_params.req_line_speed[idx] =
10498 SPEED_100;
10499 bp->port.advertising[idx] |=
10500 (ADVERTISED_100baseT_Full |
f85582f8
DK
10501 ADVERTISED_TP);
10502 } else {
51c1a580 10503 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10504 link_config,
10505 bp->link_params.speed_cap_mask[idx]);
10506 return;
10507 }
10508 break;
a2fbb9ea 10509
f85582f8
DK
10510 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10511 if (bp->port.supported[idx] &
10512 SUPPORTED_100baseT_Half) {
10513 bp->link_params.req_line_speed[idx] =
10514 SPEED_100;
10515 bp->link_params.req_duplex[idx] =
10516 DUPLEX_HALF;
a22f0788
YR
10517 bp->port.advertising[idx] |=
10518 (ADVERTISED_100baseT_Half |
f85582f8
DK
10519 ADVERTISED_TP);
10520 } else {
51c1a580 10521 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10522 link_config,
10523 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10524 return;
10525 }
10526 break;
a2fbb9ea 10527
f85582f8 10528 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10529 if (bp->port.supported[idx] &
10530 SUPPORTED_1000baseT_Full) {
10531 bp->link_params.req_line_speed[idx] =
10532 SPEED_1000;
10533 bp->port.advertising[idx] |=
10534 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10535 ADVERTISED_TP);
10536 } else {
51c1a580 10537 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10538 link_config,
10539 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10540 return;
10541 }
10542 break;
a2fbb9ea 10543
f85582f8 10544 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10545 if (bp->port.supported[idx] &
10546 SUPPORTED_2500baseX_Full) {
10547 bp->link_params.req_line_speed[idx] =
10548 SPEED_2500;
10549 bp->port.advertising[idx] |=
10550 (ADVERTISED_2500baseX_Full |
34f80b04 10551 ADVERTISED_TP);
f85582f8 10552 } else {
51c1a580 10553 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10554 link_config,
f85582f8
DK
10555 bp->link_params.speed_cap_mask[idx]);
10556 return;
10557 }
10558 break;
a2fbb9ea 10559
f85582f8 10560 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10561 if (bp->port.supported[idx] &
10562 SUPPORTED_10000baseT_Full) {
10563 bp->link_params.req_line_speed[idx] =
10564 SPEED_10000;
10565 bp->port.advertising[idx] |=
10566 (ADVERTISED_10000baseT_Full |
34f80b04 10567 ADVERTISED_FIBRE);
f85582f8 10568 } else {
51c1a580 10569 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10570 link_config,
f85582f8
DK
10571 bp->link_params.speed_cap_mask[idx]);
10572 return;
10573 }
10574 break;
3c9ada22
YR
10575 case PORT_FEATURE_LINK_SPEED_20G:
10576 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10577
3c9ada22 10578 break;
f85582f8 10579 default:
51c1a580 10580 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10581 link_config);
f85582f8
DK
10582 bp->link_params.req_line_speed[idx] =
10583 SPEED_AUTO_NEG;
10584 bp->port.advertising[idx] =
10585 bp->port.supported[idx];
10586 break;
10587 }
a2fbb9ea 10588
a22f0788 10589 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10590 PORT_FEATURE_FLOW_CONTROL_MASK);
cd1dfce2
YM
10591 if (bp->link_params.req_flow_ctrl[idx] ==
10592 BNX2X_FLOW_CTRL_AUTO) {
10593 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10594 bp->link_params.req_flow_ctrl[idx] =
10595 BNX2X_FLOW_CTRL_NONE;
10596 else
10597 bnx2x_set_requested_fc(bp);
a22f0788 10598 }
a2fbb9ea 10599
51c1a580 10600 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10601 bp->link_params.req_line_speed[idx],
10602 bp->link_params.req_duplex[idx],
10603 bp->link_params.req_flow_ctrl[idx],
10604 bp->port.advertising[idx]);
10605 }
a2fbb9ea
ET
10606}
10607
0329aba1 10608static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
e665bfda 10609{
86564c3f
YM
10610 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10611 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10612 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10613 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
e665bfda
MC
10614}
10615
0329aba1 10616static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10617{
34f80b04 10618 int port = BP_PORT(bp);
589abe3a 10619 u32 config;
c8c60d88 10620 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10621
c18487ee 10622 bp->link_params.bp = bp;
34f80b04 10623 bp->link_params.port = port;
c18487ee 10624
c18487ee 10625 bp->link_params.lane_config =
a2fbb9ea 10626 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10627
a22f0788 10628 bp->link_params.speed_cap_mask[0] =
a2fbb9ea 10629 SHMEM_RD(bp,
b0261926
YR
10630 dev_info.port_hw_config[port].speed_capability_mask) &
10631 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
a22f0788
YR
10632 bp->link_params.speed_cap_mask[1] =
10633 SHMEM_RD(bp,
b0261926
YR
10634 dev_info.port_hw_config[port].speed_capability_mask2) &
10635 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
a22f0788 10636 bp->port.link_config[0] =
a2fbb9ea
ET
10637 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10638
a22f0788
YR
10639 bp->port.link_config[1] =
10640 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10641
a22f0788
YR
10642 bp->link_params.multi_phy_config =
10643 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10644 /* If the device is capable of WoL, set the default state according
10645 * to the HW
10646 */
4d295db0 10647 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10648 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10649 (config & PORT_FEATURE_WOL_ENABLED));
10650
4ba7699b
YM
10651 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10652 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
10653 bp->flags |= NO_ISCSI_FLAG;
10654 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10655 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
10656 bp->flags |= NO_FCOE_FLAG;
10657
51c1a580 10658 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10659 bp->link_params.lane_config,
a22f0788
YR
10660 bp->link_params.speed_cap_mask[0],
10661 bp->port.link_config[0]);
a2fbb9ea 10662
a22f0788 10663 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10664 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10665 bnx2x_phy_probe(&bp->link_params);
c18487ee 10666 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10667
10668 bnx2x_link_settings_requested(bp);
10669
01cd4528
EG
10670 /*
10671 * If connected directly, work with the internal PHY, otherwise, work
10672 * with the external PHY
10673 */
b7737c9b
YR
10674 ext_phy_config =
10675 SHMEM_RD(bp,
10676 dev_info.port_hw_config[port].external_phy_config);
10677 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10678 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10679 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10680
10681 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10682 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10683 bp->mdio.prtad =
b7737c9b 10684 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10685
c8c60d88
YM
10686 /* Configure link feature according to nvram value */
10687 eee_mode = (((SHMEM_RD(bp, dev_info.
10688 port_feature_config[port].eee_power_mode)) &
10689 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10690 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10691 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10692 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10693 EEE_MODE_ENABLE_LPI |
10694 EEE_MODE_OUTPUT_TIME;
10695 } else {
10696 bp->link_params.eee_mode = 0;
10697 }
0793f83f 10698}
01cd4528 10699
b306f5ed 10700void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10701{
9e62e912 10702 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10703 int port = BP_PORT(bp);
2ba45142 10704 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10705 drv_lic_key[port].max_iscsi_conn);
2ba45142 10706
55c11941
MS
10707 if (!CNIC_SUPPORT(bp)) {
10708 bp->flags |= no_flags;
10709 return;
10710 }
10711
b306f5ed 10712 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10713 bp->cnic_eth_dev.max_iscsi_conn =
10714 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10715 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10716
b306f5ed
DK
10717 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10718 bp->cnic_eth_dev.max_iscsi_conn);
10719
10720 /*
10721 * If maximum allowed number of connections is zero -
10722 * disable the feature.
10723 */
10724 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10725 bp->flags |= no_flags;
b306f5ed
DK
10726}
10727
0329aba1 10728static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9e62e912
DK
10729{
10730 /* Port info */
10731 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10732 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10733 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10734 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10735
10736 /* Node info */
10737 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10738 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10739 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10740 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10741}
86800194
DK
10742
10743static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
10744{
10745 u8 count = 0;
10746
10747 if (IS_MF(bp)) {
10748 u8 fid;
10749
10750 /* iterate over absolute function ids for this path: */
10751 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
10752 if (IS_MF_SD(bp)) {
10753 u32 cfg = MF_CFG_RD(bp,
10754 func_mf_config[fid].config);
10755
10756 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
10757 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
10758 FUNC_MF_CFG_PROTOCOL_FCOE))
10759 count++;
10760 } else {
10761 u32 cfg = MF_CFG_RD(bp,
10762 func_ext_config[fid].
10763 func_cfg);
10764
10765 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
10766 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
10767 count++;
10768 }
10769 }
10770 } else { /* SF */
10771 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
10772
10773 for (port = 0; port < port_cnt; port++) {
10774 u32 lic = SHMEM_RD(bp,
10775 drv_lic_key[port].max_fcoe_conn) ^
10776 FW_ENCODE_32BIT_PATTERN;
10777 if (lic)
10778 count++;
10779 }
10780 }
10781
10782 return count;
10783}
10784
0329aba1 10785static void bnx2x_get_fcoe_info(struct bnx2x *bp)
b306f5ed
DK
10786{
10787 int port = BP_PORT(bp);
10788 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10789 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10790 drv_lic_key[port].max_fcoe_conn);
86800194 10791 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
b306f5ed 10792
55c11941
MS
10793 if (!CNIC_SUPPORT(bp)) {
10794 bp->flags |= NO_FCOE_FLAG;
10795 return;
10796 }
10797
b306f5ed 10798 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10799 bp->cnic_eth_dev.max_fcoe_conn =
10800 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10801 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10802
0eb43b4b
BPG
10803 /* Calculate the number of maximum allowed FCoE tasks */
10804 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
86800194
DK
10805
10806 /* check if FCoE resources must be shared between different functions */
10807 if (num_fcoe_func)
10808 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
0eb43b4b 10809
bf61ee14
VZ
10810 /* Read the WWN: */
10811 if (!IS_MF(bp)) {
10812 /* Port info */
10813 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10814 SHMEM_RD(bp,
2de67439 10815 dev_info.port_hw_config[port].
bf61ee14
VZ
10816 fcoe_wwn_port_name_upper);
10817 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10818 SHMEM_RD(bp,
2de67439 10819 dev_info.port_hw_config[port].
bf61ee14
VZ
10820 fcoe_wwn_port_name_lower);
10821
10822 /* Node info */
10823 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10824 SHMEM_RD(bp,
2de67439 10825 dev_info.port_hw_config[port].
bf61ee14
VZ
10826 fcoe_wwn_node_name_upper);
10827 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10828 SHMEM_RD(bp,
2de67439 10829 dev_info.port_hw_config[port].
bf61ee14
VZ
10830 fcoe_wwn_node_name_lower);
10831 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10832 /*
10833 * Read the WWN info only if the FCoE feature is enabled for
10834 * this function.
10835 */
7b5342d9 10836 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10837 bnx2x_get_ext_wwn_info(bp, func);
10838
382e513a 10839 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 10840 bnx2x_get_ext_wwn_info(bp, func);
382e513a 10841 }
bf61ee14 10842
b306f5ed 10843 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10844
bf61ee14
VZ
10845 /*
10846 * If maximum allowed number of connections is zero -
2ba45142
VZ
10847 * disable the feature.
10848 */
2ba45142
VZ
10849 if (!bp->cnic_eth_dev.max_fcoe_conn)
10850 bp->flags |= NO_FCOE_FLAG;
10851}
b306f5ed 10852
0329aba1 10853static void bnx2x_get_cnic_info(struct bnx2x *bp)
b306f5ed
DK
10854{
10855 /*
10856 * iSCSI may be dynamically disabled but reading
10857 * info here we will decrease memory usage by driver
10858 * if the feature is disabled for good
10859 */
10860 bnx2x_get_iscsi_info(bp);
10861 bnx2x_get_fcoe_info(bp);
10862}
2ba45142 10863
0329aba1 10864static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10865{
10866 u32 val, val2;
10867 int func = BP_ABS_FUNC(bp);
10868 int port = BP_PORT(bp);
2ba45142
VZ
10869 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10870 u8 *fip_mac = bp->fip_mac;
0793f83f 10871
55c11941
MS
10872 if (IS_MF(bp)) {
10873 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10874 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10875 * In non SD mode features configuration comes from struct
10876 * func_ext_config.
2ba45142 10877 */
55c11941 10878 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10879 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10880 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10881 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10882 iscsi_mac_addr_upper);
0793f83f 10883 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10884 iscsi_mac_addr_lower);
2ba45142 10885 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10886 BNX2X_DEV_INFO
10887 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10888 } else {
2ba45142 10889 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10890 }
2ba45142
VZ
10891
10892 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10893 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10894 fcoe_mac_addr_upper);
2ba45142 10895 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10896 fcoe_mac_addr_lower);
2ba45142 10897 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10898 BNX2X_DEV_INFO
10899 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10900 } else {
2ba45142 10901 bp->flags |= NO_FCOE_FLAG;
55c11941 10902 }
a3348722
BW
10903
10904 bp->mf_ext_config = cfg;
10905
9e62e912 10906 } else { /* SD MODE */
55c11941
MS
10907 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10908 /* use primary mac as iscsi mac */
10909 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10910
10911 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10912 BNX2X_DEV_INFO
10913 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10914 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10915 /* use primary mac as fip mac */
10916 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10917 BNX2X_DEV_INFO("SD FCoE MODE\n");
10918 BNX2X_DEV_INFO
10919 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10920 }
0793f83f 10921 }
a3348722 10922
82594f8f
YM
10923 /* If this is a storage-only interface, use SAN mac as
10924 * primary MAC. Notice that for SD this is already the case,
10925 * as the SAN mac was copied from the primary MAC.
10926 */
10927 if (IS_MF_FCOE_AFEX(bp))
a3348722 10928 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
0793f83f 10929 } else {
0793f83f 10930 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10931 iscsi_mac_upper);
0793f83f 10932 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10933 iscsi_mac_lower);
2ba45142 10934 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10935
10936 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10937 fcoe_fip_mac_upper);
c03bd39c 10938 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10939 fcoe_fip_mac_lower);
c03bd39c 10940 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10941 }
10942
55c11941 10943 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10944 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10945 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10946 memset(iscsi_mac, 0, ETH_ALEN);
10947 }
10948
55c11941 10949 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10950 if (!is_valid_ether_addr(fip_mac)) {
10951 bp->flags |= NO_FCOE_FLAG;
10952 memset(bp->fip_mac, 0, ETH_ALEN);
10953 }
55c11941
MS
10954}
10955
0329aba1 10956static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
55c11941
MS
10957{
10958 u32 val, val2;
10959 int func = BP_ABS_FUNC(bp);
10960 int port = BP_PORT(bp);
10961
10962 /* Zero primary MAC configuration */
10963 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10964
10965 if (BP_NOMCP(bp)) {
10966 BNX2X_ERROR("warning: random MAC workaround active\n");
10967 eth_hw_addr_random(bp->dev);
10968 } else if (IS_MF(bp)) {
10969 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10970 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10971 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10972 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10973 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10974
10975 if (CNIC_SUPPORT(bp))
10976 bnx2x_get_cnic_mac_hwinfo(bp);
10977 } else {
10978 /* in SF read MACs from port configuration */
10979 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10980 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10981 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10982
10983 if (CNIC_SUPPORT(bp))
10984 bnx2x_get_cnic_mac_hwinfo(bp);
10985 }
10986
10987 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10988
614c76df 10989 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10990 dev_err(&bp->pdev->dev,
51c1a580
MS
10991 "bad Ethernet MAC address configuration: %pM\n"
10992 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10993 bp->dev->dev_addr);
7964211d 10994}
51c1a580 10995
0329aba1 10996static bool bnx2x_get_dropless_info(struct bnx2x *bp)
7964211d
YM
10997{
10998 int tmp;
10999 u32 cfg;
51c1a580 11000
7964211d
YM
11001 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11002 /* Take function: tmp = func */
11003 tmp = BP_ABS_FUNC(bp);
11004 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11005 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11006 } else {
11007 /* Take port: tmp = port */
11008 tmp = BP_PORT(bp);
11009 cfg = SHMEM_RD(bp,
11010 dev_info.port_hw_config[tmp].generic_features);
11011 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11012 }
11013 return cfg;
34f80b04
EG
11014}
11015
0329aba1 11016static int bnx2x_get_hwinfo(struct bnx2x *bp)
34f80b04 11017{
0793f83f 11018 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 11019 int vn;
0793f83f 11020 u32 val = 0;
34f80b04 11021 int rc = 0;
a2fbb9ea 11022
34f80b04 11023 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 11024
6383c0b3
AE
11025 /*
11026 * initialize IGU parameters
11027 */
f2e0899f
DK
11028 if (CHIP_IS_E1x(bp)) {
11029 bp->common.int_block = INT_BLOCK_HC;
11030
11031 bp->igu_dsb_id = DEF_SB_IGU_ID;
11032 bp->igu_base_sb = 0;
f2e0899f
DK
11033 } else {
11034 bp->common.int_block = INT_BLOCK_IGU;
7a06a122 11035
16a5fd92 11036 /* do not allow device reset during IGU info processing */
7a06a122
DK
11037 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11038
f2e0899f 11039 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
11040
11041 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11042 int tout = 5000;
11043
11044 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11045
11046 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11047 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11048 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11049
11050 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11051 tout--;
0926d499 11052 usleep_range(1000, 2000);
619c5cb6
VZ
11053 }
11054
11055 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11056 dev_err(&bp->pdev->dev,
11057 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
11058 bnx2x_release_hw_lock(bp,
11059 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
11060 return -EPERM;
11061 }
11062 }
11063
f2e0899f 11064 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 11065 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
11066 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11067 } else
619c5cb6 11068 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 11069
9b341bb1 11070 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 11071 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
11072 if (rc)
11073 return rc;
f2e0899f 11074 }
619c5cb6
VZ
11075
11076 /*
11077 * set base FW non-default (fast path) status block id, this value is
11078 * used to initialize the fw_sb_id saved on the fp/queue structure to
11079 * determine the id used by the FW.
11080 */
11081 if (CHIP_IS_E1x(bp))
11082 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11083 else /*
11084 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11085 * the same queue are indicated on the same IGU SB). So we prefer
11086 * FW and IGU SBs to be the same value.
11087 */
11088 bp->base_fw_ndsb = bp->igu_base_sb;
11089
11090 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11091 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11092 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
11093
11094 /*
11095 * Initialize MF configuration
11096 */
523224a3 11097
fb3bff17
DK
11098 bp->mf_ov = 0;
11099 bp->mf_mode = 0;
3395a033 11100 vn = BP_VN(bp);
0793f83f 11101
f2e0899f 11102 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
11103 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11104 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11105 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11106
f2e0899f
DK
11107 if (SHMEM2_HAS(bp, mf_cfg_addr))
11108 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11109 else
11110 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
11111 offsetof(struct shmem_region, func_mb) +
11112 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
11113 /*
11114 * get mf configuration:
16a5fd92 11115 * 1. Existence of MF configuration
0793f83f
DK
11116 * 2. MAC address must be legal (check only upper bytes)
11117 * for Switch-Independent mode;
11118 * OVLAN must be legal for Switch-Dependent mode
11119 * 3. SF_MODE configures specific MF mode
11120 */
11121 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11122 /* get mf configuration */
11123 val = SHMEM_RD(bp,
11124 dev_info.shared_feature_config.config);
11125 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
11126
11127 switch (val) {
11128 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11129 val = MF_CFG_RD(bp, func_mf_config[func].
11130 mac_upper);
11131 /* check for legal mac (upper bytes)*/
11132 if (val != 0xffff) {
11133 bp->mf_mode = MULTI_FUNCTION_SI;
11134 bp->mf_config[vn] = MF_CFG_RD(bp,
11135 func_mf_config[func].config);
11136 } else
51c1a580 11137 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 11138 break;
a3348722
BW
11139 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11140 if ((!CHIP_IS_E1x(bp)) &&
11141 (MF_CFG_RD(bp, func_mf_config[func].
11142 mac_upper) != 0xffff) &&
11143 (SHMEM2_HAS(bp,
11144 afex_driver_support))) {
11145 bp->mf_mode = MULTI_FUNCTION_AFEX;
11146 bp->mf_config[vn] = MF_CFG_RD(bp,
11147 func_mf_config[func].config);
11148 } else {
11149 BNX2X_DEV_INFO("can not configure afex mode\n");
11150 }
11151 break;
0793f83f
DK
11152 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11153 /* get OV configuration */
11154 val = MF_CFG_RD(bp,
11155 func_mf_config[FUNC_0].e1hov_tag);
11156 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11157
11158 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11159 bp->mf_mode = MULTI_FUNCTION_SD;
11160 bp->mf_config[vn] = MF_CFG_RD(bp,
11161 func_mf_config[func].config);
11162 } else
754a2f52 11163 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f 11164 break;
3786b942
AE
11165 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11166 bp->mf_config[vn] = 0;
11167 break;
0793f83f
DK
11168 default:
11169 /* Unknown configuration: reset mf_config */
11170 bp->mf_config[vn] = 0;
51c1a580 11171 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
11172 }
11173 }
a2fbb9ea 11174
2691d51d 11175 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 11176 IS_MF(bp) ? "multi" : "single");
2691d51d 11177
0793f83f
DK
11178 switch (bp->mf_mode) {
11179 case MULTI_FUNCTION_SD:
11180 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11181 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 11182 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 11183 bp->mf_ov = val;
619c5cb6
VZ
11184 bp->path_has_ovlan = true;
11185
51c1a580
MS
11186 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11187 func, bp->mf_ov, bp->mf_ov);
2691d51d 11188 } else {
619c5cb6 11189 dev_err(&bp->pdev->dev,
51c1a580
MS
11190 "No valid MF OV for func %d, aborting\n",
11191 func);
619c5cb6 11192 return -EPERM;
34f80b04 11193 }
0793f83f 11194 break;
a3348722
BW
11195 case MULTI_FUNCTION_AFEX:
11196 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11197 break;
0793f83f 11198 case MULTI_FUNCTION_SI:
51c1a580
MS
11199 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11200 func);
0793f83f
DK
11201 break;
11202 default:
11203 if (vn) {
619c5cb6 11204 dev_err(&bp->pdev->dev,
51c1a580
MS
11205 "VN %d is in a single function mode, aborting\n",
11206 vn);
619c5cb6 11207 return -EPERM;
2691d51d 11208 }
0793f83f 11209 break;
34f80b04 11210 }
0793f83f 11211
619c5cb6
VZ
11212 /* check if other port on the path needs ovlan:
11213 * Since MF configuration is shared between ports
11214 * Possible mixed modes are only
11215 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11216 */
11217 if (CHIP_MODE_IS_4_PORT(bp) &&
11218 !bp->path_has_ovlan &&
11219 !IS_MF(bp) &&
11220 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11221 u8 other_port = !BP_PORT(bp);
11222 u8 other_func = BP_PATH(bp) + 2*other_port;
11223 val = MF_CFG_RD(bp,
11224 func_mf_config[other_func].e1hov_tag);
11225 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11226 bp->path_has_ovlan = true;
11227 }
34f80b04 11228 }
a2fbb9ea 11229
f2e0899f
DK
11230 /* adjust igu_sb_cnt to MF for E1x */
11231 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
11232 bp->igu_sb_cnt /= E1HVN_MAX;
11233
619c5cb6
VZ
11234 /* port info */
11235 bnx2x_get_port_hwinfo(bp);
f2e0899f 11236
0793f83f
DK
11237 /* Get MAC addresses */
11238 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 11239
2ba45142 11240 bnx2x_get_cnic_info(bp);
2ba45142 11241
34f80b04
EG
11242 return rc;
11243}
11244
0329aba1 11245static void bnx2x_read_fwinfo(struct bnx2x *bp)
34f24c7f
VZ
11246{
11247 int cnt, i, block_end, rodi;
fcdf95cb 11248 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
11249 char str_id_reg[VENDOR_ID_LEN+1];
11250 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
11251 char *vpd_data;
11252 char *vpd_extended_data = NULL;
34f24c7f
VZ
11253 u8 len;
11254
fcdf95cb 11255 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
11256 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11257
11258 if (cnt < BNX2X_VPD_LEN)
11259 goto out_not_found;
11260
fcdf95cb
BW
11261 /* VPD RO tag should be first tag after identifier string, hence
11262 * we should be able to find it in first BNX2X_VPD_LEN chars
11263 */
11264 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
11265 PCI_VPD_LRDT_RO_DATA);
11266 if (i < 0)
11267 goto out_not_found;
11268
34f24c7f 11269 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 11270 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
11271
11272 i += PCI_VPD_LRDT_TAG_SIZE;
11273
fcdf95cb
BW
11274 if (block_end > BNX2X_VPD_LEN) {
11275 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11276 if (vpd_extended_data == NULL)
11277 goto out_not_found;
11278
11279 /* read rest of vpd image into vpd_extended_data */
11280 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11281 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11282 block_end - BNX2X_VPD_LEN,
11283 vpd_extended_data + BNX2X_VPD_LEN);
11284 if (cnt < (block_end - BNX2X_VPD_LEN))
11285 goto out_not_found;
11286 vpd_data = vpd_extended_data;
11287 } else
11288 vpd_data = vpd_start;
11289
11290 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
11291
11292 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11293 PCI_VPD_RO_KEYWORD_MFR_ID);
11294 if (rodi < 0)
11295 goto out_not_found;
11296
11297 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11298
11299 if (len != VENDOR_ID_LEN)
11300 goto out_not_found;
11301
11302 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11303
11304 /* vendor specific info */
11305 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11306 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11307 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11308 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11309
11310 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11311 PCI_VPD_RO_KEYWORD_VENDOR0);
11312 if (rodi >= 0) {
11313 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11314
11315 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11316
11317 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11318 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11319 bp->fw_ver[len] = ' ';
11320 }
11321 }
fcdf95cb 11322 kfree(vpd_extended_data);
34f24c7f
VZ
11323 return;
11324 }
11325out_not_found:
fcdf95cb 11326 kfree(vpd_extended_data);
34f24c7f
VZ
11327 return;
11328}
11329
0329aba1 11330static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
619c5cb6
VZ
11331{
11332 u32 flags = 0;
11333
11334 if (CHIP_REV_IS_FPGA(bp))
11335 SET_FLAGS(flags, MODE_FPGA);
11336 else if (CHIP_REV_IS_EMUL(bp))
11337 SET_FLAGS(flags, MODE_EMUL);
11338 else
11339 SET_FLAGS(flags, MODE_ASIC);
11340
11341 if (CHIP_MODE_IS_4_PORT(bp))
11342 SET_FLAGS(flags, MODE_PORT4);
11343 else
11344 SET_FLAGS(flags, MODE_PORT2);
11345
11346 if (CHIP_IS_E2(bp))
11347 SET_FLAGS(flags, MODE_E2);
11348 else if (CHIP_IS_E3(bp)) {
11349 SET_FLAGS(flags, MODE_E3);
11350 if (CHIP_REV(bp) == CHIP_REV_Ax)
11351 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11352 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11353 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11354 }
11355
11356 if (IS_MF(bp)) {
11357 SET_FLAGS(flags, MODE_MF);
11358 switch (bp->mf_mode) {
11359 case MULTI_FUNCTION_SD:
11360 SET_FLAGS(flags, MODE_MF_SD);
11361 break;
11362 case MULTI_FUNCTION_SI:
11363 SET_FLAGS(flags, MODE_MF_SI);
11364 break;
a3348722
BW
11365 case MULTI_FUNCTION_AFEX:
11366 SET_FLAGS(flags, MODE_MF_AFEX);
11367 break;
619c5cb6
VZ
11368 }
11369 } else
11370 SET_FLAGS(flags, MODE_SF);
11371
11372#if defined(__LITTLE_ENDIAN)
11373 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11374#else /*(__BIG_ENDIAN)*/
11375 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11376#endif
11377 INIT_MODE_FLAGS(bp) = flags;
11378}
11379
0329aba1 11380static int bnx2x_init_bp(struct bnx2x *bp)
34f80b04 11381{
f2e0899f 11382 int func;
34f80b04
EG
11383 int rc;
11384
34f80b04 11385 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11386 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11387 spin_lock_init(&bp->stats_lock);
55c11941 11388
1cf167f2 11389 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11390 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11391 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
1ab4434c
AE
11392 if (IS_PF(bp)) {
11393 rc = bnx2x_get_hwinfo(bp);
11394 if (rc)
11395 return rc;
11396 } else {
e09b74d0 11397 eth_zero_addr(bp->dev->dev_addr);
1ab4434c 11398 }
34f80b04 11399
619c5cb6
VZ
11400 bnx2x_set_modes_bitmap(bp);
11401
11402 rc = bnx2x_alloc_mem_bp(bp);
11403 if (rc)
11404 return rc;
523224a3 11405
34f24c7f 11406 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11407
11408 func = BP_FUNC(bp);
11409
34f80b04 11410 /* need to reset chip if undi was active */
1ab4434c 11411 if (IS_PF(bp) && !BP_NOMCP(bp)) {
452427b0
YM
11412 /* init fw_seq */
11413 bp->fw_seq =
11414 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11415 DRV_MSG_SEQ_NUMBER_MASK;
11416 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11417
11418 bnx2x_prev_unload(bp);
11419 }
11420
34f80b04 11421 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11422 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11423
11424 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11425 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11426
614c76df 11427 bp->disable_tpa = disable_tpa;
a3348722 11428 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11429
7a9b2557 11430 /* Set TPA flags */
614c76df 11431 if (bp->disable_tpa) {
621b4d66 11432 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11433 bp->dev->features &= ~NETIF_F_LRO;
11434 } else {
621b4d66 11435 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11436 bp->dev->features |= NETIF_F_LRO;
11437 }
11438
a18f5128
EG
11439 if (CHIP_IS_E1(bp))
11440 bp->dropless_fc = 0;
11441 else
7964211d 11442 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11443
8d5726c4 11444 bp->mrrs = mrrs;
7a9b2557 11445
a3348722 11446 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1ab4434c
AE
11447 if (IS_VF(bp))
11448 bp->rx_ring_size = MAX_RX_AVAIL;
34f80b04 11449
7d323bfd 11450 /* make sure that the numbers are in the right granularity */
523224a3
DK
11451 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11452 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11453
fc543637 11454 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11455
11456 init_timer(&bp->timer);
11457 bp->timer.expires = jiffies + bp->current_interval;
11458 bp->timer.data = (unsigned long) bp;
11459 bp->timer.function = bnx2x_timer;
11460
0370cf90
BW
11461 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11462 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11463 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11464 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11465 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11466 bnx2x_dcbx_init_params(bp);
11467 } else {
11468 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11469 }
e4901dde 11470
619c5cb6
VZ
11471 if (CHIP_IS_E1x(bp))
11472 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11473 else
11474 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11475
6383c0b3 11476 /* multiple tx priority */
1ab4434c
AE
11477 if (IS_VF(bp))
11478 bp->max_cos = 1;
11479 else if (CHIP_IS_E1x(bp))
6383c0b3 11480 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
1ab4434c 11481 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
6383c0b3 11482 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
1ab4434c 11483 else if (CHIP_IS_E3B0(bp))
6383c0b3 11484 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
1ab4434c
AE
11485 else
11486 BNX2X_ERR("unknown chip %x revision %x\n",
11487 CHIP_NUM(bp), CHIP_REV(bp));
11488 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
6383c0b3 11489
55c11941
MS
11490 /* We need at least one default status block for slow-path events,
11491 * second status block for the L2 queue, and a third status block for
16a5fd92 11492 * CNIC if supported.
55c11941
MS
11493 */
11494 if (CNIC_SUPPORT(bp))
11495 bp->min_msix_vec_cnt = 3;
11496 else
11497 bp->min_msix_vec_cnt = 2;
11498 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11499
34f80b04 11500 return rc;
a2fbb9ea
ET
11501}
11502
de0c62db
DK
11503/****************************************************************************
11504* General service functions
11505****************************************************************************/
a2fbb9ea 11506
619c5cb6
VZ
11507/*
11508 * net_device service functions
11509 */
11510
bb2a0f7a 11511/* called with rtnl_lock */
a2fbb9ea
ET
11512static int bnx2x_open(struct net_device *dev)
11513{
11514 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11515 bool global = false;
11516 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11517 bool other_load_status, load_status;
8395be5e 11518 int rc;
a2fbb9ea 11519
1355b704
MY
11520 bp->stats_init = true;
11521
6eccabb3
EG
11522 netif_carrier_off(dev);
11523
a2fbb9ea
ET
11524 bnx2x_set_power_state(bp, PCI_D0);
11525
ad5afc89 11526 /* If parity had happen during the unload, then attentions
c9ee9206
VZ
11527 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11528 * want the first function loaded on the current engine to
11529 * complete the recovery.
ad5afc89 11530 * Parity recovery is only relevant for PF driver.
c9ee9206 11531 */
ad5afc89
AE
11532 if (IS_PF(bp)) {
11533 other_load_status = bnx2x_get_load_status(bp, other_engine);
11534 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11535 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11536 bnx2x_chk_parity_attn(bp, &global, true)) {
11537 do {
11538 /* If there are attentions and they are in a
11539 * global blocks, set the GLOBAL_RESET bit
11540 * regardless whether it will be this function
11541 * that will complete the recovery or not.
11542 */
11543 if (global)
11544 bnx2x_set_reset_global(bp);
72fd0718 11545
ad5afc89
AE
11546 /* Only the first function on the current
11547 * engine should try to recover in open. In case
11548 * of attentions in global blocks only the first
11549 * in the chip should try to recover.
11550 */
11551 if ((!load_status &&
11552 (!global || !other_load_status)) &&
11553 bnx2x_trylock_leader_lock(bp) &&
11554 !bnx2x_leader_reset(bp)) {
11555 netdev_info(bp->dev,
11556 "Recovered in open\n");
11557 break;
11558 }
72fd0718 11559
ad5afc89
AE
11560 /* recovery has failed... */
11561 bnx2x_set_power_state(bp, PCI_D3hot);
11562 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11563
ad5afc89
AE
11564 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11565 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718 11566
ad5afc89
AE
11567 return -EAGAIN;
11568 } while (0);
11569 }
11570 }
72fd0718
VZ
11571
11572 bp->recovery_state = BNX2X_RECOVERY_DONE;
8395be5e
AE
11573 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11574 if (rc)
11575 return rc;
11576 return bnx2x_open_epilog(bp);
a2fbb9ea
ET
11577}
11578
bb2a0f7a 11579/* called with rtnl_lock */
56ad3152 11580static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11581{
a2fbb9ea
ET
11582 struct bnx2x *bp = netdev_priv(dev);
11583
11584 /* Unload the driver, release IRQs */
5d07d868 11585 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206 11586
a2fbb9ea
ET
11587 return 0;
11588}
11589
1191cb83
ED
11590static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11591 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11592{
619c5cb6
VZ
11593 int mc_count = netdev_mc_count(bp->dev);
11594 struct bnx2x_mcast_list_elem *mc_mac =
11595 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11596 struct netdev_hw_addr *ha;
6e30dd4e 11597
619c5cb6
VZ
11598 if (!mc_mac)
11599 return -ENOMEM;
6e30dd4e 11600
619c5cb6 11601 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11602
619c5cb6
VZ
11603 netdev_for_each_mc_addr(ha, bp->dev) {
11604 mc_mac->mac = bnx2x_mc_addr(ha);
11605 list_add_tail(&mc_mac->link, &p->mcast_list);
11606 mc_mac++;
6e30dd4e 11607 }
619c5cb6
VZ
11608
11609 p->mcast_list_len = mc_count;
11610
11611 return 0;
6e30dd4e
VZ
11612}
11613
1191cb83 11614static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11615 struct bnx2x_mcast_ramrod_params *p)
11616{
11617 struct bnx2x_mcast_list_elem *mc_mac =
11618 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11619 link);
11620
11621 WARN_ON(!mc_mac);
11622 kfree(mc_mac);
11623}
11624
11625/**
11626 * bnx2x_set_uc_list - configure a new unicast MACs list.
11627 *
11628 * @bp: driver handle
6e30dd4e 11629 *
619c5cb6 11630 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11631 */
1191cb83 11632static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11633{
619c5cb6 11634 int rc;
6e30dd4e 11635 struct net_device *dev = bp->dev;
6e30dd4e 11636 struct netdev_hw_addr *ha;
15192a8c 11637 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11638 unsigned long ramrod_flags = 0;
6e30dd4e 11639
619c5cb6
VZ
11640 /* First schedule a cleanup up of old configuration */
11641 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11642 if (rc < 0) {
11643 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11644 return rc;
11645 }
6e30dd4e
VZ
11646
11647 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11648 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11649 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11650 if (rc == -EEXIST) {
11651 DP(BNX2X_MSG_SP,
11652 "Failed to schedule ADD operations: %d\n", rc);
11653 /* do not treat adding same MAC as error */
11654 rc = 0;
11655
11656 } else if (rc < 0) {
11657
619c5cb6
VZ
11658 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11659 rc);
11660 return rc;
6e30dd4e
VZ
11661 }
11662 }
11663
619c5cb6
VZ
11664 /* Execute the pending commands */
11665 __set_bit(RAMROD_CONT, &ramrod_flags);
11666 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11667 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11668}
11669
1191cb83 11670static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11671{
619c5cb6 11672 struct net_device *dev = bp->dev;
3b603066 11673 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11674 int rc = 0;
6e30dd4e 11675
619c5cb6 11676 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11677
619c5cb6
VZ
11678 /* first, clear all configured multicast MACs */
11679 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11680 if (rc < 0) {
51c1a580 11681 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11682 return rc;
11683 }
6e30dd4e 11684
619c5cb6
VZ
11685 /* then, configure a new MACs list */
11686 if (netdev_mc_count(dev)) {
11687 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11688 if (rc) {
51c1a580
MS
11689 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11690 rc);
619c5cb6
VZ
11691 return rc;
11692 }
6e30dd4e 11693
619c5cb6
VZ
11694 /* Now add the new MACs */
11695 rc = bnx2x_config_mcast(bp, &rparam,
11696 BNX2X_MCAST_CMD_ADD);
11697 if (rc < 0)
51c1a580
MS
11698 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11699 rc);
6e30dd4e 11700
619c5cb6
VZ
11701 bnx2x_free_mcast_macs_list(&rparam);
11702 }
6e30dd4e 11703
619c5cb6 11704 return rc;
6e30dd4e
VZ
11705}
11706
619c5cb6 11707/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11708void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11709{
11710 struct bnx2x *bp = netdev_priv(dev);
11711 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11712
11713 if (bp->state != BNX2X_STATE_OPEN) {
11714 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11715 return;
11716 }
11717
619c5cb6 11718 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11719
11720 if (dev->flags & IFF_PROMISC)
11721 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11722 else if ((dev->flags & IFF_ALLMULTI) ||
11723 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11724 CHIP_IS_E1(bp)))
34f80b04 11725 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e 11726 else {
381ac16b
AE
11727 if (IS_PF(bp)) {
11728 /* some multicasts */
11729 if (bnx2x_set_mc_list(bp) < 0)
11730 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11731
381ac16b
AE
11732 if (bnx2x_set_uc_list(bp) < 0)
11733 rx_mode = BNX2X_RX_MODE_PROMISC;
11734 } else {
11735 /* configuring mcast to a vf involves sleeping (when we
11736 * wait for the pf's response). Since this function is
11737 * called from non sleepable context we must schedule
11738 * a work item for this purpose
11739 */
11740 smp_mb__before_clear_bit();
11741 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
11742 &bp->sp_rtnl_state);
11743 smp_mb__after_clear_bit();
11744 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11745 }
34f80b04
EG
11746 }
11747
11748 bp->rx_mode = rx_mode;
614c76df
DK
11749 /* handle ISCSI SD mode */
11750 if (IS_MF_ISCSI_SD(bp))
11751 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11752
11753 /* Schedule the rx_mode command */
11754 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11755 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11756 return;
11757 }
11758
381ac16b
AE
11759 if (IS_PF(bp)) {
11760 bnx2x_set_storm_rx_mode(bp);
11761 } else {
11762 /* configuring rx mode to storms in a vf involves sleeping (when
11763 * we wait for the pf's response). Since this function is
11764 * called from non sleepable context we must schedule
11765 * a work item for this purpose
11766 */
11767 smp_mb__before_clear_bit();
11768 set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
11769 &bp->sp_rtnl_state);
11770 smp_mb__after_clear_bit();
11771 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11772 }
34f80b04
EG
11773}
11774
c18487ee 11775/* called with rtnl_lock */
01cd4528
EG
11776static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11777 int devad, u16 addr)
a2fbb9ea 11778{
01cd4528
EG
11779 struct bnx2x *bp = netdev_priv(netdev);
11780 u16 value;
11781 int rc;
a2fbb9ea 11782
01cd4528
EG
11783 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11784 prtad, devad, addr);
a2fbb9ea 11785
01cd4528
EG
11786 /* The HW expects different devad if CL22 is used */
11787 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11788
01cd4528 11789 bnx2x_acquire_phy_lock(bp);
e10bc84d 11790 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11791 bnx2x_release_phy_lock(bp);
11792 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11793
01cd4528
EG
11794 if (!rc)
11795 rc = value;
11796 return rc;
11797}
a2fbb9ea 11798
01cd4528
EG
11799/* called with rtnl_lock */
11800static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11801 u16 addr, u16 value)
11802{
11803 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11804 int rc;
11805
51c1a580
MS
11806 DP(NETIF_MSG_LINK,
11807 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11808 prtad, devad, addr, value);
01cd4528 11809
01cd4528
EG
11810 /* The HW expects different devad if CL22 is used */
11811 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11812
01cd4528 11813 bnx2x_acquire_phy_lock(bp);
e10bc84d 11814 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11815 bnx2x_release_phy_lock(bp);
11816 return rc;
11817}
c18487ee 11818
01cd4528
EG
11819/* called with rtnl_lock */
11820static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11821{
11822 struct bnx2x *bp = netdev_priv(dev);
11823 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11824
01cd4528
EG
11825 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11826 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11827
01cd4528
EG
11828 if (!netif_running(dev))
11829 return -EAGAIN;
11830
11831 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11832}
11833
257ddbda 11834#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11835static void poll_bnx2x(struct net_device *dev)
11836{
11837 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11838 int i;
a2fbb9ea 11839
14a15d61
MS
11840 for_each_eth_queue(bp, i) {
11841 struct bnx2x_fastpath *fp = &bp->fp[i];
11842 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11843 }
a2fbb9ea
ET
11844}
11845#endif
11846
614c76df
DK
11847static int bnx2x_validate_addr(struct net_device *dev)
11848{
11849 struct bnx2x *bp = netdev_priv(dev);
11850
e09b74d0
AE
11851 /* query the bulletin board for mac address configured by the PF */
11852 if (IS_VF(bp))
11853 bnx2x_sample_bulletin(bp);
11854
51c1a580
MS
11855 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11856 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11857 return -EADDRNOTAVAIL;
51c1a580 11858 }
614c76df
DK
11859 return 0;
11860}
11861
c64213cd
SH
11862static const struct net_device_ops bnx2x_netdev_ops = {
11863 .ndo_open = bnx2x_open,
11864 .ndo_stop = bnx2x_close,
11865 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11866 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11867 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11868 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11869 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11870 .ndo_do_ioctl = bnx2x_ioctl,
11871 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11872 .ndo_fix_features = bnx2x_fix_features,
11873 .ndo_set_features = bnx2x_set_features,
c64213cd 11874 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11875#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11876 .ndo_poll_controller = poll_bnx2x,
11877#endif
6383c0b3 11878 .ndo_setup_tc = bnx2x_setup_tc,
6411280a 11879#ifdef CONFIG_BNX2X_SRIOV
abc5a021 11880 .ndo_set_vf_mac = bnx2x_set_vf_mac,
3ec9f9ca
AE
11881 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
11882 .ndo_get_vf_config = bnx2x_get_vf_config,
6411280a 11883#endif
55c11941 11884#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11885 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11886#endif
c64213cd
SH
11887};
11888
1191cb83 11889static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11890{
11891 struct device *dev = &bp->pdev->dev;
11892
11893 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11894 bp->flags |= USING_DAC_FLAG;
11895 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11896 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11897 return -EIO;
11898 }
11899 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11900 dev_err(dev, "System does not support DMA, aborting\n");
11901 return -EIO;
11902 }
11903
11904 return 0;
11905}
11906
1ab4434c
AE
11907static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
11908 struct net_device *dev, unsigned long board_type)
a2fbb9ea 11909{
a2fbb9ea 11910 int rc;
c22610d0 11911 u32 pci_cfg_dword;
65087cfe
AE
11912 bool chip_is_e1x = (board_type == BCM57710 ||
11913 board_type == BCM57711 ||
11914 board_type == BCM57711E);
a2fbb9ea
ET
11915
11916 SET_NETDEV_DEV(dev, &pdev->dev);
a2fbb9ea 11917
34f80b04
EG
11918 bp->dev = dev;
11919 bp->pdev = pdev;
a2fbb9ea
ET
11920
11921 rc = pci_enable_device(pdev);
11922 if (rc) {
cdaa7cb8
VZ
11923 dev_err(&bp->pdev->dev,
11924 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11925 goto err_out;
11926 }
11927
11928 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11929 dev_err(&bp->pdev->dev,
11930 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11931 rc = -ENODEV;
11932 goto err_out_disable;
11933 }
11934
1ab4434c
AE
11935 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11936 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
a2fbb9ea
ET
11937 rc = -ENODEV;
11938 goto err_out_disable;
11939 }
11940
092a5fc9
YR
11941 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
11942 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
11943 PCICFG_REVESION_ID_ERROR_VAL) {
11944 pr_err("PCI device error, probably due to fan failure, aborting\n");
11945 rc = -ENODEV;
11946 goto err_out_disable;
11947 }
11948
34f80b04
EG
11949 if (atomic_read(&pdev->enable_cnt) == 1) {
11950 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11951 if (rc) {
cdaa7cb8
VZ
11952 dev_err(&bp->pdev->dev,
11953 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11954 goto err_out_disable;
11955 }
a2fbb9ea 11956
34f80b04
EG
11957 pci_set_master(pdev);
11958 pci_save_state(pdev);
11959 }
a2fbb9ea 11960
1ab4434c
AE
11961 if (IS_PF(bp)) {
11962 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11963 if (bp->pm_cap == 0) {
11964 dev_err(&bp->pdev->dev,
11965 "Cannot find power management capability, aborting\n");
11966 rc = -EIO;
11967 goto err_out_release;
11968 }
a2fbb9ea
ET
11969 }
11970
77c98e6a 11971 if (!pci_is_pcie(pdev)) {
51c1a580 11972 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11973 rc = -EIO;
11974 goto err_out_release;
11975 }
11976
619c5cb6
VZ
11977 rc = bnx2x_set_coherency_mask(bp);
11978 if (rc)
a2fbb9ea 11979 goto err_out_release;
a2fbb9ea 11980
34f80b04
EG
11981 dev->mem_start = pci_resource_start(pdev, 0);
11982 dev->base_addr = dev->mem_start;
11983 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11984
11985 dev->irq = pdev->irq;
11986
275f165f 11987 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11988 if (!bp->regview) {
cdaa7cb8
VZ
11989 dev_err(&bp->pdev->dev,
11990 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11991 rc = -ENOMEM;
11992 goto err_out_release;
11993 }
11994
c22610d0
AE
11995 /* In E1/E1H use pci device function given by kernel.
11996 * In E2/E3 read physical function from ME register since these chips
11997 * support Physical Device Assignment where kernel BDF maybe arbitrary
11998 * (depending on hypervisor).
11999 */
2de67439 12000 if (chip_is_e1x) {
c22610d0 12001 bp->pf_num = PCI_FUNC(pdev->devfn);
2de67439
YM
12002 } else {
12003 /* chip is E2/3*/
c22610d0
AE
12004 pci_read_config_dword(bp->pdev,
12005 PCICFG_ME_REGISTER, &pci_cfg_dword);
12006 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
2de67439 12007 ME_REG_ABS_PF_NUM_SHIFT);
c22610d0 12008 }
51c1a580 12009 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 12010
a2fbb9ea
ET
12011 bnx2x_set_power_state(bp, PCI_D0);
12012
34f80b04
EG
12013 /* clean indirect addresses */
12014 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12015 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
12016 /*
12017 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
12018 * is not used by the driver.
12019 */
1ab4434c
AE
12020 if (IS_PF(bp)) {
12021 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12022 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12023 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12024 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
12025
12026 if (chip_is_e1x) {
12027 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12028 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12029 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12030 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12031 }
a5c53dbc 12032
1ab4434c
AE
12033 /* Enable internal target-read (in case we are probed after PF
12034 * FLR). Must be done prior to any BAR read access. Only for
12035 * 57712 and up
12036 */
12037 if (!chip_is_e1x)
12038 REG_WR(bp,
12039 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
a5c53dbc 12040 }
a2fbb9ea 12041
34f80b04 12042 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 12043
c64213cd 12044 dev->netdev_ops = &bnx2x_netdev_ops;
005a07ba 12045 bnx2x_set_ethtool_ops(bp, dev);
5316bc0b 12046
01789349
JP
12047 dev->priv_flags |= IFF_UNICAST_FLT;
12048
66371c44 12049 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
12050 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12051 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
f646968f 12052 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
a848ade4 12053 if (!CHIP_IS_E1x(bp)) {
65bc0cfe 12054 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
a848ade4
DK
12055 dev->hw_enc_features =
12056 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12057 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
65bc0cfe 12058 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
a848ade4 12059 }
66371c44
MM
12060
12061 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12062 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12063
f646968f 12064 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
5316bc0b 12065 if (bp->flags & USING_DAC_FLAG)
66371c44 12066 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 12067
538dd2e3
MB
12068 /* Add Loopback capability to the device */
12069 dev->hw_features |= NETIF_F_LOOPBACK;
12070
98507672 12071#ifdef BCM_DCBNL
785b9b1a
SR
12072 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12073#endif
12074
01cd4528
EG
12075 /* get_port_hwinfo() will set prtad and mmds properly */
12076 bp->mdio.prtad = MDIO_PRTAD_NONE;
12077 bp->mdio.mmds = 0;
12078 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12079 bp->mdio.dev = dev;
12080 bp->mdio.mdio_read = bnx2x_mdio_read;
12081 bp->mdio.mdio_write = bnx2x_mdio_write;
12082
a2fbb9ea
ET
12083 return 0;
12084
a2fbb9ea 12085err_out_release:
34f80b04
EG
12086 if (atomic_read(&pdev->enable_cnt) == 1)
12087 pci_release_regions(pdev);
a2fbb9ea
ET
12088
12089err_out_disable:
12090 pci_disable_device(pdev);
12091 pci_set_drvdata(pdev, NULL);
12092
12093err_out:
12094 return rc;
12095}
12096
ca1ee4b2
DK
12097static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
12098 enum bnx2x_pci_bus_speed *speed)
25047950 12099{
ca1ee4b2 12100 u32 link_speed, val = 0;
25047950 12101
1ab4434c 12102 pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
37f9ce62 12103 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 12104
ca1ee4b2
DK
12105 link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
12106
12107 switch (link_speed) {
12108 case 3:
12109 *speed = BNX2X_PCI_LINK_SPEED_8000;
12110 break;
12111 case 2:
12112 *speed = BNX2X_PCI_LINK_SPEED_5000;
12113 break;
12114 default:
12115 *speed = BNX2X_PCI_LINK_SPEED_2500;
12116 }
25047950 12117}
37f9ce62 12118
6891dd25 12119static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 12120{
37f9ce62 12121 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
12122 struct bnx2x_fw_file_hdr *fw_hdr;
12123 struct bnx2x_fw_file_section *sections;
94a78b79 12124 u32 offset, len, num_ops;
86564c3f 12125 __be16 *ops_offsets;
94a78b79 12126 int i;
37f9ce62 12127 const u8 *fw_ver;
94a78b79 12128
51c1a580
MS
12129 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12130 BNX2X_ERR("Wrong FW size\n");
94a78b79 12131 return -EINVAL;
51c1a580 12132 }
94a78b79
VZ
12133
12134 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12135 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12136
12137 /* Make sure none of the offsets and sizes make us read beyond
12138 * the end of the firmware data */
12139 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12140 offset = be32_to_cpu(sections[i].offset);
12141 len = be32_to_cpu(sections[i].len);
12142 if (offset + len > firmware->size) {
51c1a580 12143 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
12144 return -EINVAL;
12145 }
12146 }
12147
12148 /* Likewise for the init_ops offsets */
12149 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
86564c3f 12150 ops_offsets = (__force __be16 *)(firmware->data + offset);
94a78b79
VZ
12151 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12152
12153 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12154 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 12155 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
12156 return -EINVAL;
12157 }
12158 }
12159
12160 /* Check FW version */
12161 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12162 fw_ver = firmware->data + offset;
12163 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12164 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12165 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12166 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
12167 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12168 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12169 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
12170 BCM_5710_FW_MINOR_VERSION,
12171 BCM_5710_FW_REVISION_VERSION,
12172 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 12173 return -EINVAL;
94a78b79
VZ
12174 }
12175
12176 return 0;
12177}
12178
1191cb83 12179static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12180{
ab6ad5a4
EG
12181 const __be32 *source = (const __be32 *)_source;
12182 u32 *target = (u32 *)_target;
94a78b79 12183 u32 i;
94a78b79
VZ
12184
12185 for (i = 0; i < n/4; i++)
12186 target[i] = be32_to_cpu(source[i]);
12187}
12188
12189/*
12190 Ops array is stored in the following format:
12191 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12192 */
1191cb83 12193static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 12194{
ab6ad5a4
EG
12195 const __be32 *source = (const __be32 *)_source;
12196 struct raw_op *target = (struct raw_op *)_target;
94a78b79 12197 u32 i, j, tmp;
94a78b79 12198
ab6ad5a4 12199 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
12200 tmp = be32_to_cpu(source[j]);
12201 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
12202 target[i].offset = tmp & 0xffffff;
12203 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
12204 }
12205}
ab6ad5a4 12206
1aa8b471 12207/* IRO array is stored in the following format:
523224a3
DK
12208 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12209 */
1191cb83 12210static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
12211{
12212 const __be32 *source = (const __be32 *)_source;
12213 struct iro *target = (struct iro *)_target;
12214 u32 i, j, tmp;
12215
12216 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12217 target[i].base = be32_to_cpu(source[j]);
12218 j++;
12219 tmp = be32_to_cpu(source[j]);
12220 target[i].m1 = (tmp >> 16) & 0xffff;
12221 target[i].m2 = tmp & 0xffff;
12222 j++;
12223 tmp = be32_to_cpu(source[j]);
12224 target[i].m3 = (tmp >> 16) & 0xffff;
12225 target[i].size = tmp & 0xffff;
12226 j++;
12227 }
12228}
12229
1191cb83 12230static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12231{
ab6ad5a4
EG
12232 const __be16 *source = (const __be16 *)_source;
12233 u16 *target = (u16 *)_target;
94a78b79 12234 u32 i;
94a78b79
VZ
12235
12236 for (i = 0; i < n/2; i++)
12237 target[i] = be16_to_cpu(source[i]);
12238}
12239
7995c64e
JP
12240#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12241do { \
12242 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12243 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 12244 if (!bp->arr) \
7995c64e 12245 goto lbl; \
7995c64e
JP
12246 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12247 (u8 *)bp->arr, len); \
12248} while (0)
94a78b79 12249
3b603066 12250static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 12251{
c0ea452e 12252 const char *fw_file_name;
94a78b79 12253 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 12254 int rc;
94a78b79 12255
c0ea452e
MS
12256 if (bp->firmware)
12257 return 0;
94a78b79 12258
c0ea452e
MS
12259 if (CHIP_IS_E1(bp))
12260 fw_file_name = FW_FILE_NAME_E1;
12261 else if (CHIP_IS_E1H(bp))
12262 fw_file_name = FW_FILE_NAME_E1H;
12263 else if (!CHIP_IS_E1x(bp))
12264 fw_file_name = FW_FILE_NAME_E2;
12265 else {
12266 BNX2X_ERR("Unsupported chip revision\n");
12267 return -EINVAL;
12268 }
12269 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 12270
c0ea452e
MS
12271 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12272 if (rc) {
12273 BNX2X_ERR("Can't load firmware file %s\n",
12274 fw_file_name);
12275 goto request_firmware_exit;
12276 }
eb2afd4a 12277
c0ea452e
MS
12278 rc = bnx2x_check_firmware(bp);
12279 if (rc) {
12280 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12281 goto request_firmware_exit;
94a78b79
VZ
12282 }
12283
12284 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12285
12286 /* Initialize the pointers to the init arrays */
12287 /* Blob */
12288 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12289
12290 /* Opcodes */
12291 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12292
12293 /* Offsets */
ab6ad5a4
EG
12294 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12295 be16_to_cpu_n);
94a78b79
VZ
12296
12297 /* STORMs firmware */
573f2035
EG
12298 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12299 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12300 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12301 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12302 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12303 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12304 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12305 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12306 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12307 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12308 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12309 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12310 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12311 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12312 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12313 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
12314 /* IRO */
12315 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
12316
12317 return 0;
ab6ad5a4 12318
523224a3
DK
12319iro_alloc_err:
12320 kfree(bp->init_ops_offsets);
94a78b79
VZ
12321init_offsets_alloc_err:
12322 kfree(bp->init_ops);
12323init_ops_alloc_err:
12324 kfree(bp->init_data);
12325request_firmware_exit:
12326 release_firmware(bp->firmware);
127d0a19 12327 bp->firmware = NULL;
94a78b79
VZ
12328
12329 return rc;
12330}
12331
619c5cb6
VZ
12332static void bnx2x_release_firmware(struct bnx2x *bp)
12333{
12334 kfree(bp->init_ops_offsets);
12335 kfree(bp->init_ops);
12336 kfree(bp->init_data);
12337 release_firmware(bp->firmware);
eb2afd4a 12338 bp->firmware = NULL;
619c5cb6
VZ
12339}
12340
619c5cb6
VZ
12341static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12342 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12343 .init_hw_cmn = bnx2x_init_hw_common,
12344 .init_hw_port = bnx2x_init_hw_port,
12345 .init_hw_func = bnx2x_init_hw_func,
12346
12347 .reset_hw_cmn = bnx2x_reset_common,
12348 .reset_hw_port = bnx2x_reset_port,
12349 .reset_hw_func = bnx2x_reset_func,
12350
12351 .gunzip_init = bnx2x_gunzip_init,
12352 .gunzip_end = bnx2x_gunzip_end,
12353
12354 .init_fw = bnx2x_init_firmware,
12355 .release_fw = bnx2x_release_firmware,
12356};
12357
12358void bnx2x__init_func_obj(struct bnx2x *bp)
12359{
12360 /* Prepare DMAE related driver resources */
12361 bnx2x_setup_dmae(bp);
12362
12363 bnx2x_init_func_obj(bp, &bp->func_obj,
12364 bnx2x_sp(bp, func_rdata),
12365 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
12366 bnx2x_sp(bp, func_afex_rdata),
12367 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
12368 &bnx2x_func_sp_drv);
12369}
12370
12371/* must be called after sriov-enable */
1191cb83 12372static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 12373{
37ae41a9 12374 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 12375
290ca2bb
AE
12376 if (IS_SRIOV(bp))
12377 cid_count += BNX2X_VF_CIDS;
12378
55c11941
MS
12379 if (CNIC_SUPPORT(bp))
12380 cid_count += CNIC_CID_MAX;
290ca2bb 12381
523224a3
DK
12382 return roundup(cid_count, QM_CID_ROUND);
12383}
f85582f8 12384
619c5cb6 12385/**
6383c0b3 12386 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
12387 *
12388 * @dev: pci device
12389 *
12390 */
55c11941 12391static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
1ab4434c 12392 int cnic_cnt, bool is_vf)
619c5cb6 12393{
1ab4434c
AE
12394 int pos, index;
12395 u16 control = 0;
619c5cb6
VZ
12396
12397 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
12398
12399 /*
12400 * If MSI-X is not supported - return number of SBs needed to support
12401 * one fast path queue: one FP queue + SB for CNIC
12402 */
1ab4434c
AE
12403 if (!pos) {
12404 dev_info(&pdev->dev, "no msix capability found\n");
55c11941 12405 return 1 + cnic_cnt;
1ab4434c
AE
12406 }
12407 dev_info(&pdev->dev, "msix capability found\n");
619c5cb6 12408
6383c0b3
AE
12409 /*
12410 * The value in the PCI configuration space is the index of the last
12411 * entry, namely one less than the actual size of the table, which is
12412 * exactly what we want to return from this function: number of all SBs
12413 * without the default SB.
1ab4434c 12414 * For VFs there is no default SB, then we return (index+1).
6383c0b3 12415 */
619c5cb6 12416 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
619c5cb6 12417
1ab4434c 12418 index = control & PCI_MSIX_FLAGS_QSIZE;
4bd9b0ff 12419
1ab4434c
AE
12420 return is_vf ? index + 1 : index;
12421}
523224a3 12422
1ab4434c
AE
12423static int set_max_cos_est(int chip_id)
12424{
12425 switch (chip_id) {
f2e0899f
DK
12426 case BCM57710:
12427 case BCM57711:
12428 case BCM57711E:
1ab4434c 12429 return BNX2X_MULTI_TX_COS_E1X;
f2e0899f 12430 case BCM57712:
619c5cb6 12431 case BCM57712_MF:
1ab4434c
AE
12432 case BCM57712_VF:
12433 return BNX2X_MULTI_TX_COS_E2_E3A0;
619c5cb6
VZ
12434 case BCM57800:
12435 case BCM57800_MF:
1ab4434c 12436 case BCM57800_VF:
619c5cb6
VZ
12437 case BCM57810:
12438 case BCM57810_MF:
c3def943
YM
12439 case BCM57840_4_10:
12440 case BCM57840_2_20:
1ab4434c 12441 case BCM57840_O:
c3def943 12442 case BCM57840_MFO:
1ab4434c 12443 case BCM57810_VF:
619c5cb6 12444 case BCM57840_MF:
1ab4434c 12445 case BCM57840_VF:
7e8e02df
BW
12446 case BCM57811:
12447 case BCM57811_MF:
1ab4434c
AE
12448 case BCM57811_VF:
12449 return BNX2X_MULTI_TX_COS_E3B0;
12450 return 1;
f2e0899f 12451 default:
1ab4434c 12452 pr_err("Unknown board_type (%d), aborting\n", chip_id);
870634b0 12453 return -ENODEV;
f2e0899f 12454 }
1ab4434c 12455}
f2e0899f 12456
1ab4434c
AE
12457static int set_is_vf(int chip_id)
12458{
12459 switch (chip_id) {
12460 case BCM57712_VF:
12461 case BCM57800_VF:
12462 case BCM57810_VF:
12463 case BCM57840_VF:
12464 case BCM57811_VF:
12465 return true;
12466 default:
12467 return false;
12468 }
12469}
6383c0b3 12470
1ab4434c
AE
12471struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12472
12473static int bnx2x_init_one(struct pci_dev *pdev,
12474 const struct pci_device_id *ent)
12475{
12476 struct net_device *dev = NULL;
12477 struct bnx2x *bp;
ca1ee4b2
DK
12478 int pcie_width;
12479 enum bnx2x_pci_bus_speed pcie_speed;
1ab4434c
AE
12480 int rc, max_non_def_sbs;
12481 int rx_count, tx_count, rss_count, doorbell_size;
12482 int max_cos_est;
12483 bool is_vf;
12484 int cnic_cnt;
12485
12486 /* An estimated maximum supported CoS number according to the chip
12487 * version.
12488 * We will try to roughly estimate the maximum number of CoSes this chip
12489 * may support in order to minimize the memory allocated for Tx
12490 * netdev_queue's. This number will be accurately calculated during the
12491 * initialization of bp->max_cos based on the chip versions AND chip
12492 * revision in the bnx2x_init_bp().
12493 */
12494 max_cos_est = set_max_cos_est(ent->driver_data);
12495 if (max_cos_est < 0)
12496 return max_cos_est;
12497 is_vf = set_is_vf(ent->driver_data);
12498 cnic_cnt = is_vf ? 0 : 1;
12499
12500 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
6383c0b3
AE
12501
12502 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
1ab4434c
AE
12503 rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
12504
12505 if (rss_count < 1)
12506 return -EINVAL;
6383c0b3
AE
12507
12508 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12509 rx_count = rss_count + cnic_cnt;
6383c0b3 12510
1ab4434c 12511 /* Maximum number of netdev Tx queues:
37ae41a9 12512 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12513 */
55c11941 12514 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12515
a2fbb9ea 12516 /* dev zeroed in init_etherdev */
6383c0b3 12517 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12518 if (!dev)
a2fbb9ea
ET
12519 return -ENOMEM;
12520
a2fbb9ea 12521 bp = netdev_priv(dev);
a2fbb9ea 12522
1ab4434c
AE
12523 bp->flags = 0;
12524 if (is_vf)
12525 bp->flags |= IS_VF_FLAG;
12526
6383c0b3 12527 bp->igu_sb_cnt = max_non_def_sbs;
1ab4434c 12528 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
6383c0b3 12529 bp->msg_enable = debug;
55c11941 12530 bp->cnic_support = cnic_cnt;
4bd9b0ff 12531 bp->cnic_probe = bnx2x_cnic_probe;
55c11941 12532
6383c0b3 12533 pci_set_drvdata(pdev, dev);
523224a3 12534
1ab4434c 12535 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
a2fbb9ea
ET
12536 if (rc < 0) {
12537 free_netdev(dev);
12538 return rc;
12539 }
12540
1ab4434c
AE
12541 BNX2X_DEV_INFO("This is a %s function\n",
12542 IS_PF(bp) ? "physical" : "virtual");
55c11941 12543 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
1ab4434c 12544 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
60aa0509 12545 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
2de67439 12546 tx_count, rx_count);
60aa0509 12547
34f80b04 12548 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12549 if (rc)
12550 goto init_one_exit;
12551
1ab4434c
AE
12552 /* Map doorbells here as we need the real value of bp->max_cos which
12553 * is initialized in bnx2x_init_bp() to determine the number of
12554 * l2 connections.
6383c0b3 12555 */
1ab4434c 12556 if (IS_VF(bp)) {
1d6f3cd8 12557 bp->doorbells = bnx2x_vf_doorbells(bp);
6411280a
AE
12558 rc = bnx2x_vf_pci_alloc(bp);
12559 if (rc)
12560 goto init_one_exit;
1ab4434c
AE
12561 } else {
12562 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12563 if (doorbell_size > pci_resource_len(pdev, 2)) {
12564 dev_err(&bp->pdev->dev,
12565 "Cannot map doorbells, bar size too small, aborting\n");
12566 rc = -ENOMEM;
12567 goto init_one_exit;
12568 }
12569 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12570 doorbell_size);
37ae41a9 12571 }
6383c0b3
AE
12572 if (!bp->doorbells) {
12573 dev_err(&bp->pdev->dev,
12574 "Cannot map doorbell space, aborting\n");
12575 rc = -ENOMEM;
12576 goto init_one_exit;
12577 }
12578
be1f1ffa
AE
12579 if (IS_VF(bp)) {
12580 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12581 if (rc)
12582 goto init_one_exit;
12583 }
12584
3c76feff
AE
12585 /* Enable SRIOV if capability found in configuration space */
12586 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
290ca2bb
AE
12587 if (rc)
12588 goto init_one_exit;
12589
523224a3 12590 /* calc qm_cid_count */
6383c0b3 12591 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
1ab4434c 12592 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
523224a3 12593
55c11941 12594 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12595 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12596 bp->flags |= NO_FCOE_FLAG;
12597
0e8d2ec5
MS
12598 /* Set bp->num_queues for MSI-X mode*/
12599 bnx2x_set_num_queues(bp);
12600
25985edc 12601 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12602 * needed.
d6214d7a 12603 */
1ab4434c
AE
12604 rc = bnx2x_set_int_mode(bp);
12605 if (rc) {
12606 dev_err(&pdev->dev, "Cannot set interrupts\n");
12607 goto init_one_exit;
12608 }
04c46736 12609 BNX2X_DEV_INFO("set interrupts successfully\n");
d6214d7a 12610
1ab4434c 12611 /* register the net device */
b340007f
VZ
12612 rc = register_netdev(dev);
12613 if (rc) {
12614 dev_err(&pdev->dev, "Cannot register net device\n");
12615 goto init_one_exit;
12616 }
1ab4434c 12617 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
b340007f 12618
ec6ba945
VZ
12619 if (!NO_FCOE(bp)) {
12620 /* Add storage MAC address */
12621 rtnl_lock();
12622 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12623 rtnl_unlock();
12624 }
ec6ba945 12625
37f9ce62 12626 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
1ab4434c
AE
12627 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12628 pcie_width, pcie_speed);
d6214d7a 12629
ca1ee4b2
DK
12630 BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
12631 board_info[ent->driver_data].name,
12632 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12633 pcie_width,
12634 pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
12635 pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
12636 pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
12637 "Unknown",
12638 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12639
a2fbb9ea 12640 return 0;
34f80b04
EG
12641
12642init_one_exit:
12643 if (bp->regview)
12644 iounmap(bp->regview);
12645
1ab4434c 12646 if (IS_PF(bp) && bp->doorbells)
34f80b04
EG
12647 iounmap(bp->doorbells);
12648
12649 free_netdev(dev);
12650
12651 if (atomic_read(&pdev->enable_cnt) == 1)
12652 pci_release_regions(pdev);
12653
12654 pci_disable_device(pdev);
12655 pci_set_drvdata(pdev, NULL);
12656
12657 return rc;
a2fbb9ea
ET
12658}
12659
b030ed2f
YM
12660static void __bnx2x_remove(struct pci_dev *pdev,
12661 struct net_device *dev,
12662 struct bnx2x *bp,
12663 bool remove_netdev)
a2fbb9ea 12664{
ec6ba945
VZ
12665 /* Delete storage MAC address */
12666 if (!NO_FCOE(bp)) {
12667 rtnl_lock();
12668 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12669 rtnl_unlock();
12670 }
ec6ba945 12671
98507672
SR
12672#ifdef BCM_DCBNL
12673 /* Delete app tlvs from dcbnl */
12674 bnx2x_dcbnl_update_applist(bp, true);
12675#endif
12676
b030ed2f
YM
12677 /* Close the interface - either directly or implicitly */
12678 if (remove_netdev) {
12679 unregister_netdev(dev);
12680 } else {
12681 rtnl_lock();
12682 if (netif_running(dev))
12683 bnx2x_close(dev);
12684 rtnl_unlock();
12685 }
a2fbb9ea 12686
084d6cbb 12687 /* Power on: we can't let PCI layer write to us while we are in D3 */
1ab4434c
AE
12688 if (IS_PF(bp))
12689 bnx2x_set_power_state(bp, PCI_D0);
084d6cbb 12690
d6214d7a
DK
12691 /* Disable MSI/MSI-X */
12692 bnx2x_disable_msi(bp);
f85582f8 12693
084d6cbb 12694 /* Power off */
1ab4434c
AE
12695 if (IS_PF(bp))
12696 bnx2x_set_power_state(bp, PCI_D3hot);
084d6cbb 12697
72fd0718 12698 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12699 cancel_delayed_work_sync(&bp->sp_rtnl_task);
290ca2bb
AE
12700
12701 bnx2x_iov_remove_one(bp);
12702
4513f925
AE
12703 /* send message via vfpf channel to release the resources of this vf */
12704 if (IS_VF(bp))
12705 bnx2x_vfpf_release(bp);
72fd0718 12706
b030ed2f
YM
12707 /* Assumes no further PCIe PM changes will occur */
12708 if (system_state == SYSTEM_POWER_OFF) {
12709 pci_wake_from_d3(pdev, bp->wol);
12710 pci_set_power_state(pdev, PCI_D3hot);
12711 }
12712
a2fbb9ea
ET
12713 if (bp->regview)
12714 iounmap(bp->regview);
12715
1ab4434c
AE
12716 /* for vf doorbells are part of the regview and were unmapped along with
12717 * it. FW is only loaded by PF.
12718 */
12719 if (IS_PF(bp)) {
12720 if (bp->doorbells)
12721 iounmap(bp->doorbells);
eb2afd4a 12722
1ab4434c
AE
12723 bnx2x_release_firmware(bp);
12724 }
523224a3
DK
12725 bnx2x_free_mem_bp(bp);
12726
b030ed2f
YM
12727 if (remove_netdev)
12728 free_netdev(dev);
34f80b04
EG
12729
12730 if (atomic_read(&pdev->enable_cnt) == 1)
12731 pci_release_regions(pdev);
12732
a2fbb9ea
ET
12733 pci_disable_device(pdev);
12734 pci_set_drvdata(pdev, NULL);
12735}
12736
b030ed2f
YM
12737static void bnx2x_remove_one(struct pci_dev *pdev)
12738{
12739 struct net_device *dev = pci_get_drvdata(pdev);
12740 struct bnx2x *bp;
12741
12742 if (!dev) {
12743 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
12744 return;
12745 }
12746 bp = netdev_priv(dev);
12747
12748 __bnx2x_remove(pdev, dev, bp, true);
12749}
12750
f8ef6e44
YG
12751static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12752{
7fa6f340 12753 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
f8ef6e44
YG
12754
12755 bp->rx_mode = BNX2X_RX_MODE_NONE;
12756
55c11941
MS
12757 if (CNIC_LOADED(bp))
12758 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12759
619c5cb6
VZ
12760 /* Stop Tx */
12761 bnx2x_tx_disable(bp);
26614ba5
MS
12762 /* Delete all NAPI objects */
12763 bnx2x_del_all_napi(bp);
55c11941
MS
12764 if (CNIC_LOADED(bp))
12765 bnx2x_del_all_napi_cnic(bp);
7fa6f340 12766 netdev_reset_tc(bp->dev);
f8ef6e44
YG
12767
12768 del_timer_sync(&bp->timer);
7fa6f340
YM
12769 cancel_delayed_work(&bp->sp_task);
12770 cancel_delayed_work(&bp->period_task);
619c5cb6 12771
7fa6f340
YM
12772 spin_lock_bh(&bp->stats_lock);
12773 bp->stats_state = STATS_STATE_DISABLED;
12774 spin_unlock_bh(&bp->stats_lock);
f8ef6e44 12775
7fa6f340 12776 bnx2x_save_statistics(bp);
f8ef6e44 12777
619c5cb6
VZ
12778 netif_carrier_off(bp->dev);
12779
f8ef6e44
YG
12780 return 0;
12781}
12782
493adb1f
WX
12783/**
12784 * bnx2x_io_error_detected - called when PCI error is detected
12785 * @pdev: Pointer to PCI device
12786 * @state: The current pci connection state
12787 *
12788 * This function is called after a PCI bus error affecting
12789 * this device has been detected.
12790 */
12791static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12792 pci_channel_state_t state)
12793{
12794 struct net_device *dev = pci_get_drvdata(pdev);
12795 struct bnx2x *bp = netdev_priv(dev);
12796
12797 rtnl_lock();
12798
7fa6f340
YM
12799 BNX2X_ERR("IO error detected\n");
12800
493adb1f
WX
12801 netif_device_detach(dev);
12802
07ce50e4
DN
12803 if (state == pci_channel_io_perm_failure) {
12804 rtnl_unlock();
12805 return PCI_ERS_RESULT_DISCONNECT;
12806 }
12807
493adb1f 12808 if (netif_running(dev))
f8ef6e44 12809 bnx2x_eeh_nic_unload(bp);
493adb1f 12810
7fa6f340
YM
12811 bnx2x_prev_path_mark_eeh(bp);
12812
493adb1f
WX
12813 pci_disable_device(pdev);
12814
12815 rtnl_unlock();
12816
12817 /* Request a slot reset */
12818 return PCI_ERS_RESULT_NEED_RESET;
12819}
12820
12821/**
12822 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12823 * @pdev: Pointer to PCI device
12824 *
12825 * Restart the card from scratch, as if from a cold-boot.
12826 */
12827static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12828{
12829 struct net_device *dev = pci_get_drvdata(pdev);
12830 struct bnx2x *bp = netdev_priv(dev);
7fa6f340 12831 int i;
493adb1f
WX
12832
12833 rtnl_lock();
7fa6f340 12834 BNX2X_ERR("IO slot reset initializing...\n");
493adb1f
WX
12835 if (pci_enable_device(pdev)) {
12836 dev_err(&pdev->dev,
12837 "Cannot re-enable PCI device after reset\n");
12838 rtnl_unlock();
12839 return PCI_ERS_RESULT_DISCONNECT;
12840 }
12841
12842 pci_set_master(pdev);
12843 pci_restore_state(pdev);
70632d0a 12844 pci_save_state(pdev);
493adb1f
WX
12845
12846 if (netif_running(dev))
12847 bnx2x_set_power_state(bp, PCI_D0);
12848
7fa6f340
YM
12849 if (netif_running(dev)) {
12850 BNX2X_ERR("IO slot reset --> driver unload\n");
e68072ef
YM
12851
12852 /* MCP should have been reset; Need to wait for validity */
12853 bnx2x_init_shmem(bp);
12854
7fa6f340
YM
12855 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
12856 u32 v;
12857
12858 v = SHMEM2_RD(bp,
12859 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
12860 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
12861 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
12862 }
12863 bnx2x_drain_tx_queues(bp);
12864 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
12865 bnx2x_netif_stop(bp, 1);
12866 bnx2x_free_irq(bp);
12867
12868 /* Report UNLOAD_DONE to MCP */
12869 bnx2x_send_unload_done(bp, true);
12870
12871 bp->sp_state = 0;
12872 bp->port.pmf = 0;
12873
12874 bnx2x_prev_unload(bp);
12875
16a5fd92 12876 /* We should have reseted the engine, so It's fair to
7fa6f340
YM
12877 * assume the FW will no longer write to the bnx2x driver.
12878 */
12879 bnx2x_squeeze_objects(bp);
12880 bnx2x_free_skbs(bp);
12881 for_each_rx_queue(bp, i)
12882 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
12883 bnx2x_free_fp_mem(bp);
12884 bnx2x_free_mem(bp);
12885
12886 bp->state = BNX2X_STATE_CLOSED;
12887 }
12888
493adb1f
WX
12889 rtnl_unlock();
12890
12891 return PCI_ERS_RESULT_RECOVERED;
12892}
12893
12894/**
12895 * bnx2x_io_resume - called when traffic can start flowing again
12896 * @pdev: Pointer to PCI device
12897 *
12898 * This callback is called when the error recovery driver tells us that
12899 * its OK to resume normal operation.
12900 */
12901static void bnx2x_io_resume(struct pci_dev *pdev)
12902{
12903 struct net_device *dev = pci_get_drvdata(pdev);
12904 struct bnx2x *bp = netdev_priv(dev);
12905
72fd0718 12906 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12907 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12908 return;
12909 }
12910
493adb1f
WX
12911 rtnl_lock();
12912
7fa6f340
YM
12913 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
12914 DRV_MSG_SEQ_NUMBER_MASK;
12915
493adb1f 12916 if (netif_running(dev))
f8ef6e44 12917 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12918
12919 netif_device_attach(dev);
12920
12921 rtnl_unlock();
12922}
12923
3646f0e5 12924static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12925 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12926 .slot_reset = bnx2x_io_slot_reset,
12927 .resume = bnx2x_io_resume,
493adb1f
WX
12928};
12929
b030ed2f
YM
12930static void bnx2x_shutdown(struct pci_dev *pdev)
12931{
12932 struct net_device *dev = pci_get_drvdata(pdev);
12933 struct bnx2x *bp;
12934
12935 if (!dev)
12936 return;
12937
12938 bp = netdev_priv(dev);
12939 if (!bp)
12940 return;
12941
12942 rtnl_lock();
12943 netif_device_detach(dev);
12944 rtnl_unlock();
12945
12946 /* Don't remove the netdevice, as there are scenarios which will cause
12947 * the kernel to hang, e.g., when trying to remove bnx2i while the
12948 * rootfs is mounted from SAN.
12949 */
12950 __bnx2x_remove(pdev, dev, bp, false);
12951}
12952
a2fbb9ea 12953static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12954 .name = DRV_MODULE_NAME,
12955 .id_table = bnx2x_pci_tbl,
12956 .probe = bnx2x_init_one,
0329aba1 12957 .remove = bnx2x_remove_one,
493adb1f
WX
12958 .suspend = bnx2x_suspend,
12959 .resume = bnx2x_resume,
12960 .err_handler = &bnx2x_err_handler,
3c76feff
AE
12961#ifdef CONFIG_BNX2X_SRIOV
12962 .sriov_configure = bnx2x_sriov_configure,
12963#endif
b030ed2f 12964 .shutdown = bnx2x_shutdown,
a2fbb9ea
ET
12965};
12966
12967static int __init bnx2x_init(void)
12968{
dd21ca6d
SG
12969 int ret;
12970
7995c64e 12971 pr_info("%s", version);
938cf541 12972
1cf167f2
EG
12973 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12974 if (bnx2x_wq == NULL) {
7995c64e 12975 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12976 return -ENOMEM;
12977 }
12978
dd21ca6d
SG
12979 ret = pci_register_driver(&bnx2x_pci_driver);
12980 if (ret) {
7995c64e 12981 pr_err("Cannot register driver\n");
dd21ca6d
SG
12982 destroy_workqueue(bnx2x_wq);
12983 }
12984 return ret;
a2fbb9ea
ET
12985}
12986
12987static void __exit bnx2x_cleanup(void)
12988{
452427b0 12989 struct list_head *pos, *q;
d76a6111 12990
a2fbb9ea 12991 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12992
12993 destroy_workqueue(bnx2x_wq);
452427b0 12994
16a5fd92 12995 /* Free globally allocated resources */
452427b0
YM
12996 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12997 struct bnx2x_prev_path_list *tmp =
12998 list_entry(pos, struct bnx2x_prev_path_list, list);
12999 list_del(pos);
13000 kfree(tmp);
13001 }
a2fbb9ea
ET
13002}
13003
3deb8167
YR
13004void bnx2x_notify_link_changed(struct bnx2x *bp)
13005{
13006 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13007}
13008
a2fbb9ea
ET
13009module_init(bnx2x_init);
13010module_exit(bnx2x_cleanup);
13011
619c5cb6
VZ
13012/**
13013 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13014 *
13015 * @bp: driver handle
13016 * @set: set or clear the CAM entry
13017 *
16a5fd92 13018 * This function will wait until the ramrod completion returns.
619c5cb6
VZ
13019 * Return 0 if success, -ENODEV if ramrod doesn't return.
13020 */
1191cb83 13021static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
13022{
13023 unsigned long ramrod_flags = 0;
13024
13025 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13026 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13027 &bp->iscsi_l2_mac_obj, true,
13028 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13029}
993ac7b5
MC
13030
13031/* count denotes the number of new completions we have seen */
13032static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13033{
13034 struct eth_spe *spe;
a052997e 13035 int cxt_index, cxt_offset;
993ac7b5
MC
13036
13037#ifdef BNX2X_STOP_ON_ERROR
13038 if (unlikely(bp->panic))
13039 return;
13040#endif
13041
13042 spin_lock_bh(&bp->spq_lock);
c2bff63f 13043 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
13044 bp->cnic_spq_pending -= count;
13045
c2bff63f
DK
13046 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13047 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13048 & SPE_HDR_CONN_TYPE) >>
13049 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
13050 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13051 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
13052
13053 /* Set validation for iSCSI L2 client before sending SETUP
13054 * ramrod
13055 */
13056 if (type == ETH_CONNECTION_TYPE) {
a052997e 13057 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 13058 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 13059 ILT_PAGE_CIDS;
37ae41a9 13060 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
13061 (cxt_index * ILT_PAGE_CIDS);
13062 bnx2x_set_ctx_validation(bp,
13063 &bp->context[cxt_index].
13064 vcxt[cxt_offset].eth,
37ae41a9 13065 BNX2X_ISCSI_ETH_CID(bp));
a052997e 13066 }
c2bff63f
DK
13067 }
13068
619c5cb6
VZ
13069 /*
13070 * There may be not more than 8 L2, not more than 8 L5 SPEs
13071 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
13072 * COMMON ramrods is not more than the EQ and SPQ can
13073 * accommodate.
c2bff63f 13074 */
6e30dd4e
VZ
13075 if (type == ETH_CONNECTION_TYPE) {
13076 if (!atomic_read(&bp->cq_spq_left))
13077 break;
13078 else
13079 atomic_dec(&bp->cq_spq_left);
13080 } else if (type == NONE_CONNECTION_TYPE) {
13081 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
13082 break;
13083 else
6e30dd4e 13084 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
13085 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13086 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
13087 if (bp->cnic_spq_pending >=
13088 bp->cnic_eth_dev.max_kwqe_pending)
13089 break;
13090 else
13091 bp->cnic_spq_pending++;
13092 } else {
13093 BNX2X_ERR("Unknown SPE type: %d\n", type);
13094 bnx2x_panic();
993ac7b5 13095 break;
c2bff63f 13096 }
993ac7b5
MC
13097
13098 spe = bnx2x_sp_get_next(bp);
13099 *spe = *bp->cnic_kwq_cons;
13100
51c1a580 13101 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
13102 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13103
13104 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13105 bp->cnic_kwq_cons = bp->cnic_kwq;
13106 else
13107 bp->cnic_kwq_cons++;
13108 }
13109 bnx2x_sp_prod_update(bp);
13110 spin_unlock_bh(&bp->spq_lock);
13111}
13112
13113static int bnx2x_cnic_sp_queue(struct net_device *dev,
13114 struct kwqe_16 *kwqes[], u32 count)
13115{
13116 struct bnx2x *bp = netdev_priv(dev);
13117 int i;
13118
13119#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
13120 if (unlikely(bp->panic)) {
13121 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 13122 return -EIO;
51c1a580 13123 }
993ac7b5
MC
13124#endif
13125
95c6c616
AE
13126 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13127 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 13128 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
13129 return -EAGAIN;
13130 }
13131
993ac7b5
MC
13132 spin_lock_bh(&bp->spq_lock);
13133
13134 for (i = 0; i < count; i++) {
13135 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13136
13137 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13138 break;
13139
13140 *bp->cnic_kwq_prod = *spe;
13141
13142 bp->cnic_kwq_pending++;
13143
51c1a580 13144 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 13145 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
13146 spe->data.update_data_addr.hi,
13147 spe->data.update_data_addr.lo,
993ac7b5
MC
13148 bp->cnic_kwq_pending);
13149
13150 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13151 bp->cnic_kwq_prod = bp->cnic_kwq;
13152 else
13153 bp->cnic_kwq_prod++;
13154 }
13155
13156 spin_unlock_bh(&bp->spq_lock);
13157
13158 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13159 bnx2x_cnic_sp_post(bp, 0);
13160
13161 return i;
13162}
13163
13164static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13165{
13166 struct cnic_ops *c_ops;
13167 int rc = 0;
13168
13169 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
13170 c_ops = rcu_dereference_protected(bp->cnic_ops,
13171 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
13172 if (c_ops)
13173 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13174 mutex_unlock(&bp->cnic_mutex);
13175
13176 return rc;
13177}
13178
13179static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13180{
13181 struct cnic_ops *c_ops;
13182 int rc = 0;
13183
13184 rcu_read_lock();
13185 c_ops = rcu_dereference(bp->cnic_ops);
13186 if (c_ops)
13187 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13188 rcu_read_unlock();
13189
13190 return rc;
13191}
13192
13193/*
13194 * for commands that have no data
13195 */
9f6c9258 13196int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
13197{
13198 struct cnic_ctl_info ctl = {0};
13199
13200 ctl.cmd = cmd;
13201
13202 return bnx2x_cnic_ctl_send(bp, &ctl);
13203}
13204
619c5cb6 13205static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 13206{
619c5cb6 13207 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
13208
13209 /* first we tell CNIC and only then we count this as a completion */
13210 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13211 ctl.data.comp.cid = cid;
619c5cb6 13212 ctl.data.comp.error = err;
993ac7b5
MC
13213
13214 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 13215 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
13216}
13217
619c5cb6
VZ
13218/* Called with netif_addr_lock_bh() taken.
13219 * Sets an rx_mode config for an iSCSI ETH client.
13220 * Doesn't block.
13221 * Completion should be checked outside.
13222 */
13223static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13224{
13225 unsigned long accept_flags = 0, ramrod_flags = 0;
13226 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13227 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13228
13229 if (start) {
13230 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13231 * because it's the only way for UIO Queue to accept
13232 * multicasts (in non-promiscuous mode only one Queue per
13233 * function will receive multicast packets (leading in our
13234 * case).
13235 */
13236 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13237 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13238 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13239 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13240
13241 /* Clear STOP_PENDING bit if START is requested */
13242 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13243
13244 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13245 } else
13246 /* Clear START_PENDING bit if STOP is requested */
13247 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13248
13249 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13250 set_bit(sched_state, &bp->sp_state);
13251 else {
13252 __set_bit(RAMROD_RX, &ramrod_flags);
13253 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13254 ramrod_flags);
13255 }
13256}
13257
993ac7b5
MC
13258static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13259{
13260 struct bnx2x *bp = netdev_priv(dev);
13261 int rc = 0;
13262
13263 switch (ctl->cmd) {
13264 case DRV_CTL_CTXTBL_WR_CMD: {
13265 u32 index = ctl->data.io.offset;
13266 dma_addr_t addr = ctl->data.io.dma_addr;
13267
13268 bnx2x_ilt_wr(bp, index, addr);
13269 break;
13270 }
13271
c2bff63f
DK
13272 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13273 int count = ctl->data.credit.credit_count;
993ac7b5
MC
13274
13275 bnx2x_cnic_sp_post(bp, count);
13276 break;
13277 }
13278
13279 /* rtnl_lock is held. */
13280 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
13281 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13282 unsigned long sp_bits = 0;
13283
13284 /* Configure the iSCSI classification object */
13285 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13286 cp->iscsi_l2_client_id,
13287 cp->iscsi_l2_cid, BP_FUNC(bp),
13288 bnx2x_sp(bp, mac_rdata),
13289 bnx2x_sp_mapping(bp, mac_rdata),
13290 BNX2X_FILTER_MAC_PENDING,
13291 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13292 &bp->macs_pool);
ec6ba945 13293
523224a3 13294 /* Set iSCSI MAC address */
619c5cb6
VZ
13295 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13296 if (rc)
13297 break;
523224a3
DK
13298
13299 mmiowb();
13300 barrier();
13301
619c5cb6
VZ
13302 /* Start accepting on iSCSI L2 ring */
13303
13304 netif_addr_lock_bh(dev);
13305 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13306 netif_addr_unlock_bh(dev);
13307
13308 /* bits to wait on */
13309 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13310 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13311
13312 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13313 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 13314
993ac7b5
MC
13315 break;
13316 }
13317
13318 /* rtnl_lock is held. */
13319 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 13320 unsigned long sp_bits = 0;
993ac7b5 13321
523224a3 13322 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
13323 netif_addr_lock_bh(dev);
13324 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13325 netif_addr_unlock_bh(dev);
13326
13327 /* bits to wait on */
13328 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13329 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13330
13331 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13332 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
13333
13334 mmiowb();
13335 barrier();
13336
13337 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
13338 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13339 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
13340 break;
13341 }
c2bff63f
DK
13342 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13343 int count = ctl->data.credit.credit_count;
13344
13345 smp_mb__before_atomic_inc();
6e30dd4e 13346 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
13347 smp_mb__after_atomic_inc();
13348 break;
13349 }
1d187b34 13350 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 13351 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
13352
13353 if (CHIP_IS_E3(bp)) {
13354 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
13355 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13356 int path = BP_PATH(bp);
13357 int port = BP_PORT(bp);
13358 int i;
13359 u32 scratch_offset;
13360 u32 *host_addr;
1d187b34 13361
2e499d3c 13362 /* first write capability to shmem2 */
1d187b34
BW
13363 if (ulp_type == CNIC_ULP_ISCSI)
13364 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13365 else if (ulp_type == CNIC_ULP_FCOE)
13366 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13367 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
13368
13369 if ((ulp_type != CNIC_ULP_FCOE) ||
13370 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13371 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13372 break;
13373
13374 /* if reached here - should write fcoe capabilities */
13375 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13376 if (!scratch_offset)
13377 break;
13378 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13379 fcoe_features[path][port]);
13380 host_addr = (u32 *) &(ctl->data.register_data.
13381 fcoe_features);
13382 for (i = 0; i < sizeof(struct fcoe_capabilities);
13383 i += 4)
13384 REG_WR(bp, scratch_offset + i,
13385 *(host_addr + i/4));
1d187b34
BW
13386 }
13387 break;
13388 }
2e499d3c 13389
1d187b34
BW
13390 case DRV_CTL_ULP_UNREGISTER_CMD: {
13391 int ulp_type = ctl->data.ulp_type;
13392
13393 if (CHIP_IS_E3(bp)) {
13394 int idx = BP_FW_MB_IDX(bp);
13395 u32 cap;
13396
13397 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13398 if (ulp_type == CNIC_ULP_ISCSI)
13399 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13400 else if (ulp_type == CNIC_ULP_FCOE)
13401 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13402 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13403 }
13404 break;
13405 }
993ac7b5
MC
13406
13407 default:
13408 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13409 rc = -EINVAL;
13410 }
13411
13412 return rc;
13413}
13414
9f6c9258 13415void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
13416{
13417 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13418
13419 if (bp->flags & USING_MSIX_FLAG) {
13420 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13421 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13422 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13423 } else {
13424 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13425 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13426 }
619c5cb6 13427 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
13428 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13429 else
13430 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13431
619c5cb6
VZ
13432 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13433 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
13434 cp->irq_arr[1].status_blk = bp->def_status_blk;
13435 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 13436 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
13437
13438 cp->num_irq = 2;
13439}
13440
37ae41a9
MS
13441void bnx2x_setup_cnic_info(struct bnx2x *bp)
13442{
13443 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13444
37ae41a9
MS
13445 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13446 bnx2x_cid_ilt_lines(bp);
13447 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13448 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13449 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13450
13451 if (NO_ISCSI_OOO(bp))
13452 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13453}
13454
993ac7b5
MC
13455static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13456 void *data)
13457{
13458 struct bnx2x *bp = netdev_priv(dev);
13459 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
13460 int rc;
13461
13462 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 13463
51c1a580
MS
13464 if (ops == NULL) {
13465 BNX2X_ERR("NULL ops received\n");
993ac7b5 13466 return -EINVAL;
51c1a580 13467 }
993ac7b5 13468
55c11941
MS
13469 if (!CNIC_SUPPORT(bp)) {
13470 BNX2X_ERR("Can't register CNIC when not supported\n");
13471 return -EOPNOTSUPP;
13472 }
13473
13474 if (!CNIC_LOADED(bp)) {
13475 rc = bnx2x_load_cnic(bp);
13476 if (rc) {
13477 BNX2X_ERR("CNIC-related load failed\n");
13478 return rc;
13479 }
55c11941
MS
13480 }
13481
13482 bp->cnic_enabled = true;
13483
993ac7b5
MC
13484 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13485 if (!bp->cnic_kwq)
13486 return -ENOMEM;
13487
13488 bp->cnic_kwq_cons = bp->cnic_kwq;
13489 bp->cnic_kwq_prod = bp->cnic_kwq;
13490 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13491
13492 bp->cnic_spq_pending = 0;
13493 bp->cnic_kwq_pending = 0;
13494
13495 bp->cnic_data = data;
13496
13497 cp->num_irq = 0;
619c5cb6 13498 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 13499 cp->iro_arr = bp->iro_arr;
993ac7b5 13500
993ac7b5 13501 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 13502
993ac7b5
MC
13503 rcu_assign_pointer(bp->cnic_ops, ops);
13504
13505 return 0;
13506}
13507
13508static int bnx2x_unregister_cnic(struct net_device *dev)
13509{
13510 struct bnx2x *bp = netdev_priv(dev);
13511 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13512
13513 mutex_lock(&bp->cnic_mutex);
993ac7b5 13514 cp->drv_state = 0;
2cfa5a04 13515 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
13516 mutex_unlock(&bp->cnic_mutex);
13517 synchronize_rcu();
fea75645 13518 bp->cnic_enabled = false;
993ac7b5
MC
13519 kfree(bp->cnic_kwq);
13520 bp->cnic_kwq = NULL;
13521
13522 return 0;
13523}
13524
13525struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13526{
13527 struct bnx2x *bp = netdev_priv(dev);
13528 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13529
2ba45142
VZ
13530 /* If both iSCSI and FCoE are disabled - return NULL in
13531 * order to indicate CNIC that it should not try to work
13532 * with this device.
13533 */
13534 if (NO_ISCSI(bp) && NO_FCOE(bp))
13535 return NULL;
13536
993ac7b5
MC
13537 cp->drv_owner = THIS_MODULE;
13538 cp->chip_id = CHIP_ID(bp);
13539 cp->pdev = bp->pdev;
13540 cp->io_base = bp->regview;
13541 cp->io_base2 = bp->doorbells;
13542 cp->max_kwqe_pending = 8;
523224a3 13543 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
13544 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13545 bnx2x_cid_ilt_lines(bp);
993ac7b5 13546 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 13547 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
13548 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13549 cp->drv_ctl = bnx2x_drv_ctl;
13550 cp->drv_register_cnic = bnx2x_register_cnic;
13551 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 13552 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
13553 cp->iscsi_l2_client_id =
13554 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 13555 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 13556
2ba45142
VZ
13557 if (NO_ISCSI_OOO(bp))
13558 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13559
13560 if (NO_ISCSI(bp))
13561 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13562
13563 if (NO_FCOE(bp))
13564 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13565
51c1a580
MS
13566 BNX2X_DEV_INFO(
13567 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13568 cp->ctx_blk_size,
13569 cp->ctx_tbl_offset,
13570 cp->ctx_tbl_len,
13571 cp->starting_cid);
993ac7b5
MC
13572 return cp;
13573}
993ac7b5 13574
6411280a 13575u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
9b176b6b 13576{
6411280a
AE
13577 struct bnx2x *bp = fp->bp;
13578 u32 offset = BAR_USTRORM_INTMEM;
abc5a021 13579
6411280a
AE
13580 if (IS_VF(bp))
13581 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13582 else if (!CHIP_IS_E1x(bp))
13583 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13584 else
13585 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
8d9ac297 13586
6411280a 13587 return offset;
8d9ac297 13588}
381ac16b 13589
6411280a
AE
13590/* called only on E1H or E2.
13591 * When pretending to be PF, the pretend value is the function number 0...7
13592 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13593 * combination
13594 */
13595int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
381ac16b 13596{
6411280a 13597 u32 pretend_reg;
381ac16b 13598
23826850 13599 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
6411280a 13600 return -1;
381ac16b 13601
6411280a
AE
13602 /* get my own pretend register */
13603 pretend_reg = bnx2x_get_pretend_reg(bp);
13604 REG_WR(bp, pretend_reg, pretend_func_val);
13605 REG_RD(bp, pretend_reg);
381ac16b
AE
13606 return 0;
13607}