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