]> git.ipfire.org Git - thirdparty/linux.git/blame - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
bnx2x: Remove many sparse warnings
[thirdparty/linux.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_main.c
CommitLineData
34f80b04 1/* bnx2x_main.c: Broadcom Everest network driver.
a2fbb9ea 2 *
247fa82b 3 * Copyright (c) 2007-2013 Broadcom Corporation
a2fbb9ea
ET
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
24e3fcef
EG
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
a2fbb9ea
ET
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
ca00392c 13 * Slowpath and fastpath rework by Vladislav Zolotarov
c14423fe 14 * Statistics and Link management by Yitchak Gertner
a2fbb9ea
ET
15 *
16 */
17
f1deab50
JP
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
a2fbb9ea
ET
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/kernel.h>
23#include <linux/device.h> /* for dev_info() */
24#include <linux/timer.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
a2fbb9ea
ET
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/dma-mapping.h>
35#include <linux/bitops.h>
36#include <linux/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
0c6671b0 42#include <linux/if_vlan.h>
a2fbb9ea 43#include <net/ip.h>
619c5cb6 44#include <net/ipv6.h>
a2fbb9ea
ET
45#include <net/tcp.h>
46#include <net/checksum.h>
34f80b04 47#include <net/ip6_checksum.h>
a2fbb9ea
ET
48#include <linux/workqueue.h>
49#include <linux/crc32.h>
34f80b04 50#include <linux/crc32c.h>
a2fbb9ea
ET
51#include <linux/prefetch.h>
52#include <linux/zlib.h>
a2fbb9ea 53#include <linux/io.h>
452427b0 54#include <linux/semaphore.h>
45229b42 55#include <linux/stringify.h>
7ab24bfd 56#include <linux/vmalloc.h>
a2fbb9ea 57
a2fbb9ea
ET
58#include "bnx2x.h"
59#include "bnx2x_init.h"
94a78b79 60#include "bnx2x_init_ops.h"
9f6c9258 61#include "bnx2x_cmn.h"
1ab4434c 62#include "bnx2x_vfpf.h"
e4901dde 63#include "bnx2x_dcb.h"
042181f5 64#include "bnx2x_sp.h"
a2fbb9ea 65
94a78b79
VZ
66#include <linux/firmware.h>
67#include "bnx2x_fw_file_hdr.h"
68/* FW files */
45229b42
BH
69#define FW_FILE_VERSION \
70 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
71 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
72 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
73 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
560131f3
DK
74#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
75#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
f2e0899f 76#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
94a78b79 77
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 /* fastpath */
b3b83c3f 7742 bnx2x_free_fp_mem(bp);
a2fbb9ea
ET
7743 /* end of fastpath */
7744
7745 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
523224a3 7746 sizeof(struct host_sp_status_block));
a2fbb9ea 7747
619c5cb6
VZ
7748 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7749 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7750
a2fbb9ea 7751 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
34f80b04 7752 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7753
a052997e
MS
7754 for (i = 0; i < L2_ILT_LINES(bp); i++)
7755 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7756 bp->context[i].size);
523224a3
DK
7757 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7758
7759 BNX2X_FREE(bp->ilt->lines);
f85582f8 7760
7a9b2557 7761 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
a2fbb9ea 7762
523224a3
DK
7763 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7764 BCM_PAGE_SIZE * NUM_EQ_PAGES);
619c5cb6
VZ
7765}
7766
a2fbb9ea 7767
55c11941 7768int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
a2fbb9ea 7769{
619c5cb6
VZ
7770 if (!CHIP_IS_E1x(bp))
7771 /* size = the status block + ramrod buffers */
f2e0899f
DK
7772 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7773 sizeof(struct host_hc_status_block_e2));
7774 else
55c11941
MS
7775 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7776 &bp->cnic_sb_mapping,
7777 sizeof(struct
7778 host_hc_status_block_e1x));
8badd27a 7779
55c11941
MS
7780 if (CONFIGURE_NIC_MODE(bp))
7781 /* allocate searcher T2 table, as it wan't allocated before */
7782 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7783
7784 /* write address to which L5 should insert its values */
7785 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7786 &bp->slowpath->drv_info_to_mcp;
7787
7788 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7789 goto alloc_mem_err;
7790
7791 return 0;
7792
7793alloc_mem_err:
7794 bnx2x_free_mem_cnic(bp);
7795 BNX2X_ERR("Can't allocate memory\n");
7796 return -ENOMEM;
7797}
7798
7799int bnx2x_alloc_mem(struct bnx2x *bp)
7800{
7801 int i, allocated, context_size;
a2fbb9ea 7802
55c11941
MS
7803 if (!CONFIGURE_NIC_MODE(bp))
7804 /* allocate searcher T2 table */
7805 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
8badd27a 7806
523224a3
DK
7807 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7808 sizeof(struct host_sp_status_block));
a2fbb9ea 7809
523224a3
DK
7810 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7811 sizeof(struct bnx2x_slowpath));
a2fbb9ea 7812
a052997e
MS
7813 /* Allocate memory for CDU context:
7814 * This memory is allocated separately and not in the generic ILT
7815 * functions because CDU differs in few aspects:
7816 * 1. There are multiple entities allocating memory for context -
7817 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7818 * its own ILT lines.
7819 * 2. Since CDU page-size is not a single 4KB page (which is the case
7820 * for the other ILT clients), to be efficient we want to support
7821 * allocation of sub-page-size in the last entry.
7822 * 3. Context pointers are used by the driver to pass to FW / update
7823 * the context (for the other ILT clients the pointers are used just to
7824 * free the memory during unload).
7825 */
7826 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
65abd74d 7827
a052997e
MS
7828 for (i = 0, allocated = 0; allocated < context_size; i++) {
7829 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7830 (context_size - allocated));
7831 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7832 &bp->context[i].cxt_mapping,
7833 bp->context[i].size);
7834 allocated += bp->context[i].size;
7835 }
523224a3 7836 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
65abd74d 7837
523224a3
DK
7838 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7839 goto alloc_mem_err;
65abd74d 7840
67c431a5
AE
7841 if (bnx2x_iov_alloc_mem(bp))
7842 goto alloc_mem_err;
7843
9f6c9258
DK
7844 /* Slow path ring */
7845 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
65abd74d 7846
523224a3
DK
7847 /* EQ */
7848 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7849 BCM_PAGE_SIZE * NUM_EQ_PAGES);
ab532cf3 7850
9f6c9258 7851 return 0;
e1510706 7852
9f6c9258
DK
7853alloc_mem_err:
7854 bnx2x_free_mem(bp);
51c1a580 7855 BNX2X_ERR("Can't allocate memory\n");
9f6c9258 7856 return -ENOMEM;
65abd74d
YG
7857}
7858
a2fbb9ea
ET
7859/*
7860 * Init service functions
7861 */
a2fbb9ea 7862
619c5cb6
VZ
7863int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7864 struct bnx2x_vlan_mac_obj *obj, bool set,
7865 int mac_type, unsigned long *ramrod_flags)
a2fbb9ea 7866{
619c5cb6
VZ
7867 int rc;
7868 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
a2fbb9ea 7869
619c5cb6 7870 memset(&ramrod_param, 0, sizeof(ramrod_param));
a2fbb9ea 7871
619c5cb6
VZ
7872 /* Fill general parameters */
7873 ramrod_param.vlan_mac_obj = obj;
7874 ramrod_param.ramrod_flags = *ramrod_flags;
a2fbb9ea 7875
619c5cb6
VZ
7876 /* Fill a user request section if needed */
7877 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7878 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
a2fbb9ea 7879
619c5cb6 7880 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
e3553b29 7881
619c5cb6
VZ
7882 /* Set the command: ADD or DEL */
7883 if (set)
7884 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7885 else
7886 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
a2fbb9ea
ET
7887 }
7888
619c5cb6 7889 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7b5342d9
YM
7890
7891 if (rc == -EEXIST) {
7892 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7893 /* do not treat adding same MAC as error */
7894 rc = 0;
7895 } else if (rc < 0)
619c5cb6 7896 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7b5342d9 7897
619c5cb6 7898 return rc;
a2fbb9ea
ET
7899}
7900
619c5cb6
VZ
7901int bnx2x_del_all_macs(struct bnx2x *bp,
7902 struct bnx2x_vlan_mac_obj *mac_obj,
7903 int mac_type, bool wait_for_comp)
e665bfda 7904{
619c5cb6
VZ
7905 int rc;
7906 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
0793f83f 7907
619c5cb6
VZ
7908 /* Wait for completion of requested */
7909 if (wait_for_comp)
7910 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
0793f83f 7911
619c5cb6
VZ
7912 /* Set the mac type of addresses we want to clear */
7913 __set_bit(mac_type, &vlan_mac_flags);
0793f83f 7914
619c5cb6
VZ
7915 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7916 if (rc < 0)
7917 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
0793f83f 7918
619c5cb6 7919 return rc;
0793f83f
DK
7920}
7921
619c5cb6 7922int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
523224a3 7923{
619c5cb6 7924 unsigned long ramrod_flags = 0;
e665bfda 7925
a3348722
BW
7926 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7927 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
51c1a580
MS
7928 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7929 "Ignoring Zero MAC for STORAGE SD mode\n");
614c76df
DK
7930 return 0;
7931 }
614c76df 7932
619c5cb6 7933 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
0793f83f 7934
619c5cb6
VZ
7935 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7936 /* Eth MAC is set on RSS leading client (fp[0]) */
15192a8c
BW
7937 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7938 set, BNX2X_ETH_MAC, &ramrod_flags);
e665bfda 7939}
6e30dd4e 7940
619c5cb6 7941int bnx2x_setup_leading(struct bnx2x *bp)
ec6ba945 7942{
619c5cb6 7943 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
993ac7b5 7944}
a2fbb9ea 7945
d6214d7a 7946/**
e8920674 7947 * bnx2x_set_int_mode - configure interrupt mode
d6214d7a 7948 *
e8920674 7949 * @bp: driver handle
d6214d7a 7950 *
e8920674 7951 * In case of MSI-X it will also try to enable MSI-X.
d6214d7a 7952 */
1ab4434c 7953int bnx2x_set_int_mode(struct bnx2x *bp)
ca00392c 7954{
1ab4434c
AE
7955 int rc = 0;
7956
7957 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
7958 return -EINVAL;
7959
9ee3d37b 7960 switch (int_mode) {
1ab4434c
AE
7961 case BNX2X_INT_MODE_MSIX:
7962 /* attempt to enable msix */
7963 rc = bnx2x_enable_msix(bp);
7964
7965 /* msix attained */
7966 if (!rc)
7967 return 0;
7968
7969 /* vfs use only msix */
7970 if (rc && IS_VF(bp))
7971 return rc;
7972
7973 /* failed to enable multiple MSI-X */
7974 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7975 bp->num_queues,
7976 1 + bp->num_cnic_queues);
7977
7978 /* falling through... */
7979 case BNX2X_INT_MODE_MSI:
d6214d7a 7980 bnx2x_enable_msi(bp);
1ab4434c 7981
d6214d7a 7982 /* falling through... */
1ab4434c 7983 case BNX2X_INT_MODE_INTX:
55c11941
MS
7984 bp->num_ethernet_queues = 1;
7985 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
51c1a580 7986 BNX2X_DEV_INFO("set number of queues to 1\n");
ca00392c 7987 break;
d6214d7a 7988 default:
1ab4434c
AE
7989 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
7990 return -EINVAL;
9f6c9258 7991 }
1ab4434c 7992 return 0;
a2fbb9ea
ET
7993}
7994
1ab4434c 7995/* must be called prior to any HW initializations */
c2bff63f
DK
7996static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7997{
290ca2bb
AE
7998 if (IS_SRIOV(bp))
7999 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
c2bff63f
DK
8000 return L2_ILT_LINES(bp);
8001}
8002
523224a3
DK
8003void bnx2x_ilt_set_info(struct bnx2x *bp)
8004{
8005 struct ilt_client_info *ilt_client;
8006 struct bnx2x_ilt *ilt = BP_ILT(bp);
8007 u16 line = 0;
8008
8009 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8010 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8011
8012 /* CDU */
8013 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8014 ilt_client->client_num = ILT_CLIENT_CDU;
8015 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8016 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8017 ilt_client->start = line;
619c5cb6 8018 line += bnx2x_cid_ilt_lines(bp);
55c11941
MS
8019
8020 if (CNIC_SUPPORT(bp))
8021 line += CNIC_ILT_LINES;
523224a3
DK
8022 ilt_client->end = line - 1;
8023
51c1a580 8024 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8025 ilt_client->start,
8026 ilt_client->end,
8027 ilt_client->page_size,
8028 ilt_client->flags,
8029 ilog2(ilt_client->page_size >> 12));
8030
8031 /* QM */
8032 if (QM_INIT(bp->qm_cid_count)) {
8033 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8034 ilt_client->client_num = ILT_CLIENT_QM;
8035 ilt_client->page_size = QM_ILT_PAGE_SZ;
8036 ilt_client->flags = 0;
8037 ilt_client->start = line;
8038
8039 /* 4 bytes for each cid */
8040 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8041 QM_ILT_PAGE_SZ);
8042
8043 ilt_client->end = line - 1;
8044
51c1a580
MS
8045 DP(NETIF_MSG_IFUP,
8046 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
523224a3
DK
8047 ilt_client->start,
8048 ilt_client->end,
8049 ilt_client->page_size,
8050 ilt_client->flags,
8051 ilog2(ilt_client->page_size >> 12));
8052
8053 }
523224a3 8054
55c11941
MS
8055 if (CNIC_SUPPORT(bp)) {
8056 /* SRC */
8057 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8058 ilt_client->client_num = ILT_CLIENT_SRC;
8059 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8060 ilt_client->flags = 0;
8061 ilt_client->start = line;
8062 line += SRC_ILT_LINES;
8063 ilt_client->end = line - 1;
523224a3 8064
55c11941
MS
8065 DP(NETIF_MSG_IFUP,
8066 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8067 ilt_client->start,
8068 ilt_client->end,
8069 ilt_client->page_size,
8070 ilt_client->flags,
8071 ilog2(ilt_client->page_size >> 12));
9f6c9258 8072
55c11941
MS
8073 /* TM */
8074 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8075 ilt_client->client_num = ILT_CLIENT_TM;
8076 ilt_client->page_size = TM_ILT_PAGE_SZ;
8077 ilt_client->flags = 0;
8078 ilt_client->start = line;
8079 line += TM_ILT_LINES;
8080 ilt_client->end = line - 1;
523224a3 8081
55c11941
MS
8082 DP(NETIF_MSG_IFUP,
8083 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8084 ilt_client->start,
8085 ilt_client->end,
8086 ilt_client->page_size,
8087 ilt_client->flags,
8088 ilog2(ilt_client->page_size >> 12));
8089 }
9f6c9258 8090
619c5cb6 8091 BUG_ON(line > ILT_MAX_LINES);
523224a3 8092}
f85582f8 8093
619c5cb6
VZ
8094/**
8095 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8096 *
8097 * @bp: driver handle
8098 * @fp: pointer to fastpath
8099 * @init_params: pointer to parameters structure
8100 *
8101 * parameters configured:
8102 * - HC configuration
8103 * - Queue's CDU context
8104 */
1191cb83 8105static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
619c5cb6 8106 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
a2fbb9ea 8107{
6383c0b3
AE
8108
8109 u8 cos;
a052997e
MS
8110 int cxt_index, cxt_offset;
8111
619c5cb6
VZ
8112 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8113 if (!IS_FCOE_FP(fp)) {
8114 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8115 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8116
8117 /* If HC is supporterd, enable host coalescing in the transition
8118 * to INIT state.
8119 */
8120 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8121 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8122
8123 /* HC rate */
8124 init_params->rx.hc_rate = bp->rx_ticks ?
8125 (1000000 / bp->rx_ticks) : 0;
8126 init_params->tx.hc_rate = bp->tx_ticks ?
8127 (1000000 / bp->tx_ticks) : 0;
8128
8129 /* FW SB ID */
8130 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8131 fp->fw_sb_id;
8132
8133 /*
8134 * CQ index among the SB indices: FCoE clients uses the default
8135 * SB, therefore it's different.
8136 */
6383c0b3
AE
8137 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8138 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
619c5cb6
VZ
8139 }
8140
6383c0b3
AE
8141 /* set maximum number of COSs supported by this queue */
8142 init_params->max_cos = fp->max_cos;
8143
51c1a580 8144 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
6383c0b3
AE
8145 fp->index, init_params->max_cos);
8146
8147 /* set the context pointers queue object */
a052997e 8148 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
65565884
MS
8149 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8150 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
a052997e 8151 ILT_PAGE_CIDS);
6383c0b3 8152 init_params->cxts[cos] =
a052997e
MS
8153 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8154 }
619c5cb6
VZ
8155}
8156
910cc727 8157static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6383c0b3
AE
8158 struct bnx2x_queue_state_params *q_params,
8159 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8160 int tx_index, bool leading)
8161{
8162 memset(tx_only_params, 0, sizeof(*tx_only_params));
8163
8164 /* Set the command */
8165 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8166
8167 /* Set tx-only QUEUE flags: don't zero statistics */
8168 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8169
8170 /* choose the index of the cid to send the slow path on */
8171 tx_only_params->cid_index = tx_index;
8172
8173 /* Set general TX_ONLY_SETUP parameters */
8174 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8175
8176 /* Set Tx TX_ONLY_SETUP parameters */
8177 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8178
51c1a580
MS
8179 DP(NETIF_MSG_IFUP,
8180 "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
8181 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8182 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8183 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8184
8185 /* send the ramrod */
8186 return bnx2x_queue_state_change(bp, q_params);
8187}
8188
8189
619c5cb6
VZ
8190/**
8191 * bnx2x_setup_queue - setup queue
8192 *
8193 * @bp: driver handle
8194 * @fp: pointer to fastpath
8195 * @leading: is leading
8196 *
8197 * This function performs 2 steps in a Queue state machine
8198 * actually: 1) RESET->INIT 2) INIT->SETUP
8199 */
8200
8201int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8202 bool leading)
8203{
3b603066 8204 struct bnx2x_queue_state_params q_params = {NULL};
619c5cb6
VZ
8205 struct bnx2x_queue_setup_params *setup_params =
8206 &q_params.params.setup;
6383c0b3
AE
8207 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8208 &q_params.params.tx_only;
a2fbb9ea 8209 int rc;
6383c0b3
AE
8210 u8 tx_index;
8211
51c1a580 8212 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
a2fbb9ea 8213
ec6ba945
VZ
8214 /* reset IGU state skip FCoE L2 queue */
8215 if (!IS_FCOE_FP(fp))
8216 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
523224a3 8217 IGU_INT_ENABLE, 0);
a2fbb9ea 8218
15192a8c 8219 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8220 /* We want to wait for completion in this context */
8221 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8222
619c5cb6
VZ
8223 /* Prepare the INIT parameters */
8224 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
ec6ba945 8225
619c5cb6
VZ
8226 /* Set the command */
8227 q_params.cmd = BNX2X_Q_CMD_INIT;
8228
8229 /* Change the state to INIT */
8230 rc = bnx2x_queue_state_change(bp, &q_params);
8231 if (rc) {
6383c0b3 8232 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
619c5cb6
VZ
8233 return rc;
8234 }
ec6ba945 8235
51c1a580 8236 DP(NETIF_MSG_IFUP, "init complete\n");
6383c0b3
AE
8237
8238
619c5cb6
VZ
8239 /* Now move the Queue to the SETUP state... */
8240 memset(setup_params, 0, sizeof(*setup_params));
a2fbb9ea 8241
619c5cb6
VZ
8242 /* Set QUEUE flags */
8243 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
523224a3 8244
619c5cb6 8245 /* Set general SETUP parameters */
6383c0b3
AE
8246 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8247 FIRST_TX_COS_INDEX);
619c5cb6 8248
6383c0b3 8249 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
619c5cb6
VZ
8250 &setup_params->rxq_params);
8251
6383c0b3
AE
8252 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8253 FIRST_TX_COS_INDEX);
619c5cb6
VZ
8254
8255 /* Set the command */
8256 q_params.cmd = BNX2X_Q_CMD_SETUP;
8257
55c11941
MS
8258 if (IS_FCOE_FP(fp))
8259 bp->fcoe_init = true;
8260
619c5cb6
VZ
8261 /* Change the state to SETUP */
8262 rc = bnx2x_queue_state_change(bp, &q_params);
6383c0b3
AE
8263 if (rc) {
8264 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8265 return rc;
8266 }
8267
8268 /* loop through the relevant tx-only indices */
8269 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8270 tx_index < fp->max_cos;
8271 tx_index++) {
8272
8273 /* prepare and send tx-only ramrod*/
8274 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8275 tx_only_params, tx_index, leading);
8276 if (rc) {
8277 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8278 fp->index, tx_index);
8279 return rc;
8280 }
8281 }
523224a3 8282
34f80b04 8283 return rc;
a2fbb9ea
ET
8284}
8285
619c5cb6 8286static int bnx2x_stop_queue(struct bnx2x *bp, int index)
a2fbb9ea 8287{
619c5cb6 8288 struct bnx2x_fastpath *fp = &bp->fp[index];
6383c0b3 8289 struct bnx2x_fp_txdata *txdata;
3b603066 8290 struct bnx2x_queue_state_params q_params = {NULL};
6383c0b3
AE
8291 int rc, tx_index;
8292
51c1a580 8293 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
a2fbb9ea 8294
15192a8c 8295 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
619c5cb6
VZ
8296 /* We want to wait for completion in this context */
8297 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
a2fbb9ea 8298
6383c0b3
AE
8299
8300 /* close tx-only connections */
8301 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8302 tx_index < fp->max_cos;
8303 tx_index++){
8304
8305 /* ascertain this is a normal queue*/
65565884 8306 txdata = fp->txdata_ptr[tx_index];
6383c0b3 8307
51c1a580 8308 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
6383c0b3
AE
8309 txdata->txq_index);
8310
8311 /* send halt terminate on tx-only connection */
8312 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8313 memset(&q_params.params.terminate, 0,
8314 sizeof(q_params.params.terminate));
8315 q_params.params.terminate.cid_index = tx_index;
8316
8317 rc = bnx2x_queue_state_change(bp, &q_params);
8318 if (rc)
8319 return rc;
8320
8321 /* send halt terminate on tx-only connection */
8322 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8323 memset(&q_params.params.cfc_del, 0,
8324 sizeof(q_params.params.cfc_del));
8325 q_params.params.cfc_del.cid_index = tx_index;
8326 rc = bnx2x_queue_state_change(bp, &q_params);
8327 if (rc)
8328 return rc;
8329 }
8330 /* Stop the primary connection: */
8331 /* ...halt the connection */
619c5cb6
VZ
8332 q_params.cmd = BNX2X_Q_CMD_HALT;
8333 rc = bnx2x_queue_state_change(bp, &q_params);
8334 if (rc)
da5a662a 8335 return rc;
a2fbb9ea 8336
6383c0b3 8337 /* ...terminate the connection */
619c5cb6 8338 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
6383c0b3
AE
8339 memset(&q_params.params.terminate, 0,
8340 sizeof(q_params.params.terminate));
8341 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
619c5cb6
VZ
8342 rc = bnx2x_queue_state_change(bp, &q_params);
8343 if (rc)
523224a3 8344 return rc;
6383c0b3 8345 /* ...delete cfc entry */
619c5cb6 8346 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
6383c0b3
AE
8347 memset(&q_params.params.cfc_del, 0,
8348 sizeof(q_params.params.cfc_del));
8349 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
619c5cb6 8350 return bnx2x_queue_state_change(bp, &q_params);
523224a3
DK
8351}
8352
8353
34f80b04
EG
8354static void bnx2x_reset_func(struct bnx2x *bp)
8355{
8356 int port = BP_PORT(bp);
8357 int func = BP_FUNC(bp);
f2e0899f 8358 int i;
523224a3
DK
8359
8360 /* Disable the function in the FW */
8361 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8362 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8363 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8364 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8365
8366 /* FP SBs */
ec6ba945 8367 for_each_eth_queue(bp, i) {
523224a3 8368 struct bnx2x_fastpath *fp = &bp->fp[i];
619c5cb6 8369 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6383c0b3
AE
8370 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8371 SB_DISABLED);
523224a3
DK
8372 }
8373
55c11941
MS
8374 if (CNIC_LOADED(bp))
8375 /* CNIC SB */
8376 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8377 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8378 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8379
523224a3 8380 /* SP SB */
619c5cb6 8381 REG_WR8(bp, BAR_CSTRORM_INTMEM +
2de67439
YM
8382 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8383 SB_DISABLED);
523224a3
DK
8384
8385 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8386 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8387 0);
34f80b04
EG
8388
8389 /* Configure IGU */
f2e0899f
DK
8390 if (bp->common.int_block == INT_BLOCK_HC) {
8391 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8392 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8393 } else {
8394 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8395 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8396 }
34f80b04 8397
55c11941
MS
8398 if (CNIC_LOADED(bp)) {
8399 /* Disable Timer scan */
8400 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8401 /*
8402 * Wait for at least 10ms and up to 2 second for the timers
8403 * scan to complete
8404 */
8405 for (i = 0; i < 200; i++) {
8406 msleep(10);
8407 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8408 break;
8409 }
37b091ba 8410 }
34f80b04 8411 /* Clear ILT */
f2e0899f
DK
8412 bnx2x_clear_func_ilt(bp, func);
8413
8414 /* Timers workaround bug for E2: if this is vnic-3,
8415 * we need to set the entire ilt range for this timers.
8416 */
619c5cb6 8417 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
f2e0899f
DK
8418 struct ilt_client_info ilt_cli;
8419 /* use dummy TM client */
8420 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8421 ilt_cli.start = 0;
8422 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8423 ilt_cli.client_num = ILT_CLIENT_TM;
8424
8425 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8426 }
8427
8428 /* this assumes that reset_port() called before reset_func()*/
619c5cb6 8429 if (!CHIP_IS_E1x(bp))
f2e0899f 8430 bnx2x_pf_disable(bp);
523224a3
DK
8431
8432 bp->dmae_ready = 0;
34f80b04
EG
8433}
8434
8435static void bnx2x_reset_port(struct bnx2x *bp)
8436{
8437 int port = BP_PORT(bp);
8438 u32 val;
8439
619c5cb6
VZ
8440 /* Reset physical Link */
8441 bnx2x__link_reset(bp);
8442
34f80b04
EG
8443 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8444
8445 /* Do not rcv packets to BRB */
8446 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8447 /* Do not direct rcv packets that are not for MCP to the BRB */
8448 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8449 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8450
8451 /* Configure AEU */
8452 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8453
8454 msleep(100);
8455 /* Check for BRB port occupancy */
8456 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8457 if (val)
8458 DP(NETIF_MSG_IFDOWN,
33471629 8459 "BRB1 is not empty %d blocks are occupied\n", val);
34f80b04
EG
8460
8461 /* TODO: Close Doorbell port? */
8462}
8463
1191cb83 8464static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
34f80b04 8465{
3b603066 8466 struct bnx2x_func_state_params func_params = {NULL};
34f80b04 8467
619c5cb6
VZ
8468 /* Prepare parameters for function state transitions */
8469 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
34f80b04 8470
619c5cb6
VZ
8471 func_params.f_obj = &bp->func_obj;
8472 func_params.cmd = BNX2X_F_CMD_HW_RESET;
34f80b04 8473
619c5cb6 8474 func_params.params.hw_init.load_phase = load_code;
49d66772 8475
619c5cb6 8476 return bnx2x_func_state_change(bp, &func_params);
34f80b04
EG
8477}
8478
1191cb83 8479static int bnx2x_func_stop(struct bnx2x *bp)
ec6ba945 8480{
3b603066 8481 struct bnx2x_func_state_params func_params = {NULL};
619c5cb6 8482 int rc;
228241eb 8483
619c5cb6
VZ
8484 /* Prepare parameters for function state transitions */
8485 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8486 func_params.f_obj = &bp->func_obj;
8487 func_params.cmd = BNX2X_F_CMD_STOP;
da5a662a 8488
619c5cb6
VZ
8489 /*
8490 * Try to stop the function the 'good way'. If fails (in case
8491 * of a parity error during bnx2x_chip_cleanup()) and we are
8492 * not in a debug mode, perform a state transaction in order to
8493 * enable further HW_RESET transaction.
8494 */
8495 rc = bnx2x_func_state_change(bp, &func_params);
8496 if (rc) {
34f80b04 8497#ifdef BNX2X_STOP_ON_ERROR
619c5cb6 8498 return rc;
34f80b04 8499#else
51c1a580 8500 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
619c5cb6
VZ
8501 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8502 return bnx2x_func_state_change(bp, &func_params);
34f80b04 8503#endif
228241eb 8504 }
a2fbb9ea 8505
619c5cb6
VZ
8506 return 0;
8507}
523224a3 8508
619c5cb6
VZ
8509/**
8510 * bnx2x_send_unload_req - request unload mode from the MCP.
8511 *
8512 * @bp: driver handle
8513 * @unload_mode: requested function's unload mode
8514 *
8515 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8516 */
8517u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8518{
8519 u32 reset_code = 0;
8520 int port = BP_PORT(bp);
3101c2bc 8521
619c5cb6 8522 /* Select the UNLOAD request mode */
65abd74d
YG
8523 if (unload_mode == UNLOAD_NORMAL)
8524 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8525
7d0446c2 8526 else if (bp->flags & NO_WOL_FLAG)
65abd74d 8527 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
65abd74d 8528
7d0446c2 8529 else if (bp->wol) {
65abd74d
YG
8530 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8531 u8 *mac_addr = bp->dev->dev_addr;
8532 u32 val;
f9977903
DK
8533 u16 pmc;
8534
65abd74d 8535 /* The mac address is written to entries 1-4 to
f9977903
DK
8536 * preserve entry 0 which is used by the PMF
8537 */
3395a033 8538 u8 entry = (BP_VN(bp) + 1)*8;
65abd74d
YG
8539
8540 val = (mac_addr[0] << 8) | mac_addr[1];
8541 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8542
8543 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8544 (mac_addr[4] << 8) | mac_addr[5];
8545 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8546
f9977903
DK
8547 /* Enable the PME and clear the status */
8548 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8549 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8550 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8551
65abd74d
YG
8552 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8553
8554 } else
8555 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
da5a662a 8556
619c5cb6
VZ
8557 /* Send the request to the MCP */
8558 if (!BP_NOMCP(bp))
8559 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8560 else {
8561 int path = BP_PATH(bp);
8562
51c1a580 8563 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8564 path, load_count[path][0], load_count[path][1],
8565 load_count[path][2]);
8566 load_count[path][0]--;
8567 load_count[path][1 + port]--;
51c1a580 8568 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
619c5cb6
VZ
8569 path, load_count[path][0], load_count[path][1],
8570 load_count[path][2]);
8571 if (load_count[path][0] == 0)
8572 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8573 else if (load_count[path][1 + port] == 0)
8574 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8575 else
8576 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8577 }
8578
8579 return reset_code;
8580}
8581
8582/**
8583 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8584 *
8585 * @bp: driver handle
5d07d868 8586 * @keep_link: true iff link should be kept up
619c5cb6 8587 */
5d07d868 8588void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
619c5cb6 8589{
5d07d868
YM
8590 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8591
619c5cb6
VZ
8592 /* Report UNLOAD_DONE to MCP */
8593 if (!BP_NOMCP(bp))
5d07d868 8594 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
619c5cb6
VZ
8595}
8596
1191cb83 8597static int bnx2x_func_wait_started(struct bnx2x *bp)
6debea87
DK
8598{
8599 int tout = 50;
8600 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8601
8602 if (!bp->port.pmf)
8603 return 0;
8604
8605 /*
8606 * (assumption: No Attention from MCP at this stage)
8607 * PMF probably in the middle of TXdisable/enable transaction
8608 * 1. Sync IRS for default SB
8609 * 2. Sync SP queue - this guarantes us that attention handling started
8610 * 3. Wait, that TXdisable/enable transaction completes
8611 *
8612 * 1+2 guranty that if DCBx attention was scheduled it already changed
8613 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8614 * received complettion for the transaction the state is TX_STOPPED.
8615 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8616 * transaction.
8617 */
8618
8619 /* make sure default SB ISR is done */
8620 if (msix)
8621 synchronize_irq(bp->msix_table[0].vector);
8622 else
8623 synchronize_irq(bp->pdev->irq);
8624
8625 flush_workqueue(bnx2x_wq);
8626
8627 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8628 BNX2X_F_STATE_STARTED && tout--)
8629 msleep(20);
8630
8631 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8632 BNX2X_F_STATE_STARTED) {
8633#ifdef BNX2X_STOP_ON_ERROR
51c1a580 8634 BNX2X_ERR("Wrong function state\n");
6debea87
DK
8635 return -EBUSY;
8636#else
8637 /*
8638 * Failed to complete the transaction in a "good way"
8639 * Force both transactions with CLR bit
8640 */
3b603066 8641 struct bnx2x_func_state_params func_params = {NULL};
6debea87 8642
51c1a580
MS
8643 DP(NETIF_MSG_IFDOWN,
8644 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
6debea87
DK
8645
8646 func_params.f_obj = &bp->func_obj;
8647 __set_bit(RAMROD_DRV_CLR_ONLY,
8648 &func_params.ramrod_flags);
8649
8650 /* STARTED-->TX_ST0PPED */
8651 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8652 bnx2x_func_state_change(bp, &func_params);
8653
8654 /* TX_ST0PPED-->STARTED */
8655 func_params.cmd = BNX2X_F_CMD_TX_START;
8656 return bnx2x_func_state_change(bp, &func_params);
8657#endif
8658 }
8659
8660 return 0;
8661}
8662
5d07d868 8663void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
619c5cb6
VZ
8664{
8665 int port = BP_PORT(bp);
6383c0b3
AE
8666 int i, rc = 0;
8667 u8 cos;
3b603066 8668 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6
VZ
8669 u32 reset_code;
8670
8671 /* Wait until tx fastpath tasks complete */
8672 for_each_tx_queue(bp, i) {
8673 struct bnx2x_fastpath *fp = &bp->fp[i];
8674
6383c0b3 8675 for_each_cos_in_tx_queue(fp, cos)
65565884 8676 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
619c5cb6
VZ
8677#ifdef BNX2X_STOP_ON_ERROR
8678 if (rc)
8679 return;
8680#endif
8681 }
8682
8683 /* Give HW time to discard old tx messages */
0926d499 8684 usleep_range(1000, 2000);
619c5cb6
VZ
8685
8686 /* Clean all ETH MACs */
15192a8c
BW
8687 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8688 false);
619c5cb6
VZ
8689 if (rc < 0)
8690 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8691
8692 /* Clean up UC list */
15192a8c 8693 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
619c5cb6
VZ
8694 true);
8695 if (rc < 0)
51c1a580
MS
8696 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8697 rc);
619c5cb6
VZ
8698
8699 /* Disable LLH */
8700 if (!CHIP_IS_E1(bp))
8701 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8702
8703 /* Set "drop all" (stop Rx).
8704 * We need to take a netif_addr_lock() here in order to prevent
8705 * a race between the completion code and this code.
8706 */
8707 netif_addr_lock_bh(bp->dev);
8708 /* Schedule the rx_mode command */
8709 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8710 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8711 else
8712 bnx2x_set_storm_rx_mode(bp);
8713
8714 /* Cleanup multicast configuration */
8715 rparam.mcast_obj = &bp->mcast_obj;
8716 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8717 if (rc < 0)
8718 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8719
8720 netif_addr_unlock_bh(bp->dev);
8721
f1929b01 8722 bnx2x_iov_chip_cleanup(bp);
619c5cb6 8723
6debea87
DK
8724
8725 /*
8726 * Send the UNLOAD_REQUEST to the MCP. This will return if
8727 * this function should perform FUNC, PORT or COMMON HW
8728 * reset.
8729 */
8730 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8731
8732 /*
8733 * (assumption: No Attention from MCP at this stage)
8734 * PMF probably in the middle of TXdisable/enable transaction
8735 */
8736 rc = bnx2x_func_wait_started(bp);
8737 if (rc) {
8738 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8739#ifdef BNX2X_STOP_ON_ERROR
8740 return;
8741#endif
8742 }
8743
34f80b04 8744 /* Close multi and leading connections
619c5cb6
VZ
8745 * Completions for ramrods are collected in a synchronous way
8746 */
55c11941 8747 for_each_eth_queue(bp, i)
619c5cb6 8748 if (bnx2x_stop_queue(bp, i))
523224a3
DK
8749#ifdef BNX2X_STOP_ON_ERROR
8750 return;
8751#else
228241eb 8752 goto unload_error;
523224a3 8753#endif
55c11941
MS
8754
8755 if (CNIC_LOADED(bp)) {
8756 for_each_cnic_queue(bp, i)
8757 if (bnx2x_stop_queue(bp, i))
8758#ifdef BNX2X_STOP_ON_ERROR
8759 return;
8760#else
8761 goto unload_error;
8762#endif
8763 }
8764
619c5cb6
VZ
8765 /* If SP settings didn't get completed so far - something
8766 * very wrong has happen.
8767 */
8768 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8769 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
a2fbb9ea 8770
619c5cb6
VZ
8771#ifndef BNX2X_STOP_ON_ERROR
8772unload_error:
8773#endif
523224a3 8774 rc = bnx2x_func_stop(bp);
da5a662a 8775 if (rc) {
523224a3 8776 BNX2X_ERR("Function stop failed!\n");
da5a662a 8777#ifdef BNX2X_STOP_ON_ERROR
523224a3 8778 return;
523224a3 8779#endif
34f80b04 8780 }
a2fbb9ea 8781
523224a3
DK
8782 /* Disable HW interrupts, NAPI */
8783 bnx2x_netif_stop(bp, 1);
26614ba5
MS
8784 /* Delete all NAPI objects */
8785 bnx2x_del_all_napi(bp);
55c11941
MS
8786 if (CNIC_LOADED(bp))
8787 bnx2x_del_all_napi_cnic(bp);
523224a3
DK
8788
8789 /* Release IRQs */
d6214d7a 8790 bnx2x_free_irq(bp);
523224a3 8791
a2fbb9ea 8792 /* Reset the chip */
619c5cb6
VZ
8793 rc = bnx2x_reset_hw(bp, reset_code);
8794 if (rc)
8795 BNX2X_ERR("HW_RESET failed\n");
a2fbb9ea 8796
356e2385 8797
619c5cb6 8798 /* Report UNLOAD_DONE to MCP */
5d07d868 8799 bnx2x_send_unload_done(bp, keep_link);
72fd0718
VZ
8800}
8801
9f6c9258 8802void bnx2x_disable_close_the_gate(struct bnx2x *bp)
72fd0718
VZ
8803{
8804 u32 val;
8805
51c1a580 8806 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
72fd0718
VZ
8807
8808 if (CHIP_IS_E1(bp)) {
8809 int port = BP_PORT(bp);
8810 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8811 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8812
8813 val = REG_RD(bp, addr);
8814 val &= ~(0x300);
8815 REG_WR(bp, addr, val);
619c5cb6 8816 } else {
72fd0718
VZ
8817 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8818 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8819 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8820 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8821 }
8822}
8823
72fd0718
VZ
8824/* Close gates #2, #3 and #4: */
8825static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8826{
c9ee9206 8827 u32 val;
72fd0718
VZ
8828
8829 /* Gates #2 and #4a are closed/opened for "not E1" only */
8830 if (!CHIP_IS_E1(bp)) {
8831 /* #4 */
c9ee9206 8832 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
72fd0718 8833 /* #2 */
c9ee9206 8834 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
72fd0718
VZ
8835 }
8836
8837 /* #3 */
c9ee9206
VZ
8838 if (CHIP_IS_E1x(bp)) {
8839 /* Prevent interrupts from HC on both ports */
8840 val = REG_RD(bp, HC_REG_CONFIG_1);
8841 REG_WR(bp, HC_REG_CONFIG_1,
8842 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8843 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8844
8845 val = REG_RD(bp, HC_REG_CONFIG_0);
8846 REG_WR(bp, HC_REG_CONFIG_0,
8847 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8848 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8849 } else {
8850 /* Prevent incomming interrupts in IGU */
8851 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8852
8853 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8854 (!close) ?
8855 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8856 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8857 }
72fd0718 8858
51c1a580 8859 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
72fd0718
VZ
8860 close ? "closing" : "opening");
8861 mmiowb();
8862}
8863
8864#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8865
8866static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8867{
8868 /* Do some magic... */
8869 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8870 *magic_val = val & SHARED_MF_CLP_MAGIC;
8871 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8872}
8873
e8920674
DK
8874/**
8875 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
72fd0718 8876 *
e8920674
DK
8877 * @bp: driver handle
8878 * @magic_val: old value of the `magic' bit.
72fd0718
VZ
8879 */
8880static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8881{
8882 /* Restore the `magic' bit value... */
72fd0718
VZ
8883 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8884 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8885 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8886}
8887
f85582f8 8888/**
e8920674 8889 * bnx2x_reset_mcp_prep - prepare for MCP reset.
72fd0718 8890 *
e8920674
DK
8891 * @bp: driver handle
8892 * @magic_val: old value of 'magic' bit.
8893 *
8894 * Takes care of CLP configurations.
72fd0718
VZ
8895 */
8896static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8897{
8898 u32 shmem;
8899 u32 validity_offset;
8900
51c1a580 8901 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
72fd0718
VZ
8902
8903 /* Set `magic' bit in order to save MF config */
8904 if (!CHIP_IS_E1(bp))
8905 bnx2x_clp_reset_prep(bp, magic_val);
8906
8907 /* Get shmem offset */
8908 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
c55e771b
BW
8909 validity_offset =
8910 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
72fd0718
VZ
8911
8912 /* Clear validity map flags */
8913 if (shmem > 0)
8914 REG_WR(bp, shmem + validity_offset, 0);
8915}
8916
8917#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8918#define MCP_ONE_TIMEOUT 100 /* 100 ms */
8919
e8920674
DK
8920/**
8921 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
72fd0718 8922 *
e8920674 8923 * @bp: driver handle
72fd0718 8924 */
1191cb83 8925static void bnx2x_mcp_wait_one(struct bnx2x *bp)
72fd0718
VZ
8926{
8927 /* special handling for emulation and FPGA,
8928 wait 10 times longer */
8929 if (CHIP_REV_IS_SLOW(bp))
8930 msleep(MCP_ONE_TIMEOUT*10);
8931 else
8932 msleep(MCP_ONE_TIMEOUT);
8933}
8934
1b6e2ceb
DK
8935/*
8936 * initializes bp->common.shmem_base and waits for validity signature to appear
8937 */
8938static int bnx2x_init_shmem(struct bnx2x *bp)
72fd0718 8939{
1b6e2ceb
DK
8940 int cnt = 0;
8941 u32 val = 0;
72fd0718 8942
1b6e2ceb
DK
8943 do {
8944 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8945 if (bp->common.shmem_base) {
8946 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8947 if (val & SHR_MEM_VALIDITY_MB)
8948 return 0;
8949 }
72fd0718 8950
1b6e2ceb 8951 bnx2x_mcp_wait_one(bp);
72fd0718 8952
1b6e2ceb 8953 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
72fd0718 8954
1b6e2ceb 8955 BNX2X_ERR("BAD MCP validity signature\n");
72fd0718 8956
1b6e2ceb
DK
8957 return -ENODEV;
8958}
72fd0718 8959
1b6e2ceb
DK
8960static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8961{
8962 int rc = bnx2x_init_shmem(bp);
72fd0718 8963
72fd0718
VZ
8964 /* Restore the `magic' bit value */
8965 if (!CHIP_IS_E1(bp))
8966 bnx2x_clp_reset_done(bp, magic_val);
8967
8968 return rc;
8969}
8970
8971static void bnx2x_pxp_prep(struct bnx2x *bp)
8972{
8973 if (!CHIP_IS_E1(bp)) {
8974 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8975 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
72fd0718
VZ
8976 mmiowb();
8977 }
8978}
8979
8980/*
8981 * Reset the whole chip except for:
8982 * - PCIE core
8983 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8984 * one reset bit)
8985 * - IGU
8986 * - MISC (including AEU)
8987 * - GRC
8988 * - RBCN, RBCP
8989 */
c9ee9206 8990static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
72fd0718
VZ
8991{
8992 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8736c826 8993 u32 global_bits2, stay_reset2;
c9ee9206
VZ
8994
8995 /*
8996 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8997 * (per chip) blocks.
8998 */
8999 global_bits2 =
9000 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9001 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
72fd0718 9002
c55e771b
BW
9003 /* Don't reset the following blocks.
9004 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9005 * reset, as in 4 port device they might still be owned
9006 * by the MCP (there is only one leader per path).
9007 */
72fd0718
VZ
9008 not_reset_mask1 =
9009 MISC_REGISTERS_RESET_REG_1_RST_HC |
9010 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9011 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9012
9013 not_reset_mask2 =
c9ee9206 9014 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
72fd0718
VZ
9015 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9016 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9017 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9018 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9019 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9020 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8736c826
VZ
9021 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9022 MISC_REGISTERS_RESET_REG_2_RST_ATC |
c55e771b
BW
9023 MISC_REGISTERS_RESET_REG_2_PGLC |
9024 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9025 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9026 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9027 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9028 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9029 MISC_REGISTERS_RESET_REG_2_UMAC1;
72fd0718 9030
8736c826
VZ
9031 /*
9032 * Keep the following blocks in reset:
9033 * - all xxMACs are handled by the bnx2x_link code.
9034 */
9035 stay_reset2 =
8736c826
VZ
9036 MISC_REGISTERS_RESET_REG_2_XMAC |
9037 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9038
9039 /* Full reset masks according to the chip */
72fd0718
VZ
9040 reset_mask1 = 0xffffffff;
9041
9042 if (CHIP_IS_E1(bp))
9043 reset_mask2 = 0xffff;
8736c826 9044 else if (CHIP_IS_E1H(bp))
72fd0718 9045 reset_mask2 = 0x1ffff;
8736c826
VZ
9046 else if (CHIP_IS_E2(bp))
9047 reset_mask2 = 0xfffff;
9048 else /* CHIP_IS_E3 */
9049 reset_mask2 = 0x3ffffff;
c9ee9206
VZ
9050
9051 /* Don't reset global blocks unless we need to */
9052 if (!global)
9053 reset_mask2 &= ~global_bits2;
9054
9055 /*
9056 * In case of attention in the QM, we need to reset PXP
9057 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9058 * because otherwise QM reset would release 'close the gates' shortly
9059 * before resetting the PXP, then the PSWRQ would send a write
9060 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9061 * read the payload data from PSWWR, but PSWWR would not
9062 * respond. The write queue in PGLUE would stuck, dmae commands
9063 * would not return. Therefore it's important to reset the second
9064 * reset register (containing the
9065 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9066 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9067 * bit).
9068 */
72fd0718
VZ
9069 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9070 reset_mask2 & (~not_reset_mask2));
9071
c9ee9206
VZ
9072 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9073 reset_mask1 & (~not_reset_mask1));
9074
72fd0718
VZ
9075 barrier();
9076 mmiowb();
9077
8736c826
VZ
9078 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9079 reset_mask2 & (~stay_reset2));
9080
9081 barrier();
9082 mmiowb();
9083
c9ee9206 9084 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
72fd0718
VZ
9085 mmiowb();
9086}
9087
c9ee9206
VZ
9088/**
9089 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9090 * It should get cleared in no more than 1s.
9091 *
9092 * @bp: driver handle
9093 *
9094 * It should get cleared in no more than 1s. Returns 0 if
9095 * pending writes bit gets cleared.
9096 */
9097static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9098{
9099 u32 cnt = 1000;
9100 u32 pend_bits = 0;
9101
9102 do {
9103 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9104
9105 if (pend_bits == 0)
9106 break;
9107
0926d499 9108 usleep_range(1000, 2000);
c9ee9206
VZ
9109 } while (cnt-- > 0);
9110
9111 if (cnt <= 0) {
9112 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9113 pend_bits);
9114 return -EBUSY;
9115 }
9116
9117 return 0;
9118}
9119
9120static int bnx2x_process_kill(struct bnx2x *bp, bool global)
72fd0718
VZ
9121{
9122 int cnt = 1000;
9123 u32 val = 0;
9124 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
2de67439 9125 u32 tags_63_32 = 0;
72fd0718
VZ
9126
9127 /* Empty the Tetris buffer, wait for 1s */
9128 do {
9129 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9130 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9131 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9132 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9133 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
c55e771b
BW
9134 if (CHIP_IS_E3(bp))
9135 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9136
72fd0718
VZ
9137 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9138 ((port_is_idle_0 & 0x1) == 0x1) &&
9139 ((port_is_idle_1 & 0x1) == 0x1) &&
c55e771b
BW
9140 (pgl_exp_rom2 == 0xffffffff) &&
9141 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
72fd0718 9142 break;
0926d499 9143 usleep_range(1000, 2000);
72fd0718
VZ
9144 } while (cnt-- > 0);
9145
9146 if (cnt <= 0) {
51c1a580
MS
9147 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9148 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
9149 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9150 pgl_exp_rom2);
9151 return -EAGAIN;
9152 }
9153
9154 barrier();
9155
9156 /* Close gates #2, #3 and #4 */
9157 bnx2x_set_234_gates(bp, true);
9158
c9ee9206
VZ
9159 /* Poll for IGU VQs for 57712 and newer chips */
9160 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9161 return -EAGAIN;
9162
9163
72fd0718
VZ
9164 /* TBD: Indicate that "process kill" is in progress to MCP */
9165
9166 /* Clear "unprepared" bit */
9167 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9168 barrier();
9169
9170 /* Make sure all is written to the chip before the reset */
9171 mmiowb();
9172
9173 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9174 * PSWHST, GRC and PSWRD Tetris buffer.
9175 */
0926d499 9176 usleep_range(1000, 2000);
72fd0718
VZ
9177
9178 /* Prepare to chip reset: */
9179 /* MCP */
c9ee9206
VZ
9180 if (global)
9181 bnx2x_reset_mcp_prep(bp, &val);
72fd0718
VZ
9182
9183 /* PXP */
9184 bnx2x_pxp_prep(bp);
9185 barrier();
9186
9187 /* reset the chip */
c9ee9206 9188 bnx2x_process_kill_chip_reset(bp, global);
72fd0718
VZ
9189 barrier();
9190
9191 /* Recover after reset: */
9192 /* MCP */
c9ee9206 9193 if (global && bnx2x_reset_mcp_comp(bp, val))
72fd0718
VZ
9194 return -EAGAIN;
9195
c9ee9206
VZ
9196 /* TBD: Add resetting the NO_MCP mode DB here */
9197
72fd0718
VZ
9198 /* Open the gates #2, #3 and #4 */
9199 bnx2x_set_234_gates(bp, false);
9200
9201 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9202 * reset state, re-enable attentions. */
9203
a2fbb9ea
ET
9204 return 0;
9205}
9206
910cc727 9207static int bnx2x_leader_reset(struct bnx2x *bp)
72fd0718
VZ
9208{
9209 int rc = 0;
c9ee9206 9210 bool global = bnx2x_reset_is_global(bp);
95c6c616
AE
9211 u32 load_code;
9212
9213 /* if not going to reset MCP - load "fake" driver to reset HW while
9214 * driver is owner of the HW
9215 */
9216 if (!global && !BP_NOMCP(bp)) {
5d07d868
YM
9217 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9218 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
95c6c616
AE
9219 if (!load_code) {
9220 BNX2X_ERR("MCP response failure, aborting\n");
9221 rc = -EAGAIN;
9222 goto exit_leader_reset;
9223 }
9224 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9225 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9226 BNX2X_ERR("MCP unexpected resp, aborting\n");
9227 rc = -EAGAIN;
9228 goto exit_leader_reset2;
9229 }
9230 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9231 if (!load_code) {
9232 BNX2X_ERR("MCP response failure, aborting\n");
9233 rc = -EAGAIN;
9234 goto exit_leader_reset2;
9235 }
9236 }
c9ee9206 9237
72fd0718 9238 /* Try to recover after the failure */
c9ee9206 9239 if (bnx2x_process_kill(bp, global)) {
51c1a580
MS
9240 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9241 BP_PATH(bp));
72fd0718 9242 rc = -EAGAIN;
95c6c616 9243 goto exit_leader_reset2;
72fd0718
VZ
9244 }
9245
c9ee9206
VZ
9246 /*
9247 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9248 * state.
9249 */
72fd0718 9250 bnx2x_set_reset_done(bp);
c9ee9206
VZ
9251 if (global)
9252 bnx2x_clear_reset_global(bp);
72fd0718 9253
95c6c616
AE
9254exit_leader_reset2:
9255 /* unload "fake driver" if it was loaded */
9256 if (!global && !BP_NOMCP(bp)) {
9257 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9258 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9259 }
72fd0718
VZ
9260exit_leader_reset:
9261 bp->is_leader = 0;
c9ee9206
VZ
9262 bnx2x_release_leader_lock(bp);
9263 smp_mb();
72fd0718
VZ
9264 return rc;
9265}
9266
1191cb83 9267static void bnx2x_recovery_failed(struct bnx2x *bp)
c9ee9206
VZ
9268{
9269 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9270
9271 /* Disconnect this device */
9272 netif_device_detach(bp->dev);
9273
9274 /*
9275 * Block ifup for all function on this engine until "process kill"
9276 * or power cycle.
9277 */
9278 bnx2x_set_reset_in_progress(bp);
9279
9280 /* Shut down the power */
9281 bnx2x_set_power_state(bp, PCI_D3hot);
9282
9283 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9284
9285 smp_mb();
9286}
9287
9288/*
9289 * Assumption: runs under rtnl lock. This together with the fact
6383c0b3 9290 * that it's called only from bnx2x_sp_rtnl() ensure that it
72fd0718
VZ
9291 * will never be called when netif_running(bp->dev) is false.
9292 */
9293static void bnx2x_parity_recover(struct bnx2x *bp)
9294{
c9ee9206 9295 bool global = false;
7a752993 9296 u32 error_recovered, error_unrecovered;
95c6c616 9297 bool is_parity;
c9ee9206 9298
72fd0718
VZ
9299 DP(NETIF_MSG_HW, "Handling parity\n");
9300 while (1) {
9301 switch (bp->recovery_state) {
9302 case BNX2X_RECOVERY_INIT:
9303 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
95c6c616
AE
9304 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9305 WARN_ON(!is_parity);
c9ee9206 9306
72fd0718 9307 /* Try to get a LEADER_LOCK HW lock */
c9ee9206
VZ
9308 if (bnx2x_trylock_leader_lock(bp)) {
9309 bnx2x_set_reset_in_progress(bp);
9310 /*
9311 * Check if there is a global attention and if
9312 * there was a global attention, set the global
9313 * reset bit.
9314 */
9315
9316 if (global)
9317 bnx2x_set_reset_global(bp);
9318
72fd0718 9319 bp->is_leader = 1;
c9ee9206 9320 }
72fd0718
VZ
9321
9322 /* Stop the driver */
9323 /* If interface has been removed - break */
5d07d868 9324 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
72fd0718
VZ
9325 return;
9326
9327 bp->recovery_state = BNX2X_RECOVERY_WAIT;
c9ee9206 9328
c9ee9206
VZ
9329 /* Ensure "is_leader", MCP command sequence and
9330 * "recovery_state" update values are seen on other
9331 * CPUs.
72fd0718 9332 */
c9ee9206 9333 smp_mb();
72fd0718
VZ
9334 break;
9335
9336 case BNX2X_RECOVERY_WAIT:
9337 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9338 if (bp->is_leader) {
c9ee9206 9339 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3
AE
9340 bool other_load_status =
9341 bnx2x_get_load_status(bp, other_engine);
9342 bool load_status =
9343 bnx2x_get_load_status(bp, BP_PATH(bp));
c9ee9206
VZ
9344 global = bnx2x_reset_is_global(bp);
9345
9346 /*
9347 * In case of a parity in a global block, let
9348 * the first leader that performs a
9349 * leader_reset() reset the global blocks in
9350 * order to clear global attentions. Otherwise
9351 * the the gates will remain closed for that
9352 * engine.
9353 */
889b9af3
AE
9354 if (load_status ||
9355 (global && other_load_status)) {
72fd0718
VZ
9356 /* Wait until all other functions get
9357 * down.
9358 */
7be08a72 9359 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9360 HZ/10);
9361 return;
9362 } else {
9363 /* If all other functions got down -
9364 * try to bring the chip back to
9365 * normal. In any case it's an exit
9366 * point for a leader.
9367 */
c9ee9206
VZ
9368 if (bnx2x_leader_reset(bp)) {
9369 bnx2x_recovery_failed(bp);
72fd0718
VZ
9370 return;
9371 }
9372
c9ee9206
VZ
9373 /* If we are here, means that the
9374 * leader has succeeded and doesn't
9375 * want to be a leader any more. Try
9376 * to continue as a none-leader.
9377 */
9378 break;
72fd0718
VZ
9379 }
9380 } else { /* non-leader */
c9ee9206 9381 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
72fd0718
VZ
9382 /* Try to get a LEADER_LOCK HW lock as
9383 * long as a former leader may have
9384 * been unloaded by the user or
9385 * released a leadership by another
9386 * reason.
9387 */
c9ee9206 9388 if (bnx2x_trylock_leader_lock(bp)) {
72fd0718
VZ
9389 /* I'm a leader now! Restart a
9390 * switch case.
9391 */
9392 bp->is_leader = 1;
9393 break;
9394 }
9395
7be08a72 9396 schedule_delayed_work(&bp->sp_rtnl_task,
72fd0718
VZ
9397 HZ/10);
9398 return;
9399
c9ee9206
VZ
9400 } else {
9401 /*
9402 * If there was a global attention, wait
9403 * for it to be cleared.
9404 */
9405 if (bnx2x_reset_is_global(bp)) {
9406 schedule_delayed_work(
7be08a72
AE
9407 &bp->sp_rtnl_task,
9408 HZ/10);
c9ee9206
VZ
9409 return;
9410 }
9411
7a752993
AE
9412 error_recovered =
9413 bp->eth_stats.recoverable_error;
9414 error_unrecovered =
9415 bp->eth_stats.unrecoverable_error;
95c6c616
AE
9416 bp->recovery_state =
9417 BNX2X_RECOVERY_NIC_LOADING;
9418 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
7a752993 9419 error_unrecovered++;
95c6c616 9420 netdev_err(bp->dev,
51c1a580 9421 "Recovery failed. Power cycle needed\n");
95c6c616
AE
9422 /* Disconnect this device */
9423 netif_device_detach(bp->dev);
9424 /* Shut down the power */
9425 bnx2x_set_power_state(
9426 bp, PCI_D3hot);
9427 smp_mb();
9428 } else {
c9ee9206
VZ
9429 bp->recovery_state =
9430 BNX2X_RECOVERY_DONE;
7a752993 9431 error_recovered++;
c9ee9206
VZ
9432 smp_mb();
9433 }
7a752993
AE
9434 bp->eth_stats.recoverable_error =
9435 error_recovered;
9436 bp->eth_stats.unrecoverable_error =
9437 error_unrecovered;
c9ee9206 9438
72fd0718
VZ
9439 return;
9440 }
9441 }
9442 default:
9443 return;
9444 }
9445 }
9446}
9447
56ad3152
MS
9448static int bnx2x_close(struct net_device *dev);
9449
72fd0718
VZ
9450/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9451 * scheduled on a general queue in order to prevent a dead lock.
9452 */
7be08a72 9453static void bnx2x_sp_rtnl_task(struct work_struct *work)
34f80b04 9454{
7be08a72 9455 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
34f80b04
EG
9456
9457 rtnl_lock();
9458
8395be5e
AE
9459 if (!netif_running(bp->dev)) {
9460 rtnl_unlock();
9461 return;
9462 }
7be08a72
AE
9463
9464 /* if stop on error is defined no recovery flows should be executed */
9465#ifdef BNX2X_STOP_ON_ERROR
51c1a580 9466 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
7be08a72 9467 "you will need to reboot when done\n");
b1fb8740 9468 goto sp_rtnl_not_reset;
7be08a72 9469#endif
34f80b04 9470
7be08a72
AE
9471 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9472 /*
b1fb8740
VZ
9473 * Clear all pending SP commands as we are going to reset the
9474 * function anyway.
7be08a72 9475 */
b1fb8740
VZ
9476 bp->sp_rtnl_state = 0;
9477 smp_mb();
9478
72fd0718 9479 bnx2x_parity_recover(bp);
b1fb8740 9480
8395be5e
AE
9481 rtnl_unlock();
9482 return;
b1fb8740
VZ
9483 }
9484
9485 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9486 /*
9487 * Clear all pending SP commands as we are going to reset the
9488 * function anyway.
9489 */
9490 bp->sp_rtnl_state = 0;
9491 smp_mb();
9492
5d07d868 9493 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
72fd0718 9494 bnx2x_nic_load(bp, LOAD_NORMAL);
b1fb8740 9495
8395be5e
AE
9496 rtnl_unlock();
9497 return;
72fd0718 9498 }
b1fb8740
VZ
9499#ifdef BNX2X_STOP_ON_ERROR
9500sp_rtnl_not_reset:
9501#endif
9502 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9503 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
a3348722
BW
9504 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9505 bnx2x_after_function_update(bp);
8304859a
AE
9506 /*
9507 * in case of fan failure we need to reset id if the "stop on error"
9508 * debug flag is set, since we trying to prevent permanent overheating
9509 * damage
9510 */
9511 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
51c1a580 9512 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8304859a
AE
9513 netif_device_detach(bp->dev);
9514 bnx2x_close(bp->dev);
8395be5e
AE
9515 rtnl_unlock();
9516 return;
8304859a
AE
9517 }
9518
381ac16b
AE
9519 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9520 DP(BNX2X_MSG_SP,
9521 "sending set mcast vf pf channel message from rtnl sp-task\n");
9522 bnx2x_vfpf_set_mcast(bp->dev);
9523 }
9524
9525 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
9526 &bp->sp_rtnl_state)) {
9527 DP(BNX2X_MSG_SP,
9528 "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
9529 bnx2x_vfpf_storm_rx_mode(bp);
9530 }
9531
8395be5e
AE
9532 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9533 * can be called from other contexts as well)
9534 */
34f80b04 9535 rtnl_unlock();
8395be5e 9536
6411280a 9537 /* enable SR-IOV if applicable */
8395be5e 9538 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
6411280a
AE
9539 &bp->sp_rtnl_state))
9540 bnx2x_enable_sriov(bp);
34f80b04
EG
9541}
9542
3deb8167
YR
9543static void bnx2x_period_task(struct work_struct *work)
9544{
9545 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9546
9547 if (!netif_running(bp->dev))
9548 goto period_task_exit;
9549
9550 if (CHIP_REV_IS_SLOW(bp)) {
9551 BNX2X_ERR("period task called on emulation, ignoring\n");
9552 goto period_task_exit;
9553 }
9554
9555 bnx2x_acquire_phy_lock(bp);
9556 /*
9557 * The barrier is needed to ensure the ordering between the writing to
9558 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9559 * the reading here.
9560 */
9561 smp_mb();
9562 if (bp->port.pmf) {
9563 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9564
9565 /* Re-queue task in 1 sec */
9566 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9567 }
9568
9569 bnx2x_release_phy_lock(bp);
9570period_task_exit:
9571 return;
9572}
9573
a2fbb9ea
ET
9574/*
9575 * Init service functions
9576 */
9577
b56e9670 9578u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
f2e0899f
DK
9579{
9580 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9581 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9582 return base + (BP_ABS_FUNC(bp)) * stride;
f1ef27ef
EG
9583}
9584
1ef1d45a
BW
9585static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9586 struct bnx2x_mac_vals *vals)
34f80b04 9587{
452427b0
YM
9588 u32 val, base_addr, offset, mask, reset_reg;
9589 bool mac_stopped = false;
9590 u8 port = BP_PORT(bp);
34f80b04 9591
1ef1d45a
BW
9592 /* reset addresses as they also mark which values were changed */
9593 vals->bmac_addr = 0;
9594 vals->umac_addr = 0;
9595 vals->xmac_addr = 0;
9596 vals->emac_addr = 0;
9597
452427b0 9598 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
f16da43b 9599
452427b0
YM
9600 if (!CHIP_IS_E3(bp)) {
9601 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9602 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9603 if ((mask & reset_reg) && val) {
9604 u32 wb_data[2];
9605 BNX2X_DEV_INFO("Disable bmac Rx\n");
9606 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9607 : NIG_REG_INGRESS_BMAC0_MEM;
9608 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9609 : BIGMAC_REGISTER_BMAC_CONTROL;
7a06a122 9610
452427b0
YM
9611 /*
9612 * use rd/wr since we cannot use dmae. This is safe
9613 * since MCP won't access the bus due to the request
9614 * to unload, and no function on the path can be
9615 * loaded at this time.
9616 */
9617 wb_data[0] = REG_RD(bp, base_addr + offset);
9618 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
1ef1d45a
BW
9619 vals->bmac_addr = base_addr + offset;
9620 vals->bmac_val[0] = wb_data[0];
9621 vals->bmac_val[1] = wb_data[1];
452427b0 9622 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1ef1d45a
BW
9623 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9624 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
452427b0
YM
9625
9626 }
9627 BNX2X_DEV_INFO("Disable emac Rx\n");
1ef1d45a
BW
9628 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9629 vals->emac_val = REG_RD(bp, vals->emac_addr);
9630 REG_WR(bp, vals->emac_addr, 0);
452427b0
YM
9631 mac_stopped = true;
9632 } else {
9633 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9634 BNX2X_DEV_INFO("Disable xmac Rx\n");
9635 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9636 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9637 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9638 val & ~(1 << 1));
9639 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9640 val | (1 << 1));
1ef1d45a
BW
9641 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9642 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9643 REG_WR(bp, vals->xmac_addr, 0);
452427b0
YM
9644 mac_stopped = true;
9645 }
9646 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9647 if (mask & reset_reg) {
9648 BNX2X_DEV_INFO("Disable umac Rx\n");
9649 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1ef1d45a
BW
9650 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9651 vals->umac_val = REG_RD(bp, vals->umac_addr);
9652 REG_WR(bp, vals->umac_addr, 0);
452427b0
YM
9653 mac_stopped = true;
9654 }
9655 }
9656
9657 if (mac_stopped)
9658 msleep(20);
9659
9660}
9661
9662#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9663#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9664#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9665#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9666
1dd06ae8 9667static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
452427b0
YM
9668{
9669 u16 rcq, bd;
9670 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9671
9672 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9673 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9674
9675 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9676 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9677
9678 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9679 port, bd, rcq);
9680}
9681
0329aba1 9682static int bnx2x_prev_mcp_done(struct bnx2x *bp)
452427b0 9683{
5d07d868
YM
9684 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9685 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
452427b0
YM
9686 if (!rc) {
9687 BNX2X_ERR("MCP response failure, aborting\n");
9688 return -EBUSY;
9689 }
9690
9691 return 0;
9692}
9693
c63da990
BW
9694static struct bnx2x_prev_path_list *
9695 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9696{
9697 struct bnx2x_prev_path_list *tmp_list;
9698
9699 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9700 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9701 bp->pdev->bus->number == tmp_list->bus &&
9702 BP_PATH(bp) == tmp_list->path)
9703 return tmp_list;
9704
9705 return NULL;
9706}
9707
0329aba1 9708static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
452427b0
YM
9709{
9710 struct bnx2x_prev_path_list *tmp_list;
9711 int rc = false;
9712
9713 if (down_trylock(&bnx2x_prev_sem))
9714 return false;
9715
9716 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9717 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9718 bp->pdev->bus->number == tmp_list->bus &&
9719 BP_PATH(bp) == tmp_list->path) {
9720 rc = true;
9721 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9722 BP_PATH(bp));
9723 break;
9724 }
9725 }
9726
9727 up(&bnx2x_prev_sem);
9728
9729 return rc;
9730}
9731
c63da990 9732static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
452427b0
YM
9733{
9734 struct bnx2x_prev_path_list *tmp_list;
9735 int rc;
9736
ea4b3857 9737 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
452427b0
YM
9738 if (!tmp_list) {
9739 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9740 return -ENOMEM;
9741 }
9742
9743 tmp_list->bus = bp->pdev->bus->number;
9744 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9745 tmp_list->path = BP_PATH(bp);
c63da990 9746 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
452427b0
YM
9747
9748 rc = down_interruptible(&bnx2x_prev_sem);
9749 if (rc) {
9750 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9751 kfree(tmp_list);
9752 } else {
9753 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9754 BP_PATH(bp));
9755 list_add(&tmp_list->list, &bnx2x_prev_list);
9756 up(&bnx2x_prev_sem);
9757 }
9758
9759 return rc;
9760}
9761
0329aba1 9762static int bnx2x_do_flr(struct bnx2x *bp)
452427b0 9763{
2a80eebc 9764 int i;
452427b0
YM
9765 u16 status;
9766 struct pci_dev *dev = bp->pdev;
9767
8eee694c
YM
9768
9769 if (CHIP_IS_E1x(bp)) {
9770 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9771 return -EINVAL;
9772 }
9773
9774 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9775 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9776 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9777 bp->common.bc_ver);
9778 return -EINVAL;
9779 }
452427b0 9780
452427b0
YM
9781 /* Wait for Transaction Pending bit clean */
9782 for (i = 0; i < 4; i++) {
9783 if (i)
9784 msleep((1 << (i - 1)) * 100);
9785
2a80eebc 9786 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
452427b0
YM
9787 if (!(status & PCI_EXP_DEVSTA_TRPND))
9788 goto clear;
9789 }
9790
9791 dev_err(&dev->dev,
9792 "transaction is not cleared; proceeding with reset anyway\n");
9793
9794clear:
452427b0 9795
8eee694c 9796 BNX2X_DEV_INFO("Initiating FLR\n");
452427b0
YM
9797 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9798
9799 return 0;
9800}
9801
0329aba1 9802static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
452427b0
YM
9803{
9804 int rc;
9805
9806 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9807
9808 /* Test if previous unload process was already finished for this path */
9809 if (bnx2x_prev_is_path_marked(bp))
9810 return bnx2x_prev_mcp_done(bp);
9811
04c46736
YM
9812 BNX2X_DEV_INFO("Path is unmarked\n");
9813
452427b0
YM
9814 /* If function has FLR capabilities, and existing FW version matches
9815 * the one required, then FLR will be sufficient to clean any residue
9816 * left by previous driver
9817 */
ad5afc89 9818 rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
8eee694c
YM
9819
9820 if (!rc) {
9821 /* fw version is good */
9822 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9823 rc = bnx2x_do_flr(bp);
9824 }
9825
9826 if (!rc) {
9827 /* FLR was performed */
9828 BNX2X_DEV_INFO("FLR successful\n");
9829 return 0;
9830 }
9831
9832 BNX2X_DEV_INFO("Could not FLR\n");
452427b0
YM
9833
9834 /* Close the MCP request, return failure*/
9835 rc = bnx2x_prev_mcp_done(bp);
9836 if (!rc)
9837 rc = BNX2X_PREV_WAIT_NEEDED;
9838
9839 return rc;
9840}
9841
0329aba1 9842static int bnx2x_prev_unload_common(struct bnx2x *bp)
452427b0
YM
9843{
9844 u32 reset_reg, tmp_reg = 0, rc;
c63da990 9845 bool prev_undi = false;
1ef1d45a
BW
9846 struct bnx2x_mac_vals mac_vals;
9847
452427b0
YM
9848 /* It is possible a previous function received 'common' answer,
9849 * but hasn't loaded yet, therefore creating a scenario of
9850 * multiple functions receiving 'common' on the same path.
9851 */
9852 BNX2X_DEV_INFO("Common unload Flow\n");
9853
1ef1d45a
BW
9854 memset(&mac_vals, 0, sizeof(mac_vals));
9855
452427b0
YM
9856 if (bnx2x_prev_is_path_marked(bp))
9857 return bnx2x_prev_mcp_done(bp);
9858
9859 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9860
9861 /* Reset should be performed after BRB is emptied */
9862 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9863 u32 timer_count = 1000;
452427b0
YM
9864
9865 /* Close the MAC Rx to prevent BRB from filling up */
1ef1d45a
BW
9866 bnx2x_prev_unload_close_mac(bp, &mac_vals);
9867
9868 /* close LLH filters towards the BRB */
9869 bnx2x_set_rx_filter(&bp->link_params, 0);
452427b0
YM
9870
9871 /* Check if the UNDI driver was previously loaded
34f80b04
EG
9872 * UNDI driver initializes CID offset for normal bell to 0x7
9873 */
452427b0
YM
9874 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9875 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9876 if (tmp_reg == 0x7) {
9877 BNX2X_DEV_INFO("UNDI previously loaded\n");
9878 prev_undi = true;
9879 /* clear the UNDI indication */
9880 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
a74801c5
YM
9881 /* clear possible idle check errors */
9882 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
34f80b04 9883 }
452427b0
YM
9884 }
9885 /* wait until BRB is empty */
9886 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9887 while (timer_count) {
9888 u32 prev_brb = tmp_reg;
34f80b04 9889
452427b0
YM
9890 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9891 if (!tmp_reg)
9892 break;
619c5cb6 9893
452427b0 9894 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
619c5cb6 9895
452427b0
YM
9896 /* reset timer as long as BRB actually gets emptied */
9897 if (prev_brb > tmp_reg)
9898 timer_count = 1000;
9899 else
9900 timer_count--;
da5a662a 9901
452427b0
YM
9902 /* If UNDI resides in memory, manually increment it */
9903 if (prev_undi)
9904 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
da5a662a 9905
452427b0 9906 udelay(10);
7a06a122 9907 }
452427b0
YM
9908
9909 if (!timer_count)
9910 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9911
34f80b04 9912 }
f16da43b 9913
452427b0
YM
9914 /* No packets are in the pipeline, path is ready for reset */
9915 bnx2x_reset_common(bp);
9916
1ef1d45a
BW
9917 if (mac_vals.xmac_addr)
9918 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
9919 if (mac_vals.umac_addr)
9920 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
9921 if (mac_vals.emac_addr)
9922 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
9923 if (mac_vals.bmac_addr) {
9924 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
9925 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
9926 }
9927
c63da990 9928 rc = bnx2x_prev_mark_path(bp, prev_undi);
452427b0
YM
9929 if (rc) {
9930 bnx2x_prev_mcp_done(bp);
9931 return rc;
9932 }
9933
9934 return bnx2x_prev_mcp_done(bp);
9935}
9936
24f06716
AE
9937/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9938 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9939 * the addresses of the transaction, resulting in was-error bit set in the pci
9940 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9941 * to clear the interrupt which detected this from the pglueb and the was done
9942 * bit
9943 */
0329aba1 9944static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
24f06716 9945{
4a25417c
AE
9946 if (!CHIP_IS_E1x(bp)) {
9947 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9948 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
04c46736
YM
9949 DP(BNX2X_MSG_SP,
9950 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
4a25417c
AE
9951 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9952 1 << BP_FUNC(bp));
9953 }
24f06716
AE
9954 }
9955}
9956
0329aba1 9957static int bnx2x_prev_unload(struct bnx2x *bp)
452427b0
YM
9958{
9959 int time_counter = 10;
9960 u32 rc, fw, hw_lock_reg, hw_lock_val;
c63da990 9961 struct bnx2x_prev_path_list *prev_list;
452427b0
YM
9962 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9963
24f06716
AE
9964 /* clear hw from errors which may have resulted from an interrupted
9965 * dmae transaction.
9966 */
9967 bnx2x_prev_interrupted_dmae(bp);
9968
9969 /* Release previously held locks */
452427b0
YM
9970 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9971 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9972 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9973
9974 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9975 if (hw_lock_val) {
9976 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9977 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9978 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9979 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9980 }
9981
9982 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9983 REG_WR(bp, hw_lock_reg, 0xffffffff);
9984 } else
9985 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9986
9987 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9988 BNX2X_DEV_INFO("Release previously held alr\n");
9989 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9990 }
9991
452427b0
YM
9992 do {
9993 /* Lock MCP using an unload request */
9994 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9995 if (!fw) {
9996 BNX2X_ERR("MCP response failure, aborting\n");
9997 rc = -EBUSY;
9998 break;
9999 }
10000
10001 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
10002 rc = bnx2x_prev_unload_common(bp);
10003 break;
10004 }
10005
10006 /* non-common reply from MCP night require looping */
10007 rc = bnx2x_prev_unload_uncommon(bp);
10008 if (rc != BNX2X_PREV_WAIT_NEEDED)
10009 break;
10010
10011 msleep(20);
10012 } while (--time_counter);
10013
10014 if (!time_counter || rc) {
10015 BNX2X_ERR("Failed unloading previous driver, aborting\n");
10016 rc = -EBUSY;
10017 }
10018
c63da990
BW
10019 /* Mark function if its port was used to boot from SAN */
10020 prev_list = bnx2x_prev_path_get_entry(bp);
10021 if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
10022 bp->link_params.feature_config_flags |=
10023 FEATURE_CONFIG_BOOT_FROM_SAN;
10024
452427b0
YM
10025 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10026
10027 return rc;
34f80b04
EG
10028}
10029
0329aba1 10030static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
34f80b04 10031{
1d187b34 10032 u32 val, val2, val3, val4, id, boot_mode;
72ce58c3 10033 u16 pmc;
34f80b04
EG
10034
10035 /* Get the chip revision id and number. */
10036 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10037 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10038 id = ((val & 0xffff) << 16);
10039 val = REG_RD(bp, MISC_REG_CHIP_REV);
10040 id |= ((val & 0xf) << 12);
10041 val = REG_RD(bp, MISC_REG_CHIP_METAL);
10042 id |= ((val & 0xff) << 4);
5a40e08e 10043 val = REG_RD(bp, MISC_REG_BOND_ID);
34f80b04
EG
10044 id |= (val & 0xf);
10045 bp->common.chip_id = id;
523224a3 10046
7e8e02df
BW
10047 /* force 57811 according to MISC register */
10048 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10049 if (CHIP_IS_57810(bp))
10050 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10051 (bp->common.chip_id & 0x0000FFFF);
10052 else if (CHIP_IS_57810_MF(bp))
10053 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10054 (bp->common.chip_id & 0x0000FFFF);
10055 bp->common.chip_id |= 0x1;
10056 }
10057
523224a3
DK
10058 /* Set doorbell size */
10059 bp->db_size = (1 << BNX2X_DB_SHIFT);
10060
619c5cb6 10061 if (!CHIP_IS_E1x(bp)) {
f2e0899f
DK
10062 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10063 if ((val & 1) == 0)
10064 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10065 else
10066 val = (val >> 1) & 1;
10067 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10068 "2_PORT_MODE");
10069 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10070 CHIP_2_PORT_MODE;
10071
10072 if (CHIP_MODE_IS_4_PORT(bp))
10073 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10074 else
10075 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10076 } else {
10077 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10078 bp->pfid = bp->pf_num; /* 0..7 */
10079 }
10080
51c1a580
MS
10081 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10082
f2e0899f
DK
10083 bp->link_params.chip_id = bp->common.chip_id;
10084 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
523224a3 10085
1c06328c
EG
10086 val = (REG_RD(bp, 0x2874) & 0x55);
10087 if ((bp->common.chip_id & 0x1) ||
10088 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10089 bp->flags |= ONE_PORT_FLAG;
10090 BNX2X_DEV_INFO("single port device\n");
10091 }
10092
34f80b04 10093 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
754a2f52 10094 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
34f80b04
EG
10095 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10096 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10097 bp->common.flash_size, bp->common.flash_size);
10098
1b6e2ceb
DK
10099 bnx2x_init_shmem(bp);
10100
619c5cb6
VZ
10101
10102
f2e0899f
DK
10103 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10104 MISC_REG_GENERIC_CR_1 :
10105 MISC_REG_GENERIC_CR_0));
1b6e2ceb 10106
34f80b04 10107 bp->link_params.shmem_base = bp->common.shmem_base;
a22f0788 10108 bp->link_params.shmem2_base = bp->common.shmem2_base;
b884d95b
YR
10109 if (SHMEM2_RD(bp, size) >
10110 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10111 bp->link_params.lfa_base =
10112 REG_RD(bp, bp->common.shmem2_base +
10113 (u32)offsetof(struct shmem2_region,
10114 lfa_host_addr[BP_PORT(bp)]));
10115 else
10116 bp->link_params.lfa_base = 0;
2691d51d
EG
10117 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10118 bp->common.shmem_base, bp->common.shmem2_base);
34f80b04 10119
f2e0899f 10120 if (!bp->common.shmem_base) {
34f80b04
EG
10121 BNX2X_DEV_INFO("MCP not active\n");
10122 bp->flags |= NO_MCP_FLAG;
10123 return;
10124 }
10125
34f80b04 10126 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
35b19ba5 10127 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
34f80b04
EG
10128
10129 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10130 SHARED_HW_CFG_LED_MODE_MASK) >>
10131 SHARED_HW_CFG_LED_MODE_SHIFT);
10132
c2c8b03e
EG
10133 bp->link_params.feature_config_flags = 0;
10134 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10135 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10136 bp->link_params.feature_config_flags |=
10137 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10138 else
10139 bp->link_params.feature_config_flags &=
10140 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10141
34f80b04
EG
10142 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10143 bp->common.bc_ver = val;
10144 BNX2X_DEV_INFO("bc_ver %X\n", val);
10145 if (val < BNX2X_BC_VER) {
10146 /* for now only warn
10147 * later we might need to enforce this */
51c1a580
MS
10148 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10149 BNX2X_BC_VER, val);
34f80b04 10150 }
4d295db0 10151 bp->link_params.feature_config_flags |=
a22f0788 10152 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
f85582f8
DK
10153 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10154
a22f0788
YR
10155 bp->link_params.feature_config_flags |=
10156 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10157 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
a3348722
BW
10158 bp->link_params.feature_config_flags |=
10159 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10160 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
85242eea
YR
10161 bp->link_params.feature_config_flags |=
10162 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10163 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
55386fe8
YR
10164
10165 bp->link_params.feature_config_flags |=
10166 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10167 FEATURE_CONFIG_MT_SUPPORT : 0;
10168
0e898dd7
BW
10169 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10170 BC_SUPPORTS_PFC_STATS : 0;
85242eea 10171
2e499d3c
BW
10172 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10173 BC_SUPPORTS_FCOE_FEATURES : 0;
10174
9876879f
BW
10175 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10176 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
1d187b34
BW
10177 boot_mode = SHMEM_RD(bp,
10178 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10179 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10180 switch (boot_mode) {
10181 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10182 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10183 break;
10184 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10185 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10186 break;
10187 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10188 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10189 break;
10190 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10191 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10192 break;
10193 }
10194
f9a3ebbe
DK
10195 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
10196 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10197
72ce58c3 10198 BNX2X_DEV_INFO("%sWoL capable\n",
f5372251 10199 (bp->flags & NO_WOL_FLAG) ? "not " : "");
34f80b04
EG
10200
10201 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10202 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10203 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10204 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10205
cdaa7cb8
VZ
10206 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10207 val, val2, val3, val4);
34f80b04
EG
10208}
10209
f2e0899f
DK
10210#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10211#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10212
0329aba1 10213static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
f2e0899f
DK
10214{
10215 int pfid = BP_FUNC(bp);
f2e0899f
DK
10216 int igu_sb_id;
10217 u32 val;
6383c0b3 10218 u8 fid, igu_sb_cnt = 0;
f2e0899f
DK
10219
10220 bp->igu_base_sb = 0xff;
f2e0899f 10221 if (CHIP_INT_MODE_IS_BC(bp)) {
3395a033 10222 int vn = BP_VN(bp);
6383c0b3 10223 igu_sb_cnt = bp->igu_sb_cnt;
f2e0899f
DK
10224 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10225 FP_SB_MAX_E1x;
10226
10227 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10228 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10229
9b341bb1 10230 return 0;
f2e0899f
DK
10231 }
10232
10233 /* IGU in normal mode - read CAM */
10234 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10235 igu_sb_id++) {
10236 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10237 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10238 continue;
10239 fid = IGU_FID(val);
10240 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10241 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10242 continue;
10243 if (IGU_VEC(val) == 0)
10244 /* default status block */
10245 bp->igu_dsb_id = igu_sb_id;
10246 else {
10247 if (bp->igu_base_sb == 0xff)
10248 bp->igu_base_sb = igu_sb_id;
6383c0b3 10249 igu_sb_cnt++;
f2e0899f
DK
10250 }
10251 }
10252 }
619c5cb6 10253
6383c0b3 10254#ifdef CONFIG_PCI_MSI
185d4c8b
AE
10255 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10256 * optional that number of CAM entries will not be equal to the value
10257 * advertised in PCI.
10258 * Driver should use the minimal value of both as the actual status
10259 * block count
619c5cb6 10260 */
185d4c8b 10261 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
6383c0b3 10262#endif
619c5cb6 10263
9b341bb1 10264 if (igu_sb_cnt == 0) {
f2e0899f 10265 BNX2X_ERR("CAM configuration error\n");
9b341bb1
BW
10266 return -EINVAL;
10267 }
10268
10269 return 0;
f2e0899f
DK
10270}
10271
1dd06ae8 10272static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
a2fbb9ea 10273{
a22f0788
YR
10274 int cfg_size = 0, idx, port = BP_PORT(bp);
10275
10276 /* Aggregation of supported attributes of all external phys */
10277 bp->port.supported[0] = 0;
10278 bp->port.supported[1] = 0;
b7737c9b
YR
10279 switch (bp->link_params.num_phys) {
10280 case 1:
a22f0788
YR
10281 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10282 cfg_size = 1;
10283 break;
b7737c9b 10284 case 2:
a22f0788
YR
10285 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10286 cfg_size = 1;
10287 break;
10288 case 3:
10289 if (bp->link_params.multi_phy_config &
10290 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10291 bp->port.supported[1] =
10292 bp->link_params.phy[EXT_PHY1].supported;
10293 bp->port.supported[0] =
10294 bp->link_params.phy[EXT_PHY2].supported;
10295 } else {
10296 bp->port.supported[0] =
10297 bp->link_params.phy[EXT_PHY1].supported;
10298 bp->port.supported[1] =
10299 bp->link_params.phy[EXT_PHY2].supported;
10300 }
10301 cfg_size = 2;
10302 break;
b7737c9b 10303 }
a2fbb9ea 10304
a22f0788 10305 if (!(bp->port.supported[0] || bp->port.supported[1])) {
51c1a580 10306 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
b7737c9b 10307 SHMEM_RD(bp,
a22f0788
YR
10308 dev_info.port_hw_config[port].external_phy_config),
10309 SHMEM_RD(bp,
10310 dev_info.port_hw_config[port].external_phy_config2));
a2fbb9ea 10311 return;
f85582f8 10312 }
a2fbb9ea 10313
619c5cb6
VZ
10314 if (CHIP_IS_E3(bp))
10315 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10316 else {
10317 switch (switch_cfg) {
10318 case SWITCH_CFG_1G:
10319 bp->port.phy_addr = REG_RD(
10320 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10321 break;
10322 case SWITCH_CFG_10G:
10323 bp->port.phy_addr = REG_RD(
10324 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10325 break;
10326 default:
10327 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10328 bp->port.link_config[0]);
10329 return;
10330 }
a2fbb9ea 10331 }
619c5cb6 10332 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
a22f0788
YR
10333 /* mask what we support according to speed_cap_mask per configuration */
10334 for (idx = 0; idx < cfg_size; idx++) {
10335 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10336 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
a22f0788 10337 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
a2fbb9ea 10338
a22f0788 10339 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10340 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
a22f0788 10341 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
a2fbb9ea 10342
a22f0788 10343 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10344 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
a22f0788 10345 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
a2fbb9ea 10346
a22f0788 10347 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10348 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
a22f0788 10349 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
a2fbb9ea 10350
a22f0788 10351 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10352 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
a22f0788 10353 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
f85582f8 10354 SUPPORTED_1000baseT_Full);
a2fbb9ea 10355
a22f0788 10356 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10357 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
a22f0788 10358 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
a2fbb9ea 10359
a22f0788 10360 if (!(bp->link_params.speed_cap_mask[idx] &
c18487ee 10361 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
a22f0788
YR
10362 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10363
10364 }
a2fbb9ea 10365
a22f0788
YR
10366 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10367 bp->port.supported[1]);
a2fbb9ea
ET
10368}
10369
0329aba1 10370static void bnx2x_link_settings_requested(struct bnx2x *bp)
a2fbb9ea 10371{
a22f0788
YR
10372 u32 link_config, idx, cfg_size = 0;
10373 bp->port.advertising[0] = 0;
10374 bp->port.advertising[1] = 0;
10375 switch (bp->link_params.num_phys) {
10376 case 1:
10377 case 2:
10378 cfg_size = 1;
10379 break;
10380 case 3:
10381 cfg_size = 2;
10382 break;
10383 }
10384 for (idx = 0; idx < cfg_size; idx++) {
10385 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10386 link_config = bp->port.link_config[idx];
10387 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
f85582f8 10388 case PORT_FEATURE_LINK_SPEED_AUTO:
a22f0788
YR
10389 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10390 bp->link_params.req_line_speed[idx] =
10391 SPEED_AUTO_NEG;
10392 bp->port.advertising[idx] |=
10393 bp->port.supported[idx];
10bd1f24
MY
10394 if (bp->link_params.phy[EXT_PHY1].type ==
10395 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10396 bp->port.advertising[idx] |=
10397 (SUPPORTED_100baseT_Half |
10398 SUPPORTED_100baseT_Full);
f85582f8
DK
10399 } else {
10400 /* force 10G, no AN */
a22f0788
YR
10401 bp->link_params.req_line_speed[idx] =
10402 SPEED_10000;
10403 bp->port.advertising[idx] |=
10404 (ADVERTISED_10000baseT_Full |
f85582f8 10405 ADVERTISED_FIBRE);
a22f0788 10406 continue;
f85582f8
DK
10407 }
10408 break;
a2fbb9ea 10409
f85582f8 10410 case PORT_FEATURE_LINK_SPEED_10M_FULL:
a22f0788
YR
10411 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10412 bp->link_params.req_line_speed[idx] =
10413 SPEED_10;
10414 bp->port.advertising[idx] |=
10415 (ADVERTISED_10baseT_Full |
f85582f8
DK
10416 ADVERTISED_TP);
10417 } else {
51c1a580 10418 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8 10419 link_config,
a22f0788 10420 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10421 return;
10422 }
10423 break;
a2fbb9ea 10424
f85582f8 10425 case PORT_FEATURE_LINK_SPEED_10M_HALF:
a22f0788
YR
10426 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10427 bp->link_params.req_line_speed[idx] =
10428 SPEED_10;
10429 bp->link_params.req_duplex[idx] =
10430 DUPLEX_HALF;
10431 bp->port.advertising[idx] |=
10432 (ADVERTISED_10baseT_Half |
f85582f8
DK
10433 ADVERTISED_TP);
10434 } else {
51c1a580 10435 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10436 link_config,
10437 bp->link_params.speed_cap_mask[idx]);
10438 return;
10439 }
10440 break;
a2fbb9ea 10441
f85582f8
DK
10442 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10443 if (bp->port.supported[idx] &
10444 SUPPORTED_100baseT_Full) {
a22f0788
YR
10445 bp->link_params.req_line_speed[idx] =
10446 SPEED_100;
10447 bp->port.advertising[idx] |=
10448 (ADVERTISED_100baseT_Full |
f85582f8
DK
10449 ADVERTISED_TP);
10450 } else {
51c1a580 10451 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
f85582f8
DK
10452 link_config,
10453 bp->link_params.speed_cap_mask[idx]);
10454 return;
10455 }
10456 break;
a2fbb9ea 10457
f85582f8
DK
10458 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10459 if (bp->port.supported[idx] &
10460 SUPPORTED_100baseT_Half) {
10461 bp->link_params.req_line_speed[idx] =
10462 SPEED_100;
10463 bp->link_params.req_duplex[idx] =
10464 DUPLEX_HALF;
a22f0788
YR
10465 bp->port.advertising[idx] |=
10466 (ADVERTISED_100baseT_Half |
f85582f8
DK
10467 ADVERTISED_TP);
10468 } else {
51c1a580 10469 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10470 link_config,
10471 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10472 return;
10473 }
10474 break;
a2fbb9ea 10475
f85582f8 10476 case PORT_FEATURE_LINK_SPEED_1G:
a22f0788
YR
10477 if (bp->port.supported[idx] &
10478 SUPPORTED_1000baseT_Full) {
10479 bp->link_params.req_line_speed[idx] =
10480 SPEED_1000;
10481 bp->port.advertising[idx] |=
10482 (ADVERTISED_1000baseT_Full |
f85582f8
DK
10483 ADVERTISED_TP);
10484 } else {
51c1a580 10485 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788
YR
10486 link_config,
10487 bp->link_params.speed_cap_mask[idx]);
f85582f8
DK
10488 return;
10489 }
10490 break;
a2fbb9ea 10491
f85582f8 10492 case PORT_FEATURE_LINK_SPEED_2_5G:
a22f0788
YR
10493 if (bp->port.supported[idx] &
10494 SUPPORTED_2500baseX_Full) {
10495 bp->link_params.req_line_speed[idx] =
10496 SPEED_2500;
10497 bp->port.advertising[idx] |=
10498 (ADVERTISED_2500baseX_Full |
34f80b04 10499 ADVERTISED_TP);
f85582f8 10500 } else {
51c1a580 10501 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10502 link_config,
f85582f8
DK
10503 bp->link_params.speed_cap_mask[idx]);
10504 return;
10505 }
10506 break;
a2fbb9ea 10507
f85582f8 10508 case PORT_FEATURE_LINK_SPEED_10G_CX4:
a22f0788
YR
10509 if (bp->port.supported[idx] &
10510 SUPPORTED_10000baseT_Full) {
10511 bp->link_params.req_line_speed[idx] =
10512 SPEED_10000;
10513 bp->port.advertising[idx] |=
10514 (ADVERTISED_10000baseT_Full |
34f80b04 10515 ADVERTISED_FIBRE);
f85582f8 10516 } else {
51c1a580 10517 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
a22f0788 10518 link_config,
f85582f8
DK
10519 bp->link_params.speed_cap_mask[idx]);
10520 return;
10521 }
10522 break;
3c9ada22
YR
10523 case PORT_FEATURE_LINK_SPEED_20G:
10524 bp->link_params.req_line_speed[idx] = SPEED_20000;
a2fbb9ea 10525
3c9ada22 10526 break;
f85582f8 10527 default:
51c1a580 10528 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
754a2f52 10529 link_config);
f85582f8
DK
10530 bp->link_params.req_line_speed[idx] =
10531 SPEED_AUTO_NEG;
10532 bp->port.advertising[idx] =
10533 bp->port.supported[idx];
10534 break;
10535 }
a2fbb9ea 10536
a22f0788 10537 bp->link_params.req_flow_ctrl[idx] = (link_config &
34f80b04 10538 PORT_FEATURE_FLOW_CONTROL_MASK);
cd1dfce2
YM
10539 if (bp->link_params.req_flow_ctrl[idx] ==
10540 BNX2X_FLOW_CTRL_AUTO) {
10541 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10542 bp->link_params.req_flow_ctrl[idx] =
10543 BNX2X_FLOW_CTRL_NONE;
10544 else
10545 bnx2x_set_requested_fc(bp);
a22f0788 10546 }
a2fbb9ea 10547
51c1a580 10548 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
a22f0788
YR
10549 bp->link_params.req_line_speed[idx],
10550 bp->link_params.req_duplex[idx],
10551 bp->link_params.req_flow_ctrl[idx],
10552 bp->port.advertising[idx]);
10553 }
a2fbb9ea
ET
10554}
10555
0329aba1 10556static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
e665bfda 10557{
86564c3f
YM
10558 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10559 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10560 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10561 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
e665bfda
MC
10562}
10563
0329aba1 10564static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
a2fbb9ea 10565{
34f80b04 10566 int port = BP_PORT(bp);
589abe3a 10567 u32 config;
c8c60d88 10568 u32 ext_phy_type, ext_phy_config, eee_mode;
a2fbb9ea 10569
c18487ee 10570 bp->link_params.bp = bp;
34f80b04 10571 bp->link_params.port = port;
c18487ee 10572
c18487ee 10573 bp->link_params.lane_config =
a2fbb9ea 10574 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
4d295db0 10575
a22f0788 10576 bp->link_params.speed_cap_mask[0] =
a2fbb9ea
ET
10577 SHMEM_RD(bp,
10578 dev_info.port_hw_config[port].speed_capability_mask);
a22f0788
YR
10579 bp->link_params.speed_cap_mask[1] =
10580 SHMEM_RD(bp,
10581 dev_info.port_hw_config[port].speed_capability_mask2);
10582 bp->port.link_config[0] =
a2fbb9ea
ET
10583 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10584
a22f0788
YR
10585 bp->port.link_config[1] =
10586 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
c2c8b03e 10587
a22f0788
YR
10588 bp->link_params.multi_phy_config =
10589 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
3ce2c3f9
EG
10590 /* If the device is capable of WoL, set the default state according
10591 * to the HW
10592 */
4d295db0 10593 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
3ce2c3f9
EG
10594 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10595 (config & PORT_FEATURE_WOL_ENABLED));
10596
4ba7699b
YM
10597 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10598 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
10599 bp->flags |= NO_ISCSI_FLAG;
10600 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10601 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
10602 bp->flags |= NO_FCOE_FLAG;
10603
51c1a580 10604 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
c18487ee 10605 bp->link_params.lane_config,
a22f0788
YR
10606 bp->link_params.speed_cap_mask[0],
10607 bp->port.link_config[0]);
a2fbb9ea 10608
a22f0788 10609 bp->link_params.switch_cfg = (bp->port.link_config[0] &
f85582f8 10610 PORT_FEATURE_CONNECTED_SWITCH_MASK);
b7737c9b 10611 bnx2x_phy_probe(&bp->link_params);
c18487ee 10612 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
a2fbb9ea
ET
10613
10614 bnx2x_link_settings_requested(bp);
10615
01cd4528
EG
10616 /*
10617 * If connected directly, work with the internal PHY, otherwise, work
10618 * with the external PHY
10619 */
b7737c9b
YR
10620 ext_phy_config =
10621 SHMEM_RD(bp,
10622 dev_info.port_hw_config[port].external_phy_config);
10623 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
01cd4528 10624 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
b7737c9b 10625 bp->mdio.prtad = bp->port.phy_addr;
01cd4528
EG
10626
10627 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10628 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10629 bp->mdio.prtad =
b7737c9b 10630 XGXS_EXT_PHY_ADDR(ext_phy_config);
5866df6d 10631
c8c60d88
YM
10632 /* Configure link feature according to nvram value */
10633 eee_mode = (((SHMEM_RD(bp, dev_info.
10634 port_feature_config[port].eee_power_mode)) &
10635 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10636 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10637 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10638 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10639 EEE_MODE_ENABLE_LPI |
10640 EEE_MODE_OUTPUT_TIME;
10641 } else {
10642 bp->link_params.eee_mode = 0;
10643 }
0793f83f 10644}
01cd4528 10645
b306f5ed 10646void bnx2x_get_iscsi_info(struct bnx2x *bp)
2ba45142 10647{
9e62e912 10648 u32 no_flags = NO_ISCSI_FLAG;
bf61ee14 10649 int port = BP_PORT(bp);
2ba45142 10650 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
bf61ee14 10651 drv_lic_key[port].max_iscsi_conn);
2ba45142 10652
55c11941
MS
10653 if (!CNIC_SUPPORT(bp)) {
10654 bp->flags |= no_flags;
10655 return;
10656 }
10657
b306f5ed 10658 /* Get the number of maximum allowed iSCSI connections */
2ba45142
VZ
10659 bp->cnic_eth_dev.max_iscsi_conn =
10660 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10661 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10662
b306f5ed
DK
10663 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10664 bp->cnic_eth_dev.max_iscsi_conn);
10665
10666 /*
10667 * If maximum allowed number of connections is zero -
10668 * disable the feature.
10669 */
10670 if (!bp->cnic_eth_dev.max_iscsi_conn)
9e62e912 10671 bp->flags |= no_flags;
55c11941 10672
b306f5ed
DK
10673}
10674
0329aba1 10675static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9e62e912
DK
10676{
10677 /* Port info */
10678 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10679 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10680 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10681 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10682
10683 /* Node info */
10684 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10685 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10686 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10687 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10688}
0329aba1 10689static void bnx2x_get_fcoe_info(struct bnx2x *bp)
b306f5ed
DK
10690{
10691 int port = BP_PORT(bp);
10692 int func = BP_ABS_FUNC(bp);
b306f5ed
DK
10693 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10694 drv_lic_key[port].max_fcoe_conn);
10695
55c11941
MS
10696 if (!CNIC_SUPPORT(bp)) {
10697 bp->flags |= NO_FCOE_FLAG;
10698 return;
10699 }
10700
b306f5ed 10701 /* Get the number of maximum allowed FCoE connections */
2ba45142
VZ
10702 bp->cnic_eth_dev.max_fcoe_conn =
10703 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10704 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10705
bf61ee14
VZ
10706 /* Read the WWN: */
10707 if (!IS_MF(bp)) {
10708 /* Port info */
10709 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10710 SHMEM_RD(bp,
2de67439 10711 dev_info.port_hw_config[port].
bf61ee14
VZ
10712 fcoe_wwn_port_name_upper);
10713 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10714 SHMEM_RD(bp,
2de67439 10715 dev_info.port_hw_config[port].
bf61ee14
VZ
10716 fcoe_wwn_port_name_lower);
10717
10718 /* Node info */
10719 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10720 SHMEM_RD(bp,
2de67439 10721 dev_info.port_hw_config[port].
bf61ee14
VZ
10722 fcoe_wwn_node_name_upper);
10723 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10724 SHMEM_RD(bp,
2de67439 10725 dev_info.port_hw_config[port].
bf61ee14
VZ
10726 fcoe_wwn_node_name_lower);
10727 } else if (!IS_MF_SD(bp)) {
bf61ee14
VZ
10728 /*
10729 * Read the WWN info only if the FCoE feature is enabled for
10730 * this function.
10731 */
7b5342d9 10732 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
9e62e912
DK
10733 bnx2x_get_ext_wwn_info(bp, func);
10734
382e513a 10735 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
9e62e912 10736 bnx2x_get_ext_wwn_info(bp, func);
382e513a 10737 }
bf61ee14 10738
b306f5ed 10739 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
2ba45142 10740
bf61ee14
VZ
10741 /*
10742 * If maximum allowed number of connections is zero -
2ba45142
VZ
10743 * disable the feature.
10744 */
2ba45142
VZ
10745 if (!bp->cnic_eth_dev.max_fcoe_conn)
10746 bp->flags |= NO_FCOE_FLAG;
10747}
b306f5ed 10748
0329aba1 10749static void bnx2x_get_cnic_info(struct bnx2x *bp)
b306f5ed
DK
10750{
10751 /*
10752 * iSCSI may be dynamically disabled but reading
10753 * info here we will decrease memory usage by driver
10754 * if the feature is disabled for good
10755 */
10756 bnx2x_get_iscsi_info(bp);
10757 bnx2x_get_fcoe_info(bp);
10758}
2ba45142 10759
0329aba1 10760static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
0793f83f
DK
10761{
10762 u32 val, val2;
10763 int func = BP_ABS_FUNC(bp);
10764 int port = BP_PORT(bp);
2ba45142
VZ
10765 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10766 u8 *fip_mac = bp->fip_mac;
0793f83f 10767
55c11941
MS
10768 if (IS_MF(bp)) {
10769 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
2ba45142 10770 * FCoE MAC then the appropriate feature should be disabled.
55c11941
MS
10771 * In non SD mode features configuration comes from struct
10772 * func_ext_config.
2ba45142 10773 */
55c11941 10774 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
0793f83f
DK
10775 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10776 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10777 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10778 iscsi_mac_addr_upper);
0793f83f 10779 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10780 iscsi_mac_addr_lower);
2ba45142 10781 bnx2x_set_mac_buf(iscsi_mac, val, val2);
55c11941
MS
10782 BNX2X_DEV_INFO
10783 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10784 } else {
2ba45142 10785 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
55c11941 10786 }
2ba45142
VZ
10787
10788 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10789 val2 = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10790 fcoe_mac_addr_upper);
2ba45142 10791 val = MF_CFG_RD(bp, func_ext_config[func].
55c11941 10792 fcoe_mac_addr_lower);
2ba45142 10793 bnx2x_set_mac_buf(fip_mac, val, val2);
55c11941
MS
10794 BNX2X_DEV_INFO
10795 ("Read FCoE L2 MAC: %pM\n", fip_mac);
10796 } else {
2ba45142 10797 bp->flags |= NO_FCOE_FLAG;
55c11941 10798 }
a3348722
BW
10799
10800 bp->mf_ext_config = cfg;
10801
9e62e912 10802 } else { /* SD MODE */
55c11941
MS
10803 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10804 /* use primary mac as iscsi mac */
10805 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
10806
10807 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10808 BNX2X_DEV_INFO
10809 ("Read iSCSI MAC: %pM\n", iscsi_mac);
10810 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
10811 /* use primary mac as fip mac */
10812 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
10813 BNX2X_DEV_INFO("SD FCoE MODE\n");
10814 BNX2X_DEV_INFO
10815 ("Read FIP MAC: %pM\n", fip_mac);
614c76df 10816 }
0793f83f 10817 }
a3348722 10818
55c11941
MS
10819 if (IS_MF_STORAGE_SD(bp))
10820 /* Zero primary MAC configuration */
10821 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10822
f72839d0 10823 if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
a3348722
BW
10824 /* use FIP MAC as primary MAC */
10825 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10826
0793f83f 10827 } else {
0793f83f 10828 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10829 iscsi_mac_upper);
0793f83f 10830 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10831 iscsi_mac_lower);
2ba45142 10832 bnx2x_set_mac_buf(iscsi_mac, val, val2);
c03bd39c
VZ
10833
10834 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10835 fcoe_fip_mac_upper);
c03bd39c 10836 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
55c11941 10837 fcoe_fip_mac_lower);
c03bd39c 10838 bnx2x_set_mac_buf(fip_mac, val, val2);
0793f83f
DK
10839 }
10840
55c11941 10841 /* Disable iSCSI OOO if MAC configuration is invalid. */
426b9241 10842 if (!is_valid_ether_addr(iscsi_mac)) {
55c11941 10843 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
426b9241
DK
10844 memset(iscsi_mac, 0, ETH_ALEN);
10845 }
10846
55c11941 10847 /* Disable FCoE if MAC configuration is invalid. */
426b9241
DK
10848 if (!is_valid_ether_addr(fip_mac)) {
10849 bp->flags |= NO_FCOE_FLAG;
10850 memset(bp->fip_mac, 0, ETH_ALEN);
10851 }
55c11941
MS
10852}
10853
0329aba1 10854static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
55c11941
MS
10855{
10856 u32 val, val2;
10857 int func = BP_ABS_FUNC(bp);
10858 int port = BP_PORT(bp);
10859
10860 /* Zero primary MAC configuration */
10861 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10862
10863 if (BP_NOMCP(bp)) {
10864 BNX2X_ERROR("warning: random MAC workaround active\n");
10865 eth_hw_addr_random(bp->dev);
10866 } else if (IS_MF(bp)) {
10867 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10868 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10869 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10870 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10871 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10872
10873 if (CNIC_SUPPORT(bp))
10874 bnx2x_get_cnic_mac_hwinfo(bp);
10875 } else {
10876 /* in SF read MACs from port configuration */
10877 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10878 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10879 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10880
10881 if (CNIC_SUPPORT(bp))
10882 bnx2x_get_cnic_mac_hwinfo(bp);
10883 }
10884
10885 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
619c5cb6 10886
614c76df 10887 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
619c5cb6 10888 dev_err(&bp->pdev->dev,
51c1a580
MS
10889 "bad Ethernet MAC address configuration: %pM\n"
10890 "change it manually before bringing up the appropriate network interface\n",
0f9dad10 10891 bp->dev->dev_addr);
7964211d 10892}
51c1a580 10893
0329aba1 10894static bool bnx2x_get_dropless_info(struct bnx2x *bp)
7964211d
YM
10895{
10896 int tmp;
10897 u32 cfg;
51c1a580 10898
7964211d
YM
10899 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
10900 /* Take function: tmp = func */
10901 tmp = BP_ABS_FUNC(bp);
10902 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
10903 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
10904 } else {
10905 /* Take port: tmp = port */
10906 tmp = BP_PORT(bp);
10907 cfg = SHMEM_RD(bp,
10908 dev_info.port_hw_config[tmp].generic_features);
10909 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
10910 }
10911 return cfg;
34f80b04
EG
10912}
10913
0329aba1 10914static int bnx2x_get_hwinfo(struct bnx2x *bp)
34f80b04 10915{
0793f83f 10916 int /*abs*/func = BP_ABS_FUNC(bp);
b8ee8328 10917 int vn;
0793f83f 10918 u32 val = 0;
34f80b04 10919 int rc = 0;
a2fbb9ea 10920
34f80b04 10921 bnx2x_get_common_hwinfo(bp);
a2fbb9ea 10922
6383c0b3
AE
10923 /*
10924 * initialize IGU parameters
10925 */
f2e0899f
DK
10926 if (CHIP_IS_E1x(bp)) {
10927 bp->common.int_block = INT_BLOCK_HC;
10928
10929 bp->igu_dsb_id = DEF_SB_IGU_ID;
10930 bp->igu_base_sb = 0;
f2e0899f
DK
10931 } else {
10932 bp->common.int_block = INT_BLOCK_IGU;
7a06a122
DK
10933
10934 /* do not allow device reset during IGU info preocessing */
10935 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10936
f2e0899f 10937 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
619c5cb6
VZ
10938
10939 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10940 int tout = 5000;
10941
10942 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10943
10944 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10945 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10946 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10947
10948 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10949 tout--;
0926d499 10950 usleep_range(1000, 2000);
619c5cb6
VZ
10951 }
10952
10953 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10954 dev_err(&bp->pdev->dev,
10955 "FORCING Normal Mode failed!!!\n");
9b341bb1
BW
10956 bnx2x_release_hw_lock(bp,
10957 HW_LOCK_RESOURCE_RESET);
619c5cb6
VZ
10958 return -EPERM;
10959 }
10960 }
10961
f2e0899f 10962 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
619c5cb6 10963 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
f2e0899f
DK
10964 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10965 } else
619c5cb6 10966 BNX2X_DEV_INFO("IGU Normal Mode\n");
523224a3 10967
9b341bb1 10968 rc = bnx2x_get_igu_cam_info(bp);
7a06a122 10969 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9b341bb1
BW
10970 if (rc)
10971 return rc;
f2e0899f 10972 }
619c5cb6
VZ
10973
10974 /*
10975 * set base FW non-default (fast path) status block id, this value is
10976 * used to initialize the fw_sb_id saved on the fp/queue structure to
10977 * determine the id used by the FW.
10978 */
10979 if (CHIP_IS_E1x(bp))
10980 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10981 else /*
10982 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10983 * the same queue are indicated on the same IGU SB). So we prefer
10984 * FW and IGU SBs to be the same value.
10985 */
10986 bp->base_fw_ndsb = bp->igu_base_sb;
10987
10988 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10989 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10990 bp->igu_sb_cnt, bp->base_fw_ndsb);
f2e0899f
DK
10991
10992 /*
10993 * Initialize MF configuration
10994 */
523224a3 10995
fb3bff17
DK
10996 bp->mf_ov = 0;
10997 bp->mf_mode = 0;
3395a033 10998 vn = BP_VN(bp);
0793f83f 10999
f2e0899f 11000 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
619c5cb6
VZ
11001 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11002 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11003 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11004
f2e0899f
DK
11005 if (SHMEM2_HAS(bp, mf_cfg_addr))
11006 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11007 else
11008 bp->common.mf_cfg_base = bp->common.shmem_base +
523224a3
DK
11009 offsetof(struct shmem_region, func_mb) +
11010 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
0793f83f
DK
11011 /*
11012 * get mf configuration:
25985edc 11013 * 1. existence of MF configuration
0793f83f
DK
11014 * 2. MAC address must be legal (check only upper bytes)
11015 * for Switch-Independent mode;
11016 * OVLAN must be legal for Switch-Dependent mode
11017 * 3. SF_MODE configures specific MF mode
11018 */
11019 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11020 /* get mf configuration */
11021 val = SHMEM_RD(bp,
11022 dev_info.shared_feature_config.config);
11023 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
11024
11025 switch (val) {
11026 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11027 val = MF_CFG_RD(bp, func_mf_config[func].
11028 mac_upper);
11029 /* check for legal mac (upper bytes)*/
11030 if (val != 0xffff) {
11031 bp->mf_mode = MULTI_FUNCTION_SI;
11032 bp->mf_config[vn] = MF_CFG_RD(bp,
11033 func_mf_config[func].config);
11034 } else
51c1a580 11035 BNX2X_DEV_INFO("illegal MAC address for SI\n");
0793f83f 11036 break;
a3348722
BW
11037 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11038 if ((!CHIP_IS_E1x(bp)) &&
11039 (MF_CFG_RD(bp, func_mf_config[func].
11040 mac_upper) != 0xffff) &&
11041 (SHMEM2_HAS(bp,
11042 afex_driver_support))) {
11043 bp->mf_mode = MULTI_FUNCTION_AFEX;
11044 bp->mf_config[vn] = MF_CFG_RD(bp,
11045 func_mf_config[func].config);
11046 } else {
11047 BNX2X_DEV_INFO("can not configure afex mode\n");
11048 }
11049 break;
0793f83f
DK
11050 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11051 /* get OV configuration */
11052 val = MF_CFG_RD(bp,
11053 func_mf_config[FUNC_0].e1hov_tag);
11054 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11055
11056 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11057 bp->mf_mode = MULTI_FUNCTION_SD;
11058 bp->mf_config[vn] = MF_CFG_RD(bp,
11059 func_mf_config[func].config);
11060 } else
754a2f52 11061 BNX2X_DEV_INFO("illegal OV for SD\n");
0793f83f
DK
11062 break;
11063 default:
11064 /* Unknown configuration: reset mf_config */
11065 bp->mf_config[vn] = 0;
51c1a580 11066 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
0793f83f
DK
11067 }
11068 }
a2fbb9ea 11069
2691d51d 11070 BNX2X_DEV_INFO("%s function mode\n",
fb3bff17 11071 IS_MF(bp) ? "multi" : "single");
2691d51d 11072
0793f83f
DK
11073 switch (bp->mf_mode) {
11074 case MULTI_FUNCTION_SD:
11075 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11076 FUNC_MF_CFG_E1HOV_TAG_MASK;
2691d51d 11077 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
fb3bff17 11078 bp->mf_ov = val;
619c5cb6
VZ
11079 bp->path_has_ovlan = true;
11080
51c1a580
MS
11081 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11082 func, bp->mf_ov, bp->mf_ov);
2691d51d 11083 } else {
619c5cb6 11084 dev_err(&bp->pdev->dev,
51c1a580
MS
11085 "No valid MF OV for func %d, aborting\n",
11086 func);
619c5cb6 11087 return -EPERM;
34f80b04 11088 }
0793f83f 11089 break;
a3348722
BW
11090 case MULTI_FUNCTION_AFEX:
11091 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11092 break;
0793f83f 11093 case MULTI_FUNCTION_SI:
51c1a580
MS
11094 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11095 func);
0793f83f
DK
11096 break;
11097 default:
11098 if (vn) {
619c5cb6 11099 dev_err(&bp->pdev->dev,
51c1a580
MS
11100 "VN %d is in a single function mode, aborting\n",
11101 vn);
619c5cb6 11102 return -EPERM;
2691d51d 11103 }
0793f83f 11104 break;
34f80b04 11105 }
0793f83f 11106
619c5cb6
VZ
11107 /* check if other port on the path needs ovlan:
11108 * Since MF configuration is shared between ports
11109 * Possible mixed modes are only
11110 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11111 */
11112 if (CHIP_MODE_IS_4_PORT(bp) &&
11113 !bp->path_has_ovlan &&
11114 !IS_MF(bp) &&
11115 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11116 u8 other_port = !BP_PORT(bp);
11117 u8 other_func = BP_PATH(bp) + 2*other_port;
11118 val = MF_CFG_RD(bp,
11119 func_mf_config[other_func].e1hov_tag);
11120 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11121 bp->path_has_ovlan = true;
11122 }
34f80b04 11123 }
a2fbb9ea 11124
f2e0899f
DK
11125 /* adjust igu_sb_cnt to MF for E1x */
11126 if (CHIP_IS_E1x(bp) && IS_MF(bp))
523224a3
DK
11127 bp->igu_sb_cnt /= E1HVN_MAX;
11128
619c5cb6
VZ
11129 /* port info */
11130 bnx2x_get_port_hwinfo(bp);
f2e0899f 11131
0793f83f
DK
11132 /* Get MAC addresses */
11133 bnx2x_get_mac_hwinfo(bp);
a2fbb9ea 11134
2ba45142 11135 bnx2x_get_cnic_info(bp);
2ba45142 11136
34f80b04
EG
11137 return rc;
11138}
11139
0329aba1 11140static void bnx2x_read_fwinfo(struct bnx2x *bp)
34f24c7f
VZ
11141{
11142 int cnt, i, block_end, rodi;
fcdf95cb 11143 char vpd_start[BNX2X_VPD_LEN+1];
34f24c7f
VZ
11144 char str_id_reg[VENDOR_ID_LEN+1];
11145 char str_id_cap[VENDOR_ID_LEN+1];
fcdf95cb
BW
11146 char *vpd_data;
11147 char *vpd_extended_data = NULL;
34f24c7f
VZ
11148 u8 len;
11149
fcdf95cb 11150 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
34f24c7f
VZ
11151 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11152
11153 if (cnt < BNX2X_VPD_LEN)
11154 goto out_not_found;
11155
fcdf95cb
BW
11156 /* VPD RO tag should be first tag after identifier string, hence
11157 * we should be able to find it in first BNX2X_VPD_LEN chars
11158 */
11159 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
34f24c7f
VZ
11160 PCI_VPD_LRDT_RO_DATA);
11161 if (i < 0)
11162 goto out_not_found;
11163
34f24c7f 11164 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
fcdf95cb 11165 pci_vpd_lrdt_size(&vpd_start[i]);
34f24c7f
VZ
11166
11167 i += PCI_VPD_LRDT_TAG_SIZE;
11168
fcdf95cb
BW
11169 if (block_end > BNX2X_VPD_LEN) {
11170 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11171 if (vpd_extended_data == NULL)
11172 goto out_not_found;
11173
11174 /* read rest of vpd image into vpd_extended_data */
11175 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11176 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11177 block_end - BNX2X_VPD_LEN,
11178 vpd_extended_data + BNX2X_VPD_LEN);
11179 if (cnt < (block_end - BNX2X_VPD_LEN))
11180 goto out_not_found;
11181 vpd_data = vpd_extended_data;
11182 } else
11183 vpd_data = vpd_start;
11184
11185 /* now vpd_data holds full vpd content in both cases */
34f24c7f
VZ
11186
11187 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11188 PCI_VPD_RO_KEYWORD_MFR_ID);
11189 if (rodi < 0)
11190 goto out_not_found;
11191
11192 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11193
11194 if (len != VENDOR_ID_LEN)
11195 goto out_not_found;
11196
11197 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11198
11199 /* vendor specific info */
11200 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11201 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11202 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11203 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11204
11205 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11206 PCI_VPD_RO_KEYWORD_VENDOR0);
11207 if (rodi >= 0) {
11208 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11209
11210 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11211
11212 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11213 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11214 bp->fw_ver[len] = ' ';
11215 }
11216 }
fcdf95cb 11217 kfree(vpd_extended_data);
34f24c7f
VZ
11218 return;
11219 }
11220out_not_found:
fcdf95cb 11221 kfree(vpd_extended_data);
34f24c7f
VZ
11222 return;
11223}
11224
0329aba1 11225static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
619c5cb6
VZ
11226{
11227 u32 flags = 0;
11228
11229 if (CHIP_REV_IS_FPGA(bp))
11230 SET_FLAGS(flags, MODE_FPGA);
11231 else if (CHIP_REV_IS_EMUL(bp))
11232 SET_FLAGS(flags, MODE_EMUL);
11233 else
11234 SET_FLAGS(flags, MODE_ASIC);
11235
11236 if (CHIP_MODE_IS_4_PORT(bp))
11237 SET_FLAGS(flags, MODE_PORT4);
11238 else
11239 SET_FLAGS(flags, MODE_PORT2);
11240
11241 if (CHIP_IS_E2(bp))
11242 SET_FLAGS(flags, MODE_E2);
11243 else if (CHIP_IS_E3(bp)) {
11244 SET_FLAGS(flags, MODE_E3);
11245 if (CHIP_REV(bp) == CHIP_REV_Ax)
11246 SET_FLAGS(flags, MODE_E3_A0);
6383c0b3
AE
11247 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11248 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
619c5cb6
VZ
11249 }
11250
11251 if (IS_MF(bp)) {
11252 SET_FLAGS(flags, MODE_MF);
11253 switch (bp->mf_mode) {
11254 case MULTI_FUNCTION_SD:
11255 SET_FLAGS(flags, MODE_MF_SD);
11256 break;
11257 case MULTI_FUNCTION_SI:
11258 SET_FLAGS(flags, MODE_MF_SI);
11259 break;
a3348722
BW
11260 case MULTI_FUNCTION_AFEX:
11261 SET_FLAGS(flags, MODE_MF_AFEX);
11262 break;
619c5cb6
VZ
11263 }
11264 } else
11265 SET_FLAGS(flags, MODE_SF);
11266
11267#if defined(__LITTLE_ENDIAN)
11268 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11269#else /*(__BIG_ENDIAN)*/
11270 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11271#endif
11272 INIT_MODE_FLAGS(bp) = flags;
11273}
11274
0329aba1 11275static int bnx2x_init_bp(struct bnx2x *bp)
34f80b04 11276{
f2e0899f 11277 int func;
34f80b04
EG
11278 int rc;
11279
34f80b04 11280 mutex_init(&bp->port.phy_mutex);
c4ff7cbf 11281 mutex_init(&bp->fw_mb_mutex);
bb7e95c8 11282 spin_lock_init(&bp->stats_lock);
55c11941 11283
a2fbb9ea 11284
1cf167f2 11285 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
7be08a72 11286 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
3deb8167 11287 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
1ab4434c
AE
11288 if (IS_PF(bp)) {
11289 rc = bnx2x_get_hwinfo(bp);
11290 if (rc)
11291 return rc;
11292 } else {
11293 random_ether_addr(bp->dev->dev_addr);
11294 }
34f80b04 11295
619c5cb6
VZ
11296 bnx2x_set_modes_bitmap(bp);
11297
11298 rc = bnx2x_alloc_mem_bp(bp);
11299 if (rc)
11300 return rc;
523224a3 11301
34f24c7f 11302 bnx2x_read_fwinfo(bp);
f2e0899f
DK
11303
11304 func = BP_FUNC(bp);
11305
34f80b04 11306 /* need to reset chip if undi was active */
1ab4434c 11307 if (IS_PF(bp) && !BP_NOMCP(bp)) {
452427b0
YM
11308 /* init fw_seq */
11309 bp->fw_seq =
11310 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11311 DRV_MSG_SEQ_NUMBER_MASK;
11312 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11313
11314 bnx2x_prev_unload(bp);
11315 }
11316
34f80b04
EG
11317
11318 if (CHIP_REV_IS_FPGA(bp))
cdaa7cb8 11319 dev_err(&bp->pdev->dev, "FPGA detected\n");
34f80b04
EG
11320
11321 if (BP_NOMCP(bp) && (func == 0))
51c1a580 11322 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
34f80b04 11323
614c76df 11324 bp->disable_tpa = disable_tpa;
a3348722 11325 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
614c76df 11326
7a9b2557 11327 /* Set TPA flags */
614c76df 11328 if (bp->disable_tpa) {
621b4d66 11329 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11330 bp->dev->features &= ~NETIF_F_LRO;
11331 } else {
621b4d66 11332 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
7a9b2557
VZ
11333 bp->dev->features |= NETIF_F_LRO;
11334 }
11335
a18f5128
EG
11336 if (CHIP_IS_E1(bp))
11337 bp->dropless_fc = 0;
11338 else
7964211d 11339 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
a18f5128 11340
8d5726c4 11341 bp->mrrs = mrrs;
7a9b2557 11342
a3348722 11343 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1ab4434c
AE
11344 if (IS_VF(bp))
11345 bp->rx_ring_size = MAX_RX_AVAIL;
34f80b04 11346
7d323bfd 11347 /* make sure that the numbers are in the right granularity */
523224a3
DK
11348 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11349 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
34f80b04 11350
fc543637 11351 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
34f80b04
EG
11352
11353 init_timer(&bp->timer);
11354 bp->timer.expires = jiffies + bp->current_interval;
11355 bp->timer.data = (unsigned long) bp;
11356 bp->timer.function = bnx2x_timer;
11357
0370cf90
BW
11358 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11359 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11360 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11361 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11362 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11363 bnx2x_dcbx_init_params(bp);
11364 } else {
11365 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11366 }
e4901dde 11367
619c5cb6
VZ
11368 if (CHIP_IS_E1x(bp))
11369 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11370 else
11371 bp->cnic_base_cl_id = FP_SB_MAX_E2;
619c5cb6 11372
6383c0b3 11373 /* multiple tx priority */
1ab4434c
AE
11374 if (IS_VF(bp))
11375 bp->max_cos = 1;
11376 else if (CHIP_IS_E1x(bp))
6383c0b3 11377 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
1ab4434c 11378 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
6383c0b3 11379 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
1ab4434c 11380 else if (CHIP_IS_E3B0(bp))
6383c0b3 11381 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
1ab4434c
AE
11382 else
11383 BNX2X_ERR("unknown chip %x revision %x\n",
11384 CHIP_NUM(bp), CHIP_REV(bp));
11385 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
6383c0b3 11386
55c11941
MS
11387 /* We need at least one default status block for slow-path events,
11388 * second status block for the L2 queue, and a third status block for
11389 * CNIC if supproted.
11390 */
11391 if (CNIC_SUPPORT(bp))
11392 bp->min_msix_vec_cnt = 3;
11393 else
11394 bp->min_msix_vec_cnt = 2;
11395 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11396
34f80b04 11397 return rc;
a2fbb9ea
ET
11398}
11399
a2fbb9ea 11400
de0c62db
DK
11401/****************************************************************************
11402* General service functions
11403****************************************************************************/
a2fbb9ea 11404
619c5cb6
VZ
11405/*
11406 * net_device service functions
11407 */
11408
8395be5e
AE
11409static int bnx2x_open_epilog(struct bnx2x *bp)
11410{
11411 /* Enable sriov via delayed work. This must be done via delayed work
11412 * because it causes the probe of the vf devices to be run, which invoke
11413 * register_netdevice which must have rtnl lock taken. As we are holding
11414 * the lock right now, that could only work if the probe would not take
11415 * the lock. However, as the probe of the vf may be called from other
11416 * contexts as well (such as passthrough to vm failes) it can't assume
11417 * the lock is being held for it. Using delayed work here allows the
11418 * probe code to simply take the lock (i.e. wait for it to be released
11419 * if it is being held).
11420 */
11421 smp_mb__before_clear_bit();
11422 set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
11423 smp_mb__after_clear_bit();
11424 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11425
11426 return 0;
11427}
11428
bb2a0f7a 11429/* called with rtnl_lock */
a2fbb9ea
ET
11430static int bnx2x_open(struct net_device *dev)
11431{
11432 struct bnx2x *bp = netdev_priv(dev);
c9ee9206
VZ
11433 bool global = false;
11434 int other_engine = BP_PATH(bp) ? 0 : 1;
889b9af3 11435 bool other_load_status, load_status;
8395be5e 11436 int rc;
a2fbb9ea 11437
1355b704
MY
11438 bp->stats_init = true;
11439
6eccabb3
EG
11440 netif_carrier_off(dev);
11441
a2fbb9ea
ET
11442 bnx2x_set_power_state(bp, PCI_D0);
11443
ad5afc89 11444 /* If parity had happen during the unload, then attentions
c9ee9206
VZ
11445 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11446 * want the first function loaded on the current engine to
11447 * complete the recovery.
ad5afc89 11448 * Parity recovery is only relevant for PF driver.
c9ee9206 11449 */
ad5afc89
AE
11450 if (IS_PF(bp)) {
11451 other_load_status = bnx2x_get_load_status(bp, other_engine);
11452 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11453 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11454 bnx2x_chk_parity_attn(bp, &global, true)) {
11455 do {
11456 /* If there are attentions and they are in a
11457 * global blocks, set the GLOBAL_RESET bit
11458 * regardless whether it will be this function
11459 * that will complete the recovery or not.
11460 */
11461 if (global)
11462 bnx2x_set_reset_global(bp);
72fd0718 11463
ad5afc89
AE
11464 /* Only the first function on the current
11465 * engine should try to recover in open. In case
11466 * of attentions in global blocks only the first
11467 * in the chip should try to recover.
11468 */
11469 if ((!load_status &&
11470 (!global || !other_load_status)) &&
11471 bnx2x_trylock_leader_lock(bp) &&
11472 !bnx2x_leader_reset(bp)) {
11473 netdev_info(bp->dev,
11474 "Recovered in open\n");
11475 break;
11476 }
72fd0718 11477
ad5afc89
AE
11478 /* recovery has failed... */
11479 bnx2x_set_power_state(bp, PCI_D3hot);
11480 bp->recovery_state = BNX2X_RECOVERY_FAILED;
72fd0718 11481
ad5afc89
AE
11482 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11483 "If you still see this message after a few retries then power cycle is required.\n");
72fd0718 11484
ad5afc89
AE
11485 return -EAGAIN;
11486 } while (0);
11487 }
11488 }
72fd0718
VZ
11489
11490 bp->recovery_state = BNX2X_RECOVERY_DONE;
8395be5e
AE
11491 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11492 if (rc)
11493 return rc;
11494 return bnx2x_open_epilog(bp);
a2fbb9ea
ET
11495}
11496
bb2a0f7a 11497/* called with rtnl_lock */
56ad3152 11498static int bnx2x_close(struct net_device *dev)
a2fbb9ea 11499{
a2fbb9ea
ET
11500 struct bnx2x *bp = netdev_priv(dev);
11501
11502 /* Unload the driver, release IRQs */
5d07d868 11503 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
c9ee9206
VZ
11504
11505 /* Power off */
d3dbfee0 11506 bnx2x_set_power_state(bp, PCI_D3hot);
a2fbb9ea
ET
11507
11508 return 0;
11509}
11510
1191cb83
ED
11511static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11512 struct bnx2x_mcast_ramrod_params *p)
6e30dd4e 11513{
619c5cb6
VZ
11514 int mc_count = netdev_mc_count(bp->dev);
11515 struct bnx2x_mcast_list_elem *mc_mac =
11516 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11517 struct netdev_hw_addr *ha;
6e30dd4e 11518
619c5cb6
VZ
11519 if (!mc_mac)
11520 return -ENOMEM;
6e30dd4e 11521
619c5cb6 11522 INIT_LIST_HEAD(&p->mcast_list);
6e30dd4e 11523
619c5cb6
VZ
11524 netdev_for_each_mc_addr(ha, bp->dev) {
11525 mc_mac->mac = bnx2x_mc_addr(ha);
11526 list_add_tail(&mc_mac->link, &p->mcast_list);
11527 mc_mac++;
6e30dd4e 11528 }
619c5cb6
VZ
11529
11530 p->mcast_list_len = mc_count;
11531
11532 return 0;
6e30dd4e
VZ
11533}
11534
1191cb83 11535static void bnx2x_free_mcast_macs_list(
619c5cb6
VZ
11536 struct bnx2x_mcast_ramrod_params *p)
11537{
11538 struct bnx2x_mcast_list_elem *mc_mac =
11539 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11540 link);
11541
11542 WARN_ON(!mc_mac);
11543 kfree(mc_mac);
11544}
11545
11546/**
11547 * bnx2x_set_uc_list - configure a new unicast MACs list.
11548 *
11549 * @bp: driver handle
6e30dd4e 11550 *
619c5cb6 11551 * We will use zero (0) as a MAC type for these MACs.
6e30dd4e 11552 */
1191cb83 11553static int bnx2x_set_uc_list(struct bnx2x *bp)
6e30dd4e 11554{
619c5cb6 11555 int rc;
6e30dd4e 11556 struct net_device *dev = bp->dev;
6e30dd4e 11557 struct netdev_hw_addr *ha;
15192a8c 11558 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
619c5cb6 11559 unsigned long ramrod_flags = 0;
6e30dd4e 11560
619c5cb6
VZ
11561 /* First schedule a cleanup up of old configuration */
11562 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11563 if (rc < 0) {
11564 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11565 return rc;
11566 }
6e30dd4e
VZ
11567
11568 netdev_for_each_uc_addr(ha, dev) {
619c5cb6
VZ
11569 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11570 BNX2X_UC_LIST_MAC, &ramrod_flags);
7b5342d9
YM
11571 if (rc == -EEXIST) {
11572 DP(BNX2X_MSG_SP,
11573 "Failed to schedule ADD operations: %d\n", rc);
11574 /* do not treat adding same MAC as error */
11575 rc = 0;
11576
11577 } else if (rc < 0) {
11578
619c5cb6
VZ
11579 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11580 rc);
11581 return rc;
6e30dd4e
VZ
11582 }
11583 }
11584
619c5cb6
VZ
11585 /* Execute the pending commands */
11586 __set_bit(RAMROD_CONT, &ramrod_flags);
11587 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11588 BNX2X_UC_LIST_MAC, &ramrod_flags);
6e30dd4e
VZ
11589}
11590
1191cb83 11591static int bnx2x_set_mc_list(struct bnx2x *bp)
6e30dd4e 11592{
619c5cb6 11593 struct net_device *dev = bp->dev;
3b603066 11594 struct bnx2x_mcast_ramrod_params rparam = {NULL};
619c5cb6 11595 int rc = 0;
6e30dd4e 11596
619c5cb6 11597 rparam.mcast_obj = &bp->mcast_obj;
6e30dd4e 11598
619c5cb6
VZ
11599 /* first, clear all configured multicast MACs */
11600 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11601 if (rc < 0) {
51c1a580 11602 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
619c5cb6
VZ
11603 return rc;
11604 }
6e30dd4e 11605
619c5cb6
VZ
11606 /* then, configure a new MACs list */
11607 if (netdev_mc_count(dev)) {
11608 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11609 if (rc) {
51c1a580
MS
11610 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11611 rc);
619c5cb6
VZ
11612 return rc;
11613 }
6e30dd4e 11614
619c5cb6
VZ
11615 /* Now add the new MACs */
11616 rc = bnx2x_config_mcast(bp, &rparam,
11617 BNX2X_MCAST_CMD_ADD);
11618 if (rc < 0)
51c1a580
MS
11619 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11620 rc);
6e30dd4e 11621
619c5cb6
VZ
11622 bnx2x_free_mcast_macs_list(&rparam);
11623 }
6e30dd4e 11624
619c5cb6 11625 return rc;
6e30dd4e
VZ
11626}
11627
619c5cb6 11628/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9f6c9258 11629void bnx2x_set_rx_mode(struct net_device *dev)
34f80b04
EG
11630{
11631 struct bnx2x *bp = netdev_priv(dev);
11632 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
34f80b04
EG
11633
11634 if (bp->state != BNX2X_STATE_OPEN) {
11635 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11636 return;
11637 }
11638
619c5cb6 11639 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
34f80b04
EG
11640
11641 if (dev->flags & IFF_PROMISC)
11642 rx_mode = BNX2X_RX_MODE_PROMISC;
619c5cb6
VZ
11643 else if ((dev->flags & IFF_ALLMULTI) ||
11644 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11645 CHIP_IS_E1(bp)))
34f80b04 11646 rx_mode = BNX2X_RX_MODE_ALLMULTI;
6e30dd4e 11647 else {
381ac16b
AE
11648 if (IS_PF(bp)) {
11649 /* some multicasts */
11650 if (bnx2x_set_mc_list(bp) < 0)
11651 rx_mode = BNX2X_RX_MODE_ALLMULTI;
34f80b04 11652
381ac16b
AE
11653 if (bnx2x_set_uc_list(bp) < 0)
11654 rx_mode = BNX2X_RX_MODE_PROMISC;
11655 } else {
11656 /* configuring mcast to a vf involves sleeping (when we
11657 * wait for the pf's response). Since this function is
11658 * called from non sleepable context we must schedule
11659 * a work item for this purpose
11660 */
11661 smp_mb__before_clear_bit();
11662 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
11663 &bp->sp_rtnl_state);
11664 smp_mb__after_clear_bit();
11665 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11666 }
34f80b04
EG
11667 }
11668
11669 bp->rx_mode = rx_mode;
614c76df
DK
11670 /* handle ISCSI SD mode */
11671 if (IS_MF_ISCSI_SD(bp))
11672 bp->rx_mode = BNX2X_RX_MODE_NONE;
619c5cb6
VZ
11673
11674 /* Schedule the rx_mode command */
11675 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11676 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11677 return;
11678 }
11679
381ac16b
AE
11680 if (IS_PF(bp)) {
11681 bnx2x_set_storm_rx_mode(bp);
11682 } else {
11683 /* configuring rx mode to storms in a vf involves sleeping (when
11684 * we wait for the pf's response). Since this function is
11685 * called from non sleepable context we must schedule
11686 * a work item for this purpose
11687 */
11688 smp_mb__before_clear_bit();
11689 set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
11690 &bp->sp_rtnl_state);
11691 smp_mb__after_clear_bit();
11692 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11693 }
34f80b04
EG
11694}
11695
c18487ee 11696/* called with rtnl_lock */
01cd4528
EG
11697static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11698 int devad, u16 addr)
a2fbb9ea 11699{
01cd4528
EG
11700 struct bnx2x *bp = netdev_priv(netdev);
11701 u16 value;
11702 int rc;
a2fbb9ea 11703
01cd4528
EG
11704 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11705 prtad, devad, addr);
a2fbb9ea 11706
01cd4528
EG
11707 /* The HW expects different devad if CL22 is used */
11708 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
c18487ee 11709
01cd4528 11710 bnx2x_acquire_phy_lock(bp);
e10bc84d 11711 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
01cd4528
EG
11712 bnx2x_release_phy_lock(bp);
11713 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
a2fbb9ea 11714
01cd4528
EG
11715 if (!rc)
11716 rc = value;
11717 return rc;
11718}
a2fbb9ea 11719
01cd4528
EG
11720/* called with rtnl_lock */
11721static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11722 u16 addr, u16 value)
11723{
11724 struct bnx2x *bp = netdev_priv(netdev);
01cd4528
EG
11725 int rc;
11726
51c1a580
MS
11727 DP(NETIF_MSG_LINK,
11728 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11729 prtad, devad, addr, value);
01cd4528 11730
01cd4528
EG
11731 /* The HW expects different devad if CL22 is used */
11732 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
a2fbb9ea 11733
01cd4528 11734 bnx2x_acquire_phy_lock(bp);
e10bc84d 11735 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
01cd4528
EG
11736 bnx2x_release_phy_lock(bp);
11737 return rc;
11738}
c18487ee 11739
01cd4528
EG
11740/* called with rtnl_lock */
11741static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11742{
11743 struct bnx2x *bp = netdev_priv(dev);
11744 struct mii_ioctl_data *mdio = if_mii(ifr);
a2fbb9ea 11745
01cd4528
EG
11746 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11747 mdio->phy_id, mdio->reg_num, mdio->val_in);
a2fbb9ea 11748
01cd4528
EG
11749 if (!netif_running(dev))
11750 return -EAGAIN;
11751
11752 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
a2fbb9ea
ET
11753}
11754
257ddbda 11755#ifdef CONFIG_NET_POLL_CONTROLLER
a2fbb9ea
ET
11756static void poll_bnx2x(struct net_device *dev)
11757{
11758 struct bnx2x *bp = netdev_priv(dev);
14a15d61 11759 int i;
a2fbb9ea 11760
14a15d61
MS
11761 for_each_eth_queue(bp, i) {
11762 struct bnx2x_fastpath *fp = &bp->fp[i];
11763 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11764 }
a2fbb9ea
ET
11765}
11766#endif
11767
614c76df
DK
11768static int bnx2x_validate_addr(struct net_device *dev)
11769{
11770 struct bnx2x *bp = netdev_priv(dev);
11771
51c1a580
MS
11772 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11773 BNX2X_ERR("Non-valid Ethernet address\n");
614c76df 11774 return -EADDRNOTAVAIL;
51c1a580 11775 }
614c76df
DK
11776 return 0;
11777}
11778
c64213cd
SH
11779static const struct net_device_ops bnx2x_netdev_ops = {
11780 .ndo_open = bnx2x_open,
11781 .ndo_stop = bnx2x_close,
11782 .ndo_start_xmit = bnx2x_start_xmit,
8307fa3e 11783 .ndo_select_queue = bnx2x_select_queue,
6e30dd4e 11784 .ndo_set_rx_mode = bnx2x_set_rx_mode,
c64213cd 11785 .ndo_set_mac_address = bnx2x_change_mac_addr,
614c76df 11786 .ndo_validate_addr = bnx2x_validate_addr,
c64213cd
SH
11787 .ndo_do_ioctl = bnx2x_ioctl,
11788 .ndo_change_mtu = bnx2x_change_mtu,
66371c44
MM
11789 .ndo_fix_features = bnx2x_fix_features,
11790 .ndo_set_features = bnx2x_set_features,
c64213cd 11791 .ndo_tx_timeout = bnx2x_tx_timeout,
257ddbda 11792#ifdef CONFIG_NET_POLL_CONTROLLER
c64213cd
SH
11793 .ndo_poll_controller = poll_bnx2x,
11794#endif
6383c0b3 11795 .ndo_setup_tc = bnx2x_setup_tc,
6411280a 11796#ifdef CONFIG_BNX2X_SRIOV
abc5a021 11797 .ndo_set_vf_mac = bnx2x_set_vf_mac,
6411280a 11798#endif
55c11941 11799#ifdef NETDEV_FCOE_WWNN
bf61ee14
VZ
11800 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11801#endif
c64213cd
SH
11802};
11803
1191cb83 11804static int bnx2x_set_coherency_mask(struct bnx2x *bp)
619c5cb6
VZ
11805{
11806 struct device *dev = &bp->pdev->dev;
11807
11808 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11809 bp->flags |= USING_DAC_FLAG;
11810 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
51c1a580 11811 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
619c5cb6
VZ
11812 return -EIO;
11813 }
11814 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11815 dev_err(dev, "System does not support DMA, aborting\n");
11816 return -EIO;
11817 }
11818
11819 return 0;
11820}
11821
1ab4434c
AE
11822static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
11823 struct net_device *dev, unsigned long board_type)
a2fbb9ea 11824{
a2fbb9ea 11825 int rc;
c22610d0 11826 u32 pci_cfg_dword;
65087cfe
AE
11827 bool chip_is_e1x = (board_type == BCM57710 ||
11828 board_type == BCM57711 ||
11829 board_type == BCM57711E);
a2fbb9ea
ET
11830
11831 SET_NETDEV_DEV(dev, &pdev->dev);
a2fbb9ea 11832
34f80b04
EG
11833 bp->dev = dev;
11834 bp->pdev = pdev;
a2fbb9ea
ET
11835
11836 rc = pci_enable_device(pdev);
11837 if (rc) {
cdaa7cb8
VZ
11838 dev_err(&bp->pdev->dev,
11839 "Cannot enable PCI device, aborting\n");
a2fbb9ea
ET
11840 goto err_out;
11841 }
11842
11843 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
cdaa7cb8
VZ
11844 dev_err(&bp->pdev->dev,
11845 "Cannot find PCI device base address, aborting\n");
a2fbb9ea
ET
11846 rc = -ENODEV;
11847 goto err_out_disable;
11848 }
11849
1ab4434c
AE
11850 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11851 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
a2fbb9ea
ET
11852 rc = -ENODEV;
11853 goto err_out_disable;
11854 }
11855
092a5fc9
YR
11856 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
11857 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
11858 PCICFG_REVESION_ID_ERROR_VAL) {
11859 pr_err("PCI device error, probably due to fan failure, aborting\n");
11860 rc = -ENODEV;
11861 goto err_out_disable;
11862 }
11863
34f80b04
EG
11864 if (atomic_read(&pdev->enable_cnt) == 1) {
11865 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11866 if (rc) {
cdaa7cb8
VZ
11867 dev_err(&bp->pdev->dev,
11868 "Cannot obtain PCI resources, aborting\n");
34f80b04
EG
11869 goto err_out_disable;
11870 }
a2fbb9ea 11871
34f80b04
EG
11872 pci_set_master(pdev);
11873 pci_save_state(pdev);
11874 }
a2fbb9ea 11875
1ab4434c
AE
11876 if (IS_PF(bp)) {
11877 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11878 if (bp->pm_cap == 0) {
11879 dev_err(&bp->pdev->dev,
11880 "Cannot find power management capability, aborting\n");
11881 rc = -EIO;
11882 goto err_out_release;
11883 }
a2fbb9ea
ET
11884 }
11885
77c98e6a 11886 if (!pci_is_pcie(pdev)) {
51c1a580 11887 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
a2fbb9ea
ET
11888 rc = -EIO;
11889 goto err_out_release;
11890 }
11891
619c5cb6
VZ
11892 rc = bnx2x_set_coherency_mask(bp);
11893 if (rc)
a2fbb9ea 11894 goto err_out_release;
a2fbb9ea 11895
34f80b04
EG
11896 dev->mem_start = pci_resource_start(pdev, 0);
11897 dev->base_addr = dev->mem_start;
11898 dev->mem_end = pci_resource_end(pdev, 0);
a2fbb9ea
ET
11899
11900 dev->irq = pdev->irq;
11901
275f165f 11902 bp->regview = pci_ioremap_bar(pdev, 0);
a2fbb9ea 11903 if (!bp->regview) {
cdaa7cb8
VZ
11904 dev_err(&bp->pdev->dev,
11905 "Cannot map register space, aborting\n");
a2fbb9ea
ET
11906 rc = -ENOMEM;
11907 goto err_out_release;
11908 }
11909
c22610d0
AE
11910 /* In E1/E1H use pci device function given by kernel.
11911 * In E2/E3 read physical function from ME register since these chips
11912 * support Physical Device Assignment where kernel BDF maybe arbitrary
11913 * (depending on hypervisor).
11914 */
2de67439 11915 if (chip_is_e1x) {
c22610d0 11916 bp->pf_num = PCI_FUNC(pdev->devfn);
2de67439
YM
11917 } else {
11918 /* chip is E2/3*/
c22610d0
AE
11919 pci_read_config_dword(bp->pdev,
11920 PCICFG_ME_REGISTER, &pci_cfg_dword);
11921 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
2de67439 11922 ME_REG_ABS_PF_NUM_SHIFT);
c22610d0 11923 }
51c1a580 11924 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
c22610d0 11925
a2fbb9ea
ET
11926 bnx2x_set_power_state(bp, PCI_D0);
11927
34f80b04
EG
11928 /* clean indirect addresses */
11929 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11930 PCICFG_VENDOR_ID_OFFSET);
a5c53dbc
DK
11931 /*
11932 * Clean the following indirect addresses for all functions since it
9f0096a1
DK
11933 * is not used by the driver.
11934 */
1ab4434c
AE
11935 if (IS_PF(bp)) {
11936 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11937 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11938 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11939 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
11940
11941 if (chip_is_e1x) {
11942 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11943 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11944 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11945 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11946 }
a5c53dbc 11947
1ab4434c
AE
11948 /* Enable internal target-read (in case we are probed after PF
11949 * FLR). Must be done prior to any BAR read access. Only for
11950 * 57712 and up
11951 */
11952 if (!chip_is_e1x)
11953 REG_WR(bp,
11954 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
a5c53dbc 11955 }
a2fbb9ea 11956
34f80b04 11957 dev->watchdog_timeo = TX_TIMEOUT;
a2fbb9ea 11958
c64213cd 11959 dev->netdev_ops = &bnx2x_netdev_ops;
de0c62db 11960 bnx2x_set_ethtool_ops(dev);
5316bc0b 11961
01789349
JP
11962 dev->priv_flags |= IFF_UNICAST_FLT;
11963
66371c44 11964 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
621b4d66
DK
11965 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11966 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11967 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
66371c44
MM
11968
11969 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11970 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11971
11972 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
5316bc0b 11973 if (bp->flags & USING_DAC_FLAG)
66371c44 11974 dev->features |= NETIF_F_HIGHDMA;
a2fbb9ea 11975
538dd2e3
MB
11976 /* Add Loopback capability to the device */
11977 dev->hw_features |= NETIF_F_LOOPBACK;
11978
98507672 11979#ifdef BCM_DCBNL
785b9b1a
SR
11980 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11981#endif
11982
01cd4528
EG
11983 /* get_port_hwinfo() will set prtad and mmds properly */
11984 bp->mdio.prtad = MDIO_PRTAD_NONE;
11985 bp->mdio.mmds = 0;
11986 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11987 bp->mdio.dev = dev;
11988 bp->mdio.mdio_read = bnx2x_mdio_read;
11989 bp->mdio.mdio_write = bnx2x_mdio_write;
11990
a2fbb9ea
ET
11991 return 0;
11992
a2fbb9ea 11993err_out_release:
34f80b04
EG
11994 if (atomic_read(&pdev->enable_cnt) == 1)
11995 pci_release_regions(pdev);
a2fbb9ea
ET
11996
11997err_out_disable:
11998 pci_disable_device(pdev);
11999 pci_set_drvdata(pdev, NULL);
12000
12001err_out:
12002 return rc;
12003}
12004
1dd06ae8 12005static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
25047950 12006{
1ab4434c 12007 u32 val = 0;
25047950 12008
1ab4434c 12009 pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
37f9ce62 12010 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
25047950 12011
37f9ce62
EG
12012 /* return value of 1=2.5GHz 2=5GHz */
12013 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
25047950 12014}
37f9ce62 12015
6891dd25 12016static int bnx2x_check_firmware(struct bnx2x *bp)
94a78b79 12017{
37f9ce62 12018 const struct firmware *firmware = bp->firmware;
94a78b79
VZ
12019 struct bnx2x_fw_file_hdr *fw_hdr;
12020 struct bnx2x_fw_file_section *sections;
94a78b79 12021 u32 offset, len, num_ops;
86564c3f 12022 __be16 *ops_offsets;
94a78b79 12023 int i;
37f9ce62 12024 const u8 *fw_ver;
94a78b79 12025
51c1a580
MS
12026 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12027 BNX2X_ERR("Wrong FW size\n");
94a78b79 12028 return -EINVAL;
51c1a580 12029 }
94a78b79
VZ
12030
12031 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12032 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12033
12034 /* Make sure none of the offsets and sizes make us read beyond
12035 * the end of the firmware data */
12036 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12037 offset = be32_to_cpu(sections[i].offset);
12038 len = be32_to_cpu(sections[i].len);
12039 if (offset + len > firmware->size) {
51c1a580 12040 BNX2X_ERR("Section %d length is out of bounds\n", i);
94a78b79
VZ
12041 return -EINVAL;
12042 }
12043 }
12044
12045 /* Likewise for the init_ops offsets */
12046 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
86564c3f 12047 ops_offsets = (__force __be16 *)(firmware->data + offset);
94a78b79
VZ
12048 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12049
12050 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12051 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
51c1a580 12052 BNX2X_ERR("Section offset %d is out of bounds\n", i);
94a78b79
VZ
12053 return -EINVAL;
12054 }
12055 }
12056
12057 /* Check FW version */
12058 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12059 fw_ver = firmware->data + offset;
12060 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12061 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12062 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12063 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
51c1a580
MS
12064 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12065 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12066 BCM_5710_FW_MAJOR_VERSION,
94a78b79
VZ
12067 BCM_5710_FW_MINOR_VERSION,
12068 BCM_5710_FW_REVISION_VERSION,
12069 BCM_5710_FW_ENGINEERING_VERSION);
ab6ad5a4 12070 return -EINVAL;
94a78b79
VZ
12071 }
12072
12073 return 0;
12074}
12075
1191cb83 12076static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12077{
ab6ad5a4
EG
12078 const __be32 *source = (const __be32 *)_source;
12079 u32 *target = (u32 *)_target;
94a78b79 12080 u32 i;
94a78b79
VZ
12081
12082 for (i = 0; i < n/4; i++)
12083 target[i] = be32_to_cpu(source[i]);
12084}
12085
12086/*
12087 Ops array is stored in the following format:
12088 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12089 */
1191cb83 12090static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
94a78b79 12091{
ab6ad5a4
EG
12092 const __be32 *source = (const __be32 *)_source;
12093 struct raw_op *target = (struct raw_op *)_target;
94a78b79 12094 u32 i, j, tmp;
94a78b79 12095
ab6ad5a4 12096 for (i = 0, j = 0; i < n/8; i++, j += 2) {
94a78b79
VZ
12097 tmp = be32_to_cpu(source[j]);
12098 target[i].op = (tmp >> 24) & 0xff;
cdaa7cb8
VZ
12099 target[i].offset = tmp & 0xffffff;
12100 target[i].raw_data = be32_to_cpu(source[j + 1]);
94a78b79
VZ
12101 }
12102}
ab6ad5a4 12103
1aa8b471 12104/* IRO array is stored in the following format:
523224a3
DK
12105 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12106 */
1191cb83 12107static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
523224a3
DK
12108{
12109 const __be32 *source = (const __be32 *)_source;
12110 struct iro *target = (struct iro *)_target;
12111 u32 i, j, tmp;
12112
12113 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12114 target[i].base = be32_to_cpu(source[j]);
12115 j++;
12116 tmp = be32_to_cpu(source[j]);
12117 target[i].m1 = (tmp >> 16) & 0xffff;
12118 target[i].m2 = tmp & 0xffff;
12119 j++;
12120 tmp = be32_to_cpu(source[j]);
12121 target[i].m3 = (tmp >> 16) & 0xffff;
12122 target[i].size = tmp & 0xffff;
12123 j++;
12124 }
12125}
12126
1191cb83 12127static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
94a78b79 12128{
ab6ad5a4
EG
12129 const __be16 *source = (const __be16 *)_source;
12130 u16 *target = (u16 *)_target;
94a78b79 12131 u32 i;
94a78b79
VZ
12132
12133 for (i = 0; i < n/2; i++)
12134 target[i] = be16_to_cpu(source[i]);
12135}
12136
7995c64e
JP
12137#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12138do { \
12139 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12140 bp->arr = kmalloc(len, GFP_KERNEL); \
e404decb 12141 if (!bp->arr) \
7995c64e 12142 goto lbl; \
7995c64e
JP
12143 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12144 (u8 *)bp->arr, len); \
12145} while (0)
94a78b79 12146
3b603066 12147static int bnx2x_init_firmware(struct bnx2x *bp)
94a78b79 12148{
c0ea452e 12149 const char *fw_file_name;
94a78b79 12150 struct bnx2x_fw_file_hdr *fw_hdr;
45229b42 12151 int rc;
94a78b79 12152
c0ea452e
MS
12153 if (bp->firmware)
12154 return 0;
94a78b79 12155
c0ea452e
MS
12156 if (CHIP_IS_E1(bp))
12157 fw_file_name = FW_FILE_NAME_E1;
12158 else if (CHIP_IS_E1H(bp))
12159 fw_file_name = FW_FILE_NAME_E1H;
12160 else if (!CHIP_IS_E1x(bp))
12161 fw_file_name = FW_FILE_NAME_E2;
12162 else {
12163 BNX2X_ERR("Unsupported chip revision\n");
12164 return -EINVAL;
12165 }
12166 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
94a78b79 12167
c0ea452e
MS
12168 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12169 if (rc) {
12170 BNX2X_ERR("Can't load firmware file %s\n",
12171 fw_file_name);
12172 goto request_firmware_exit;
12173 }
eb2afd4a 12174
c0ea452e
MS
12175 rc = bnx2x_check_firmware(bp);
12176 if (rc) {
12177 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12178 goto request_firmware_exit;
94a78b79
VZ
12179 }
12180
12181 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12182
12183 /* Initialize the pointers to the init arrays */
12184 /* Blob */
12185 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12186
12187 /* Opcodes */
12188 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12189
12190 /* Offsets */
ab6ad5a4
EG
12191 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12192 be16_to_cpu_n);
94a78b79
VZ
12193
12194 /* STORMs firmware */
573f2035
EG
12195 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12196 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12197 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12198 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12199 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12200 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12201 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12202 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12203 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12204 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12205 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12206 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12207 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12208 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12209 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12210 be32_to_cpu(fw_hdr->csem_pram_data.offset);
523224a3
DK
12211 /* IRO */
12212 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
94a78b79
VZ
12213
12214 return 0;
ab6ad5a4 12215
523224a3
DK
12216iro_alloc_err:
12217 kfree(bp->init_ops_offsets);
94a78b79
VZ
12218init_offsets_alloc_err:
12219 kfree(bp->init_ops);
12220init_ops_alloc_err:
12221 kfree(bp->init_data);
12222request_firmware_exit:
12223 release_firmware(bp->firmware);
127d0a19 12224 bp->firmware = NULL;
94a78b79
VZ
12225
12226 return rc;
12227}
12228
619c5cb6
VZ
12229static void bnx2x_release_firmware(struct bnx2x *bp)
12230{
12231 kfree(bp->init_ops_offsets);
12232 kfree(bp->init_ops);
12233 kfree(bp->init_data);
12234 release_firmware(bp->firmware);
eb2afd4a 12235 bp->firmware = NULL;
619c5cb6
VZ
12236}
12237
12238
12239static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12240 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12241 .init_hw_cmn = bnx2x_init_hw_common,
12242 .init_hw_port = bnx2x_init_hw_port,
12243 .init_hw_func = bnx2x_init_hw_func,
12244
12245 .reset_hw_cmn = bnx2x_reset_common,
12246 .reset_hw_port = bnx2x_reset_port,
12247 .reset_hw_func = bnx2x_reset_func,
12248
12249 .gunzip_init = bnx2x_gunzip_init,
12250 .gunzip_end = bnx2x_gunzip_end,
12251
12252 .init_fw = bnx2x_init_firmware,
12253 .release_fw = bnx2x_release_firmware,
12254};
12255
12256void bnx2x__init_func_obj(struct bnx2x *bp)
12257{
12258 /* Prepare DMAE related driver resources */
12259 bnx2x_setup_dmae(bp);
12260
12261 bnx2x_init_func_obj(bp, &bp->func_obj,
12262 bnx2x_sp(bp, func_rdata),
12263 bnx2x_sp_mapping(bp, func_rdata),
a3348722
BW
12264 bnx2x_sp(bp, func_afex_rdata),
12265 bnx2x_sp_mapping(bp, func_afex_rdata),
619c5cb6
VZ
12266 &bnx2x_func_sp_drv);
12267}
12268
12269/* must be called after sriov-enable */
1191cb83 12270static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
523224a3 12271{
37ae41a9 12272 int cid_count = BNX2X_L2_MAX_CID(bp);
94a78b79 12273
290ca2bb
AE
12274 if (IS_SRIOV(bp))
12275 cid_count += BNX2X_VF_CIDS;
12276
55c11941
MS
12277 if (CNIC_SUPPORT(bp))
12278 cid_count += CNIC_CID_MAX;
290ca2bb 12279
523224a3
DK
12280 return roundup(cid_count, QM_CID_ROUND);
12281}
f85582f8 12282
619c5cb6 12283/**
6383c0b3 12284 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
619c5cb6
VZ
12285 *
12286 * @dev: pci device
12287 *
12288 */
55c11941 12289static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
1ab4434c 12290 int cnic_cnt, bool is_vf)
619c5cb6 12291{
1ab4434c
AE
12292 int pos, index;
12293 u16 control = 0;
619c5cb6
VZ
12294
12295 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
6383c0b3
AE
12296
12297 /*
12298 * If MSI-X is not supported - return number of SBs needed to support
12299 * one fast path queue: one FP queue + SB for CNIC
12300 */
1ab4434c
AE
12301 if (!pos) {
12302 dev_info(&pdev->dev, "no msix capability found\n");
55c11941 12303 return 1 + cnic_cnt;
1ab4434c
AE
12304 }
12305 dev_info(&pdev->dev, "msix capability found\n");
619c5cb6 12306
6383c0b3
AE
12307 /*
12308 * The value in the PCI configuration space is the index of the last
12309 * entry, namely one less than the actual size of the table, which is
12310 * exactly what we want to return from this function: number of all SBs
12311 * without the default SB.
1ab4434c 12312 * For VFs there is no default SB, then we return (index+1).
6383c0b3 12313 */
619c5cb6 12314 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
619c5cb6 12315
1ab4434c 12316 index = control & PCI_MSIX_FLAGS_QSIZE;
4bd9b0ff 12317
1ab4434c
AE
12318 return is_vf ? index + 1 : index;
12319}
523224a3 12320
1ab4434c
AE
12321static int set_max_cos_est(int chip_id)
12322{
12323 switch (chip_id) {
f2e0899f
DK
12324 case BCM57710:
12325 case BCM57711:
12326 case BCM57711E:
1ab4434c 12327 return BNX2X_MULTI_TX_COS_E1X;
f2e0899f 12328 case BCM57712:
619c5cb6 12329 case BCM57712_MF:
1ab4434c
AE
12330 case BCM57712_VF:
12331 return BNX2X_MULTI_TX_COS_E2_E3A0;
619c5cb6
VZ
12332 case BCM57800:
12333 case BCM57800_MF:
1ab4434c 12334 case BCM57800_VF:
619c5cb6
VZ
12335 case BCM57810:
12336 case BCM57810_MF:
c3def943
YM
12337 case BCM57840_4_10:
12338 case BCM57840_2_20:
1ab4434c 12339 case BCM57840_O:
c3def943 12340 case BCM57840_MFO:
1ab4434c 12341 case BCM57810_VF:
619c5cb6 12342 case BCM57840_MF:
1ab4434c 12343 case BCM57840_VF:
7e8e02df
BW
12344 case BCM57811:
12345 case BCM57811_MF:
1ab4434c
AE
12346 case BCM57811_VF:
12347 return BNX2X_MULTI_TX_COS_E3B0;
12348 return 1;
f2e0899f 12349 default:
1ab4434c 12350 pr_err("Unknown board_type (%d), aborting\n", chip_id);
870634b0 12351 return -ENODEV;
f2e0899f 12352 }
1ab4434c 12353}
f2e0899f 12354
1ab4434c
AE
12355static int set_is_vf(int chip_id)
12356{
12357 switch (chip_id) {
12358 case BCM57712_VF:
12359 case BCM57800_VF:
12360 case BCM57810_VF:
12361 case BCM57840_VF:
12362 case BCM57811_VF:
12363 return true;
12364 default:
12365 return false;
12366 }
12367}
6383c0b3 12368
1ab4434c
AE
12369struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12370
12371static int bnx2x_init_one(struct pci_dev *pdev,
12372 const struct pci_device_id *ent)
12373{
12374 struct net_device *dev = NULL;
12375 struct bnx2x *bp;
12376 int pcie_width, pcie_speed;
12377 int rc, max_non_def_sbs;
12378 int rx_count, tx_count, rss_count, doorbell_size;
12379 int max_cos_est;
12380 bool is_vf;
12381 int cnic_cnt;
12382
12383 /* An estimated maximum supported CoS number according to the chip
12384 * version.
12385 * We will try to roughly estimate the maximum number of CoSes this chip
12386 * may support in order to minimize the memory allocated for Tx
12387 * netdev_queue's. This number will be accurately calculated during the
12388 * initialization of bp->max_cos based on the chip versions AND chip
12389 * revision in the bnx2x_init_bp().
12390 */
12391 max_cos_est = set_max_cos_est(ent->driver_data);
12392 if (max_cos_est < 0)
12393 return max_cos_est;
12394 is_vf = set_is_vf(ent->driver_data);
12395 cnic_cnt = is_vf ? 0 : 1;
12396
12397 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
6383c0b3
AE
12398
12399 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
1ab4434c
AE
12400 rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
12401
12402 if (rss_count < 1)
12403 return -EINVAL;
6383c0b3
AE
12404
12405 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
55c11941 12406 rx_count = rss_count + cnic_cnt;
6383c0b3 12407
1ab4434c 12408 /* Maximum number of netdev Tx queues:
37ae41a9 12409 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
6383c0b3 12410 */
55c11941 12411 tx_count = rss_count * max_cos_est + cnic_cnt;
f85582f8 12412
a2fbb9ea 12413 /* dev zeroed in init_etherdev */
6383c0b3 12414 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
41de8d4c 12415 if (!dev)
a2fbb9ea
ET
12416 return -ENOMEM;
12417
a2fbb9ea 12418 bp = netdev_priv(dev);
a2fbb9ea 12419
1ab4434c
AE
12420 bp->flags = 0;
12421 if (is_vf)
12422 bp->flags |= IS_VF_FLAG;
12423
6383c0b3 12424 bp->igu_sb_cnt = max_non_def_sbs;
1ab4434c 12425 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
6383c0b3 12426 bp->msg_enable = debug;
55c11941 12427 bp->cnic_support = cnic_cnt;
4bd9b0ff 12428 bp->cnic_probe = bnx2x_cnic_probe;
55c11941 12429
6383c0b3 12430 pci_set_drvdata(pdev, dev);
523224a3 12431
1ab4434c 12432 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
a2fbb9ea
ET
12433 if (rc < 0) {
12434 free_netdev(dev);
12435 return rc;
12436 }
12437
1ab4434c
AE
12438 BNX2X_DEV_INFO("This is a %s function\n",
12439 IS_PF(bp) ? "physical" : "virtual");
55c11941 12440 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
1ab4434c 12441 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
60aa0509 12442 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
2de67439 12443 tx_count, rx_count);
60aa0509 12444
34f80b04 12445 rc = bnx2x_init_bp(bp);
693fc0d1
EG
12446 if (rc)
12447 goto init_one_exit;
12448
1ab4434c
AE
12449 /* Map doorbells here as we need the real value of bp->max_cos which
12450 * is initialized in bnx2x_init_bp() to determine the number of
12451 * l2 connections.
6383c0b3 12452 */
1ab4434c 12453 if (IS_VF(bp)) {
6411280a
AE
12454 bnx2x_vf_map_doorbells(bp);
12455 rc = bnx2x_vf_pci_alloc(bp);
12456 if (rc)
12457 goto init_one_exit;
1ab4434c
AE
12458 } else {
12459 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12460 if (doorbell_size > pci_resource_len(pdev, 2)) {
12461 dev_err(&bp->pdev->dev,
12462 "Cannot map doorbells, bar size too small, aborting\n");
12463 rc = -ENOMEM;
12464 goto init_one_exit;
12465 }
12466 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12467 doorbell_size);
37ae41a9 12468 }
6383c0b3
AE
12469 if (!bp->doorbells) {
12470 dev_err(&bp->pdev->dev,
12471 "Cannot map doorbell space, aborting\n");
12472 rc = -ENOMEM;
12473 goto init_one_exit;
12474 }
12475
be1f1ffa
AE
12476 if (IS_VF(bp)) {
12477 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12478 if (rc)
12479 goto init_one_exit;
12480 }
12481
290ca2bb
AE
12482 /* Enable SRIOV if capability found in configuration space.
12483 * Once the generic SR-IOV framework makes it in from the
12484 * pci tree this will be revised, to allow dynamic control
12485 * over the number of VFs. Right now, change the num of vfs
12486 * param below to enable SR-IOV.
12487 */
12488 rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
12489 if (rc)
12490 goto init_one_exit;
12491
523224a3 12492 /* calc qm_cid_count */
6383c0b3 12493 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
1ab4434c 12494 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
523224a3 12495
55c11941 12496 /* disable FCOE L2 queue for E1x*/
62ac0dc9 12497 if (CHIP_IS_E1x(bp))
ec6ba945
VZ
12498 bp->flags |= NO_FCOE_FLAG;
12499
477864dd
DK
12500 /* disable FCOE for 57840 device, until FW supports it */
12501 switch (ent->driver_data) {
12502 case BCM57840_O:
12503 case BCM57840_4_10:
12504 case BCM57840_2_20:
12505 case BCM57840_MFO:
12506 case BCM57840_MF:
12507 bp->flags |= NO_FCOE_FLAG;
12508 }
0e8d2ec5
MS
12509
12510 /* Set bp->num_queues for MSI-X mode*/
12511 bnx2x_set_num_queues(bp);
12512
25985edc 12513 /* Configure interrupt mode: try to enable MSI-X/MSI if
0e8d2ec5 12514 * needed.
d6214d7a 12515 */
1ab4434c
AE
12516 rc = bnx2x_set_int_mode(bp);
12517 if (rc) {
12518 dev_err(&pdev->dev, "Cannot set interrupts\n");
12519 goto init_one_exit;
12520 }
04c46736 12521 BNX2X_DEV_INFO("set interrupts successfully\n");
d6214d7a 12522
1ab4434c 12523 /* register the net device */
b340007f
VZ
12524 rc = register_netdev(dev);
12525 if (rc) {
12526 dev_err(&pdev->dev, "Cannot register net device\n");
12527 goto init_one_exit;
12528 }
1ab4434c 12529 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
b340007f 12530
55c11941 12531
ec6ba945
VZ
12532 if (!NO_FCOE(bp)) {
12533 /* Add storage MAC address */
12534 rtnl_lock();
12535 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12536 rtnl_unlock();
12537 }
ec6ba945 12538
37f9ce62 12539 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
1ab4434c
AE
12540 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12541 pcie_width, pcie_speed);
d6214d7a 12542
51c1a580
MS
12543 BNX2X_DEV_INFO(
12544 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
94f05b0f
JP
12545 board_info[ent->driver_data].name,
12546 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12547 pcie_width,
12548 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
12549 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
12550 "5GHz (Gen2)" : "2.5GHz",
12551 dev->base_addr, bp->pdev->irq, dev->dev_addr);
c016201c 12552
a2fbb9ea 12553 return 0;
34f80b04
EG
12554
12555init_one_exit:
12556 if (bp->regview)
12557 iounmap(bp->regview);
12558
1ab4434c 12559 if (IS_PF(bp) && bp->doorbells)
34f80b04
EG
12560 iounmap(bp->doorbells);
12561
12562 free_netdev(dev);
12563
12564 if (atomic_read(&pdev->enable_cnt) == 1)
12565 pci_release_regions(pdev);
12566
12567 pci_disable_device(pdev);
12568 pci_set_drvdata(pdev, NULL);
12569
12570 return rc;
a2fbb9ea
ET
12571}
12572
0329aba1 12573static void bnx2x_remove_one(struct pci_dev *pdev)
a2fbb9ea
ET
12574{
12575 struct net_device *dev = pci_get_drvdata(pdev);
228241eb
ET
12576 struct bnx2x *bp;
12577
12578 if (!dev) {
cdaa7cb8 12579 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
228241eb
ET
12580 return;
12581 }
228241eb 12582 bp = netdev_priv(dev);
a2fbb9ea 12583
ec6ba945
VZ
12584 /* Delete storage MAC address */
12585 if (!NO_FCOE(bp)) {
12586 rtnl_lock();
12587 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12588 rtnl_unlock();
12589 }
ec6ba945 12590
98507672
SR
12591#ifdef BCM_DCBNL
12592 /* Delete app tlvs from dcbnl */
12593 bnx2x_dcbnl_update_applist(bp, true);
12594#endif
12595
a2fbb9ea
ET
12596 unregister_netdev(dev);
12597
084d6cbb 12598 /* Power on: we can't let PCI layer write to us while we are in D3 */
1ab4434c
AE
12599 if (IS_PF(bp))
12600 bnx2x_set_power_state(bp, PCI_D0);
084d6cbb 12601
d6214d7a
DK
12602 /* Disable MSI/MSI-X */
12603 bnx2x_disable_msi(bp);
f85582f8 12604
084d6cbb 12605 /* Power off */
1ab4434c
AE
12606 if (IS_PF(bp))
12607 bnx2x_set_power_state(bp, PCI_D3hot);
084d6cbb 12608
72fd0718 12609 /* Make sure RESET task is not scheduled before continuing */
7be08a72 12610 cancel_delayed_work_sync(&bp->sp_rtnl_task);
290ca2bb
AE
12611
12612 bnx2x_iov_remove_one(bp);
12613
4513f925
AE
12614 /* send message via vfpf channel to release the resources of this vf */
12615 if (IS_VF(bp))
12616 bnx2x_vfpf_release(bp);
72fd0718 12617
a2fbb9ea
ET
12618 if (bp->regview)
12619 iounmap(bp->regview);
12620
1ab4434c
AE
12621 /* for vf doorbells are part of the regview and were unmapped along with
12622 * it. FW is only loaded by PF.
12623 */
12624 if (IS_PF(bp)) {
12625 if (bp->doorbells)
12626 iounmap(bp->doorbells);
eb2afd4a 12627
1ab4434c
AE
12628 bnx2x_release_firmware(bp);
12629 }
523224a3
DK
12630 bnx2x_free_mem_bp(bp);
12631
a2fbb9ea 12632 free_netdev(dev);
34f80b04
EG
12633
12634 if (atomic_read(&pdev->enable_cnt) == 1)
12635 pci_release_regions(pdev);
12636
a2fbb9ea
ET
12637 pci_disable_device(pdev);
12638 pci_set_drvdata(pdev, NULL);
12639}
12640
f8ef6e44
YG
12641static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12642{
12643 int i;
12644
12645 bp->state = BNX2X_STATE_ERROR;
12646
12647 bp->rx_mode = BNX2X_RX_MODE_NONE;
12648
55c11941
MS
12649 if (CNIC_LOADED(bp))
12650 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12651
619c5cb6
VZ
12652 /* Stop Tx */
12653 bnx2x_tx_disable(bp);
12654
f8ef6e44 12655 bnx2x_netif_stop(bp, 0);
26614ba5
MS
12656 /* Delete all NAPI objects */
12657 bnx2x_del_all_napi(bp);
55c11941
MS
12658 if (CNIC_LOADED(bp))
12659 bnx2x_del_all_napi_cnic(bp);
f8ef6e44
YG
12660
12661 del_timer_sync(&bp->timer);
619c5cb6
VZ
12662
12663 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
f8ef6e44
YG
12664
12665 /* Release IRQs */
d6214d7a 12666 bnx2x_free_irq(bp);
f8ef6e44 12667
f8ef6e44
YG
12668 /* Free SKBs, SGEs, TPA pool and driver internals */
12669 bnx2x_free_skbs(bp);
523224a3 12670
ec6ba945 12671 for_each_rx_queue(bp, i)
f8ef6e44 12672 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
d6214d7a 12673
f8ef6e44
YG
12674 bnx2x_free_mem(bp);
12675
12676 bp->state = BNX2X_STATE_CLOSED;
12677
619c5cb6
VZ
12678 netif_carrier_off(bp->dev);
12679
f8ef6e44
YG
12680 return 0;
12681}
12682
12683static void bnx2x_eeh_recover(struct bnx2x *bp)
12684{
12685 u32 val;
12686
12687 mutex_init(&bp->port.phy_mutex);
12688
f8ef6e44
YG
12689
12690 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12691 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12692 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12693 BNX2X_ERR("BAD MCP validity signature\n");
f8ef6e44
YG
12694}
12695
493adb1f
WX
12696/**
12697 * bnx2x_io_error_detected - called when PCI error is detected
12698 * @pdev: Pointer to PCI device
12699 * @state: The current pci connection state
12700 *
12701 * This function is called after a PCI bus error affecting
12702 * this device has been detected.
12703 */
12704static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12705 pci_channel_state_t state)
12706{
12707 struct net_device *dev = pci_get_drvdata(pdev);
12708 struct bnx2x *bp = netdev_priv(dev);
12709
12710 rtnl_lock();
12711
12712 netif_device_detach(dev);
12713
07ce50e4
DN
12714 if (state == pci_channel_io_perm_failure) {
12715 rtnl_unlock();
12716 return PCI_ERS_RESULT_DISCONNECT;
12717 }
12718
493adb1f 12719 if (netif_running(dev))
f8ef6e44 12720 bnx2x_eeh_nic_unload(bp);
493adb1f
WX
12721
12722 pci_disable_device(pdev);
12723
12724 rtnl_unlock();
12725
12726 /* Request a slot reset */
12727 return PCI_ERS_RESULT_NEED_RESET;
12728}
12729
12730/**
12731 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12732 * @pdev: Pointer to PCI device
12733 *
12734 * Restart the card from scratch, as if from a cold-boot.
12735 */
12736static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12737{
12738 struct net_device *dev = pci_get_drvdata(pdev);
12739 struct bnx2x *bp = netdev_priv(dev);
12740
12741 rtnl_lock();
12742
12743 if (pci_enable_device(pdev)) {
12744 dev_err(&pdev->dev,
12745 "Cannot re-enable PCI device after reset\n");
12746 rtnl_unlock();
12747 return PCI_ERS_RESULT_DISCONNECT;
12748 }
12749
12750 pci_set_master(pdev);
12751 pci_restore_state(pdev);
12752
12753 if (netif_running(dev))
12754 bnx2x_set_power_state(bp, PCI_D0);
12755
12756 rtnl_unlock();
12757
12758 return PCI_ERS_RESULT_RECOVERED;
12759}
12760
12761/**
12762 * bnx2x_io_resume - called when traffic can start flowing again
12763 * @pdev: Pointer to PCI device
12764 *
12765 * This callback is called when the error recovery driver tells us that
12766 * its OK to resume normal operation.
12767 */
12768static void bnx2x_io_resume(struct pci_dev *pdev)
12769{
12770 struct net_device *dev = pci_get_drvdata(pdev);
12771 struct bnx2x *bp = netdev_priv(dev);
12772
72fd0718 12773 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
51c1a580 12774 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
72fd0718
VZ
12775 return;
12776 }
12777
493adb1f
WX
12778 rtnl_lock();
12779
f8ef6e44
YG
12780 bnx2x_eeh_recover(bp);
12781
493adb1f 12782 if (netif_running(dev))
f8ef6e44 12783 bnx2x_nic_load(bp, LOAD_NORMAL);
493adb1f
WX
12784
12785 netif_device_attach(dev);
12786
12787 rtnl_unlock();
12788}
12789
3646f0e5 12790static const struct pci_error_handlers bnx2x_err_handler = {
493adb1f 12791 .error_detected = bnx2x_io_error_detected,
356e2385
EG
12792 .slot_reset = bnx2x_io_slot_reset,
12793 .resume = bnx2x_io_resume,
493adb1f
WX
12794};
12795
a2fbb9ea 12796static struct pci_driver bnx2x_pci_driver = {
493adb1f
WX
12797 .name = DRV_MODULE_NAME,
12798 .id_table = bnx2x_pci_tbl,
12799 .probe = bnx2x_init_one,
0329aba1 12800 .remove = bnx2x_remove_one,
493adb1f
WX
12801 .suspend = bnx2x_suspend,
12802 .resume = bnx2x_resume,
12803 .err_handler = &bnx2x_err_handler,
a2fbb9ea
ET
12804};
12805
12806static int __init bnx2x_init(void)
12807{
dd21ca6d
SG
12808 int ret;
12809
7995c64e 12810 pr_info("%s", version);
938cf541 12811
1cf167f2
EG
12812 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12813 if (bnx2x_wq == NULL) {
7995c64e 12814 pr_err("Cannot create workqueue\n");
1cf167f2
EG
12815 return -ENOMEM;
12816 }
12817
dd21ca6d
SG
12818 ret = pci_register_driver(&bnx2x_pci_driver);
12819 if (ret) {
7995c64e 12820 pr_err("Cannot register driver\n");
dd21ca6d
SG
12821 destroy_workqueue(bnx2x_wq);
12822 }
12823 return ret;
a2fbb9ea
ET
12824}
12825
12826static void __exit bnx2x_cleanup(void)
12827{
452427b0 12828 struct list_head *pos, *q;
a2fbb9ea 12829 pci_unregister_driver(&bnx2x_pci_driver);
1cf167f2
EG
12830
12831 destroy_workqueue(bnx2x_wq);
452427b0
YM
12832
12833 /* Free globablly allocated resources */
12834 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12835 struct bnx2x_prev_path_list *tmp =
12836 list_entry(pos, struct bnx2x_prev_path_list, list);
12837 list_del(pos);
12838 kfree(tmp);
12839 }
a2fbb9ea
ET
12840}
12841
3deb8167
YR
12842void bnx2x_notify_link_changed(struct bnx2x *bp)
12843{
12844 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12845}
12846
a2fbb9ea
ET
12847module_init(bnx2x_init);
12848module_exit(bnx2x_cleanup);
12849
619c5cb6
VZ
12850/**
12851 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12852 *
12853 * @bp: driver handle
12854 * @set: set or clear the CAM entry
12855 *
12856 * This function will wait until the ramdord completion returns.
12857 * Return 0 if success, -ENODEV if ramrod doesn't return.
12858 */
1191cb83 12859static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
619c5cb6
VZ
12860{
12861 unsigned long ramrod_flags = 0;
12862
12863 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12864 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12865 &bp->iscsi_l2_mac_obj, true,
12866 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12867}
993ac7b5
MC
12868
12869/* count denotes the number of new completions we have seen */
12870static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12871{
12872 struct eth_spe *spe;
a052997e 12873 int cxt_index, cxt_offset;
993ac7b5
MC
12874
12875#ifdef BNX2X_STOP_ON_ERROR
12876 if (unlikely(bp->panic))
12877 return;
12878#endif
12879
12880 spin_lock_bh(&bp->spq_lock);
c2bff63f 12881 BUG_ON(bp->cnic_spq_pending < count);
993ac7b5
MC
12882 bp->cnic_spq_pending -= count;
12883
993ac7b5 12884
c2bff63f
DK
12885 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12886 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12887 & SPE_HDR_CONN_TYPE) >>
12888 SPE_HDR_CONN_TYPE_SHIFT;
619c5cb6
VZ
12889 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12890 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
c2bff63f
DK
12891
12892 /* Set validation for iSCSI L2 client before sending SETUP
12893 * ramrod
12894 */
12895 if (type == ETH_CONNECTION_TYPE) {
a052997e 12896 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
37ae41a9 12897 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
a052997e 12898 ILT_PAGE_CIDS;
37ae41a9 12899 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
a052997e
MS
12900 (cxt_index * ILT_PAGE_CIDS);
12901 bnx2x_set_ctx_validation(bp,
12902 &bp->context[cxt_index].
12903 vcxt[cxt_offset].eth,
37ae41a9 12904 BNX2X_ISCSI_ETH_CID(bp));
a052997e 12905 }
c2bff63f
DK
12906 }
12907
619c5cb6
VZ
12908 /*
12909 * There may be not more than 8 L2, not more than 8 L5 SPEs
12910 * and in the air. We also check that number of outstanding
6e30dd4e
VZ
12911 * COMMON ramrods is not more than the EQ and SPQ can
12912 * accommodate.
c2bff63f 12913 */
6e30dd4e
VZ
12914 if (type == ETH_CONNECTION_TYPE) {
12915 if (!atomic_read(&bp->cq_spq_left))
12916 break;
12917 else
12918 atomic_dec(&bp->cq_spq_left);
12919 } else if (type == NONE_CONNECTION_TYPE) {
12920 if (!atomic_read(&bp->eq_spq_left))
c2bff63f
DK
12921 break;
12922 else
6e30dd4e 12923 atomic_dec(&bp->eq_spq_left);
ec6ba945
VZ
12924 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12925 (type == FCOE_CONNECTION_TYPE)) {
c2bff63f
DK
12926 if (bp->cnic_spq_pending >=
12927 bp->cnic_eth_dev.max_kwqe_pending)
12928 break;
12929 else
12930 bp->cnic_spq_pending++;
12931 } else {
12932 BNX2X_ERR("Unknown SPE type: %d\n", type);
12933 bnx2x_panic();
993ac7b5 12934 break;
c2bff63f 12935 }
993ac7b5
MC
12936
12937 spe = bnx2x_sp_get_next(bp);
12938 *spe = *bp->cnic_kwq_cons;
12939
51c1a580 12940 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
993ac7b5
MC
12941 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12942
12943 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12944 bp->cnic_kwq_cons = bp->cnic_kwq;
12945 else
12946 bp->cnic_kwq_cons++;
12947 }
12948 bnx2x_sp_prod_update(bp);
12949 spin_unlock_bh(&bp->spq_lock);
12950}
12951
12952static int bnx2x_cnic_sp_queue(struct net_device *dev,
12953 struct kwqe_16 *kwqes[], u32 count)
12954{
12955 struct bnx2x *bp = netdev_priv(dev);
12956 int i;
12957
12958#ifdef BNX2X_STOP_ON_ERROR
51c1a580
MS
12959 if (unlikely(bp->panic)) {
12960 BNX2X_ERR("Can't post to SP queue while panic\n");
993ac7b5 12961 return -EIO;
51c1a580 12962 }
993ac7b5
MC
12963#endif
12964
95c6c616
AE
12965 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12966 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
51c1a580 12967 BNX2X_ERR("Handling parity error recovery. Try again later\n");
95c6c616
AE
12968 return -EAGAIN;
12969 }
12970
993ac7b5
MC
12971 spin_lock_bh(&bp->spq_lock);
12972
12973 for (i = 0; i < count; i++) {
12974 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12975
12976 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12977 break;
12978
12979 *bp->cnic_kwq_prod = *spe;
12980
12981 bp->cnic_kwq_pending++;
12982
51c1a580 12983 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
993ac7b5 12984 spe->hdr.conn_and_cmd_data, spe->hdr.type,
523224a3
DK
12985 spe->data.update_data_addr.hi,
12986 spe->data.update_data_addr.lo,
993ac7b5
MC
12987 bp->cnic_kwq_pending);
12988
12989 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12990 bp->cnic_kwq_prod = bp->cnic_kwq;
12991 else
12992 bp->cnic_kwq_prod++;
12993 }
12994
12995 spin_unlock_bh(&bp->spq_lock);
12996
12997 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12998 bnx2x_cnic_sp_post(bp, 0);
12999
13000 return i;
13001}
13002
13003static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13004{
13005 struct cnic_ops *c_ops;
13006 int rc = 0;
13007
13008 mutex_lock(&bp->cnic_mutex);
13707f9e
ED
13009 c_ops = rcu_dereference_protected(bp->cnic_ops,
13010 lockdep_is_held(&bp->cnic_mutex));
993ac7b5
MC
13011 if (c_ops)
13012 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13013 mutex_unlock(&bp->cnic_mutex);
13014
13015 return rc;
13016}
13017
13018static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13019{
13020 struct cnic_ops *c_ops;
13021 int rc = 0;
13022
13023 rcu_read_lock();
13024 c_ops = rcu_dereference(bp->cnic_ops);
13025 if (c_ops)
13026 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13027 rcu_read_unlock();
13028
13029 return rc;
13030}
13031
13032/*
13033 * for commands that have no data
13034 */
9f6c9258 13035int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
993ac7b5
MC
13036{
13037 struct cnic_ctl_info ctl = {0};
13038
13039 ctl.cmd = cmd;
13040
13041 return bnx2x_cnic_ctl_send(bp, &ctl);
13042}
13043
619c5cb6 13044static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
993ac7b5 13045{
619c5cb6 13046 struct cnic_ctl_info ctl = {0};
993ac7b5
MC
13047
13048 /* first we tell CNIC and only then we count this as a completion */
13049 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13050 ctl.data.comp.cid = cid;
619c5cb6 13051 ctl.data.comp.error = err;
993ac7b5
MC
13052
13053 bnx2x_cnic_ctl_send_bh(bp, &ctl);
c2bff63f 13054 bnx2x_cnic_sp_post(bp, 0);
993ac7b5
MC
13055}
13056
619c5cb6
VZ
13057
13058/* Called with netif_addr_lock_bh() taken.
13059 * Sets an rx_mode config for an iSCSI ETH client.
13060 * Doesn't block.
13061 * Completion should be checked outside.
13062 */
13063static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13064{
13065 unsigned long accept_flags = 0, ramrod_flags = 0;
13066 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13067 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13068
13069 if (start) {
13070 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13071 * because it's the only way for UIO Queue to accept
13072 * multicasts (in non-promiscuous mode only one Queue per
13073 * function will receive multicast packets (leading in our
13074 * case).
13075 */
13076 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13077 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13078 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13079 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13080
13081 /* Clear STOP_PENDING bit if START is requested */
13082 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13083
13084 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13085 } else
13086 /* Clear START_PENDING bit if STOP is requested */
13087 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13088
13089 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13090 set_bit(sched_state, &bp->sp_state);
13091 else {
13092 __set_bit(RAMROD_RX, &ramrod_flags);
13093 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13094 ramrod_flags);
13095 }
13096}
13097
13098
993ac7b5
MC
13099static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13100{
13101 struct bnx2x *bp = netdev_priv(dev);
13102 int rc = 0;
13103
13104 switch (ctl->cmd) {
13105 case DRV_CTL_CTXTBL_WR_CMD: {
13106 u32 index = ctl->data.io.offset;
13107 dma_addr_t addr = ctl->data.io.dma_addr;
13108
13109 bnx2x_ilt_wr(bp, index, addr);
13110 break;
13111 }
13112
c2bff63f
DK
13113 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13114 int count = ctl->data.credit.credit_count;
993ac7b5
MC
13115
13116 bnx2x_cnic_sp_post(bp, count);
13117 break;
13118 }
13119
13120 /* rtnl_lock is held. */
13121 case DRV_CTL_START_L2_CMD: {
619c5cb6
VZ
13122 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13123 unsigned long sp_bits = 0;
13124
13125 /* Configure the iSCSI classification object */
13126 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13127 cp->iscsi_l2_client_id,
13128 cp->iscsi_l2_cid, BP_FUNC(bp),
13129 bnx2x_sp(bp, mac_rdata),
13130 bnx2x_sp_mapping(bp, mac_rdata),
13131 BNX2X_FILTER_MAC_PENDING,
13132 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13133 &bp->macs_pool);
ec6ba945 13134
523224a3 13135 /* Set iSCSI MAC address */
619c5cb6
VZ
13136 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13137 if (rc)
13138 break;
523224a3
DK
13139
13140 mmiowb();
13141 barrier();
13142
619c5cb6
VZ
13143 /* Start accepting on iSCSI L2 ring */
13144
13145 netif_addr_lock_bh(dev);
13146 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13147 netif_addr_unlock_bh(dev);
13148
13149 /* bits to wait on */
13150 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13151 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13152
13153 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13154 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3 13155
993ac7b5
MC
13156 break;
13157 }
13158
13159 /* rtnl_lock is held. */
13160 case DRV_CTL_STOP_L2_CMD: {
619c5cb6 13161 unsigned long sp_bits = 0;
993ac7b5 13162
523224a3 13163 /* Stop accepting on iSCSI L2 ring */
619c5cb6
VZ
13164 netif_addr_lock_bh(dev);
13165 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13166 netif_addr_unlock_bh(dev);
13167
13168 /* bits to wait on */
13169 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13170 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13171
13172 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13173 BNX2X_ERR("rx_mode completion timed out!\n");
523224a3
DK
13174
13175 mmiowb();
13176 barrier();
13177
13178 /* Unset iSCSI L2 MAC */
619c5cb6
VZ
13179 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13180 BNX2X_ISCSI_ETH_MAC, true);
993ac7b5
MC
13181 break;
13182 }
c2bff63f
DK
13183 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13184 int count = ctl->data.credit.credit_count;
13185
13186 smp_mb__before_atomic_inc();
6e30dd4e 13187 atomic_add(count, &bp->cq_spq_left);
c2bff63f
DK
13188 smp_mb__after_atomic_inc();
13189 break;
13190 }
1d187b34 13191 case DRV_CTL_ULP_REGISTER_CMD: {
2e499d3c 13192 int ulp_type = ctl->data.register_data.ulp_type;
1d187b34
BW
13193
13194 if (CHIP_IS_E3(bp)) {
13195 int idx = BP_FW_MB_IDX(bp);
2e499d3c
BW
13196 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13197 int path = BP_PATH(bp);
13198 int port = BP_PORT(bp);
13199 int i;
13200 u32 scratch_offset;
13201 u32 *host_addr;
1d187b34 13202
2e499d3c 13203 /* first write capability to shmem2 */
1d187b34
BW
13204 if (ulp_type == CNIC_ULP_ISCSI)
13205 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13206 else if (ulp_type == CNIC_ULP_FCOE)
13207 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13208 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
2e499d3c
BW
13209
13210 if ((ulp_type != CNIC_ULP_FCOE) ||
13211 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13212 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13213 break;
13214
13215 /* if reached here - should write fcoe capabilities */
13216 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13217 if (!scratch_offset)
13218 break;
13219 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13220 fcoe_features[path][port]);
13221 host_addr = (u32 *) &(ctl->data.register_data.
13222 fcoe_features);
13223 for (i = 0; i < sizeof(struct fcoe_capabilities);
13224 i += 4)
13225 REG_WR(bp, scratch_offset + i,
13226 *(host_addr + i/4));
1d187b34
BW
13227 }
13228 break;
13229 }
2e499d3c 13230
1d187b34
BW
13231 case DRV_CTL_ULP_UNREGISTER_CMD: {
13232 int ulp_type = ctl->data.ulp_type;
13233
13234 if (CHIP_IS_E3(bp)) {
13235 int idx = BP_FW_MB_IDX(bp);
13236 u32 cap;
13237
13238 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13239 if (ulp_type == CNIC_ULP_ISCSI)
13240 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13241 else if (ulp_type == CNIC_ULP_FCOE)
13242 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13243 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13244 }
13245 break;
13246 }
993ac7b5
MC
13247
13248 default:
13249 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13250 rc = -EINVAL;
13251 }
13252
13253 return rc;
13254}
13255
9f6c9258 13256void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
993ac7b5
MC
13257{
13258 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13259
13260 if (bp->flags & USING_MSIX_FLAG) {
13261 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13262 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13263 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13264 } else {
13265 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13266 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13267 }
619c5cb6 13268 if (!CHIP_IS_E1x(bp))
f2e0899f
DK
13269 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13270 else
13271 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13272
619c5cb6
VZ
13273 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13274 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
993ac7b5
MC
13275 cp->irq_arr[1].status_blk = bp->def_status_blk;
13276 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
523224a3 13277 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
993ac7b5
MC
13278
13279 cp->num_irq = 2;
13280}
13281
37ae41a9
MS
13282void bnx2x_setup_cnic_info(struct bnx2x *bp)
13283{
13284 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13285
13286
13287 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13288 bnx2x_cid_ilt_lines(bp);
13289 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13290 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13291 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13292
13293 if (NO_ISCSI_OOO(bp))
13294 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13295}
13296
993ac7b5
MC
13297static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13298 void *data)
13299{
13300 struct bnx2x *bp = netdev_priv(dev);
13301 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
55c11941
MS
13302 int rc;
13303
13304 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
993ac7b5 13305
51c1a580
MS
13306 if (ops == NULL) {
13307 BNX2X_ERR("NULL ops received\n");
993ac7b5 13308 return -EINVAL;
51c1a580 13309 }
993ac7b5 13310
55c11941
MS
13311 if (!CNIC_SUPPORT(bp)) {
13312 BNX2X_ERR("Can't register CNIC when not supported\n");
13313 return -EOPNOTSUPP;
13314 }
13315
13316 if (!CNIC_LOADED(bp)) {
13317 rc = bnx2x_load_cnic(bp);
13318 if (rc) {
13319 BNX2X_ERR("CNIC-related load failed\n");
13320 return rc;
13321 }
13322
13323 }
13324
13325 bp->cnic_enabled = true;
13326
993ac7b5
MC
13327 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13328 if (!bp->cnic_kwq)
13329 return -ENOMEM;
13330
13331 bp->cnic_kwq_cons = bp->cnic_kwq;
13332 bp->cnic_kwq_prod = bp->cnic_kwq;
13333 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13334
13335 bp->cnic_spq_pending = 0;
13336 bp->cnic_kwq_pending = 0;
13337
13338 bp->cnic_data = data;
13339
13340 cp->num_irq = 0;
619c5cb6 13341 cp->drv_state |= CNIC_DRV_STATE_REGD;
523224a3 13342 cp->iro_arr = bp->iro_arr;
993ac7b5 13343
993ac7b5 13344 bnx2x_setup_cnic_irq_info(bp);
c2bff63f 13345
993ac7b5
MC
13346 rcu_assign_pointer(bp->cnic_ops, ops);
13347
13348 return 0;
13349}
13350
13351static int bnx2x_unregister_cnic(struct net_device *dev)
13352{
13353 struct bnx2x *bp = netdev_priv(dev);
13354 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13355
13356 mutex_lock(&bp->cnic_mutex);
993ac7b5 13357 cp->drv_state = 0;
2cfa5a04 13358 RCU_INIT_POINTER(bp->cnic_ops, NULL);
993ac7b5
MC
13359 mutex_unlock(&bp->cnic_mutex);
13360 synchronize_rcu();
13361 kfree(bp->cnic_kwq);
13362 bp->cnic_kwq = NULL;
13363
13364 return 0;
13365}
13366
13367struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13368{
13369 struct bnx2x *bp = netdev_priv(dev);
13370 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13371
2ba45142
VZ
13372 /* If both iSCSI and FCoE are disabled - return NULL in
13373 * order to indicate CNIC that it should not try to work
13374 * with this device.
13375 */
13376 if (NO_ISCSI(bp) && NO_FCOE(bp))
13377 return NULL;
13378
993ac7b5
MC
13379 cp->drv_owner = THIS_MODULE;
13380 cp->chip_id = CHIP_ID(bp);
13381 cp->pdev = bp->pdev;
13382 cp->io_base = bp->regview;
13383 cp->io_base2 = bp->doorbells;
13384 cp->max_kwqe_pending = 8;
523224a3 13385 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
c2bff63f
DK
13386 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13387 bnx2x_cid_ilt_lines(bp);
993ac7b5 13388 cp->ctx_tbl_len = CNIC_ILT_LINES;
c2bff63f 13389 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
993ac7b5
MC
13390 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13391 cp->drv_ctl = bnx2x_drv_ctl;
13392 cp->drv_register_cnic = bnx2x_register_cnic;
13393 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
37ae41a9 13394 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
619c5cb6
VZ
13395 cp->iscsi_l2_client_id =
13396 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
37ae41a9 13397 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
c2bff63f 13398
2ba45142
VZ
13399 if (NO_ISCSI_OOO(bp))
13400 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13401
13402 if (NO_ISCSI(bp))
13403 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13404
13405 if (NO_FCOE(bp))
13406 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13407
51c1a580
MS
13408 BNX2X_DEV_INFO(
13409 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
c2bff63f
DK
13410 cp->ctx_blk_size,
13411 cp->ctx_tbl_offset,
13412 cp->ctx_tbl_len,
13413 cp->starting_cid);
993ac7b5
MC
13414 return cp;
13415}
993ac7b5 13416
6411280a 13417u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
9b176b6b 13418{
6411280a
AE
13419 struct bnx2x *bp = fp->bp;
13420 u32 offset = BAR_USTRORM_INTMEM;
abc5a021 13421
6411280a
AE
13422 if (IS_VF(bp))
13423 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13424 else if (!CHIP_IS_E1x(bp))
13425 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13426 else
13427 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
8d9ac297 13428
6411280a 13429 return offset;
8d9ac297 13430}
381ac16b 13431
6411280a
AE
13432/* called only on E1H or E2.
13433 * When pretending to be PF, the pretend value is the function number 0...7
13434 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13435 * combination
13436 */
13437int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
381ac16b 13438{
6411280a 13439 u32 pretend_reg;
381ac16b 13440
23826850 13441 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
6411280a 13442 return -1;
381ac16b 13443
6411280a
AE
13444 /* get my own pretend register */
13445 pretend_reg = bnx2x_get_pretend_reg(bp);
13446 REG_WR(bp, pretend_reg, pretend_func_val);
13447 REG_RD(bp, pretend_reg);
381ac16b
AE
13448 return 0;
13449}