bnx2x: correct memory release scheme
[deliverable/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
2e499d3c
BW
78#define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
79
34f80b04
EG
80/* Time in jiffies before concluding the transmitter is hung */
81#define TX_TIMEOUT (5*HZ)
a2fbb9ea 82
0329aba1 83static char version[] =
619c5cb6 84 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
a2fbb9ea
ET
85 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
86
24e3fcef 87MODULE_AUTHOR("Eliezer Tamir");
f2e0899f 88MODULE_DESCRIPTION("Broadcom NetXtreme II "
619c5cb6
VZ
89 "BCM57710/57711/57711E/"
90 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
91 "57840/57840_MF Driver");
a2fbb9ea
ET
92MODULE_LICENSE("GPL");
93MODULE_VERSION(DRV_MODULE_VERSION);
45229b42
BH
94MODULE_FIRMWARE(FW_FILE_NAME_E1);
95MODULE_FIRMWARE(FW_FILE_NAME_E1H);
f2e0899f 96MODULE_FIRMWARE(FW_FILE_NAME_E2);
a2fbb9ea 97
ca00392c 98
d6214d7a 99int num_queues;
54b9ddaa 100module_param(num_queues, int, 0);
96305234
DK
101MODULE_PARM_DESC(num_queues,
102 " Set number of queues (default is as a number of CPUs)");
555f6c78 103
19680c48 104static int disable_tpa;
19680c48 105module_param(disable_tpa, int, 0);
9898f86d 106MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
8badd27a 107
9ee3d37b
DK
108#define INT_MODE_INTx 1
109#define INT_MODE_MSI 2
0e8d2ec5 110int int_mode;
8badd27a 111module_param(int_mode, int, 0);
619c5cb6 112MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
cdaa7cb8 113 "(1 INT#x; 2 MSI)");
8badd27a 114
a18f5128
EG
115static int dropless_fc;
116module_param(dropless_fc, int, 0);
117MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
118
8d5726c4
EG
119static int mrrs = -1;
120module_param(mrrs, int, 0);
121MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
122
9898f86d 123static int debug;
a2fbb9ea 124module_param(debug, int, 0);
9898f86d
EG
125MODULE_PARM_DESC(debug, " Default debug msglevel");
126
a2fbb9ea 127
619c5cb6
VZ
128
129struct workqueue_struct *bnx2x_wq;
ec6ba945 130
1ef1d45a
BW
131struct bnx2x_mac_vals {
132 u32 xmac_addr;
133 u32 xmac_val;
134 u32 emac_addr;
135 u32 emac_val;
136 u32 umac_addr;
137 u32 umac_val;
138 u32 bmac_addr;
139 u32 bmac_val[2];
140};
141
a2fbb9ea
ET
142enum bnx2x_board_type {
143 BCM57710 = 0,
619c5cb6
VZ
144 BCM57711,
145 BCM57711E,
146 BCM57712,
147 BCM57712_MF,
1ab4434c 148 BCM57712_VF,
619c5cb6
VZ
149 BCM57800,
150 BCM57800_MF,
1ab4434c 151 BCM57800_VF,
619c5cb6
VZ
152 BCM57810,
153 BCM57810_MF,
1ab4434c 154 BCM57810_VF,
c3def943
YM
155 BCM57840_4_10,
156 BCM57840_2_20,
7e8e02df 157 BCM57840_MF,
1ab4434c 158 BCM57840_VF,
7e8e02df 159 BCM57811,
1ab4434c
AE
160 BCM57811_MF,
161 BCM57840_O,
162 BCM57840_MFO,
163 BCM57811_VF
a2fbb9ea
ET
164};
165
34f80b04 166/* indexed by board_type, above */
53a10565 167static struct {
a2fbb9ea 168 char *name;
0329aba1 169} board_info[] = {
1ab4434c
AE
170 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
171 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
172 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
173 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
174 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
175 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
176 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
177 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
178 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
179 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
180 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
181 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
182 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
183 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
184 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
185 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
186 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
187 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
188 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
189 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
190 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
a2fbb9ea
ET
191};
192
619c5cb6
VZ
193#ifndef PCI_DEVICE_ID_NX2_57710
194#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
195#endif
196#ifndef PCI_DEVICE_ID_NX2_57711
197#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
198#endif
199#ifndef PCI_DEVICE_ID_NX2_57711E
200#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
201#endif
202#ifndef PCI_DEVICE_ID_NX2_57712
203#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
204#endif
205#ifndef PCI_DEVICE_ID_NX2_57712_MF
206#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
207#endif
8395be5e
AE
208#ifndef PCI_DEVICE_ID_NX2_57712_VF
209#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
210#endif
619c5cb6
VZ
211#ifndef PCI_DEVICE_ID_NX2_57800
212#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
213#endif
214#ifndef PCI_DEVICE_ID_NX2_57800_MF
215#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
216#endif
8395be5e
AE
217#ifndef PCI_DEVICE_ID_NX2_57800_VF
218#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
219#endif
619c5cb6
VZ
220#ifndef PCI_DEVICE_ID_NX2_57810
221#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
222#endif
223#ifndef PCI_DEVICE_ID_NX2_57810_MF
224#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
225#endif
c3def943
YM
226#ifndef PCI_DEVICE_ID_NX2_57840_O
227#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
228#endif
8395be5e
AE
229#ifndef PCI_DEVICE_ID_NX2_57810_VF
230#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
231#endif
c3def943
YM
232#ifndef PCI_DEVICE_ID_NX2_57840_4_10
233#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
234#endif
235#ifndef PCI_DEVICE_ID_NX2_57840_2_20
236#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
237#endif
238#ifndef PCI_DEVICE_ID_NX2_57840_MFO
239#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
619c5cb6
VZ
240#endif
241#ifndef PCI_DEVICE_ID_NX2_57840_MF
242#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
243#endif
8395be5e
AE
244#ifndef PCI_DEVICE_ID_NX2_57840_VF
245#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
246#endif
7e8e02df
BW
247#ifndef PCI_DEVICE_ID_NX2_57811
248#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
249#endif
250#ifndef PCI_DEVICE_ID_NX2_57811_MF
251#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
252#endif
8395be5e
AE
253#ifndef PCI_DEVICE_ID_NX2_57811_VF
254#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
255#endif
256
a3aa1884 257static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
e4ed7113
EG
258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
f2e0899f 261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
619c5cb6 262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
8395be5e 263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
619c5cb6
VZ
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
8395be5e 266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
619c5cb6
VZ
267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
c3def943
YM
269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
8395be5e 272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
c3def943 273 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
619c5cb6 274 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
8395be5e 275 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
7e8e02df
BW
276 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
277 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
8395be5e 278 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
a2fbb9ea
ET
279 { 0 }
280};
281
282MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
283
452427b0
YM
284/* Global resources for unloading a previously loaded device */
285#define BNX2X_PREV_WAIT_NEEDED 1
286static DEFINE_SEMAPHORE(bnx2x_prev_sem);
287static LIST_HEAD(bnx2x_prev_list);
a2fbb9ea
ET
288/****************************************************************************
289* General service functions
290****************************************************************************/
291
1191cb83 292static void __storm_memset_dma_mapping(struct bnx2x *bp,
619c5cb6
VZ
293 u32 addr, dma_addr_t mapping)
294{
295 REG_WR(bp, addr, U64_LO(mapping));
296 REG_WR(bp, addr + 4, U64_HI(mapping));
297}
298
1191cb83
ED
299static void storm_memset_spq_addr(struct bnx2x *bp,
300 dma_addr_t mapping, u16 abs_fid)
619c5cb6
VZ
301{
302 u32 addr = XSEM_REG_FAST_MEMORY +
303 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
304
305 __storm_memset_dma_mapping(bp, addr, mapping);
306}
307
1191cb83
ED
308static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
309 u16 pf_id)
523224a3 310{
619c5cb6
VZ
311 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
312 pf_id);
313 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
314 pf_id);
315 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
316 pf_id);
317 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
318 pf_id);
523224a3
DK
319}
320
1191cb83
ED
321static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
322 u8 enable)
619c5cb6
VZ
323{
324 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
325 enable);
326 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
327 enable);
328 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
329 enable);
330 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
331 enable);
332}
523224a3 333
1191cb83
ED
334static void storm_memset_eq_data(struct bnx2x *bp,
335 struct event_ring_data *eq_data,
523224a3
DK
336 u16 pfid)
337{
338 size_t size = sizeof(struct event_ring_data);
339
340 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
341
342 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
343}
344
1191cb83
ED
345static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
346 u16 pfid)
523224a3
DK
347{
348 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
349 REG_WR16(bp, addr, eq_prod);
350}
351
a2fbb9ea
ET
352/* used only at init
353 * locking is done by mcp
354 */
8d96286a 355static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
a2fbb9ea
ET
356{
357 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
358 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
359 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
360 PCICFG_VENDOR_ID_OFFSET);
361}
362
a2fbb9ea
ET
363static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
364{
365 u32 val;
366
367 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
368 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
369 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
370 PCICFG_VENDOR_ID_OFFSET);
371
372 return val;
373}
a2fbb9ea 374
f2e0899f
DK
375#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
376#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
377#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
378#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
379#define DMAE_DP_DST_NONE "dst_addr [none]"
380
fd1fc79d
AE
381void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
382{
383 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
384
385 switch (dmae->opcode & DMAE_COMMAND_DST) {
386 case DMAE_CMD_DST_PCI:
387 if (src_type == DMAE_CMD_SRC_PCI)
388 DP(msglvl, "DMAE: opcode 0x%08x\n"
389 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
390 "comp_addr [%x:%08x], comp_val 0x%08x\n",
391 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
392 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
393 dmae->comp_addr_hi, dmae->comp_addr_lo,
394 dmae->comp_val);
395 else
396 DP(msglvl, "DMAE: opcode 0x%08x\n"
397 "src [%08x], len [%d*4], dst [%x:%08x]\n"
398 "comp_addr [%x:%08x], comp_val 0x%08x\n",
399 dmae->opcode, dmae->src_addr_lo >> 2,
400 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
401 dmae->comp_addr_hi, dmae->comp_addr_lo,
402 dmae->comp_val);
403 break;
404 case DMAE_CMD_DST_GRC:
405 if (src_type == DMAE_CMD_SRC_PCI)
406 DP(msglvl, "DMAE: opcode 0x%08x\n"
407 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
408 "comp_addr [%x:%08x], comp_val 0x%08x\n",
409 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
410 dmae->len, dmae->dst_addr_lo >> 2,
411 dmae->comp_addr_hi, dmae->comp_addr_lo,
412 dmae->comp_val);
413 else
414 DP(msglvl, "DMAE: opcode 0x%08x\n"
415 "src [%08x], len [%d*4], dst [%08x]\n"
416 "comp_addr [%x:%08x], comp_val 0x%08x\n",
417 dmae->opcode, dmae->src_addr_lo >> 2,
418 dmae->len, dmae->dst_addr_lo >> 2,
419 dmae->comp_addr_hi, dmae->comp_addr_lo,
420 dmae->comp_val);
421 break;
422 default:
423 if (src_type == DMAE_CMD_SRC_PCI)
424 DP(msglvl, "DMAE: opcode 0x%08x\n"
425 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
426 "comp_addr [%x:%08x] comp_val 0x%08x\n",
427 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
428 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
429 dmae->comp_val);
430 else
431 DP(msglvl, "DMAE: opcode 0x%08x\n"
432 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
433 "comp_addr [%x:%08x] comp_val 0x%08x\n",
434 dmae->opcode, dmae->src_addr_lo >> 2,
435 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
436 dmae->comp_val);
437 break;
438 }
439}
f2e0899f 440
a2fbb9ea 441/* copy command into DMAE command memory and set DMAE command go */
6c719d00 442void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
a2fbb9ea
ET
443{
444 u32 cmd_offset;
445 int i;
446
447 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
448 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
449 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
a2fbb9ea
ET
450 }
451 REG_WR(bp, dmae_reg_go_c[idx], 1);
452}
453
f2e0899f 454u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
a2fbb9ea 455{
f2e0899f
DK
456 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
457 DMAE_CMD_C_ENABLE);
458}
ad8d3948 459
f2e0899f
DK
460u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
461{
462 return opcode & ~DMAE_CMD_SRC_RESET;
463}
ad8d3948 464
f2e0899f
DK
465u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
466 bool with_comp, u8 comp_type)
467{
468 u32 opcode = 0;
469
470 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
471 (dst_type << DMAE_COMMAND_DST_SHIFT));
ad8d3948 472
f2e0899f
DK
473 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
474
475 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
3395a033
DK
476 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
477 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
f2e0899f 478 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
a2fbb9ea 479
a2fbb9ea 480#ifdef __BIG_ENDIAN
f2e0899f 481 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
a2fbb9ea 482#else
f2e0899f 483 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
a2fbb9ea 484#endif
f2e0899f
DK
485 if (with_comp)
486 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
487 return opcode;
488}
489
fd1fc79d 490void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
8d96286a 491 struct dmae_command *dmae,
492 u8 src_type, u8 dst_type)
f2e0899f
DK
493{
494 memset(dmae, 0, sizeof(struct dmae_command));
495
496 /* set the opcode */
497 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
498 true, DMAE_COMP_PCI);
499
500 /* fill in the completion parameters */
501 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
502 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
503 dmae->comp_val = DMAE_COMP_VAL;
504}
505
fd1fc79d
AE
506/* issue a dmae command over the init-channel and wait for completion */
507int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
f2e0899f
DK
508{
509 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
5e374b5a 510 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
f2e0899f
DK
511 int rc = 0;
512
619c5cb6
VZ
513 /*
514 * Lock the dmae channel. Disable BHs to prevent a dead-lock
515 * as long as this code is called both from syscall context and
516 * from ndo_set_rx_mode() flow that may be called from BH.
517 */
6e30dd4e 518 spin_lock_bh(&bp->dmae_lock);
5ff7b6d4 519
f2e0899f 520 /* reset completion */
a2fbb9ea
ET
521 *wb_comp = 0;
522
f2e0899f
DK
523 /* post the command on the channel used for initializations */
524 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
a2fbb9ea 525
f2e0899f 526 /* wait for completion */
a2fbb9ea 527 udelay(5);
f2e0899f 528 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
ad8d3948 529
95c6c616
AE
530 if (!cnt ||
531 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
532 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
c3eefaf6 533 BNX2X_ERR("DMAE timeout!\n");
f2e0899f
DK
534 rc = DMAE_TIMEOUT;
535 goto unlock;
a2fbb9ea 536 }
ad8d3948 537 cnt--;
f2e0899f 538 udelay(50);
a2fbb9ea 539 }
f2e0899f
DK
540 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
541 BNX2X_ERR("DMAE PCI error!\n");
542 rc = DMAE_PCI_ERROR;
543 }
544
f2e0899f 545unlock:
6e30dd4e 546 spin_unlock_bh(&bp->dmae_lock);
f2e0899f
DK
547 return rc;
548}
549
550void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
551 u32 len32)
552{
553 struct dmae_command dmae;
554
555 if (!bp->dmae_ready) {
556 u32 *data = bnx2x_sp(bp, wb_data[0]);
557
127a425e
AE
558 if (CHIP_IS_E1(bp))
559 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
560 else
561 bnx2x_init_str_wr(bp, dst_addr, data, len32);
f2e0899f
DK
562 return;
563 }
564
565 /* set opcode and fixed command fields */
566 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
567
568 /* fill in addresses and len */
569 dmae.src_addr_lo = U64_LO(dma_addr);
570 dmae.src_addr_hi = U64_HI(dma_addr);
571 dmae.dst_addr_lo = dst_addr >> 2;
572 dmae.dst_addr_hi = 0;
573 dmae.len = len32;
574
f2e0899f
DK
575 /* issue the command and wait for completion */
576 bnx2x_issue_dmae_with_comp(bp, &dmae);
a2fbb9ea
ET
577}
578
c18487ee 579void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
a2fbb9ea 580{
5ff7b6d4 581 struct dmae_command dmae;
ad8d3948
EG
582
583 if (!bp->dmae_ready) {
584 u32 *data = bnx2x_sp(bp, wb_data[0]);
585 int i;
586
51c1a580 587 if (CHIP_IS_E1(bp))
127a425e
AE
588 for (i = 0; i < len32; i++)
589 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
51c1a580 590 else
127a425e
AE
591 for (i = 0; i < len32; i++)
592 data[i] = REG_RD(bp, src_addr + i*4);
593
ad8d3948
EG
594 return;
595 }
596
f2e0899f
DK
597 /* set opcode and fixed command fields */
598 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
a2fbb9ea 599
f2e0899f 600 /* fill in addresses and len */
5ff7b6d4
EG
601 dmae.src_addr_lo = src_addr >> 2;
602 dmae.src_addr_hi = 0;
603 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
604 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
605 dmae.len = len32;
ad8d3948 606
f2e0899f
DK
607 /* issue the command and wait for completion */
608 bnx2x_issue_dmae_with_comp(bp, &dmae);
ad8d3948
EG
609}
610
8d96286a 611static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
612 u32 addr, u32 len)
573f2035 613{
02e3c6cb 614 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
573f2035
EG
615 int offset = 0;
616
02e3c6cb 617 while (len > dmae_wr_max) {
573f2035 618 bnx2x_write_dmae(bp, phys_addr + offset,
02e3c6cb
VZ
619 addr + offset, dmae_wr_max);
620 offset += dmae_wr_max * 4;
621 len -= dmae_wr_max;
573f2035
EG
622 }
623
624 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
625}
626
a2fbb9ea
ET
627static int bnx2x_mc_assert(struct bnx2x *bp)
628{
a2fbb9ea 629 char last_idx;
34f80b04
EG
630 int i, rc = 0;
631 u32 row0, row1, row2, row3;
632
633 /* XSTORM */
634 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
635 XSTORM_ASSERT_LIST_INDEX_OFFSET);
636 if (last_idx)
637 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
638
639 /* print the asserts */
640 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
641
642 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
643 XSTORM_ASSERT_LIST_OFFSET(i));
644 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
645 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
646 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
647 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
648 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
649 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
650
651 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 652 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
653 i, row3, row2, row1, row0);
654 rc++;
655 } else {
656 break;
657 }
658 }
659
660 /* TSTORM */
661 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
662 TSTORM_ASSERT_LIST_INDEX_OFFSET);
663 if (last_idx)
664 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
665
666 /* print the asserts */
667 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
668
669 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
670 TSTORM_ASSERT_LIST_OFFSET(i));
671 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
672 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
673 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
674 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
675 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
676 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
677
678 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 679 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
680 i, row3, row2, row1, row0);
681 rc++;
682 } else {
683 break;
684 }
685 }
686
687 /* CSTORM */
688 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
689 CSTORM_ASSERT_LIST_INDEX_OFFSET);
690 if (last_idx)
691 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
692
693 /* print the asserts */
694 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
695
696 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
697 CSTORM_ASSERT_LIST_OFFSET(i));
698 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
699 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
700 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
701 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
702 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
703 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
704
705 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 706 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
707 i, row3, row2, row1, row0);
708 rc++;
709 } else {
710 break;
711 }
712 }
713
714 /* USTORM */
715 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
716 USTORM_ASSERT_LIST_INDEX_OFFSET);
717 if (last_idx)
718 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
719
720 /* print the asserts */
721 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
722
723 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
724 USTORM_ASSERT_LIST_OFFSET(i));
725 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
726 USTORM_ASSERT_LIST_OFFSET(i) + 4);
727 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
728 USTORM_ASSERT_LIST_OFFSET(i) + 8);
729 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
730 USTORM_ASSERT_LIST_OFFSET(i) + 12);
731
732 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
51c1a580 733 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
34f80b04
EG
734 i, row3, row2, row1, row0);
735 rc++;
736 } else {
737 break;
a2fbb9ea
ET
738 }
739 }
34f80b04 740
a2fbb9ea
ET
741 return rc;
742}
c14423fe 743
7a25cc73 744void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
a2fbb9ea 745{
7a25cc73 746 u32 addr, val;
a2fbb9ea 747 u32 mark, offset;
4781bfad 748 __be32 data[9];
a2fbb9ea 749 int word;
f2e0899f 750 u32 trace_shmem_base;
2145a920
VZ
751 if (BP_NOMCP(bp)) {
752 BNX2X_ERR("NO MCP - can not dump\n");
753 return;
754 }
7a25cc73
DK
755 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
756 (bp->common.bc_ver & 0xff0000) >> 16,
757 (bp->common.bc_ver & 0xff00) >> 8,
758 (bp->common.bc_ver & 0xff));
759
760 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
761 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
51c1a580 762 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
cdaa7cb8 763
f2e0899f
DK
764 if (BP_PATH(bp) == 0)
765 trace_shmem_base = bp->common.shmem_base;
766 else
767 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
de128804
DK
768 addr = trace_shmem_base - 0x800;
769
770 /* validate TRCB signature */
771 mark = REG_RD(bp, addr);
772 if (mark != MFW_TRACE_SIGNATURE) {
773 BNX2X_ERR("Trace buffer signature is missing.");
774 return ;
775 }
776
777 /* read cyclic buffer pointer */
778 addr += 4;
cdaa7cb8 779 mark = REG_RD(bp, addr);
f2e0899f
DK
780 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
781 + ((mark + 0x3) & ~0x3) - 0x08000000;
7a25cc73 782 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
a2fbb9ea 783
7a25cc73 784 printk("%s", lvl);
2de67439
YM
785
786 /* dump buffer after the mark */
f2e0899f 787 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
a2fbb9ea 788 for (word = 0; word < 8; word++)
cdaa7cb8 789 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 790 data[8] = 0x0;
7995c64e 791 pr_cont("%s", (char *)data);
a2fbb9ea 792 }
2de67439
YM
793
794 /* dump buffer before the mark */
cdaa7cb8 795 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
a2fbb9ea 796 for (word = 0; word < 8; word++)
cdaa7cb8 797 data[word] = htonl(REG_RD(bp, offset + 4*word));
a2fbb9ea 798 data[8] = 0x0;
7995c64e 799 pr_cont("%s", (char *)data);
a2fbb9ea 800 }
7a25cc73
DK
801 printk("%s" "end of fw dump\n", lvl);
802}
803
1191cb83 804static void bnx2x_fw_dump(struct bnx2x *bp)
7a25cc73
DK
805{
806 bnx2x_fw_dump_lvl(bp, KERN_ERR);
a2fbb9ea
ET
807}
808
823e1d90
YM
809static void bnx2x_hc_int_disable(struct bnx2x *bp)
810{
811 int port = BP_PORT(bp);
812 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
813 u32 val = REG_RD(bp, addr);
814
815 /* in E1 we must use only PCI configuration space to disable
816 * MSI/MSIX capablility
817 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
818 */
819 if (CHIP_IS_E1(bp)) {
820 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
821 * Use mask register to prevent from HC sending interrupts
822 * after we exit the function
823 */
824 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
825
826 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
827 HC_CONFIG_0_REG_INT_LINE_EN_0 |
828 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
829 } else
830 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
831 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
832 HC_CONFIG_0_REG_INT_LINE_EN_0 |
833 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
834
835 DP(NETIF_MSG_IFDOWN,
836 "write %x to HC %d (addr 0x%x)\n",
837 val, port, addr);
838
839 /* flush all outstanding writes */
840 mmiowb();
841
842 REG_WR(bp, addr, val);
843 if (REG_RD(bp, addr) != val)
844 BNX2X_ERR("BUG! proper val not read from IGU!\n");
845}
846
847static void bnx2x_igu_int_disable(struct bnx2x *bp)
848{
849 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
850
851 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
852 IGU_PF_CONF_INT_LINE_EN |
853 IGU_PF_CONF_ATTN_BIT_EN);
854
855 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
856
857 /* flush all outstanding writes */
858 mmiowb();
859
860 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
861 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
862 BNX2X_ERR("BUG! proper val not read from IGU!\n");
863}
864
865static void bnx2x_int_disable(struct bnx2x *bp)
866{
867 if (bp->common.int_block == INT_BLOCK_HC)
868 bnx2x_hc_int_disable(bp);
869 else
870 bnx2x_igu_int_disable(bp);
871}
872
873void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
a2fbb9ea
ET
874{
875 int i;
523224a3
DK
876 u16 j;
877 struct hc_sp_status_block_data sp_sb_data;
878 int func = BP_FUNC(bp);
879#ifdef BNX2X_STOP_ON_ERROR
880 u16 start = 0, end = 0;
6383c0b3 881 u8 cos;
523224a3 882#endif
823e1d90
YM
883 if (disable_int)
884 bnx2x_int_disable(bp);
a2fbb9ea 885
66e855f3 886 bp->stats_state = STATS_STATE_DISABLED;
7a752993 887 bp->eth_stats.unrecoverable_error++;
66e855f3
YG
888 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
889
a2fbb9ea
ET
890 BNX2X_ERR("begin crash dump -----------------\n");
891
8440d2b6
EG
892 /* Indices */
893 /* Common */
51c1a580 894 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
895 bp->def_idx, bp->def_att_idx, bp->attn_state,
896 bp->spq_prod_idx, bp->stats_counter);
523224a3
DK
897 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
898 bp->def_status_blk->atten_status_block.attn_bits,
899 bp->def_status_blk->atten_status_block.attn_bits_ack,
900 bp->def_status_blk->atten_status_block.status_block_id,
901 bp->def_status_blk->atten_status_block.attn_bits_index);
902 BNX2X_ERR(" def (");
903 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
904 pr_cont("0x%x%s",
f1deab50
JP
905 bp->def_status_blk->sp_sb.index_values[i],
906 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
523224a3
DK
907
908 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
909 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
910 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
911 i*sizeof(u32));
912
f1deab50 913 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
914 sp_sb_data.igu_sb_id,
915 sp_sb_data.igu_seg_id,
916 sp_sb_data.p_func.pf_id,
917 sp_sb_data.p_func.vnic_id,
918 sp_sb_data.p_func.vf_id,
619c5cb6
VZ
919 sp_sb_data.p_func.vf_valid,
920 sp_sb_data.state);
523224a3 921
8440d2b6 922
ec6ba945 923 for_each_eth_queue(bp, i) {
a2fbb9ea 924 struct bnx2x_fastpath *fp = &bp->fp[i];
523224a3 925 int loop;
f2e0899f 926 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
927 struct hc_status_block_data_e1x sb_data_e1x;
928 struct hc_status_block_sm *hc_sm_p =
619c5cb6
VZ
929 CHIP_IS_E1x(bp) ?
930 sb_data_e1x.common.state_machine :
931 sb_data_e2.common.state_machine;
523224a3 932 struct hc_index_data *hc_index_p =
619c5cb6
VZ
933 CHIP_IS_E1x(bp) ?
934 sb_data_e1x.index_data :
935 sb_data_e2.index_data;
6383c0b3 936 u8 data_size, cos;
523224a3 937 u32 *sb_data_p;
6383c0b3 938 struct bnx2x_fp_txdata txdata;
523224a3
DK
939
940 /* Rx */
51c1a580 941 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 942 i, fp->rx_bd_prod, fp->rx_bd_cons,
523224a3 943 fp->rx_comp_prod,
66e855f3 944 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
51c1a580 945 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
8440d2b6 946 fp->rx_sge_prod, fp->last_max_sge,
523224a3 947 le16_to_cpu(fp->fp_hc_idx));
a2fbb9ea 948
523224a3 949 /* Tx */
6383c0b3
AE
950 for_each_cos_in_tx_queue(fp, cos)
951 {
65565884 952 txdata = *fp->txdata_ptr[cos];
51c1a580 953 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
954 i, txdata.tx_pkt_prod,
955 txdata.tx_pkt_cons, txdata.tx_bd_prod,
956 txdata.tx_bd_cons,
957 le16_to_cpu(*txdata.tx_cons_sb));
958 }
523224a3 959
619c5cb6
VZ
960 loop = CHIP_IS_E1x(bp) ?
961 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
523224a3
DK
962
963 /* host sb data */
964
ec6ba945
VZ
965 if (IS_FCOE_FP(fp))
966 continue;
55c11941 967
523224a3
DK
968 BNX2X_ERR(" run indexes (");
969 for (j = 0; j < HC_SB_MAX_SM; j++)
970 pr_cont("0x%x%s",
971 fp->sb_running_index[j],
972 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
973
974 BNX2X_ERR(" indexes (");
975 for (j = 0; j < loop; j++)
976 pr_cont("0x%x%s",
977 fp->sb_index_values[j],
978 (j == loop - 1) ? ")" : " ");
979 /* fw sb data */
619c5cb6
VZ
980 data_size = CHIP_IS_E1x(bp) ?
981 sizeof(struct hc_status_block_data_e1x) :
982 sizeof(struct hc_status_block_data_e2);
523224a3 983 data_size /= sizeof(u32);
619c5cb6
VZ
984 sb_data_p = CHIP_IS_E1x(bp) ?
985 (u32 *)&sb_data_e1x :
986 (u32 *)&sb_data_e2;
523224a3
DK
987 /* copy sb data in here */
988 for (j = 0; j < data_size; j++)
989 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
990 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
991 j * sizeof(u32));
992
619c5cb6 993 if (!CHIP_IS_E1x(bp)) {
51c1a580 994 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
995 sb_data_e2.common.p_func.pf_id,
996 sb_data_e2.common.p_func.vf_id,
997 sb_data_e2.common.p_func.vf_valid,
998 sb_data_e2.common.p_func.vnic_id,
619c5cb6
VZ
999 sb_data_e2.common.same_igu_sb_1b,
1000 sb_data_e2.common.state);
f2e0899f 1001 } else {
51c1a580 1002 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
1003 sb_data_e1x.common.p_func.pf_id,
1004 sb_data_e1x.common.p_func.vf_id,
1005 sb_data_e1x.common.p_func.vf_valid,
1006 sb_data_e1x.common.p_func.vnic_id,
619c5cb6
VZ
1007 sb_data_e1x.common.same_igu_sb_1b,
1008 sb_data_e1x.common.state);
f2e0899f 1009 }
523224a3
DK
1010
1011 /* SB_SMs data */
1012 for (j = 0; j < HC_SB_MAX_SM; j++) {
51c1a580
MS
1013 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",
1014 j, hc_sm_p[j].__flags,
1015 hc_sm_p[j].igu_sb_id,
1016 hc_sm_p[j].igu_seg_id,
1017 hc_sm_p[j].time_to_expire,
1018 hc_sm_p[j].timer_value);
523224a3
DK
1019 }
1020
1021 /* Indecies data */
1022 for (j = 0; j < loop; j++) {
51c1a580 1023 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
523224a3
DK
1024 hc_index_p[j].flags,
1025 hc_index_p[j].timeout);
1026 }
8440d2b6 1027 }
a2fbb9ea 1028
523224a3 1029#ifdef BNX2X_STOP_ON_ERROR
04c46736
YM
1030
1031 /* event queue */
1032 for (i = 0; i < NUM_EQ_DESC; i++) {
1033 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
1034
1035 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1036 i, bp->eq_ring[i].message.opcode,
1037 bp->eq_ring[i].message.error);
1038 BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
1039 }
1040
8440d2b6
EG
1041 /* Rings */
1042 /* Rx */
55c11941 1043 for_each_valid_rx_queue(bp, i) {
8440d2b6 1044 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea
ET
1045
1046 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1047 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
8440d2b6 1048 for (j = start; j != end; j = RX_BD(j + 1)) {
a2fbb9ea
ET
1049 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1050 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1051
c3eefaf6 1052 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
44151acb 1053 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
a2fbb9ea
ET
1054 }
1055
3196a88a
EG
1056 start = RX_SGE(fp->rx_sge_prod);
1057 end = RX_SGE(fp->last_max_sge);
8440d2b6 1058 for (j = start; j != end; j = RX_SGE(j + 1)) {
7a9b2557
VZ
1059 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1060 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1061
c3eefaf6
EG
1062 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1063 i, j, rx_sge[1], rx_sge[0], sw_page->page);
7a9b2557
VZ
1064 }
1065
a2fbb9ea
ET
1066 start = RCQ_BD(fp->rx_comp_cons - 10);
1067 end = RCQ_BD(fp->rx_comp_cons + 503);
8440d2b6 1068 for (j = start; j != end; j = RCQ_BD(j + 1)) {
a2fbb9ea
ET
1069 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1070
c3eefaf6
EG
1071 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1072 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
a2fbb9ea
ET
1073 }
1074 }
1075
8440d2b6 1076 /* Tx */
55c11941 1077 for_each_valid_tx_queue(bp, i) {
8440d2b6 1078 struct bnx2x_fastpath *fp = &bp->fp[i];
6383c0b3 1079 for_each_cos_in_tx_queue(fp, cos) {
65565884 1080 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
6383c0b3
AE
1081
1082 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1083 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1084 for (j = start; j != end; j = TX_BD(j + 1)) {
1085 struct sw_tx_bd *sw_bd =
1086 &txdata->tx_buf_ring[j];
1087
51c1a580 1088 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
6383c0b3
AE
1089 i, cos, j, sw_bd->skb,
1090 sw_bd->first_bd);
1091 }
8440d2b6 1092
6383c0b3
AE
1093 start = TX_BD(txdata->tx_bd_cons - 10);
1094 end = TX_BD(txdata->tx_bd_cons + 254);
1095 for (j = start; j != end; j = TX_BD(j + 1)) {
1096 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
8440d2b6 1097
51c1a580 1098 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
6383c0b3
AE
1099 i, cos, j, tx_bd[0], tx_bd[1],
1100 tx_bd[2], tx_bd[3]);
1101 }
8440d2b6
EG
1102 }
1103 }
523224a3 1104#endif
34f80b04 1105 bnx2x_fw_dump(bp);
a2fbb9ea
ET
1106 bnx2x_mc_assert(bp);
1107 BNX2X_ERR("end crash dump -----------------\n");
a2fbb9ea
ET
1108}
1109
619c5cb6
VZ
1110/*
1111 * FLR Support for E2
1112 *
1113 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1114 * initialization.
1115 */
1116#define FLR_WAIT_USEC 10000 /* 10 miliseconds */
89db4ad8
AE
1117#define FLR_WAIT_INTERVAL 50 /* usec */
1118#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
619c5cb6
VZ
1119
1120struct pbf_pN_buf_regs {
1121 int pN;
1122 u32 init_crd;
1123 u32 crd;
1124 u32 crd_freed;
1125};
1126
1127struct pbf_pN_cmd_regs {
1128 int pN;
1129 u32 lines_occup;
1130 u32 lines_freed;
1131};
1132
1133static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1134 struct pbf_pN_buf_regs *regs,
1135 u32 poll_count)
1136{
1137 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1138 u32 cur_cnt = poll_count;
1139
1140 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1141 crd = crd_start = REG_RD(bp, regs->crd);
1142 init_crd = REG_RD(bp, regs->init_crd);
1143
1144 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1145 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1146 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1147
1148 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1149 (init_crd - crd_start))) {
1150 if (cur_cnt--) {
89db4ad8 1151 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1152 crd = REG_RD(bp, regs->crd);
1153 crd_freed = REG_RD(bp, regs->crd_freed);
1154 } else {
1155 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1156 regs->pN);
1157 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1158 regs->pN, crd);
1159 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1160 regs->pN, crd_freed);
1161 break;
1162 }
1163 }
1164 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
89db4ad8 1165 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1166}
1167
1168static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1169 struct pbf_pN_cmd_regs *regs,
1170 u32 poll_count)
1171{
1172 u32 occup, to_free, freed, freed_start;
1173 u32 cur_cnt = poll_count;
1174
1175 occup = to_free = REG_RD(bp, regs->lines_occup);
1176 freed = freed_start = REG_RD(bp, regs->lines_freed);
1177
1178 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1179 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1180
1181 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1182 if (cur_cnt--) {
89db4ad8 1183 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1184 occup = REG_RD(bp, regs->lines_occup);
1185 freed = REG_RD(bp, regs->lines_freed);
1186 } else {
1187 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1188 regs->pN);
1189 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1190 regs->pN, occup);
1191 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1192 regs->pN, freed);
1193 break;
1194 }
1195 }
1196 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
89db4ad8 1197 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
619c5cb6
VZ
1198}
1199
1191cb83
ED
1200static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1201 u32 expected, u32 poll_count)
619c5cb6
VZ
1202{
1203 u32 cur_cnt = poll_count;
1204 u32 val;
1205
1206 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
89db4ad8 1207 udelay(FLR_WAIT_INTERVAL);
619c5cb6
VZ
1208
1209 return val;
1210}
1211
d16132ce
AE
1212int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1213 char *msg, u32 poll_cnt)
619c5cb6
VZ
1214{
1215 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1216 if (val != 0) {
1217 BNX2X_ERR("%s usage count=%d\n", msg, val);
1218 return 1;
1219 }
1220 return 0;
1221}
1222
d16132ce
AE
1223/* Common routines with VF FLR cleanup */
1224u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
619c5cb6
VZ
1225{
1226 /* adjust polling timeout */
1227 if (CHIP_REV_IS_EMUL(bp))
1228 return FLR_POLL_CNT * 2000;
1229
1230 if (CHIP_REV_IS_FPGA(bp))
1231 return FLR_POLL_CNT * 120;
1232
1233 return FLR_POLL_CNT;
1234}
1235
d16132ce 1236void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
619c5cb6
VZ
1237{
1238 struct pbf_pN_cmd_regs cmd_regs[] = {
1239 {0, (CHIP_IS_E3B0(bp)) ?
1240 PBF_REG_TQ_OCCUPANCY_Q0 :
1241 PBF_REG_P0_TQ_OCCUPANCY,
1242 (CHIP_IS_E3B0(bp)) ?
1243 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1244 PBF_REG_P0_TQ_LINES_FREED_CNT},
1245 {1, (CHIP_IS_E3B0(bp)) ?
1246 PBF_REG_TQ_OCCUPANCY_Q1 :
1247 PBF_REG_P1_TQ_OCCUPANCY,
1248 (CHIP_IS_E3B0(bp)) ?
1249 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1250 PBF_REG_P1_TQ_LINES_FREED_CNT},
1251 {4, (CHIP_IS_E3B0(bp)) ?
1252 PBF_REG_TQ_OCCUPANCY_LB_Q :
1253 PBF_REG_P4_TQ_OCCUPANCY,
1254 (CHIP_IS_E3B0(bp)) ?
1255 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1256 PBF_REG_P4_TQ_LINES_FREED_CNT}
1257 };
1258
1259 struct pbf_pN_buf_regs buf_regs[] = {
1260 {0, (CHIP_IS_E3B0(bp)) ?
1261 PBF_REG_INIT_CRD_Q0 :
1262 PBF_REG_P0_INIT_CRD ,
1263 (CHIP_IS_E3B0(bp)) ?
1264 PBF_REG_CREDIT_Q0 :
1265 PBF_REG_P0_CREDIT,
1266 (CHIP_IS_E3B0(bp)) ?
1267 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1268 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1269 {1, (CHIP_IS_E3B0(bp)) ?
1270 PBF_REG_INIT_CRD_Q1 :
1271 PBF_REG_P1_INIT_CRD,
1272 (CHIP_IS_E3B0(bp)) ?
1273 PBF_REG_CREDIT_Q1 :
1274 PBF_REG_P1_CREDIT,
1275 (CHIP_IS_E3B0(bp)) ?
1276 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1277 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1278 {4, (CHIP_IS_E3B0(bp)) ?
1279 PBF_REG_INIT_CRD_LB_Q :
1280 PBF_REG_P4_INIT_CRD,
1281 (CHIP_IS_E3B0(bp)) ?
1282 PBF_REG_CREDIT_LB_Q :
1283 PBF_REG_P4_CREDIT,
1284 (CHIP_IS_E3B0(bp)) ?
1285 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1286 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1287 };
1288
1289 int i;
1290
1291 /* Verify the command queues are flushed P0, P1, P4 */
1292 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1293 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1294
1295
1296 /* Verify the transmission buffers are flushed P0, P1, P4 */
1297 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1298 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1299}
1300
1301#define OP_GEN_PARAM(param) \
1302 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1303
1304#define OP_GEN_TYPE(type) \
1305 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1306
1307#define OP_GEN_AGG_VECT(index) \
1308 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1309
1310
d16132ce 1311int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
619c5cb6 1312{
86564c3f 1313 u32 op_gen_command = 0;
619c5cb6
VZ
1314
1315 u32 comp_addr = BAR_CSTRORM_INTMEM +
1316 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1317 int ret = 0;
1318
1319 if (REG_RD(bp, comp_addr)) {
89db4ad8 1320 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
619c5cb6
VZ
1321 return 1;
1322 }
1323
86564c3f
YM
1324 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1325 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1326 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1327 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
619c5cb6 1328
89db4ad8 1329 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
86564c3f 1330 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
619c5cb6
VZ
1331
1332 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1333 BNX2X_ERR("FW final cleanup did not succeed\n");
51c1a580
MS
1334 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1335 (REG_RD(bp, comp_addr)));
d16132ce
AE
1336 bnx2x_panic();
1337 return 1;
619c5cb6
VZ
1338 }
1339 /* Zero completion for nxt FLR */
1340 REG_WR(bp, comp_addr, 0);
1341
1342 return ret;
1343}
1344
b56e9670 1345u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
619c5cb6 1346{
619c5cb6
VZ
1347 u16 status;
1348
2a80eebc 1349 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
619c5cb6
VZ
1350 return status & PCI_EXP_DEVSTA_TRPND;
1351}
1352
1353/* PF FLR specific routines
1354*/
1355static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1356{
1357
1358 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1359 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1360 CFC_REG_NUM_LCIDS_INSIDE_PF,
1361 "CFC PF usage counter timed out",
1362 poll_cnt))
1363 return 1;
1364
1365
1366 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1367 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1368 DORQ_REG_PF_USAGE_CNT,
1369 "DQ PF usage counter timed out",
1370 poll_cnt))
1371 return 1;
1372
1373 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1374 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1375 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1376 "QM PF usage counter timed out",
1377 poll_cnt))
1378 return 1;
1379
1380 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1381 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1382 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1383 "Timers VNIC usage counter timed out",
1384 poll_cnt))
1385 return 1;
1386 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1387 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1388 "Timers NUM_SCANS usage counter timed out",
1389 poll_cnt))
1390 return 1;
1391
1392 /* Wait DMAE PF usage counter to zero */
1393 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1394 dmae_reg_go_c[INIT_DMAE_C(bp)],
1395 "DMAE dommand register timed out",
1396 poll_cnt))
1397 return 1;
1398
1399 return 0;
1400}
1401
1402static void bnx2x_hw_enable_status(struct bnx2x *bp)
1403{
1404 u32 val;
1405
1406 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1407 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1408
1409 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1410 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1411
1412 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1413 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1414
1415 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1416 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1417
1418 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1419 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1420
1421 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1422 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1423
1424 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1425 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1426
1427 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1428 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1429 val);
1430}
1431
1432static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1433{
1434 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1435
1436 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1437
1438 /* Re-enable PF target read access */
1439 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1440
1441 /* Poll HW usage counters */
89db4ad8 1442 DP(BNX2X_MSG_SP, "Polling usage counters\n");
619c5cb6
VZ
1443 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1444 return -EBUSY;
1445
1446 /* Zero the igu 'trailing edge' and 'leading edge' */
1447
1448 /* Send the FW cleanup command */
1449 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1450 return -EBUSY;
1451
1452 /* ATC cleanup */
1453
1454 /* Verify TX hw is flushed */
1455 bnx2x_tx_hw_flushed(bp, poll_cnt);
1456
1457 /* Wait 100ms (not adjusted according to platform) */
1458 msleep(100);
1459
1460 /* Verify no pending pci transactions */
1461 if (bnx2x_is_pcie_pending(bp->pdev))
1462 BNX2X_ERR("PCIE Transactions still pending\n");
1463
1464 /* Debug */
1465 bnx2x_hw_enable_status(bp);
1466
1467 /*
1468 * Master enable - Due to WB DMAE writes performed before this
1469 * register is re-initialized as part of the regular function init
1470 */
1471 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1472
1473 return 0;
1474}
1475
f2e0899f 1476static void bnx2x_hc_int_enable(struct bnx2x *bp)
a2fbb9ea 1477{
34f80b04 1478 int port = BP_PORT(bp);
a2fbb9ea
ET
1479 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1480 u32 val = REG_RD(bp, addr);
69c326b3
DK
1481 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1482 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1483 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
a2fbb9ea
ET
1484
1485 if (msix) {
8badd27a
EG
1486 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1487 HC_CONFIG_0_REG_INT_LINE_EN_0);
a2fbb9ea
ET
1488 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1489 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
69c326b3
DK
1490 if (single_msix)
1491 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
8badd27a
EG
1492 } else if (msi) {
1493 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1494 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1495 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1496 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
a2fbb9ea
ET
1497 } else {
1498 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
615f8fd9 1499 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
a2fbb9ea
ET
1500 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1501 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
615f8fd9 1502
a0fd065c 1503 if (!CHIP_IS_E1(bp)) {
51c1a580
MS
1504 DP(NETIF_MSG_IFUP,
1505 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
615f8fd9 1506
a0fd065c 1507 REG_WR(bp, addr, val);
615f8fd9 1508
a0fd065c
DK
1509 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1510 }
a2fbb9ea
ET
1511 }
1512
a0fd065c
DK
1513 if (CHIP_IS_E1(bp))
1514 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1515
51c1a580
MS
1516 DP(NETIF_MSG_IFUP,
1517 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1518 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
a2fbb9ea
ET
1519
1520 REG_WR(bp, addr, val);
37dbbf32
EG
1521 /*
1522 * Ensure that HC_CONFIG is written before leading/trailing edge config
1523 */
1524 mmiowb();
1525 barrier();
34f80b04 1526
f2e0899f 1527 if (!CHIP_IS_E1(bp)) {
34f80b04 1528 /* init leading/trailing edge */
fb3bff17 1529 if (IS_MF(bp)) {
3395a033 1530 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
34f80b04 1531 if (bp->port.pmf)
4acac6a5
EG
1532 /* enable nig and gpio3 attention */
1533 val |= 0x1100;
34f80b04
EG
1534 } else
1535 val = 0xffff;
1536
1537 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1538 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1539 }
37dbbf32
EG
1540
1541 /* Make sure that interrupts are indeed enabled from here on */
1542 mmiowb();
a2fbb9ea
ET
1543}
1544
f2e0899f
DK
1545static void bnx2x_igu_int_enable(struct bnx2x *bp)
1546{
1547 u32 val;
30a5de77
DK
1548 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1549 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1550 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
f2e0899f
DK
1551
1552 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1553
1554 if (msix) {
1555 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1556 IGU_PF_CONF_SINGLE_ISR_EN);
ebe61d80 1557 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f 1558 IGU_PF_CONF_ATTN_BIT_EN);
30a5de77
DK
1559
1560 if (single_msix)
1561 val |= IGU_PF_CONF_SINGLE_ISR_EN;
f2e0899f
DK
1562 } else if (msi) {
1563 val &= ~IGU_PF_CONF_INT_LINE_EN;
ebe61d80 1564 val |= (IGU_PF_CONF_MSI_MSIX_EN |
f2e0899f
DK
1565 IGU_PF_CONF_ATTN_BIT_EN |
1566 IGU_PF_CONF_SINGLE_ISR_EN);
1567 } else {
1568 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
ebe61d80 1569 val |= (IGU_PF_CONF_INT_LINE_EN |
f2e0899f
DK
1570 IGU_PF_CONF_ATTN_BIT_EN |
1571 IGU_PF_CONF_SINGLE_ISR_EN);
1572 }
1573
ebe61d80
YM
1574 /* Clean previous status - need to configure igu prior to ack*/
1575 if ((!msix) || single_msix) {
1576 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1577 bnx2x_ack_int(bp);
1578 }
1579
1580 val |= IGU_PF_CONF_FUNC_EN;
1581
51c1a580 1582 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
f2e0899f
DK
1583 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1584
1585 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1586
79a8557a
YM
1587 if (val & IGU_PF_CONF_INT_LINE_EN)
1588 pci_intx(bp->pdev, true);
1589
f2e0899f
DK
1590 barrier();
1591
1592 /* init leading/trailing edge */
1593 if (IS_MF(bp)) {
3395a033 1594 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
1595 if (bp->port.pmf)
1596 /* enable nig and gpio3 attention */
1597 val |= 0x1100;
1598 } else
1599 val = 0xffff;
1600
1601 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1602 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1603
1604 /* Make sure that interrupts are indeed enabled from here on */
1605 mmiowb();
1606}
1607
1608void bnx2x_int_enable(struct bnx2x *bp)
1609{
1610 if (bp->common.int_block == INT_BLOCK_HC)
1611 bnx2x_hc_int_enable(bp);
1612 else
1613 bnx2x_igu_int_enable(bp);
1614}
1615
9f6c9258 1616void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
a2fbb9ea 1617{
a2fbb9ea 1618 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8badd27a 1619 int i, offset;
a2fbb9ea 1620
f8ef6e44
YG
1621 if (disable_hw)
1622 /* prevent the HW from sending interrupts */
1623 bnx2x_int_disable(bp);
a2fbb9ea
ET
1624
1625 /* make sure all ISRs are done */
1626 if (msix) {
8badd27a
EG
1627 synchronize_irq(bp->msix_table[0].vector);
1628 offset = 1;
55c11941
MS
1629 if (CNIC_SUPPORT(bp))
1630 offset++;
ec6ba945 1631 for_each_eth_queue(bp, i)
754a2f52 1632 synchronize_irq(bp->msix_table[offset++].vector);
a2fbb9ea
ET
1633 } else
1634 synchronize_irq(bp->pdev->irq);
1635
1636 /* make sure sp_task is not running */
1cf167f2 1637 cancel_delayed_work(&bp->sp_task);
3deb8167 1638 cancel_delayed_work(&bp->period_task);
1cf167f2 1639 flush_workqueue(bnx2x_wq);
a2fbb9ea
ET
1640}
1641
34f80b04 1642/* fast path */
a2fbb9ea
ET
1643
1644/*
34f80b04 1645 * General service functions
a2fbb9ea
ET
1646 */
1647
72fd0718
VZ
1648/* Return true if succeeded to acquire the lock */
1649static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1650{
1651 u32 lock_status;
1652 u32 resource_bit = (1 << resource);
1653 int func = BP_FUNC(bp);
1654 u32 hw_lock_control_reg;
1655
51c1a580
MS
1656 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1657 "Trying to take a lock on resource %d\n", resource);
72fd0718
VZ
1658
1659 /* Validating that the resource is within range */
1660 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1661 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
72fd0718
VZ
1662 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1663 resource, HW_LOCK_MAX_RESOURCE_VALUE);
0fdf4d09 1664 return false;
72fd0718
VZ
1665 }
1666
1667 if (func <= 5)
1668 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1669 else
1670 hw_lock_control_reg =
1671 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1672
1673 /* Try to acquire the lock */
1674 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1675 lock_status = REG_RD(bp, hw_lock_control_reg);
1676 if (lock_status & resource_bit)
1677 return true;
1678
51c1a580
MS
1679 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1680 "Failed to get a lock on resource %d\n", resource);
72fd0718
VZ
1681 return false;
1682}
1683
c9ee9206
VZ
1684/**
1685 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1686 *
1687 * @bp: driver handle
1688 *
1689 * Returns the recovery leader resource id according to the engine this function
1690 * belongs to. Currently only only 2 engines is supported.
1691 */
1191cb83 1692static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
c9ee9206
VZ
1693{
1694 if (BP_PATH(bp))
1695 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1696 else
1697 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1698}
1699
1700/**
2de67439 1701 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
c9ee9206
VZ
1702 *
1703 * @bp: driver handle
1704 *
2de67439 1705 * Tries to acquire a leader lock for current engine.
c9ee9206 1706 */
1191cb83 1707static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
c9ee9206
VZ
1708{
1709 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1710}
1711
619c5cb6 1712static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
55c11941 1713
fd1fc79d
AE
1714/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1715static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1716{
1717 /* Set the interrupt occurred bit for the sp-task to recognize it
1718 * must ack the interrupt and transition according to the IGU
1719 * state machine.
1720 */
1721 atomic_set(&bp->interrupt_occurred, 1);
1722
1723 /* The sp_task must execute only after this bit
1724 * is set, otherwise we will get out of sync and miss all
1725 * further interrupts. Hence, the barrier.
1726 */
1727 smp_wmb();
1728
1729 /* schedule sp_task to workqueue */
1730 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1731}
3196a88a 1732
619c5cb6 1733void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
a2fbb9ea
ET
1734{
1735 struct bnx2x *bp = fp->bp;
1736 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1737 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
619c5cb6 1738 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
15192a8c 1739 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a2fbb9ea 1740
34f80b04 1741 DP(BNX2X_MSG_SP,
a2fbb9ea 1742 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
0626b899 1743 fp->index, cid, command, bp->state,
34f80b04 1744 rr_cqe->ramrod_cqe.ramrod_type);
a2fbb9ea 1745
fd1fc79d
AE
1746 /* If cid is within VF range, replace the slowpath object with the
1747 * one corresponding to this VF
1748 */
1749 if (cid >= BNX2X_FIRST_VF_CID &&
1750 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1751 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1752
619c5cb6
VZ
1753 switch (command) {
1754 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
d6cae238 1755 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
619c5cb6
VZ
1756 drv_cmd = BNX2X_Q_CMD_UPDATE;
1757 break;
d6cae238 1758
619c5cb6 1759 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
d6cae238 1760 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
619c5cb6 1761 drv_cmd = BNX2X_Q_CMD_SETUP;
a2fbb9ea
ET
1762 break;
1763
6383c0b3 1764 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
51c1a580 1765 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
6383c0b3
AE
1766 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1767 break;
1768
619c5cb6 1769 case (RAMROD_CMD_ID_ETH_HALT):
d6cae238 1770 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
619c5cb6 1771 drv_cmd = BNX2X_Q_CMD_HALT;
a2fbb9ea
ET
1772 break;
1773
619c5cb6 1774 case (RAMROD_CMD_ID_ETH_TERMINATE):
d6cae238 1775 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
619c5cb6 1776 drv_cmd = BNX2X_Q_CMD_TERMINATE;
a2fbb9ea
ET
1777 break;
1778
619c5cb6 1779 case (RAMROD_CMD_ID_ETH_EMPTY):
d6cae238 1780 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
619c5cb6 1781 drv_cmd = BNX2X_Q_CMD_EMPTY;
993ac7b5 1782 break;
619c5cb6
VZ
1783
1784 default:
1785 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1786 command, fp->index);
1787 return;
523224a3 1788 }
3196a88a 1789
619c5cb6
VZ
1790 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1791 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1792 /* q_obj->complete_cmd() failure means that this was
1793 * an unexpected completion.
1794 *
1795 * In this case we don't want to increase the bp->spq_left
1796 * because apparently we haven't sent this command the first
1797 * place.
1798 */
1799#ifdef BNX2X_STOP_ON_ERROR
1800 bnx2x_panic();
1801#else
1802 return;
1803#endif
fd1fc79d
AE
1804 /* SRIOV: reschedule any 'in_progress' operations */
1805 bnx2x_iov_sp_event(bp, cid, true);
619c5cb6 1806
8fe23fbd 1807 smp_mb__before_atomic_inc();
6e30dd4e 1808 atomic_inc(&bp->cq_spq_left);
619c5cb6
VZ
1809 /* push the change in bp->spq_left and towards the memory */
1810 smp_mb__after_atomic_inc();
49d66772 1811
d6cae238
VZ
1812 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1813
a3348722
BW
1814 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1815 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1816 /* if Q update ramrod is completed for last Q in AFEX vif set
1817 * flow, then ACK MCP at the end
1818 *
1819 * mark pending ACK to MCP bit.
1820 * prevent case that both bits are cleared.
1821 * At the end of load/unload driver checks that
2de67439 1822 * sp_state is cleared, and this order prevents
a3348722
BW
1823 * races
1824 */
1825 smp_mb__before_clear_bit();
1826 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1827 wmb();
1828 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1829 smp_mb__after_clear_bit();
1830
fd1fc79d
AE
1831 /* schedule the sp task as mcp ack is required */
1832 bnx2x_schedule_sp_task(bp);
a3348722
BW
1833 }
1834
523224a3 1835 return;
a2fbb9ea
ET
1836}
1837
9f6c9258 1838irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
a2fbb9ea 1839{
555f6c78 1840 struct bnx2x *bp = netdev_priv(dev_instance);
a2fbb9ea 1841 u16 status = bnx2x_ack_int(bp);
34f80b04 1842 u16 mask;
ca00392c 1843 int i;
6383c0b3 1844 u8 cos;
a2fbb9ea 1845
34f80b04 1846 /* Return here if interrupt is shared and it's not for us */
a2fbb9ea
ET
1847 if (unlikely(status == 0)) {
1848 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1849 return IRQ_NONE;
1850 }
f5372251 1851 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
a2fbb9ea 1852
3196a88a
EG
1853#ifdef BNX2X_STOP_ON_ERROR
1854 if (unlikely(bp->panic))
1855 return IRQ_HANDLED;
1856#endif
1857
ec6ba945 1858 for_each_eth_queue(bp, i) {
ca00392c 1859 struct bnx2x_fastpath *fp = &bp->fp[i];
a2fbb9ea 1860
55c11941 1861 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
ca00392c 1862 if (status & mask) {
619c5cb6 1863 /* Handle Rx or Tx according to SB id */
54b9ddaa 1864 prefetch(fp->rx_cons_sb);
6383c0b3 1865 for_each_cos_in_tx_queue(fp, cos)
65565884 1866 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
523224a3 1867 prefetch(&fp->sb_running_index[SM_RX_ID]);
54b9ddaa 1868 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
ca00392c
EG
1869 status &= ~mask;
1870 }
a2fbb9ea
ET
1871 }
1872
55c11941
MS
1873 if (CNIC_SUPPORT(bp)) {
1874 mask = 0x2;
1875 if (status & (mask | 0x1)) {
1876 struct cnic_ops *c_ops = NULL;
993ac7b5 1877
55c11941
MS
1878 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1879 rcu_read_lock();
1880 c_ops = rcu_dereference(bp->cnic_ops);
1881 if (c_ops)
1882 c_ops->cnic_handler(bp->cnic_data,
1883 NULL);
1884 rcu_read_unlock();
1885 }
993ac7b5 1886
55c11941
MS
1887 status &= ~mask;
1888 }
993ac7b5 1889 }
a2fbb9ea 1890
34f80b04 1891 if (unlikely(status & 0x1)) {
fd1fc79d
AE
1892
1893 /* schedule sp task to perform default status block work, ack
1894 * attentions and enable interrupts.
1895 */
1896 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
1897
1898 status &= ~0x1;
1899 if (!status)
1900 return IRQ_HANDLED;
1901 }
1902
cdaa7cb8
VZ
1903 if (unlikely(status))
1904 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
34f80b04 1905 status);
a2fbb9ea 1906
c18487ee 1907 return IRQ_HANDLED;
a2fbb9ea
ET
1908}
1909
c18487ee
YR
1910/* Link */
1911
1912/*
1913 * General service functions
1914 */
a2fbb9ea 1915
9f6c9258 1916int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1917{
1918 u32 lock_status;
1919 u32 resource_bit = (1 << resource);
4a37fb66
YG
1920 int func = BP_FUNC(bp);
1921 u32 hw_lock_control_reg;
c18487ee 1922 int cnt;
a2fbb9ea 1923
c18487ee
YR
1924 /* Validating that the resource is within range */
1925 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1926 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1927 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1928 return -EINVAL;
1929 }
a2fbb9ea 1930
4a37fb66
YG
1931 if (func <= 5) {
1932 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1933 } else {
1934 hw_lock_control_reg =
1935 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1936 }
1937
c18487ee 1938 /* Validating that the resource is not already taken */
4a37fb66 1939 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1940 if (lock_status & resource_bit) {
51c1a580 1941 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
c18487ee
YR
1942 lock_status, resource_bit);
1943 return -EEXIST;
1944 }
a2fbb9ea 1945
46230476
EG
1946 /* Try for 5 second every 5ms */
1947 for (cnt = 0; cnt < 1000; cnt++) {
c18487ee 1948 /* Try to acquire the lock */
4a37fb66
YG
1949 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1950 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee
YR
1951 if (lock_status & resource_bit)
1952 return 0;
a2fbb9ea 1953
c18487ee 1954 msleep(5);
a2fbb9ea 1955 }
51c1a580 1956 BNX2X_ERR("Timeout\n");
c18487ee
YR
1957 return -EAGAIN;
1958}
a2fbb9ea 1959
c9ee9206
VZ
1960int bnx2x_release_leader_lock(struct bnx2x *bp)
1961{
1962 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1963}
1964
9f6c9258 1965int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
c18487ee
YR
1966{
1967 u32 lock_status;
1968 u32 resource_bit = (1 << resource);
4a37fb66
YG
1969 int func = BP_FUNC(bp);
1970 u32 hw_lock_control_reg;
a2fbb9ea 1971
c18487ee
YR
1972 /* Validating that the resource is within range */
1973 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
51c1a580 1974 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
c18487ee
YR
1975 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1976 return -EINVAL;
1977 }
1978
4a37fb66
YG
1979 if (func <= 5) {
1980 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1981 } else {
1982 hw_lock_control_reg =
1983 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1984 }
1985
c18487ee 1986 /* Validating that the resource is currently taken */
4a37fb66 1987 lock_status = REG_RD(bp, hw_lock_control_reg);
c18487ee 1988 if (!(lock_status & resource_bit)) {
51c1a580 1989 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
c18487ee
YR
1990 lock_status, resource_bit);
1991 return -EFAULT;
a2fbb9ea
ET
1992 }
1993
9f6c9258
DK
1994 REG_WR(bp, hw_lock_control_reg, resource_bit);
1995 return 0;
c18487ee 1996}
a2fbb9ea 1997
9f6c9258 1998
4acac6a5
EG
1999int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2000{
2001 /* The GPIO should be swapped if swap register is set and active */
2002 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2003 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2004 int gpio_shift = gpio_num +
2005 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2006 u32 gpio_mask = (1 << gpio_shift);
2007 u32 gpio_reg;
2008 int value;
2009
2010 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2011 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2012 return -EINVAL;
2013 }
2014
2015 /* read GPIO value */
2016 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2017
2018 /* get the requested pin value */
2019 if ((gpio_reg & gpio_mask) == gpio_mask)
2020 value = 1;
2021 else
2022 value = 0;
2023
2024 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2025
2026 return value;
2027}
2028
17de50b7 2029int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
c18487ee
YR
2030{
2031 /* The GPIO should be swapped if swap register is set and active */
2032 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
17de50b7 2033 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
c18487ee
YR
2034 int gpio_shift = gpio_num +
2035 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2036 u32 gpio_mask = (1 << gpio_shift);
2037 u32 gpio_reg;
a2fbb9ea 2038
c18487ee
YR
2039 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2040 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2041 return -EINVAL;
2042 }
a2fbb9ea 2043
4a37fb66 2044 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
c18487ee
YR
2045 /* read GPIO and mask except the float bits */
2046 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
a2fbb9ea 2047
c18487ee
YR
2048 switch (mode) {
2049 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
51c1a580
MS
2050 DP(NETIF_MSG_LINK,
2051 "Set GPIO %d (shift %d) -> output low\n",
c18487ee
YR
2052 gpio_num, gpio_shift);
2053 /* clear FLOAT and set CLR */
2054 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2055 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2056 break;
a2fbb9ea 2057
c18487ee 2058 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
51c1a580
MS
2059 DP(NETIF_MSG_LINK,
2060 "Set GPIO %d (shift %d) -> output high\n",
c18487ee
YR
2061 gpio_num, gpio_shift);
2062 /* clear FLOAT and set SET */
2063 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2064 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2065 break;
a2fbb9ea 2066
17de50b7 2067 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
51c1a580
MS
2068 DP(NETIF_MSG_LINK,
2069 "Set GPIO %d (shift %d) -> input\n",
c18487ee
YR
2070 gpio_num, gpio_shift);
2071 /* set FLOAT */
2072 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2073 break;
a2fbb9ea 2074
c18487ee
YR
2075 default:
2076 break;
a2fbb9ea
ET
2077 }
2078
c18487ee 2079 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
4a37fb66 2080 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
f1410647 2081
c18487ee 2082 return 0;
a2fbb9ea
ET
2083}
2084
0d40f0d4
YR
2085int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2086{
2087 u32 gpio_reg = 0;
2088 int rc = 0;
2089
2090 /* Any port swapping should be handled by caller. */
2091
2092 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2093 /* read GPIO and mask except the float bits */
2094 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2095 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2096 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2097 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2098
2099 switch (mode) {
2100 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2101 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2102 /* set CLR */
2103 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2104 break;
2105
2106 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2107 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2108 /* set SET */
2109 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2110 break;
2111
2112 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2113 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2114 /* set FLOAT */
2115 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2116 break;
2117
2118 default:
2119 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2120 rc = -EINVAL;
2121 break;
2122 }
2123
2124 if (rc == 0)
2125 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2126
2127 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2128
2129 return rc;
2130}
2131
4acac6a5
EG
2132int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2133{
2134 /* The GPIO should be swapped if swap register is set and active */
2135 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2136 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2137 int gpio_shift = gpio_num +
2138 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2139 u32 gpio_mask = (1 << gpio_shift);
2140 u32 gpio_reg;
2141
2142 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2143 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2144 return -EINVAL;
2145 }
2146
2147 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2148 /* read GPIO int */
2149 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2150
2151 switch (mode) {
2152 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
51c1a580
MS
2153 DP(NETIF_MSG_LINK,
2154 "Clear GPIO INT %d (shift %d) -> output low\n",
2155 gpio_num, gpio_shift);
4acac6a5
EG
2156 /* clear SET and set CLR */
2157 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2158 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2159 break;
2160
2161 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
51c1a580
MS
2162 DP(NETIF_MSG_LINK,
2163 "Set GPIO INT %d (shift %d) -> output high\n",
2164 gpio_num, gpio_shift);
4acac6a5
EG
2165 /* clear CLR and set SET */
2166 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2167 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2168 break;
2169
2170 default:
2171 break;
2172 }
2173
2174 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2175 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2176
2177 return 0;
2178}
2179
d6d99a3f 2180static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
a2fbb9ea 2181{
c18487ee 2182 u32 spio_reg;
a2fbb9ea 2183
d6d99a3f
YM
2184 /* Only 2 SPIOs are configurable */
2185 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2186 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
c18487ee 2187 return -EINVAL;
a2fbb9ea
ET
2188 }
2189
4a37fb66 2190 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2191 /* read SPIO and mask except the float bits */
d6d99a3f 2192 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
a2fbb9ea 2193
c18487ee 2194 switch (mode) {
d6d99a3f
YM
2195 case MISC_SPIO_OUTPUT_LOW:
2196 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
c18487ee 2197 /* clear FLOAT and set CLR */
d6d99a3f
YM
2198 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2199 spio_reg |= (spio << MISC_SPIO_CLR_POS);
c18487ee 2200 break;
a2fbb9ea 2201
d6d99a3f
YM
2202 case MISC_SPIO_OUTPUT_HIGH:
2203 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
c18487ee 2204 /* clear FLOAT and set SET */
d6d99a3f
YM
2205 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2206 spio_reg |= (spio << MISC_SPIO_SET_POS);
c18487ee 2207 break;
a2fbb9ea 2208
d6d99a3f
YM
2209 case MISC_SPIO_INPUT_HI_Z:
2210 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
c18487ee 2211 /* set FLOAT */
d6d99a3f 2212 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
c18487ee 2213 break;
a2fbb9ea 2214
c18487ee
YR
2215 default:
2216 break;
a2fbb9ea
ET
2217 }
2218
c18487ee 2219 REG_WR(bp, MISC_REG_SPIO, spio_reg);
4a37fb66 2220 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
c18487ee 2221
a2fbb9ea
ET
2222 return 0;
2223}
2224
9f6c9258 2225void bnx2x_calc_fc_adv(struct bnx2x *bp)
a2fbb9ea 2226{
a22f0788 2227 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
ad33ea3a
EG
2228 switch (bp->link_vars.ieee_fc &
2229 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
c18487ee 2230 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
a22f0788 2231 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2232 ADVERTISED_Pause);
c18487ee 2233 break;
356e2385 2234
c18487ee 2235 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
a22f0788 2236 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
f85582f8 2237 ADVERTISED_Pause);
c18487ee 2238 break;
356e2385 2239
c18487ee 2240 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
a22f0788 2241 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
c18487ee 2242 break;
356e2385 2243
c18487ee 2244 default:
a22f0788 2245 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
f85582f8 2246 ADVERTISED_Pause);
c18487ee
YR
2247 break;
2248 }
2249}
f1410647 2250
cd1dfce2 2251static void bnx2x_set_requested_fc(struct bnx2x *bp)
c18487ee 2252{
cd1dfce2
YM
2253 /* Initialize link parameters structure variables
2254 * It is recommended to turn off RX FC for jumbo frames
2255 * for better performance
2256 */
2257 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2258 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2259 else
2260 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2261}
a2fbb9ea 2262
cd1dfce2
YM
2263int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2264{
2265 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2266 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2267
2268 if (!BP_NOMCP(bp)) {
2269 bnx2x_set_requested_fc(bp);
4a37fb66 2270 bnx2x_acquire_phy_lock(bp);
b5bf9068 2271
a22f0788 2272 if (load_mode == LOAD_DIAG) {
1cb0c788
YR
2273 struct link_params *lp = &bp->link_params;
2274 lp->loopback_mode = LOOPBACK_XGXS;
2275 /* do PHY loopback at 10G speed, if possible */
2276 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2277 if (lp->speed_cap_mask[cfx_idx] &
2278 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2279 lp->req_line_speed[cfx_idx] =
2280 SPEED_10000;
2281 else
2282 lp->req_line_speed[cfx_idx] =
2283 SPEED_1000;
2284 }
a22f0788 2285 }
b5bf9068 2286
8970b2e4
MS
2287 if (load_mode == LOAD_LOOPBACK_EXT) {
2288 struct link_params *lp = &bp->link_params;
2289 lp->loopback_mode = LOOPBACK_EXT;
2290 }
2291
19680c48 2292 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
b5bf9068 2293
4a37fb66 2294 bnx2x_release_phy_lock(bp);
a2fbb9ea 2295
3c96c68b
EG
2296 bnx2x_calc_fc_adv(bp);
2297
cd1dfce2 2298 if (bp->link_vars.link_up) {
b5bf9068 2299 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
19680c48 2300 bnx2x_link_report(bp);
cd1dfce2
YM
2301 }
2302 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
a22f0788 2303 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
19680c48
EG
2304 return rc;
2305 }
f5372251 2306 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
19680c48 2307 return -EINVAL;
a2fbb9ea
ET
2308}
2309
9f6c9258 2310void bnx2x_link_set(struct bnx2x *bp)
a2fbb9ea 2311{
19680c48 2312 if (!BP_NOMCP(bp)) {
4a37fb66 2313 bnx2x_acquire_phy_lock(bp);
19680c48 2314 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
4a37fb66 2315 bnx2x_release_phy_lock(bp);
a2fbb9ea 2316
19680c48
EG
2317 bnx2x_calc_fc_adv(bp);
2318 } else
f5372251 2319 BNX2X_ERR("Bootcode is missing - can not set link\n");
c18487ee 2320}
a2fbb9ea 2321
c18487ee
YR
2322static void bnx2x__link_reset(struct bnx2x *bp)
2323{
19680c48 2324 if (!BP_NOMCP(bp)) {
4a37fb66 2325 bnx2x_acquire_phy_lock(bp);
5d07d868 2326 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
4a37fb66 2327 bnx2x_release_phy_lock(bp);
19680c48 2328 } else
f5372251 2329 BNX2X_ERR("Bootcode is missing - can not reset link\n");
c18487ee 2330}
a2fbb9ea 2331
5d07d868
YM
2332void bnx2x_force_link_reset(struct bnx2x *bp)
2333{
2334 bnx2x_acquire_phy_lock(bp);
2335 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2336 bnx2x_release_phy_lock(bp);
2337}
2338
a22f0788 2339u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
c18487ee 2340{
2145a920 2341 u8 rc = 0;
a2fbb9ea 2342
2145a920
VZ
2343 if (!BP_NOMCP(bp)) {
2344 bnx2x_acquire_phy_lock(bp);
a22f0788
YR
2345 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2346 is_serdes);
2145a920
VZ
2347 bnx2x_release_phy_lock(bp);
2348 } else
2349 BNX2X_ERR("Bootcode is missing - can not test link\n");
a2fbb9ea 2350
c18487ee
YR
2351 return rc;
2352}
a2fbb9ea 2353
34f80b04 2354
2691d51d
EG
2355/* Calculates the sum of vn_min_rates.
2356 It's needed for further normalizing of the min_rates.
2357 Returns:
2358 sum of vn_min_rates.
2359 or
2360 0 - if all the min_rates are 0.
2361 In the later case fainess algorithm should be deactivated.
2362 If not all min_rates are zero then those that are zeroes will be set to 1.
2363 */
b475d78f
YM
2364static void bnx2x_calc_vn_min(struct bnx2x *bp,
2365 struct cmng_init_input *input)
2691d51d
EG
2366{
2367 int all_zero = 1;
2691d51d
EG
2368 int vn;
2369
3395a033 2370 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
f2e0899f 2371 u32 vn_cfg = bp->mf_config[vn];
2691d51d
EG
2372 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2373 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2374
2375 /* Skip hidden vns */
2376 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
b475d78f 2377 vn_min_rate = 0;
2691d51d 2378 /* If min rate is zero - set it to 1 */
b475d78f 2379 else if (!vn_min_rate)
2691d51d
EG
2380 vn_min_rate = DEF_MIN_RATE;
2381 else
2382 all_zero = 0;
2383
b475d78f 2384 input->vnic_min_rate[vn] = vn_min_rate;
2691d51d
EG
2385 }
2386
30ae438b
DK
2387 /* if ETS or all min rates are zeros - disable fairness */
2388 if (BNX2X_IS_ETS_ENABLED(bp)) {
b475d78f 2389 input->flags.cmng_enables &=
30ae438b
DK
2390 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2391 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2392 } else if (all_zero) {
b475d78f 2393 input->flags.cmng_enables &=
b015e3d1 2394 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
b475d78f
YM
2395 DP(NETIF_MSG_IFUP,
2396 "All MIN values are zeroes fairness will be disabled\n");
b015e3d1 2397 } else
b475d78f 2398 input->flags.cmng_enables |=
b015e3d1 2399 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2691d51d
EG
2400}
2401
b475d78f
YM
2402static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2403 struct cmng_init_input *input)
34f80b04 2404{
b475d78f 2405 u16 vn_max_rate;
f2e0899f 2406 u32 vn_cfg = bp->mf_config[vn];
34f80b04 2407
b475d78f 2408 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
34f80b04 2409 vn_max_rate = 0;
b475d78f 2410 else {
faa6fcbb
DK
2411 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2412
b475d78f 2413 if (IS_MF_SI(bp)) {
faa6fcbb
DK
2414 /* maxCfg in percents of linkspeed */
2415 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
b475d78f 2416 } else /* SD modes */
faa6fcbb
DK
2417 /* maxCfg is absolute in 100Mb units */
2418 vn_max_rate = maxCfg * 100;
34f80b04 2419 }
f85582f8 2420
b475d78f 2421 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
34f80b04 2422
b475d78f 2423 input->vnic_max_rate[vn] = vn_max_rate;
34f80b04 2424}
f85582f8 2425
b475d78f 2426
523224a3
DK
2427static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2428{
2429 if (CHIP_REV_IS_SLOW(bp))
2430 return CMNG_FNS_NONE;
fb3bff17 2431 if (IS_MF(bp))
523224a3
DK
2432 return CMNG_FNS_MINMAX;
2433
2434 return CMNG_FNS_NONE;
2435}
2436
2ae17f66 2437void bnx2x_read_mf_cfg(struct bnx2x *bp)
523224a3 2438{
0793f83f 2439 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
523224a3
DK
2440
2441 if (BP_NOMCP(bp))
2442 return; /* what should be the default bvalue in this case */
2443
0793f83f
DK
2444 /* For 2 port configuration the absolute function number formula
2445 * is:
2446 * abs_func = 2 * vn + BP_PORT + BP_PATH
2447 *
2448 * and there are 4 functions per port
2449 *
2450 * For 4 port configuration it is
2451 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2452 *
2453 * and there are 2 functions per port
2454 */
3395a033 2455 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
0793f83f
DK
2456 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2457
2458 if (func >= E1H_FUNC_MAX)
2459 break;
2460
f2e0899f 2461 bp->mf_config[vn] =
523224a3
DK
2462 MF_CFG_RD(bp, func_mf_config[func].config);
2463 }
a3348722
BW
2464 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2465 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2466 bp->flags |= MF_FUNC_DIS;
2467 } else {
2468 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2469 bp->flags &= ~MF_FUNC_DIS;
2470 }
523224a3
DK
2471}
2472
2473static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2474{
b475d78f
YM
2475 struct cmng_init_input input;
2476 memset(&input, 0, sizeof(struct cmng_init_input));
2477
2478 input.port_rate = bp->link_vars.line_speed;
523224a3
DK
2479
2480 if (cmng_type == CMNG_FNS_MINMAX) {
2481 int vn;
2482
523224a3
DK
2483 /* read mf conf from shmem */
2484 if (read_cfg)
2485 bnx2x_read_mf_cfg(bp);
2486
523224a3 2487 /* vn_weight_sum and enable fairness if not 0 */
b475d78f 2488 bnx2x_calc_vn_min(bp, &input);
523224a3
DK
2489
2490 /* calculate and set min-max rate for each vn */
c4154f25 2491 if (bp->port.pmf)
3395a033 2492 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
b475d78f 2493 bnx2x_calc_vn_max(bp, vn, &input);
523224a3
DK
2494
2495 /* always enable rate shaping and fairness */
b475d78f 2496 input.flags.cmng_enables |=
523224a3 2497 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
b475d78f
YM
2498
2499 bnx2x_init_cmng(&input, &bp->cmng);
523224a3
DK
2500 return;
2501 }
2502
2503 /* rate shaping and fairness are disabled */
2504 DP(NETIF_MSG_IFUP,
2505 "rate shaping and fairness are disabled\n");
2506}
34f80b04 2507
1191cb83
ED
2508static void storm_memset_cmng(struct bnx2x *bp,
2509 struct cmng_init *cmng,
2510 u8 port)
2511{
2512 int vn;
2513 size_t size = sizeof(struct cmng_struct_per_port);
2514
2515 u32 addr = BAR_XSTRORM_INTMEM +
2516 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2517
2518 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2519
2520 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2521 int func = func_by_vn(bp, vn);
2522
2523 addr = BAR_XSTRORM_INTMEM +
2524 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2525 size = sizeof(struct rate_shaping_vars_per_vn);
2526 __storm_memset_struct(bp, addr, size,
2527 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2528
2529 addr = BAR_XSTRORM_INTMEM +
2530 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2531 size = sizeof(struct fairness_vars_per_vn);
2532 __storm_memset_struct(bp, addr, size,
2533 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2534 }
2535}
2536
c18487ee
YR
2537/* This function is called upon link interrupt */
2538static void bnx2x_link_attn(struct bnx2x *bp)
2539{
bb2a0f7a
YG
2540 /* Make sure that we are synced with the current statistics */
2541 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2542
c18487ee 2543 bnx2x_link_update(&bp->link_params, &bp->link_vars);
a2fbb9ea 2544
bb2a0f7a
YG
2545 if (bp->link_vars.link_up) {
2546
1c06328c 2547 /* dropless flow control */
f2e0899f 2548 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
1c06328c
EG
2549 int port = BP_PORT(bp);
2550 u32 pause_enabled = 0;
2551
2552 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2553 pause_enabled = 1;
2554
2555 REG_WR(bp, BAR_USTRORM_INTMEM +
ca00392c 2556 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
1c06328c
EG
2557 pause_enabled);
2558 }
2559
619c5cb6 2560 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
bb2a0f7a
YG
2561 struct host_port_stats *pstats;
2562
2563 pstats = bnx2x_sp(bp, port_stats);
619c5cb6 2564 /* reset old mac stats */
bb2a0f7a
YG
2565 memset(&(pstats->mac_stx[0]), 0,
2566 sizeof(struct mac_stx));
2567 }
f34d28ea 2568 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a
YG
2569 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2570 }
2571
f2e0899f
DK
2572 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2573 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
8a1c38d1 2574
f2e0899f
DK
2575 if (cmng_fns != CMNG_FNS_NONE) {
2576 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2577 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2578 } else
2579 /* rate shaping and fairness are disabled */
2580 DP(NETIF_MSG_IFUP,
2581 "single function mode without fairness\n");
34f80b04 2582 }
9fdc3e95 2583
2ae17f66
VZ
2584 __bnx2x_link_report(bp);
2585
9fdc3e95
DK
2586 if (IS_MF(bp))
2587 bnx2x_link_sync_notify(bp);
c18487ee 2588}
a2fbb9ea 2589
9f6c9258 2590void bnx2x__link_status_update(struct bnx2x *bp)
c18487ee 2591{
2ae17f66 2592 if (bp->state != BNX2X_STATE_OPEN)
c18487ee 2593 return;
a2fbb9ea 2594
00253a8c 2595 /* read updated dcb configuration */
ad5afc89
AE
2596 if (IS_PF(bp)) {
2597 bnx2x_dcbx_pmf_update(bp);
2598 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2599 if (bp->link_vars.link_up)
2600 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2601 else
2602 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2603 /* indicate link status */
2604 bnx2x_link_report(bp);
a2fbb9ea 2605
ad5afc89
AE
2606 } else { /* VF */
2607 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2608 SUPPORTED_10baseT_Full |
2609 SUPPORTED_100baseT_Half |
2610 SUPPORTED_100baseT_Full |
2611 SUPPORTED_1000baseT_Full |
2612 SUPPORTED_2500baseX_Full |
2613 SUPPORTED_10000baseT_Full |
2614 SUPPORTED_TP |
2615 SUPPORTED_FIBRE |
2616 SUPPORTED_Autoneg |
2617 SUPPORTED_Pause |
2618 SUPPORTED_Asym_Pause);
2619 bp->port.advertising[0] = bp->port.supported[0];
2620
2621 bp->link_params.bp = bp;
2622 bp->link_params.port = BP_PORT(bp);
2623 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2624 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2625 bp->link_params.req_line_speed[0] = SPEED_10000;
2626 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2627 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2628 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2629 bp->link_vars.line_speed = SPEED_10000;
2630 bp->link_vars.link_status =
2631 (LINK_STATUS_LINK_UP |
2632 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2633 bp->link_vars.link_up = 1;
2634 bp->link_vars.duplex = DUPLEX_FULL;
2635 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2636 __bnx2x_link_report(bp);
bb2a0f7a 2637 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
ad5afc89 2638 }
a2fbb9ea 2639}
a2fbb9ea 2640
a3348722
BW
2641static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2642 u16 vlan_val, u8 allowed_prio)
2643{
86564c3f 2644 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2645 struct bnx2x_func_afex_update_params *f_update_params =
2646 &func_params.params.afex_update;
2647
2648 func_params.f_obj = &bp->func_obj;
2649 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2650
2651 /* no need to wait for RAMROD completion, so don't
2652 * set RAMROD_COMP_WAIT flag
2653 */
2654
2655 f_update_params->vif_id = vifid;
2656 f_update_params->afex_default_vlan = vlan_val;
2657 f_update_params->allowed_priorities = allowed_prio;
2658
2659 /* if ramrod can not be sent, response to MCP immediately */
2660 if (bnx2x_func_state_change(bp, &func_params) < 0)
2661 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2662
2663 return 0;
2664}
2665
2666static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2667 u16 vif_index, u8 func_bit_map)
2668{
86564c3f 2669 struct bnx2x_func_state_params func_params = {NULL};
a3348722
BW
2670 struct bnx2x_func_afex_viflists_params *update_params =
2671 &func_params.params.afex_viflists;
2672 int rc;
2673 u32 drv_msg_code;
2674
2675 /* validate only LIST_SET and LIST_GET are received from switch */
2676 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2677 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2678 cmd_type);
2679
2680 func_params.f_obj = &bp->func_obj;
2681 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2682
2683 /* set parameters according to cmd_type */
2684 update_params->afex_vif_list_command = cmd_type;
86564c3f 2685 update_params->vif_list_index = vif_index;
a3348722
BW
2686 update_params->func_bit_map =
2687 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2688 update_params->func_to_clear = 0;
2689 drv_msg_code =
2690 (cmd_type == VIF_LIST_RULE_GET) ?
2691 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2692 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2693
2694 /* if ramrod can not be sent, respond to MCP immediately for
2695 * SET and GET requests (other are not triggered from MCP)
2696 */
2697 rc = bnx2x_func_state_change(bp, &func_params);
2698 if (rc < 0)
2699 bnx2x_fw_command(bp, drv_msg_code, 0);
2700
2701 return 0;
2702}
2703
2704static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2705{
2706 struct afex_stats afex_stats;
2707 u32 func = BP_ABS_FUNC(bp);
2708 u32 mf_config;
2709 u16 vlan_val;
2710 u32 vlan_prio;
2711 u16 vif_id;
2712 u8 allowed_prio;
2713 u8 vlan_mode;
2714 u32 addr_to_write, vifid, addrs, stats_type, i;
2715
2716 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2717 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2718 DP(BNX2X_MSG_MCP,
2719 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2720 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2721 }
2722
2723 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2724 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2725 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2726 DP(BNX2X_MSG_MCP,
2727 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2728 vifid, addrs);
2729 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2730 addrs);
2731 }
2732
2733 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2734 addr_to_write = SHMEM2_RD(bp,
2735 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2736 stats_type = SHMEM2_RD(bp,
2737 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2738
2739 DP(BNX2X_MSG_MCP,
2740 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2741 addr_to_write);
2742
2743 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2744
2745 /* write response to scratchpad, for MCP */
2746 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2747 REG_WR(bp, addr_to_write + i*sizeof(u32),
2748 *(((u32 *)(&afex_stats))+i));
2749
2750 /* send ack message to MCP */
2751 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2752 }
2753
2754 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2755 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2756 bp->mf_config[BP_VN(bp)] = mf_config;
2757 DP(BNX2X_MSG_MCP,
2758 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2759 mf_config);
2760
2761 /* if VIF_SET is "enabled" */
2762 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2763 /* set rate limit directly to internal RAM */
2764 struct cmng_init_input cmng_input;
2765 struct rate_shaping_vars_per_vn m_rs_vn;
2766 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2767 u32 addr = BAR_XSTRORM_INTMEM +
2768 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2769
2770 bp->mf_config[BP_VN(bp)] = mf_config;
2771
2772 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2773 m_rs_vn.vn_counter.rate =
2774 cmng_input.vnic_max_rate[BP_VN(bp)];
2775 m_rs_vn.vn_counter.quota =
2776 (m_rs_vn.vn_counter.rate *
2777 RS_PERIODIC_TIMEOUT_USEC) / 8;
2778
2779 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2780
2781 /* read relevant values from mf_cfg struct in shmem */
2782 vif_id =
2783 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2784 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2785 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2786 vlan_val =
2787 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2788 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2789 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2790 vlan_prio = (mf_config &
2791 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2792 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2793 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2794 vlan_mode =
2795 (MF_CFG_RD(bp,
2796 func_mf_config[func].afex_config) &
2797 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2798 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2799 allowed_prio =
2800 (MF_CFG_RD(bp,
2801 func_mf_config[func].afex_config) &
2802 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2803 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2804
2805 /* send ramrod to FW, return in case of failure */
2806 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2807 allowed_prio))
2808 return;
2809
2810 bp->afex_def_vlan_tag = vlan_val;
2811 bp->afex_vlan_mode = vlan_mode;
2812 } else {
2813 /* notify link down because BP->flags is disabled */
2814 bnx2x_link_report(bp);
2815
2816 /* send INVALID VIF ramrod to FW */
2817 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2818
2819 /* Reset the default afex VLAN */
2820 bp->afex_def_vlan_tag = -1;
2821 }
2822 }
2823}
2824
34f80b04
EG
2825static void bnx2x_pmf_update(struct bnx2x *bp)
2826{
2827 int port = BP_PORT(bp);
2828 u32 val;
2829
2830 bp->port.pmf = 1;
51c1a580 2831 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
34f80b04 2832
3deb8167
YR
2833 /*
2834 * We need the mb() to ensure the ordering between the writing to
2835 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2836 */
2837 smp_mb();
2838
2839 /* queue a periodic task */
2840 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2841
ef01854e
DK
2842 bnx2x_dcbx_pmf_update(bp);
2843
34f80b04 2844 /* enable nig attention */
3395a033 2845 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
f2e0899f
DK
2846 if (bp->common.int_block == INT_BLOCK_HC) {
2847 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2848 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
619c5cb6 2849 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
2850 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2851 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2852 }
bb2a0f7a
YG
2853
2854 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
34f80b04
EG
2855}
2856
c18487ee 2857/* end of Link */
a2fbb9ea
ET
2858
2859/* slow path */
2860
2861/*
2862 * General service functions
2863 */
2864
2691d51d 2865/* send the MCP a request, block until there is a reply */
a22f0788 2866u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2691d51d 2867{
f2e0899f 2868 int mb_idx = BP_FW_MB_IDX(bp);
a5971d43 2869 u32 seq;
2691d51d
EG
2870 u32 rc = 0;
2871 u32 cnt = 1;
2872 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2873
c4ff7cbf 2874 mutex_lock(&bp->fw_mb_mutex);
a5971d43 2875 seq = ++bp->fw_seq;
f2e0899f
DK
2876 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2877 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2878
754a2f52
DK
2879 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2880 (command | seq), param);
2691d51d
EG
2881
2882 do {
2883 /* let the FW do it's magic ... */
2884 msleep(delay);
2885
f2e0899f 2886 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2691d51d 2887
c4ff7cbf
EG
2888 /* Give the FW up to 5 second (500*10ms) */
2889 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2691d51d
EG
2890
2891 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2892 cnt*delay, rc, seq);
2893
2894 /* is this a reply to our command? */
2895 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2896 rc &= FW_MSG_CODE_MASK;
2897 else {
2898 /* FW BUG! */
2899 BNX2X_ERR("FW failed to respond!\n");
2900 bnx2x_fw_dump(bp);
2901 rc = 0;
2902 }
c4ff7cbf 2903 mutex_unlock(&bp->fw_mb_mutex);
2691d51d
EG
2904
2905 return rc;
2906}
2907
ec6ba945 2908
1191cb83
ED
2909static void storm_memset_func_cfg(struct bnx2x *bp,
2910 struct tstorm_eth_function_common_config *tcfg,
2911 u16 abs_fid)
2912{
2913 size_t size = sizeof(struct tstorm_eth_function_common_config);
2914
2915 u32 addr = BAR_TSTRORM_INTMEM +
2916 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2917
2918 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2919}
2920
619c5cb6
VZ
2921void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2922{
2923 if (CHIP_IS_E1x(bp)) {
2924 struct tstorm_eth_function_common_config tcfg = {0};
2925
2926 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2927 }
2928
2929 /* Enable the function in the FW */
2930 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2931 storm_memset_func_en(bp, p->func_id, 1);
2932
2933 /* spq */
2934 if (p->func_flgs & FUNC_FLG_SPQ) {
2935 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2936 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2937 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2938 }
2939}
2940
6383c0b3
AE
2941/**
2942 * bnx2x_get_tx_only_flags - Return common flags
2943 *
2944 * @bp device handle
2945 * @fp queue handle
2946 * @zero_stats TRUE if statistics zeroing is needed
2947 *
2948 * Return the flags that are common for the Tx-only and not normal connections.
2949 */
1191cb83
ED
2950static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2951 struct bnx2x_fastpath *fp,
2952 bool zero_stats)
28912902 2953{
619c5cb6
VZ
2954 unsigned long flags = 0;
2955
2956 /* PF driver will always initialize the Queue to an ACTIVE state */
2957 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
28912902 2958
6383c0b3
AE
2959 /* tx only connections collect statistics (on the same index as the
2960 * parent connection). The statistics are zeroed when the parent
2961 * connection is initialized.
2962 */
50f0a562
BW
2963
2964 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2965 if (zero_stats)
2966 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2967
6383c0b3 2968
823e1d90
YM
2969#ifdef BNX2X_STOP_ON_ERROR
2970 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
2971#endif
2972
6383c0b3
AE
2973 return flags;
2974}
2975
1191cb83
ED
2976static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2977 struct bnx2x_fastpath *fp,
2978 bool leading)
6383c0b3
AE
2979{
2980 unsigned long flags = 0;
2981
619c5cb6
VZ
2982 /* calculate other queue flags */
2983 if (IS_MF_SD(bp))
2984 __set_bit(BNX2X_Q_FLG_OV, &flags);
28912902 2985
a3348722 2986 if (IS_FCOE_FP(fp)) {
619c5cb6 2987 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
a3348722
BW
2988 /* For FCoE - force usage of default priority (for afex) */
2989 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2990 }
523224a3 2991
f5219d8e 2992 if (!fp->disable_tpa) {
619c5cb6 2993 __set_bit(BNX2X_Q_FLG_TPA, &flags);
f5219d8e 2994 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
621b4d66
DK
2995 if (fp->mode == TPA_MODE_GRO)
2996 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
f5219d8e 2997 }
619c5cb6 2998
619c5cb6
VZ
2999 if (leading) {
3000 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3001 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3002 }
523224a3 3003
619c5cb6
VZ
3004 /* Always set HW VLAN stripping */
3005 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
523224a3 3006
a3348722
BW
3007 /* configure silent vlan removal */
3008 if (IS_MF_AFEX(bp))
3009 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3010
6383c0b3
AE
3011
3012 return flags | bnx2x_get_common_flags(bp, fp, true);
523224a3
DK
3013}
3014
619c5cb6 3015static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
6383c0b3
AE
3016 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3017 u8 cos)
619c5cb6
VZ
3018{
3019 gen_init->stat_id = bnx2x_stats_id(fp);
3020 gen_init->spcl_id = fp->cl_id;
3021
3022 /* Always use mini-jumbo MTU for FCoE L2 ring */
3023 if (IS_FCOE_FP(fp))
3024 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3025 else
3026 gen_init->mtu = bp->dev->mtu;
6383c0b3
AE
3027
3028 gen_init->cos = cos;
619c5cb6
VZ
3029}
3030
3031static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
523224a3 3032 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
619c5cb6 3033 struct bnx2x_rxq_setup_params *rxq_init)
523224a3 3034{
619c5cb6 3035 u8 max_sge = 0;
523224a3
DK
3036 u16 sge_sz = 0;
3037 u16 tpa_agg_size = 0;
3038
523224a3 3039 if (!fp->disable_tpa) {
dfacf138
DK
3040 pause->sge_th_lo = SGE_TH_LO(bp);
3041 pause->sge_th_hi = SGE_TH_HI(bp);
3042
3043 /* validate SGE ring has enough to cross high threshold */
3044 WARN_ON(bp->dropless_fc &&
3045 pause->sge_th_hi + FW_PREFETCH_CNT >
3046 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3047
924d75ab 3048 tpa_agg_size = TPA_AGG_SIZE;
523224a3
DK
3049 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3050 SGE_PAGE_SHIFT;
3051 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3052 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
924d75ab 3053 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
523224a3
DK
3054 }
3055
3056 /* pause - not for e1 */
3057 if (!CHIP_IS_E1(bp)) {
dfacf138
DK
3058 pause->bd_th_lo = BD_TH_LO(bp);
3059 pause->bd_th_hi = BD_TH_HI(bp);
3060
3061 pause->rcq_th_lo = RCQ_TH_LO(bp);
3062 pause->rcq_th_hi = RCQ_TH_HI(bp);
3063 /*
3064 * validate that rings have enough entries to cross
3065 * high thresholds
3066 */
3067 WARN_ON(bp->dropless_fc &&
3068 pause->bd_th_hi + FW_PREFETCH_CNT >
3069 bp->rx_ring_size);
3070 WARN_ON(bp->dropless_fc &&
3071 pause->rcq_th_hi + FW_PREFETCH_CNT >
3072 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
619c5cb6 3073
523224a3
DK
3074 pause->pri_map = 1;
3075 }
3076
3077 /* rxq setup */
523224a3
DK
3078 rxq_init->dscr_map = fp->rx_desc_mapping;
3079 rxq_init->sge_map = fp->rx_sge_mapping;
3080 rxq_init->rcq_map = fp->rx_comp_mapping;
3081 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
a8c94b91 3082
619c5cb6
VZ
3083 /* This should be a maximum number of data bytes that may be
3084 * placed on the BD (not including paddings).
3085 */
e52fcb24
ED
3086 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
3087 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
a8c94b91 3088
523224a3 3089 rxq_init->cl_qzone_id = fp->cl_qzone_id;
523224a3
DK
3090 rxq_init->tpa_agg_sz = tpa_agg_size;
3091 rxq_init->sge_buf_sz = sge_sz;
3092 rxq_init->max_sges_pkt = max_sge;
619c5cb6 3093 rxq_init->rss_engine_id = BP_FUNC(bp);
259afa1f 3094 rxq_init->mcast_engine_id = BP_FUNC(bp);
619c5cb6
VZ
3095
3096 /* Maximum number or simultaneous TPA aggregation for this Queue.
3097 *
2de67439 3098 * For PF Clients it should be the maximum available number.
619c5cb6
VZ
3099 * VF driver(s) may want to define it to a smaller value.
3100 */
dfacf138 3101 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
619c5cb6 3102
523224a3
DK
3103 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3104 rxq_init->fw_sb_id = fp->fw_sb_id;
3105
ec6ba945
VZ
3106 if (IS_FCOE_FP(fp))
3107 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3108 else
6383c0b3 3109 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
a3348722
BW
3110 /* configure silent vlan removal
3111 * if multi function mode is afex, then mask default vlan
3112 */
3113 if (IS_MF_AFEX(bp)) {
3114 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3115 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3116 }
523224a3
DK
3117}
3118
619c5cb6 3119static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
6383c0b3
AE
3120 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3121 u8 cos)
523224a3 3122{
65565884 3123 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
6383c0b3 3124 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
523224a3
DK
3125 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3126 txq_init->fw_sb_id = fp->fw_sb_id;
ec6ba945 3127
619c5cb6
VZ
3128 /*
3129 * set the tss leading client id for TX classfication ==
3130 * leading RSS client id
3131 */
3132 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3133
ec6ba945
VZ
3134 if (IS_FCOE_FP(fp)) {
3135 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3136 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3137 }
523224a3
DK
3138}
3139
8d96286a 3140static void bnx2x_pf_init(struct bnx2x *bp)
523224a3
DK
3141{
3142 struct bnx2x_func_init_params func_init = {0};
523224a3
DK
3143 struct event_ring_data eq_data = { {0} };
3144 u16 flags;
3145
619c5cb6 3146 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3147 /* reset IGU PF statistics: MSIX + ATTN */
3148 /* PF */
3149 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3150 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3151 (CHIP_MODE_IS_4_PORT(bp) ?
3152 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3153 /* ATTN */
3154 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3155 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3156 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3157 (CHIP_MODE_IS_4_PORT(bp) ?
3158 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3159 }
3160
523224a3
DK
3161 /* function setup flags */
3162 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3163
619c5cb6
VZ
3164 /* This flag is relevant for E1x only.
3165 * E2 doesn't have a TPA configuration in a function level.
523224a3 3166 */
619c5cb6 3167 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
523224a3
DK
3168
3169 func_init.func_flgs = flags;
3170 func_init.pf_id = BP_FUNC(bp);
3171 func_init.func_id = BP_FUNC(bp);
523224a3
DK
3172 func_init.spq_map = bp->spq_mapping;
3173 func_init.spq_prod = bp->spq_prod_idx;
3174
3175 bnx2x_func_init(bp, &func_init);
3176
3177 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3178
3179 /*
619c5cb6
VZ
3180 * Congestion management values depend on the link rate
3181 * There is no active link so initial link rate is set to 10 Gbps.
3182 * When the link comes up The congestion management values are
3183 * re-calculated according to the actual link rate.
3184 */
523224a3
DK
3185 bp->link_vars.line_speed = SPEED_10000;
3186 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3187
3188 /* Only the PMF sets the HW */
3189 if (bp->port.pmf)
3190 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3191
86564c3f 3192 /* init Event Queue - PCI bus guarantees correct endianity*/
523224a3
DK
3193 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3194 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3195 eq_data.producer = bp->eq_prod;
3196 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3197 eq_data.sb_id = DEF_SB_ID;
3198 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3199}
3200
3201
3202static void bnx2x_e1h_disable(struct bnx2x *bp)
3203{
3204 int port = BP_PORT(bp);
3205
619c5cb6 3206 bnx2x_tx_disable(bp);
523224a3
DK
3207
3208 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
523224a3
DK
3209}
3210
3211static void bnx2x_e1h_enable(struct bnx2x *bp)
3212{
3213 int port = BP_PORT(bp);
3214
3215 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3216
3217 /* Tx queue should be only reenabled */
3218 netif_tx_wake_all_queues(bp->dev);
3219
3220 /*
3221 * Should not call netif_carrier_on since it will be called if the link
3222 * is up when checking for link state
3223 */
3224}
3225
1d187b34
BW
3226#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3227
3228static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3229{
3230 struct eth_stats_info *ether_stat =
3231 &bp->slowpath->drv_info_to_mcp.ether_stat;
3232
786fdf0b
DC
3233 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3234 ETH_STAT_INFO_VERSION_LEN);
1d187b34 3235
15192a8c
BW
3236 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3237 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3238 ether_stat->mac_local);
1d187b34
BW
3239
3240 ether_stat->mtu_size = bp->dev->mtu;
3241
3242 if (bp->dev->features & NETIF_F_RXCSUM)
3243 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3244 if (bp->dev->features & NETIF_F_TSO)
3245 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3246 ether_stat->feature_flags |= bp->common.boot_mode;
3247
3248 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3249
3250 ether_stat->txq_size = bp->tx_ring_size;
3251 ether_stat->rxq_size = bp->rx_ring_size;
3252}
3253
3254static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3255{
3256 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3257 struct fcoe_stats_info *fcoe_stat =
3258 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3259
55c11941
MS
3260 if (!CNIC_LOADED(bp))
3261 return;
3262
2e499d3c
BW
3263 memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
3264 bp->fip_mac, ETH_ALEN);
1d187b34
BW
3265
3266 fcoe_stat->qos_priority =
3267 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3268
3269 /* insert FCoE stats from ramrod response */
3270 if (!NO_FCOE(bp)) {
3271 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
65565884 3272 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3273 tstorm_queue_statistics;
3274
3275 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
65565884 3276 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
1d187b34
BW
3277 xstorm_queue_statistics;
3278
3279 struct fcoe_statistics_params *fw_fcoe_stat =
3280 &bp->fw_stats_data->fcoe;
3281
86564c3f
YM
3282 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3283 fcoe_stat->rx_bytes_lo,
3284 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
1d187b34 3285
86564c3f
YM
3286 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3287 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3288 fcoe_stat->rx_bytes_lo,
3289 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
1d187b34 3290
86564c3f
YM
3291 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3292 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3293 fcoe_stat->rx_bytes_lo,
3294 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
1d187b34 3295
86564c3f
YM
3296 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3297 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3298 fcoe_stat->rx_bytes_lo,
3299 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
1d187b34 3300
86564c3f
YM
3301 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3302 fcoe_stat->rx_frames_lo,
3303 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
1d187b34 3304
86564c3f
YM
3305 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3306 fcoe_stat->rx_frames_lo,
3307 fcoe_q_tstorm_stats->rcv_ucast_pkts);
1d187b34 3308
86564c3f
YM
3309 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3310 fcoe_stat->rx_frames_lo,
3311 fcoe_q_tstorm_stats->rcv_bcast_pkts);
1d187b34 3312
86564c3f
YM
3313 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3314 fcoe_stat->rx_frames_lo,
3315 fcoe_q_tstorm_stats->rcv_mcast_pkts);
1d187b34 3316
86564c3f
YM
3317 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3318 fcoe_stat->tx_bytes_lo,
3319 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
1d187b34 3320
86564c3f
YM
3321 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3322 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3323 fcoe_stat->tx_bytes_lo,
3324 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
1d187b34 3325
86564c3f
YM
3326 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3327 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3328 fcoe_stat->tx_bytes_lo,
3329 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
1d187b34 3330
86564c3f
YM
3331 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3332 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3333 fcoe_stat->tx_bytes_lo,
3334 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
1d187b34 3335
86564c3f
YM
3336 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3337 fcoe_stat->tx_frames_lo,
3338 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
1d187b34 3339
86564c3f
YM
3340 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3341 fcoe_stat->tx_frames_lo,
3342 fcoe_q_xstorm_stats->ucast_pkts_sent);
1d187b34 3343
86564c3f
YM
3344 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3345 fcoe_stat->tx_frames_lo,
3346 fcoe_q_xstorm_stats->bcast_pkts_sent);
1d187b34 3347
86564c3f
YM
3348 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3349 fcoe_stat->tx_frames_lo,
3350 fcoe_q_xstorm_stats->mcast_pkts_sent);
1d187b34
BW
3351 }
3352
1d187b34
BW
3353 /* ask L5 driver to add data to the struct */
3354 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
1d187b34
BW
3355}
3356
3357static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3358{
3359 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3360 struct iscsi_stats_info *iscsi_stat =
3361 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3362
55c11941
MS
3363 if (!CNIC_LOADED(bp))
3364 return;
3365
2e499d3c
BW
3366 memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
3367 bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
1d187b34
BW
3368
3369 iscsi_stat->qos_priority =
3370 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3371
1d187b34
BW
3372 /* ask L5 driver to add data to the struct */
3373 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
1d187b34
BW
3374}
3375
0793f83f
DK
3376/* called due to MCP event (on pmf):
3377 * reread new bandwidth configuration
3378 * configure FW
3379 * notify others function about the change
3380 */
1191cb83 3381static void bnx2x_config_mf_bw(struct bnx2x *bp)
0793f83f
DK
3382{
3383 if (bp->link_vars.link_up) {
3384 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3385 bnx2x_link_sync_notify(bp);
3386 }
3387 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3388}
3389
1191cb83 3390static void bnx2x_set_mf_bw(struct bnx2x *bp)
0793f83f
DK
3391{
3392 bnx2x_config_mf_bw(bp);
3393 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3394}
3395
c8c60d88
YM
3396static void bnx2x_handle_eee_event(struct bnx2x *bp)
3397{
3398 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3399 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3400}
3401
1d187b34
BW
3402static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3403{
3404 enum drv_info_opcode op_code;
3405 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3406
3407 /* if drv_info version supported by MFW doesn't match - send NACK */
3408 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3409 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3410 return;
3411 }
3412
3413 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3414 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3415
3416 memset(&bp->slowpath->drv_info_to_mcp, 0,
3417 sizeof(union drv_info_to_mcp));
3418
3419 switch (op_code) {
3420 case ETH_STATS_OPCODE:
3421 bnx2x_drv_info_ether_stat(bp);
3422 break;
3423 case FCOE_STATS_OPCODE:
3424 bnx2x_drv_info_fcoe_stat(bp);
3425 break;
3426 case ISCSI_STATS_OPCODE:
3427 bnx2x_drv_info_iscsi_stat(bp);
3428 break;
3429 default:
3430 /* if op code isn't supported - send NACK */
3431 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3432 return;
3433 }
3434
3435 /* if we got drv_info attn from MFW then these fields are defined in
3436 * shmem2 for sure
3437 */
3438 SHMEM2_WR(bp, drv_info_host_addr_lo,
3439 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3440 SHMEM2_WR(bp, drv_info_host_addr_hi,
3441 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3442
3443 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3444}
3445
523224a3
DK
3446static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3447{
3448 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3449
3450 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3451
3452 /*
3453 * This is the only place besides the function initialization
3454 * where the bp->flags can change so it is done without any
3455 * locks
3456 */
f2e0899f 3457 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
51c1a580 3458 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
523224a3
DK
3459 bp->flags |= MF_FUNC_DIS;
3460
3461 bnx2x_e1h_disable(bp);
3462 } else {
51c1a580 3463 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
523224a3
DK
3464 bp->flags &= ~MF_FUNC_DIS;
3465
3466 bnx2x_e1h_enable(bp);
3467 }
3468 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3469 }
3470 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
0793f83f 3471 bnx2x_config_mf_bw(bp);
523224a3
DK
3472 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3473 }
3474
3475 /* Report results to MCP */
3476 if (dcc_event)
3477 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3478 else
3479 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3480}
3481
3482/* must be called under the spq lock */
1191cb83 3483static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
523224a3
DK
3484{
3485 struct eth_spe *next_spe = bp->spq_prod_bd;
3486
3487 if (bp->spq_prod_bd == bp->spq_last_bd) {
3488 bp->spq_prod_bd = bp->spq;
3489 bp->spq_prod_idx = 0;
51c1a580 3490 DP(BNX2X_MSG_SP, "end of spq\n");
523224a3
DK
3491 } else {
3492 bp->spq_prod_bd++;
3493 bp->spq_prod_idx++;
3494 }
3495 return next_spe;
3496}
3497
3498/* must be called under the spq lock */
1191cb83 3499static void bnx2x_sp_prod_update(struct bnx2x *bp)
28912902
MC
3500{
3501 int func = BP_FUNC(bp);
3502
53e51e2f
VZ
3503 /*
3504 * Make sure that BD data is updated before writing the producer:
3505 * BD data is written to the memory, the producer is read from the
3506 * memory, thus we need a full memory barrier to ensure the ordering.
3507 */
3508 mb();
28912902 3509
523224a3 3510 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
f85582f8 3511 bp->spq_prod_idx);
28912902
MC
3512 mmiowb();
3513}
3514
619c5cb6
VZ
3515/**
3516 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3517 *
3518 * @cmd: command to check
3519 * @cmd_type: command type
3520 */
1191cb83 3521static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
619c5cb6
VZ
3522{
3523 if ((cmd_type == NONE_CONNECTION_TYPE) ||
6383c0b3 3524 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
619c5cb6
VZ
3525 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3526 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3527 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3528 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3529 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3530 return true;
3531 else
3532 return false;
3533
3534}
3535
3536
3537/**
3538 * bnx2x_sp_post - place a single command on an SP ring
3539 *
3540 * @bp: driver handle
3541 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3542 * @cid: SW CID the command is related to
3543 * @data_hi: command private data address (high 32 bits)
3544 * @data_lo: command private data address (low 32 bits)
3545 * @cmd_type: command type (e.g. NONE, ETH)
3546 *
3547 * SP data is handled as if it's always an address pair, thus data fields are
3548 * not swapped to little endian in upper functions. Instead this function swaps
3549 * data as if it's two u32 fields.
3550 */
9f6c9258 3551int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
619c5cb6 3552 u32 data_hi, u32 data_lo, int cmd_type)
a2fbb9ea 3553{
28912902 3554 struct eth_spe *spe;
523224a3 3555 u16 type;
619c5cb6 3556 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
a2fbb9ea 3557
a2fbb9ea 3558#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
3559 if (unlikely(bp->panic)) {
3560 BNX2X_ERR("Can't post SP when there is panic\n");
a2fbb9ea 3561 return -EIO;
51c1a580 3562 }
a2fbb9ea
ET
3563#endif
3564
34f80b04 3565 spin_lock_bh(&bp->spq_lock);
a2fbb9ea 3566
6e30dd4e
VZ
3567 if (common) {
3568 if (!atomic_read(&bp->eq_spq_left)) {
3569 BNX2X_ERR("BUG! EQ ring full!\n");
3570 spin_unlock_bh(&bp->spq_lock);
3571 bnx2x_panic();
3572 return -EBUSY;
3573 }
3574 } else if (!atomic_read(&bp->cq_spq_left)) {
3575 BNX2X_ERR("BUG! SPQ ring full!\n");
3576 spin_unlock_bh(&bp->spq_lock);
3577 bnx2x_panic();
3578 return -EBUSY;
a2fbb9ea 3579 }
f1410647 3580
28912902
MC
3581 spe = bnx2x_sp_get_next(bp);
3582
a2fbb9ea 3583 /* CID needs port number to be encoded int it */
28912902 3584 spe->hdr.conn_and_cmd_data =
cdaa7cb8
VZ
3585 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3586 HW_CID(bp, cid));
523224a3 3587
619c5cb6 3588 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
a2fbb9ea 3589
523224a3
DK
3590 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3591 SPE_HDR_FUNCTION_ID);
a2fbb9ea 3592
523224a3
DK
3593 spe->hdr.type = cpu_to_le16(type);
3594
3595 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3596 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3597
d6cae238
VZ
3598 /*
3599 * It's ok if the actual decrement is issued towards the memory
3600 * somewhere between the spin_lock and spin_unlock. Thus no
3601 * more explict memory barrier is needed.
3602 */
3603 if (common)
3604 atomic_dec(&bp->eq_spq_left);
3605 else
3606 atomic_dec(&bp->cq_spq_left);
6e30dd4e 3607
a2fbb9ea 3608
51c1a580
MS
3609 DP(BNX2X_MSG_SP,
3610 "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
3611 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3612 (u32)(U64_LO(bp->spq_mapping) +
d6cae238 3613 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
6e30dd4e
VZ
3614 HW_CID(bp, cid), data_hi, data_lo, type,
3615 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
cdaa7cb8 3616
28912902 3617 bnx2x_sp_prod_update(bp);
34f80b04 3618 spin_unlock_bh(&bp->spq_lock);
a2fbb9ea
ET
3619 return 0;
3620}
3621
3622/* acquire split MCP access lock register */
4a37fb66 3623static int bnx2x_acquire_alr(struct bnx2x *bp)
a2fbb9ea 3624{
72fd0718 3625 u32 j, val;
34f80b04 3626 int rc = 0;
a2fbb9ea
ET
3627
3628 might_sleep();
72fd0718 3629 for (j = 0; j < 1000; j++) {
a2fbb9ea
ET
3630 val = (1UL << 31);
3631 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3632 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3633 if (val & (1L << 31))
3634 break;
3635
3636 msleep(5);
3637 }
a2fbb9ea 3638 if (!(val & (1L << 31))) {
19680c48 3639 BNX2X_ERR("Cannot acquire MCP access lock register\n");
a2fbb9ea
ET
3640 rc = -EBUSY;
3641 }
3642
3643 return rc;
3644}
3645
4a37fb66
YG
3646/* release split MCP access lock register */
3647static void bnx2x_release_alr(struct bnx2x *bp)
a2fbb9ea 3648{
72fd0718 3649 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
a2fbb9ea
ET
3650}
3651
523224a3
DK
3652#define BNX2X_DEF_SB_ATT_IDX 0x0001
3653#define BNX2X_DEF_SB_IDX 0x0002
3654
1191cb83 3655static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
a2fbb9ea 3656{
523224a3 3657 struct host_sp_status_block *def_sb = bp->def_status_blk;
a2fbb9ea
ET
3658 u16 rc = 0;
3659
3660 barrier(); /* status block is written to by the chip */
a2fbb9ea
ET
3661 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3662 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
523224a3 3663 rc |= BNX2X_DEF_SB_ATT_IDX;
a2fbb9ea 3664 }
523224a3
DK
3665
3666 if (bp->def_idx != def_sb->sp_sb.running_index) {
3667 bp->def_idx = def_sb->sp_sb.running_index;
3668 rc |= BNX2X_DEF_SB_IDX;
a2fbb9ea 3669 }
523224a3
DK
3670
3671 /* Do not reorder: indecies reading should complete before handling */
3672 barrier();
a2fbb9ea
ET
3673 return rc;
3674}
3675
3676/*
3677 * slow path service functions
3678 */
3679
3680static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3681{
34f80b04 3682 int port = BP_PORT(bp);
a2fbb9ea
ET
3683 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3684 MISC_REG_AEU_MASK_ATTN_FUNC_0;
877e9aa4
ET
3685 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3686 NIG_REG_MASK_INTERRUPT_PORT0;
3fcaf2e5 3687 u32 aeu_mask;
87942b46 3688 u32 nig_mask = 0;
f2e0899f 3689 u32 reg_addr;
a2fbb9ea 3690
a2fbb9ea
ET
3691 if (bp->attn_state & asserted)
3692 BNX2X_ERR("IGU ERROR\n");
3693
3fcaf2e5
EG
3694 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3695 aeu_mask = REG_RD(bp, aeu_addr);
3696
a2fbb9ea 3697 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3fcaf2e5 3698 aeu_mask, asserted);
72fd0718 3699 aeu_mask &= ~(asserted & 0x3ff);
3fcaf2e5 3700 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 3701
3fcaf2e5
EG
3702 REG_WR(bp, aeu_addr, aeu_mask);
3703 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea 3704
3fcaf2e5 3705 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
a2fbb9ea 3706 bp->attn_state |= asserted;
3fcaf2e5 3707 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
a2fbb9ea
ET
3708
3709 if (asserted & ATTN_HARD_WIRED_MASK) {
3710 if (asserted & ATTN_NIG_FOR_FUNC) {
a2fbb9ea 3711
a5e9a7cf
EG
3712 bnx2x_acquire_phy_lock(bp);
3713
877e9aa4 3714 /* save nig interrupt mask */
87942b46 3715 nig_mask = REG_RD(bp, nig_int_mask_addr);
a2fbb9ea 3716
361c391e
YR
3717 /* If nig_mask is not set, no need to call the update
3718 * function.
3719 */
3720 if (nig_mask) {
3721 REG_WR(bp, nig_int_mask_addr, 0);
3722
3723 bnx2x_link_attn(bp);
3724 }
a2fbb9ea
ET
3725
3726 /* handle unicore attn? */
3727 }
3728 if (asserted & ATTN_SW_TIMER_4_FUNC)
3729 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3730
3731 if (asserted & GPIO_2_FUNC)
3732 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3733
3734 if (asserted & GPIO_3_FUNC)
3735 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3736
3737 if (asserted & GPIO_4_FUNC)
3738 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3739
3740 if (port == 0) {
3741 if (asserted & ATTN_GENERAL_ATTN_1) {
3742 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3743 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3744 }
3745 if (asserted & ATTN_GENERAL_ATTN_2) {
3746 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3747 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3748 }
3749 if (asserted & ATTN_GENERAL_ATTN_3) {
3750 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3751 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3752 }
3753 } else {
3754 if (asserted & ATTN_GENERAL_ATTN_4) {
3755 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3756 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3757 }
3758 if (asserted & ATTN_GENERAL_ATTN_5) {
3759 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3760 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3761 }
3762 if (asserted & ATTN_GENERAL_ATTN_6) {
3763 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3764 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3765 }
3766 }
3767
3768 } /* if hardwired */
3769
f2e0899f
DK
3770 if (bp->common.int_block == INT_BLOCK_HC)
3771 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3772 COMMAND_REG_ATTN_BITS_SET);
3773 else
3774 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3775
3776 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3777 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3778 REG_WR(bp, reg_addr, asserted);
a2fbb9ea
ET
3779
3780 /* now set back the mask */
a5e9a7cf 3781 if (asserted & ATTN_NIG_FOR_FUNC) {
27c1151c
YR
3782 /* Verify that IGU ack through BAR was written before restoring
3783 * NIG mask. This loop should exit after 2-3 iterations max.
3784 */
3785 if (bp->common.int_block != INT_BLOCK_HC) {
3786 u32 cnt = 0, igu_acked;
3787 do {
3788 igu_acked = REG_RD(bp,
3789 IGU_REG_ATTENTION_ACK_BITS);
3790 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3791 (++cnt < MAX_IGU_ATTN_ACK_TO));
3792 if (!igu_acked)
3793 DP(NETIF_MSG_HW,
3794 "Failed to verify IGU ack on time\n");
3795 barrier();
3796 }
87942b46 3797 REG_WR(bp, nig_int_mask_addr, nig_mask);
a5e9a7cf
EG
3798 bnx2x_release_phy_lock(bp);
3799 }
a2fbb9ea
ET
3800}
3801
1191cb83 3802static void bnx2x_fan_failure(struct bnx2x *bp)
fd4ef40d
EG
3803{
3804 int port = BP_PORT(bp);
b7737c9b 3805 u32 ext_phy_config;
fd4ef40d 3806 /* mark the failure */
b7737c9b
YR
3807 ext_phy_config =
3808 SHMEM_RD(bp,
3809 dev_info.port_hw_config[port].external_phy_config);
3810
3811 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3812 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
fd4ef40d 3813 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
b7737c9b 3814 ext_phy_config);
fd4ef40d
EG
3815
3816 /* log the failure */
51c1a580
MS
3817 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3818 "Please contact OEM Support for assistance\n");
8304859a
AE
3819
3820 /*
2de67439 3821 * Schedule device reset (unload)
8304859a
AE
3822 * This is due to some boards consuming sufficient power when driver is
3823 * up to overheat if fan fails.
3824 */
3825 smp_mb__before_clear_bit();
3826 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3827 smp_mb__after_clear_bit();
3828 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3829
fd4ef40d 3830}
ab6ad5a4 3831
1191cb83 3832static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
a2fbb9ea 3833{
34f80b04 3834 int port = BP_PORT(bp);
877e9aa4 3835 int reg_offset;
d90d96ba 3836 u32 val;
877e9aa4 3837
34f80b04
EG
3838 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3839 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
877e9aa4 3840
34f80b04 3841 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
877e9aa4
ET
3842
3843 val = REG_RD(bp, reg_offset);
3844 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3845 REG_WR(bp, reg_offset, val);
3846
3847 BNX2X_ERR("SPIO5 hw attention\n");
3848
fd4ef40d 3849 /* Fan failure attention */
d90d96ba 3850 bnx2x_hw_reset_phy(&bp->link_params);
fd4ef40d 3851 bnx2x_fan_failure(bp);
877e9aa4 3852 }
34f80b04 3853
3deb8167 3854 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
589abe3a
EG
3855 bnx2x_acquire_phy_lock(bp);
3856 bnx2x_handle_module_detect_int(&bp->link_params);
3857 bnx2x_release_phy_lock(bp);
3858 }
3859
34f80b04
EG
3860 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3861
3862 val = REG_RD(bp, reg_offset);
3863 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3864 REG_WR(bp, reg_offset, val);
3865
3866 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
0fc5d009 3867 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
34f80b04
EG
3868 bnx2x_panic();
3869 }
877e9aa4
ET
3870}
3871
1191cb83 3872static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3873{
3874 u32 val;
3875
0626b899 3876 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
877e9aa4
ET
3877
3878 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3879 BNX2X_ERR("DB hw attention 0x%x\n", val);
3880 /* DORQ discard attention */
3881 if (val & 0x2)
3882 BNX2X_ERR("FATAL error from DORQ\n");
3883 }
34f80b04
EG
3884
3885 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3886
3887 int port = BP_PORT(bp);
3888 int reg_offset;
3889
3890 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3891 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3892
3893 val = REG_RD(bp, reg_offset);
3894 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3895 REG_WR(bp, reg_offset, val);
3896
3897 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
0fc5d009 3898 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
34f80b04
EG
3899 bnx2x_panic();
3900 }
877e9aa4
ET
3901}
3902
1191cb83 3903static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
877e9aa4
ET
3904{
3905 u32 val;
3906
3907 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3908
3909 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3910 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3911 /* CFC error attention */
3912 if (val & 0x2)
3913 BNX2X_ERR("FATAL error from CFC\n");
3914 }
3915
3916 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
877e9aa4 3917 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
619c5cb6 3918 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
877e9aa4
ET
3919 /* RQ_USDMDP_FIFO_OVERFLOW */
3920 if (val & 0x18000)
3921 BNX2X_ERR("FATAL error from PXP\n");
619c5cb6
VZ
3922
3923 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
3924 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3925 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3926 }
877e9aa4 3927 }
34f80b04
EG
3928
3929 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3930
3931 int port = BP_PORT(bp);
3932 int reg_offset;
3933
3934 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3935 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3936
3937 val = REG_RD(bp, reg_offset);
3938 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3939 REG_WR(bp, reg_offset, val);
3940
3941 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
0fc5d009 3942 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
34f80b04
EG
3943 bnx2x_panic();
3944 }
877e9aa4
ET
3945}
3946
1191cb83 3947static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
877e9aa4 3948{
34f80b04
EG
3949 u32 val;
3950
877e9aa4
ET
3951 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3952
34f80b04
EG
3953 if (attn & BNX2X_PMF_LINK_ASSERT) {
3954 int func = BP_FUNC(bp);
3955
3956 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
a3348722 3957 bnx2x_read_mf_cfg(bp);
f2e0899f
DK
3958 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3959 func_mf_config[BP_ABS_FUNC(bp)].config);
3960 val = SHMEM_RD(bp,
3961 func_mb[BP_FW_MB_IDX(bp)].drv_status);
2691d51d
EG
3962 if (val & DRV_STATUS_DCC_EVENT_MASK)
3963 bnx2x_dcc_event(bp,
3964 (val & DRV_STATUS_DCC_EVENT_MASK));
0793f83f
DK
3965
3966 if (val & DRV_STATUS_SET_MF_BW)
3967 bnx2x_set_mf_bw(bp);
3968
1d187b34
BW
3969 if (val & DRV_STATUS_DRV_INFO_REQ)
3970 bnx2x_handle_drv_info_req(bp);
d16132ce
AE
3971
3972 if (val & DRV_STATUS_VF_DISABLED)
3973 bnx2x_vf_handle_flr_event(bp);
3974
2691d51d 3975 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
34f80b04
EG
3976 bnx2x_pmf_update(bp);
3977
e4901dde 3978 if (bp->port.pmf &&
785b9b1a
SR
3979 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3980 bp->dcbx_enabled > 0)
e4901dde
VZ
3981 /* start dcbx state machine */
3982 bnx2x_dcbx_set_params(bp,
3983 BNX2X_DCBX_STATE_NEG_RECEIVED);
a3348722
BW
3984 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3985 bnx2x_handle_afex_cmd(bp,
3986 val & DRV_STATUS_AFEX_EVENT_MASK);
c8c60d88
YM
3987 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3988 bnx2x_handle_eee_event(bp);
3deb8167
YR
3989 if (bp->link_vars.periodic_flags &
3990 PERIODIC_FLAGS_LINK_EVENT) {
3991 /* sync with link */
3992 bnx2x_acquire_phy_lock(bp);
3993 bp->link_vars.periodic_flags &=
3994 ~PERIODIC_FLAGS_LINK_EVENT;
3995 bnx2x_release_phy_lock(bp);
3996 if (IS_MF(bp))
3997 bnx2x_link_sync_notify(bp);
3998 bnx2x_link_report(bp);
3999 }
4000 /* Always call it here: bnx2x_link_report() will
4001 * prevent the link indication duplication.
4002 */
4003 bnx2x__link_status_update(bp);
34f80b04 4004 } else if (attn & BNX2X_MC_ASSERT_BITS) {
877e9aa4
ET
4005
4006 BNX2X_ERR("MC assert!\n");
d6cae238 4007 bnx2x_mc_assert(bp);
877e9aa4
ET
4008 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4009 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4010 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4011 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4012 bnx2x_panic();
4013
4014 } else if (attn & BNX2X_MCP_ASSERT) {
4015
4016 BNX2X_ERR("MCP assert!\n");
4017 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
34f80b04 4018 bnx2x_fw_dump(bp);
877e9aa4
ET
4019
4020 } else
4021 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4022 }
4023
4024 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
34f80b04
EG
4025 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4026 if (attn & BNX2X_GRC_TIMEOUT) {
f2e0899f
DK
4027 val = CHIP_IS_E1(bp) ? 0 :
4028 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
34f80b04
EG
4029 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4030 }
4031 if (attn & BNX2X_GRC_RSV) {
f2e0899f
DK
4032 val = CHIP_IS_E1(bp) ? 0 :
4033 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
34f80b04
EG
4034 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4035 }
877e9aa4 4036 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
877e9aa4
ET
4037 }
4038}
4039
c9ee9206
VZ
4040/*
4041 * Bits map:
4042 * 0-7 - Engine0 load counter.
4043 * 8-15 - Engine1 load counter.
4044 * 16 - Engine0 RESET_IN_PROGRESS bit.
4045 * 17 - Engine1 RESET_IN_PROGRESS bit.
4046 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4047 * on the engine
4048 * 19 - Engine1 ONE_IS_LOADED.
4049 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4050 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4051 * just the one belonging to its engine).
4052 *
4053 */
4054#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4055
4056#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4057#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4058#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4059#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4060#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4061#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4062#define BNX2X_GLOBAL_RESET_BIT 0x00040000
4063
4064/*
4065 * Set the GLOBAL_RESET bit.
4066 *
4067 * Should be run under rtnl lock
4068 */
4069void bnx2x_set_reset_global(struct bnx2x *bp)
4070{
f16da43b
AE
4071 u32 val;
4072 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4073 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4074 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
f16da43b 4075 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206
VZ
4076}
4077
4078/*
4079 * Clear the GLOBAL_RESET bit.
4080 *
4081 * Should be run under rtnl lock
4082 */
1191cb83 4083static void bnx2x_clear_reset_global(struct bnx2x *bp)
c9ee9206 4084{
f16da43b
AE
4085 u32 val;
4086 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4087 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206 4088 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
f16da43b 4089 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
c9ee9206 4090}
f85582f8 4091
72fd0718 4092/*
c9ee9206
VZ
4093 * Checks the GLOBAL_RESET bit.
4094 *
72fd0718
VZ
4095 * should be run under rtnl lock
4096 */
1191cb83 4097static bool bnx2x_reset_is_global(struct bnx2x *bp)
c9ee9206
VZ
4098{
4099 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4100
4101 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4102 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4103}
4104
4105/*
4106 * Clear RESET_IN_PROGRESS bit for the current engine.
4107 *
4108 * Should be run under rtnl lock
4109 */
1191cb83 4110static void bnx2x_set_reset_done(struct bnx2x *bp)
72fd0718 4111{
f16da43b 4112 u32 val;
c9ee9206
VZ
4113 u32 bit = BP_PATH(bp) ?
4114 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4115 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4116 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4117
4118 /* Clear the bit */
4119 val &= ~bit;
4120 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4121
4122 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4123}
4124
4125/*
c9ee9206
VZ
4126 * Set RESET_IN_PROGRESS for the current engine.
4127 *
72fd0718
VZ
4128 * should be run under rtnl lock
4129 */
c9ee9206 4130void bnx2x_set_reset_in_progress(struct bnx2x *bp)
72fd0718 4131{
f16da43b 4132 u32 val;
c9ee9206
VZ
4133 u32 bit = BP_PATH(bp) ?
4134 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
f16da43b
AE
4135 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4136 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
c9ee9206
VZ
4137
4138 /* Set the bit */
4139 val |= bit;
4140 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4141 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4142}
4143
4144/*
c9ee9206 4145 * Checks the RESET_IN_PROGRESS bit for the given engine.
72fd0718
VZ
4146 * should be run under rtnl lock
4147 */
c9ee9206 4148bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
72fd0718 4149{
c9ee9206
VZ
4150 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4151 u32 bit = engine ?
4152 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4153
4154 /* return false if bit is set */
4155 return (val & bit) ? false : true;
72fd0718
VZ
4156}
4157
4158/*
889b9af3 4159 * set pf load for the current pf.
c9ee9206 4160 *
72fd0718
VZ
4161 * should be run under rtnl lock
4162 */
889b9af3 4163void bnx2x_set_pf_load(struct bnx2x *bp)
72fd0718 4164{
f16da43b 4165 u32 val1, val;
c9ee9206
VZ
4166 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4167 BNX2X_PATH0_LOAD_CNT_MASK;
4168 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4169 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4170
f16da43b
AE
4171 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4172 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4173
51c1a580 4174 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4175
c9ee9206
VZ
4176 /* get the current counter value */
4177 val1 = (val & mask) >> shift;
4178
889b9af3
AE
4179 /* set bit of that PF */
4180 val1 |= (1 << bp->pf_num);
c9ee9206
VZ
4181
4182 /* clear the old value */
4183 val &= ~mask;
4184
4185 /* set the new one */
4186 val |= ((val1 << shift) & mask);
4187
4188 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b 4189 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
72fd0718
VZ
4190}
4191
c9ee9206 4192/**
889b9af3 4193 * bnx2x_clear_pf_load - clear pf load mark
c9ee9206
VZ
4194 *
4195 * @bp: driver handle
4196 *
4197 * Should be run under rtnl lock.
4198 * Decrements the load counter for the current engine. Returns
889b9af3 4199 * whether other functions are still loaded
72fd0718 4200 */
889b9af3 4201bool bnx2x_clear_pf_load(struct bnx2x *bp)
72fd0718 4202{
f16da43b 4203 u32 val1, val;
c9ee9206
VZ
4204 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4205 BNX2X_PATH0_LOAD_CNT_MASK;
4206 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4207 BNX2X_PATH0_LOAD_CNT_SHIFT;
72fd0718 4208
f16da43b
AE
4209 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4210 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
51c1a580 4211 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
72fd0718 4212
c9ee9206
VZ
4213 /* get the current counter value */
4214 val1 = (val & mask) >> shift;
4215
889b9af3
AE
4216 /* clear bit of that PF */
4217 val1 &= ~(1 << bp->pf_num);
c9ee9206
VZ
4218
4219 /* clear the old value */
4220 val &= ~mask;
4221
4222 /* set the new one */
4223 val |= ((val1 << shift) & mask);
4224
4225 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
f16da43b
AE
4226 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4227 return val1 != 0;
72fd0718
VZ
4228}
4229
4230/*
889b9af3 4231 * Read the load status for the current engine.
c9ee9206 4232 *
72fd0718
VZ
4233 * should be run under rtnl lock
4234 */
1191cb83 4235static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
72fd0718 4236{
c9ee9206
VZ
4237 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4238 BNX2X_PATH0_LOAD_CNT_MASK);
4239 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4240 BNX2X_PATH0_LOAD_CNT_SHIFT);
4241 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4242
51c1a580 4243 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
c9ee9206
VZ
4244
4245 val = (val & mask) >> shift;
4246
51c1a580
MS
4247 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4248 engine, val);
c9ee9206 4249
889b9af3 4250 return val != 0;
72fd0718
VZ
4251}
4252
1191cb83 4253static void _print_next_block(int idx, const char *blk)
72fd0718 4254{
f1deab50 4255 pr_cont("%s%s", idx ? ", " : "", blk);
72fd0718
VZ
4256}
4257
1191cb83
ED
4258static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4259 bool print)
72fd0718
VZ
4260{
4261 int i = 0;
4262 u32 cur_bit = 0;
4263 for (i = 0; sig; i++) {
4264 cur_bit = ((u32)0x1 << i);
4265 if (sig & cur_bit) {
4266 switch (cur_bit) {
4267 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
c9ee9206
VZ
4268 if (print)
4269 _print_next_block(par_num++, "BRB");
72fd0718
VZ
4270 break;
4271 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
c9ee9206
VZ
4272 if (print)
4273 _print_next_block(par_num++, "PARSER");
72fd0718
VZ
4274 break;
4275 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
c9ee9206
VZ
4276 if (print)
4277 _print_next_block(par_num++, "TSDM");
72fd0718
VZ
4278 break;
4279 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
c9ee9206
VZ
4280 if (print)
4281 _print_next_block(par_num++,
4282 "SEARCHER");
4283 break;
4284 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4285 if (print)
4286 _print_next_block(par_num++, "TCM");
72fd0718
VZ
4287 break;
4288 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
c9ee9206
VZ
4289 if (print)
4290 _print_next_block(par_num++, "TSEMI");
4291 break;
4292 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4293 if (print)
4294 _print_next_block(par_num++, "XPB");
72fd0718
VZ
4295 break;
4296 }
4297
4298 /* Clear the bit */
4299 sig &= ~cur_bit;
4300 }
4301 }
4302
4303 return par_num;
4304}
4305
1191cb83
ED
4306static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4307 bool *global, bool print)
72fd0718
VZ
4308{
4309 int i = 0;
4310 u32 cur_bit = 0;
4311 for (i = 0; sig; i++) {
4312 cur_bit = ((u32)0x1 << i);
4313 if (sig & cur_bit) {
4314 switch (cur_bit) {
c9ee9206
VZ
4315 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4316 if (print)
4317 _print_next_block(par_num++, "PBF");
72fd0718
VZ
4318 break;
4319 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
c9ee9206
VZ
4320 if (print)
4321 _print_next_block(par_num++, "QM");
4322 break;
4323 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4324 if (print)
4325 _print_next_block(par_num++, "TM");
72fd0718
VZ
4326 break;
4327 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
c9ee9206
VZ
4328 if (print)
4329 _print_next_block(par_num++, "XSDM");
4330 break;
4331 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4332 if (print)
4333 _print_next_block(par_num++, "XCM");
72fd0718
VZ
4334 break;
4335 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
c9ee9206
VZ
4336 if (print)
4337 _print_next_block(par_num++, "XSEMI");
72fd0718
VZ
4338 break;
4339 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
c9ee9206
VZ
4340 if (print)
4341 _print_next_block(par_num++,
4342 "DOORBELLQ");
4343 break;
4344 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4345 if (print)
4346 _print_next_block(par_num++, "NIG");
72fd0718
VZ
4347 break;
4348 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
c9ee9206
VZ
4349 if (print)
4350 _print_next_block(par_num++,
4351 "VAUX PCI CORE");
4352 *global = true;
72fd0718
VZ
4353 break;
4354 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
c9ee9206
VZ
4355 if (print)
4356 _print_next_block(par_num++, "DEBUG");
72fd0718
VZ
4357 break;
4358 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
c9ee9206
VZ
4359 if (print)
4360 _print_next_block(par_num++, "USDM");
72fd0718 4361 break;
8736c826
VZ
4362 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4363 if (print)
4364 _print_next_block(par_num++, "UCM");
4365 break;
72fd0718 4366 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
c9ee9206
VZ
4367 if (print)
4368 _print_next_block(par_num++, "USEMI");
72fd0718
VZ
4369 break;
4370 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
c9ee9206
VZ
4371 if (print)
4372 _print_next_block(par_num++, "UPB");
72fd0718
VZ
4373 break;
4374 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
c9ee9206
VZ
4375 if (print)
4376 _print_next_block(par_num++, "CSDM");
72fd0718 4377 break;
8736c826
VZ
4378 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4379 if (print)
4380 _print_next_block(par_num++, "CCM");
4381 break;
72fd0718
VZ
4382 }
4383
4384 /* Clear the bit */
4385 sig &= ~cur_bit;
4386 }
4387 }
4388
4389 return par_num;
4390}
4391
1191cb83
ED
4392static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4393 bool print)
72fd0718
VZ
4394{
4395 int i = 0;
4396 u32 cur_bit = 0;
4397 for (i = 0; sig; i++) {
4398 cur_bit = ((u32)0x1 << i);
4399 if (sig & cur_bit) {
4400 switch (cur_bit) {
4401 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
c9ee9206
VZ
4402 if (print)
4403 _print_next_block(par_num++, "CSEMI");
72fd0718
VZ
4404 break;
4405 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
c9ee9206
VZ
4406 if (print)
4407 _print_next_block(par_num++, "PXP");
72fd0718
VZ
4408 break;
4409 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
c9ee9206
VZ
4410 if (print)
4411 _print_next_block(par_num++,
72fd0718
VZ
4412 "PXPPCICLOCKCLIENT");
4413 break;
4414 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
c9ee9206
VZ
4415 if (print)
4416 _print_next_block(par_num++, "CFC");
72fd0718
VZ
4417 break;
4418 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
c9ee9206
VZ
4419 if (print)
4420 _print_next_block(par_num++, "CDU");
4421 break;
4422 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4423 if (print)
4424 _print_next_block(par_num++, "DMAE");
72fd0718
VZ
4425 break;
4426 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
c9ee9206
VZ
4427 if (print)
4428 _print_next_block(par_num++, "IGU");
72fd0718
VZ
4429 break;
4430 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
c9ee9206
VZ
4431 if (print)
4432 _print_next_block(par_num++, "MISC");
72fd0718
VZ
4433 break;
4434 }
4435
4436 /* Clear the bit */
4437 sig &= ~cur_bit;
4438 }
4439 }
4440
4441 return par_num;
4442}
4443
1191cb83
ED
4444static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4445 bool *global, bool print)
72fd0718
VZ
4446{
4447 int i = 0;
4448 u32 cur_bit = 0;
4449 for (i = 0; sig; i++) {
4450 cur_bit = ((u32)0x1 << i);
4451 if (sig & cur_bit) {
4452 switch (cur_bit) {
4453 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
c9ee9206
VZ
4454 if (print)
4455 _print_next_block(par_num++, "MCP ROM");
4456 *global = true;
72fd0718
VZ
4457 break;
4458 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
c9ee9206
VZ
4459 if (print)
4460 _print_next_block(par_num++,
4461 "MCP UMP RX");
4462 *global = true;
72fd0718
VZ
4463 break;
4464 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
c9ee9206
VZ
4465 if (print)
4466 _print_next_block(par_num++,
4467 "MCP UMP TX");
4468 *global = true;
72fd0718
VZ
4469 break;
4470 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
c9ee9206
VZ
4471 if (print)
4472 _print_next_block(par_num++,
4473 "MCP SCPAD");
4474 *global = true;
72fd0718
VZ
4475 break;
4476 }
4477
4478 /* Clear the bit */
4479 sig &= ~cur_bit;
4480 }
4481 }
4482
4483 return par_num;
4484}
4485
1191cb83
ED
4486static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4487 bool print)
8736c826
VZ
4488{
4489 int i = 0;
4490 u32 cur_bit = 0;
4491 for (i = 0; sig; i++) {
4492 cur_bit = ((u32)0x1 << i);
4493 if (sig & cur_bit) {
4494 switch (cur_bit) {
4495 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4496 if (print)
4497 _print_next_block(par_num++, "PGLUE_B");
4498 break;
4499 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4500 if (print)
4501 _print_next_block(par_num++, "ATC");
4502 break;
4503 }
4504
4505 /* Clear the bit */
4506 sig &= ~cur_bit;
4507 }
4508 }
4509
4510 return par_num;
4511}
4512
1191cb83
ED
4513static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4514 u32 *sig)
72fd0718 4515{
8736c826
VZ
4516 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4517 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4518 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4519 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4520 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
72fd0718 4521 int par_num = 0;
51c1a580
MS
4522 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4523 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
8736c826
VZ
4524 sig[0] & HW_PRTY_ASSERT_SET_0,
4525 sig[1] & HW_PRTY_ASSERT_SET_1,
4526 sig[2] & HW_PRTY_ASSERT_SET_2,
4527 sig[3] & HW_PRTY_ASSERT_SET_3,
4528 sig[4] & HW_PRTY_ASSERT_SET_4);
c9ee9206
VZ
4529 if (print)
4530 netdev_err(bp->dev,
4531 "Parity errors detected in blocks: ");
4532 par_num = bnx2x_check_blocks_with_parity0(
8736c826 4533 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
c9ee9206 4534 par_num = bnx2x_check_blocks_with_parity1(
8736c826 4535 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
c9ee9206 4536 par_num = bnx2x_check_blocks_with_parity2(
8736c826 4537 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
c9ee9206 4538 par_num = bnx2x_check_blocks_with_parity3(
8736c826
VZ
4539 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4540 par_num = bnx2x_check_blocks_with_parity4(
4541 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4542
c9ee9206
VZ
4543 if (print)
4544 pr_cont("\n");
8736c826 4545
72fd0718
VZ
4546 return true;
4547 } else
4548 return false;
4549}
4550
c9ee9206
VZ
4551/**
4552 * bnx2x_chk_parity_attn - checks for parity attentions.
4553 *
4554 * @bp: driver handle
4555 * @global: true if there was a global attention
4556 * @print: show parity attention in syslog
4557 */
4558bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
877e9aa4 4559{
8736c826 4560 struct attn_route attn = { {0} };
72fd0718
VZ
4561 int port = BP_PORT(bp);
4562
4563 attn.sig[0] = REG_RD(bp,
4564 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4565 port*4);
4566 attn.sig[1] = REG_RD(bp,
4567 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4568 port*4);
4569 attn.sig[2] = REG_RD(bp,
4570 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4571 port*4);
4572 attn.sig[3] = REG_RD(bp,
4573 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4574 port*4);
4575
8736c826
VZ
4576 if (!CHIP_IS_E1x(bp))
4577 attn.sig[4] = REG_RD(bp,
4578 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4579 port*4);
4580
4581 return bnx2x_parity_attn(bp, global, print, attn.sig);
72fd0718
VZ
4582}
4583
f2e0899f 4584
1191cb83 4585static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
f2e0899f
DK
4586{
4587 u32 val;
4588 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4589
4590 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4591 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4592 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
51c1a580 4593 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
f2e0899f 4594 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
51c1a580 4595 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
f2e0899f 4596 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
51c1a580 4597 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
f2e0899f 4598 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
51c1a580 4599 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
f2e0899f
DK
4600 if (val &
4601 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
51c1a580 4602 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
f2e0899f
DK
4603 if (val &
4604 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
51c1a580 4605 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
f2e0899f 4606 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
51c1a580 4607 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
f2e0899f 4608 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
51c1a580 4609 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
f2e0899f 4610 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
51c1a580 4611 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
f2e0899f
DK
4612 }
4613 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4614 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4615 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4616 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4617 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4618 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
51c1a580 4619 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
f2e0899f 4620 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
51c1a580 4621 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
f2e0899f 4622 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
51c1a580 4623 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
f2e0899f
DK
4624 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4625 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4626 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
51c1a580 4627 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
f2e0899f
DK
4628 }
4629
4630 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4631 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4632 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4633 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4634 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4635 }
4636
4637}
4638
72fd0718
VZ
4639static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4640{
4641 struct attn_route attn, *group_mask;
34f80b04 4642 int port = BP_PORT(bp);
877e9aa4 4643 int index;
a2fbb9ea
ET
4644 u32 reg_addr;
4645 u32 val;
3fcaf2e5 4646 u32 aeu_mask;
c9ee9206 4647 bool global = false;
a2fbb9ea
ET
4648
4649 /* need to take HW lock because MCP or other port might also
4650 try to handle this event */
4a37fb66 4651 bnx2x_acquire_alr(bp);
a2fbb9ea 4652
c9ee9206
VZ
4653 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4654#ifndef BNX2X_STOP_ON_ERROR
72fd0718 4655 bp->recovery_state = BNX2X_RECOVERY_INIT;
7be08a72 4656 schedule_delayed_work(&bp->sp_rtnl_task, 0);
72fd0718
VZ
4657 /* Disable HW interrupts */
4658 bnx2x_int_disable(bp);
72fd0718
VZ
4659 /* In case of parity errors don't handle attentions so that
4660 * other function would "see" parity errors.
4661 */
c9ee9206
VZ
4662#else
4663 bnx2x_panic();
4664#endif
4665 bnx2x_release_alr(bp);
72fd0718
VZ
4666 return;
4667 }
4668
a2fbb9ea
ET
4669 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4670 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4671 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4672 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
619c5cb6 4673 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
4674 attn.sig[4] =
4675 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4676 else
4677 attn.sig[4] = 0;
4678
4679 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4680 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
a2fbb9ea
ET
4681
4682 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4683 if (deasserted & (1 << index)) {
72fd0718 4684 group_mask = &bp->attn_group[index];
a2fbb9ea 4685
51c1a580 4686 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
f2e0899f
DK
4687 index,
4688 group_mask->sig[0], group_mask->sig[1],
4689 group_mask->sig[2], group_mask->sig[3],
4690 group_mask->sig[4]);
a2fbb9ea 4691
f2e0899f
DK
4692 bnx2x_attn_int_deasserted4(bp,
4693 attn.sig[4] & group_mask->sig[4]);
877e9aa4 4694 bnx2x_attn_int_deasserted3(bp,
72fd0718 4695 attn.sig[3] & group_mask->sig[3]);
877e9aa4 4696 bnx2x_attn_int_deasserted1(bp,
72fd0718 4697 attn.sig[1] & group_mask->sig[1]);
877e9aa4 4698 bnx2x_attn_int_deasserted2(bp,
72fd0718 4699 attn.sig[2] & group_mask->sig[2]);
877e9aa4 4700 bnx2x_attn_int_deasserted0(bp,
72fd0718 4701 attn.sig[0] & group_mask->sig[0]);
a2fbb9ea
ET
4702 }
4703 }
4704
4a37fb66 4705 bnx2x_release_alr(bp);
a2fbb9ea 4706
f2e0899f
DK
4707 if (bp->common.int_block == INT_BLOCK_HC)
4708 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4709 COMMAND_REG_ATTN_BITS_CLR);
4710 else
4711 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
a2fbb9ea
ET
4712
4713 val = ~deasserted;
f2e0899f
DK
4714 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4715 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5c862848 4716 REG_WR(bp, reg_addr, val);
a2fbb9ea 4717
a2fbb9ea 4718 if (~bp->attn_state & deasserted)
3fcaf2e5 4719 BNX2X_ERR("IGU ERROR\n");
a2fbb9ea
ET
4720
4721 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4722 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4723
3fcaf2e5
EG
4724 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4725 aeu_mask = REG_RD(bp, reg_addr);
4726
4727 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4728 aeu_mask, deasserted);
72fd0718 4729 aeu_mask |= (deasserted & 0x3ff);
3fcaf2e5 4730 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
a2fbb9ea 4731
3fcaf2e5
EG
4732 REG_WR(bp, reg_addr, aeu_mask);
4733 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
a2fbb9ea
ET
4734
4735 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4736 bp->attn_state &= ~deasserted;
4737 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4738}
4739
4740static void bnx2x_attn_int(struct bnx2x *bp)
4741{
4742 /* read local copy of bits */
68d59484
EG
4743 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4744 attn_bits);
4745 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4746 attn_bits_ack);
a2fbb9ea
ET
4747 u32 attn_state = bp->attn_state;
4748
4749 /* look for changed bits */
4750 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4751 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4752
4753 DP(NETIF_MSG_HW,
4754 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4755 attn_bits, attn_ack, asserted, deasserted);
4756
4757 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
34f80b04 4758 BNX2X_ERR("BAD attention state\n");
a2fbb9ea
ET
4759
4760 /* handle bits that were raised */
4761 if (asserted)
4762 bnx2x_attn_int_asserted(bp, asserted);
4763
4764 if (deasserted)
4765 bnx2x_attn_int_deasserted(bp, deasserted);
4766}
4767
619c5cb6
VZ
4768void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4769 u16 index, u8 op, u8 update)
4770{
dc1ba591
AE
4771 u32 igu_addr = bp->igu_base_addr;
4772 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
619c5cb6
VZ
4773 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4774 igu_addr);
4775}
4776
1191cb83 4777static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
523224a3
DK
4778{
4779 /* No memory barriers */
4780 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4781 mmiowb(); /* keep prod updates ordered */
4782}
4783
523224a3
DK
4784static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4785 union event_ring_elem *elem)
4786{
619c5cb6
VZ
4787 u8 err = elem->message.error;
4788
523224a3 4789 if (!bp->cnic_eth_dev.starting_cid ||
c3a8ce61
VZ
4790 (cid < bp->cnic_eth_dev.starting_cid &&
4791 cid != bp->cnic_eth_dev.iscsi_l2_cid))
523224a3
DK
4792 return 1;
4793
4794 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4795
619c5cb6
VZ
4796 if (unlikely(err)) {
4797
523224a3
DK
4798 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4799 cid);
823e1d90 4800 bnx2x_panic_dump(bp, false);
523224a3 4801 }
619c5cb6 4802 bnx2x_cnic_cfc_comp(bp, cid, err);
523224a3
DK
4803 return 0;
4804}
523224a3 4805
1191cb83 4806static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
619c5cb6
VZ
4807{
4808 struct bnx2x_mcast_ramrod_params rparam;
4809 int rc;
4810
4811 memset(&rparam, 0, sizeof(rparam));
4812
4813 rparam.mcast_obj = &bp->mcast_obj;
4814
4815 netif_addr_lock_bh(bp->dev);
4816
4817 /* Clear pending state for the last command */
4818 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4819
4820 /* If there are pending mcast commands - send them */
4821 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4822 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4823 if (rc < 0)
4824 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4825 rc);
4826 }
4827
4828 netif_addr_unlock_bh(bp->dev);
4829}
4830
1191cb83
ED
4831static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4832 union event_ring_elem *elem)
619c5cb6
VZ
4833{
4834 unsigned long ramrod_flags = 0;
4835 int rc = 0;
4836 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4837 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4838
4839 /* Always push next commands out, don't wait here */
4840 __set_bit(RAMROD_CONT, &ramrod_flags);
4841
86564c3f
YM
4842 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
4843 >> BNX2X_SWCID_SHIFT) {
619c5cb6 4844 case BNX2X_FILTER_MAC_PENDING:
51c1a580 4845 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
55c11941 4846 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
619c5cb6
VZ
4847 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4848 else
15192a8c 4849 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
619c5cb6
VZ
4850
4851 break;
619c5cb6 4852 case BNX2X_FILTER_MCAST_PENDING:
51c1a580 4853 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
619c5cb6
VZ
4854 /* This is only relevant for 57710 where multicast MACs are
4855 * configured as unicast MACs using the same ramrod.
4856 */
4857 bnx2x_handle_mcast_eqe(bp);
4858 return;
4859 default:
4860 BNX2X_ERR("Unsupported classification command: %d\n",
4861 elem->message.data.eth_event.echo);
4862 return;
4863 }
4864
4865 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4866
4867 if (rc < 0)
4868 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4869 else if (rc > 0)
4870 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4871
4872}
4873
619c5cb6 4874static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
619c5cb6 4875
1191cb83 4876static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
619c5cb6
VZ
4877{
4878 netif_addr_lock_bh(bp->dev);
4879
4880 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4881
4882 /* Send rx_mode command again if was requested */
4883 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4884 bnx2x_set_storm_rx_mode(bp);
619c5cb6
VZ
4885 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4886 &bp->sp_state))
4887 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4888 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4889 &bp->sp_state))
4890 bnx2x_set_iscsi_eth_rx_mode(bp, false);
619c5cb6
VZ
4891
4892 netif_addr_unlock_bh(bp->dev);
4893}
4894
1191cb83 4895static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
a3348722
BW
4896 union event_ring_elem *elem)
4897{
4898 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4899 DP(BNX2X_MSG_SP,
4900 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4901 elem->message.data.vif_list_event.func_bit_map);
4902 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4903 elem->message.data.vif_list_event.func_bit_map);
4904 } else if (elem->message.data.vif_list_event.echo ==
4905 VIF_LIST_RULE_SET) {
4906 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4907 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4908 }
4909}
4910
4911/* called with rtnl_lock */
1191cb83 4912static void bnx2x_after_function_update(struct bnx2x *bp)
a3348722
BW
4913{
4914 int q, rc;
4915 struct bnx2x_fastpath *fp;
4916 struct bnx2x_queue_state_params queue_params = {NULL};
4917 struct bnx2x_queue_update_params *q_update_params =
4918 &queue_params.params.update;
4919
2de67439 4920 /* Send Q update command with afex vlan removal values for all Qs */
a3348722
BW
4921 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4922
4923 /* set silent vlan removal values according to vlan mode */
4924 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4925 &q_update_params->update_flags);
4926 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4927 &q_update_params->update_flags);
4928 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4929
4930 /* in access mode mark mask and value are 0 to strip all vlans */
4931 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4932 q_update_params->silent_removal_value = 0;
4933 q_update_params->silent_removal_mask = 0;
4934 } else {
4935 q_update_params->silent_removal_value =
4936 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4937 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4938 }
4939
4940 for_each_eth_queue(bp, q) {
4941 /* Set the appropriate Queue object */
4942 fp = &bp->fp[q];
15192a8c 4943 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4944
4945 /* send the ramrod */
4946 rc = bnx2x_queue_state_change(bp, &queue_params);
4947 if (rc < 0)
4948 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4949 q);
4950 }
4951
a3348722 4952 if (!NO_FCOE(bp)) {
65565884 4953 fp = &bp->fp[FCOE_IDX(bp)];
15192a8c 4954 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
a3348722
BW
4955
4956 /* clear pending completion bit */
4957 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4958
4959 /* mark latest Q bit */
4960 smp_mb__before_clear_bit();
4961 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4962 smp_mb__after_clear_bit();
4963
4964 /* send Q update ramrod for FCoE Q */
4965 rc = bnx2x_queue_state_change(bp, &queue_params);
4966 if (rc < 0)
4967 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4968 q);
4969 } else {
4970 /* If no FCoE ring - ACK MCP now */
4971 bnx2x_link_report(bp);
4972 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4973 }
a3348722
BW
4974}
4975
1191cb83 4976static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
619c5cb6
VZ
4977 struct bnx2x *bp, u32 cid)
4978{
94f05b0f 4979 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
55c11941
MS
4980
4981 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
15192a8c 4982 return &bnx2x_fcoe_sp_obj(bp, q_obj);
619c5cb6 4983 else
15192a8c 4984 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
619c5cb6
VZ
4985}
4986
523224a3
DK
4987static void bnx2x_eq_int(struct bnx2x *bp)
4988{
4989 u16 hw_cons, sw_cons, sw_prod;
4990 union event_ring_elem *elem;
55c11941 4991 u8 echo;
523224a3
DK
4992 u32 cid;
4993 u8 opcode;
fd1fc79d 4994 int rc, spqe_cnt = 0;
619c5cb6
VZ
4995 struct bnx2x_queue_sp_obj *q_obj;
4996 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4997 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
523224a3
DK
4998
4999 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5000
5001 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
5002 * when we get the the next-page we nned to adjust so the loop
5003 * condition below will be met. The next element is the size of a
5004 * regular element and hence incrementing by 1
5005 */
5006 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5007 hw_cons++;
5008
25985edc 5009 /* This function may never run in parallel with itself for a
523224a3
DK
5010 * specific bp, thus there is no need in "paired" read memory
5011 * barrier here.
5012 */
5013 sw_cons = bp->eq_cons;
5014 sw_prod = bp->eq_prod;
5015
d6cae238 5016 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
6e30dd4e 5017 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
523224a3
DK
5018
5019 for (; sw_cons != hw_cons;
5020 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5021
523224a3
DK
5022 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5023
fd1fc79d
AE
5024 rc = bnx2x_iov_eq_sp_event(bp, elem);
5025 if (!rc) {
5026 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5027 rc);
5028 goto next_spqe;
5029 }
523224a3 5030
86564c3f
YM
5031 /* elem CID originates from FW; actually LE */
5032 cid = SW_CID((__force __le32)
5033 elem->message.data.cfc_del_event.cid);
5034 opcode = elem->message.opcode;
523224a3
DK
5035
5036 /* handle eq element */
5037 switch (opcode) {
fd1fc79d
AE
5038 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5039 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
5040 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
5041 continue;
5042
523224a3 5043 case EVENT_RING_OPCODE_STAT_QUERY:
51c1a580
MS
5044 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
5045 "got statistics comp event %d\n",
619c5cb6 5046 bp->stats_comp++);
523224a3 5047 /* nothing to do with stats comp */
d6cae238 5048 goto next_spqe;
523224a3
DK
5049
5050 case EVENT_RING_OPCODE_CFC_DEL:
5051 /* handle according to cid range */
5052 /*
5053 * we may want to verify here that the bp state is
5054 * HALTING
5055 */
d6cae238 5056 DP(BNX2X_MSG_SP,
523224a3 5057 "got delete ramrod for MULTI[%d]\n", cid);
55c11941
MS
5058
5059 if (CNIC_LOADED(bp) &&
5060 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
523224a3 5061 goto next_spqe;
55c11941 5062
619c5cb6
VZ
5063 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5064
5065 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5066 break;
5067
5068
523224a3
DK
5069
5070 goto next_spqe;
e4901dde
VZ
5071
5072 case EVENT_RING_OPCODE_STOP_TRAFFIC:
51c1a580 5073 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
6debea87
DK
5074 if (f_obj->complete_cmd(bp, f_obj,
5075 BNX2X_F_CMD_TX_STOP))
5076 break;
e4901dde
VZ
5077 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
5078 goto next_spqe;
619c5cb6 5079
e4901dde 5080 case EVENT_RING_OPCODE_START_TRAFFIC:
51c1a580 5081 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
6debea87
DK
5082 if (f_obj->complete_cmd(bp, f_obj,
5083 BNX2X_F_CMD_TX_START))
5084 break;
e4901dde
VZ
5085 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
5086 goto next_spqe;
55c11941 5087
a3348722 5088 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
55c11941
MS
5089 echo = elem->message.data.function_update_event.echo;
5090 if (echo == SWITCH_UPDATE) {
5091 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5092 "got FUNC_SWITCH_UPDATE ramrod\n");
5093 if (f_obj->complete_cmd(
5094 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5095 break;
a3348722 5096
55c11941
MS
5097 } else {
5098 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5099 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5100 f_obj->complete_cmd(bp, f_obj,
5101 BNX2X_F_CMD_AFEX_UPDATE);
5102
5103 /* We will perform the Queues update from
5104 * sp_rtnl task as all Queue SP operations
5105 * should run under rtnl_lock.
5106 */
5107 smp_mb__before_clear_bit();
5108 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5109 &bp->sp_rtnl_state);
5110 smp_mb__after_clear_bit();
5111
5112 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5113 }
a3348722 5114
a3348722
BW
5115 goto next_spqe;
5116
5117 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5118 f_obj->complete_cmd(bp, f_obj,
5119 BNX2X_F_CMD_AFEX_VIFLISTS);
5120 bnx2x_after_afex_vif_lists(bp, elem);
5121 goto next_spqe;
619c5cb6 5122 case EVENT_RING_OPCODE_FUNCTION_START:
51c1a580
MS
5123 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5124 "got FUNC_START ramrod\n");
619c5cb6
VZ
5125 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5126 break;
5127
5128 goto next_spqe;
5129
5130 case EVENT_RING_OPCODE_FUNCTION_STOP:
51c1a580
MS
5131 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5132 "got FUNC_STOP ramrod\n");
619c5cb6
VZ
5133 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5134 break;
5135
5136 goto next_spqe;
523224a3
DK
5137 }
5138
5139 switch (opcode | bp->state) {
619c5cb6
VZ
5140 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5141 BNX2X_STATE_OPEN):
5142 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
523224a3 5143 BNX2X_STATE_OPENING_WAIT4_PORT):
619c5cb6
VZ
5144 cid = elem->message.data.eth_event.echo &
5145 BNX2X_SWCID_MASK;
d6cae238 5146 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
619c5cb6
VZ
5147 cid);
5148 rss_raw->clear_pending(rss_raw);
523224a3
DK
5149 break;
5150
619c5cb6
VZ
5151 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5152 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
5153 case (EVENT_RING_OPCODE_SET_MAC |
523224a3 5154 BNX2X_STATE_CLOSING_WAIT4_HALT):
619c5cb6
VZ
5155 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5156 BNX2X_STATE_OPEN):
5157 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5158 BNX2X_STATE_DIAG):
5159 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5160 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5161 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
619c5cb6 5162 bnx2x_handle_classification_eqe(bp, elem);
523224a3
DK
5163 break;
5164
619c5cb6
VZ
5165 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5166 BNX2X_STATE_OPEN):
5167 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5168 BNX2X_STATE_DIAG):
5169 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5170 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5171 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
619c5cb6 5172 bnx2x_handle_mcast_eqe(bp);
523224a3
DK
5173 break;
5174
619c5cb6
VZ
5175 case (EVENT_RING_OPCODE_FILTERS_RULES |
5176 BNX2X_STATE_OPEN):
5177 case (EVENT_RING_OPCODE_FILTERS_RULES |
5178 BNX2X_STATE_DIAG):
5179 case (EVENT_RING_OPCODE_FILTERS_RULES |
523224a3 5180 BNX2X_STATE_CLOSING_WAIT4_HALT):
d6cae238 5181 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
619c5cb6 5182 bnx2x_handle_rx_mode_eqe(bp);
523224a3
DK
5183 break;
5184 default:
5185 /* unknown event log error and continue */
619c5cb6
VZ
5186 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5187 elem->message.opcode, bp->state);
523224a3
DK
5188 }
5189next_spqe:
5190 spqe_cnt++;
5191 } /* for */
5192
8fe23fbd 5193 smp_mb__before_atomic_inc();
6e30dd4e 5194 atomic_add(spqe_cnt, &bp->eq_spq_left);
523224a3
DK
5195
5196 bp->eq_cons = sw_cons;
5197 bp->eq_prod = sw_prod;
5198 /* Make sure that above mem writes were issued towards the memory */
5199 smp_wmb();
5200
5201 /* update producer */
5202 bnx2x_update_eq_prod(bp, bp->eq_prod);
5203}
5204
a2fbb9ea
ET
5205static void bnx2x_sp_task(struct work_struct *work)
5206{
1cf167f2 5207 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
a2fbb9ea 5208
fd1fc79d 5209 DP(BNX2X_MSG_SP, "sp task invoked\n");
a2fbb9ea 5210
fd1fc79d
AE
5211 /* make sure the atomic interupt_occurred has been written */
5212 smp_rmb();
5213 if (atomic_read(&bp->interrupt_occurred)) {
a2fbb9ea 5214
fd1fc79d
AE
5215 /* what work needs to be performed? */
5216 u16 status = bnx2x_update_dsb_idx(bp);
cdaa7cb8 5217
fd1fc79d
AE
5218 DP(BNX2X_MSG_SP, "status %x\n", status);
5219 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5220 atomic_set(&bp->interrupt_occurred, 0);
5221
5222 /* HW attentions */
5223 if (status & BNX2X_DEF_SB_ATT_IDX) {
5224 bnx2x_attn_int(bp);
5225 status &= ~BNX2X_DEF_SB_ATT_IDX;
5226 }
5227
5228 /* SP events: STAT_QUERY and others */
5229 if (status & BNX2X_DEF_SB_IDX) {
5230 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
523224a3 5231
55c11941 5232 if (FCOE_INIT(bp) &&
fd1fc79d
AE
5233 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5234 /* Prevent local bottom-halves from running as
5235 * we are going to change the local NAPI list.
5236 */
5237 local_bh_disable();
5238 napi_schedule(&bnx2x_fcoe(bp, napi));
5239 local_bh_enable();
5240 }
5241
5242 /* Handle EQ completions */
5243 bnx2x_eq_int(bp);
5244 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5245 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5246
5247 status &= ~BNX2X_DEF_SB_IDX;
019dbb4c 5248 }
55c11941 5249
fd1fc79d
AE
5250 /* if status is non zero then perhaps something went wrong */
5251 if (unlikely(status))
5252 DP(BNX2X_MSG_SP,
5253 "got an unknown interrupt! (status 0x%x)\n", status);
523224a3 5254
fd1fc79d
AE
5255 /* ack status block only if something was actually handled */
5256 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5257 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
523224a3 5258
cdaa7cb8
VZ
5259 }
5260
fd1fc79d
AE
5261 /* must be called after the EQ processing (since eq leads to sriov
5262 * ramrod completion flows).
5263 * This flow may have been scheduled by the arrival of a ramrod
5264 * completion, or by the sriov code rescheduling itself.
5265 */
5266 bnx2x_iov_sp_task(bp);
a3348722
BW
5267
5268 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5269 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5270 &bp->sp_state)) {
5271 bnx2x_link_report(bp);
5272 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5273 }
a2fbb9ea
ET
5274}
5275
9f6c9258 5276irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
a2fbb9ea
ET
5277{
5278 struct net_device *dev = dev_instance;
5279 struct bnx2x *bp = netdev_priv(dev);
5280
523224a3
DK
5281 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5282 IGU_INT_DISABLE, 0);
a2fbb9ea
ET
5283
5284#ifdef BNX2X_STOP_ON_ERROR
5285 if (unlikely(bp->panic))
5286 return IRQ_HANDLED;
5287#endif
5288
55c11941 5289 if (CNIC_LOADED(bp)) {
993ac7b5
MC
5290 struct cnic_ops *c_ops;
5291
5292 rcu_read_lock();
5293 c_ops = rcu_dereference(bp->cnic_ops);
5294 if (c_ops)
5295 c_ops->cnic_handler(bp->cnic_data, NULL);
5296 rcu_read_unlock();
5297 }
55c11941 5298
fd1fc79d
AE
5299 /* schedule sp task to perform default status block work, ack
5300 * attentions and enable interrupts.
5301 */
5302 bnx2x_schedule_sp_task(bp);
a2fbb9ea
ET
5303
5304 return IRQ_HANDLED;
5305}
5306
5307/* end of slow path */
5308
619c5cb6
VZ
5309
5310void bnx2x_drv_pulse(struct bnx2x *bp)
5311{
5312 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5313 bp->fw_drv_pulse_wr_seq);
5314}
5315
a2fbb9ea
ET
5316static void bnx2x_timer(unsigned long data)
5317{
5318 struct bnx2x *bp = (struct bnx2x *) data;
5319
5320 if (!netif_running(bp->dev))
5321 return;
5322
67c431a5
AE
5323 if (IS_PF(bp) &&
5324 !BP_NOMCP(bp)) {
f2e0899f 5325 int mb_idx = BP_FW_MB_IDX(bp);
a2fbb9ea
ET
5326 u32 drv_pulse;
5327 u32 mcp_pulse;
5328
5329 ++bp->fw_drv_pulse_wr_seq;
5330 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5331 /* TBD - add SYSTEM_TIME */
5332 drv_pulse = bp->fw_drv_pulse_wr_seq;
619c5cb6 5333 bnx2x_drv_pulse(bp);
a2fbb9ea 5334
f2e0899f 5335 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
a2fbb9ea
ET
5336 MCP_PULSE_SEQ_MASK);
5337 /* The delta between driver pulse and mcp response
5338 * should be 1 (before mcp response) or 0 (after mcp response)
5339 */
5340 if ((drv_pulse != mcp_pulse) &&
5341 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5342 /* someone lost a heartbeat... */
5343 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5344 drv_pulse, mcp_pulse);
5345 }
5346 }
5347
f34d28ea 5348 if (bp->state == BNX2X_STATE_OPEN)
bb2a0f7a 5349 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
a2fbb9ea 5350
abc5a021
AE
5351 /* sample pf vf bulletin board for new posts from pf */
5352 if (IS_VF(bp))
5353 bnx2x_sample_bulletin(bp);
5354
a2fbb9ea
ET
5355 mod_timer(&bp->timer, jiffies + bp->current_interval);
5356}
5357
5358/* end of Statistics */
5359
5360/* nic init */
5361
5362/*
5363 * nic init service functions
5364 */
5365
1191cb83 5366static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
a2fbb9ea 5367{
523224a3
DK
5368 u32 i;
5369 if (!(len%4) && !(addr%4))
5370 for (i = 0; i < len; i += 4)
5371 REG_WR(bp, addr + i, fill);
5372 else
5373 for (i = 0; i < len; i++)
5374 REG_WR8(bp, addr + i, fill);
34f80b04 5375
34f80b04
EG
5376}
5377
523224a3 5378/* helper: writes FP SP data to FW - data_size in dwords */
1191cb83
ED
5379static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5380 int fw_sb_id,
5381 u32 *sb_data_p,
5382 u32 data_size)
34f80b04 5383{
a2fbb9ea 5384 int index;
523224a3
DK
5385 for (index = 0; index < data_size; index++)
5386 REG_WR(bp, BAR_CSTRORM_INTMEM +
5387 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5388 sizeof(u32)*index,
5389 *(sb_data_p + index));
5390}
a2fbb9ea 5391
1191cb83 5392static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
523224a3
DK
5393{
5394 u32 *sb_data_p;
5395 u32 data_size = 0;
f2e0899f 5396 struct hc_status_block_data_e2 sb_data_e2;
523224a3 5397 struct hc_status_block_data_e1x sb_data_e1x;
a2fbb9ea 5398
523224a3 5399 /* disable the function first */
619c5cb6 5400 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5401 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5402 sb_data_e2.common.state = SB_DISABLED;
f2e0899f
DK
5403 sb_data_e2.common.p_func.vf_valid = false;
5404 sb_data_p = (u32 *)&sb_data_e2;
5405 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5406 } else {
5407 memset(&sb_data_e1x, 0,
5408 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5409 sb_data_e1x.common.state = SB_DISABLED;
f2e0899f
DK
5410 sb_data_e1x.common.p_func.vf_valid = false;
5411 sb_data_p = (u32 *)&sb_data_e1x;
5412 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5413 }
523224a3 5414 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
a2fbb9ea 5415
523224a3
DK
5416 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5417 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5418 CSTORM_STATUS_BLOCK_SIZE);
5419 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5420 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5421 CSTORM_SYNC_BLOCK_SIZE);
5422}
34f80b04 5423
523224a3 5424/* helper: writes SP SB data to FW */
1191cb83 5425static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
523224a3
DK
5426 struct hc_sp_status_block_data *sp_sb_data)
5427{
5428 int func = BP_FUNC(bp);
5429 int i;
5430 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5431 REG_WR(bp, BAR_CSTRORM_INTMEM +
5432 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5433 i*sizeof(u32),
5434 *((u32 *)sp_sb_data + i));
34f80b04
EG
5435}
5436
1191cb83 5437static void bnx2x_zero_sp_sb(struct bnx2x *bp)
34f80b04
EG
5438{
5439 int func = BP_FUNC(bp);
523224a3
DK
5440 struct hc_sp_status_block_data sp_sb_data;
5441 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
a2fbb9ea 5442
619c5cb6 5443 sp_sb_data.state = SB_DISABLED;
523224a3
DK
5444 sp_sb_data.p_func.vf_valid = false;
5445
5446 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5447
5448 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5449 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5450 CSTORM_SP_STATUS_BLOCK_SIZE);
5451 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5452 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5453 CSTORM_SP_SYNC_BLOCK_SIZE);
5454
5455}
5456
5457
1191cb83 5458static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
523224a3
DK
5459 int igu_sb_id, int igu_seg_id)
5460{
5461 hc_sm->igu_sb_id = igu_sb_id;
5462 hc_sm->igu_seg_id = igu_seg_id;
5463 hc_sm->timer_value = 0xFF;
5464 hc_sm->time_to_expire = 0xFFFFFFFF;
a2fbb9ea
ET
5465}
5466
150966ad
AE
5467
5468/* allocates state machine ids. */
1191cb83 5469static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
150966ad
AE
5470{
5471 /* zero out state machine indices */
5472 /* rx indices */
5473 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5474
5475 /* tx indices */
5476 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5477 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5478 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5479 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5480
5481 /* map indices */
5482 /* rx indices */
5483 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5484 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5485
5486 /* tx indices */
5487 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5488 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5489 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5490 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5491 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5492 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5493 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5494 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5495}
5496
b93288d5 5497void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
523224a3 5498 u8 vf_valid, int fw_sb_id, int igu_sb_id)
a2fbb9ea 5499{
523224a3
DK
5500 int igu_seg_id;
5501
f2e0899f 5502 struct hc_status_block_data_e2 sb_data_e2;
523224a3
DK
5503 struct hc_status_block_data_e1x sb_data_e1x;
5504 struct hc_status_block_sm *hc_sm_p;
523224a3
DK
5505 int data_size;
5506 u32 *sb_data_p;
5507
f2e0899f
DK
5508 if (CHIP_INT_MODE_IS_BC(bp))
5509 igu_seg_id = HC_SEG_ACCESS_NORM;
5510 else
5511 igu_seg_id = IGU_SEG_ACCESS_NORM;
523224a3
DK
5512
5513 bnx2x_zero_fp_sb(bp, fw_sb_id);
5514
619c5cb6 5515 if (!CHIP_IS_E1x(bp)) {
f2e0899f 5516 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
619c5cb6 5517 sb_data_e2.common.state = SB_ENABLED;
f2e0899f
DK
5518 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5519 sb_data_e2.common.p_func.vf_id = vfid;
5520 sb_data_e2.common.p_func.vf_valid = vf_valid;
5521 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5522 sb_data_e2.common.same_igu_sb_1b = true;
5523 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5524 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5525 hc_sm_p = sb_data_e2.common.state_machine;
f2e0899f
DK
5526 sb_data_p = (u32 *)&sb_data_e2;
5527 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
150966ad 5528 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
f2e0899f
DK
5529 } else {
5530 memset(&sb_data_e1x, 0,
5531 sizeof(struct hc_status_block_data_e1x));
619c5cb6 5532 sb_data_e1x.common.state = SB_ENABLED;
f2e0899f
DK
5533 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5534 sb_data_e1x.common.p_func.vf_id = 0xff;
5535 sb_data_e1x.common.p_func.vf_valid = false;
5536 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5537 sb_data_e1x.common.same_igu_sb_1b = true;
5538 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5539 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5540 hc_sm_p = sb_data_e1x.common.state_machine;
f2e0899f
DK
5541 sb_data_p = (u32 *)&sb_data_e1x;
5542 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
150966ad 5543 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
f2e0899f 5544 }
523224a3
DK
5545
5546 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5547 igu_sb_id, igu_seg_id);
5548 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5549 igu_sb_id, igu_seg_id);
5550
51c1a580 5551 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
523224a3 5552
86564c3f 5553 /* write indices to HW - PCI guarantees endianity of regpairs */
523224a3
DK
5554 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5555}
5556
619c5cb6 5557static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
523224a3
DK
5558 u16 tx_usec, u16 rx_usec)
5559{
6383c0b3 5560 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
523224a3 5561 false, rx_usec);
6383c0b3
AE
5562 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5563 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5564 tx_usec);
5565 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5566 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5567 tx_usec);
5568 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5569 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5570 tx_usec);
523224a3 5571}
f2e0899f 5572
523224a3
DK
5573static void bnx2x_init_def_sb(struct bnx2x *bp)
5574{
5575 struct host_sp_status_block *def_sb = bp->def_status_blk;
5576 dma_addr_t mapping = bp->def_status_blk_mapping;
5577 int igu_sp_sb_index;
5578 int igu_seg_id;
34f80b04
EG
5579 int port = BP_PORT(bp);
5580 int func = BP_FUNC(bp);
f2eaeb58 5581 int reg_offset, reg_offset_en5;
a2fbb9ea 5582 u64 section;
523224a3
DK
5583 int index;
5584 struct hc_sp_status_block_data sp_sb_data;
5585 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5586
f2e0899f
DK
5587 if (CHIP_INT_MODE_IS_BC(bp)) {
5588 igu_sp_sb_index = DEF_SB_IGU_ID;
5589 igu_seg_id = HC_SEG_ACCESS_DEF;
5590 } else {
5591 igu_sp_sb_index = bp->igu_dsb_id;
5592 igu_seg_id = IGU_SEG_ACCESS_DEF;
5593 }
a2fbb9ea
ET
5594
5595 /* ATTN */
523224a3 5596 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
a2fbb9ea 5597 atten_status_block);
523224a3 5598 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
a2fbb9ea 5599
49d66772
ET
5600 bp->attn_state = 0;
5601
a2fbb9ea
ET
5602 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5603 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
f2eaeb58
DK
5604 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5605 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
34f80b04 5606 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
523224a3
DK
5607 int sindex;
5608 /* take care of sig[0]..sig[4] */
5609 for (sindex = 0; sindex < 4; sindex++)
5610 bp->attn_group[index].sig[sindex] =
5611 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
f2e0899f 5612
619c5cb6 5613 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
5614 /*
5615 * enable5 is separate from the rest of the registers,
5616 * and therefore the address skip is 4
5617 * and not 16 between the different groups
5618 */
5619 bp->attn_group[index].sig[4] = REG_RD(bp,
f2eaeb58 5620 reg_offset_en5 + 0x4*index);
f2e0899f
DK
5621 else
5622 bp->attn_group[index].sig[4] = 0;
a2fbb9ea
ET
5623 }
5624
f2e0899f
DK
5625 if (bp->common.int_block == INT_BLOCK_HC) {
5626 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5627 HC_REG_ATTN_MSG0_ADDR_L);
5628
5629 REG_WR(bp, reg_offset, U64_LO(section));
5630 REG_WR(bp, reg_offset + 4, U64_HI(section));
619c5cb6 5631 } else if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5632 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5633 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5634 }
a2fbb9ea 5635
523224a3
DK
5636 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5637 sp_sb);
a2fbb9ea 5638
523224a3 5639 bnx2x_zero_sp_sb(bp);
a2fbb9ea 5640
86564c3f 5641 /* PCI guarantees endianity of regpairs */
619c5cb6 5642 sp_sb_data.state = SB_ENABLED;
523224a3
DK
5643 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5644 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5645 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5646 sp_sb_data.igu_seg_id = igu_seg_id;
5647 sp_sb_data.p_func.pf_id = func;
f2e0899f 5648 sp_sb_data.p_func.vnic_id = BP_VN(bp);
523224a3 5649 sp_sb_data.p_func.vf_id = 0xff;
a2fbb9ea 5650
523224a3 5651 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
49d66772 5652
523224a3 5653 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
a2fbb9ea
ET
5654}
5655
9f6c9258 5656void bnx2x_update_coalesce(struct bnx2x *bp)
a2fbb9ea 5657{
a2fbb9ea
ET
5658 int i;
5659
ec6ba945 5660 for_each_eth_queue(bp, i)
523224a3 5661 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
423cfa7e 5662 bp->tx_ticks, bp->rx_ticks);
a2fbb9ea
ET
5663}
5664
a2fbb9ea
ET
5665static void bnx2x_init_sp_ring(struct bnx2x *bp)
5666{
a2fbb9ea 5667 spin_lock_init(&bp->spq_lock);
6e30dd4e 5668 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
a2fbb9ea 5669
a2fbb9ea 5670 bp->spq_prod_idx = 0;
a2fbb9ea
ET
5671 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5672 bp->spq_prod_bd = bp->spq;
5673 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
a2fbb9ea
ET
5674}
5675
523224a3 5676static void bnx2x_init_eq_ring(struct bnx2x *bp)
a2fbb9ea
ET
5677{
5678 int i;
523224a3
DK
5679 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5680 union event_ring_elem *elem =
5681 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
a2fbb9ea 5682
523224a3
DK
5683 elem->next_page.addr.hi =
5684 cpu_to_le32(U64_HI(bp->eq_mapping +
5685 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5686 elem->next_page.addr.lo =
5687 cpu_to_le32(U64_LO(bp->eq_mapping +
5688 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
a2fbb9ea 5689 }
523224a3
DK
5690 bp->eq_cons = 0;
5691 bp->eq_prod = NUM_EQ_DESC;
5692 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6e30dd4e
VZ
5693 /* we want a warning message before it gets rought... */
5694 atomic_set(&bp->eq_spq_left,
5695 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
a2fbb9ea
ET
5696}
5697
619c5cb6 5698/* called with netif_addr_lock_bh() */
924d75ab
YM
5699int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5700 unsigned long rx_mode_flags,
5701 unsigned long rx_accept_flags,
5702 unsigned long tx_accept_flags,
5703 unsigned long ramrod_flags)
ab532cf3 5704{
619c5cb6
VZ
5705 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5706 int rc;
5707
5708 memset(&ramrod_param, 0, sizeof(ramrod_param));
5709
5710 /* Prepare ramrod parameters */
5711 ramrod_param.cid = 0;
5712 ramrod_param.cl_id = cl_id;
5713 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5714 ramrod_param.func_id = BP_FUNC(bp);
ab532cf3 5715
619c5cb6
VZ
5716 ramrod_param.pstate = &bp->sp_state;
5717 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
ab532cf3 5718
619c5cb6
VZ
5719 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5720 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5721
5722 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5723
5724 ramrod_param.ramrod_flags = ramrod_flags;
5725 ramrod_param.rx_mode_flags = rx_mode_flags;
5726
5727 ramrod_param.rx_accept_flags = rx_accept_flags;
5728 ramrod_param.tx_accept_flags = tx_accept_flags;
5729
5730 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5731 if (rc < 0) {
5732 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
924d75ab 5733 return rc;
619c5cb6 5734 }
924d75ab
YM
5735
5736 return 0;
a2fbb9ea
ET
5737}
5738
86564c3f
YM
5739static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
5740 unsigned long *rx_accept_flags,
5741 unsigned long *tx_accept_flags)
471de716 5742{
924d75ab
YM
5743 /* Clear the flags first */
5744 *rx_accept_flags = 0;
5745 *tx_accept_flags = 0;
619c5cb6 5746
924d75ab 5747 switch (rx_mode) {
619c5cb6
VZ
5748 case BNX2X_RX_MODE_NONE:
5749 /*
5750 * 'drop all' supersedes any accept flags that may have been
5751 * passed to the function.
5752 */
5753 break;
5754 case BNX2X_RX_MODE_NORMAL:
924d75ab
YM
5755 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5756 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
5757 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5758
5759 /* internal switching mode */
924d75ab
YM
5760 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5761 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
5762 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5763
5764 break;
5765 case BNX2X_RX_MODE_ALLMULTI:
924d75ab
YM
5766 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5767 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5768 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5769
5770 /* internal switching mode */
924d75ab
YM
5771 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5772 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5773 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5774
5775 break;
5776 case BNX2X_RX_MODE_PROMISC:
5777 /* According to deffinition of SI mode, iface in promisc mode
5778 * should receive matched and unmatched (in resolution of port)
5779 * unicast packets.
5780 */
924d75ab
YM
5781 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
5782 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5783 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5784 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
619c5cb6
VZ
5785
5786 /* internal switching mode */
924d75ab
YM
5787 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5788 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
619c5cb6
VZ
5789
5790 if (IS_MF_SI(bp))
924d75ab 5791 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
619c5cb6 5792 else
924d75ab 5793 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
619c5cb6
VZ
5794
5795 break;
5796 default:
924d75ab
YM
5797 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
5798 return -EINVAL;
619c5cb6 5799 }
de832a55 5800
924d75ab 5801 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
619c5cb6 5802 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
924d75ab
YM
5803 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
5804 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
34f80b04
EG
5805 }
5806
924d75ab
YM
5807 return 0;
5808}
5809
5810/* called with netif_addr_lock_bh() */
5811int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5812{
5813 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5814 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5815 int rc;
5816
5817 if (!NO_FCOE(bp))
5818 /* Configure rx_mode of FCoE Queue */
5819 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5820
5821 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
5822 &tx_accept_flags);
5823 if (rc)
5824 return rc;
5825
619c5cb6
VZ
5826 __set_bit(RAMROD_RX, &ramrod_flags);
5827 __set_bit(RAMROD_TX, &ramrod_flags);
5828
924d75ab
YM
5829 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
5830 rx_accept_flags, tx_accept_flags,
5831 ramrod_flags);
619c5cb6
VZ
5832}
5833
5834static void bnx2x_init_internal_common(struct bnx2x *bp)
5835{
5836 int i;
5837
0793f83f
DK
5838 if (IS_MF_SI(bp))
5839 /*
5840 * In switch independent mode, the TSTORM needs to accept
5841 * packets that failed classification, since approximate match
5842 * mac addresses aren't written to NIG LLH
5843 */
5844 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5845 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
619c5cb6
VZ
5846 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5847 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5848 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
0793f83f 5849
523224a3
DK
5850 /* Zero this manually as its initialization is
5851 currently missing in the initTool */
5852 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
ca00392c 5853 REG_WR(bp, BAR_USTRORM_INTMEM +
523224a3 5854 USTORM_AGG_DATA_OFFSET + i * 4, 0);
619c5cb6 5855 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
5856 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5857 CHIP_INT_MODE_IS_BC(bp) ?
5858 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5859 }
523224a3 5860}
8a1c38d1 5861
471de716
EG
5862static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5863{
5864 switch (load_code) {
5865 case FW_MSG_CODE_DRV_LOAD_COMMON:
f2e0899f 5866 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
471de716
EG
5867 bnx2x_init_internal_common(bp);
5868 /* no break */
5869
5870 case FW_MSG_CODE_DRV_LOAD_PORT:
619c5cb6 5871 /* nothing to do */
471de716
EG
5872 /* no break */
5873
5874 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
523224a3
DK
5875 /* internal memory per function is
5876 initialized inside bnx2x_pf_init */
471de716
EG
5877 break;
5878
5879 default:
5880 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5881 break;
5882 }
5883}
5884
619c5cb6 5885static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
523224a3 5886{
55c11941 5887 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6 5888}
523224a3 5889
619c5cb6
VZ
5890static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5891{
55c11941 5892 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
619c5cb6
VZ
5893}
5894
1191cb83 5895static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
619c5cb6
VZ
5896{
5897 if (CHIP_IS_E1x(fp->bp))
5898 return BP_L_ID(fp->bp) + fp->index;
5899 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5900 return bnx2x_fp_igu_sb_id(fp);
5901}
5902
6383c0b3 5903static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
619c5cb6
VZ
5904{
5905 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6383c0b3 5906 u8 cos;
619c5cb6 5907 unsigned long q_type = 0;
6383c0b3 5908 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
f233cafe 5909 fp->rx_queue = fp_idx;
b3b83c3f 5910 fp->cid = fp_idx;
619c5cb6
VZ
5911 fp->cl_id = bnx2x_fp_cl_id(fp);
5912 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5913 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
523224a3 5914 /* qZone id equals to FW (per path) client id */
619c5cb6
VZ
5915 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5916
523224a3 5917 /* init shortcut */
619c5cb6 5918 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
7a752993 5919
523224a3
DK
5920 /* Setup SB indicies */
5921 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
523224a3 5922
619c5cb6
VZ
5923 /* Configure Queue State object */
5924 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5925 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6383c0b3
AE
5926
5927 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5928
5929 /* init tx data */
5930 for_each_cos_in_tx_queue(fp, cos) {
65565884
MS
5931 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5932 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5933 FP_COS_TO_TXQ(fp, cos, bp),
5934 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5935 cids[cos] = fp->txdata_ptr[cos]->cid;
6383c0b3
AE
5936 }
5937
ad5afc89
AE
5938 /* nothing more for vf to do here */
5939 if (IS_VF(bp))
5940 return;
5941
5942 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5943 fp->fw_sb_id, fp->igu_sb_id);
5944 bnx2x_update_fpsb_idx(fp);
15192a8c
BW
5945 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5946 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6383c0b3 5947 bnx2x_sp_mapping(bp, q_rdata), q_type);
619c5cb6
VZ
5948
5949 /**
5950 * Configure classification DBs: Always enable Tx switching
5951 */
5952 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5953
ad5afc89
AE
5954 DP(NETIF_MSG_IFUP,
5955 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5956 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5957 fp->igu_sb_id);
523224a3
DK
5958}
5959
1191cb83
ED
5960static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5961{
5962 int i;
5963
5964 for (i = 1; i <= NUM_TX_RINGS; i++) {
5965 struct eth_tx_next_bd *tx_next_bd =
5966 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5967
5968 tx_next_bd->addr_hi =
5969 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5970 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5971 tx_next_bd->addr_lo =
5972 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5973 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5974 }
5975
5976 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5977 txdata->tx_db.data.zero_fill1 = 0;
5978 txdata->tx_db.data.prod = 0;
5979
5980 txdata->tx_pkt_prod = 0;
5981 txdata->tx_pkt_cons = 0;
5982 txdata->tx_bd_prod = 0;
5983 txdata->tx_bd_cons = 0;
5984 txdata->tx_pkt = 0;
5985}
5986
55c11941
MS
5987static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
5988{
5989 int i;
5990
5991 for_each_tx_queue_cnic(bp, i)
5992 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
5993}
1191cb83
ED
5994static void bnx2x_init_tx_rings(struct bnx2x *bp)
5995{
5996 int i;
5997 u8 cos;
5998
55c11941 5999 for_each_eth_queue(bp, i)
1191cb83 6000 for_each_cos_in_tx_queue(&bp->fp[i], cos)
65565884 6001 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
1191cb83
ED
6002}
6003
55c11941 6004void bnx2x_nic_init_cnic(struct bnx2x *bp)
a2fbb9ea 6005{
ec6ba945
VZ
6006 if (!NO_FCOE(bp))
6007 bnx2x_init_fcoe_fp(bp);
523224a3
DK
6008
6009 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6010 BNX2X_VF_ID_INVALID, false,
619c5cb6 6011 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
523224a3 6012
55c11941
MS
6013 /* ensure status block indices were read */
6014 rmb();
6015 bnx2x_init_rx_rings_cnic(bp);
6016 bnx2x_init_tx_rings_cnic(bp);
6017
6018 /* flush all */
6019 mb();
6020 mmiowb();
6021}
a2fbb9ea 6022
55c11941
MS
6023void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
6024{
6025 int i;
6026
6027 for_each_eth_queue(bp, i)
6028 bnx2x_init_eth_fp(bp, i);
ad5afc89
AE
6029
6030 /* ensure status block indices were read */
6031 rmb();
6032 bnx2x_init_rx_rings(bp);
6033 bnx2x_init_tx_rings(bp);
6034
6035 if (IS_VF(bp))
6036 return;
6037
020c7e3f
YR
6038 /* Initialize MOD_ABS interrupts */
6039 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6040 bp->common.shmem_base, bp->common.shmem2_base,
6041 BP_PORT(bp));
16119785 6042
523224a3 6043 bnx2x_init_def_sb(bp);
5c862848 6044 bnx2x_update_dsb_idx(bp);
a2fbb9ea 6045 bnx2x_init_sp_ring(bp);
523224a3 6046 bnx2x_init_eq_ring(bp);
471de716 6047 bnx2x_init_internal(bp, load_code);
523224a3 6048 bnx2x_pf_init(bp);
0ef00459
EG
6049 bnx2x_stats_init(bp);
6050
0ef00459
EG
6051 /* flush all before enabling interrupts */
6052 mb();
6053 mmiowb();
6054
615f8fd9 6055 bnx2x_int_enable(bp);
eb8da205
EG
6056
6057 /* Check for SPIO5 */
6058 bnx2x_attn_int_deasserted0(bp,
6059 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6060 AEU_INPUTS_ATTN_BITS_SPIO5);
a2fbb9ea
ET
6061}
6062
6063/* end of nic init */
6064
6065/*
6066 * gzip service functions
6067 */
6068
6069static int bnx2x_gunzip_init(struct bnx2x *bp)
6070{
1a983142
FT
6071 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6072 &bp->gunzip_mapping, GFP_KERNEL);
a2fbb9ea
ET
6073 if (bp->gunzip_buf == NULL)
6074 goto gunzip_nomem1;
6075
6076 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6077 if (bp->strm == NULL)
6078 goto gunzip_nomem2;
6079
7ab24bfd 6080 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
a2fbb9ea
ET
6081 if (bp->strm->workspace == NULL)
6082 goto gunzip_nomem3;
6083
6084 return 0;
6085
6086gunzip_nomem3:
6087 kfree(bp->strm);
6088 bp->strm = NULL;
6089
6090gunzip_nomem2:
1a983142
FT
6091 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6092 bp->gunzip_mapping);
a2fbb9ea
ET
6093 bp->gunzip_buf = NULL;
6094
6095gunzip_nomem1:
51c1a580 6096 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
a2fbb9ea
ET
6097 return -ENOMEM;
6098}
6099
6100static void bnx2x_gunzip_end(struct bnx2x *bp)
6101{
b3b83c3f 6102 if (bp->strm) {
7ab24bfd 6103 vfree(bp->strm->workspace);
b3b83c3f
DK
6104 kfree(bp->strm);
6105 bp->strm = NULL;
6106 }
a2fbb9ea
ET
6107
6108 if (bp->gunzip_buf) {
1a983142
FT
6109 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6110 bp->gunzip_mapping);
a2fbb9ea
ET
6111 bp->gunzip_buf = NULL;
6112 }
6113}
6114
94a78b79 6115static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
a2fbb9ea
ET
6116{
6117 int n, rc;
6118
6119 /* check gzip header */
94a78b79
VZ
6120 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6121 BNX2X_ERR("Bad gzip header\n");
a2fbb9ea 6122 return -EINVAL;
94a78b79 6123 }
a2fbb9ea
ET
6124
6125 n = 10;
6126
34f80b04 6127#define FNAME 0x8
a2fbb9ea
ET
6128
6129 if (zbuf[3] & FNAME)
6130 while ((zbuf[n++] != 0) && (n < len));
6131
94a78b79 6132 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
a2fbb9ea
ET
6133 bp->strm->avail_in = len - n;
6134 bp->strm->next_out = bp->gunzip_buf;
6135 bp->strm->avail_out = FW_BUF_SIZE;
6136
6137 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6138 if (rc != Z_OK)
6139 return rc;
6140
6141 rc = zlib_inflate(bp->strm, Z_FINISH);
6142 if ((rc != Z_OK) && (rc != Z_STREAM_END))
7995c64e
JP
6143 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6144 bp->strm->msg);
a2fbb9ea
ET
6145
6146 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6147 if (bp->gunzip_outlen & 0x3)
51c1a580
MS
6148 netdev_err(bp->dev,
6149 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
cdaa7cb8 6150 bp->gunzip_outlen);
a2fbb9ea
ET
6151 bp->gunzip_outlen >>= 2;
6152
6153 zlib_inflateEnd(bp->strm);
6154
6155 if (rc == Z_STREAM_END)
6156 return 0;
6157
6158 return rc;
6159}
6160
6161/* nic load/unload */
6162
6163/*
34f80b04 6164 * General service functions
a2fbb9ea
ET
6165 */
6166
6167/* send a NIG loopback debug packet */
6168static void bnx2x_lb_pckt(struct bnx2x *bp)
6169{
a2fbb9ea 6170 u32 wb_write[3];
a2fbb9ea
ET
6171
6172 /* Ethernet source and destination addresses */
a2fbb9ea
ET
6173 wb_write[0] = 0x55555555;
6174 wb_write[1] = 0x55555555;
34f80b04 6175 wb_write[2] = 0x20; /* SOP */
a2fbb9ea 6176 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6177
6178 /* NON-IP protocol */
a2fbb9ea
ET
6179 wb_write[0] = 0x09000000;
6180 wb_write[1] = 0x55555555;
34f80b04 6181 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
a2fbb9ea 6182 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
a2fbb9ea
ET
6183}
6184
6185/* some of the internal memories
6186 * are not directly readable from the driver
6187 * to test them we send debug packets
6188 */
6189static int bnx2x_int_mem_test(struct bnx2x *bp)
6190{
6191 int factor;
6192 int count, i;
6193 u32 val = 0;
6194
ad8d3948 6195 if (CHIP_REV_IS_FPGA(bp))
a2fbb9ea 6196 factor = 120;
ad8d3948
EG
6197 else if (CHIP_REV_IS_EMUL(bp))
6198 factor = 200;
6199 else
a2fbb9ea 6200 factor = 1;
a2fbb9ea 6201
a2fbb9ea
ET
6202 /* Disable inputs of parser neighbor blocks */
6203 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6204 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6205 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6206 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6207
6208 /* Write 0 to parser credits for CFC search request */
6209 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6210
6211 /* send Ethernet packet */
6212 bnx2x_lb_pckt(bp);
6213
6214 /* TODO do i reset NIG statistic? */
6215 /* Wait until NIG register shows 1 packet of size 0x10 */
6216 count = 1000 * factor;
6217 while (count) {
34f80b04 6218
a2fbb9ea
ET
6219 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6220 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6221 if (val == 0x10)
6222 break;
6223
6224 msleep(10);
6225 count--;
6226 }
6227 if (val != 0x10) {
6228 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6229 return -1;
6230 }
6231
6232 /* Wait until PRS register shows 1 packet */
6233 count = 1000 * factor;
6234 while (count) {
6235 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
a2fbb9ea
ET
6236 if (val == 1)
6237 break;
6238
6239 msleep(10);
6240 count--;
6241 }
6242 if (val != 0x1) {
6243 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6244 return -2;
6245 }
6246
6247 /* Reset and init BRB, PRS */
34f80b04 6248 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
a2fbb9ea 6249 msleep(50);
34f80b04 6250 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
a2fbb9ea 6251 msleep(50);
619c5cb6
VZ
6252 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6253 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
a2fbb9ea
ET
6254
6255 DP(NETIF_MSG_HW, "part2\n");
6256
6257 /* Disable inputs of parser neighbor blocks */
6258 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6259 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6260 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
3196a88a 6261 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
a2fbb9ea
ET
6262
6263 /* Write 0 to parser credits for CFC search request */
6264 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6265
6266 /* send 10 Ethernet packets */
6267 for (i = 0; i < 10; i++)
6268 bnx2x_lb_pckt(bp);
6269
6270 /* Wait until NIG register shows 10 + 1
6271 packets of size 11*0x10 = 0xb0 */
6272 count = 1000 * factor;
6273 while (count) {
34f80b04 6274
a2fbb9ea
ET
6275 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6276 val = *bnx2x_sp(bp, wb_data[0]);
a2fbb9ea
ET
6277 if (val == 0xb0)
6278 break;
6279
6280 msleep(10);
6281 count--;
6282 }
6283 if (val != 0xb0) {
6284 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6285 return -3;
6286 }
6287
6288 /* Wait until PRS register shows 2 packets */
6289 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6290 if (val != 2)
6291 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6292
6293 /* Write 1 to parser credits for CFC search request */
6294 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6295
6296 /* Wait until PRS register shows 3 packets */
6297 msleep(10 * factor);
6298 /* Wait until NIG register shows 1 packet of size 0x10 */
6299 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6300 if (val != 3)
6301 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6302
6303 /* clear NIG EOP FIFO */
6304 for (i = 0; i < 11; i++)
6305 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6306 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6307 if (val != 1) {
6308 BNX2X_ERR("clear of NIG failed\n");
6309 return -4;
6310 }
6311
6312 /* Reset and init BRB, PRS, NIG */
6313 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6314 msleep(50);
6315 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6316 msleep(50);
619c5cb6
VZ
6317 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6318 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
55c11941
MS
6319 if (!CNIC_SUPPORT(bp))
6320 /* set NIC mode */
6321 REG_WR(bp, PRS_REG_NIC_MODE, 1);
a2fbb9ea
ET
6322
6323 /* Enable inputs of parser neighbor blocks */
6324 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6325 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6326 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
3196a88a 6327 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
a2fbb9ea
ET
6328
6329 DP(NETIF_MSG_HW, "done\n");
6330
6331 return 0; /* OK */
6332}
6333
4a33bc03 6334static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
a2fbb9ea 6335{
b343d002
YM
6336 u32 val;
6337
a2fbb9ea 6338 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
619c5cb6 6339 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
6340 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6341 else
6342 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
a2fbb9ea
ET
6343 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6344 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
f2e0899f
DK
6345 /*
6346 * mask read length error interrupts in brb for parser
6347 * (parsing unit and 'checksum and crc' unit)
6348 * these errors are legal (PU reads fixed length and CAC can cause
6349 * read length error on truncated packets)
6350 */
6351 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
a2fbb9ea
ET
6352 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6353 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6354 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6355 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6356 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
34f80b04
EG
6357/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6358/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6359 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6360 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6361 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
34f80b04
EG
6362/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6363/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
a2fbb9ea
ET
6364 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6365 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6366 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6367 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
34f80b04
EG
6368/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6369/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
f85582f8 6370
b343d002
YM
6371 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6372 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6373 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6374 if (!CHIP_IS_E1x(bp))
6375 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6376 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6377 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6378
a2fbb9ea
ET
6379 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6380 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6381 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
34f80b04 6382/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
619c5cb6
VZ
6383
6384 if (!CHIP_IS_E1x(bp))
6385 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6386 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6387
a2fbb9ea
ET
6388 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6389 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
34f80b04 6390/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
4a33bc03 6391 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
a2fbb9ea
ET
6392}
6393
81f75bbf
EG
6394static void bnx2x_reset_common(struct bnx2x *bp)
6395{
619c5cb6
VZ
6396 u32 val = 0x1400;
6397
81f75bbf
EG
6398 /* reset_common */
6399 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6400 0xd3ffff7f);
619c5cb6
VZ
6401
6402 if (CHIP_IS_E3(bp)) {
6403 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6404 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6405 }
6406
6407 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6408}
6409
6410static void bnx2x_setup_dmae(struct bnx2x *bp)
6411{
6412 bp->dmae_ready = 0;
6413 spin_lock_init(&bp->dmae_lock);
81f75bbf
EG
6414}
6415
573f2035
EG
6416static void bnx2x_init_pxp(struct bnx2x *bp)
6417{
6418 u16 devctl;
6419 int r_order, w_order;
6420
2a80eebc 6421 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
573f2035
EG
6422 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6423 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6424 if (bp->mrrs == -1)
6425 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6426 else {
6427 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6428 r_order = bp->mrrs;
6429 }
6430
6431 bnx2x_init_pxp_arb(bp, r_order, w_order);
6432}
fd4ef40d
EG
6433
6434static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6435{
2145a920 6436 int is_required;
fd4ef40d 6437 u32 val;
2145a920 6438 int port;
fd4ef40d 6439
2145a920
VZ
6440 if (BP_NOMCP(bp))
6441 return;
6442
6443 is_required = 0;
fd4ef40d
EG
6444 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6445 SHARED_HW_CFG_FAN_FAILURE_MASK;
6446
6447 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6448 is_required = 1;
6449
6450 /*
6451 * The fan failure mechanism is usually related to the PHY type since
6452 * the power consumption of the board is affected by the PHY. Currently,
6453 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6454 */
6455 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6456 for (port = PORT_0; port < PORT_MAX; port++) {
fd4ef40d 6457 is_required |=
d90d96ba
YR
6458 bnx2x_fan_failure_det_req(
6459 bp,
6460 bp->common.shmem_base,
a22f0788 6461 bp->common.shmem2_base,
d90d96ba 6462 port);
fd4ef40d
EG
6463 }
6464
6465 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6466
6467 if (is_required == 0)
6468 return;
6469
6470 /* Fan failure is indicated by SPIO 5 */
d6d99a3f 6471 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
fd4ef40d
EG
6472
6473 /* set to active low mode */
6474 val = REG_RD(bp, MISC_REG_SPIO_INT);
d6d99a3f 6475 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
fd4ef40d
EG
6476 REG_WR(bp, MISC_REG_SPIO_INT, val);
6477
6478 /* enable interrupt to signal the IGU */
6479 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 6480 val |= MISC_SPIO_SPIO5;
fd4ef40d
EG
6481 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6482}
6483
c9ee9206 6484void bnx2x_pf_disable(struct bnx2x *bp)
f2e0899f
DK
6485{
6486 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6487 val &= ~IGU_PF_CONF_FUNC_EN;
6488
6489 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6490 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6491 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6492}
6493
1191cb83 6494static void bnx2x__common_init_phy(struct bnx2x *bp)
619c5cb6
VZ
6495{
6496 u32 shmem_base[2], shmem2_base[2];
b884d95b
YR
6497 /* Avoid common init in case MFW supports LFA */
6498 if (SHMEM2_RD(bp, size) >
6499 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6500 return;
619c5cb6
VZ
6501 shmem_base[0] = bp->common.shmem_base;
6502 shmem2_base[0] = bp->common.shmem2_base;
6503 if (!CHIP_IS_E1x(bp)) {
6504 shmem_base[1] =
6505 SHMEM2_RD(bp, other_shmem_base_addr);
6506 shmem2_base[1] =
6507 SHMEM2_RD(bp, other_shmem2_base_addr);
6508 }
6509 bnx2x_acquire_phy_lock(bp);
6510 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6511 bp->common.chip_id);
6512 bnx2x_release_phy_lock(bp);
6513}
6514
6515/**
6516 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6517 *
6518 * @bp: driver handle
6519 */
6520static int bnx2x_init_hw_common(struct bnx2x *bp)
a2fbb9ea 6521{
619c5cb6 6522 u32 val;
a2fbb9ea 6523
51c1a580 6524 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
a2fbb9ea 6525
2031bd3a 6526 /*
2de67439 6527 * take the RESET lock to protect undi_unload flow from accessing
2031bd3a
DK
6528 * registers while we're resetting the chip
6529 */
7a06a122 6530 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6531
81f75bbf 6532 bnx2x_reset_common(bp);
34f80b04 6533 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
a2fbb9ea 6534
619c5cb6
VZ
6535 val = 0xfffc;
6536 if (CHIP_IS_E3(bp)) {
6537 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6538 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6539 }
6540 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6541
7a06a122 6542 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
2031bd3a 6543
619c5cb6 6544 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
a2fbb9ea 6545
619c5cb6
VZ
6546 if (!CHIP_IS_E1x(bp)) {
6547 u8 abs_func_id;
f2e0899f
DK
6548
6549 /**
6550 * 4-port mode or 2-port mode we need to turn of master-enable
6551 * for everyone, after that, turn it back on for self.
6552 * so, we disregard multi-function or not, and always disable
6553 * for all functions on the given path, this means 0,2,4,6 for
6554 * path 0 and 1,3,5,7 for path 1
6555 */
619c5cb6
VZ
6556 for (abs_func_id = BP_PATH(bp);
6557 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6558 if (abs_func_id == BP_ABS_FUNC(bp)) {
f2e0899f
DK
6559 REG_WR(bp,
6560 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6561 1);
6562 continue;
6563 }
6564
619c5cb6 6565 bnx2x_pretend_func(bp, abs_func_id);
f2e0899f
DK
6566 /* clear pf enable */
6567 bnx2x_pf_disable(bp);
6568 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6569 }
6570 }
a2fbb9ea 6571
619c5cb6 6572 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
34f80b04
EG
6573 if (CHIP_IS_E1(bp)) {
6574 /* enable HW interrupt from PXP on USDM overflow
6575 bit 16 on INT_MASK_0 */
6576 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6577 }
a2fbb9ea 6578
619c5cb6 6579 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
34f80b04 6580 bnx2x_init_pxp(bp);
a2fbb9ea
ET
6581
6582#ifdef __BIG_ENDIAN
34f80b04
EG
6583 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6584 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6585 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6586 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6587 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
8badd27a
EG
6588 /* make sure this value is 0 */
6589 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
34f80b04
EG
6590
6591/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6592 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6593 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6594 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6595 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
a2fbb9ea
ET
6596#endif
6597
523224a3
DK
6598 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6599
34f80b04
EG
6600 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6601 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
a2fbb9ea 6602
34f80b04
EG
6603 /* let the HW do it's magic ... */
6604 msleep(100);
6605 /* finish PXP init */
6606 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6607 if (val != 1) {
6608 BNX2X_ERR("PXP2 CFG failed\n");
6609 return -EBUSY;
6610 }
6611 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6612 if (val != 1) {
6613 BNX2X_ERR("PXP2 RD_INIT failed\n");
6614 return -EBUSY;
6615 }
a2fbb9ea 6616
f2e0899f
DK
6617 /* Timers bug workaround E2 only. We need to set the entire ILT to
6618 * have entries with value "0" and valid bit on.
6619 * This needs to be done by the first PF that is loaded in a path
6620 * (i.e. common phase)
6621 */
619c5cb6
VZ
6622 if (!CHIP_IS_E1x(bp)) {
6623/* In E2 there is a bug in the timers block that can cause function 6 / 7
6624 * (i.e. vnic3) to start even if it is marked as "scan-off".
6625 * This occurs when a different function (func2,3) is being marked
6626 * as "scan-off". Real-life scenario for example: if a driver is being
6627 * load-unloaded while func6,7 are down. This will cause the timer to access
6628 * the ilt, translate to a logical address and send a request to read/write.
6629 * Since the ilt for the function that is down is not valid, this will cause
6630 * a translation error which is unrecoverable.
6631 * The Workaround is intended to make sure that when this happens nothing fatal
6632 * will occur. The workaround:
6633 * 1. First PF driver which loads on a path will:
6634 * a. After taking the chip out of reset, by using pretend,
6635 * it will write "0" to the following registers of
6636 * the other vnics.
6637 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6638 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6639 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6640 * And for itself it will write '1' to
6641 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6642 * dmae-operations (writing to pram for example.)
6643 * note: can be done for only function 6,7 but cleaner this
6644 * way.
6645 * b. Write zero+valid to the entire ILT.
6646 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6647 * VNIC3 (of that port). The range allocated will be the
6648 * entire ILT. This is needed to prevent ILT range error.
6649 * 2. Any PF driver load flow:
6650 * a. ILT update with the physical addresses of the allocated
6651 * logical pages.
6652 * b. Wait 20msec. - note that this timeout is needed to make
6653 * sure there are no requests in one of the PXP internal
6654 * queues with "old" ILT addresses.
6655 * c. PF enable in the PGLC.
6656 * d. Clear the was_error of the PF in the PGLC. (could have
2de67439 6657 * occurred while driver was down)
619c5cb6
VZ
6658 * e. PF enable in the CFC (WEAK + STRONG)
6659 * f. Timers scan enable
6660 * 3. PF driver unload flow:
6661 * a. Clear the Timers scan_en.
6662 * b. Polling for scan_on=0 for that PF.
6663 * c. Clear the PF enable bit in the PXP.
6664 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6665 * e. Write zero+valid to all ILT entries (The valid bit must
6666 * stay set)
6667 * f. If this is VNIC 3 of a port then also init
6668 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6669 * to the last enrty in the ILT.
6670 *
6671 * Notes:
6672 * Currently the PF error in the PGLC is non recoverable.
6673 * In the future the there will be a recovery routine for this error.
6674 * Currently attention is masked.
6675 * Having an MCP lock on the load/unload process does not guarantee that
6676 * there is no Timer disable during Func6/7 enable. This is because the
6677 * Timers scan is currently being cleared by the MCP on FLR.
6678 * Step 2.d can be done only for PF6/7 and the driver can also check if
6679 * there is error before clearing it. But the flow above is simpler and
6680 * more general.
6681 * All ILT entries are written by zero+valid and not just PF6/7
6682 * ILT entries since in the future the ILT entries allocation for
6683 * PF-s might be dynamic.
6684 */
f2e0899f
DK
6685 struct ilt_client_info ilt_cli;
6686 struct bnx2x_ilt ilt;
6687 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6688 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6689
b595076a 6690 /* initialize dummy TM client */
f2e0899f
DK
6691 ilt_cli.start = 0;
6692 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6693 ilt_cli.client_num = ILT_CLIENT_TM;
6694
6695 /* Step 1: set zeroes to all ilt page entries with valid bit on
6696 * Step 2: set the timers first/last ilt entry to point
6697 * to the entire range to prevent ILT range error for 3rd/4th
2de67439 6698 * vnic (this code assumes existence of the vnic)
f2e0899f
DK
6699 *
6700 * both steps performed by call to bnx2x_ilt_client_init_op()
6701 * with dummy TM client
6702 *
6703 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6704 * and his brother are split registers
6705 */
6706 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6707 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6708 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6709
6710 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6711 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6712 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6713 }
6714
34f80b04
EG
6715 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6716 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
a2fbb9ea 6717
619c5cb6 6718 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6719 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6720 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
619c5cb6 6721 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
f2e0899f 6722
619c5cb6 6723 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
f2e0899f
DK
6724
6725 /* let the HW do it's magic ... */
6726 do {
6727 msleep(200);
6728 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6729 } while (factor-- && (val != 1));
6730
6731 if (val != 1) {
6732 BNX2X_ERR("ATC_INIT failed\n");
6733 return -EBUSY;
6734 }
6735 }
6736
619c5cb6 6737 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
a2fbb9ea 6738
b56e9670
AE
6739 bnx2x_iov_init_dmae(bp);
6740
34f80b04
EG
6741 /* clean the DMAE memory */
6742 bp->dmae_ready = 1;
619c5cb6
VZ
6743 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6744
6745 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6746
6747 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6748
6749 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
a2fbb9ea 6750
619c5cb6 6751 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
a2fbb9ea 6752
34f80b04
EG
6753 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6754 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6755 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6756 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6757
619c5cb6 6758 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
37b091ba 6759
f85582f8 6760
523224a3
DK
6761 /* QM queues pointers table */
6762 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6763
34f80b04
EG
6764 /* soft reset pulse */
6765 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6766 REG_WR(bp, QM_REG_SOFT_RESET, 0);
a2fbb9ea 6767
55c11941
MS
6768 if (CNIC_SUPPORT(bp))
6769 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
a2fbb9ea 6770
619c5cb6 6771 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
523224a3 6772 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
619c5cb6 6773 if (!CHIP_REV_IS_SLOW(bp))
34f80b04
EG
6774 /* enable hw interrupt from doorbell Q */
6775 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
a2fbb9ea 6776
619c5cb6 6777 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
f2e0899f 6778
619c5cb6 6779 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
26c8fa4d 6780 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
619c5cb6 6781
f2e0899f 6782 if (!CHIP_IS_E1(bp))
619c5cb6 6783 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
f85582f8 6784
a3348722
BW
6785 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6786 if (IS_MF_AFEX(bp)) {
6787 /* configure that VNTag and VLAN headers must be
6788 * received in afex mode
6789 */
6790 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6791 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6792 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6793 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6794 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6795 } else {
6796 /* Bit-map indicating which L2 hdrs may appear
6797 * after the basic Ethernet header
6798 */
6799 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6800 bp->path_has_ovlan ? 7 : 6);
6801 }
6802 }
a2fbb9ea 6803
619c5cb6
VZ
6804 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6805 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6806 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6807 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
a2fbb9ea 6808
619c5cb6
VZ
6809 if (!CHIP_IS_E1x(bp)) {
6810 /* reset VFC memories */
6811 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6812 VFC_MEMORIES_RST_REG_CAM_RST |
6813 VFC_MEMORIES_RST_REG_RAM_RST);
6814 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6815 VFC_MEMORIES_RST_REG_CAM_RST |
6816 VFC_MEMORIES_RST_REG_RAM_RST);
a2fbb9ea 6817
619c5cb6
VZ
6818 msleep(20);
6819 }
a2fbb9ea 6820
619c5cb6
VZ
6821 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6822 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6823 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6824 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
f2e0899f 6825
34f80b04
EG
6826 /* sync semi rtc */
6827 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6828 0x80000000);
6829 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6830 0x80000000);
a2fbb9ea 6831
619c5cb6
VZ
6832 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6833 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6834 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
a2fbb9ea 6835
a3348722
BW
6836 if (!CHIP_IS_E1x(bp)) {
6837 if (IS_MF_AFEX(bp)) {
6838 /* configure that VNTag and VLAN headers must be
6839 * sent in afex mode
6840 */
6841 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6842 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6843 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6844 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6845 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6846 } else {
6847 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6848 bp->path_has_ovlan ? 7 : 6);
6849 }
6850 }
f2e0899f 6851
34f80b04 6852 REG_WR(bp, SRC_REG_SOFT_RST, 1);
f85582f8 6853
619c5cb6
VZ
6854 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6855
55c11941
MS
6856 if (CNIC_SUPPORT(bp)) {
6857 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6858 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6859 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6860 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6861 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6862 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6863 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6864 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6865 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6866 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6867 }
34f80b04 6868 REG_WR(bp, SRC_REG_SOFT_RST, 0);
a2fbb9ea 6869
34f80b04
EG
6870 if (sizeof(union cdu_context) != 1024)
6871 /* we currently assume that a context is 1024 bytes */
51c1a580
MS
6872 dev_alert(&bp->pdev->dev,
6873 "please adjust the size of cdu_context(%ld)\n",
6874 (long)sizeof(union cdu_context));
a2fbb9ea 6875
619c5cb6 6876 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
34f80b04
EG
6877 val = (4 << 24) + (0 << 12) + 1024;
6878 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
a2fbb9ea 6879
619c5cb6 6880 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
34f80b04 6881 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
8d9c5f34
EG
6882 /* enable context validation interrupt from CFC */
6883 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6884
6885 /* set the thresholds to prevent CFC/CDU race */
6886 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
a2fbb9ea 6887
619c5cb6 6888 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
f2e0899f 6889
619c5cb6 6890 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
f2e0899f
DK
6891 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6892
619c5cb6
VZ
6893 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6894 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
a2fbb9ea 6895
34f80b04
EG
6896 /* Reset PCIE errors for debug */
6897 REG_WR(bp, 0x2814, 0xffffffff);
6898 REG_WR(bp, 0x3820, 0xffffffff);
a2fbb9ea 6899
619c5cb6 6900 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
6901 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6902 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6903 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6904 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6905 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6906 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6907 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6908 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6909 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6910 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6911 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6912 }
6913
619c5cb6 6914 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
f2e0899f 6915 if (!CHIP_IS_E1(bp)) {
619c5cb6
VZ
6916 /* in E3 this done in per-port section */
6917 if (!CHIP_IS_E3(bp))
6918 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
f2e0899f 6919 }
619c5cb6
VZ
6920 if (CHIP_IS_E1H(bp))
6921 /* not applicable for E2 (and above ...) */
6922 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
34f80b04
EG
6923
6924 if (CHIP_REV_IS_SLOW(bp))
6925 msleep(200);
6926
6927 /* finish CFC init */
6928 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6929 if (val != 1) {
6930 BNX2X_ERR("CFC LL_INIT failed\n");
6931 return -EBUSY;
6932 }
6933 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6934 if (val != 1) {
6935 BNX2X_ERR("CFC AC_INIT failed\n");
6936 return -EBUSY;
6937 }
6938 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6939 if (val != 1) {
6940 BNX2X_ERR("CFC CAM_INIT failed\n");
6941 return -EBUSY;
6942 }
6943 REG_WR(bp, CFC_REG_DEBUG0, 0);
f1410647 6944
f2e0899f
DK
6945 if (CHIP_IS_E1(bp)) {
6946 /* read NIG statistic
6947 to see if this is our first up since powerup */
6948 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6949 val = *bnx2x_sp(bp, wb_data[0]);
34f80b04 6950
f2e0899f
DK
6951 /* do internal memory self test */
6952 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6953 BNX2X_ERR("internal mem self test failed\n");
6954 return -EBUSY;
6955 }
34f80b04
EG
6956 }
6957
fd4ef40d
EG
6958 bnx2x_setup_fan_failure_detection(bp);
6959
34f80b04
EG
6960 /* clear PXP2 attentions */
6961 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
a2fbb9ea 6962
4a33bc03 6963 bnx2x_enable_blocks_attention(bp);
c9ee9206 6964 bnx2x_enable_blocks_parity(bp);
a2fbb9ea 6965
6bbca910 6966 if (!BP_NOMCP(bp)) {
619c5cb6
VZ
6967 if (CHIP_IS_E1x(bp))
6968 bnx2x__common_init_phy(bp);
6bbca910
YR
6969 } else
6970 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6971
34f80b04
EG
6972 return 0;
6973}
a2fbb9ea 6974
619c5cb6
VZ
6975/**
6976 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6977 *
6978 * @bp: driver handle
6979 */
6980static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6981{
6982 int rc = bnx2x_init_hw_common(bp);
6983
6984 if (rc)
6985 return rc;
6986
6987 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6988 if (!BP_NOMCP(bp))
6989 bnx2x__common_init_phy(bp);
6990
6991 return 0;
6992}
6993
523224a3 6994static int bnx2x_init_hw_port(struct bnx2x *bp)
34f80b04
EG
6995{
6996 int port = BP_PORT(bp);
619c5cb6 6997 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
1c06328c 6998 u32 low, high;
34f80b04 6999 u32 val;
a2fbb9ea 7000
619c5cb6 7001
51c1a580 7002 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
34f80b04
EG
7003
7004 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
a2fbb9ea 7005
619c5cb6
VZ
7006 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7007 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7008 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
ca00392c 7009
f2e0899f
DK
7010 /* Timers bug workaround: disables the pf_master bit in pglue at
7011 * common phase, we need to enable it here before any dmae access are
7012 * attempted. Therefore we manually added the enable-master to the
7013 * port phase (it also happens in the function phase)
7014 */
619c5cb6 7015 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7016 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7017
619c5cb6
VZ
7018 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7019 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7020 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7021 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7022
7023 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7024 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7025 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7026 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
a2fbb9ea 7027
523224a3
DK
7028 /* QM cid (connection) count */
7029 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
a2fbb9ea 7030
55c11941
MS
7031 if (CNIC_SUPPORT(bp)) {
7032 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7033 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7034 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7035 }
cdaa7cb8 7036
619c5cb6 7037 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
f2e0899f 7038
2b674047
DK
7039 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7040
f2e0899f 7041 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
619c5cb6
VZ
7042
7043 if (IS_MF(bp))
7044 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7045 else if (bp->dev->mtu > 4096) {
7046 if (bp->flags & ONE_PORT_FLAG)
7047 low = 160;
7048 else {
7049 val = bp->dev->mtu;
7050 /* (24*1024 + val*4)/256 */
7051 low = 96 + (val/64) +
7052 ((val % 64) ? 1 : 0);
7053 }
7054 } else
7055 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7056 high = low + 56; /* 14*1024/256 */
f2e0899f
DK
7057 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7058 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
1c06328c 7059 }
1c06328c 7060
619c5cb6
VZ
7061 if (CHIP_MODE_IS_4_PORT(bp))
7062 REG_WR(bp, (BP_PORT(bp) ?
7063 BRB1_REG_MAC_GUARANTIED_1 :
7064 BRB1_REG_MAC_GUARANTIED_0), 40);
1c06328c 7065
ca00392c 7066
619c5cb6 7067 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
a3348722
BW
7068 if (CHIP_IS_E3B0(bp)) {
7069 if (IS_MF_AFEX(bp)) {
7070 /* configure headers for AFEX mode */
7071 REG_WR(bp, BP_PORT(bp) ?
7072 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7073 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7074 REG_WR(bp, BP_PORT(bp) ?
7075 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7076 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7077 REG_WR(bp, BP_PORT(bp) ?
7078 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7079 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7080 } else {
7081 /* Ovlan exists only if we are in multi-function +
7082 * switch-dependent mode, in switch-independent there
7083 * is no ovlan headers
7084 */
7085 REG_WR(bp, BP_PORT(bp) ?
7086 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7087 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7088 (bp->path_has_ovlan ? 7 : 6));
7089 }
7090 }
356e2385 7091
619c5cb6
VZ
7092 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7093 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7094 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7095 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
356e2385 7096
619c5cb6
VZ
7097 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7098 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7099 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7100 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
34f80b04 7101
619c5cb6
VZ
7102 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7103 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
a2fbb9ea 7104
619c5cb6
VZ
7105 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7106
7107 if (CHIP_IS_E1x(bp)) {
f2e0899f
DK
7108 /* configure PBF to work without PAUSE mtu 9000 */
7109 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
a2fbb9ea 7110
f2e0899f
DK
7111 /* update threshold */
7112 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7113 /* update init credit */
7114 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
a2fbb9ea 7115
f2e0899f
DK
7116 /* probe changes */
7117 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7118 udelay(50);
7119 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7120 }
a2fbb9ea 7121
55c11941
MS
7122 if (CNIC_SUPPORT(bp))
7123 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7124
619c5cb6
VZ
7125 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7126 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04
EG
7127
7128 if (CHIP_IS_E1(bp)) {
7129 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7130 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7131 }
619c5cb6 7132 bnx2x_init_block(bp, BLOCK_HC, init_phase);
34f80b04 7133
619c5cb6 7134 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7135
619c5cb6 7136 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
34f80b04
EG
7137 /* init aeu_mask_attn_func_0/1:
7138 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
7139 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
7140 * bits 4-7 are used for "per vn group attention" */
e4901dde
VZ
7141 val = IS_MF(bp) ? 0xF7 : 0x7;
7142 /* Enable DCBX attention for all but E1 */
7143 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7144 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
34f80b04 7145
619c5cb6
VZ
7146 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7147
7148 if (!CHIP_IS_E1x(bp)) {
7149 /* Bit-map indicating which L2 hdrs may appear after the
7150 * basic Ethernet header
7151 */
a3348722
BW
7152 if (IS_MF_AFEX(bp))
7153 REG_WR(bp, BP_PORT(bp) ?
7154 NIG_REG_P1_HDRS_AFTER_BASIC :
7155 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7156 else
7157 REG_WR(bp, BP_PORT(bp) ?
7158 NIG_REG_P1_HDRS_AFTER_BASIC :
7159 NIG_REG_P0_HDRS_AFTER_BASIC,
7160 IS_MF_SD(bp) ? 7 : 6);
619c5cb6
VZ
7161
7162 if (CHIP_IS_E3(bp))
7163 REG_WR(bp, BP_PORT(bp) ?
7164 NIG_REG_LLH1_MF_MODE :
7165 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7166 }
7167 if (!CHIP_IS_E3(bp))
7168 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
34f80b04 7169
f2e0899f 7170 if (!CHIP_IS_E1(bp)) {
fb3bff17 7171 /* 0x2 disable mf_ov, 0x1 enable */
34f80b04 7172 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
0793f83f 7173 (IS_MF_SD(bp) ? 0x1 : 0x2));
34f80b04 7174
619c5cb6 7175 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7176 val = 0;
7177 switch (bp->mf_mode) {
7178 case MULTI_FUNCTION_SD:
7179 val = 1;
7180 break;
7181 case MULTI_FUNCTION_SI:
a3348722 7182 case MULTI_FUNCTION_AFEX:
f2e0899f
DK
7183 val = 2;
7184 break;
7185 }
7186
7187 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7188 NIG_REG_LLH0_CLS_TYPE), val);
7189 }
1c06328c
EG
7190 {
7191 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7192 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7193 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7194 }
34f80b04
EG
7195 }
7196
619c5cb6
VZ
7197 /* If SPIO5 is set to generate interrupts, enable it for this port */
7198 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
d6d99a3f 7199 if (val & MISC_SPIO_SPIO5) {
4d295db0
EG
7200 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7201 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7202 val = REG_RD(bp, reg_addr);
f1410647 7203 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
4d295db0 7204 REG_WR(bp, reg_addr, val);
f1410647 7205 }
a2fbb9ea 7206
34f80b04
EG
7207 return 0;
7208}
7209
34f80b04
EG
7210static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7211{
7212 int reg;
32d68de1 7213 u32 wb_write[2];
34f80b04 7214
f2e0899f 7215 if (CHIP_IS_E1(bp))
34f80b04 7216 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
f2e0899f
DK
7217 else
7218 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
34f80b04 7219
32d68de1
YM
7220 wb_write[0] = ONCHIP_ADDR1(addr);
7221 wb_write[1] = ONCHIP_ADDR2(addr);
7222 REG_WR_DMAE(bp, reg, wb_write, 2);
34f80b04
EG
7223}
7224
b56e9670 7225void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
1191cb83
ED
7226{
7227 u32 data, ctl, cnt = 100;
7228 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7229 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7230 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7231 u32 sb_bit = 1 << (idu_sb_id%32);
b56e9670 7232 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
1191cb83
ED
7233 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7234
7235 /* Not supported in BC mode */
7236 if (CHIP_INT_MODE_IS_BC(bp))
7237 return;
7238
7239 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7240 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7241 IGU_REGULAR_CLEANUP_SET |
7242 IGU_REGULAR_BCLEANUP;
7243
7244 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7245 func_encode << IGU_CTRL_REG_FID_SHIFT |
7246 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7247
7248 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7249 data, igu_addr_data);
7250 REG_WR(bp, igu_addr_data, data);
7251 mmiowb();
7252 barrier();
7253 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7254 ctl, igu_addr_ctl);
7255 REG_WR(bp, igu_addr_ctl, ctl);
7256 mmiowb();
7257 barrier();
7258
7259 /* wait for clean up to finish */
7260 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7261 msleep(20);
7262
7263
7264 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7265 DP(NETIF_MSG_HW,
7266 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7267 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7268 }
7269}
7270
7271static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
f2e0899f 7272{
619c5cb6 7273 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
f2e0899f
DK
7274}
7275
1191cb83 7276static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
f2e0899f
DK
7277{
7278 u32 i, base = FUNC_ILT_BASE(func);
7279 for (i = base; i < base + ILT_PER_FUNC; i++)
7280 bnx2x_ilt_wr(bp, i, 0);
7281}
7282
55c11941 7283
910cc727 7284static void bnx2x_init_searcher(struct bnx2x *bp)
55c11941
MS
7285{
7286 int port = BP_PORT(bp);
7287 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7288 /* T1 hash bits value determines the T1 number of entries */
7289 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7290}
7291
7292static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7293{
7294 int rc;
7295 struct bnx2x_func_state_params func_params = {NULL};
7296 struct bnx2x_func_switch_update_params *switch_update_params =
7297 &func_params.params.switch_update;
7298
7299 /* Prepare parameters for function state transitions */
7300 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7301 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7302
7303 func_params.f_obj = &bp->func_obj;
7304 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7305
7306 /* Function parameters */
7307 switch_update_params->suspend = suspend;
7308
7309 rc = bnx2x_func_state_change(bp, &func_params);
7310
7311 return rc;
7312}
7313
910cc727 7314static int bnx2x_reset_nic_mode(struct bnx2x *bp)
55c11941
MS
7315{
7316 int rc, i, port = BP_PORT(bp);
7317 int vlan_en = 0, mac_en[NUM_MACS];
7318
7319
7320 /* Close input from network */
7321 if (bp->mf_mode == SINGLE_FUNCTION) {
7322 bnx2x_set_rx_filter(&bp->link_params, 0);
7323 } else {
7324 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7325 NIG_REG_LLH0_FUNC_EN);
7326 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7327 NIG_REG_LLH0_FUNC_EN, 0);
7328 for (i = 0; i < NUM_MACS; i++) {
7329 mac_en[i] = REG_RD(bp, port ?
7330 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7331 4 * i) :
7332 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7333 4 * i));
7334 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7335 4 * i) :
7336 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7337 }
7338 }
7339
7340 /* Close BMC to host */
7341 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7342 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7343
7344 /* Suspend Tx switching to the PF. Completion of this ramrod
7345 * further guarantees that all the packets of that PF / child
7346 * VFs in BRB were processed by the Parser, so it is safe to
7347 * change the NIC_MODE register.
7348 */
7349 rc = bnx2x_func_switch_update(bp, 1);
7350 if (rc) {
7351 BNX2X_ERR("Can't suspend tx-switching!\n");
7352 return rc;
7353 }
7354
7355 /* Change NIC_MODE register */
7356 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7357
7358 /* Open input from network */
7359 if (bp->mf_mode == SINGLE_FUNCTION) {
7360 bnx2x_set_rx_filter(&bp->link_params, 1);
7361 } else {
7362 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7363 NIG_REG_LLH0_FUNC_EN, vlan_en);
7364 for (i = 0; i < NUM_MACS; i++) {
7365 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7366 4 * i) :
7367 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7368 mac_en[i]);
7369 }
7370 }
7371
7372 /* Enable BMC to host */
7373 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7374 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7375
7376 /* Resume Tx switching to the PF */
7377 rc = bnx2x_func_switch_update(bp, 0);
7378 if (rc) {
7379 BNX2X_ERR("Can't resume tx-switching!\n");
7380 return rc;
7381 }
7382
7383 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7384 return 0;
7385}
7386
7387int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7388{
7389 int rc;
7390
7391 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7392
7393 if (CONFIGURE_NIC_MODE(bp)) {
7394 /* Configrue searcher as part of function hw init */
7395 bnx2x_init_searcher(bp);
7396
7397 /* Reset NIC mode */
7398 rc = bnx2x_reset_nic_mode(bp);
7399 if (rc)
7400 BNX2X_ERR("Can't change NIC mode!\n");
7401 return rc;
7402 }
7403
7404 return 0;
7405}
7406
523224a3 7407static int bnx2x_init_hw_func(struct bnx2x *bp)
34f80b04
EG
7408{
7409 int port = BP_PORT(bp);
7410 int func = BP_FUNC(bp);
619c5cb6 7411 int init_phase = PHASE_PF0 + func;
523224a3
DK
7412 struct bnx2x_ilt *ilt = BP_ILT(bp);
7413 u16 cdu_ilt_start;
8badd27a 7414 u32 addr, val;
f4a66897 7415 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
89db4ad8 7416 int i, main_mem_width, rc;
34f80b04 7417
51c1a580 7418 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
34f80b04 7419
619c5cb6 7420 /* FLR cleanup - hmmm */
89db4ad8
AE
7421 if (!CHIP_IS_E1x(bp)) {
7422 rc = bnx2x_pf_flr_clnup(bp);
04c46736
YM
7423 if (rc) {
7424 bnx2x_fw_dump(bp);
89db4ad8 7425 return rc;
04c46736 7426 }
89db4ad8 7427 }
619c5cb6 7428
8badd27a 7429 /* set MSI reconfigure capability */
f2e0899f
DK
7430 if (bp->common.int_block == INT_BLOCK_HC) {
7431 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7432 val = REG_RD(bp, addr);
7433 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7434 REG_WR(bp, addr, val);
7435 }
8badd27a 7436
619c5cb6
VZ
7437 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7438 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7439
523224a3
DK
7440 ilt = BP_ILT(bp);
7441 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
37b091ba 7442
290ca2bb
AE
7443 if (IS_SRIOV(bp))
7444 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7445 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7446
7447 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7448 * those of the VFs, so start line should be reset
7449 */
7450 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
523224a3 7451 for (i = 0; i < L2_ILT_LINES(bp); i++) {
a052997e 7452 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
523224a3 7453 ilt->lines[cdu_ilt_start + i].page_mapping =
a052997e
MS
7454 bp->context[i].cxt_mapping;
7455 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
37b091ba 7456 }
290ca2bb 7457
523224a3 7458 bnx2x_ilt_init_op(bp, INITOP_SET);
f85582f8 7459
55c11941
MS
7460 if (!CONFIGURE_NIC_MODE(bp)) {
7461 bnx2x_init_searcher(bp);
7462 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7463 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7464 } else {
7465 /* Set NIC mode */
7466 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7467 DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
37b091ba 7468
55c11941 7469 }
37b091ba 7470
619c5cb6 7471 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7472 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7473
7474 /* Turn on a single ISR mode in IGU if driver is going to use
7475 * INT#x or MSI
7476 */
7477 if (!(bp->flags & USING_MSIX_FLAG))
7478 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7479 /*
7480 * Timers workaround bug: function init part.
7481 * Need to wait 20msec after initializing ILT,
7482 * needed to make sure there are no requests in
7483 * one of the PXP internal queues with "old" ILT addresses
7484 */
7485 msleep(20);
7486 /*
7487 * Master enable - Due to WB DMAE writes performed before this
7488 * register is re-initialized as part of the regular function
7489 * init
7490 */
7491 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7492 /* Enable the function in IGU */
7493 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7494 }
7495
523224a3 7496 bp->dmae_ready = 1;
34f80b04 7497
619c5cb6 7498 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
523224a3 7499
619c5cb6 7500 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7501 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7502
619c5cb6
VZ
7503 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7504 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7505 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7506 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7507 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7508 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7509 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7510 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7511 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7512 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7513 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7514 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7515 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7516
7517 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7518 REG_WR(bp, QM_REG_PF_EN, 1);
7519
619c5cb6
VZ
7520 if (!CHIP_IS_E1x(bp)) {
7521 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7522 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7523 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7524 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7525 }
7526 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7527
7528 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7529 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
b56e9670
AE
7530
7531 bnx2x_iov_init_dq(bp);
7532
619c5cb6
VZ
7533 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7534 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7535 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7536 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7537 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7538 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7539 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7540 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7541 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7542 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7543 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7544
619c5cb6 7545 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
523224a3 7546
619c5cb6 7547 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
34f80b04 7548
619c5cb6 7549 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
7550 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7551
fb3bff17 7552 if (IS_MF(bp)) {
34f80b04 7553 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
fb3bff17 7554 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
34f80b04
EG
7555 }
7556
619c5cb6 7557 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
523224a3 7558
34f80b04 7559 /* HC init per function */
f2e0899f
DK
7560 if (bp->common.int_block == INT_BLOCK_HC) {
7561 if (CHIP_IS_E1H(bp)) {
7562 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7563
7564 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7565 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7566 }
619c5cb6 7567 bnx2x_init_block(bp, BLOCK_HC, init_phase);
f2e0899f
DK
7568
7569 } else {
7570 int num_segs, sb_idx, prod_offset;
7571
34f80b04
EG
7572 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7573
619c5cb6 7574 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7575 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7576 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7577 }
7578
619c5cb6 7579 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
f2e0899f 7580
619c5cb6 7581 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
7582 int dsb_idx = 0;
7583 /**
7584 * Producer memory:
7585 * E2 mode: address 0-135 match to the mapping memory;
7586 * 136 - PF0 default prod; 137 - PF1 default prod;
7587 * 138 - PF2 default prod; 139 - PF3 default prod;
7588 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7589 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7590 * 144-147 reserved.
7591 *
7592 * E1.5 mode - In backward compatible mode;
7593 * for non default SB; each even line in the memory
7594 * holds the U producer and each odd line hold
7595 * the C producer. The first 128 producers are for
7596 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7597 * producers are for the DSB for each PF.
7598 * Each PF has five segments: (the order inside each
7599 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7600 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7601 * 144-147 attn prods;
7602 */
7603 /* non-default-status-blocks */
7604 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7605 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7606 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7607 prod_offset = (bp->igu_base_sb + sb_idx) *
7608 num_segs;
7609
7610 for (i = 0; i < num_segs; i++) {
7611 addr = IGU_REG_PROD_CONS_MEMORY +
7612 (prod_offset + i) * 4;
7613 REG_WR(bp, addr, 0);
7614 }
7615 /* send consumer update with value 0 */
7616 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7617 USTORM_ID, 0, IGU_INT_NOP, 1);
7618 bnx2x_igu_clear_sb(bp,
7619 bp->igu_base_sb + sb_idx);
7620 }
7621
7622 /* default-status-blocks */
7623 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7624 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7625
7626 if (CHIP_MODE_IS_4_PORT(bp))
7627 dsb_idx = BP_FUNC(bp);
7628 else
3395a033 7629 dsb_idx = BP_VN(bp);
f2e0899f
DK
7630
7631 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7632 IGU_BC_BASE_DSB_PROD + dsb_idx :
7633 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7634
3395a033
DK
7635 /*
7636 * igu prods come in chunks of E1HVN_MAX (4) -
7637 * does not matters what is the current chip mode
7638 */
f2e0899f
DK
7639 for (i = 0; i < (num_segs * E1HVN_MAX);
7640 i += E1HVN_MAX) {
7641 addr = IGU_REG_PROD_CONS_MEMORY +
7642 (prod_offset + i)*4;
7643 REG_WR(bp, addr, 0);
7644 }
7645 /* send consumer update with 0 */
7646 if (CHIP_INT_MODE_IS_BC(bp)) {
7647 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7648 USTORM_ID, 0, IGU_INT_NOP, 1);
7649 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7650 CSTORM_ID, 0, IGU_INT_NOP, 1);
7651 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7652 XSTORM_ID, 0, IGU_INT_NOP, 1);
7653 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7654 TSTORM_ID, 0, IGU_INT_NOP, 1);
7655 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7656 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7657 } else {
7658 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7659 USTORM_ID, 0, IGU_INT_NOP, 1);
7660 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7661 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7662 }
7663 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7664
7665 /* !!! these should become driver const once
7666 rf-tool supports split-68 const */
7667 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7668 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7669 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7670 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7671 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7672 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7673 }
34f80b04 7674 }
34f80b04 7675
c14423fe 7676 /* Reset PCIE errors for debug */
a2fbb9ea
ET
7677 REG_WR(bp, 0x2114, 0xffffffff);
7678 REG_WR(bp, 0x2120, 0xffffffff);
523224a3 7679
f4a66897
VZ
7680 if (CHIP_IS_E1x(bp)) {
7681 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7682 main_mem_base = HC_REG_MAIN_MEMORY +
7683 BP_PORT(bp) * (main_mem_size * 4);
7684 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7685 main_mem_width = 8;
7686
7687 val = REG_RD(bp, main_mem_prty_clr);
7688 if (val)
51c1a580
MS
7689 DP(NETIF_MSG_HW,
7690 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7691 val);
f4a66897
VZ
7692
7693 /* Clear "false" parity errors in MSI-X table */
7694 for (i = main_mem_base;
7695 i < main_mem_base + main_mem_size * 4;
7696 i += main_mem_width) {
7697 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7698 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7699 i, main_mem_width / 4);
7700 }
7701 /* Clear HC parity attention */
7702 REG_RD(bp, main_mem_prty_clr);
7703 }
7704
619c5cb6
VZ
7705#ifdef BNX2X_STOP_ON_ERROR
7706 /* Enable STORMs SP logging */
7707 REG_WR8(bp, BAR_USTRORM_INTMEM +
7708 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7709 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7710 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7711 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7712 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7713 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7714 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7715#endif
7716
b7737c9b 7717 bnx2x_phy_probe(&bp->link_params);
f85582f8 7718
34f80b04
EG
7719 return 0;
7720}
7721
a2fbb9ea 7722
55c11941
MS
7723void bnx2x_free_mem_cnic(struct bnx2x *bp)
7724{
7725 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7726
7727 if (!CHIP_IS_E1x(bp))
7728 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7729 sizeof(struct host_hc_status_block_e2));
7730 else
7731 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7732 sizeof(struct host_hc_status_block_e1x));
7733
7734 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7735}
7736
9f6c9258 7737void bnx2x_free_mem(struct bnx2x *bp)
a2fbb9ea 7738{
a052997e
MS
7739 int i;
7740
a2fbb9ea 7741 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7742 sizeof(struct host_sp_status_block));
a2fbb9ea 7743
619c5cb6
VZ
7744 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7745 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7746
a2fbb9ea 7747 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7748 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7749
a052997e
MS
7750 for (i = 0; i < L2_ILT_LINES(bp); i++)
7751 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7752 bp->context[i].size);
523224a3
DK
7753 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7754
7755 BNX2X_FREE(bp->ilt->lines);
f85582f8 7756
7a9b2557 7757 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7758
523224a3
DK
7759 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7760 BCM_PAGE_SIZE * NUM_EQ_PAGES);
580d9d08
YM
7761
7762 bnx2x_iov_free_mem(bp);
619c5cb6
VZ
7763}
7764
a2fbb9ea 7765
55c11941 7766int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7767{
619c5cb6
VZ
7768 if (!CHIP_IS_E1x(bp))
7769 /* size = the status block + ramrod buffers */
f2e0899f
DK
7770 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7771 sizeof(struct host_hc_status_block_e2));
7772 else
55c11941
MS
7773 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7774 &bp->cnic_sb_mapping,
7775 sizeof(struct
7776 host_hc_status_block_e1x));
8badd27a 7777
55c11941
MS
7778 if (CONFIGURE_NIC_MODE(bp))
7779 /* allocate searcher T2 table, as it wan't allocated before */
7780 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7781
7782 /* write address to which L5 should insert its values */
7783 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7784 &bp->slowpath->drv_info_to_mcp;
7785
7786 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7787 goto alloc_mem_err;
7788
7789 return 0;
7790
7791alloc_mem_err:
7792 bnx2x_free_mem_cnic(bp);
7793 BNX2X_ERR("Can't allocate memory\n");
7794 return -ENOMEM;
7795}
7796
7797int bnx2x_alloc_mem(struct bnx2x *bp)
7798{
7799 int i, allocated, context_size;
a2fbb9ea 7800
55c11941
MS
7801 if (!CONFIGURE_NIC_MODE(bp))
7802 /* allocate searcher T2 table */
7803 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7804
523224a3
DK
7805 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7806 sizeof(struct host_sp_status_block));
a2fbb9ea 7807
523224a3
DK
7808 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7809 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7810
a052997e
MS
7811 /* Allocate memory for CDU context:
7812 * This memory is allocated separately and not in the generic ILT
7813 * functions because CDU differs in few aspects:
7814 * 1. There are multiple entities allocating memory for context -
7815 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7816 * its own ILT lines.
7817 * 2. Since CDU page-size is not a single 4KB page (which is the case
7818 * for the other ILT clients), to be efficient we want to support
7819 * allocation of sub-page-size in the last entry.
7820 * 3. Context pointers are used by the driver to pass to FW / update
7821 * the context (for the other ILT clients the pointers are used just to
7822 * free the memory during unload).
7823 */
7824 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7825
a052997e
MS
7826 for (i = 0, allocated = 0; allocated < context_size; i++) {
7827 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7828 (context_size - allocated));
7829 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7830 &bp->context[i].cxt_mapping,
7831 bp->context[i].size);
7832 allocated += bp->context[i].size;
7833 }
523224a3 7834 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7835
523224a3
DK
7836 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7837 goto alloc_mem_err;
65abd74d 7838
67c431a5
AE
7839 if (bnx2x_iov_alloc_mem(bp))
7840 goto alloc_mem_err;
7841
9f6c9258
DK
7842 /* Slow path ring */
7843 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7844
523224a3
DK
7845 /* EQ */
7846 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7847 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7848
9f6c9258 7849 return 0;
e1510706 7850
9f6c9258
DK
7851alloc_mem_err:
7852 bnx2x_free_mem(bp);
51c1a580 7853 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7854 return -ENOMEM;
65abd74d
YG
7855}
7856
a2fbb9ea
ET
7857/*
7858 * Init service functions
7859 */
a2fbb9ea 7860
619c5cb6
VZ
7861int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7862 struct bnx2x_vlan_mac_obj *obj, bool set,
7863 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7864{
619c5cb6
VZ
7865 int rc;
7866 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7867
619c5cb6 7868 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7869
619c5cb6
VZ
7870 /* Fill general parameters */
7871 ramrod_param.vlan_mac_obj = obj;
7872 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7873
619c5cb6
VZ
7874 /* Fill a user request section if needed */
7875 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7876 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7877
619c5cb6 7878 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7879
619c5cb6
VZ
7880 /* Set the command: ADD or DEL */
7881 if (set)
7882 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7883 else
7884 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7885 }
7886
619c5cb6 7887 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7888
7889 if (rc == -EEXIST) {
7890 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7891 /* do not treat adding same MAC as error */
7892 rc = 0;
7893 } else if (rc < 0)
619c5cb6 7894 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7895
619c5cb6 7896 return rc;
a2fbb9ea
ET
7897}
7898
619c5cb6
VZ
7899int bnx2x_del_all_macs(struct bnx2x *bp,
7900 struct bnx2x_vlan_mac_obj *mac_obj,
7901 int mac_type, bool wait_for_comp)
e665bfda 7902{
619c5cb6
VZ
7903 int rc;
7904 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7905
619c5cb6
VZ
7906 /* Wait for completion of requested */
7907 if (wait_for_comp)
7908 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7909
619c5cb6
VZ
7910 /* Set the mac type of addresses we want to clear */
7911 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7912
619c5cb6
VZ
7913 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7914 if (rc < 0)
7915 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7916
619c5cb6 7917 return rc;
0793f83f
DK
7918}
7919
619c5cb6 7920int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7921{
619c5cb6 7922 unsigned long ramrod_flags = 0;
e665bfda 7923
a3348722
BW
7924 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7925 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7926 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7927 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7928 return 0;
7929 }
614c76df 7930
619c5cb6 7931 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7932
619c5cb6
VZ
7933 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7934 /* Eth MAC is set on RSS leading client (fp[0]) */
15192a8c
BW
7935 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7936 set, BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7937}
6e30dd4e 7938
619c5cb6 7939int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7940{
619c5cb6 7941 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7942}
a2fbb9ea 7943
d6214d7a 7944/**
e8920674 7945 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7946 *
e8920674 7947 * @bp: driver handle
d6214d7a 7948 *
e8920674 7949 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7950 */
1ab4434c 7951int bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7952{
1ab4434c
AE
7953 int rc = 0;
7954
7955 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
7956 return -EINVAL;
7957
9ee3d37b 7958 switch (int_mode) {
1ab4434c
AE
7959 case BNX2X_INT_MODE_MSIX:
7960 /* attempt to enable msix */
7961 rc = bnx2x_enable_msix(bp);
7962
7963 /* msix attained */
7964 if (!rc)
7965 return 0;
7966
7967 /* vfs use only msix */
7968 if (rc && IS_VF(bp))
7969 return rc;
7970
7971 /* failed to enable multiple MSI-X */
7972 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7973 bp->num_queues,
7974 1 + bp->num_cnic_queues);
7975
7976 /* falling through... */
7977 case BNX2X_INT_MODE_MSI:
d6214d7a 7978 bnx2x_enable_msi(bp);
1ab4434c 7979
d6214d7a 7980 /* falling through... */
1ab4434c 7981 case BNX2X_INT_MODE_INTX:
55c11941
MS
7982 bp->num_ethernet_queues = 1;
7983 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7984 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7985 break;
d6214d7a 7986 default:
1ab4434c
AE
7987 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
7988 return -EINVAL;
9f6c9258 7989 }
1ab4434c 7990 return 0;
a2fbb9ea
ET
7991}
7992
1ab4434c 7993/* must be called prior to any HW initializations */
c2bff63f
DK
7994static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7995{
290ca2bb
AE
7996 if (IS_SRIOV(bp))
7997 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
c2bff63f
DK
7998 return L2_ILT_LINES(bp);
7999}
8000
523224a3
DK
8001void bnx2x_ilt_set_info(struct bnx2x *bp)
8002{
8003 struct ilt_client_info *ilt_client;
8004 struct bnx2x_ilt *ilt = BP_ILT(bp);
8005 u16 line = 0;
8006
8007 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8008 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8009
8010 /* CDU */
8011 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8012 ilt_client->client_num = ILT_CLIENT_CDU;
8013 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8014 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8015 ilt_client->start = line;
619c5cb6 8016 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
8017
8018 if (CNIC_SUPPORT(bp))
8019 line += CNIC_ILT_LINES;
523224a3
DK
8020 ilt_client->end = line - 1;
8021
51c1a580 8022 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8023 ilt_client->start,
8024 ilt_client->end,
8025 ilt_client->page_size,
8026 ilt_client->flags,
8027 ilog2(ilt_client->page_size >> 12));
8028
8029 /* QM */
8030 if (QM_INIT(bp->qm_cid_count)) {
8031 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8032 ilt_client->client_num = ILT_CLIENT_QM;
8033 ilt_client->page_size = QM_ILT_PAGE_SZ;
8034 ilt_client->flags = 0;
8035 ilt_client->start = line;
8036
8037 /* 4 bytes for each cid */
8038 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8039 QM_ILT_PAGE_SZ);
8040
8041 ilt_client->end = line - 1;
8042
51c1a580
MS
8043 DP(NETIF_MSG_IFUP,
8044 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8045 ilt_client->start,
8046 ilt_client->end,
8047 ilt_client->page_size,
8048 ilt_client->flags,
8049 ilog2(ilt_client->page_size >> 12));
8050
8051 }
523224a3 8052
55c11941
MS
8053 if (CNIC_SUPPORT(bp)) {
8054 /* SRC */
8055 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8056 ilt_client->client_num = ILT_CLIENT_SRC;
8057 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8058 ilt_client->flags = 0;
8059 ilt_client->start = line;
8060 line += SRC_ILT_LINES;
8061 ilt_client->end = line - 1;
523224a3 8062
55c11941
MS
8063 DP(NETIF_MSG_IFUP,
8064 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8065 ilt_client->start,
8066 ilt_client->end,
8067 ilt_client->page_size,
8068 ilt_client->flags,
8069 ilog2(ilt_client->page_size >> 12));
9f6c9258 8070
55c11941
MS
8071 /* TM */
8072 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8073 ilt_client->client_num = ILT_CLIENT_TM;
8074 ilt_client->page_size = TM_ILT_PAGE_SZ;
8075 ilt_client->flags = 0;
8076 ilt_client->start = line;
8077 line += TM_ILT_LINES;
8078 ilt_client->end = line - 1;
523224a3 8079
55c11941
MS
8080 DP(NETIF_MSG_IFUP,
8081 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8082 ilt_client->start,
8083 ilt_client->end,
8084 ilt_client->page_size,
8085 ilt_client->flags,
8086 ilog2(ilt_client->page_size >> 12));
8087 }
9f6c9258 8088
619c5cb6 8089 BUG_ON(line > ILT_MAX_LINES);
523224a3 8090}
f85582f8 8091
619c5cb6
VZ
8092/**
8093 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8094 *
8095 * @bp: driver handle
8096 * @fp: pointer to fastpath
8097 * @init_params: pointer to parameters structure
8098 *
8099 * parameters configured:
8100 * - HC configuration
8101 * - Queue's CDU context
8102 */
1191cb83 8103static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 8104 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 8105{
6383c0b3
AE
8106
8107 u8 cos;
a052997e
MS
8108 int cxt_index, cxt_offset;
8109
619c5cb6
VZ
8110 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8111 if (!IS_FCOE_FP(fp)) {
8112 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8113 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8114
8115 /* If HC is supporterd, enable host coalescing in the transition
8116 * to INIT state.
8117 */
8118 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8119 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8120
8121 /* HC rate */
8122 init_params->rx.hc_rate = bp->rx_ticks ?
8123 (1000000 / bp->rx_ticks) : 0;
8124 init_params->tx.hc_rate = bp->tx_ticks ?
8125 (1000000 / bp->tx_ticks) : 0;
8126
8127 /* FW SB ID */
8128 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8129 fp->fw_sb_id;
8130
8131 /*
8132 * CQ index among the SB indices: FCoE clients uses the default
8133 * SB, therefore it's different.
8134 */
6383c0b3
AE
8135 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8136 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
8137 }
8138
6383c0b3
AE
8139 /* set maximum number of COSs supported by this queue */
8140 init_params->max_cos = fp->max_cos;
8141
51c1a580 8142 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
8143 fp->index, init_params->max_cos);
8144
8145 /* set the context pointers queue object */
a052997e 8146 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
8147 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8148 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 8149 ILT_PAGE_CIDS);
6383c0b3 8150 init_params->cxts[cos] =
a052997e
MS
8151 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8152 }
619c5cb6
VZ
8153}
8154
910cc727 8155static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
8156 struct bnx2x_queue_state_params *q_params,
8157 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8158 int tx_index, bool leading)
8159{
8160 memset(tx_only_params, 0, sizeof(*tx_only_params));
8161
8162 /* Set the command */
8163 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8164
8165 /* Set tx-only QUEUE flags: don't zero statistics */
8166 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8167
8168 /* choose the index of the cid to send the slow path on */
8169 tx_only_params->cid_index = tx_index;
8170
8171 /* Set general TX_ONLY_SETUP parameters */
8172 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8173
8174 /* Set Tx TX_ONLY_SETUP parameters */
8175 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8176
51c1a580
MS
8177 DP(NETIF_MSG_IFUP,
8178 "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
8179 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8180 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8181 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8182
8183 /* send the ramrod */
8184 return bnx2x_queue_state_change(bp, q_params);
8185}
8186
8187
619c5cb6
VZ
8188/**
8189 * bnx2x_setup_queue - setup queue
8190 *
8191 * @bp: driver handle
8192 * @fp: pointer to fastpath
8193 * @leading: is leading
8194 *
8195 * This function performs 2 steps in a Queue state machine
8196 * actually: 1) RESET->INIT 2) INIT->SETUP
8197 */
8198
8199int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8200 bool leading)
8201{
3b603066 8202 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8203 struct bnx2x_queue_setup_params *setup_params =
8204 &q_params.params.setup;
6383c0b3
AE
8205 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8206 &q_params.params.tx_only;
a2fbb9ea 8207 int rc;
6383c0b3
AE
8208 u8 tx_index;
8209
51c1a580 8210 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8211
ec6ba945
VZ
8212 /* reset IGU state skip FCoE L2 queue */
8213 if (!IS_FCOE_FP(fp))
8214 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8215 IGU_INT_ENABLE, 0);
a2fbb9ea 8216
15192a8c 8217 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8218 /* We want to wait for completion in this context */
8219 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8220
619c5cb6
VZ
8221 /* Prepare the INIT parameters */
8222 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8223
619c5cb6
VZ
8224 /* Set the command */
8225 q_params.cmd = BNX2X_Q_CMD_INIT;
8226
8227 /* Change the state to INIT */
8228 rc = bnx2x_queue_state_change(bp, &q_params);
8229 if (rc) {
6383c0b3 8230 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8231 return rc;
8232 }
ec6ba945 8233
51c1a580 8234 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
8235
8236
619c5cb6
VZ
8237 /* Now move the Queue to the SETUP state... */
8238 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8239
619c5cb6
VZ
8240 /* Set QUEUE flags */
8241 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8242
619c5cb6 8243 /* Set general SETUP parameters */
6383c0b3
AE
8244 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8245 FIRST_TX_COS_INDEX);
619c5cb6 8246
6383c0b3 8247 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8248 &setup_params->rxq_params);
8249
6383c0b3
AE
8250 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8251 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8252
8253 /* Set the command */
8254 q_params.cmd = BNX2X_Q_CMD_SETUP;
8255
55c11941
MS
8256 if (IS_FCOE_FP(fp))
8257 bp->fcoe_init = true;
8258
619c5cb6
VZ
8259 /* Change the state to SETUP */
8260 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8261 if (rc) {
8262 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8263 return rc;
8264 }
8265
8266 /* loop through the relevant tx-only indices */
8267 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8268 tx_index < fp->max_cos;
8269 tx_index++) {
8270
8271 /* prepare and send tx-only ramrod*/
8272 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8273 tx_only_params, tx_index, leading);
8274 if (rc) {
8275 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8276 fp->index, tx_index);
8277 return rc;
8278 }
8279 }
523224a3 8280
34f80b04 8281 return rc;
a2fbb9ea
ET
8282}
8283
619c5cb6 8284static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8285{
619c5cb6 8286 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8287 struct bnx2x_fp_txdata *txdata;
3b603066 8288 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8289 int rc, tx_index;
8290
51c1a580 8291 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8292
15192a8c 8293 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8294 /* We want to wait for completion in this context */
8295 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8296
6383c0b3
AE
8297
8298 /* close tx-only connections */
8299 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8300 tx_index < fp->max_cos;
8301 tx_index++){
8302
8303 /* ascertain this is a normal queue*/
65565884 8304 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8305
51c1a580 8306 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8307 txdata->txq_index);
8308
8309 /* send halt terminate on tx-only connection */
8310 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8311 memset(&q_params.params.terminate, 0,
8312 sizeof(q_params.params.terminate));
8313 q_params.params.terminate.cid_index = tx_index;
8314
8315 rc = bnx2x_queue_state_change(bp, &q_params);
8316 if (rc)
8317 return rc;
8318
8319 /* send halt terminate on tx-only connection */
8320 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8321 memset(&q_params.params.cfc_del, 0,
8322 sizeof(q_params.params.cfc_del));
8323 q_params.params.cfc_del.cid_index = tx_index;
8324 rc = bnx2x_queue_state_change(bp, &q_params);
8325 if (rc)
8326 return rc;
8327 }
8328 /* Stop the primary connection: */
8329 /* ...halt the connection */
619c5cb6
VZ
8330 q_params.cmd = BNX2X_Q_CMD_HALT;
8331 rc = bnx2x_queue_state_change(bp, &q_params);
8332 if (rc)
da5a662a 8333 return rc;
a2fbb9ea 8334
6383c0b3 8335 /* ...terminate the connection */
619c5cb6 8336 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8337 memset(&q_params.params.terminate, 0,
8338 sizeof(q_params.params.terminate));
8339 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8340 rc = bnx2x_queue_state_change(bp, &q_params);
8341 if (rc)
523224a3 8342 return rc;
6383c0b3 8343 /* ...delete cfc entry */
619c5cb6 8344 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8345 memset(&q_params.params.cfc_del, 0,
8346 sizeof(q_params.params.cfc_del));
8347 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8348 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8349}
8350
8351
34f80b04
EG
8352static void bnx2x_reset_func(struct bnx2x *bp)
8353{
8354 int port = BP_PORT(bp);
8355 int func = BP_FUNC(bp);
f2e0899f 8356 int i;
523224a3
DK
8357
8358 /* Disable the function in the FW */
8359 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8360 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8361 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8362 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8363
8364 /* FP SBs */
ec6ba945 8365 for_each_eth_queue(bp, i) {
523224a3 8366 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8367 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8368 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8369 SB_DISABLED);
523224a3
DK
8370 }
8371
55c11941
MS
8372 if (CNIC_LOADED(bp))
8373 /* CNIC SB */
8374 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8375 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8376 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8377
523224a3 8378 /* SP SB */
619c5cb6 8379 REG_WR8(bp, BAR_CSTRORM_INTMEM +
2de67439
YM
8380 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8381 SB_DISABLED);
523224a3
DK
8382
8383 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8384 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8385 0);
34f80b04
EG
8386
8387 /* Configure IGU */
f2e0899f
DK
8388 if (bp->common.int_block == INT_BLOCK_HC) {
8389 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8390 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8391 } else {
8392 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8393 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8394 }
34f80b04 8395
55c11941
MS
8396 if (CNIC_LOADED(bp)) {
8397 /* Disable Timer scan */
8398 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8399 /*
8400 * Wait for at least 10ms and up to 2 second for the timers
8401 * scan to complete
8402 */
8403 for (i = 0; i < 200; i++) {
8404 msleep(10);
8405 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8406 break;
8407 }
37b091ba 8408 }
34f80b04 8409 /* Clear ILT */
f2e0899f
DK
8410 bnx2x_clear_func_ilt(bp, func);
8411
8412 /* Timers workaround bug for E2: if this is vnic-3,
8413 * we need to set the entire ilt range for this timers.
8414 */
619c5cb6 8415 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8416 struct ilt_client_info ilt_cli;
8417 /* use dummy TM client */
8418 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8419 ilt_cli.start = 0;
8420 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8421 ilt_cli.client_num = ILT_CLIENT_TM;
8422
8423 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8424 }
8425
8426 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8427 if (!CHIP_IS_E1x(bp))
f2e0899f 8428 bnx2x_pf_disable(bp);
523224a3
DK
8429
8430 bp->dmae_ready = 0;
34f80b04
EG
8431}
8432
8433static void bnx2x_reset_port(struct bnx2x *bp)
8434{
8435 int port = BP_PORT(bp);
8436 u32 val;
8437
619c5cb6
VZ
8438 /* Reset physical Link */
8439 bnx2x__link_reset(bp);
8440
34f80b04
EG
8441 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8442
8443 /* Do not rcv packets to BRB */
8444 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8445 /* Do not direct rcv packets that are not for MCP to the BRB */
8446 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8447 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8448
8449 /* Configure AEU */
8450 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8451
8452 msleep(100);
8453 /* Check for BRB port occupancy */
8454 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8455 if (val)
8456 DP(NETIF_MSG_IFDOWN,
33471629 8457 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8458
8459 /* TODO: Close Doorbell port? */
8460}
8461
1191cb83 8462static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8463{
3b603066 8464 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8465
619c5cb6
VZ
8466 /* Prepare parameters for function state transitions */
8467 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8468
619c5cb6
VZ
8469 func_params.f_obj = &bp->func_obj;
8470 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8471
619c5cb6 8472 func_params.params.hw_init.load_phase = load_code;
49d66772 8473
619c5cb6 8474 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8475}
8476
1191cb83 8477static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8478{
3b603066 8479 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8480 int rc;
228241eb 8481
619c5cb6
VZ
8482 /* Prepare parameters for function state transitions */
8483 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8484 func_params.f_obj = &bp->func_obj;
8485 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8486
619c5cb6
VZ
8487 /*
8488 * Try to stop the function the 'good way'. If fails (in case
8489 * of a parity error during bnx2x_chip_cleanup()) and we are
8490 * not in a debug mode, perform a state transaction in order to
8491 * enable further HW_RESET transaction.
8492 */
8493 rc = bnx2x_func_state_change(bp, &func_params);
8494 if (rc) {
34f80b04 8495#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8496 return rc;
34f80b04 8497#else
51c1a580 8498 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8499 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8500 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8501#endif
228241eb 8502 }
a2fbb9ea 8503
619c5cb6
VZ
8504 return 0;
8505}
523224a3 8506
619c5cb6
VZ
8507/**
8508 * bnx2x_send_unload_req - request unload mode from the MCP.
8509 *
8510 * @bp: driver handle
8511 * @unload_mode: requested function's unload mode
8512 *
8513 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8514 */
8515u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8516{
8517 u32 reset_code = 0;
8518 int port = BP_PORT(bp);
3101c2bc 8519
619c5cb6 8520 /* Select the UNLOAD request mode */
65abd74d
YG
8521 if (unload_mode == UNLOAD_NORMAL)
8522 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8523
7d0446c2 8524 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8525 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8526
7d0446c2 8527 else if (bp->wol) {
65abd74d
YG
8528 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8529 u8 *mac_addr = bp->dev->dev_addr;
8530 u32 val;
f9977903
DK
8531 u16 pmc;
8532
65abd74d 8533 /* The mac address is written to entries 1-4 to
f9977903
DK
8534 * preserve entry 0 which is used by the PMF
8535 */
3395a033 8536 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8537
8538 val = (mac_addr[0] << 8) | mac_addr[1];
8539 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8540
8541 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8542 (mac_addr[4] << 8) | mac_addr[5];
8543 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8544
f9977903
DK
8545 /* Enable the PME and clear the status */
8546 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8547 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8548 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8549
65abd74d
YG
8550 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8551
8552 } else
8553 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8554
619c5cb6
VZ
8555 /* Send the request to the MCP */
8556 if (!BP_NOMCP(bp))
8557 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8558 else {
8559 int path = BP_PATH(bp);
8560
51c1a580 8561 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8562 path, load_count[path][0], load_count[path][1],
8563 load_count[path][2]);
8564 load_count[path][0]--;
8565 load_count[path][1 + port]--;
51c1a580 8566 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8567 path, load_count[path][0], load_count[path][1],
8568 load_count[path][2]);
8569 if (load_count[path][0] == 0)
8570 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8571 else if (load_count[path][1 + port] == 0)
8572 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8573 else
8574 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8575 }
8576
8577 return reset_code;
8578}
8579
8580/**
8581 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8582 *
8583 * @bp: driver handle
5d07d868 8584 * @keep_link: true iff link should be kept up
619c5cb6 8585 */
5d07d868 8586void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8587{
5d07d868
YM
8588 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8589
619c5cb6
VZ
8590 /* Report UNLOAD_DONE to MCP */
8591 if (!BP_NOMCP(bp))
5d07d868 8592 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8593}
8594
1191cb83 8595static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8596{
8597 int tout = 50;
8598 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8599
8600 if (!bp->port.pmf)
8601 return 0;
8602
8603 /*
8604 * (assumption: No Attention from MCP at this stage)
8605 * PMF probably in the middle of TXdisable/enable transaction
8606 * 1. Sync IRS for default SB
8607 * 2. Sync SP queue - this guarantes us that attention handling started
8608 * 3. Wait, that TXdisable/enable transaction completes
8609 *
8610 * 1+2 guranty that if DCBx attention was scheduled it already changed
8611 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8612 * received complettion for the transaction the state is TX_STOPPED.
8613 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8614 * transaction.
8615 */
8616
8617 /* make sure default SB ISR is done */
8618 if (msix)
8619 synchronize_irq(bp->msix_table[0].vector);
8620 else
8621 synchronize_irq(bp->pdev->irq);
8622
8623 flush_workqueue(bnx2x_wq);
8624
8625 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8626 BNX2X_F_STATE_STARTED && tout--)
8627 msleep(20);
8628
8629 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8630 BNX2X_F_STATE_STARTED) {
8631#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8632 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8633 return -EBUSY;
8634#else
8635 /*
8636 * Failed to complete the transaction in a "good way"
8637 * Force both transactions with CLR bit
8638 */
3b603066 8639 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8640
51c1a580
MS
8641 DP(NETIF_MSG_IFDOWN,
8642 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8643
8644 func_params.f_obj = &bp->func_obj;
8645 __set_bit(RAMROD_DRV_CLR_ONLY,
8646 &func_params.ramrod_flags);
8647
8648 /* STARTED-->TX_ST0PPED */
8649 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8650 bnx2x_func_state_change(bp, &func_params);
8651
8652 /* TX_ST0PPED-->STARTED */
8653 func_params.cmd = BNX2X_F_CMD_TX_START;
8654 return bnx2x_func_state_change(bp, &func_params);
8655#endif
8656 }
8657
8658 return 0;
8659}
8660
5d07d868 8661void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8662{
8663 int port = BP_PORT(bp);
6383c0b3
AE
8664 int i, rc = 0;
8665 u8 cos;
3b603066 8666 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8667 u32 reset_code;
8668
8669 /* Wait until tx fastpath tasks complete */
8670 for_each_tx_queue(bp, i) {
8671 struct bnx2x_fastpath *fp = &bp->fp[i];
8672
6383c0b3 8673 for_each_cos_in_tx_queue(fp, cos)
65565884 8674 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8675#ifdef BNX2X_STOP_ON_ERROR
8676 if (rc)
8677 return;
8678#endif
8679 }
8680
8681 /* Give HW time to discard old tx messages */
0926d499 8682 usleep_range(1000, 2000);
619c5cb6
VZ
8683
8684 /* Clean all ETH MACs */
15192a8c
BW
8685 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8686 false);
619c5cb6
VZ
8687 if (rc < 0)
8688 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8689
8690 /* Clean up UC list */
15192a8c 8691 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8692 true);
8693 if (rc < 0)
51c1a580
MS
8694 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8695 rc);
619c5cb6
VZ
8696
8697 /* Disable LLH */
8698 if (!CHIP_IS_E1(bp))
8699 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8700
8701 /* Set "drop all" (stop Rx).
8702 * We need to take a netif_addr_lock() here in order to prevent
8703 * a race between the completion code and this code.
8704 */
8705 netif_addr_lock_bh(bp->dev);
8706 /* Schedule the rx_mode command */
8707 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8708 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8709 else
8710 bnx2x_set_storm_rx_mode(bp);
8711
8712 /* Cleanup multicast configuration */
8713 rparam.mcast_obj = &bp->mcast_obj;
8714 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8715 if (rc < 0)
8716 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8717
8718 netif_addr_unlock_bh(bp->dev);
8719
f1929b01 8720 bnx2x_iov_chip_cleanup(bp);
619c5cb6 8721
6debea87
DK
8722
8723 /*
8724 * Send the UNLOAD_REQUEST to the MCP. This will return if
8725 * this function should perform FUNC, PORT or COMMON HW
8726 * reset.
8727 */
8728 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8729
8730 /*
8731 * (assumption: No Attention from MCP at this stage)
8732 * PMF probably in the middle of TXdisable/enable transaction
8733 */
8734 rc = bnx2x_func_wait_started(bp);
8735 if (rc) {
8736 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8737#ifdef BNX2X_STOP_ON_ERROR
8738 return;
8739#endif
8740 }
8741
34f80b04 8742 /* Close multi and leading connections
619c5cb6
VZ
8743 * Completions for ramrods are collected in a synchronous way
8744 */
55c11941 8745 for_each_eth_queue(bp, i)
619c5cb6 8746 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8747#ifdef BNX2X_STOP_ON_ERROR
8748 return;
8749#else
228241eb 8750 goto unload_error;
523224a3 8751#endif
55c11941
MS
8752
8753 if (CNIC_LOADED(bp)) {
8754 for_each_cnic_queue(bp, i)
8755 if (bnx2x_stop_queue(bp, i))
8756#ifdef BNX2X_STOP_ON_ERROR
8757 return;
8758#else
8759 goto unload_error;
8760#endif
8761 }
8762
619c5cb6
VZ
8763 /* If SP settings didn't get completed so far - something
8764 * very wrong has happen.
8765 */
8766 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8767 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8768
619c5cb6
VZ
8769#ifndef BNX2X_STOP_ON_ERROR
8770unload_error:
8771#endif
523224a3 8772 rc = bnx2x_func_stop(bp);
da5a662a 8773 if (rc) {
523224a3 8774 BNX2X_ERR("Function stop failed!\n");
da5a662a 8775#ifdef BNX2X_STOP_ON_ERROR
523224a3 8776 return;
523224a3 8777#endif
34f80b04 8778 }
a2fbb9ea 8779
523224a3
DK
8780 /* Disable HW interrupts, NAPI */
8781 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8782 /* Delete all NAPI objects */
8783 bnx2x_del_all_napi(bp);
55c11941
MS
8784 if (CNIC_LOADED(bp))
8785 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8786
8787 /* Release IRQs */
d6214d7a 8788 bnx2x_free_irq(bp);
523224a3 8789
a2fbb9ea 8790 /* Reset the chip */
619c5cb6
VZ
8791 rc = bnx2x_reset_hw(bp, reset_code);
8792 if (rc)
8793 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8794
356e2385 8795
619c5cb6 8796 /* Report UNLOAD_DONE to MCP */
5d07d868 8797 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8798}
8799
9f6c9258 8800void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8801{
8802 u32 val;
8803
51c1a580 8804 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8805
8806 if (CHIP_IS_E1(bp)) {
8807 int port = BP_PORT(bp);
8808 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8809 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8810
8811 val = REG_RD(bp, addr);
8812 val &= ~(0x300);
8813 REG_WR(bp, addr, val);
619c5cb6 8814 } else {
72fd0718
VZ
8815 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8816 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8817 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8818 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8819 }
8820}
8821
72fd0718
VZ
8822/* Close gates #2, #3 and #4: */
8823static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8824{
c9ee9206 8825 u32 val;
72fd0718
VZ
8826
8827 /* Gates #2 and #4a are closed/opened for "not E1" only */
8828 if (!CHIP_IS_E1(bp)) {
8829 /* #4 */
c9ee9206 8830 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8831 /* #2 */
c9ee9206 8832 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8833 }
8834
8835 /* #3 */
c9ee9206
VZ
8836 if (CHIP_IS_E1x(bp)) {
8837 /* Prevent interrupts from HC on both ports */
8838 val = REG_RD(bp, HC_REG_CONFIG_1);
8839 REG_WR(bp, HC_REG_CONFIG_1,
8840 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8841 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8842
8843 val = REG_RD(bp, HC_REG_CONFIG_0);
8844 REG_WR(bp, HC_REG_CONFIG_0,
8845 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8846 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8847 } else {
8848 /* Prevent incomming interrupts in IGU */
8849 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8850
8851 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8852 (!close) ?
8853 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8854 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8855 }
72fd0718 8856
51c1a580 8857 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8858 close ? "closing" : "opening");
8859 mmiowb();
8860}
8861
8862#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8863
8864static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8865{
8866 /* Do some magic... */
8867 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8868 *magic_val = val & SHARED_MF_CLP_MAGIC;
8869 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8870}
8871
e8920674
DK
8872/**
8873 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8874 *
e8920674
DK
8875 * @bp: driver handle
8876 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8877 */
8878static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8879{
8880 /* Restore the `magic' bit value... */
72fd0718
VZ
8881 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8882 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8883 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8884}
8885
f85582f8 8886/**
e8920674 8887 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8888 *
e8920674
DK
8889 * @bp: driver handle
8890 * @magic_val: old value of 'magic' bit.
8891 *
8892 * Takes care of CLP configurations.
72fd0718
VZ
8893 */
8894static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8895{
8896 u32 shmem;
8897 u32 validity_offset;
8898
51c1a580 8899 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8900
8901 /* Set `magic' bit in order to save MF config */
8902 if (!CHIP_IS_E1(bp))
8903 bnx2x_clp_reset_prep(bp, magic_val);
8904
8905 /* Get shmem offset */
8906 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
8907 validity_offset =
8908 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
8909
8910 /* Clear validity map flags */
8911 if (shmem > 0)
8912 REG_WR(bp, shmem + validity_offset, 0);
8913}
8914
8915#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8916#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8917
e8920674
DK
8918/**
8919 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8920 *
e8920674 8921 * @bp: driver handle
72fd0718 8922 */
1191cb83 8923static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8924{
8925 /* special handling for emulation and FPGA,
8926 wait 10 times longer */
8927 if (CHIP_REV_IS_SLOW(bp))
8928 msleep(MCP_ONE_TIMEOUT*10);
8929 else
8930 msleep(MCP_ONE_TIMEOUT);
8931}
8932
1b6e2ceb
DK
8933/*
8934 * initializes bp->common.shmem_base and waits for validity signature to appear
8935 */
8936static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8937{
1b6e2ceb
DK
8938 int cnt = 0;
8939 u32 val = 0;
72fd0718 8940
1b6e2ceb
DK
8941 do {
8942 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8943 if (bp->common.shmem_base) {
8944 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8945 if (val & SHR_MEM_VALIDITY_MB)
8946 return 0;
8947 }
72fd0718 8948
1b6e2ceb 8949 bnx2x_mcp_wait_one(bp);
72fd0718 8950
1b6e2ceb 8951 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8952
1b6e2ceb 8953 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8954
1b6e2ceb
DK
8955 return -ENODEV;
8956}
72fd0718 8957
1b6e2ceb
DK
8958static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8959{
8960 int rc = bnx2x_init_shmem(bp);
72fd0718 8961
72fd0718
VZ
8962 /* Restore the `magic' bit value */
8963 if (!CHIP_IS_E1(bp))
8964 bnx2x_clp_reset_done(bp, magic_val);
8965
8966 return rc;
8967}
8968
8969static void bnx2x_pxp_prep(struct bnx2x *bp)
8970{
8971 if (!CHIP_IS_E1(bp)) {
8972 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8973 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8974 mmiowb();
8975 }
8976}
8977
8978/*
8979 * Reset the whole chip except for:
8980 * - PCIE core
8981 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8982 * one reset bit)
8983 * - IGU
8984 * - MISC (including AEU)
8985 * - GRC
8986 * - RBCN, RBCP
8987 */
c9ee9206 8988static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8989{
8990 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8991 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8992
8993 /*
8994 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8995 * (per chip) blocks.
8996 */
8997 global_bits2 =
8998 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8999 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 9000
c55e771b
BW
9001 /* Don't reset the following blocks.
9002 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9003 * reset, as in 4 port device they might still be owned
9004 * by the MCP (there is only one leader per path).
9005 */
72fd0718
VZ
9006 not_reset_mask1 =
9007 MISC_REGISTERS_RESET_REG_1_RST_HC |
9008 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9009 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9010
9011 not_reset_mask2 =
c9ee9206 9012 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
9013 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9014 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9015 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9016 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9017 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9018 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
9019 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9020 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
9021 MISC_REGISTERS_RESET_REG_2_PGLC |
9022 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9023 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9024 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9025 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9026 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9027 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 9028
8736c826
VZ
9029 /*
9030 * Keep the following blocks in reset:
9031 * - all xxMACs are handled by the bnx2x_link code.
9032 */
9033 stay_reset2 =
8736c826
VZ
9034 MISC_REGISTERS_RESET_REG_2_XMAC |
9035 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9036
9037 /* Full reset masks according to the chip */
72fd0718
VZ
9038 reset_mask1 = 0xffffffff;
9039
9040 if (CHIP_IS_E1(bp))
9041 reset_mask2 = 0xffff;
8736c826 9042 else if (CHIP_IS_E1H(bp))
72fd0718 9043 reset_mask2 = 0x1ffff;
8736c826
VZ
9044 else if (CHIP_IS_E2(bp))
9045 reset_mask2 = 0xfffff;
9046 else /* CHIP_IS_E3 */
9047 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
9048
9049 /* Don't reset global blocks unless we need to */
9050 if (!global)
9051 reset_mask2 &= ~global_bits2;
9052
9053 /*
9054 * In case of attention in the QM, we need to reset PXP
9055 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9056 * because otherwise QM reset would release 'close the gates' shortly
9057 * before resetting the PXP, then the PSWRQ would send a write
9058 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9059 * read the payload data from PSWWR, but PSWWR would not
9060 * respond. The write queue in PGLUE would stuck, dmae commands
9061 * would not return. Therefore it's important to reset the second
9062 * reset register (containing the
9063 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9064 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9065 * bit).
9066 */
72fd0718
VZ
9067 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9068 reset_mask2 & (~not_reset_mask2));
9069
c9ee9206
VZ
9070 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9071 reset_mask1 & (~not_reset_mask1));
9072
72fd0718
VZ
9073 barrier();
9074 mmiowb();
9075
8736c826
VZ
9076 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9077 reset_mask2 & (~stay_reset2));
9078
9079 barrier();
9080 mmiowb();
9081
c9ee9206 9082 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
9083 mmiowb();
9084}
9085
c9ee9206
VZ
9086/**
9087 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9088 * It should get cleared in no more than 1s.
9089 *
9090 * @bp: driver handle
9091 *
9092 * It should get cleared in no more than 1s. Returns 0 if
9093 * pending writes bit gets cleared.
9094 */
9095static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9096{
9097 u32 cnt = 1000;
9098 u32 pend_bits = 0;
9099
9100 do {
9101 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9102
9103 if (pend_bits == 0)
9104 break;
9105
0926d499 9106 usleep_range(1000, 2000);
c9ee9206
VZ
9107 } while (cnt-- > 0);
9108
9109 if (cnt <= 0) {
9110 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9111 pend_bits);
9112 return -EBUSY;
9113 }
9114
9115 return 0;
9116}
9117
9118static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
9119{
9120 int cnt = 1000;
9121 u32 val = 0;
9122 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
2de67439 9123 u32 tags_63_32 = 0;
72fd0718
VZ
9124
9125 /* Empty the Tetris buffer, wait for 1s */
9126 do {
9127 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9128 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9129 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9130 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9131 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
9132 if (CHIP_IS_E3(bp))
9133 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9134
72fd0718
VZ
9135 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9136 ((port_is_idle_0 & 0x1) == 0x1) &&
9137 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
9138 (pgl_exp_rom2 == 0xffffffff) &&
9139 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 9140 break;
0926d499 9141 usleep_range(1000, 2000);
72fd0718
VZ
9142 } while (cnt-- > 0);
9143
9144 if (cnt <= 0) {
51c1a580
MS
9145 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9146 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
9147 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9148 pgl_exp_rom2);
9149 return -EAGAIN;
9150 }
9151
9152 barrier();
9153
9154 /* Close gates #2, #3 and #4 */
9155 bnx2x_set_234_gates(bp, true);
9156
c9ee9206
VZ
9157 /* Poll for IGU VQs for 57712 and newer chips */
9158 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9159 return -EAGAIN;
9160
9161
72fd0718
VZ
9162 /* TBD: Indicate that "process kill" is in progress to MCP */
9163
9164 /* Clear "unprepared" bit */
9165 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9166 barrier();
9167
9168 /* Make sure all is written to the chip before the reset */
9169 mmiowb();
9170
9171 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9172 * PSWHST, GRC and PSWRD Tetris buffer.
9173 */
0926d499 9174 usleep_range(1000, 2000);
72fd0718
VZ
9175
9176 /* Prepare to chip reset: */
9177 /* MCP */
c9ee9206
VZ
9178 if (global)
9179 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
9180
9181 /* PXP */
9182 bnx2x_pxp_prep(bp);
9183 barrier();
9184
9185 /* reset the chip */
c9ee9206 9186 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9187 barrier();
9188
9189 /* Recover after reset: */
9190 /* MCP */
c9ee9206 9191 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9192 return -EAGAIN;
9193
c9ee9206
VZ
9194 /* TBD: Add resetting the NO_MCP mode DB here */
9195
72fd0718
VZ
9196 /* Open the gates #2, #3 and #4 */
9197 bnx2x_set_234_gates(bp, false);
9198
9199 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9200 * reset state, re-enable attentions. */
9201
a2fbb9ea
ET
9202 return 0;
9203}
9204
910cc727 9205static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9206{
9207 int rc = 0;
c9ee9206 9208 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9209 u32 load_code;
9210
9211 /* if not going to reset MCP - load "fake" driver to reset HW while
9212 * driver is owner of the HW
9213 */
9214 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9215 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9216 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9217 if (!load_code) {
9218 BNX2X_ERR("MCP response failure, aborting\n");
9219 rc = -EAGAIN;
9220 goto exit_leader_reset;
9221 }
9222 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9223 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9224 BNX2X_ERR("MCP unexpected resp, aborting\n");
9225 rc = -EAGAIN;
9226 goto exit_leader_reset2;
9227 }
9228 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9229 if (!load_code) {
9230 BNX2X_ERR("MCP response failure, aborting\n");
9231 rc = -EAGAIN;
9232 goto exit_leader_reset2;
9233 }
9234 }
c9ee9206 9235
72fd0718 9236 /* Try to recover after the failure */
c9ee9206 9237 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9238 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9239 BP_PATH(bp));
72fd0718 9240 rc = -EAGAIN;
95c6c616 9241 goto exit_leader_reset2;
72fd0718
VZ
9242 }
9243
c9ee9206
VZ
9244 /*
9245 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9246 * state.
9247 */
72fd0718 9248 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9249 if (global)
9250 bnx2x_clear_reset_global(bp);
72fd0718 9251
95c6c616
AE
9252exit_leader_reset2:
9253 /* unload "fake driver" if it was loaded */
9254 if (!global && !BP_NOMCP(bp)) {
9255 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9256 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9257 }
72fd0718
VZ
9258exit_leader_reset:
9259 bp->is_leader = 0;
c9ee9206
VZ
9260 bnx2x_release_leader_lock(bp);
9261 smp_mb();
72fd0718
VZ
9262 return rc;
9263}
9264
1191cb83 9265static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9266{
9267 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9268
9269 /* Disconnect this device */
9270 netif_device_detach(bp->dev);
9271
9272 /*
9273 * Block ifup for all function on this engine until "process kill"
9274 * or power cycle.
9275 */
9276 bnx2x_set_reset_in_progress(bp);
9277
9278 /* Shut down the power */
9279 bnx2x_set_power_state(bp, PCI_D3hot);
9280
9281 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9282
9283 smp_mb();
9284}
9285
9286/*
9287 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9288 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9289 * will never be called when netif_running(bp->dev) is false.
9290 */
9291static void bnx2x_parity_recover(struct bnx2x *bp)
9292{
c9ee9206 9293 bool global = false;
7a752993 9294 u32 error_recovered, error_unrecovered;
95c6c616 9295 bool is_parity;
c9ee9206 9296
72fd0718
VZ
9297 DP(NETIF_MSG_HW, "Handling parity\n");
9298 while (1) {
9299 switch (bp->recovery_state) {
9300 case BNX2X_RECOVERY_INIT:
9301 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9302 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9303 WARN_ON(!is_parity);
c9ee9206 9304
72fd0718 9305 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9306 if (bnx2x_trylock_leader_lock(bp)) {
9307 bnx2x_set_reset_in_progress(bp);
9308 /*
9309 * Check if there is a global attention and if
9310 * there was a global attention, set the global
9311 * reset bit.
9312 */
9313
9314 if (global)
9315 bnx2x_set_reset_global(bp);
9316
72fd0718 9317 bp->is_leader = 1;
c9ee9206 9318 }
72fd0718
VZ
9319
9320 /* Stop the driver */
9321 /* If interface has been removed - break */
5d07d868 9322 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9323 return;
9324
9325 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9326
c9ee9206
VZ
9327 /* Ensure "is_leader", MCP command sequence and
9328 * "recovery_state" update values are seen on other
9329 * CPUs.
72fd0718 9330 */
c9ee9206 9331 smp_mb();
72fd0718
VZ
9332 break;
9333
9334 case BNX2X_RECOVERY_WAIT:
9335 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9336 if (bp->is_leader) {
c9ee9206 9337 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9338 bool other_load_status =
9339 bnx2x_get_load_status(bp, other_engine);
9340 bool load_status =
9341 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9342 global = bnx2x_reset_is_global(bp);
9343
9344 /*
9345 * In case of a parity in a global block, let
9346 * the first leader that performs a
9347 * leader_reset() reset the global blocks in
9348 * order to clear global attentions. Otherwise
9349 * the the gates will remain closed for that
9350 * engine.
9351 */
889b9af3
AE
9352 if (load_status ||
9353 (global && other_load_status)) {
72fd0718
VZ
9354 /* Wait until all other functions get
9355 * down.
9356 */
7be08a72 9357 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9358 HZ/10);
9359 return;
9360 } else {
9361 /* If all other functions got down -
9362 * try to bring the chip back to
9363 * normal. In any case it's an exit
9364 * point for a leader.
9365 */
c9ee9206
VZ
9366 if (bnx2x_leader_reset(bp)) {
9367 bnx2x_recovery_failed(bp);
72fd0718
VZ
9368 return;
9369 }
9370
c9ee9206
VZ
9371 /* If we are here, means that the
9372 * leader has succeeded and doesn't
9373 * want to be a leader any more. Try
9374 * to continue as a none-leader.
9375 */
9376 break;
72fd0718
VZ
9377 }
9378 } else { /* non-leader */
c9ee9206 9379 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9380 /* Try to get a LEADER_LOCK HW lock as
9381 * long as a former leader may have
9382 * been unloaded by the user or
9383 * released a leadership by another
9384 * reason.
9385 */
c9ee9206 9386 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9387 /* I'm a leader now! Restart a
9388 * switch case.
9389 */
9390 bp->is_leader = 1;
9391 break;
9392 }
9393
7be08a72 9394 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9395 HZ/10);
9396 return;
9397
c9ee9206
VZ
9398 } else {
9399 /*
9400 * If there was a global attention, wait
9401 * for it to be cleared.
9402 */
9403 if (bnx2x_reset_is_global(bp)) {
9404 schedule_delayed_work(
7be08a72
AE
9405 &bp->sp_rtnl_task,
9406 HZ/10);
c9ee9206
VZ
9407 return;
9408 }
9409
7a752993
AE
9410 error_recovered =
9411 bp->eth_stats.recoverable_error;
9412 error_unrecovered =
9413 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9414 bp->recovery_state =
9415 BNX2X_RECOVERY_NIC_LOADING;
9416 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9417 error_unrecovered++;
95c6c616 9418 netdev_err(bp->dev,
51c1a580 9419 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9420 /* Disconnect this device */
9421 netif_device_detach(bp->dev);
9422 /* Shut down the power */
9423 bnx2x_set_power_state(
9424 bp, PCI_D3hot);
9425 smp_mb();
9426 } else {
c9ee9206
VZ
9427 bp->recovery_state =
9428 BNX2X_RECOVERY_DONE;
7a752993 9429 error_recovered++;
c9ee9206
VZ
9430 smp_mb();
9431 }
7a752993
AE
9432 bp->eth_stats.recoverable_error =
9433 error_recovered;
9434 bp->eth_stats.unrecoverable_error =
9435 error_unrecovered;
c9ee9206 9436
72fd0718
VZ
9437 return;
9438 }
9439 }
9440 default:
9441 return;
9442 }
9443 }
9444}
9445
56ad3152
MS
9446static int bnx2x_close(struct net_device *dev);
9447
72fd0718
VZ
9448/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9449 * scheduled on a general queue in order to prevent a dead lock.
9450 */
7be08a72 9451static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9452{
7be08a72 9453 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9454
9455 rtnl_lock();
9456
8395be5e
AE
9457 if (!netif_running(bp->dev)) {
9458 rtnl_unlock();
9459 return;
9460 }
7be08a72
AE
9461
9462 /* if stop on error is defined no recovery flows should be executed */
9463#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9464 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9465 "you will need to reboot when done\n");
b1fb8740 9466 goto sp_rtnl_not_reset;
7be08a72 9467#endif
34f80b04 9468
7be08a72
AE
9469 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9470 /*
b1fb8740
VZ
9471 * Clear all pending SP commands as we are going to reset the
9472 * function anyway.
7be08a72 9473 */
b1fb8740
VZ
9474 bp->sp_rtnl_state = 0;
9475 smp_mb();
9476
72fd0718 9477 bnx2x_parity_recover(bp);
b1fb8740 9478
8395be5e
AE
9479 rtnl_unlock();
9480 return;
b1fb8740
VZ
9481 }
9482
9483 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9484 /*
9485 * Clear all pending SP commands as we are going to reset the
9486 * function anyway.
9487 */
9488 bp->sp_rtnl_state = 0;
9489 smp_mb();
9490
5d07d868 9491 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9492 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740 9493
8395be5e
AE
9494 rtnl_unlock();
9495 return;
72fd0718 9496 }
b1fb8740
VZ
9497#ifdef BNX2X_STOP_ON_ERROR
9498sp_rtnl_not_reset:
9499#endif
9500 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9501 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9502 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9503 bnx2x_after_function_update(bp);
8304859a
AE
9504 /*
9505 * in case of fan failure we need to reset id if the "stop on error"
9506 * debug flag is set, since we trying to prevent permanent overheating
9507 * damage
9508 */
9509 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9510 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9511 netif_device_detach(bp->dev);
9512 bnx2x_close(bp->dev);
8395be5e
AE
9513 rtnl_unlock();
9514 return;
8304859a
AE
9515 }
9516
381ac16b
AE
9517 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9518 DP(BNX2X_MSG_SP,
9519 "sending set mcast vf pf channel message from rtnl sp-task\n");
9520 bnx2x_vfpf_set_mcast(bp->dev);
9521 }
9522
9523 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
9524 &bp->sp_rtnl_state)) {
9525 DP(BNX2X_MSG_SP,
9526 "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
9527 bnx2x_vfpf_storm_rx_mode(bp);
9528 }
9529
8395be5e
AE
9530 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9531 * can be called from other contexts as well)
9532 */
34f80b04 9533 rtnl_unlock();
8395be5e 9534
6411280a 9535 /* enable SR-IOV if applicable */
8395be5e 9536 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
6411280a
AE
9537 &bp->sp_rtnl_state))
9538 bnx2x_enable_sriov(bp);
34f80b04
EG
9539}
9540
3deb8167
YR
9541static void bnx2x_period_task(struct work_struct *work)
9542{
9543 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9544
9545 if (!netif_running(bp->dev))
9546 goto period_task_exit;
9547
9548 if (CHIP_REV_IS_SLOW(bp)) {
9549 BNX2X_ERR("period task called on emulation, ignoring\n");
9550 goto period_task_exit;
9551 }
9552
9553 bnx2x_acquire_phy_lock(bp);
9554 /*
9555 * The barrier is needed to ensure the ordering between the writing to
9556 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9557 * the reading here.
9558 */
9559 smp_mb();
9560 if (bp->port.pmf) {
9561 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9562
9563 /* Re-queue task in 1 sec */
9564 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9565 }
9566
9567 bnx2x_release_phy_lock(bp);
9568period_task_exit:
9569 return;
9570}
9571
a2fbb9ea
ET
9572/*
9573 * Init service functions
9574 */
9575
b56e9670 9576u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9577{
9578 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9579 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9580 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9581}
9582
1ef1d45a
BW
9583static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9584 struct bnx2x_mac_vals *vals)
34f80b04 9585{
452427b0
YM
9586 u32 val, base_addr, offset, mask, reset_reg;
9587 bool mac_stopped = false;
9588 u8 port = BP_PORT(bp);
34f80b04 9589
1ef1d45a
BW
9590 /* reset addresses as they also mark which values were changed */
9591 vals->bmac_addr = 0;
9592 vals->umac_addr = 0;
9593 vals->xmac_addr = 0;
9594 vals->emac_addr = 0;
9595
452427b0 9596 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9597
452427b0
YM
9598 if (!CHIP_IS_E3(bp)) {
9599 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9600 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9601 if ((mask & reset_reg) && val) {
9602 u32 wb_data[2];
9603 BNX2X_DEV_INFO("Disable bmac Rx\n");
9604 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9605 : NIG_REG_INGRESS_BMAC0_MEM;
9606 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9607 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9608
452427b0
YM
9609 /*
9610 * use rd/wr since we cannot use dmae. This is safe
9611 * since MCP won't access the bus due to the request
9612 * to unload, and no function on the path can be
9613 * loaded at this time.
9614 */
9615 wb_data[0] = REG_RD(bp, base_addr + offset);
9616 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
1ef1d45a
BW
9617 vals->bmac_addr = base_addr + offset;
9618 vals->bmac_val[0] = wb_data[0];
9619 vals->bmac_val[1] = wb_data[1];
452427b0 9620 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1ef1d45a
BW
9621 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9622 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
452427b0
YM
9623
9624 }
9625 BNX2X_DEV_INFO("Disable emac Rx\n");
1ef1d45a
BW
9626 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9627 vals->emac_val = REG_RD(bp, vals->emac_addr);
9628 REG_WR(bp, vals->emac_addr, 0);
452427b0
YM
9629 mac_stopped = true;
9630 } else {
9631 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9632 BNX2X_DEV_INFO("Disable xmac Rx\n");
9633 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9634 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9635 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9636 val & ~(1 << 1));
9637 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9638 val | (1 << 1));
1ef1d45a
BW
9639 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9640 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9641 REG_WR(bp, vals->xmac_addr, 0);
452427b0
YM
9642 mac_stopped = true;
9643 }
9644 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9645 if (mask & reset_reg) {
9646 BNX2X_DEV_INFO("Disable umac Rx\n");
9647 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1ef1d45a
BW
9648 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9649 vals->umac_val = REG_RD(bp, vals->umac_addr);
9650 REG_WR(bp, vals->umac_addr, 0);
452427b0
YM
9651 mac_stopped = true;
9652 }
9653 }
9654
9655 if (mac_stopped)
9656 msleep(20);
9657
9658}
9659
9660#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9661#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9662#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9663#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9664
1dd06ae8 9665static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
452427b0
YM
9666{
9667 u16 rcq, bd;
9668 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9669
9670 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9671 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9672
9673 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9674 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9675
9676 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9677 port, bd, rcq);
9678}
9679
0329aba1 9680static int bnx2x_prev_mcp_done(struct bnx2x *bp)
452427b0 9681{
5d07d868
YM
9682 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9683 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9684 if (!rc) {
9685 BNX2X_ERR("MCP response failure, aborting\n");
9686 return -EBUSY;
9687 }
9688
9689 return 0;
9690}
9691
c63da990
BW
9692static struct bnx2x_prev_path_list *
9693 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9694{
9695 struct bnx2x_prev_path_list *tmp_list;
9696
9697 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9698 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9699 bp->pdev->bus->number == tmp_list->bus &&
9700 BP_PATH(bp) == tmp_list->path)
9701 return tmp_list;
9702
9703 return NULL;
9704}
9705
0329aba1 9706static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
452427b0
YM
9707{
9708 struct bnx2x_prev_path_list *tmp_list;
9709 int rc = false;
9710
9711 if (down_trylock(&bnx2x_prev_sem))
9712 return false;
9713
9714 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9715 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9716 bp->pdev->bus->number == tmp_list->bus &&
9717 BP_PATH(bp) == tmp_list->path) {
9718 rc = true;
9719 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9720 BP_PATH(bp));
9721 break;
9722 }
9723 }
9724
9725 up(&bnx2x_prev_sem);
9726
9727 return rc;
9728}
9729
c63da990 9730static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
452427b0
YM
9731{
9732 struct bnx2x_prev_path_list *tmp_list;
9733 int rc;
9734
ea4b3857 9735 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9736 if (!tmp_list) {
9737 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9738 return -ENOMEM;
9739 }
9740
9741 tmp_list->bus = bp->pdev->bus->number;
9742 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9743 tmp_list->path = BP_PATH(bp);
c63da990 9744 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
452427b0
YM
9745
9746 rc = down_interruptible(&bnx2x_prev_sem);
9747 if (rc) {
9748 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9749 kfree(tmp_list);
9750 } else {
9751 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9752 BP_PATH(bp));
9753 list_add(&tmp_list->list, &bnx2x_prev_list);
9754 up(&bnx2x_prev_sem);
9755 }
9756
9757 return rc;
9758}
9759
0329aba1 9760static int bnx2x_do_flr(struct bnx2x *bp)
452427b0 9761{
2a80eebc 9762 int i;
452427b0
YM
9763 u16 status;
9764 struct pci_dev *dev = bp->pdev;
9765
8eee694c
YM
9766
9767 if (CHIP_IS_E1x(bp)) {
9768 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9769 return -EINVAL;
9770 }
9771
9772 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9773 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9774 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9775 bp->common.bc_ver);
9776 return -EINVAL;
9777 }
452427b0 9778
452427b0
YM
9779 /* Wait for Transaction Pending bit clean */
9780 for (i = 0; i < 4; i++) {
9781 if (i)
9782 msleep((1 << (i - 1)) * 100);
9783
2a80eebc 9784 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9785 if (!(status & PCI_EXP_DEVSTA_TRPND))
9786 goto clear;
9787 }
9788
9789 dev_err(&dev->dev,
9790 "transaction is not cleared; proceeding with reset anyway\n");
9791
9792clear:
452427b0 9793
8eee694c 9794 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9795 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9796
9797 return 0;
9798}
9799
0329aba1 9800static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
452427b0
YM
9801{
9802 int rc;
9803
9804 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9805
9806 /* Test if previous unload process was already finished for this path */
9807 if (bnx2x_prev_is_path_marked(bp))
9808 return bnx2x_prev_mcp_done(bp);
9809
04c46736
YM
9810 BNX2X_DEV_INFO("Path is unmarked\n");
9811
452427b0
YM
9812 /* If function has FLR capabilities, and existing FW version matches
9813 * the one required, then FLR will be sufficient to clean any residue
9814 * left by previous driver
9815 */
ad5afc89 9816 rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
8eee694c
YM
9817
9818 if (!rc) {
9819 /* fw version is good */
9820 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9821 rc = bnx2x_do_flr(bp);
9822 }
9823
9824 if (!rc) {
9825 /* FLR was performed */
9826 BNX2X_DEV_INFO("FLR successful\n");
9827 return 0;
9828 }
9829
9830 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9831
9832 /* Close the MCP request, return failure*/
9833 rc = bnx2x_prev_mcp_done(bp);
9834 if (!rc)
9835 rc = BNX2X_PREV_WAIT_NEEDED;
9836
9837 return rc;
9838}
9839
0329aba1 9840static int bnx2x_prev_unload_common(struct bnx2x *bp)
452427b0
YM
9841{
9842 u32 reset_reg, tmp_reg = 0, rc;
c63da990 9843 bool prev_undi = false;
1ef1d45a
BW
9844 struct bnx2x_mac_vals mac_vals;
9845
452427b0
YM
9846 /* It is possible a previous function received 'common' answer,
9847 * but hasn't loaded yet, therefore creating a scenario of
9848 * multiple functions receiving 'common' on the same path.
9849 */
9850 BNX2X_DEV_INFO("Common unload Flow\n");
9851
1ef1d45a
BW
9852 memset(&mac_vals, 0, sizeof(mac_vals));
9853
452427b0
YM
9854 if (bnx2x_prev_is_path_marked(bp))
9855 return bnx2x_prev_mcp_done(bp);
9856
9857 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9858
9859 /* Reset should be performed after BRB is emptied */
9860 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9861 u32 timer_count = 1000;
452427b0
YM
9862
9863 /* Close the MAC Rx to prevent BRB from filling up */
1ef1d45a
BW
9864 bnx2x_prev_unload_close_mac(bp, &mac_vals);
9865
9866 /* close LLH filters towards the BRB */
9867 bnx2x_set_rx_filter(&bp->link_params, 0);
452427b0
YM
9868
9869 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9870 * UNDI driver initializes CID offset for normal bell to 0x7
9871 */
452427b0
YM
9872 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9873 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9874 if (tmp_reg == 0x7) {
9875 BNX2X_DEV_INFO("UNDI previously loaded\n");
9876 prev_undi = true;
9877 /* clear the UNDI indication */
9878 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
a74801c5
YM
9879 /* clear possible idle check errors */
9880 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
34f80b04 9881 }
452427b0
YM
9882 }
9883 /* wait until BRB is empty */
9884 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9885 while (timer_count) {
9886 u32 prev_brb = tmp_reg;
34f80b04 9887
452427b0
YM
9888 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9889 if (!tmp_reg)
9890 break;
619c5cb6 9891
452427b0 9892 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9893
452427b0
YM
9894 /* reset timer as long as BRB actually gets emptied */
9895 if (prev_brb > tmp_reg)
9896 timer_count = 1000;
9897 else
9898 timer_count--;
da5a662a 9899
452427b0
YM
9900 /* If UNDI resides in memory, manually increment it */
9901 if (prev_undi)
9902 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9903
452427b0 9904 udelay(10);
7a06a122 9905 }
452427b0
YM
9906
9907 if (!timer_count)
9908 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9909
34f80b04 9910 }
f16da43b 9911
452427b0
YM
9912 /* No packets are in the pipeline, path is ready for reset */
9913 bnx2x_reset_common(bp);
9914
1ef1d45a
BW
9915 if (mac_vals.xmac_addr)
9916 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
9917 if (mac_vals.umac_addr)
9918 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
9919 if (mac_vals.emac_addr)
9920 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
9921 if (mac_vals.bmac_addr) {
9922 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
9923 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
9924 }
9925
c63da990 9926 rc = bnx2x_prev_mark_path(bp, prev_undi);
452427b0
YM
9927 if (rc) {
9928 bnx2x_prev_mcp_done(bp);
9929 return rc;
9930 }
9931
9932 return bnx2x_prev_mcp_done(bp);
9933}
9934
24f06716
AE
9935/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9936 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9937 * the addresses of the transaction, resulting in was-error bit set in the pci
9938 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9939 * to clear the interrupt which detected this from the pglueb and the was done
9940 * bit
9941 */
0329aba1 9942static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
24f06716 9943{
4a25417c
AE
9944 if (!CHIP_IS_E1x(bp)) {
9945 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9946 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
04c46736
YM
9947 DP(BNX2X_MSG_SP,
9948 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
4a25417c
AE
9949 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9950 1 << BP_FUNC(bp));
9951 }
24f06716
AE
9952 }
9953}
9954
0329aba1 9955static int bnx2x_prev_unload(struct bnx2x *bp)
452427b0
YM
9956{
9957 int time_counter = 10;
9958 u32 rc, fw, hw_lock_reg, hw_lock_val;
c63da990 9959 struct bnx2x_prev_path_list *prev_list;
452427b0
YM
9960 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9961
24f06716
AE
9962 /* clear hw from errors which may have resulted from an interrupted
9963 * dmae transaction.
9964 */
9965 bnx2x_prev_interrupted_dmae(bp);
9966
9967 /* Release previously held locks */
452427b0
YM
9968 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9969 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9970 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9971
9972 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9973 if (hw_lock_val) {
9974 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9975 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9976 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9977 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9978 }
9979
9980 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9981 REG_WR(bp, hw_lock_reg, 0xffffffff);
9982 } else
9983 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9984
9985 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9986 BNX2X_DEV_INFO("Release previously held alr\n");
9987 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9988 }
9989
452427b0
YM
9990 do {
9991 /* Lock MCP using an unload request */
9992 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9993 if (!fw) {
9994 BNX2X_ERR("MCP response failure, aborting\n");
9995 rc = -EBUSY;
9996 break;
9997 }
9998
9999 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
10000 rc = bnx2x_prev_unload_common(bp);
10001 break;
10002 }
10003
10004 /* non-common reply from MCP night require looping */
10005 rc = bnx2x_prev_unload_uncommon(bp);
10006 if (rc != BNX2X_PREV_WAIT_NEEDED)
10007 break;
10008
10009 msleep(20);
10010 } while (--time_counter);
10011
10012 if (!time_counter || rc) {
10013 BNX2X_ERR("Failed unloading previous driver, aborting\n");
10014 rc = -EBUSY;
10015 }
10016
c63da990
BW
10017 /* Mark function if its port was used to boot from SAN */
10018 prev_list = bnx2x_prev_path_get_entry(bp);
10019 if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
10020 bp->link_params.feature_config_flags |=
10021 FEATURE_CONFIG_BOOT_FROM_SAN;
10022
452427b0
YM
10023 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10024
10025 return rc;
34f80b04
EG
10026}
10027
0329aba1 10028static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
34f80b04 10029{
1d187b34 10030 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 10031 u16 pmc;
34f80b04
EG
10032
10033 /* Get the chip revision id and number. */
10034 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10035 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10036 id = ((val & 0xffff) << 16);
10037 val = REG_RD(bp, MISC_REG_CHIP_REV);
10038 id |= ((val & 0xf) << 12);
10039 val = REG_RD(bp, MISC_REG_CHIP_METAL);
10040 id |= ((val & 0xff) << 4);
5a40e08e 10041 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
10042 id |= (val & 0xf);
10043 bp->common.chip_id = id;
523224a3 10044
7e8e02df
BW
10045 /* force 57811 according to MISC register */
10046 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10047 if (CHIP_IS_57810(bp))
10048 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10049 (bp->common.chip_id & 0x0000FFFF);
10050 else if (CHIP_IS_57810_MF(bp))
10051 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10052 (bp->common.chip_id & 0x0000FFFF);
10053 bp->common.chip_id |= 0x1;
10054 }
10055
523224a3
DK
10056 /* Set doorbell size */
10057 bp->db_size = (1 << BNX2X_DB_SHIFT);
10058
619c5cb6 10059 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
10060 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10061 if ((val & 1) == 0)
10062 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10063 else
10064 val = (val >> 1) & 1;
10065 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10066 "2_PORT_MODE");
10067 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10068 CHIP_2_PORT_MODE;
10069
10070 if (CHIP_MODE_IS_4_PORT(bp))
10071 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10072 else
10073 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10074 } else {
10075 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10076 bp->pfid = bp->pf_num; /* 0..7 */
10077 }
10078
51c1a580
MS
10079 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10080
f2e0899f
DK
10081 bp->link_params.chip_id = bp->common.chip_id;
10082 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 10083
1c06328c
EG
10084 val = (REG_RD(bp, 0x2874) & 0x55);
10085 if ((bp->common.chip_id & 0x1) ||
10086 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10087 bp->flags |= ONE_PORT_FLAG;
10088 BNX2X_DEV_INFO("single port device\n");
10089 }
10090
34f80b04 10091 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 10092 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
10093 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10094 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10095 bp->common.flash_size, bp->common.flash_size);
10096
1b6e2ceb
DK
10097 bnx2x_init_shmem(bp);
10098
619c5cb6
VZ
10099
10100
f2e0899f
DK
10101 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10102 MISC_REG_GENERIC_CR_1 :
10103 MISC_REG_GENERIC_CR_0));
1b6e2ceb 10104
34f80b04 10105 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 10106 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
10107 if (SHMEM2_RD(bp, size) >
10108 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10109 bp->link_params.lfa_base =
10110 REG_RD(bp, bp->common.shmem2_base +
10111 (u32)offsetof(struct shmem2_region,
10112 lfa_host_addr[BP_PORT(bp)]));
10113 else
10114 bp->link_params.lfa_base = 0;
2691d51d
EG
10115 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10116 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 10117
f2e0899f 10118 if (!bp->common.shmem_base) {
34f80b04
EG
10119 BNX2X_DEV_INFO("MCP not active\n");
10120 bp->flags |= NO_MCP_FLAG;
10121 return;
10122 }
10123
34f80b04 10124 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 10125 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
10126
10127 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10128 SHARED_HW_CFG_LED_MODE_MASK) >>
10129 SHARED_HW_CFG_LED_MODE_SHIFT);
10130
c2c8b03e
EG
10131 bp->link_params.feature_config_flags = 0;
10132 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10133 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10134 bp->link_params.feature_config_flags |=
10135 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10136 else
10137 bp->link_params.feature_config_flags &=
10138 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10139
34f80b04
EG
10140 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10141 bp->common.bc_ver = val;
10142 BNX2X_DEV_INFO("bc_ver %X\n", val);
10143 if (val < BNX2X_BC_VER) {
10144 /* for now only warn
10145 * later we might need to enforce this */
51c1a580
MS
10146 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10147 BNX2X_BC_VER, val);
34f80b04 10148 }
4d295db0 10149 bp->link_params.feature_config_flags |=
a22f0788 10150 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
10151 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10152
a22f0788
YR
10153 bp->link_params.feature_config_flags |=
10154 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10155 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
10156 bp->link_params.feature_config_flags |=
10157 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10158 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
10159 bp->link_params.feature_config_flags |=
10160 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10161 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
10162
10163 bp->link_params.feature_config_flags |=
10164 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10165 FEATURE_CONFIG_MT_SUPPORT : 0;
10166
0e898dd7
BW
10167 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10168 BC_SUPPORTS_PFC_STATS : 0;
85242eea 10169
2e499d3c
BW
10170 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10171 BC_SUPPORTS_FCOE_FEATURES : 0;
10172
9876879f
BW
10173 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10174 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
10175 boot_mode = SHMEM_RD(bp,
10176 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10177 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10178 switch (boot_mode) {
10179 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10180 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10181 break;
10182 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10183 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10184 break;
10185 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10186 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10187 break;
10188 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10189 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10190 break;
10191 }
10192
f9a3ebbe
DK
10193 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
10194 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10195
72ce58c3 10196 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 10197 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
10198
10199 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10200 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10201 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10202 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10203
cdaa7cb8
VZ
10204 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10205 val, val2, val3, val4);
34f80b04
EG
10206}
10207
f2e0899f
DK
10208#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10209#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10210
0329aba1 10211static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
10212{
10213 int pfid = BP_FUNC(bp);
f2e0899f
DK
10214 int igu_sb_id;
10215 u32 val;
6383c0b3 10216 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
10217
10218 bp->igu_base_sb = 0xff;
f2e0899f 10219 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 10220 int vn = BP_VN(bp);
6383c0b3 10221 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
10222 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10223 FP_SB_MAX_E1x;
10224
10225 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10226 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10227
9b341bb1 10228 return 0;
f2e0899f
DK
10229 }
10230
10231 /* IGU in normal mode - read CAM */
10232 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10233 igu_sb_id++) {
10234 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10235 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10236 continue;
10237 fid = IGU_FID(val);
10238 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10239 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10240 continue;
10241 if (IGU_VEC(val) == 0)
10242 /* default status block */
10243 bp->igu_dsb_id = igu_sb_id;
10244 else {
10245 if (bp->igu_base_sb == 0xff)
10246 bp->igu_base_sb = igu_sb_id;
6383c0b3 10247 igu_sb_cnt++;
f2e0899f
DK
10248 }
10249 }
10250 }
619c5cb6 10251
6383c0b3 10252#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10253 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10254 * optional that number of CAM entries will not be equal to the value
10255 * advertised in PCI.
10256 * Driver should use the minimal value of both as the actual status
10257 * block count
619c5cb6 10258 */
185d4c8b 10259 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10260#endif
619c5cb6 10261
9b341bb1 10262 if (igu_sb_cnt == 0) {
f2e0899f 10263 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10264 return -EINVAL;
10265 }
10266
10267 return 0;
f2e0899f
DK
10268}
10269
1dd06ae8 10270static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
a2fbb9ea 10271{
a22f0788
YR
10272 int cfg_size = 0, idx, port = BP_PORT(bp);
10273
10274 /* Aggregation of supported attributes of all external phys */
10275 bp->port.supported[0] = 0;
10276 bp->port.supported[1] = 0;
b7737c9b
YR
10277 switch (bp->link_params.num_phys) {
10278 case 1:
a22f0788
YR
10279 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10280 cfg_size = 1;
10281 break;
b7737c9b 10282 case 2:
a22f0788
YR
10283 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10284 cfg_size = 1;
10285 break;
10286 case 3:
10287 if (bp->link_params.multi_phy_config &
10288 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10289 bp->port.supported[1] =
10290 bp->link_params.phy[EXT_PHY1].supported;
10291 bp->port.supported[0] =
10292 bp->link_params.phy[EXT_PHY2].supported;
10293 } else {
10294 bp->port.supported[0] =
10295 bp->link_params.phy[EXT_PHY1].supported;
10296 bp->port.supported[1] =
10297 bp->link_params.phy[EXT_PHY2].supported;
10298 }
10299 cfg_size = 2;
10300 break;
b7737c9b 10301 }
a2fbb9ea 10302
a22f0788 10303 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10304 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10305 SHMEM_RD(bp,
a22f0788
YR
10306 dev_info.port_hw_config[port].external_phy_config),
10307 SHMEM_RD(bp,
10308 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10309 return;
f85582f8 10310 }
a2fbb9ea 10311
619c5cb6
VZ
10312 if (CHIP_IS_E3(bp))
10313 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10314 else {
10315 switch (switch_cfg) {
10316 case SWITCH_CFG_1G:
10317 bp->port.phy_addr = REG_RD(
10318 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10319 break;
10320 case SWITCH_CFG_10G:
10321 bp->port.phy_addr = REG_RD(
10322 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10323 break;
10324 default:
10325 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10326 bp->port.link_config[0]);
10327 return;
10328 }
a2fbb9ea 10329 }
619c5cb6 10330 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10331 /* mask what we support according to speed_cap_mask per configuration */
10332 for (idx = 0; idx < cfg_size; idx++) {
10333 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10334 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10335 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10336
a22f0788 10337 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10338 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10339 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10340
a22f0788 10341 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10342 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10343 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10344
a22f0788 10345 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10346 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10347 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10348
a22f0788 10349 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10350 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10351 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10352 SUPPORTED_1000baseT_Full);
a2fbb9ea 10353
a22f0788 10354 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10355 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10356 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10357
a22f0788 10358 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10359 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
10360 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10361
10362 }
a2fbb9ea 10363
a22f0788
YR
10364 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10365 bp->port.supported[1]);
a2fbb9ea
ET
10366}
10367
0329aba1 10368static void bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10369{
a22f0788
YR
10370 u32 link_config, idx, cfg_size = 0;
10371 bp->port.advertising[0] = 0;
10372 bp->port.advertising[1] = 0;
10373 switch (bp->link_params.num_phys) {
10374 case 1:
10375 case 2:
10376 cfg_size = 1;
10377 break;
10378 case 3:
10379 cfg_size = 2;
10380 break;
10381 }
10382 for (idx = 0; idx < cfg_size; idx++) {
10383 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10384 link_config = bp->port.link_config[idx];
10385 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10386 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10387 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10388 bp->link_params.req_line_speed[idx] =
10389 SPEED_AUTO_NEG;
10390 bp->port.advertising[idx] |=
10391 bp->port.supported[idx];
10bd1f24
MY
10392 if (bp->link_params.phy[EXT_PHY1].type ==
10393 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10394 bp->port.advertising[idx] |=
10395 (SUPPORTED_100baseT_Half |
10396 SUPPORTED_100baseT_Full);
f85582f8
DK
10397 } else {
10398 /* force 10G, no AN */
a22f0788
YR
10399 bp->link_params.req_line_speed[idx] =
10400 SPEED_10000;
10401 bp->port.advertising[idx] |=
10402 (ADVERTISED_10000baseT_Full |
f85582f8 10403 ADVERTISED_FIBRE);
a22f0788 10404 continue;
f85582f8
DK
10405 }
10406 break;
a2fbb9ea 10407
f85582f8 10408 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10409 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10410 bp->link_params.req_line_speed[idx] =
10411 SPEED_10;
10412 bp->port.advertising[idx] |=
10413 (ADVERTISED_10baseT_Full |
f85582f8
DK
10414 ADVERTISED_TP);
10415 } else {
51c1a580 10416 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10417 link_config,
a22f0788 10418 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10419 return;
10420 }
10421 break;
a2fbb9ea 10422
f85582f8 10423 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10424 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10425 bp->link_params.req_line_speed[idx] =
10426 SPEED_10;
10427 bp->link_params.req_duplex[idx] =
10428 DUPLEX_HALF;
10429 bp->port.advertising[idx] |=
10430 (ADVERTISED_10baseT_Half |
f85582f8
DK
10431 ADVERTISED_TP);
10432 } else {
51c1a580 10433 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10434 link_config,
10435 bp->link_params.speed_cap_mask[idx]);
10436 return;
10437 }
10438 break;
a2fbb9ea 10439
f85582f8
DK
10440 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10441 if (bp->port.supported[idx] &
10442 SUPPORTED_100baseT_Full) {
a22f0788
YR
10443 bp->link_params.req_line_speed[idx] =
10444 SPEED_100;
10445 bp->port.advertising[idx] |=
10446 (ADVERTISED_100baseT_Full |
f85582f8
DK
10447 ADVERTISED_TP);
10448 } else {
51c1a580 10449 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10450 link_config,
10451 bp->link_params.speed_cap_mask[idx]);
10452 return;
10453 }
10454 break;
a2fbb9ea 10455
f85582f8
DK
10456 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10457 if (bp->port.supported[idx] &
10458 SUPPORTED_100baseT_Half) {
10459 bp->link_params.req_line_speed[idx] =
10460 SPEED_100;
10461 bp->link_params.req_duplex[idx] =
10462 DUPLEX_HALF;
a22f0788
YR
10463 bp->port.advertising[idx] |=
10464 (ADVERTISED_100baseT_Half |
f85582f8
DK
10465 ADVERTISED_TP);
10466 } else {
51c1a580 10467 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10468 link_config,
10469 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10470 return;
10471 }
10472 break;
a2fbb9ea 10473
f85582f8 10474 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10475 if (bp->port.supported[idx] &
10476 SUPPORTED_1000baseT_Full) {
10477 bp->link_params.req_line_speed[idx] =
10478 SPEED_1000;
10479 bp->port.advertising[idx] |=
10480 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10481 ADVERTISED_TP);
10482 } else {
51c1a580 10483 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10484 link_config,
10485 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10486 return;
10487 }
10488 break;
a2fbb9ea 10489
f85582f8 10490 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10491 if (bp->port.supported[idx] &
10492 SUPPORTED_2500baseX_Full) {
10493 bp->link_params.req_line_speed[idx] =
10494 SPEED_2500;
10495 bp->port.advertising[idx] |=
10496 (ADVERTISED_2500baseX_Full |
34f80b04 10497 ADVERTISED_TP);
f85582f8 10498 } else {
51c1a580 10499 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10500 link_config,
f85582f8
DK
10501 bp->link_params.speed_cap_mask[idx]);
10502 return;
10503 }
10504 break;
a2fbb9ea 10505
f85582f8 10506 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10507 if (bp->port.supported[idx] &
10508 SUPPORTED_10000baseT_Full) {
10509 bp->link_params.req_line_speed[idx] =
10510 SPEED_10000;
10511 bp->port.advertising[idx] |=
10512 (ADVERTISED_10000baseT_Full |
34f80b04 10513 ADVERTISED_FIBRE);
f85582f8 10514 } else {
51c1a580 10515 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10516 link_config,
f85582f8
DK
10517 bp->link_params.speed_cap_mask[idx]);
10518 return;
10519 }
10520 break;
3c9ada22
YR
10521 case PORT_FEATURE_LINK_SPEED_20G:
10522 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10523
3c9ada22 10524 break;
f85582f8 10525 default:
51c1a580 10526 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10527 link_config);
f85582f8
DK
10528 bp->link_params.req_line_speed[idx] =
10529 SPEED_AUTO_NEG;
10530 bp->port.advertising[idx] =
10531 bp->port.supported[idx];
10532 break;
10533 }
a2fbb9ea 10534
a22f0788 10535 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10536 PORT_FEATURE_FLOW_CONTROL_MASK);
cd1dfce2
YM
10537 if (bp->link_params.req_flow_ctrl[idx] ==
10538 BNX2X_FLOW_CTRL_AUTO) {
10539 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10540 bp->link_params.req_flow_ctrl[idx] =
10541 BNX2X_FLOW_CTRL_NONE;
10542 else
10543 bnx2x_set_requested_fc(bp);
a22f0788 10544 }
a2fbb9ea 10545
51c1a580 10546 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10547 bp->link_params.req_line_speed[idx],
10548 bp->link_params.req_duplex[idx],
10549 bp->link_params.req_flow_ctrl[idx],
10550 bp->port.advertising[idx]);
10551 }
a2fbb9ea
ET
10552}
10553
0329aba1 10554static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
e665bfda 10555{
86564c3f
YM
10556 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10557 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10558 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10559 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
e665bfda
MC
10560}
10561
0329aba1 10562static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10563{
34f80b04 10564 int port = BP_PORT(bp);
589abe3a 10565 u32 config;
c8c60d88 10566 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10567
c18487ee 10568 bp->link_params.bp = bp;
34f80b04 10569 bp->link_params.port = port;
c18487ee 10570
c18487ee 10571 bp->link_params.lane_config =
a2fbb9ea 10572 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10573
a22f0788 10574 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
10575 SHMEM_RD(bp,
10576 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
10577 bp->link_params.speed_cap_mask[1] =
10578 SHMEM_RD(bp,
10579 dev_info.port_hw_config[port].speed_capability_mask2);
10580 bp->port.link_config[0] =
a2fbb9ea
ET
10581 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10582
a22f0788
YR
10583 bp->port.link_config[1] =
10584 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10585
a22f0788
YR
10586 bp->link_params.multi_phy_config =
10587 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10588 /* If the device is capable of WoL, set the default state according
10589 * to the HW
10590 */
4d295db0 10591 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10592 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10593 (config & PORT_FEATURE_WOL_ENABLED));
10594
4ba7699b
YM
10595 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10596 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
10597 bp->flags |= NO_ISCSI_FLAG;
10598 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10599 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
10600 bp->flags |= NO_FCOE_FLAG;
10601
51c1a580 10602 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10603 bp->link_params.lane_config,
a22f0788
YR
10604 bp->link_params.speed_cap_mask[0],
10605 bp->port.link_config[0]);
a2fbb9ea 10606
a22f0788 10607 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10608 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10609 bnx2x_phy_probe(&bp->link_params);
c18487ee 10610 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10611
10612 bnx2x_link_settings_requested(bp);
10613
01cd4528
EG
10614 /*
10615 * If connected directly, work with the internal PHY, otherwise, work
10616 * with the external PHY
10617 */
b7737c9b
YR
10618 ext_phy_config =
10619 SHMEM_RD(bp,
10620 dev_info.port_hw_config[port].external_phy_config);
10621 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10622 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10623 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10624
10625 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10626 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10627 bp->mdio.prtad =
b7737c9b 10628 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10629
c8c60d88
YM
10630 /* Configure link feature according to nvram value */
10631 eee_mode = (((SHMEM_RD(bp, dev_info.
10632 port_feature_config[port].eee_power_mode)) &
10633 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10634 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10635 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10636 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10637 EEE_MODE_ENABLE_LPI |
10638 EEE_MODE_OUTPUT_TIME;
10639 } else {
10640 bp->link_params.eee_mode = 0;
10641 }
0793f83f 10642}
01cd4528 10643
b306f5ed 10644void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10645{
9e62e912 10646 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10647 int port = BP_PORT(bp);
2ba45142 10648 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10649 drv_lic_key[port].max_iscsi_conn);
2ba45142 10650
55c11941
MS
10651 if (!CNIC_SUPPORT(bp)) {
10652 bp->flags |= no_flags;
10653 return;
10654 }
10655
b306f5ed 10656 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10657 bp->cnic_eth_dev.max_iscsi_conn =
10658 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10659 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10660
b306f5ed
DK
10661 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10662 bp->cnic_eth_dev.max_iscsi_conn);
10663
10664 /*
10665 * If maximum allowed number of connections is zero -
10666 * disable the feature.
10667 */
10668 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10669 bp->flags |= no_flags;
55c11941 10670
b306f5ed
DK
10671}
10672
0329aba1 10673static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9e62e912
DK
10674{
10675 /* Port info */
10676 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10677 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10678 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10679 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10680
10681 /* Node info */
10682 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10683 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10684 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10685 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10686}
0329aba1 10687static void bnx2x_get_fcoe_info(struct bnx2x *bp)
b306f5ed
DK
10688{
10689 int port = BP_PORT(bp);
10690 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10691 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10692 drv_lic_key[port].max_fcoe_conn);
10693
55c11941
MS
10694 if (!CNIC_SUPPORT(bp)) {
10695 bp->flags |= NO_FCOE_FLAG;
10696 return;
10697 }
10698
b306f5ed 10699 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10700 bp->cnic_eth_dev.max_fcoe_conn =
10701 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10702 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10703
bf61ee14
VZ
10704 /* Read the WWN: */
10705 if (!IS_MF(bp)) {
10706 /* Port info */
10707 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10708 SHMEM_RD(bp,
2de67439 10709 dev_info.port_hw_config[port].
bf61ee14
VZ
10710 fcoe_wwn_port_name_upper);
10711 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10712 SHMEM_RD(bp,
2de67439 10713 dev_info.port_hw_config[port].
bf61ee14
VZ
10714 fcoe_wwn_port_name_lower);
10715
10716 /* Node info */
10717 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10718 SHMEM_RD(bp,
2de67439 10719 dev_info.port_hw_config[port].
bf61ee14
VZ
10720 fcoe_wwn_node_name_upper);
10721 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10722 SHMEM_RD(bp,
2de67439 10723 dev_info.port_hw_config[port].
bf61ee14
VZ
10724 fcoe_wwn_node_name_lower);
10725 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10726 /*
10727 * Read the WWN info only if the FCoE feature is enabled for
10728 * this function.
10729 */
7b5342d9 10730 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10731 bnx2x_get_ext_wwn_info(bp, func);
10732
382e513a 10733 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 10734 bnx2x_get_ext_wwn_info(bp, func);
382e513a 10735 }
bf61ee14 10736
b306f5ed 10737 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10738
bf61ee14
VZ
10739 /*
10740 * If maximum allowed number of connections is zero -
2ba45142
VZ
10741 * disable the feature.
10742 */
2ba45142
VZ
10743 if (!bp->cnic_eth_dev.max_fcoe_conn)
10744 bp->flags |= NO_FCOE_FLAG;
10745}
b306f5ed 10746
0329aba1 10747static void bnx2x_get_cnic_info(struct bnx2x *bp)
b306f5ed
DK
10748{
10749 /*
10750 * iSCSI may be dynamically disabled but reading
10751 * info here we will decrease memory usage by driver
10752 * if the feature is disabled for good
10753 */
10754 bnx2x_get_iscsi_info(bp);
10755 bnx2x_get_fcoe_info(bp);
10756}
2ba45142 10757
0329aba1 10758static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10759{
10760 u32 val, val2;
10761 int func = BP_ABS_FUNC(bp);
10762 int port = BP_PORT(bp);
2ba45142
VZ
10763 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10764 u8 *fip_mac = bp->fip_mac;
0793f83f 10765
55c11941
MS
10766 if (IS_MF(bp)) {
10767 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10768 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10769 * In non SD mode features configuration comes from struct
10770 * func_ext_config.
2ba45142 10771 */
55c11941 10772 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10773 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10774 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10775 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10776 iscsi_mac_addr_upper);
0793f83f 10777 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10778 iscsi_mac_addr_lower);
2ba45142 10779 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10780 BNX2X_DEV_INFO
10781 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10782 } else {
2ba45142 10783 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10784 }
2ba45142
VZ
10785
10786 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10787 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10788 fcoe_mac_addr_upper);
2ba45142 10789 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10790 fcoe_mac_addr_lower);
2ba45142 10791 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10792 BNX2X_DEV_INFO
10793 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10794 } else {
2ba45142 10795 bp->flags |= NO_FCOE_FLAG;
55c11941 10796 }
a3348722
BW
10797
10798 bp->mf_ext_config = cfg;
10799
9e62e912 10800 } else { /* SD MODE */
55c11941
MS
10801 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10802 /* use primary mac as iscsi mac */
10803 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10804
10805 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10806 BNX2X_DEV_INFO
10807 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10808 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10809 /* use primary mac as fip mac */
10810 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10811 BNX2X_DEV_INFO("SD FCoE MODE\n");
10812 BNX2X_DEV_INFO
10813 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10814 }
0793f83f 10815 }
a3348722 10816
55c11941
MS
10817 if (IS_MF_STORAGE_SD(bp))
10818 /* Zero primary MAC configuration */
10819 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10820
f72839d0 10821 if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
a3348722
BW
10822 /* use FIP MAC as primary MAC */
10823 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10824
0793f83f 10825 } else {
0793f83f 10826 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10827 iscsi_mac_upper);
0793f83f 10828 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10829 iscsi_mac_lower);
2ba45142 10830 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10831
10832 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10833 fcoe_fip_mac_upper);
c03bd39c 10834 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10835 fcoe_fip_mac_lower);
c03bd39c 10836 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10837 }
10838
55c11941 10839 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10840 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10841 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10842 memset(iscsi_mac, 0, ETH_ALEN);
10843 }
10844
55c11941 10845 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10846 if (!is_valid_ether_addr(fip_mac)) {
10847 bp->flags |= NO_FCOE_FLAG;
10848 memset(bp->fip_mac, 0, ETH_ALEN);
10849 }
55c11941
MS
10850}
10851
0329aba1 10852static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
55c11941
MS
10853{
10854 u32 val, val2;
10855 int func = BP_ABS_FUNC(bp);
10856 int port = BP_PORT(bp);
10857
10858 /* Zero primary MAC configuration */
10859 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10860
10861 if (BP_NOMCP(bp)) {
10862 BNX2X_ERROR("warning: random MAC workaround active\n");
10863 eth_hw_addr_random(bp->dev);
10864 } else if (IS_MF(bp)) {
10865 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10866 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10867 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10868 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10869 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10870
10871 if (CNIC_SUPPORT(bp))
10872 bnx2x_get_cnic_mac_hwinfo(bp);
10873 } else {
10874 /* in SF read MACs from port configuration */
10875 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10876 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10877 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10878
10879 if (CNIC_SUPPORT(bp))
10880 bnx2x_get_cnic_mac_hwinfo(bp);
10881 }
10882
10883 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10884
614c76df 10885 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10886 dev_err(&bp->pdev->dev,
51c1a580
MS
10887 "bad Ethernet MAC address configuration: %pM\n"
10888 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10889 bp->dev->dev_addr);
7964211d 10890}
51c1a580 10891
0329aba1 10892static bool bnx2x_get_dropless_info(struct bnx2x *bp)
7964211d
YM
10893{
10894 int tmp;
10895 u32 cfg;
51c1a580 10896
7964211d
YM
10897 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
10898 /* Take function: tmp = func */
10899 tmp = BP_ABS_FUNC(bp);
10900 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
10901 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
10902 } else {
10903 /* Take port: tmp = port */
10904 tmp = BP_PORT(bp);
10905 cfg = SHMEM_RD(bp,
10906 dev_info.port_hw_config[tmp].generic_features);
10907 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
10908 }
10909 return cfg;
34f80b04
EG
10910}
10911
0329aba1 10912static int bnx2x_get_hwinfo(struct bnx2x *bp)
34f80b04 10913{
0793f83f 10914 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 10915 int vn;
0793f83f 10916 u32 val = 0;
34f80b04 10917 int rc = 0;
a2fbb9ea 10918
34f80b04 10919 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 10920
6383c0b3
AE
10921 /*
10922 * initialize IGU parameters
10923 */
f2e0899f
DK
10924 if (CHIP_IS_E1x(bp)) {
10925 bp->common.int_block = INT_BLOCK_HC;
10926
10927 bp->igu_dsb_id = DEF_SB_IGU_ID;
10928 bp->igu_base_sb = 0;
f2e0899f
DK
10929 } else {
10930 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
10931
10932 /* do not allow device reset during IGU info preocessing */
10933 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10934
f2e0899f 10935 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
10936
10937 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10938 int tout = 5000;
10939
10940 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10941
10942 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10943 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10944 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10945
10946 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10947 tout--;
0926d499 10948 usleep_range(1000, 2000);
619c5cb6
VZ
10949 }
10950
10951 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10952 dev_err(&bp->pdev->dev,
10953 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
10954 bnx2x_release_hw_lock(bp,
10955 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
10956 return -EPERM;
10957 }
10958 }
10959
f2e0899f 10960 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 10961 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
10962 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10963 } else
619c5cb6 10964 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 10965
9b341bb1 10966 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 10967 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
10968 if (rc)
10969 return rc;
f2e0899f 10970 }
619c5cb6
VZ
10971
10972 /*
10973 * set base FW non-default (fast path) status block id, this value is
10974 * used to initialize the fw_sb_id saved on the fp/queue structure to
10975 * determine the id used by the FW.
10976 */
10977 if (CHIP_IS_E1x(bp))
10978 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10979 else /*
10980 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10981 * the same queue are indicated on the same IGU SB). So we prefer
10982 * FW and IGU SBs to be the same value.
10983 */
10984 bp->base_fw_ndsb = bp->igu_base_sb;
10985
10986 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10987 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10988 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
10989
10990 /*
10991 * Initialize MF configuration
10992 */
523224a3 10993
fb3bff17
DK
10994 bp->mf_ov = 0;
10995 bp->mf_mode = 0;
3395a033 10996 vn = BP_VN(bp);
0793f83f 10997
f2e0899f 10998 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
10999 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11000 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11001 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11002
f2e0899f
DK
11003 if (SHMEM2_HAS(bp, mf_cfg_addr))
11004 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11005 else
11006 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
11007 offsetof(struct shmem_region, func_mb) +
11008 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
11009 /*
11010 * get mf configuration:
25985edc 11011 * 1. existence of MF configuration
0793f83f
DK
11012 * 2. MAC address must be legal (check only upper bytes)
11013 * for Switch-Independent mode;
11014 * OVLAN must be legal for Switch-Dependent mode
11015 * 3. SF_MODE configures specific MF mode
11016 */
11017 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11018 /* get mf configuration */
11019 val = SHMEM_RD(bp,
11020 dev_info.shared_feature_config.config);
11021 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
11022
11023 switch (val) {
11024 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11025 val = MF_CFG_RD(bp, func_mf_config[func].
11026 mac_upper);
11027 /* check for legal mac (upper bytes)*/
11028 if (val != 0xffff) {
11029 bp->mf_mode = MULTI_FUNCTION_SI;
11030 bp->mf_config[vn] = MF_CFG_RD(bp,
11031 func_mf_config[func].config);
11032 } else
51c1a580 11033 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 11034 break;
a3348722
BW
11035 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11036 if ((!CHIP_IS_E1x(bp)) &&
11037 (MF_CFG_RD(bp, func_mf_config[func].
11038 mac_upper) != 0xffff) &&
11039 (SHMEM2_HAS(bp,
11040 afex_driver_support))) {
11041 bp->mf_mode = MULTI_FUNCTION_AFEX;
11042 bp->mf_config[vn] = MF_CFG_RD(bp,
11043 func_mf_config[func].config);
11044 } else {
11045 BNX2X_DEV_INFO("can not configure afex mode\n");
11046 }
11047 break;
0793f83f
DK
11048 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11049 /* get OV configuration */
11050 val = MF_CFG_RD(bp,
11051 func_mf_config[FUNC_0].e1hov_tag);
11052 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11053
11054 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11055 bp->mf_mode = MULTI_FUNCTION_SD;
11056 bp->mf_config[vn] = MF_CFG_RD(bp,
11057 func_mf_config[func].config);
11058 } else
754a2f52 11059 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
11060 break;
11061 default:
11062 /* Unknown configuration: reset mf_config */
11063 bp->mf_config[vn] = 0;
51c1a580 11064 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
11065 }
11066 }
a2fbb9ea 11067
2691d51d 11068 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 11069 IS_MF(bp) ? "multi" : "single");
2691d51d 11070
0793f83f
DK
11071 switch (bp->mf_mode) {
11072 case MULTI_FUNCTION_SD:
11073 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11074 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 11075 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 11076 bp->mf_ov = val;
619c5cb6
VZ
11077 bp->path_has_ovlan = true;
11078
51c1a580
MS
11079 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11080 func, bp->mf_ov, bp->mf_ov);
2691d51d 11081 } else {
619c5cb6 11082 dev_err(&bp->pdev->dev,
51c1a580
MS
11083 "No valid MF OV for func %d, aborting\n",
11084 func);
619c5cb6 11085 return -EPERM;
34f80b04 11086 }
0793f83f 11087 break;
a3348722
BW
11088 case MULTI_FUNCTION_AFEX:
11089 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11090 break;
0793f83f 11091 case MULTI_FUNCTION_SI:
51c1a580
MS
11092 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11093 func);
0793f83f
DK
11094 break;
11095 default:
11096 if (vn) {
619c5cb6 11097 dev_err(&bp->pdev->dev,
51c1a580
MS
11098 "VN %d is in a single function mode, aborting\n",
11099 vn);
619c5cb6 11100 return -EPERM;
2691d51d 11101 }
0793f83f 11102 break;
34f80b04 11103 }
0793f83f 11104
619c5cb6
VZ
11105 /* check if other port on the path needs ovlan:
11106 * Since MF configuration is shared between ports
11107 * Possible mixed modes are only
11108 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11109 */
11110 if (CHIP_MODE_IS_4_PORT(bp) &&
11111 !bp->path_has_ovlan &&
11112 !IS_MF(bp) &&
11113 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11114 u8 other_port = !BP_PORT(bp);
11115 u8 other_func = BP_PATH(bp) + 2*other_port;
11116 val = MF_CFG_RD(bp,
11117 func_mf_config[other_func].e1hov_tag);
11118 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11119 bp->path_has_ovlan = true;
11120 }
34f80b04 11121 }
a2fbb9ea 11122
f2e0899f
DK
11123 /* adjust igu_sb_cnt to MF for E1x */
11124 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
11125 bp->igu_sb_cnt /= E1HVN_MAX;
11126
619c5cb6
VZ
11127 /* port info */
11128 bnx2x_get_port_hwinfo(bp);
f2e0899f 11129
0793f83f
DK
11130 /* Get MAC addresses */
11131 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 11132
2ba45142 11133 bnx2x_get_cnic_info(bp);
2ba45142 11134
34f80b04
EG
11135 return rc;
11136}
11137
0329aba1 11138static void bnx2x_read_fwinfo(struct bnx2x *bp)
34f24c7f
VZ
11139{
11140 int cnt, i, block_end, rodi;
fcdf95cb 11141 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
11142 char str_id_reg[VENDOR_ID_LEN+1];
11143 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
11144 char *vpd_data;
11145 char *vpd_extended_data = NULL;
34f24c7f
VZ
11146 u8 len;
11147
fcdf95cb 11148 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
11149 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11150
11151 if (cnt < BNX2X_VPD_LEN)
11152 goto out_not_found;
11153
fcdf95cb
BW
11154 /* VPD RO tag should be first tag after identifier string, hence
11155 * we should be able to find it in first BNX2X_VPD_LEN chars
11156 */
11157 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
11158 PCI_VPD_LRDT_RO_DATA);
11159 if (i < 0)
11160 goto out_not_found;
11161
34f24c7f 11162 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 11163 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
11164
11165 i += PCI_VPD_LRDT_TAG_SIZE;
11166
fcdf95cb
BW
11167 if (block_end > BNX2X_VPD_LEN) {
11168 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11169 if (vpd_extended_data == NULL)
11170 goto out_not_found;
11171
11172 /* read rest of vpd image into vpd_extended_data */
11173 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11174 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11175 block_end - BNX2X_VPD_LEN,
11176 vpd_extended_data + BNX2X_VPD_LEN);
11177 if (cnt < (block_end - BNX2X_VPD_LEN))
11178 goto out_not_found;
11179 vpd_data = vpd_extended_data;
11180 } else
11181 vpd_data = vpd_start;
11182
11183 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
11184
11185 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11186 PCI_VPD_RO_KEYWORD_MFR_ID);
11187 if (rodi < 0)
11188 goto out_not_found;
11189
11190 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11191
11192 if (len != VENDOR_ID_LEN)
11193 goto out_not_found;
11194
11195 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11196
11197 /* vendor specific info */
11198 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11199 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11200 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11201 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11202
11203 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11204 PCI_VPD_RO_KEYWORD_VENDOR0);
11205 if (rodi >= 0) {
11206 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11207
11208 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11209
11210 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11211 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11212 bp->fw_ver[len] = ' ';
11213 }
11214 }
fcdf95cb 11215 kfree(vpd_extended_data);
34f24c7f
VZ
11216 return;
11217 }
11218out_not_found:
fcdf95cb 11219 kfree(vpd_extended_data);
34f24c7f
VZ
11220 return;
11221}
11222
0329aba1 11223static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
619c5cb6
VZ
11224{
11225 u32 flags = 0;
11226
11227 if (CHIP_REV_IS_FPGA(bp))
11228 SET_FLAGS(flags, MODE_FPGA);
11229 else if (CHIP_REV_IS_EMUL(bp))
11230 SET_FLAGS(flags, MODE_EMUL);
11231 else
11232 SET_FLAGS(flags, MODE_ASIC);
11233
11234 if (CHIP_MODE_IS_4_PORT(bp))
11235 SET_FLAGS(flags, MODE_PORT4);
11236 else
11237 SET_FLAGS(flags, MODE_PORT2);
11238
11239 if (CHIP_IS_E2(bp))
11240 SET_FLAGS(flags, MODE_E2);
11241 else if (CHIP_IS_E3(bp)) {
11242 SET_FLAGS(flags, MODE_E3);
11243 if (CHIP_REV(bp) == CHIP_REV_Ax)
11244 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11245 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11246 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11247 }
11248
11249 if (IS_MF(bp)) {
11250 SET_FLAGS(flags, MODE_MF);
11251 switch (bp->mf_mode) {
11252 case MULTI_FUNCTION_SD:
11253 SET_FLAGS(flags, MODE_MF_SD);
11254 break;
11255 case MULTI_FUNCTION_SI:
11256 SET_FLAGS(flags, MODE_MF_SI);
11257 break;
a3348722
BW
11258 case MULTI_FUNCTION_AFEX:
11259 SET_FLAGS(flags, MODE_MF_AFEX);
11260 break;
619c5cb6
VZ
11261 }
11262 } else
11263 SET_FLAGS(flags, MODE_SF);
11264
11265#if defined(__LITTLE_ENDIAN)
11266 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11267#else /*(__BIG_ENDIAN)*/
11268 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11269#endif
11270 INIT_MODE_FLAGS(bp) = flags;
11271}
11272
0329aba1 11273static int bnx2x_init_bp(struct bnx2x *bp)
34f80b04 11274{
f2e0899f 11275 int func;
34f80b04
EG
11276 int rc;
11277
34f80b04 11278 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11279 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11280 spin_lock_init(&bp->stats_lock);
55c11941 11281
a2fbb9ea 11282
1cf167f2 11283 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11284 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11285 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
1ab4434c
AE
11286 if (IS_PF(bp)) {
11287 rc = bnx2x_get_hwinfo(bp);
11288 if (rc)
11289 return rc;
11290 } else {
11291 random_ether_addr(bp->dev->dev_addr);
11292 }
34f80b04 11293
619c5cb6
VZ
11294 bnx2x_set_modes_bitmap(bp);
11295
11296 rc = bnx2x_alloc_mem_bp(bp);
11297 if (rc)
11298 return rc;
523224a3 11299
34f24c7f 11300 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11301
11302 func = BP_FUNC(bp);
11303
34f80b04 11304 /* need to reset chip if undi was active */
1ab4434c 11305 if (IS_PF(bp) && !BP_NOMCP(bp)) {
452427b0
YM
11306 /* init fw_seq */
11307 bp->fw_seq =
11308 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11309 DRV_MSG_SEQ_NUMBER_MASK;
11310 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11311
11312 bnx2x_prev_unload(bp);
11313 }
11314
34f80b04
EG
11315
11316 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11317 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11318
11319 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11320 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11321
614c76df 11322 bp->disable_tpa = disable_tpa;
a3348722 11323 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11324
7a9b2557 11325 /* Set TPA flags */
614c76df 11326 if (bp->disable_tpa) {
621b4d66 11327 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11328 bp->dev->features &= ~NETIF_F_LRO;
11329 } else {
621b4d66 11330 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11331 bp->dev->features |= NETIF_F_LRO;
11332 }
11333
a18f5128
EG
11334 if (CHIP_IS_E1(bp))
11335 bp->dropless_fc = 0;
11336 else
7964211d 11337 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11338
8d5726c4 11339 bp->mrrs = mrrs;
7a9b2557 11340
a3348722 11341 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1ab4434c
AE
11342 if (IS_VF(bp))
11343 bp->rx_ring_size = MAX_RX_AVAIL;
34f80b04 11344
7d323bfd 11345 /* make sure that the numbers are in the right granularity */
523224a3
DK
11346 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11347 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11348
fc543637 11349 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11350
11351 init_timer(&bp->timer);
11352 bp->timer.expires = jiffies + bp->current_interval;
11353 bp->timer.data = (unsigned long) bp;
11354 bp->timer.function = bnx2x_timer;
11355
0370cf90
BW
11356 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11357 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11358 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11359 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11360 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11361 bnx2x_dcbx_init_params(bp);
11362 } else {
11363 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11364 }
e4901dde 11365
619c5cb6
VZ
11366 if (CHIP_IS_E1x(bp))
11367 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11368 else
11369 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11370
6383c0b3 11371 /* multiple tx priority */
1ab4434c
AE
11372 if (IS_VF(bp))
11373 bp->max_cos = 1;
11374 else if (CHIP_IS_E1x(bp))
6383c0b3 11375 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
1ab4434c 11376 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
6383c0b3 11377 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
1ab4434c 11378 else if (CHIP_IS_E3B0(bp))
6383c0b3 11379 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
1ab4434c
AE
11380 else
11381 BNX2X_ERR("unknown chip %x revision %x\n",
11382 CHIP_NUM(bp), CHIP_REV(bp));
11383 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
6383c0b3 11384
55c11941
MS
11385 /* We need at least one default status block for slow-path events,
11386 * second status block for the L2 queue, and a third status block for
11387 * CNIC if supproted.
11388 */
11389 if (CNIC_SUPPORT(bp))
11390 bp->min_msix_vec_cnt = 3;
11391 else
11392 bp->min_msix_vec_cnt = 2;
11393 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11394
34f80b04 11395 return rc;
a2fbb9ea
ET
11396}
11397
a2fbb9ea 11398
de0c62db
DK
11399/****************************************************************************
11400* General service functions
11401****************************************************************************/
a2fbb9ea 11402
619c5cb6
VZ
11403/*
11404 * net_device service functions
11405 */
11406
8395be5e
AE
11407static int bnx2x_open_epilog(struct bnx2x *bp)
11408{
11409 /* Enable sriov via delayed work. This must be done via delayed work
11410 * because it causes the probe of the vf devices to be run, which invoke
11411 * register_netdevice which must have rtnl lock taken. As we are holding
11412 * the lock right now, that could only work if the probe would not take
11413 * the lock. However, as the probe of the vf may be called from other
11414 * contexts as well (such as passthrough to vm failes) it can't assume
11415 * the lock is being held for it. Using delayed work here allows the
11416 * probe code to simply take the lock (i.e. wait for it to be released
11417 * if it is being held).
11418 */
11419 smp_mb__before_clear_bit();
11420 set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
11421 smp_mb__after_clear_bit();
11422 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11423
11424 return 0;
11425}
11426
bb2a0f7a 11427/* called with rtnl_lock */
a2fbb9ea
ET
11428static int bnx2x_open(struct net_device *dev)
11429{
11430 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11431 bool global = false;
11432 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11433 bool other_load_status, load_status;
8395be5e 11434 int rc;
a2fbb9ea 11435
1355b704
MY
11436 bp->stats_init = true;
11437
6eccabb3
EG
11438 netif_carrier_off(dev);
11439
a2fbb9ea
ET
11440 bnx2x_set_power_state(bp, PCI_D0);
11441
ad5afc89 11442 /* If parity had happen during the unload, then attentions
c9ee9206
VZ
11443 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11444 * want the first function loaded on the current engine to
11445 * complete the recovery.
ad5afc89 11446 * Parity recovery is only relevant for PF driver.
c9ee9206 11447 */
ad5afc89
AE
11448 if (IS_PF(bp)) {
11449 other_load_status = bnx2x_get_load_status(bp, other_engine);
11450 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11451 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11452 bnx2x_chk_parity_attn(bp, &global, true)) {
11453 do {
11454 /* If there are attentions and they are in a
11455 * global blocks, set the GLOBAL_RESET bit
11456 * regardless whether it will be this function
11457 * that will complete the recovery or not.
11458 */
11459 if (global)
11460 bnx2x_set_reset_global(bp);
72fd0718 11461
ad5afc89
AE
11462 /* Only the first function on the current
11463 * engine should try to recover in open. In case
11464 * of attentions in global blocks only the first
11465 * in the chip should try to recover.
11466 */
11467 if ((!load_status &&
11468 (!global || !other_load_status)) &&
11469 bnx2x_trylock_leader_lock(bp) &&
11470 !bnx2x_leader_reset(bp)) {
11471 netdev_info(bp->dev,
11472 "Recovered in open\n");
11473 break;
11474 }
72fd0718 11475
ad5afc89
AE
11476 /* recovery has failed... */
11477 bnx2x_set_power_state(bp, PCI_D3hot);
11478 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11479
ad5afc89
AE
11480 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11481 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718 11482
ad5afc89
AE
11483 return -EAGAIN;
11484 } while (0);
11485 }
11486 }
72fd0718
VZ
11487
11488 bp->recovery_state = BNX2X_RECOVERY_DONE;
8395be5e
AE
11489 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11490 if (rc)
11491 return rc;
11492 return bnx2x_open_epilog(bp);
a2fbb9ea
ET
11493}
11494
bb2a0f7a 11495/* called with rtnl_lock */
56ad3152 11496static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11497{
a2fbb9ea
ET
11498 struct bnx2x *bp = netdev_priv(dev);
11499
11500 /* Unload the driver, release IRQs */
5d07d868 11501 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206
VZ
11502
11503 /* Power off */
d3dbfee0 11504 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
11505
11506 return 0;
11507}
11508
1191cb83
ED
11509static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11510 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11511{
619c5cb6
VZ
11512 int mc_count = netdev_mc_count(bp->dev);
11513 struct bnx2x_mcast_list_elem *mc_mac =
11514 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11515 struct netdev_hw_addr *ha;
6e30dd4e 11516
619c5cb6
VZ
11517 if (!mc_mac)
11518 return -ENOMEM;
6e30dd4e 11519
619c5cb6 11520 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11521
619c5cb6
VZ
11522 netdev_for_each_mc_addr(ha, bp->dev) {
11523 mc_mac->mac = bnx2x_mc_addr(ha);
11524 list_add_tail(&mc_mac->link, &p->mcast_list);
11525 mc_mac++;
6e30dd4e 11526 }
619c5cb6
VZ
11527
11528 p->mcast_list_len = mc_count;
11529
11530 return 0;
6e30dd4e
VZ
11531}
11532
1191cb83 11533static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11534 struct bnx2x_mcast_ramrod_params *p)
11535{
11536 struct bnx2x_mcast_list_elem *mc_mac =
11537 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11538 link);
11539
11540 WARN_ON(!mc_mac);
11541 kfree(mc_mac);
11542}
11543
11544/**
11545 * bnx2x_set_uc_list - configure a new unicast MACs list.
11546 *
11547 * @bp: driver handle
6e30dd4e 11548 *
619c5cb6 11549 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11550 */
1191cb83 11551static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11552{
619c5cb6 11553 int rc;
6e30dd4e 11554 struct net_device *dev = bp->dev;
6e30dd4e 11555 struct netdev_hw_addr *ha;
15192a8c 11556 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11557 unsigned long ramrod_flags = 0;
6e30dd4e 11558
619c5cb6
VZ
11559 /* First schedule a cleanup up of old configuration */
11560 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11561 if (rc < 0) {
11562 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11563 return rc;
11564 }
6e30dd4e
VZ
11565
11566 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11567 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11568 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11569 if (rc == -EEXIST) {
11570 DP(BNX2X_MSG_SP,
11571 "Failed to schedule ADD operations: %d\n", rc);
11572 /* do not treat adding same MAC as error */
11573 rc = 0;
11574
11575 } else if (rc < 0) {
11576
619c5cb6
VZ
11577 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11578 rc);
11579 return rc;
6e30dd4e
VZ
11580 }
11581 }
11582
619c5cb6
VZ
11583 /* Execute the pending commands */
11584 __set_bit(RAMROD_CONT, &ramrod_flags);
11585 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11586 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11587}
11588
1191cb83 11589static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11590{
619c5cb6 11591 struct net_device *dev = bp->dev;
3b603066 11592 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11593 int rc = 0;
6e30dd4e 11594
619c5cb6 11595 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11596
619c5cb6
VZ
11597 /* first, clear all configured multicast MACs */
11598 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11599 if (rc < 0) {
51c1a580 11600 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11601 return rc;
11602 }
6e30dd4e 11603
619c5cb6
VZ
11604 /* then, configure a new MACs list */
11605 if (netdev_mc_count(dev)) {
11606 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11607 if (rc) {
51c1a580
MS
11608 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11609 rc);
619c5cb6
VZ
11610 return rc;
11611 }
6e30dd4e 11612
619c5cb6
VZ
11613 /* Now add the new MACs */
11614 rc = bnx2x_config_mcast(bp, &rparam,
11615 BNX2X_MCAST_CMD_ADD);
11616 if (rc < 0)
51c1a580
MS
11617 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11618 rc);
6e30dd4e 11619
619c5cb6
VZ
11620 bnx2x_free_mcast_macs_list(&rparam);
11621 }
6e30dd4e 11622
619c5cb6 11623 return rc;
6e30dd4e
VZ
11624}
11625
619c5cb6 11626/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11627void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11628{
11629 struct bnx2x *bp = netdev_priv(dev);
11630 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11631
11632 if (bp->state != BNX2X_STATE_OPEN) {
11633 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11634 return;
11635 }
11636
619c5cb6 11637 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11638
11639 if (dev->flags & IFF_PROMISC)
11640 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11641 else if ((dev->flags & IFF_ALLMULTI) ||
11642 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11643 CHIP_IS_E1(bp)))
34f80b04 11644 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e 11645 else {
381ac16b
AE
11646 if (IS_PF(bp)) {
11647 /* some multicasts */
11648 if (bnx2x_set_mc_list(bp) < 0)
11649 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11650
381ac16b
AE
11651 if (bnx2x_set_uc_list(bp) < 0)
11652 rx_mode = BNX2X_RX_MODE_PROMISC;
11653 } else {
11654 /* configuring mcast to a vf involves sleeping (when we
11655 * wait for the pf's response). Since this function is
11656 * called from non sleepable context we must schedule
11657 * a work item for this purpose
11658 */
11659 smp_mb__before_clear_bit();
11660 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
11661 &bp->sp_rtnl_state);
11662 smp_mb__after_clear_bit();
11663 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11664 }
34f80b04
EG
11665 }
11666
11667 bp->rx_mode = rx_mode;
614c76df
DK
11668 /* handle ISCSI SD mode */
11669 if (IS_MF_ISCSI_SD(bp))
11670 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11671
11672 /* Schedule the rx_mode command */
11673 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11674 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11675 return;
11676 }
11677
381ac16b
AE
11678 if (IS_PF(bp)) {
11679 bnx2x_set_storm_rx_mode(bp);
11680 } else {
11681 /* configuring rx mode to storms in a vf involves sleeping (when
11682 * we wait for the pf's response). Since this function is
11683 * called from non sleepable context we must schedule
11684 * a work item for this purpose
11685 */
11686 smp_mb__before_clear_bit();
11687 set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
11688 &bp->sp_rtnl_state);
11689 smp_mb__after_clear_bit();
11690 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11691 }
34f80b04
EG
11692}
11693
c18487ee 11694/* called with rtnl_lock */
01cd4528
EG
11695static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11696 int devad, u16 addr)
a2fbb9ea 11697{
01cd4528
EG
11698 struct bnx2x *bp = netdev_priv(netdev);
11699 u16 value;
11700 int rc;
a2fbb9ea 11701
01cd4528
EG
11702 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11703 prtad, devad, addr);
a2fbb9ea 11704
01cd4528
EG
11705 /* The HW expects different devad if CL22 is used */
11706 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11707
01cd4528 11708 bnx2x_acquire_phy_lock(bp);
e10bc84d 11709 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11710 bnx2x_release_phy_lock(bp);
11711 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11712
01cd4528
EG
11713 if (!rc)
11714 rc = value;
11715 return rc;
11716}
a2fbb9ea 11717
01cd4528
EG
11718/* called with rtnl_lock */
11719static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11720 u16 addr, u16 value)
11721{
11722 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11723 int rc;
11724
51c1a580
MS
11725 DP(NETIF_MSG_LINK,
11726 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11727 prtad, devad, addr, value);
01cd4528 11728
01cd4528
EG
11729 /* The HW expects different devad if CL22 is used */
11730 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11731
01cd4528 11732 bnx2x_acquire_phy_lock(bp);
e10bc84d 11733 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11734 bnx2x_release_phy_lock(bp);
11735 return rc;
11736}
c18487ee 11737
01cd4528
EG
11738/* called with rtnl_lock */
11739static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11740{
11741 struct bnx2x *bp = netdev_priv(dev);
11742 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11743
01cd4528
EG
11744 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11745 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11746
01cd4528
EG
11747 if (!netif_running(dev))
11748 return -EAGAIN;
11749
11750 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11751}
11752
257ddbda 11753#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11754static void poll_bnx2x(struct net_device *dev)
11755{
11756 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11757 int i;
a2fbb9ea 11758
14a15d61
MS
11759 for_each_eth_queue(bp, i) {
11760 struct bnx2x_fastpath *fp = &bp->fp[i];
11761 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11762 }
a2fbb9ea
ET
11763}
11764#endif
11765
614c76df
DK
11766static int bnx2x_validate_addr(struct net_device *dev)
11767{
11768 struct bnx2x *bp = netdev_priv(dev);
11769
51c1a580
MS
11770 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11771 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11772 return -EADDRNOTAVAIL;
51c1a580 11773 }
614c76df
DK
11774 return 0;
11775}
11776
c64213cd
SH
11777static const struct net_device_ops bnx2x_netdev_ops = {
11778 .ndo_open = bnx2x_open,
11779 .ndo_stop = bnx2x_close,
11780 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11781 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11782 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11783 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11784 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11785 .ndo_do_ioctl = bnx2x_ioctl,
11786 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11787 .ndo_fix_features = bnx2x_fix_features,
11788 .ndo_set_features = bnx2x_set_features,
c64213cd 11789 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11790#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11791 .ndo_poll_controller = poll_bnx2x,
11792#endif
6383c0b3 11793 .ndo_setup_tc = bnx2x_setup_tc,
6411280a 11794#ifdef CONFIG_BNX2X_SRIOV
abc5a021 11795 .ndo_set_vf_mac = bnx2x_set_vf_mac,
6411280a 11796#endif
55c11941 11797#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11798 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11799#endif
c64213cd
SH
11800};
11801
1191cb83 11802static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11803{
11804 struct device *dev = &bp->pdev->dev;
11805
11806 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11807 bp->flags |= USING_DAC_FLAG;
11808 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11809 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11810 return -EIO;
11811 }
11812 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11813 dev_err(dev, "System does not support DMA, aborting\n");
11814 return -EIO;
11815 }
11816
11817 return 0;
11818}
11819
1ab4434c
AE
11820static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
11821 struct net_device *dev, unsigned long board_type)
a2fbb9ea 11822{
a2fbb9ea 11823 int rc;
c22610d0 11824 u32 pci_cfg_dword;
65087cfe
AE
11825 bool chip_is_e1x = (board_type == BCM57710 ||
11826 board_type == BCM57711 ||
11827 board_type == BCM57711E);
a2fbb9ea
ET
11828
11829 SET_NETDEV_DEV(dev, &pdev->dev);
a2fbb9ea 11830
34f80b04
EG
11831 bp->dev = dev;
11832 bp->pdev = pdev;
a2fbb9ea
ET
11833
11834 rc = pci_enable_device(pdev);
11835 if (rc) {
cdaa7cb8
VZ
11836 dev_err(&bp->pdev->dev,
11837 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11838 goto err_out;
11839 }
11840
11841 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11842 dev_err(&bp->pdev->dev,
11843 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11844 rc = -ENODEV;
11845 goto err_out_disable;
11846 }
11847
1ab4434c
AE
11848 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11849 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
a2fbb9ea
ET
11850 rc = -ENODEV;
11851 goto err_out_disable;
11852 }
11853
092a5fc9
YR
11854 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
11855 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
11856 PCICFG_REVESION_ID_ERROR_VAL) {
11857 pr_err("PCI device error, probably due to fan failure, aborting\n");
11858 rc = -ENODEV;
11859 goto err_out_disable;
11860 }
11861
34f80b04
EG
11862 if (atomic_read(&pdev->enable_cnt) == 1) {
11863 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11864 if (rc) {
cdaa7cb8
VZ
11865 dev_err(&bp->pdev->dev,
11866 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11867 goto err_out_disable;
11868 }
a2fbb9ea 11869
34f80b04
EG
11870 pci_set_master(pdev);
11871 pci_save_state(pdev);
11872 }
a2fbb9ea 11873
1ab4434c
AE
11874 if (IS_PF(bp)) {
11875 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11876 if (bp->pm_cap == 0) {
11877 dev_err(&bp->pdev->dev,
11878 "Cannot find power management capability, aborting\n");
11879 rc = -EIO;
11880 goto err_out_release;
11881 }
a2fbb9ea
ET
11882 }
11883
77c98e6a 11884 if (!pci_is_pcie(pdev)) {
51c1a580 11885 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11886 rc = -EIO;
11887 goto err_out_release;
11888 }
11889
619c5cb6
VZ
11890 rc = bnx2x_set_coherency_mask(bp);
11891 if (rc)
a2fbb9ea 11892 goto err_out_release;
a2fbb9ea 11893
34f80b04
EG
11894 dev->mem_start = pci_resource_start(pdev, 0);
11895 dev->base_addr = dev->mem_start;
11896 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11897
11898 dev->irq = pdev->irq;
11899
275f165f 11900 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11901 if (!bp->regview) {
cdaa7cb8
VZ
11902 dev_err(&bp->pdev->dev,
11903 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11904 rc = -ENOMEM;
11905 goto err_out_release;
11906 }
11907
c22610d0
AE
11908 /* In E1/E1H use pci device function given by kernel.
11909 * In E2/E3 read physical function from ME register since these chips
11910 * support Physical Device Assignment where kernel BDF maybe arbitrary
11911 * (depending on hypervisor).
11912 */
2de67439 11913 if (chip_is_e1x) {
c22610d0 11914 bp->pf_num = PCI_FUNC(pdev->devfn);
2de67439
YM
11915 } else {
11916 /* chip is E2/3*/
c22610d0
AE
11917 pci_read_config_dword(bp->pdev,
11918 PCICFG_ME_REGISTER, &pci_cfg_dword);
11919 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
2de67439 11920 ME_REG_ABS_PF_NUM_SHIFT);
c22610d0 11921 }
51c1a580 11922 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 11923
a2fbb9ea
ET
11924 bnx2x_set_power_state(bp, PCI_D0);
11925
34f80b04
EG
11926 /* clean indirect addresses */
11927 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11928 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
11929 /*
11930 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
11931 * is not used by the driver.
11932 */
1ab4434c
AE
11933 if (IS_PF(bp)) {
11934 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11935 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11936 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11937 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
11938
11939 if (chip_is_e1x) {
11940 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11941 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11942 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11943 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11944 }
a5c53dbc 11945
1ab4434c
AE
11946 /* Enable internal target-read (in case we are probed after PF
11947 * FLR). Must be done prior to any BAR read access. Only for
11948 * 57712 and up
11949 */
11950 if (!chip_is_e1x)
11951 REG_WR(bp,
11952 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
a5c53dbc 11953 }
a2fbb9ea 11954
34f80b04 11955 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 11956
c64213cd 11957 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 11958 bnx2x_set_ethtool_ops(dev);
5316bc0b 11959
01789349
JP
11960 dev->priv_flags |= IFF_UNICAST_FLT;
11961
66371c44 11962 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
11963 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11964 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11965 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
11966
11967 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11968 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11969
11970 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 11971 if (bp->flags & USING_DAC_FLAG)
66371c44 11972 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 11973
538dd2e3
MB
11974 /* Add Loopback capability to the device */
11975 dev->hw_features |= NETIF_F_LOOPBACK;
11976
98507672 11977#ifdef BCM_DCBNL
785b9b1a
SR
11978 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11979#endif
11980
01cd4528
EG
11981 /* get_port_hwinfo() will set prtad and mmds properly */
11982 bp->mdio.prtad = MDIO_PRTAD_NONE;
11983 bp->mdio.mmds = 0;
11984 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11985 bp->mdio.dev = dev;
11986 bp->mdio.mdio_read = bnx2x_mdio_read;
11987 bp->mdio.mdio_write = bnx2x_mdio_write;
11988
a2fbb9ea
ET
11989 return 0;
11990
a2fbb9ea 11991err_out_release:
34f80b04
EG
11992 if (atomic_read(&pdev->enable_cnt) == 1)
11993 pci_release_regions(pdev);
a2fbb9ea
ET
11994
11995err_out_disable:
11996 pci_disable_device(pdev);
11997 pci_set_drvdata(pdev, NULL);
11998
11999err_out:
12000 return rc;
12001}
12002
1dd06ae8 12003static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
25047950 12004{
1ab4434c 12005 u32 val = 0;
25047950 12006
1ab4434c 12007 pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
37f9ce62 12008 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 12009
37f9ce62
EG
12010 /* return value of 1=2.5GHz 2=5GHz */
12011 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 12012}
37f9ce62 12013
6891dd25 12014static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 12015{
37f9ce62 12016 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
12017 struct bnx2x_fw_file_hdr *fw_hdr;
12018 struct bnx2x_fw_file_section *sections;
94a78b79 12019 u32 offset, len, num_ops;
86564c3f 12020 __be16 *ops_offsets;
94a78b79 12021 int i;
37f9ce62 12022 const u8 *fw_ver;
94a78b79 12023
51c1a580
MS
12024 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12025 BNX2X_ERR("Wrong FW size\n");
94a78b79 12026 return -EINVAL;
51c1a580 12027 }
94a78b79
VZ
12028
12029 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12030 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12031
12032 /* Make sure none of the offsets and sizes make us read beyond
12033 * the end of the firmware data */
12034 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12035 offset = be32_to_cpu(sections[i].offset);
12036 len = be32_to_cpu(sections[i].len);
12037 if (offset + len > firmware->size) {
51c1a580 12038 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
12039 return -EINVAL;
12040 }
12041 }
12042
12043 /* Likewise for the init_ops offsets */
12044 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
86564c3f 12045 ops_offsets = (__force __be16 *)(firmware->data + offset);
94a78b79
VZ
12046 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12047
12048 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12049 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 12050 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
12051 return -EINVAL;
12052 }
12053 }
12054
12055 /* Check FW version */
12056 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12057 fw_ver = firmware->data + offset;
12058 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12059 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12060 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12061 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
12062 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12063 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12064 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
12065 BCM_5710_FW_MINOR_VERSION,
12066 BCM_5710_FW_REVISION_VERSION,
12067 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 12068 return -EINVAL;
94a78b79
VZ
12069 }
12070
12071 return 0;
12072}
12073
1191cb83 12074static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12075{
ab6ad5a4
EG
12076 const __be32 *source = (const __be32 *)_source;
12077 u32 *target = (u32 *)_target;
94a78b79 12078 u32 i;
94a78b79
VZ
12079
12080 for (i = 0; i < n/4; i++)
12081 target[i] = be32_to_cpu(source[i]);
12082}
12083
12084/*
12085 Ops array is stored in the following format:
12086 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12087 */
1191cb83 12088static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 12089{
ab6ad5a4
EG
12090 const __be32 *source = (const __be32 *)_source;
12091 struct raw_op *target = (struct raw_op *)_target;
94a78b79 12092 u32 i, j, tmp;
94a78b79 12093
ab6ad5a4 12094 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
12095 tmp = be32_to_cpu(source[j]);
12096 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
12097 target[i].offset = tmp & 0xffffff;
12098 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
12099 }
12100}
ab6ad5a4 12101
1aa8b471 12102/* IRO array is stored in the following format:
523224a3
DK
12103 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12104 */
1191cb83 12105static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
12106{
12107 const __be32 *source = (const __be32 *)_source;
12108 struct iro *target = (struct iro *)_target;
12109 u32 i, j, tmp;
12110
12111 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12112 target[i].base = be32_to_cpu(source[j]);
12113 j++;
12114 tmp = be32_to_cpu(source[j]);
12115 target[i].m1 = (tmp >> 16) & 0xffff;
12116 target[i].m2 = tmp & 0xffff;
12117 j++;
12118 tmp = be32_to_cpu(source[j]);
12119 target[i].m3 = (tmp >> 16) & 0xffff;
12120 target[i].size = tmp & 0xffff;
12121 j++;
12122 }
12123}
12124
1191cb83 12125static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12126{
ab6ad5a4
EG
12127 const __be16 *source = (const __be16 *)_source;
12128 u16 *target = (u16 *)_target;
94a78b79 12129 u32 i;
94a78b79
VZ
12130
12131 for (i = 0; i < n/2; i++)
12132 target[i] = be16_to_cpu(source[i]);
12133}
12134
7995c64e
JP
12135#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12136do { \
12137 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12138 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 12139 if (!bp->arr) \
7995c64e 12140 goto lbl; \
7995c64e
JP
12141 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12142 (u8 *)bp->arr, len); \
12143} while (0)
94a78b79 12144
3b603066 12145static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 12146{
c0ea452e 12147 const char *fw_file_name;
94a78b79 12148 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 12149 int rc;
94a78b79 12150
c0ea452e
MS
12151 if (bp->firmware)
12152 return 0;
94a78b79 12153
c0ea452e
MS
12154 if (CHIP_IS_E1(bp))
12155 fw_file_name = FW_FILE_NAME_E1;
12156 else if (CHIP_IS_E1H(bp))
12157 fw_file_name = FW_FILE_NAME_E1H;
12158 else if (!CHIP_IS_E1x(bp))
12159 fw_file_name = FW_FILE_NAME_E2;
12160 else {
12161 BNX2X_ERR("Unsupported chip revision\n");
12162 return -EINVAL;
12163 }
12164 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 12165
c0ea452e
MS
12166 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12167 if (rc) {
12168 BNX2X_ERR("Can't load firmware file %s\n",
12169 fw_file_name);
12170 goto request_firmware_exit;
12171 }
eb2afd4a 12172
c0ea452e
MS
12173 rc = bnx2x_check_firmware(bp);
12174 if (rc) {
12175 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12176 goto request_firmware_exit;
94a78b79
VZ
12177 }
12178
12179 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12180
12181 /* Initialize the pointers to the init arrays */
12182 /* Blob */
12183 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12184
12185 /* Opcodes */
12186 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12187
12188 /* Offsets */
ab6ad5a4
EG
12189 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12190 be16_to_cpu_n);
94a78b79
VZ
12191
12192 /* STORMs firmware */
573f2035
EG
12193 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12194 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12195 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12196 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12197 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12198 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12199 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12200 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12201 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12202 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12203 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12204 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12205 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12206 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12207 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12208 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
12209 /* IRO */
12210 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
12211
12212 return 0;
ab6ad5a4 12213
523224a3
DK
12214iro_alloc_err:
12215 kfree(bp->init_ops_offsets);
94a78b79
VZ
12216init_offsets_alloc_err:
12217 kfree(bp->init_ops);
12218init_ops_alloc_err:
12219 kfree(bp->init_data);
12220request_firmware_exit:
12221 release_firmware(bp->firmware);
127d0a19 12222 bp->firmware = NULL;
94a78b79
VZ
12223
12224 return rc;
12225}
12226
619c5cb6
VZ
12227static void bnx2x_release_firmware(struct bnx2x *bp)
12228{
12229 kfree(bp->init_ops_offsets);
12230 kfree(bp->init_ops);
12231 kfree(bp->init_data);
12232 release_firmware(bp->firmware);
eb2afd4a 12233 bp->firmware = NULL;
619c5cb6
VZ
12234}
12235
12236
12237static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12238 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12239 .init_hw_cmn = bnx2x_init_hw_common,
12240 .init_hw_port = bnx2x_init_hw_port,
12241 .init_hw_func = bnx2x_init_hw_func,
12242
12243 .reset_hw_cmn = bnx2x_reset_common,
12244 .reset_hw_port = bnx2x_reset_port,
12245 .reset_hw_func = bnx2x_reset_func,
12246
12247 .gunzip_init = bnx2x_gunzip_init,
12248 .gunzip_end = bnx2x_gunzip_end,
12249
12250 .init_fw = bnx2x_init_firmware,
12251 .release_fw = bnx2x_release_firmware,
12252};
12253
12254void bnx2x__init_func_obj(struct bnx2x *bp)
12255{
12256 /* Prepare DMAE related driver resources */
12257 bnx2x_setup_dmae(bp);
12258
12259 bnx2x_init_func_obj(bp, &bp->func_obj,
12260 bnx2x_sp(bp, func_rdata),
12261 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
12262 bnx2x_sp(bp, func_afex_rdata),
12263 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
12264 &bnx2x_func_sp_drv);
12265}
12266
12267/* must be called after sriov-enable */
1191cb83 12268static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 12269{
37ae41a9 12270 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 12271
290ca2bb
AE
12272 if (IS_SRIOV(bp))
12273 cid_count += BNX2X_VF_CIDS;
12274
55c11941
MS
12275 if (CNIC_SUPPORT(bp))
12276 cid_count += CNIC_CID_MAX;
290ca2bb 12277
523224a3
DK
12278 return roundup(cid_count, QM_CID_ROUND);
12279}
f85582f8 12280
619c5cb6 12281/**
6383c0b3 12282 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
12283 *
12284 * @dev: pci device
12285 *
12286 */
55c11941 12287static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
1ab4434c 12288 int cnic_cnt, bool is_vf)
619c5cb6 12289{
1ab4434c
AE
12290 int pos, index;
12291 u16 control = 0;
619c5cb6
VZ
12292
12293 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
12294
12295 /*
12296 * If MSI-X is not supported - return number of SBs needed to support
12297 * one fast path queue: one FP queue + SB for CNIC
12298 */
1ab4434c
AE
12299 if (!pos) {
12300 dev_info(&pdev->dev, "no msix capability found\n");
55c11941 12301 return 1 + cnic_cnt;
1ab4434c
AE
12302 }
12303 dev_info(&pdev->dev, "msix capability found\n");
619c5cb6 12304
6383c0b3
AE
12305 /*
12306 * The value in the PCI configuration space is the index of the last
12307 * entry, namely one less than the actual size of the table, which is
12308 * exactly what we want to return from this function: number of all SBs
12309 * without the default SB.
1ab4434c 12310 * For VFs there is no default SB, then we return (index+1).
6383c0b3 12311 */
619c5cb6 12312 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
619c5cb6 12313
1ab4434c 12314 index = control & PCI_MSIX_FLAGS_QSIZE;
4bd9b0ff 12315
1ab4434c
AE
12316 return is_vf ? index + 1 : index;
12317}
523224a3 12318
1ab4434c
AE
12319static int set_max_cos_est(int chip_id)
12320{
12321 switch (chip_id) {
f2e0899f
DK
12322 case BCM57710:
12323 case BCM57711:
12324 case BCM57711E:
1ab4434c 12325 return BNX2X_MULTI_TX_COS_E1X;
f2e0899f 12326 case BCM57712:
619c5cb6 12327 case BCM57712_MF:
1ab4434c
AE
12328 case BCM57712_VF:
12329 return BNX2X_MULTI_TX_COS_E2_E3A0;
619c5cb6
VZ
12330 case BCM57800:
12331 case BCM57800_MF:
1ab4434c 12332 case BCM57800_VF:
619c5cb6
VZ
12333 case BCM57810:
12334 case BCM57810_MF:
c3def943
YM
12335 case BCM57840_4_10:
12336 case BCM57840_2_20:
1ab4434c 12337 case BCM57840_O:
c3def943 12338 case BCM57840_MFO:
1ab4434c 12339 case BCM57810_VF:
619c5cb6 12340 case BCM57840_MF:
1ab4434c 12341 case BCM57840_VF:
7e8e02df
BW
12342 case BCM57811:
12343 case BCM57811_MF:
1ab4434c
AE
12344 case BCM57811_VF:
12345 return BNX2X_MULTI_TX_COS_E3B0;
12346 return 1;
f2e0899f 12347 default:
1ab4434c 12348 pr_err("Unknown board_type (%d), aborting\n", chip_id);
870634b0 12349 return -ENODEV;
f2e0899f 12350 }
1ab4434c 12351}
f2e0899f 12352
1ab4434c
AE
12353static int set_is_vf(int chip_id)
12354{
12355 switch (chip_id) {
12356 case BCM57712_VF:
12357 case BCM57800_VF:
12358 case BCM57810_VF:
12359 case BCM57840_VF:
12360 case BCM57811_VF:
12361 return true;
12362 default:
12363 return false;
12364 }
12365}
6383c0b3 12366
1ab4434c
AE
12367struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12368
12369static int bnx2x_init_one(struct pci_dev *pdev,
12370 const struct pci_device_id *ent)
12371{
12372 struct net_device *dev = NULL;
12373 struct bnx2x *bp;
12374 int pcie_width, pcie_speed;
12375 int rc, max_non_def_sbs;
12376 int rx_count, tx_count, rss_count, doorbell_size;
12377 int max_cos_est;
12378 bool is_vf;
12379 int cnic_cnt;
12380
12381 /* An estimated maximum supported CoS number according to the chip
12382 * version.
12383 * We will try to roughly estimate the maximum number of CoSes this chip
12384 * may support in order to minimize the memory allocated for Tx
12385 * netdev_queue's. This number will be accurately calculated during the
12386 * initialization of bp->max_cos based on the chip versions AND chip
12387 * revision in the bnx2x_init_bp().
12388 */
12389 max_cos_est = set_max_cos_est(ent->driver_data);
12390 if (max_cos_est < 0)
12391 return max_cos_est;
12392 is_vf = set_is_vf(ent->driver_data);
12393 cnic_cnt = is_vf ? 0 : 1;
12394
12395 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
6383c0b3
AE
12396
12397 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
1ab4434c
AE
12398 rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
12399
12400 if (rss_count < 1)
12401 return -EINVAL;
6383c0b3
AE
12402
12403 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12404 rx_count = rss_count + cnic_cnt;
6383c0b3 12405
1ab4434c 12406 /* Maximum number of netdev Tx queues:
37ae41a9 12407 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12408 */
55c11941 12409 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12410
a2fbb9ea 12411 /* dev zeroed in init_etherdev */
6383c0b3 12412 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12413 if (!dev)
a2fbb9ea
ET
12414 return -ENOMEM;
12415
a2fbb9ea 12416 bp = netdev_priv(dev);
a2fbb9ea 12417
1ab4434c
AE
12418 bp->flags = 0;
12419 if (is_vf)
12420 bp->flags |= IS_VF_FLAG;
12421
6383c0b3 12422 bp->igu_sb_cnt = max_non_def_sbs;
1ab4434c 12423 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
6383c0b3 12424 bp->msg_enable = debug;
55c11941 12425 bp->cnic_support = cnic_cnt;
4bd9b0ff 12426 bp->cnic_probe = bnx2x_cnic_probe;
55c11941 12427
6383c0b3 12428 pci_set_drvdata(pdev, dev);
523224a3 12429
1ab4434c 12430 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
a2fbb9ea
ET
12431 if (rc < 0) {
12432 free_netdev(dev);
12433 return rc;
12434 }
12435
1ab4434c
AE
12436 BNX2X_DEV_INFO("This is a %s function\n",
12437 IS_PF(bp) ? "physical" : "virtual");
55c11941 12438 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
1ab4434c 12439 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
60aa0509 12440 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
2de67439 12441 tx_count, rx_count);
60aa0509 12442
34f80b04 12443 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12444 if (rc)
12445 goto init_one_exit;
12446
1ab4434c
AE
12447 /* Map doorbells here as we need the real value of bp->max_cos which
12448 * is initialized in bnx2x_init_bp() to determine the number of
12449 * l2 connections.
6383c0b3 12450 */
1ab4434c 12451 if (IS_VF(bp)) {
6411280a
AE
12452 bnx2x_vf_map_doorbells(bp);
12453 rc = bnx2x_vf_pci_alloc(bp);
12454 if (rc)
12455 goto init_one_exit;
1ab4434c
AE
12456 } else {
12457 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12458 if (doorbell_size > pci_resource_len(pdev, 2)) {
12459 dev_err(&bp->pdev->dev,
12460 "Cannot map doorbells, bar size too small, aborting\n");
12461 rc = -ENOMEM;
12462 goto init_one_exit;
12463 }
12464 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12465 doorbell_size);
37ae41a9 12466 }
6383c0b3
AE
12467 if (!bp->doorbells) {
12468 dev_err(&bp->pdev->dev,
12469 "Cannot map doorbell space, aborting\n");
12470 rc = -ENOMEM;
12471 goto init_one_exit;
12472 }
12473
be1f1ffa
AE
12474 if (IS_VF(bp)) {
12475 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12476 if (rc)
12477 goto init_one_exit;
12478 }
12479
290ca2bb
AE
12480 /* Enable SRIOV if capability found in configuration space.
12481 * Once the generic SR-IOV framework makes it in from the
12482 * pci tree this will be revised, to allow dynamic control
12483 * over the number of VFs. Right now, change the num of vfs
12484 * param below to enable SR-IOV.
12485 */
12486 rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
12487 if (rc)
12488 goto init_one_exit;
12489
523224a3 12490 /* calc qm_cid_count */
6383c0b3 12491 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
1ab4434c 12492 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
523224a3 12493
55c11941 12494 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12495 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12496 bp->flags |= NO_FCOE_FLAG;
12497
477864dd
DK
12498 /* disable FCOE for 57840 device, until FW supports it */
12499 switch (ent->driver_data) {
12500 case BCM57840_O:
12501 case BCM57840_4_10:
12502 case BCM57840_2_20:
12503 case BCM57840_MFO:
12504 case BCM57840_MF:
12505 bp->flags |= NO_FCOE_FLAG;
12506 }
0e8d2ec5
MS
12507
12508 /* Set bp->num_queues for MSI-X mode*/
12509 bnx2x_set_num_queues(bp);
12510
25985edc 12511 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12512 * needed.
d6214d7a 12513 */
1ab4434c
AE
12514 rc = bnx2x_set_int_mode(bp);
12515 if (rc) {
12516 dev_err(&pdev->dev, "Cannot set interrupts\n");
12517 goto init_one_exit;
12518 }
04c46736 12519 BNX2X_DEV_INFO("set interrupts successfully\n");
d6214d7a 12520
1ab4434c 12521 /* register the net device */
b340007f
VZ
12522 rc = register_netdev(dev);
12523 if (rc) {
12524 dev_err(&pdev->dev, "Cannot register net device\n");
12525 goto init_one_exit;
12526 }
1ab4434c 12527 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
b340007f 12528
55c11941 12529
ec6ba945
VZ
12530 if (!NO_FCOE(bp)) {
12531 /* Add storage MAC address */
12532 rtnl_lock();
12533 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12534 rtnl_unlock();
12535 }
ec6ba945 12536
37f9ce62 12537 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
1ab4434c
AE
12538 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12539 pcie_width, pcie_speed);
d6214d7a 12540
51c1a580
MS
12541 BNX2X_DEV_INFO(
12542 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
12543 board_info[ent->driver_data].name,
12544 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12545 pcie_width,
12546 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
12547 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
12548 "5GHz (Gen2)" : "2.5GHz",
12549 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12550
a2fbb9ea 12551 return 0;
34f80b04
EG
12552
12553init_one_exit:
12554 if (bp->regview)
12555 iounmap(bp->regview);
12556
1ab4434c 12557 if (IS_PF(bp) && bp->doorbells)
34f80b04
EG
12558 iounmap(bp->doorbells);
12559
12560 free_netdev(dev);
12561
12562 if (atomic_read(&pdev->enable_cnt) == 1)
12563 pci_release_regions(pdev);
12564
12565 pci_disable_device(pdev);
12566 pci_set_drvdata(pdev, NULL);
12567
12568 return rc;
a2fbb9ea
ET
12569}
12570
0329aba1 12571static void bnx2x_remove_one(struct pci_dev *pdev)
a2fbb9ea
ET
12572{
12573 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
12574 struct bnx2x *bp;
12575
12576 if (!dev) {
cdaa7cb8 12577 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
12578 return;
12579 }
228241eb 12580 bp = netdev_priv(dev);
a2fbb9ea 12581
ec6ba945
VZ
12582 /* Delete storage MAC address */
12583 if (!NO_FCOE(bp)) {
12584 rtnl_lock();
12585 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12586 rtnl_unlock();
12587 }
ec6ba945 12588
98507672
SR
12589#ifdef BCM_DCBNL
12590 /* Delete app tlvs from dcbnl */
12591 bnx2x_dcbnl_update_applist(bp, true);
12592#endif
12593
a2fbb9ea
ET
12594 unregister_netdev(dev);
12595
084d6cbb 12596 /* Power on: we can't let PCI layer write to us while we are in D3 */
1ab4434c
AE
12597 if (IS_PF(bp))
12598 bnx2x_set_power_state(bp, PCI_D0);
084d6cbb 12599
d6214d7a
DK
12600 /* Disable MSI/MSI-X */
12601 bnx2x_disable_msi(bp);
f85582f8 12602
084d6cbb 12603 /* Power off */
1ab4434c
AE
12604 if (IS_PF(bp))
12605 bnx2x_set_power_state(bp, PCI_D3hot);
084d6cbb 12606
72fd0718 12607 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12608 cancel_delayed_work_sync(&bp->sp_rtnl_task);
290ca2bb
AE
12609
12610 bnx2x_iov_remove_one(bp);
12611
4513f925
AE
12612 /* send message via vfpf channel to release the resources of this vf */
12613 if (IS_VF(bp))
12614 bnx2x_vfpf_release(bp);
72fd0718 12615
a2fbb9ea
ET
12616 if (bp->regview)
12617 iounmap(bp->regview);
12618
1ab4434c
AE
12619 /* for vf doorbells are part of the regview and were unmapped along with
12620 * it. FW is only loaded by PF.
12621 */
12622 if (IS_PF(bp)) {
12623 if (bp->doorbells)
12624 iounmap(bp->doorbells);
eb2afd4a 12625
1ab4434c
AE
12626 bnx2x_release_firmware(bp);
12627 }
523224a3
DK
12628 bnx2x_free_mem_bp(bp);
12629
a2fbb9ea 12630 free_netdev(dev);
34f80b04
EG
12631
12632 if (atomic_read(&pdev->enable_cnt) == 1)
12633 pci_release_regions(pdev);
12634
a2fbb9ea
ET
12635 pci_disable_device(pdev);
12636 pci_set_drvdata(pdev, NULL);
12637}
12638
f8ef6e44
YG
12639static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12640{
12641 int i;
12642
12643 bp->state = BNX2X_STATE_ERROR;
12644
12645 bp->rx_mode = BNX2X_RX_MODE_NONE;
12646
55c11941
MS
12647 if (CNIC_LOADED(bp))
12648 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12649
619c5cb6
VZ
12650 /* Stop Tx */
12651 bnx2x_tx_disable(bp);
12652
f8ef6e44 12653 bnx2x_netif_stop(bp, 0);
26614ba5
MS
12654 /* Delete all NAPI objects */
12655 bnx2x_del_all_napi(bp);
55c11941
MS
12656 if (CNIC_LOADED(bp))
12657 bnx2x_del_all_napi_cnic(bp);
f8ef6e44
YG
12658
12659 del_timer_sync(&bp->timer);
619c5cb6
VZ
12660
12661 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
12662
12663 /* Release IRQs */
d6214d7a 12664 bnx2x_free_irq(bp);
f8ef6e44 12665
f8ef6e44
YG
12666 /* Free SKBs, SGEs, TPA pool and driver internals */
12667 bnx2x_free_skbs(bp);
523224a3 12668
ec6ba945 12669 for_each_rx_queue(bp, i)
f8ef6e44 12670 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 12671
f8ef6e44
YG
12672 bnx2x_free_mem(bp);
12673
12674 bp->state = BNX2X_STATE_CLOSED;
12675
619c5cb6
VZ
12676 netif_carrier_off(bp->dev);
12677
f8ef6e44
YG
12678 return 0;
12679}
12680
12681static void bnx2x_eeh_recover(struct bnx2x *bp)
12682{
12683 u32 val;
12684
12685 mutex_init(&bp->port.phy_mutex);
12686
f8ef6e44
YG
12687
12688 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12689 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12690 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12691 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
12692}
12693
493adb1f
WX
12694/**
12695 * bnx2x_io_error_detected - called when PCI error is detected
12696 * @pdev: Pointer to PCI device
12697 * @state: The current pci connection state
12698 *
12699 * This function is called after a PCI bus error affecting
12700 * this device has been detected.
12701 */
12702static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12703 pci_channel_state_t state)
12704{
12705 struct net_device *dev = pci_get_drvdata(pdev);
12706 struct bnx2x *bp = netdev_priv(dev);
12707
12708 rtnl_lock();
12709
12710 netif_device_detach(dev);
12711
07ce50e4
DN
12712 if (state == pci_channel_io_perm_failure) {
12713 rtnl_unlock();
12714 return PCI_ERS_RESULT_DISCONNECT;
12715 }
12716
493adb1f 12717 if (netif_running(dev))
f8ef6e44 12718 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
12719
12720 pci_disable_device(pdev);
12721
12722 rtnl_unlock();
12723
12724 /* Request a slot reset */
12725 return PCI_ERS_RESULT_NEED_RESET;
12726}
12727
12728/**
12729 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12730 * @pdev: Pointer to PCI device
12731 *
12732 * Restart the card from scratch, as if from a cold-boot.
12733 */
12734static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12735{
12736 struct net_device *dev = pci_get_drvdata(pdev);
12737 struct bnx2x *bp = netdev_priv(dev);
12738
12739 rtnl_lock();
12740
12741 if (pci_enable_device(pdev)) {
12742 dev_err(&pdev->dev,
12743 "Cannot re-enable PCI device after reset\n");
12744 rtnl_unlock();
12745 return PCI_ERS_RESULT_DISCONNECT;
12746 }
12747
12748 pci_set_master(pdev);
12749 pci_restore_state(pdev);
12750
12751 if (netif_running(dev))
12752 bnx2x_set_power_state(bp, PCI_D0);
12753
12754 rtnl_unlock();
12755
12756 return PCI_ERS_RESULT_RECOVERED;
12757}
12758
12759/**
12760 * bnx2x_io_resume - called when traffic can start flowing again
12761 * @pdev: Pointer to PCI device
12762 *
12763 * This callback is called when the error recovery driver tells us that
12764 * its OK to resume normal operation.
12765 */
12766static void bnx2x_io_resume(struct pci_dev *pdev)
12767{
12768 struct net_device *dev = pci_get_drvdata(pdev);
12769 struct bnx2x *bp = netdev_priv(dev);
12770
72fd0718 12771 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12772 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12773 return;
12774 }
12775
493adb1f
WX
12776 rtnl_lock();
12777
f8ef6e44
YG
12778 bnx2x_eeh_recover(bp);
12779
493adb1f 12780 if (netif_running(dev))
f8ef6e44 12781 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12782
12783 netif_device_attach(dev);
12784
12785 rtnl_unlock();
12786}
12787
3646f0e5 12788static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12789 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12790 .slot_reset = bnx2x_io_slot_reset,
12791 .resume = bnx2x_io_resume,
493adb1f
WX
12792};
12793
a2fbb9ea 12794static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12795 .name = DRV_MODULE_NAME,
12796 .id_table = bnx2x_pci_tbl,
12797 .probe = bnx2x_init_one,
0329aba1 12798 .remove = bnx2x_remove_one,
493adb1f
WX
12799 .suspend = bnx2x_suspend,
12800 .resume = bnx2x_resume,
12801 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
12802};
12803
12804static int __init bnx2x_init(void)
12805{
dd21ca6d
SG
12806 int ret;
12807
7995c64e 12808 pr_info("%s", version);
938cf541 12809
1cf167f2
EG
12810 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12811 if (bnx2x_wq == NULL) {
7995c64e 12812 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12813 return -ENOMEM;
12814 }
12815
dd21ca6d
SG
12816 ret = pci_register_driver(&bnx2x_pci_driver);
12817 if (ret) {
7995c64e 12818 pr_err("Cannot register driver\n");
dd21ca6d
SG
12819 destroy_workqueue(bnx2x_wq);
12820 }
12821 return ret;
a2fbb9ea
ET
12822}
12823
12824static void __exit bnx2x_cleanup(void)
12825{
452427b0 12826 struct list_head *pos, *q;
a2fbb9ea 12827 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12828
12829 destroy_workqueue(bnx2x_wq);
452427b0
YM
12830
12831 /* Free globablly allocated resources */
12832 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12833 struct bnx2x_prev_path_list *tmp =
12834 list_entry(pos, struct bnx2x_prev_path_list, list);
12835 list_del(pos);
12836 kfree(tmp);
12837 }
a2fbb9ea
ET
12838}
12839
3deb8167
YR
12840void bnx2x_notify_link_changed(struct bnx2x *bp)
12841{
12842 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12843}
12844
a2fbb9ea
ET
12845module_init(bnx2x_init);
12846module_exit(bnx2x_cleanup);
12847
619c5cb6
VZ
12848/**
12849 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12850 *
12851 * @bp: driver handle
12852 * @set: set or clear the CAM entry
12853 *
12854 * This function will wait until the ramdord completion returns.
12855 * Return 0 if success, -ENODEV if ramrod doesn't return.
12856 */
1191cb83 12857static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
12858{
12859 unsigned long ramrod_flags = 0;
12860
12861 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12862 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12863 &bp->iscsi_l2_mac_obj, true,
12864 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12865}
993ac7b5
MC
12866
12867/* count denotes the number of new completions we have seen */
12868static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12869{
12870 struct eth_spe *spe;
a052997e 12871 int cxt_index, cxt_offset;
993ac7b5
MC
12872
12873#ifdef BNX2X_STOP_ON_ERROR
12874 if (unlikely(bp->panic))
12875 return;
12876#endif
12877
12878 spin_lock_bh(&bp->spq_lock);
c2bff63f 12879 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
12880 bp->cnic_spq_pending -= count;
12881
993ac7b5 12882
c2bff63f
DK
12883 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12884 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12885 & SPE_HDR_CONN_TYPE) >>
12886 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
12887 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12888 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
12889
12890 /* Set validation for iSCSI L2 client before sending SETUP
12891 * ramrod
12892 */
12893 if (type == ETH_CONNECTION_TYPE) {
a052997e 12894 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 12895 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 12896 ILT_PAGE_CIDS;
37ae41a9 12897 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
12898 (cxt_index * ILT_PAGE_CIDS);
12899 bnx2x_set_ctx_validation(bp,
12900 &bp->context[cxt_index].
12901 vcxt[cxt_offset].eth,
37ae41a9 12902 BNX2X_ISCSI_ETH_CID(bp));
a052997e 12903 }
c2bff63f
DK
12904 }
12905
619c5cb6
VZ
12906 /*
12907 * There may be not more than 8 L2, not more than 8 L5 SPEs
12908 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
12909 * COMMON ramrods is not more than the EQ and SPQ can
12910 * accommodate.
c2bff63f 12911 */
6e30dd4e
VZ
12912 if (type == ETH_CONNECTION_TYPE) {
12913 if (!atomic_read(&bp->cq_spq_left))
12914 break;
12915 else
12916 atomic_dec(&bp->cq_spq_left);
12917 } else if (type == NONE_CONNECTION_TYPE) {
12918 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
12919 break;
12920 else
6e30dd4e 12921 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
12922 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12923 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
12924 if (bp->cnic_spq_pending >=
12925 bp->cnic_eth_dev.max_kwqe_pending)
12926 break;
12927 else
12928 bp->cnic_spq_pending++;
12929 } else {
12930 BNX2X_ERR("Unknown SPE type: %d\n", type);
12931 bnx2x_panic();
993ac7b5 12932 break;
c2bff63f 12933 }
993ac7b5
MC
12934
12935 spe = bnx2x_sp_get_next(bp);
12936 *spe = *bp->cnic_kwq_cons;
12937
51c1a580 12938 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
12939 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12940
12941 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12942 bp->cnic_kwq_cons = bp->cnic_kwq;
12943 else
12944 bp->cnic_kwq_cons++;
12945 }
12946 bnx2x_sp_prod_update(bp);
12947 spin_unlock_bh(&bp->spq_lock);
12948}
12949
12950static int bnx2x_cnic_sp_queue(struct net_device *dev,
12951 struct kwqe_16 *kwqes[], u32 count)
12952{
12953 struct bnx2x *bp = netdev_priv(dev);
12954 int i;
12955
12956#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
12957 if (unlikely(bp->panic)) {
12958 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 12959 return -EIO;
51c1a580 12960 }
993ac7b5
MC
12961#endif
12962
95c6c616
AE
12963 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12964 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 12965 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
12966 return -EAGAIN;
12967 }
12968
993ac7b5
MC
12969 spin_lock_bh(&bp->spq_lock);
12970
12971 for (i = 0; i < count; i++) {
12972 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12973
12974 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12975 break;
12976
12977 *bp->cnic_kwq_prod = *spe;
12978
12979 bp->cnic_kwq_pending++;
12980
51c1a580 12981 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 12982 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
12983 spe->data.update_data_addr.hi,
12984 spe->data.update_data_addr.lo,
993ac7b5
MC
12985 bp->cnic_kwq_pending);
12986
12987 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12988 bp->cnic_kwq_prod = bp->cnic_kwq;
12989 else
12990 bp->cnic_kwq_prod++;
12991 }
12992
12993 spin_unlock_bh(&bp->spq_lock);
12994
12995 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12996 bnx2x_cnic_sp_post(bp, 0);
12997
12998 return i;
12999}
13000
13001static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13002{
13003 struct cnic_ops *c_ops;
13004 int rc = 0;
13005
13006 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
13007 c_ops = rcu_dereference_protected(bp->cnic_ops,
13008 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
13009 if (c_ops)
13010 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13011 mutex_unlock(&bp->cnic_mutex);
13012
13013 return rc;
13014}
13015
13016static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13017{
13018 struct cnic_ops *c_ops;
13019 int rc = 0;
13020
13021 rcu_read_lock();
13022 c_ops = rcu_dereference(bp->cnic_ops);
13023 if (c_ops)
13024 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13025 rcu_read_unlock();
13026
13027 return rc;
13028}
13029
13030/*
13031 * for commands that have no data
13032 */
9f6c9258 13033int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
13034{
13035 struct cnic_ctl_info ctl = {0};
13036
13037 ctl.cmd = cmd;
13038
13039 return bnx2x_cnic_ctl_send(bp, &ctl);
13040}
13041
619c5cb6 13042static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 13043{
619c5cb6 13044 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
13045
13046 /* first we tell CNIC and only then we count this as a completion */
13047 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13048 ctl.data.comp.cid = cid;
619c5cb6 13049 ctl.data.comp.error = err;
993ac7b5
MC
13050
13051 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 13052 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
13053}
13054
619c5cb6
VZ
13055
13056/* Called with netif_addr_lock_bh() taken.
13057 * Sets an rx_mode config for an iSCSI ETH client.
13058 * Doesn't block.
13059 * Completion should be checked outside.
13060 */
13061static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13062{
13063 unsigned long accept_flags = 0, ramrod_flags = 0;
13064 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13065 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13066
13067 if (start) {
13068 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13069 * because it's the only way for UIO Queue to accept
13070 * multicasts (in non-promiscuous mode only one Queue per
13071 * function will receive multicast packets (leading in our
13072 * case).
13073 */
13074 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13075 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13076 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13077 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13078
13079 /* Clear STOP_PENDING bit if START is requested */
13080 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13081
13082 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13083 } else
13084 /* Clear START_PENDING bit if STOP is requested */
13085 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13086
13087 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13088 set_bit(sched_state, &bp->sp_state);
13089 else {
13090 __set_bit(RAMROD_RX, &ramrod_flags);
13091 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13092 ramrod_flags);
13093 }
13094}
13095
13096
993ac7b5
MC
13097static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13098{
13099 struct bnx2x *bp = netdev_priv(dev);
13100 int rc = 0;
13101
13102 switch (ctl->cmd) {
13103 case DRV_CTL_CTXTBL_WR_CMD: {
13104 u32 index = ctl->data.io.offset;
13105 dma_addr_t addr = ctl->data.io.dma_addr;
13106
13107 bnx2x_ilt_wr(bp, index, addr);
13108 break;
13109 }
13110
c2bff63f
DK
13111 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13112 int count = ctl->data.credit.credit_count;
993ac7b5
MC
13113
13114 bnx2x_cnic_sp_post(bp, count);
13115 break;
13116 }
13117
13118 /* rtnl_lock is held. */
13119 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
13120 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13121 unsigned long sp_bits = 0;
13122
13123 /* Configure the iSCSI classification object */
13124 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13125 cp->iscsi_l2_client_id,
13126 cp->iscsi_l2_cid, BP_FUNC(bp),
13127 bnx2x_sp(bp, mac_rdata),
13128 bnx2x_sp_mapping(bp, mac_rdata),
13129 BNX2X_FILTER_MAC_PENDING,
13130 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13131 &bp->macs_pool);
ec6ba945 13132
523224a3 13133 /* Set iSCSI MAC address */
619c5cb6
VZ
13134 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13135 if (rc)
13136 break;
523224a3
DK
13137
13138 mmiowb();
13139 barrier();
13140
619c5cb6
VZ
13141 /* Start accepting on iSCSI L2 ring */
13142
13143 netif_addr_lock_bh(dev);
13144 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13145 netif_addr_unlock_bh(dev);
13146
13147 /* bits to wait on */
13148 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13149 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13150
13151 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13152 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 13153
993ac7b5
MC
13154 break;
13155 }
13156
13157 /* rtnl_lock is held. */
13158 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 13159 unsigned long sp_bits = 0;
993ac7b5 13160
523224a3 13161 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
13162 netif_addr_lock_bh(dev);
13163 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13164 netif_addr_unlock_bh(dev);
13165
13166 /* bits to wait on */
13167 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13168 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13169
13170 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13171 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
13172
13173 mmiowb();
13174 barrier();
13175
13176 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
13177 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13178 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
13179 break;
13180 }
c2bff63f
DK
13181 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13182 int count = ctl->data.credit.credit_count;
13183
13184 smp_mb__before_atomic_inc();
6e30dd4e 13185 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
13186 smp_mb__after_atomic_inc();
13187 break;
13188 }
1d187b34 13189 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 13190 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
13191
13192 if (CHIP_IS_E3(bp)) {
13193 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
13194 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13195 int path = BP_PATH(bp);
13196 int port = BP_PORT(bp);
13197 int i;
13198 u32 scratch_offset;
13199 u32 *host_addr;
1d187b34 13200
2e499d3c 13201 /* first write capability to shmem2 */
1d187b34
BW
13202 if (ulp_type == CNIC_ULP_ISCSI)
13203 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13204 else if (ulp_type == CNIC_ULP_FCOE)
13205 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13206 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
13207
13208 if ((ulp_type != CNIC_ULP_FCOE) ||
13209 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13210 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13211 break;
13212
13213 /* if reached here - should write fcoe capabilities */
13214 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13215 if (!scratch_offset)
13216 break;
13217 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13218 fcoe_features[path][port]);
13219 host_addr = (u32 *) &(ctl->data.register_data.
13220 fcoe_features);
13221 for (i = 0; i < sizeof(struct fcoe_capabilities);
13222 i += 4)
13223 REG_WR(bp, scratch_offset + i,
13224 *(host_addr + i/4));
1d187b34
BW
13225 }
13226 break;
13227 }
2e499d3c 13228
1d187b34
BW
13229 case DRV_CTL_ULP_UNREGISTER_CMD: {
13230 int ulp_type = ctl->data.ulp_type;
13231
13232 if (CHIP_IS_E3(bp)) {
13233 int idx = BP_FW_MB_IDX(bp);
13234 u32 cap;
13235
13236 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13237 if (ulp_type == CNIC_ULP_ISCSI)
13238 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13239 else if (ulp_type == CNIC_ULP_FCOE)
13240 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13241 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13242 }
13243 break;
13244 }
993ac7b5
MC
13245
13246 default:
13247 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13248 rc = -EINVAL;
13249 }
13250
13251 return rc;
13252}
13253
9f6c9258 13254void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
13255{
13256 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13257
13258 if (bp->flags & USING_MSIX_FLAG) {
13259 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13260 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13261 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13262 } else {
13263 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13264 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13265 }
619c5cb6 13266 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
13267 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13268 else
13269 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13270
619c5cb6
VZ
13271 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13272 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
13273 cp->irq_arr[1].status_blk = bp->def_status_blk;
13274 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 13275 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
13276
13277 cp->num_irq = 2;
13278}
13279
37ae41a9
MS
13280void bnx2x_setup_cnic_info(struct bnx2x *bp)
13281{
13282 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13283
13284
13285 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13286 bnx2x_cid_ilt_lines(bp);
13287 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13288 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13289 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13290
13291 if (NO_ISCSI_OOO(bp))
13292 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13293}
13294
993ac7b5
MC
13295static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13296 void *data)
13297{
13298 struct bnx2x *bp = netdev_priv(dev);
13299 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
13300 int rc;
13301
13302 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 13303
51c1a580
MS
13304 if (ops == NULL) {
13305 BNX2X_ERR("NULL ops received\n");
993ac7b5 13306 return -EINVAL;
51c1a580 13307 }
993ac7b5 13308
55c11941
MS
13309 if (!CNIC_SUPPORT(bp)) {
13310 BNX2X_ERR("Can't register CNIC when not supported\n");
13311 return -EOPNOTSUPP;
13312 }
13313
13314 if (!CNIC_LOADED(bp)) {
13315 rc = bnx2x_load_cnic(bp);
13316 if (rc) {
13317 BNX2X_ERR("CNIC-related load failed\n");
13318 return rc;
13319 }
13320
13321 }
13322
13323 bp->cnic_enabled = true;
13324
993ac7b5
MC
13325 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13326 if (!bp->cnic_kwq)
13327 return -ENOMEM;
13328
13329 bp->cnic_kwq_cons = bp->cnic_kwq;
13330 bp->cnic_kwq_prod = bp->cnic_kwq;
13331 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13332
13333 bp->cnic_spq_pending = 0;
13334 bp->cnic_kwq_pending = 0;
13335
13336 bp->cnic_data = data;
13337
13338 cp->num_irq = 0;
619c5cb6 13339 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 13340 cp->iro_arr = bp->iro_arr;
993ac7b5 13341
993ac7b5 13342 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 13343
993ac7b5
MC
13344 rcu_assign_pointer(bp->cnic_ops, ops);
13345
13346 return 0;
13347}
13348
13349static int bnx2x_unregister_cnic(struct net_device *dev)
13350{
13351 struct bnx2x *bp = netdev_priv(dev);
13352 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13353
13354 mutex_lock(&bp->cnic_mutex);
993ac7b5 13355 cp->drv_state = 0;
2cfa5a04 13356 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
13357 mutex_unlock(&bp->cnic_mutex);
13358 synchronize_rcu();
13359 kfree(bp->cnic_kwq);
13360 bp->cnic_kwq = NULL;
13361
13362 return 0;
13363}
13364
13365struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13366{
13367 struct bnx2x *bp = netdev_priv(dev);
13368 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13369
2ba45142
VZ
13370 /* If both iSCSI and FCoE are disabled - return NULL in
13371 * order to indicate CNIC that it should not try to work
13372 * with this device.
13373 */
13374 if (NO_ISCSI(bp) && NO_FCOE(bp))
13375 return NULL;
13376
993ac7b5
MC
13377 cp->drv_owner = THIS_MODULE;
13378 cp->chip_id = CHIP_ID(bp);
13379 cp->pdev = bp->pdev;
13380 cp->io_base = bp->regview;
13381 cp->io_base2 = bp->doorbells;
13382 cp->max_kwqe_pending = 8;
523224a3 13383 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
13384 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13385 bnx2x_cid_ilt_lines(bp);
993ac7b5 13386 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 13387 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
13388 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13389 cp->drv_ctl = bnx2x_drv_ctl;
13390 cp->drv_register_cnic = bnx2x_register_cnic;
13391 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 13392 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
13393 cp->iscsi_l2_client_id =
13394 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 13395 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 13396
2ba45142
VZ
13397 if (NO_ISCSI_OOO(bp))
13398 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13399
13400 if (NO_ISCSI(bp))
13401 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13402
13403 if (NO_FCOE(bp))
13404 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13405
51c1a580
MS
13406 BNX2X_DEV_INFO(
13407 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13408 cp->ctx_blk_size,
13409 cp->ctx_tbl_offset,
13410 cp->ctx_tbl_len,
13411 cp->starting_cid);
993ac7b5
MC
13412 return cp;
13413}
993ac7b5 13414
6411280a 13415u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
9b176b6b 13416{
6411280a
AE
13417 struct bnx2x *bp = fp->bp;
13418 u32 offset = BAR_USTRORM_INTMEM;
abc5a021 13419
6411280a
AE
13420 if (IS_VF(bp))
13421 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13422 else if (!CHIP_IS_E1x(bp))
13423 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13424 else
13425 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
8d9ac297 13426
6411280a 13427 return offset;
8d9ac297 13428}
381ac16b 13429
6411280a
AE
13430/* called only on E1H or E2.
13431 * When pretending to be PF, the pretend value is the function number 0...7
13432 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13433 * combination
13434 */
13435int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
381ac16b 13436{
6411280a 13437 u32 pretend_reg;
381ac16b 13438
23826850 13439 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
6411280a 13440 return -1;
381ac16b 13441
6411280a
AE
13442 /* get my own pretend register */
13443 pretend_reg = bnx2x_get_pretend_reg(bp);
13444 REG_WR(bp, pretend_reg, pretend_func_val);
13445 REG_RD(bp, pretend_reg);
381ac16b
AE
13446 return 0;
13447}
This page took 2.278875 seconds and 5 git commands to generate.