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