1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2013 Broadcom Corporation
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.
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
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>
42 #include <linux/if_vlan.h>
46 #include <net/checksum.h>
47 #include <net/ip6_checksum.h>
48 #include <linux/workqueue.h>
49 #include <linux/crc32.h>
50 #include <linux/crc32c.h>
51 #include <linux/prefetch.h>
52 #include <linux/zlib.h>
54 #include <linux/semaphore.h>
55 #include <linux/stringify.h>
56 #include <linux/vmalloc.h>
59 #include "bnx2x_init.h"
60 #include "bnx2x_init_ops.h"
61 #include "bnx2x_cmn.h"
62 #include "bnx2x_vfpf.h"
63 #include "bnx2x_dcb.h"
66 #include <linux/firmware.h>
67 #include "bnx2x_fw_file_hdr.h"
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)
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"
76 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
78 #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
80 /* Time in jiffies before concluding the transmitter is hung */
81 #define TX_TIMEOUT (5*HZ)
83 static char version
[] =
84 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
85 DRV_MODULE_NAME
" " DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
87 MODULE_AUTHOR("Eliezer Tamir");
88 MODULE_DESCRIPTION("Broadcom NetXtreme II "
89 "BCM57710/57711/57711E/"
90 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
91 "57840/57840_MF Driver");
92 MODULE_LICENSE("GPL");
93 MODULE_VERSION(DRV_MODULE_VERSION
);
94 MODULE_FIRMWARE(FW_FILE_NAME_E1
);
95 MODULE_FIRMWARE(FW_FILE_NAME_E1H
);
96 MODULE_FIRMWARE(FW_FILE_NAME_E2
);
100 module_param(num_queues
, int, 0);
101 MODULE_PARM_DESC(num_queues
,
102 " Set number of queues (default is as a number of CPUs)");
104 static int disable_tpa
;
105 module_param(disable_tpa
, int, 0);
106 MODULE_PARM_DESC(disable_tpa
, " Disable the TPA (LRO) feature");
108 #define INT_MODE_INTx 1
109 #define INT_MODE_MSI 2
111 module_param(int_mode
, int, 0);
112 MODULE_PARM_DESC(int_mode
, " Force interrupt mode other than MSI-X "
115 static int dropless_fc
;
116 module_param(dropless_fc
, int, 0);
117 MODULE_PARM_DESC(dropless_fc
, " Pause on exhausted host ring");
119 static int mrrs
= -1;
120 module_param(mrrs
, int, 0);
121 MODULE_PARM_DESC(mrrs
, " Force Max Read Req Size (0..3) (for debug)");
124 module_param(debug
, int, 0);
125 MODULE_PARM_DESC(debug
, " Default debug msglevel");
129 struct workqueue_struct
*bnx2x_wq
;
131 struct bnx2x_mac_vals
{
142 enum bnx2x_board_type
{
166 /* indexed by board_type, above */
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" }
193 #ifndef PCI_DEVICE_ID_NX2_57710
194 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
196 #ifndef PCI_DEVICE_ID_NX2_57711
197 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
199 #ifndef PCI_DEVICE_ID_NX2_57711E
200 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
202 #ifndef PCI_DEVICE_ID_NX2_57712
203 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
205 #ifndef PCI_DEVICE_ID_NX2_57712_MF
206 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
208 #ifndef PCI_DEVICE_ID_NX2_57712_VF
209 #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
211 #ifndef PCI_DEVICE_ID_NX2_57800
212 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
214 #ifndef PCI_DEVICE_ID_NX2_57800_MF
215 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
217 #ifndef PCI_DEVICE_ID_NX2_57800_VF
218 #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
220 #ifndef PCI_DEVICE_ID_NX2_57810
221 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
223 #ifndef PCI_DEVICE_ID_NX2_57810_MF
224 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
226 #ifndef PCI_DEVICE_ID_NX2_57840_O
227 #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
229 #ifndef PCI_DEVICE_ID_NX2_57810_VF
230 #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
232 #ifndef PCI_DEVICE_ID_NX2_57840_4_10
233 #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
235 #ifndef PCI_DEVICE_ID_NX2_57840_2_20
236 #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
238 #ifndef PCI_DEVICE_ID_NX2_57840_MFO
239 #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
241 #ifndef PCI_DEVICE_ID_NX2_57840_MF
242 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
244 #ifndef PCI_DEVICE_ID_NX2_57840_VF
245 #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
247 #ifndef PCI_DEVICE_ID_NX2_57811
248 #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
250 #ifndef PCI_DEVICE_ID_NX2_57811_MF
251 #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
253 #ifndef PCI_DEVICE_ID_NX2_57811_VF
254 #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
257 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl
) = {
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
},
261 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57712
), BCM57712
},
262 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57712_MF
), BCM57712_MF
},
263 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57712_VF
), BCM57712_VF
},
264 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57800
), BCM57800
},
265 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57800_MF
), BCM57800_MF
},
266 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57800_VF
), BCM57800_VF
},
267 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57810
), BCM57810
},
268 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57810_MF
), BCM57810_MF
},
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
},
272 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57810_VF
), BCM57810_VF
},
273 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_MFO
), BCM57840_MFO
},
274 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_MF
), BCM57840_MF
},
275 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_VF
), BCM57840_VF
},
276 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57811
), BCM57811
},
277 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57811_MF
), BCM57811_MF
},
278 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57811_VF
), BCM57811_VF
},
282 MODULE_DEVICE_TABLE(pci
, bnx2x_pci_tbl
);
284 /* Global resources for unloading a previously loaded device */
285 #define BNX2X_PREV_WAIT_NEEDED 1
286 static DEFINE_SEMAPHORE(bnx2x_prev_sem
);
287 static LIST_HEAD(bnx2x_prev_list
);
288 /****************************************************************************
289 * General service functions
290 ****************************************************************************/
292 static void __storm_memset_dma_mapping(struct bnx2x
*bp
,
293 u32 addr
, dma_addr_t mapping
)
295 REG_WR(bp
, addr
, U64_LO(mapping
));
296 REG_WR(bp
, addr
+ 4, U64_HI(mapping
));
299 static void storm_memset_spq_addr(struct bnx2x
*bp
,
300 dma_addr_t mapping
, u16 abs_fid
)
302 u32 addr
= XSEM_REG_FAST_MEMORY
+
303 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid
);
305 __storm_memset_dma_mapping(bp
, addr
, mapping
);
308 static void storm_memset_vf_to_pf(struct bnx2x
*bp
, u16 abs_fid
,
311 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_VF_TO_PF_OFFSET(abs_fid
),
313 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_VF_TO_PF_OFFSET(abs_fid
),
315 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_VF_TO_PF_OFFSET(abs_fid
),
317 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_VF_TO_PF_OFFSET(abs_fid
),
321 static void storm_memset_func_en(struct bnx2x
*bp
, u16 abs_fid
,
324 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_FUNC_EN_OFFSET(abs_fid
),
326 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_FUNC_EN_OFFSET(abs_fid
),
328 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_FUNC_EN_OFFSET(abs_fid
),
330 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_FUNC_EN_OFFSET(abs_fid
),
334 static void storm_memset_eq_data(struct bnx2x
*bp
,
335 struct event_ring_data
*eq_data
,
338 size_t size
= sizeof(struct event_ring_data
);
340 u32 addr
= BAR_CSTRORM_INTMEM
+ CSTORM_EVENT_RING_DATA_OFFSET(pfid
);
342 __storm_memset_struct(bp
, addr
, size
, (u32
*)eq_data
);
345 static void storm_memset_eq_prod(struct bnx2x
*bp
, u16 eq_prod
,
348 u32 addr
= BAR_CSTRORM_INTMEM
+ CSTORM_EVENT_RING_PROD_OFFSET(pfid
);
349 REG_WR16(bp
, addr
, eq_prod
);
353 * locking is done by mcp
355 static void bnx2x_reg_wr_ind(struct bnx2x
*bp
, u32 addr
, u32 val
)
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
);
363 static u32
bnx2x_reg_rd_ind(struct bnx2x
*bp
, u32 addr
)
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
);
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]"
381 void bnx2x_dp_dmae(struct bnx2x
*bp
, struct dmae_command
*dmae
, int msglvl
)
383 u32 src_type
= dmae
->opcode
& DMAE_COMMAND_SRC
;
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
,
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
,
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
,
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
,
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
,
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
,
441 /* copy command into DMAE command memory and set DMAE command go */
442 void bnx2x_post_dmae(struct bnx2x
*bp
, struct dmae_command
*dmae
, int idx
)
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
));
451 REG_WR(bp
, dmae_reg_go_c
[idx
], 1);
454 u32
bnx2x_dmae_opcode_add_comp(u32 opcode
, u8 comp_type
)
456 return opcode
| ((comp_type
<< DMAE_COMMAND_C_DST_SHIFT
) |
460 u32
bnx2x_dmae_opcode_clr_src_reset(u32 opcode
)
462 return opcode
& ~DMAE_CMD_SRC_RESET
;
465 u32
bnx2x_dmae_opcode(struct bnx2x
*bp
, u8 src_type
, u8 dst_type
,
466 bool with_comp
, u8 comp_type
)
470 opcode
|= ((src_type
<< DMAE_COMMAND_SRC_SHIFT
) |
471 (dst_type
<< DMAE_COMMAND_DST_SHIFT
));
473 opcode
|= (DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
);
475 opcode
|= (BP_PORT(bp
) ? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
);
476 opcode
|= ((BP_VN(bp
) << DMAE_CMD_E1HVN_SHIFT
) |
477 (BP_VN(bp
) << DMAE_COMMAND_DST_VN_SHIFT
));
478 opcode
|= (DMAE_COM_SET_ERR
<< DMAE_COMMAND_ERR_POLICY_SHIFT
);
481 opcode
|= DMAE_CMD_ENDIANITY_B_DW_SWAP
;
483 opcode
|= DMAE_CMD_ENDIANITY_DW_SWAP
;
486 opcode
= bnx2x_dmae_opcode_add_comp(opcode
, comp_type
);
490 void bnx2x_prep_dmae_with_comp(struct bnx2x
*bp
,
491 struct dmae_command
*dmae
,
492 u8 src_type
, u8 dst_type
)
494 memset(dmae
, 0, sizeof(struct dmae_command
));
497 dmae
->opcode
= bnx2x_dmae_opcode(bp
, src_type
, dst_type
,
498 true, DMAE_COMP_PCI
);
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
;
506 /* issue a dmae command over the init-channel and wait for completion */
507 int bnx2x_issue_dmae_with_comp(struct bnx2x
*bp
, struct dmae_command
*dmae
)
509 u32
*wb_comp
= bnx2x_sp(bp
, wb_comp
);
510 int cnt
= CHIP_REV_IS_SLOW(bp
) ? (400000) : 4000;
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.
518 spin_lock_bh(&bp
->dmae_lock
);
520 /* reset completion */
523 /* post the command on the channel used for initializations */
524 bnx2x_post_dmae(bp
, dmae
, INIT_DMAE_C(bp
));
526 /* wait for completion */
528 while ((*wb_comp
& ~DMAE_PCI_ERR_FLAG
) != DMAE_COMP_VAL
) {
531 (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
&&
532 bp
->recovery_state
!= BNX2X_RECOVERY_NIC_LOADING
)) {
533 BNX2X_ERR("DMAE timeout!\n");
540 if (*wb_comp
& DMAE_PCI_ERR_FLAG
) {
541 BNX2X_ERR("DMAE PCI error!\n");
546 spin_unlock_bh(&bp
->dmae_lock
);
550 void bnx2x_write_dmae(struct bnx2x
*bp
, dma_addr_t dma_addr
, u32 dst_addr
,
553 struct dmae_command dmae
;
555 if (!bp
->dmae_ready
) {
556 u32
*data
= bnx2x_sp(bp
, wb_data
[0]);
559 bnx2x_init_ind_wr(bp
, dst_addr
, data
, len32
);
561 bnx2x_init_str_wr(bp
, dst_addr
, data
, len32
);
565 /* set opcode and fixed command fields */
566 bnx2x_prep_dmae_with_comp(bp
, &dmae
, DMAE_SRC_PCI
, DMAE_DST_GRC
);
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;
575 /* issue the command and wait for completion */
576 bnx2x_issue_dmae_with_comp(bp
, &dmae
);
579 void bnx2x_read_dmae(struct bnx2x
*bp
, u32 src_addr
, u32 len32
)
581 struct dmae_command dmae
;
583 if (!bp
->dmae_ready
) {
584 u32
*data
= bnx2x_sp(bp
, wb_data
[0]);
588 for (i
= 0; i
< len32
; i
++)
589 data
[i
] = bnx2x_reg_rd_ind(bp
, src_addr
+ i
*4);
591 for (i
= 0; i
< len32
; i
++)
592 data
[i
] = REG_RD(bp
, src_addr
+ i
*4);
597 /* set opcode and fixed command fields */
598 bnx2x_prep_dmae_with_comp(bp
, &dmae
, DMAE_SRC_GRC
, DMAE_DST_PCI
);
600 /* fill in addresses and len */
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
));
607 /* issue the command and wait for completion */
608 bnx2x_issue_dmae_with_comp(bp
, &dmae
);
611 static void bnx2x_write_dmae_phys_len(struct bnx2x
*bp
, dma_addr_t phys_addr
,
614 int dmae_wr_max
= DMAE_LEN32_WR_MAX(bp
);
617 while (len
> dmae_wr_max
) {
618 bnx2x_write_dmae(bp
, phys_addr
+ offset
,
619 addr
+ offset
, dmae_wr_max
);
620 offset
+= dmae_wr_max
* 4;
624 bnx2x_write_dmae(bp
, phys_addr
+ offset
, addr
+ offset
, len
);
627 static int bnx2x_mc_assert(struct bnx2x
*bp
)
631 u32 row0
, row1
, row2
, row3
;
634 last_idx
= REG_RD8(bp
, BAR_XSTRORM_INTMEM
+
635 XSTORM_ASSERT_LIST_INDEX_OFFSET
);
637 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
639 /* print the asserts */
640 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
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);
651 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
652 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
653 i
, row3
, row2
, row1
, row0
);
661 last_idx
= REG_RD8(bp
, BAR_TSTRORM_INTMEM
+
662 TSTORM_ASSERT_LIST_INDEX_OFFSET
);
664 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
666 /* print the asserts */
667 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
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);
678 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
679 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
680 i
, row3
, row2
, row1
, row0
);
688 last_idx
= REG_RD8(bp
, BAR_CSTRORM_INTMEM
+
689 CSTORM_ASSERT_LIST_INDEX_OFFSET
);
691 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
693 /* print the asserts */
694 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
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);
705 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
706 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
707 i
, row3
, row2
, row1
, row0
);
715 last_idx
= REG_RD8(bp
, BAR_USTRORM_INTMEM
+
716 USTORM_ASSERT_LIST_INDEX_OFFSET
);
718 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
720 /* print the asserts */
721 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
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);
732 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
733 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
734 i
, row3
, row2
, row1
, row0
);
744 void bnx2x_fw_dump_lvl(struct bnx2x
*bp
, const char *lvl
)
750 u32 trace_shmem_base
;
752 BNX2X_ERR("NO MCP - can not dump\n");
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));
760 val
= REG_RD(bp
, MCP_REG_MCPR_CPU_PROGRAM_COUNTER
);
761 if (val
== REG_RD(bp
, MCP_REG_MCPR_CPU_PROGRAM_COUNTER
))
762 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl
, val
);
764 if (BP_PATH(bp
) == 0)
765 trace_shmem_base
= bp
->common
.shmem_base
;
767 trace_shmem_base
= SHMEM2_RD(bp
, other_shmem_base_addr
);
768 addr
= trace_shmem_base
- 0x800;
770 /* validate TRCB signature */
771 mark
= REG_RD(bp
, addr
);
772 if (mark
!= MFW_TRACE_SIGNATURE
) {
773 BNX2X_ERR("Trace buffer signature is missing.");
777 /* read cyclic buffer pointer */
779 mark
= REG_RD(bp
, addr
);
780 mark
= (CHIP_IS_E1x(bp
) ? MCP_REG_MCPR_SCRATCH
: MCP_A_REG_MCPR_SCRATCH
)
781 + ((mark
+ 0x3) & ~0x3) - 0x08000000;
782 printk("%s" "begin fw dump (mark 0x%x)\n", lvl
, mark
);
786 /* dump buffer after the mark */
787 for (offset
= mark
; offset
<= trace_shmem_base
; offset
+= 0x8*4) {
788 for (word
= 0; word
< 8; word
++)
789 data
[word
] = htonl(REG_RD(bp
, offset
+ 4*word
));
791 pr_cont("%s", (char *)data
);
794 /* dump buffer before the mark */
795 for (offset
= addr
+ 4; offset
<= mark
; offset
+= 0x8*4) {
796 for (word
= 0; word
< 8; word
++)
797 data
[word
] = htonl(REG_RD(bp
, offset
+ 4*word
));
799 pr_cont("%s", (char *)data
);
801 printk("%s" "end of fw dump\n", lvl
);
804 static void bnx2x_fw_dump(struct bnx2x
*bp
)
806 bnx2x_fw_dump_lvl(bp
, KERN_ERR
);
809 static void bnx2x_hc_int_disable(struct bnx2x
*bp
)
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
);
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
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
824 REG_WR(bp
, HC_REG_INT_MASK
+ port
*4, 0);
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
);
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
);
836 "write %x to HC %d (addr 0x%x)\n",
839 /* flush all outstanding writes */
842 REG_WR(bp
, addr
, val
);
843 if (REG_RD(bp
, addr
) != val
)
844 BNX2X_ERR("BUG! proper val not read from IGU!\n");
847 static void bnx2x_igu_int_disable(struct bnx2x
*bp
)
849 u32 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
851 val
&= ~(IGU_PF_CONF_MSI_MSIX_EN
|
852 IGU_PF_CONF_INT_LINE_EN
|
853 IGU_PF_CONF_ATTN_BIT_EN
);
855 DP(NETIF_MSG_IFDOWN
, "write %x to IGU\n", val
);
857 /* flush all outstanding writes */
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");
865 static void bnx2x_int_disable(struct bnx2x
*bp
)
867 if (bp
->common
.int_block
== INT_BLOCK_HC
)
868 bnx2x_hc_int_disable(bp
);
870 bnx2x_igu_int_disable(bp
);
873 void bnx2x_panic_dump(struct bnx2x
*bp
, bool disable_int
)
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;
884 bnx2x_int_disable(bp
);
886 bp
->stats_state
= STATS_STATE_DISABLED
;
887 bp
->eth_stats
.unrecoverable_error
++;
888 DP(BNX2X_MSG_STATS
, "stats_state - DISABLED\n");
890 BNX2X_ERR("begin crash dump -----------------\n");
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",
895 bp
->def_idx
, bp
->def_att_idx
, bp
->attn_state
,
896 bp
->spq_prod_idx
, bp
->stats_counter
);
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
);
903 for (i
= 0; i
< HC_SP_SB_MAX_INDICES
; i
++)
905 bp
->def_status_blk
->sp_sb
.index_values
[i
],
906 (i
== HC_SP_SB_MAX_INDICES
- 1) ? ") " : " ");
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
) +
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",
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
,
919 sp_sb_data
.p_func
.vf_valid
,
923 for_each_eth_queue(bp
, i
) {
924 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
926 struct hc_status_block_data_e2 sb_data_e2
;
927 struct hc_status_block_data_e1x sb_data_e1x
;
928 struct hc_status_block_sm
*hc_sm_p
=
930 sb_data_e1x
.common
.state_machine
:
931 sb_data_e2
.common
.state_machine
;
932 struct hc_index_data
*hc_index_p
=
934 sb_data_e1x
.index_data
:
935 sb_data_e2
.index_data
;
938 struct bnx2x_fp_txdata txdata
;
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",
942 i
, fp
->rx_bd_prod
, fp
->rx_bd_cons
,
944 fp
->rx_comp_cons
, le16_to_cpu(*fp
->rx_cons_sb
));
945 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
946 fp
->rx_sge_prod
, fp
->last_max_sge
,
947 le16_to_cpu(fp
->fp_hc_idx
));
950 for_each_cos_in_tx_queue(fp
, cos
)
952 txdata
= *fp
->txdata_ptr
[cos
];
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",
954 i
, txdata
.tx_pkt_prod
,
955 txdata
.tx_pkt_cons
, txdata
.tx_bd_prod
,
957 le16_to_cpu(*txdata
.tx_cons_sb
));
960 loop
= CHIP_IS_E1x(bp
) ?
961 HC_SB_MAX_INDICES_E1X
: HC_SB_MAX_INDICES_E2
;
968 BNX2X_ERR(" run indexes (");
969 for (j
= 0; j
< HC_SB_MAX_SM
; j
++)
971 fp
->sb_running_index
[j
],
972 (j
== HC_SB_MAX_SM
- 1) ? ")" : " ");
974 BNX2X_ERR(" indexes (");
975 for (j
= 0; j
< loop
; j
++)
977 fp
->sb_index_values
[j
],
978 (j
== loop
- 1) ? ")" : " ");
980 data_size
= CHIP_IS_E1x(bp
) ?
981 sizeof(struct hc_status_block_data_e1x
) :
982 sizeof(struct hc_status_block_data_e2
);
983 data_size
/= sizeof(u32
);
984 sb_data_p
= CHIP_IS_E1x(bp
) ?
985 (u32
*)&sb_data_e1x
:
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
) +
993 if (!CHIP_IS_E1x(bp
)) {
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",
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
,
999 sb_data_e2
.common
.same_igu_sb_1b
,
1000 sb_data_e2
.common
.state
);
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",
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
,
1007 sb_data_e1x
.common
.same_igu_sb_1b
,
1008 sb_data_e1x
.common
.state
);
1012 for (j
= 0; j
< HC_SB_MAX_SM
; j
++) {
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
);
1022 for (j
= 0; j
< loop
; j
++) {
1023 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j
,
1024 hc_index_p
[j
].flags
,
1025 hc_index_p
[j
].timeout
);
1029 #ifdef BNX2X_STOP_ON_ERROR
1032 for (i
= 0; i
< NUM_EQ_DESC
; i
++) {
1033 u32
*data
= (u32
*)&bp
->eq_ring
[i
].message
.data
;
1035 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1036 i
, bp
->eq_ring
[i
].message
.opcode
,
1037 bp
->eq_ring
[i
].message
.error
);
1038 BNX2X_ERR("data: %x %x %x\n", data
[0], data
[1], data
[2]);
1043 for_each_valid_rx_queue(bp
, i
) {
1044 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1046 start
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) - 10);
1047 end
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) + 503);
1048 for (j
= start
; j
!= end
; j
= RX_BD(j
+ 1)) {
1049 u32
*rx_bd
= (u32
*)&fp
->rx_desc_ring
[j
];
1050 struct sw_rx_bd
*sw_bd
= &fp
->rx_buf_ring
[j
];
1052 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
1053 i
, j
, rx_bd
[1], rx_bd
[0], sw_bd
->data
);
1056 start
= RX_SGE(fp
->rx_sge_prod
);
1057 end
= RX_SGE(fp
->last_max_sge
);
1058 for (j
= start
; j
!= end
; j
= RX_SGE(j
+ 1)) {
1059 u32
*rx_sge
= (u32
*)&fp
->rx_sge_ring
[j
];
1060 struct sw_rx_page
*sw_page
= &fp
->rx_page_ring
[j
];
1062 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1063 i
, j
, rx_sge
[1], rx_sge
[0], sw_page
->page
);
1066 start
= RCQ_BD(fp
->rx_comp_cons
- 10);
1067 end
= RCQ_BD(fp
->rx_comp_cons
+ 503);
1068 for (j
= start
; j
!= end
; j
= RCQ_BD(j
+ 1)) {
1069 u32
*cqe
= (u32
*)&fp
->rx_comp_ring
[j
];
1071 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1072 i
, j
, cqe
[0], cqe
[1], cqe
[2], cqe
[3]);
1077 for_each_valid_tx_queue(bp
, i
) {
1078 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1079 for_each_cos_in_tx_queue(fp
, cos
) {
1080 struct bnx2x_fp_txdata
*txdata
= fp
->txdata_ptr
[cos
];
1082 start
= TX_BD(le16_to_cpu(*txdata
->tx_cons_sb
) - 10);
1083 end
= TX_BD(le16_to_cpu(*txdata
->tx_cons_sb
) + 245);
1084 for (j
= start
; j
!= end
; j
= TX_BD(j
+ 1)) {
1085 struct sw_tx_bd
*sw_bd
=
1086 &txdata
->tx_buf_ring
[j
];
1088 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
1089 i
, cos
, j
, sw_bd
->skb
,
1093 start
= TX_BD(txdata
->tx_bd_cons
- 10);
1094 end
= TX_BD(txdata
->tx_bd_cons
+ 254);
1095 for (j
= start
; j
!= end
; j
= TX_BD(j
+ 1)) {
1096 u32
*tx_bd
= (u32
*)&txdata
->tx_desc_ring
[j
];
1098 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
1099 i
, cos
, j
, tx_bd
[0], tx_bd
[1],
1100 tx_bd
[2], tx_bd
[3]);
1106 bnx2x_mc_assert(bp
);
1107 BNX2X_ERR("end crash dump -----------------\n");
1111 * FLR Support for E2
1113 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1116 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
1117 #define FLR_WAIT_INTERVAL 50 /* usec */
1118 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
1120 struct pbf_pN_buf_regs
{
1127 struct pbf_pN_cmd_regs
{
1133 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x
*bp
,
1134 struct pbf_pN_buf_regs
*regs
,
1137 u32 init_crd
, crd
, crd_start
, crd_freed
, crd_freed_start
;
1138 u32 cur_cnt
= poll_count
;
1140 crd_freed
= crd_freed_start
= REG_RD(bp
, regs
->crd_freed
);
1141 crd
= crd_start
= REG_RD(bp
, regs
->crd
);
1142 init_crd
= REG_RD(bp
, regs
->init_crd
);
1144 DP(BNX2X_MSG_SP
, "INIT CREDIT[%d] : %x\n", regs
->pN
, init_crd
);
1145 DP(BNX2X_MSG_SP
, "CREDIT[%d] : s:%x\n", regs
->pN
, crd
);
1146 DP(BNX2X_MSG_SP
, "CREDIT_FREED[%d]: s:%x\n", regs
->pN
, crd_freed
);
1148 while ((crd
!= init_crd
) && ((u32
)SUB_S32(crd_freed
, crd_freed_start
) <
1149 (init_crd
- crd_start
))) {
1151 udelay(FLR_WAIT_INTERVAL
);
1152 crd
= REG_RD(bp
, regs
->crd
);
1153 crd_freed
= REG_RD(bp
, regs
->crd_freed
);
1155 DP(BNX2X_MSG_SP
, "PBF tx buffer[%d] timed out\n",
1157 DP(BNX2X_MSG_SP
, "CREDIT[%d] : c:%x\n",
1159 DP(BNX2X_MSG_SP
, "CREDIT_FREED[%d]: c:%x\n",
1160 regs
->pN
, crd_freed
);
1164 DP(BNX2X_MSG_SP
, "Waited %d*%d usec for PBF tx buffer[%d]\n",
1165 poll_count
-cur_cnt
, FLR_WAIT_INTERVAL
, regs
->pN
);
1168 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x
*bp
,
1169 struct pbf_pN_cmd_regs
*regs
,
1172 u32 occup
, to_free
, freed
, freed_start
;
1173 u32 cur_cnt
= poll_count
;
1175 occup
= to_free
= REG_RD(bp
, regs
->lines_occup
);
1176 freed
= freed_start
= REG_RD(bp
, regs
->lines_freed
);
1178 DP(BNX2X_MSG_SP
, "OCCUPANCY[%d] : s:%x\n", regs
->pN
, occup
);
1179 DP(BNX2X_MSG_SP
, "LINES_FREED[%d] : s:%x\n", regs
->pN
, freed
);
1181 while (occup
&& ((u32
)SUB_S32(freed
, freed_start
) < to_free
)) {
1183 udelay(FLR_WAIT_INTERVAL
);
1184 occup
= REG_RD(bp
, regs
->lines_occup
);
1185 freed
= REG_RD(bp
, regs
->lines_freed
);
1187 DP(BNX2X_MSG_SP
, "PBF cmd queue[%d] timed out\n",
1189 DP(BNX2X_MSG_SP
, "OCCUPANCY[%d] : s:%x\n",
1191 DP(BNX2X_MSG_SP
, "LINES_FREED[%d] : s:%x\n",
1196 DP(BNX2X_MSG_SP
, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1197 poll_count
-cur_cnt
, FLR_WAIT_INTERVAL
, regs
->pN
);
1200 static u32
bnx2x_flr_clnup_reg_poll(struct bnx2x
*bp
, u32 reg
,
1201 u32 expected
, u32 poll_count
)
1203 u32 cur_cnt
= poll_count
;
1206 while ((val
= REG_RD(bp
, reg
)) != expected
&& cur_cnt
--)
1207 udelay(FLR_WAIT_INTERVAL
);
1212 int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x
*bp
, u32 reg
,
1213 char *msg
, u32 poll_cnt
)
1215 u32 val
= bnx2x_flr_clnup_reg_poll(bp
, reg
, 0, poll_cnt
);
1217 BNX2X_ERR("%s usage count=%d\n", msg
, val
);
1223 /* Common routines with VF FLR cleanup */
1224 u32
bnx2x_flr_clnup_poll_count(struct bnx2x
*bp
)
1226 /* adjust polling timeout */
1227 if (CHIP_REV_IS_EMUL(bp
))
1228 return FLR_POLL_CNT
* 2000;
1230 if (CHIP_REV_IS_FPGA(bp
))
1231 return FLR_POLL_CNT
* 120;
1233 return FLR_POLL_CNT
;
1236 void bnx2x_tx_hw_flushed(struct bnx2x
*bp
, u32 poll_count
)
1238 struct pbf_pN_cmd_regs cmd_regs
[] = {
1239 {0, (CHIP_IS_E3B0(bp
)) ?
1240 PBF_REG_TQ_OCCUPANCY_Q0
:
1241 PBF_REG_P0_TQ_OCCUPANCY
,
1242 (CHIP_IS_E3B0(bp
)) ?
1243 PBF_REG_TQ_LINES_FREED_CNT_Q0
:
1244 PBF_REG_P0_TQ_LINES_FREED_CNT
},
1245 {1, (CHIP_IS_E3B0(bp
)) ?
1246 PBF_REG_TQ_OCCUPANCY_Q1
:
1247 PBF_REG_P1_TQ_OCCUPANCY
,
1248 (CHIP_IS_E3B0(bp
)) ?
1249 PBF_REG_TQ_LINES_FREED_CNT_Q1
:
1250 PBF_REG_P1_TQ_LINES_FREED_CNT
},
1251 {4, (CHIP_IS_E3B0(bp
)) ?
1252 PBF_REG_TQ_OCCUPANCY_LB_Q
:
1253 PBF_REG_P4_TQ_OCCUPANCY
,
1254 (CHIP_IS_E3B0(bp
)) ?
1255 PBF_REG_TQ_LINES_FREED_CNT_LB_Q
:
1256 PBF_REG_P4_TQ_LINES_FREED_CNT
}
1259 struct pbf_pN_buf_regs buf_regs
[] = {
1260 {0, (CHIP_IS_E3B0(bp
)) ?
1261 PBF_REG_INIT_CRD_Q0
:
1262 PBF_REG_P0_INIT_CRD
,
1263 (CHIP_IS_E3B0(bp
)) ?
1266 (CHIP_IS_E3B0(bp
)) ?
1267 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0
:
1268 PBF_REG_P0_INTERNAL_CRD_FREED_CNT
},
1269 {1, (CHIP_IS_E3B0(bp
)) ?
1270 PBF_REG_INIT_CRD_Q1
:
1271 PBF_REG_P1_INIT_CRD
,
1272 (CHIP_IS_E3B0(bp
)) ?
1275 (CHIP_IS_E3B0(bp
)) ?
1276 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1
:
1277 PBF_REG_P1_INTERNAL_CRD_FREED_CNT
},
1278 {4, (CHIP_IS_E3B0(bp
)) ?
1279 PBF_REG_INIT_CRD_LB_Q
:
1280 PBF_REG_P4_INIT_CRD
,
1281 (CHIP_IS_E3B0(bp
)) ?
1282 PBF_REG_CREDIT_LB_Q
:
1284 (CHIP_IS_E3B0(bp
)) ?
1285 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q
:
1286 PBF_REG_P4_INTERNAL_CRD_FREED_CNT
},
1291 /* Verify the command queues are flushed P0, P1, P4 */
1292 for (i
= 0; i
< ARRAY_SIZE(cmd_regs
); i
++)
1293 bnx2x_pbf_pN_cmd_flushed(bp
, &cmd_regs
[i
], poll_count
);
1296 /* Verify the transmission buffers are flushed P0, P1, P4 */
1297 for (i
= 0; i
< ARRAY_SIZE(buf_regs
); i
++)
1298 bnx2x_pbf_pN_buf_flushed(bp
, &buf_regs
[i
], poll_count
);
1301 #define OP_GEN_PARAM(param) \
1302 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1304 #define OP_GEN_TYPE(type) \
1305 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1307 #define OP_GEN_AGG_VECT(index) \
1308 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1311 int bnx2x_send_final_clnup(struct bnx2x
*bp
, u8 clnup_func
, u32 poll_cnt
)
1313 u32 op_gen_command
= 0;
1315 u32 comp_addr
= BAR_CSTRORM_INTMEM
+
1316 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func
);
1319 if (REG_RD(bp
, comp_addr
)) {
1320 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1324 op_gen_command
|= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX
);
1325 op_gen_command
|= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE
);
1326 op_gen_command
|= OP_GEN_AGG_VECT(clnup_func
);
1327 op_gen_command
|= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT
;
1329 DP(BNX2X_MSG_SP
, "sending FW Final cleanup\n");
1330 REG_WR(bp
, XSDM_REG_OPERATION_GEN
, op_gen_command
);
1332 if (bnx2x_flr_clnup_reg_poll(bp
, comp_addr
, 1, poll_cnt
) != 1) {
1333 BNX2X_ERR("FW final cleanup did not succeed\n");
1334 DP(BNX2X_MSG_SP
, "At timeout completion address contained %x\n",
1335 (REG_RD(bp
, comp_addr
)));
1339 /* Zero completion for nxt FLR */
1340 REG_WR(bp
, comp_addr
, 0);
1345 u8
bnx2x_is_pcie_pending(struct pci_dev
*dev
)
1349 pcie_capability_read_word(dev
, PCI_EXP_DEVSTA
, &status
);
1350 return status
& PCI_EXP_DEVSTA_TRPND
;
1353 /* PF FLR specific routines
1355 static int bnx2x_poll_hw_usage_counters(struct bnx2x
*bp
, u32 poll_cnt
)
1358 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1359 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1360 CFC_REG_NUM_LCIDS_INSIDE_PF
,
1361 "CFC PF usage counter timed out",
1366 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1367 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1368 DORQ_REG_PF_USAGE_CNT
,
1369 "DQ PF usage counter timed out",
1373 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1374 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1375 QM_REG_PF_USG_CNT_0
+ 4*BP_FUNC(bp
),
1376 "QM PF usage counter timed out",
1380 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1381 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1382 TM_REG_LIN0_VNIC_UC
+ 4*BP_PORT(bp
),
1383 "Timers VNIC usage counter timed out",
1386 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1387 TM_REG_LIN0_NUM_SCANS
+ 4*BP_PORT(bp
),
1388 "Timers NUM_SCANS usage counter timed out",
1392 /* Wait DMAE PF usage counter to zero */
1393 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1394 dmae_reg_go_c
[INIT_DMAE_C(bp
)],
1395 "DMAE dommand register timed out",
1402 static void bnx2x_hw_enable_status(struct bnx2x
*bp
)
1406 val
= REG_RD(bp
, CFC_REG_WEAK_ENABLE_PF
);
1407 DP(BNX2X_MSG_SP
, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val
);
1409 val
= REG_RD(bp
, PBF_REG_DISABLE_PF
);
1410 DP(BNX2X_MSG_SP
, "PBF_REG_DISABLE_PF is 0x%x\n", val
);
1412 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSI_EN
);
1413 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val
);
1415 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSIX_EN
);
1416 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val
);
1418 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSIX_FUNC_MASK
);
1419 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val
);
1421 val
= REG_RD(bp
, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR
);
1422 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val
);
1424 val
= REG_RD(bp
, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR
);
1425 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val
);
1427 val
= REG_RD(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
);
1428 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1432 static int bnx2x_pf_flr_clnup(struct bnx2x
*bp
)
1434 u32 poll_cnt
= bnx2x_flr_clnup_poll_count(bp
);
1436 DP(BNX2X_MSG_SP
, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp
));
1438 /* Re-enable PF target read access */
1439 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ
, 1);
1441 /* Poll HW usage counters */
1442 DP(BNX2X_MSG_SP
, "Polling usage counters\n");
1443 if (bnx2x_poll_hw_usage_counters(bp
, poll_cnt
))
1446 /* Zero the igu 'trailing edge' and 'leading edge' */
1448 /* Send the FW cleanup command */
1449 if (bnx2x_send_final_clnup(bp
, (u8
)BP_FUNC(bp
), poll_cnt
))
1454 /* Verify TX hw is flushed */
1455 bnx2x_tx_hw_flushed(bp
, poll_cnt
);
1457 /* Wait 100ms (not adjusted according to platform) */
1460 /* Verify no pending pci transactions */
1461 if (bnx2x_is_pcie_pending(bp
->pdev
))
1462 BNX2X_ERR("PCIE Transactions still pending\n");
1465 bnx2x_hw_enable_status(bp
);
1468 * Master enable - Due to WB DMAE writes performed before this
1469 * register is re-initialized as part of the regular function init
1471 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
1476 static void bnx2x_hc_int_enable(struct bnx2x
*bp
)
1478 int port
= BP_PORT(bp
);
1479 u32 addr
= port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
;
1480 u32 val
= REG_RD(bp
, addr
);
1481 bool msix
= (bp
->flags
& USING_MSIX_FLAG
) ? true : false;
1482 bool single_msix
= (bp
->flags
& USING_SINGLE_MSIX_FLAG
) ? true : false;
1483 bool msi
= (bp
->flags
& USING_MSI_FLAG
) ? true : false;
1486 val
&= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1487 HC_CONFIG_0_REG_INT_LINE_EN_0
);
1488 val
|= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1489 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1491 val
|= HC_CONFIG_0_REG_SINGLE_ISR_EN_0
;
1493 val
&= ~HC_CONFIG_0_REG_INT_LINE_EN_0
;
1494 val
|= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1495 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1496 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1498 val
|= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1499 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1500 HC_CONFIG_0_REG_INT_LINE_EN_0
|
1501 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1503 if (!CHIP_IS_E1(bp
)) {
1505 "write %x to HC %d (addr 0x%x)\n", val
, port
, addr
);
1507 REG_WR(bp
, addr
, val
);
1509 val
&= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
;
1514 REG_WR(bp
, HC_REG_INT_MASK
+ port
*4, 0x1FFFF);
1517 "write %x to HC %d (addr 0x%x) mode %s\n", val
, port
, addr
,
1518 (msix
? "MSI-X" : (msi
? "MSI" : "INTx")));
1520 REG_WR(bp
, addr
, val
);
1522 * Ensure that HC_CONFIG is written before leading/trailing edge config
1527 if (!CHIP_IS_E1(bp
)) {
1528 /* init leading/trailing edge */
1530 val
= (0xee0f | (1 << (BP_VN(bp
) + 4)));
1532 /* enable nig and gpio3 attention */
1537 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, val
);
1538 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, val
);
1541 /* Make sure that interrupts are indeed enabled from here on */
1545 static void bnx2x_igu_int_enable(struct bnx2x
*bp
)
1548 bool msix
= (bp
->flags
& USING_MSIX_FLAG
) ? true : false;
1549 bool single_msix
= (bp
->flags
& USING_SINGLE_MSIX_FLAG
) ? true : false;
1550 bool msi
= (bp
->flags
& USING_MSI_FLAG
) ? true : false;
1552 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
1555 val
&= ~(IGU_PF_CONF_INT_LINE_EN
|
1556 IGU_PF_CONF_SINGLE_ISR_EN
);
1557 val
|= (IGU_PF_CONF_MSI_MSIX_EN
|
1558 IGU_PF_CONF_ATTN_BIT_EN
);
1561 val
|= IGU_PF_CONF_SINGLE_ISR_EN
;
1563 val
&= ~IGU_PF_CONF_INT_LINE_EN
;
1564 val
|= (IGU_PF_CONF_MSI_MSIX_EN
|
1565 IGU_PF_CONF_ATTN_BIT_EN
|
1566 IGU_PF_CONF_SINGLE_ISR_EN
);
1568 val
&= ~IGU_PF_CONF_MSI_MSIX_EN
;
1569 val
|= (IGU_PF_CONF_INT_LINE_EN
|
1570 IGU_PF_CONF_ATTN_BIT_EN
|
1571 IGU_PF_CONF_SINGLE_ISR_EN
);
1574 /* Clean previous status - need to configure igu prior to ack*/
1575 if ((!msix
) || single_msix
) {
1576 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
1580 val
|= IGU_PF_CONF_FUNC_EN
;
1582 DP(NETIF_MSG_IFUP
, "write 0x%x to IGU mode %s\n",
1583 val
, (msix
? "MSI-X" : (msi
? "MSI" : "INTx")));
1585 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
1587 if (val
& IGU_PF_CONF_INT_LINE_EN
)
1588 pci_intx(bp
->pdev
, true);
1592 /* init leading/trailing edge */
1594 val
= (0xee0f | (1 << (BP_VN(bp
) + 4)));
1596 /* enable nig and gpio3 attention */
1601 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, val
);
1602 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, val
);
1604 /* Make sure that interrupts are indeed enabled from here on */
1608 void bnx2x_int_enable(struct bnx2x
*bp
)
1610 if (bp
->common
.int_block
== INT_BLOCK_HC
)
1611 bnx2x_hc_int_enable(bp
);
1613 bnx2x_igu_int_enable(bp
);
1616 void bnx2x_int_disable_sync(struct bnx2x
*bp
, int disable_hw
)
1618 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
1622 /* prevent the HW from sending interrupts */
1623 bnx2x_int_disable(bp
);
1625 /* make sure all ISRs are done */
1627 synchronize_irq(bp
->msix_table
[0].vector
);
1629 if (CNIC_SUPPORT(bp
))
1631 for_each_eth_queue(bp
, i
)
1632 synchronize_irq(bp
->msix_table
[offset
++].vector
);
1634 synchronize_irq(bp
->pdev
->irq
);
1636 /* make sure sp_task is not running */
1637 cancel_delayed_work(&bp
->sp_task
);
1638 cancel_delayed_work(&bp
->period_task
);
1639 flush_workqueue(bnx2x_wq
);
1645 * General service functions
1648 /* Return true if succeeded to acquire the lock */
1649 static bool bnx2x_trylock_hw_lock(struct bnx2x
*bp
, u32 resource
)
1652 u32 resource_bit
= (1 << resource
);
1653 int func
= BP_FUNC(bp
);
1654 u32 hw_lock_control_reg
;
1656 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1657 "Trying to take a lock on resource %d\n", resource
);
1659 /* Validating that the resource is within range */
1660 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1661 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1662 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1663 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1668 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1670 hw_lock_control_reg
=
1671 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1673 /* Try to acquire the lock */
1674 REG_WR(bp
, hw_lock_control_reg
+ 4, resource_bit
);
1675 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1676 if (lock_status
& resource_bit
)
1679 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1680 "Failed to get a lock on resource %d\n", resource
);
1685 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1687 * @bp: driver handle
1689 * Returns the recovery leader resource id according to the engine this function
1690 * belongs to. Currently only only 2 engines is supported.
1692 static int bnx2x_get_leader_lock_resource(struct bnx2x
*bp
)
1695 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1
;
1697 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0
;
1701 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
1703 * @bp: driver handle
1705 * Tries to acquire a leader lock for current engine.
1707 static bool bnx2x_trylock_leader_lock(struct bnx2x
*bp
)
1709 return bnx2x_trylock_hw_lock(bp
, bnx2x_get_leader_lock_resource(bp
));
1712 static void bnx2x_cnic_cfc_comp(struct bnx2x
*bp
, int cid
, u8 err
);
1714 /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1715 static int bnx2x_schedule_sp_task(struct bnx2x
*bp
)
1717 /* Set the interrupt occurred bit for the sp-task to recognize it
1718 * must ack the interrupt and transition according to the IGU
1721 atomic_set(&bp
->interrupt_occurred
, 1);
1723 /* The sp_task must execute only after this bit
1724 * is set, otherwise we will get out of sync and miss all
1725 * further interrupts. Hence, the barrier.
1729 /* schedule sp_task to workqueue */
1730 return queue_delayed_work(bnx2x_wq
, &bp
->sp_task
, 0);
1733 void bnx2x_sp_event(struct bnx2x_fastpath
*fp
, union eth_rx_cqe
*rr_cqe
)
1735 struct bnx2x
*bp
= fp
->bp
;
1736 int cid
= SW_CID(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
1737 int command
= CQE_CMD(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
1738 enum bnx2x_queue_cmd drv_cmd
= BNX2X_Q_CMD_MAX
;
1739 struct bnx2x_queue_sp_obj
*q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
1742 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1743 fp
->index
, cid
, command
, bp
->state
,
1744 rr_cqe
->ramrod_cqe
.ramrod_type
);
1746 /* If cid is within VF range, replace the slowpath object with the
1747 * one corresponding to this VF
1749 if (cid
>= BNX2X_FIRST_VF_CID
&&
1750 cid
< BNX2X_FIRST_VF_CID
+ BNX2X_VF_CIDS
)
1751 bnx2x_iov_set_queue_sp_obj(bp
, cid
, &q_obj
);
1754 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE
):
1755 DP(BNX2X_MSG_SP
, "got UPDATE ramrod. CID %d\n", cid
);
1756 drv_cmd
= BNX2X_Q_CMD_UPDATE
;
1759 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP
):
1760 DP(BNX2X_MSG_SP
, "got MULTI[%d] setup ramrod\n", cid
);
1761 drv_cmd
= BNX2X_Q_CMD_SETUP
;
1764 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP
):
1765 DP(BNX2X_MSG_SP
, "got MULTI[%d] tx-only setup ramrod\n", cid
);
1766 drv_cmd
= BNX2X_Q_CMD_SETUP_TX_ONLY
;
1769 case (RAMROD_CMD_ID_ETH_HALT
):
1770 DP(BNX2X_MSG_SP
, "got MULTI[%d] halt ramrod\n", cid
);
1771 drv_cmd
= BNX2X_Q_CMD_HALT
;
1774 case (RAMROD_CMD_ID_ETH_TERMINATE
):
1775 DP(BNX2X_MSG_SP
, "got MULTI[%d] teminate ramrod\n", cid
);
1776 drv_cmd
= BNX2X_Q_CMD_TERMINATE
;
1779 case (RAMROD_CMD_ID_ETH_EMPTY
):
1780 DP(BNX2X_MSG_SP
, "got MULTI[%d] empty ramrod\n", cid
);
1781 drv_cmd
= BNX2X_Q_CMD_EMPTY
;
1785 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1786 command
, fp
->index
);
1790 if ((drv_cmd
!= BNX2X_Q_CMD_MAX
) &&
1791 q_obj
->complete_cmd(bp
, q_obj
, drv_cmd
))
1792 /* q_obj->complete_cmd() failure means that this was
1793 * an unexpected completion.
1795 * In this case we don't want to increase the bp->spq_left
1796 * because apparently we haven't sent this command the first
1799 #ifdef BNX2X_STOP_ON_ERROR
1804 /* SRIOV: reschedule any 'in_progress' operations */
1805 bnx2x_iov_sp_event(bp
, cid
, true);
1807 smp_mb__before_atomic_inc();
1808 atomic_inc(&bp
->cq_spq_left
);
1809 /* push the change in bp->spq_left and towards the memory */
1810 smp_mb__after_atomic_inc();
1812 DP(BNX2X_MSG_SP
, "bp->cq_spq_left %x\n", atomic_read(&bp
->cq_spq_left
));
1814 if ((drv_cmd
== BNX2X_Q_CMD_UPDATE
) && (IS_FCOE_FP(fp
)) &&
1815 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
))) {
1816 /* if Q update ramrod is completed for last Q in AFEX vif set
1817 * flow, then ACK MCP at the end
1819 * mark pending ACK to MCP bit.
1820 * prevent case that both bits are cleared.
1821 * At the end of load/unload driver checks that
1822 * sp_state is cleared, and this order prevents
1825 smp_mb__before_clear_bit();
1826 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK
, &bp
->sp_state
);
1828 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
);
1829 smp_mb__after_clear_bit();
1831 /* schedule the sp task as mcp ack is required */
1832 bnx2x_schedule_sp_task(bp
);
1838 irqreturn_t
bnx2x_interrupt(int irq
, void *dev_instance
)
1840 struct bnx2x
*bp
= netdev_priv(dev_instance
);
1841 u16 status
= bnx2x_ack_int(bp
);
1846 /* Return here if interrupt is shared and it's not for us */
1847 if (unlikely(status
== 0)) {
1848 DP(NETIF_MSG_INTR
, "not our interrupt!\n");
1851 DP(NETIF_MSG_INTR
, "got an interrupt status 0x%x\n", status
);
1853 #ifdef BNX2X_STOP_ON_ERROR
1854 if (unlikely(bp
->panic
))
1858 for_each_eth_queue(bp
, i
) {
1859 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1861 mask
= 0x2 << (fp
->index
+ CNIC_SUPPORT(bp
));
1862 if (status
& mask
) {
1863 /* Handle Rx or Tx according to SB id */
1864 prefetch(fp
->rx_cons_sb
);
1865 for_each_cos_in_tx_queue(fp
, cos
)
1866 prefetch(fp
->txdata_ptr
[cos
]->tx_cons_sb
);
1867 prefetch(&fp
->sb_running_index
[SM_RX_ID
]);
1868 napi_schedule(&bnx2x_fp(bp
, fp
->index
, napi
));
1873 if (CNIC_SUPPORT(bp
)) {
1875 if (status
& (mask
| 0x1)) {
1876 struct cnic_ops
*c_ops
= NULL
;
1879 c_ops
= rcu_dereference(bp
->cnic_ops
);
1880 if (c_ops
&& (bp
->cnic_eth_dev
.drv_state
&
1881 CNIC_DRV_STATE_HANDLES_IRQ
))
1882 c_ops
->cnic_handler(bp
->cnic_data
, NULL
);
1889 if (unlikely(status
& 0x1)) {
1891 /* schedule sp task to perform default status block work, ack
1892 * attentions and enable interrupts.
1894 bnx2x_schedule_sp_task(bp
);
1901 if (unlikely(status
))
1902 DP(NETIF_MSG_INTR
, "got an unknown interrupt! (status 0x%x)\n",
1911 * General service functions
1914 int bnx2x_acquire_hw_lock(struct bnx2x
*bp
, u32 resource
)
1917 u32 resource_bit
= (1 << resource
);
1918 int func
= BP_FUNC(bp
);
1919 u32 hw_lock_control_reg
;
1922 /* Validating that the resource is within range */
1923 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1924 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1925 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1930 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1932 hw_lock_control_reg
=
1933 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1936 /* Validating that the resource is not already taken */
1937 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1938 if (lock_status
& resource_bit
) {
1939 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
1940 lock_status
, resource_bit
);
1944 /* Try for 5 second every 5ms */
1945 for (cnt
= 0; cnt
< 1000; cnt
++) {
1946 /* Try to acquire the lock */
1947 REG_WR(bp
, hw_lock_control_reg
+ 4, resource_bit
);
1948 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1949 if (lock_status
& resource_bit
)
1954 BNX2X_ERR("Timeout\n");
1958 int bnx2x_release_leader_lock(struct bnx2x
*bp
)
1960 return bnx2x_release_hw_lock(bp
, bnx2x_get_leader_lock_resource(bp
));
1963 int bnx2x_release_hw_lock(struct bnx2x
*bp
, u32 resource
)
1966 u32 resource_bit
= (1 << resource
);
1967 int func
= BP_FUNC(bp
);
1968 u32 hw_lock_control_reg
;
1970 /* Validating that the resource is within range */
1971 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1972 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1973 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1978 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1980 hw_lock_control_reg
=
1981 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1984 /* Validating that the resource is currently taken */
1985 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1986 if (!(lock_status
& resource_bit
)) {
1987 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
1988 lock_status
, resource_bit
);
1992 REG_WR(bp
, hw_lock_control_reg
, resource_bit
);
1997 int bnx2x_get_gpio(struct bnx2x
*bp
, int gpio_num
, u8 port
)
1999 /* The GPIO should be swapped if swap register is set and active */
2000 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
2001 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
2002 int gpio_shift
= gpio_num
+
2003 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
2004 u32 gpio_mask
= (1 << gpio_shift
);
2008 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
2009 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
2013 /* read GPIO value */
2014 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO
);
2016 /* get the requested pin value */
2017 if ((gpio_reg
& gpio_mask
) == gpio_mask
)
2022 DP(NETIF_MSG_LINK
, "pin %d value 0x%x\n", gpio_num
, value
);
2027 int bnx2x_set_gpio(struct bnx2x
*bp
, int gpio_num
, u32 mode
, u8 port
)
2029 /* The GPIO should be swapped if swap register is set and active */
2030 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
2031 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
2032 int gpio_shift
= gpio_num
+
2033 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
2034 u32 gpio_mask
= (1 << gpio_shift
);
2037 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
2038 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
2042 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2043 /* read GPIO and mask except the float bits */
2044 gpio_reg
= (REG_RD(bp
, MISC_REG_GPIO
) & MISC_REGISTERS_GPIO_FLOAT
);
2047 case MISC_REGISTERS_GPIO_OUTPUT_LOW
:
2049 "Set GPIO %d (shift %d) -> output low\n",
2050 gpio_num
, gpio_shift
);
2051 /* clear FLOAT and set CLR */
2052 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
2053 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_CLR_POS
);
2056 case MISC_REGISTERS_GPIO_OUTPUT_HIGH
:
2058 "Set GPIO %d (shift %d) -> output high\n",
2059 gpio_num
, gpio_shift
);
2060 /* clear FLOAT and set SET */
2061 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
2062 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_SET_POS
);
2065 case MISC_REGISTERS_GPIO_INPUT_HI_Z
:
2067 "Set GPIO %d (shift %d) -> input\n",
2068 gpio_num
, gpio_shift
);
2070 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
2077 REG_WR(bp
, MISC_REG_GPIO
, gpio_reg
);
2078 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2083 int bnx2x_set_mult_gpio(struct bnx2x
*bp
, u8 pins
, u32 mode
)
2088 /* Any port swapping should be handled by caller. */
2090 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2091 /* read GPIO and mask except the float bits */
2092 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO
);
2093 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
2094 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_CLR_POS
);
2095 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_SET_POS
);
2098 case MISC_REGISTERS_GPIO_OUTPUT_LOW
:
2099 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> output low\n", pins
);
2101 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_CLR_POS
);
2104 case MISC_REGISTERS_GPIO_OUTPUT_HIGH
:
2105 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> output high\n", pins
);
2107 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_SET_POS
);
2110 case MISC_REGISTERS_GPIO_INPUT_HI_Z
:
2111 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> input\n", pins
);
2113 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
2117 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode
);
2123 REG_WR(bp
, MISC_REG_GPIO
, gpio_reg
);
2125 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2130 int bnx2x_set_gpio_int(struct bnx2x
*bp
, int gpio_num
, u32 mode
, u8 port
)
2132 /* The GPIO should be swapped if swap register is set and active */
2133 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
2134 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
2135 int gpio_shift
= gpio_num
+
2136 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
2137 u32 gpio_mask
= (1 << gpio_shift
);
2140 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
2141 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
2145 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2147 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO_INT
);
2150 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR
:
2152 "Clear GPIO INT %d (shift %d) -> output low\n",
2153 gpio_num
, gpio_shift
);
2154 /* clear SET and set CLR */
2155 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_INT_SET_POS
);
2156 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_INT_CLR_POS
);
2159 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET
:
2161 "Set GPIO INT %d (shift %d) -> output high\n",
2162 gpio_num
, gpio_shift
);
2163 /* clear CLR and set SET */
2164 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_INT_CLR_POS
);
2165 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_INT_SET_POS
);
2172 REG_WR(bp
, MISC_REG_GPIO_INT
, gpio_reg
);
2173 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2178 static int bnx2x_set_spio(struct bnx2x
*bp
, int spio
, u32 mode
)
2182 /* Only 2 SPIOs are configurable */
2183 if ((spio
!= MISC_SPIO_SPIO4
) && (spio
!= MISC_SPIO_SPIO5
)) {
2184 BNX2X_ERR("Invalid SPIO 0x%x\n", spio
);
2188 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_SPIO
);
2189 /* read SPIO and mask except the float bits */
2190 spio_reg
= (REG_RD(bp
, MISC_REG_SPIO
) & MISC_SPIO_FLOAT
);
2193 case MISC_SPIO_OUTPUT_LOW
:
2194 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> output low\n", spio
);
2195 /* clear FLOAT and set CLR */
2196 spio_reg
&= ~(spio
<< MISC_SPIO_FLOAT_POS
);
2197 spio_reg
|= (spio
<< MISC_SPIO_CLR_POS
);
2200 case MISC_SPIO_OUTPUT_HIGH
:
2201 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> output high\n", spio
);
2202 /* clear FLOAT and set SET */
2203 spio_reg
&= ~(spio
<< MISC_SPIO_FLOAT_POS
);
2204 spio_reg
|= (spio
<< MISC_SPIO_SET_POS
);
2207 case MISC_SPIO_INPUT_HI_Z
:
2208 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> input\n", spio
);
2210 spio_reg
|= (spio
<< MISC_SPIO_FLOAT_POS
);
2217 REG_WR(bp
, MISC_REG_SPIO
, spio_reg
);
2218 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_SPIO
);
2223 void bnx2x_calc_fc_adv(struct bnx2x
*bp
)
2225 u8 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
2226 switch (bp
->link_vars
.ieee_fc
&
2227 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK
) {
2228 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE
:
2229 bp
->port
.advertising
[cfg_idx
] &= ~(ADVERTISED_Asym_Pause
|
2233 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH
:
2234 bp
->port
.advertising
[cfg_idx
] |= (ADVERTISED_Asym_Pause
|
2238 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC
:
2239 bp
->port
.advertising
[cfg_idx
] |= ADVERTISED_Asym_Pause
;
2243 bp
->port
.advertising
[cfg_idx
] &= ~(ADVERTISED_Asym_Pause
|
2249 static void bnx2x_set_requested_fc(struct bnx2x
*bp
)
2251 /* Initialize link parameters structure variables
2252 * It is recommended to turn off RX FC for jumbo frames
2253 * for better performance
2255 if (CHIP_IS_E1x(bp
) && (bp
->dev
->mtu
> 5000))
2256 bp
->link_params
.req_fc_auto_adv
= BNX2X_FLOW_CTRL_TX
;
2258 bp
->link_params
.req_fc_auto_adv
= BNX2X_FLOW_CTRL_BOTH
;
2261 int bnx2x_initial_phy_init(struct bnx2x
*bp
, int load_mode
)
2263 int rc
, cfx_idx
= bnx2x_get_link_cfg_idx(bp
);
2264 u16 req_line_speed
= bp
->link_params
.req_line_speed
[cfx_idx
];
2266 if (!BP_NOMCP(bp
)) {
2267 bnx2x_set_requested_fc(bp
);
2268 bnx2x_acquire_phy_lock(bp
);
2270 if (load_mode
== LOAD_DIAG
) {
2271 struct link_params
*lp
= &bp
->link_params
;
2272 lp
->loopback_mode
= LOOPBACK_XGXS
;
2273 /* do PHY loopback at 10G speed, if possible */
2274 if (lp
->req_line_speed
[cfx_idx
] < SPEED_10000
) {
2275 if (lp
->speed_cap_mask
[cfx_idx
] &
2276 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
)
2277 lp
->req_line_speed
[cfx_idx
] =
2280 lp
->req_line_speed
[cfx_idx
] =
2285 if (load_mode
== LOAD_LOOPBACK_EXT
) {
2286 struct link_params
*lp
= &bp
->link_params
;
2287 lp
->loopback_mode
= LOOPBACK_EXT
;
2290 rc
= bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
2292 bnx2x_release_phy_lock(bp
);
2294 bnx2x_calc_fc_adv(bp
);
2296 if (bp
->link_vars
.link_up
) {
2297 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2298 bnx2x_link_report(bp
);
2300 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 0);
2301 bp
->link_params
.req_line_speed
[cfx_idx
] = req_line_speed
;
2304 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2308 void bnx2x_link_set(struct bnx2x
*bp
)
2310 if (!BP_NOMCP(bp
)) {
2311 bnx2x_acquire_phy_lock(bp
);
2312 bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
2313 bnx2x_release_phy_lock(bp
);
2315 bnx2x_calc_fc_adv(bp
);
2317 BNX2X_ERR("Bootcode is missing - can not set link\n");
2320 static void bnx2x__link_reset(struct bnx2x
*bp
)
2322 if (!BP_NOMCP(bp
)) {
2323 bnx2x_acquire_phy_lock(bp
);
2324 bnx2x_lfa_reset(&bp
->link_params
, &bp
->link_vars
);
2325 bnx2x_release_phy_lock(bp
);
2327 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2330 void bnx2x_force_link_reset(struct bnx2x
*bp
)
2332 bnx2x_acquire_phy_lock(bp
);
2333 bnx2x_link_reset(&bp
->link_params
, &bp
->link_vars
, 1);
2334 bnx2x_release_phy_lock(bp
);
2337 u8
bnx2x_link_test(struct bnx2x
*bp
, u8 is_serdes
)
2341 if (!BP_NOMCP(bp
)) {
2342 bnx2x_acquire_phy_lock(bp
);
2343 rc
= bnx2x_test_link(&bp
->link_params
, &bp
->link_vars
,
2345 bnx2x_release_phy_lock(bp
);
2347 BNX2X_ERR("Bootcode is missing - can not test link\n");
2353 /* Calculates the sum of vn_min_rates.
2354 It's needed for further normalizing of the min_rates.
2356 sum of vn_min_rates.
2358 0 - if all the min_rates are 0.
2359 In the later case fainess algorithm should be deactivated.
2360 If not all min_rates are zero then those that are zeroes will be set to 1.
2362 static void bnx2x_calc_vn_min(struct bnx2x
*bp
,
2363 struct cmng_init_input
*input
)
2368 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2369 u32 vn_cfg
= bp
->mf_config
[vn
];
2370 u32 vn_min_rate
= ((vn_cfg
& FUNC_MF_CFG_MIN_BW_MASK
) >>
2371 FUNC_MF_CFG_MIN_BW_SHIFT
) * 100;
2373 /* Skip hidden vns */
2374 if (vn_cfg
& FUNC_MF_CFG_FUNC_HIDE
)
2376 /* If min rate is zero - set it to 1 */
2377 else if (!vn_min_rate
)
2378 vn_min_rate
= DEF_MIN_RATE
;
2382 input
->vnic_min_rate
[vn
] = vn_min_rate
;
2385 /* if ETS or all min rates are zeros - disable fairness */
2386 if (BNX2X_IS_ETS_ENABLED(bp
)) {
2387 input
->flags
.cmng_enables
&=
2388 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2389 DP(NETIF_MSG_IFUP
, "Fairness will be disabled due to ETS\n");
2390 } else if (all_zero
) {
2391 input
->flags
.cmng_enables
&=
2392 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2394 "All MIN values are zeroes fairness will be disabled\n");
2396 input
->flags
.cmng_enables
|=
2397 CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2400 static void bnx2x_calc_vn_max(struct bnx2x
*bp
, int vn
,
2401 struct cmng_init_input
*input
)
2404 u32 vn_cfg
= bp
->mf_config
[vn
];
2406 if (vn_cfg
& FUNC_MF_CFG_FUNC_HIDE
)
2409 u32 maxCfg
= bnx2x_extract_max_cfg(bp
, vn_cfg
);
2412 /* maxCfg in percents of linkspeed */
2413 vn_max_rate
= (bp
->link_vars
.line_speed
* maxCfg
) / 100;
2414 } else /* SD modes */
2415 /* maxCfg is absolute in 100Mb units */
2416 vn_max_rate
= maxCfg
* 100;
2419 DP(NETIF_MSG_IFUP
, "vn %d: vn_max_rate %d\n", vn
, vn_max_rate
);
2421 input
->vnic_max_rate
[vn
] = vn_max_rate
;
2425 static int bnx2x_get_cmng_fns_mode(struct bnx2x
*bp
)
2427 if (CHIP_REV_IS_SLOW(bp
))
2428 return CMNG_FNS_NONE
;
2430 return CMNG_FNS_MINMAX
;
2432 return CMNG_FNS_NONE
;
2435 void bnx2x_read_mf_cfg(struct bnx2x
*bp
)
2437 int vn
, n
= (CHIP_MODE_IS_4_PORT(bp
) ? 2 : 1);
2440 return; /* what should be the default bvalue in this case */
2442 /* For 2 port configuration the absolute function number formula
2444 * abs_func = 2 * vn + BP_PORT + BP_PATH
2446 * and there are 4 functions per port
2448 * For 4 port configuration it is
2449 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2451 * and there are 2 functions per port
2453 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2454 int /*abs*/func
= n
* (2 * vn
+ BP_PORT(bp
)) + BP_PATH(bp
);
2456 if (func
>= E1H_FUNC_MAX
)
2460 MF_CFG_RD(bp
, func_mf_config
[func
].config
);
2462 if (bp
->mf_config
[BP_VN(bp
)] & FUNC_MF_CFG_FUNC_DISABLED
) {
2463 DP(NETIF_MSG_IFUP
, "mf_cfg function disabled\n");
2464 bp
->flags
|= MF_FUNC_DIS
;
2466 DP(NETIF_MSG_IFUP
, "mf_cfg function enabled\n");
2467 bp
->flags
&= ~MF_FUNC_DIS
;
2471 static void bnx2x_cmng_fns_init(struct bnx2x
*bp
, u8 read_cfg
, u8 cmng_type
)
2473 struct cmng_init_input input
;
2474 memset(&input
, 0, sizeof(struct cmng_init_input
));
2476 input
.port_rate
= bp
->link_vars
.line_speed
;
2478 if (cmng_type
== CMNG_FNS_MINMAX
) {
2481 /* read mf conf from shmem */
2483 bnx2x_read_mf_cfg(bp
);
2485 /* vn_weight_sum and enable fairness if not 0 */
2486 bnx2x_calc_vn_min(bp
, &input
);
2488 /* calculate and set min-max rate for each vn */
2490 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++)
2491 bnx2x_calc_vn_max(bp
, vn
, &input
);
2493 /* always enable rate shaping and fairness */
2494 input
.flags
.cmng_enables
|=
2495 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN
;
2497 bnx2x_init_cmng(&input
, &bp
->cmng
);
2501 /* rate shaping and fairness are disabled */
2503 "rate shaping and fairness are disabled\n");
2506 static void storm_memset_cmng(struct bnx2x
*bp
,
2507 struct cmng_init
*cmng
,
2511 size_t size
= sizeof(struct cmng_struct_per_port
);
2513 u32 addr
= BAR_XSTRORM_INTMEM
+
2514 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port
);
2516 __storm_memset_struct(bp
, addr
, size
, (u32
*)&cmng
->port
);
2518 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2519 int func
= func_by_vn(bp
, vn
);
2521 addr
= BAR_XSTRORM_INTMEM
+
2522 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func
);
2523 size
= sizeof(struct rate_shaping_vars_per_vn
);
2524 __storm_memset_struct(bp
, addr
, size
,
2525 (u32
*)&cmng
->vnic
.vnic_max_rate
[vn
]);
2527 addr
= BAR_XSTRORM_INTMEM
+
2528 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func
);
2529 size
= sizeof(struct fairness_vars_per_vn
);
2530 __storm_memset_struct(bp
, addr
, size
,
2531 (u32
*)&cmng
->vnic
.vnic_min_rate
[vn
]);
2535 /* This function is called upon link interrupt */
2536 static void bnx2x_link_attn(struct bnx2x
*bp
)
2538 /* Make sure that we are synced with the current statistics */
2539 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
2541 bnx2x_link_update(&bp
->link_params
, &bp
->link_vars
);
2543 if (bp
->link_vars
.link_up
) {
2545 /* dropless flow control */
2546 if (!CHIP_IS_E1(bp
) && bp
->dropless_fc
) {
2547 int port
= BP_PORT(bp
);
2548 u32 pause_enabled
= 0;
2550 if (bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_TX
)
2553 REG_WR(bp
, BAR_USTRORM_INTMEM
+
2554 USTORM_ETH_PAUSE_ENABLED_OFFSET(port
),
2558 if (bp
->link_vars
.mac_type
!= MAC_TYPE_EMAC
) {
2559 struct host_port_stats
*pstats
;
2561 pstats
= bnx2x_sp(bp
, port_stats
);
2562 /* reset old mac stats */
2563 memset(&(pstats
->mac_stx
[0]), 0,
2564 sizeof(struct mac_stx
));
2566 if (bp
->state
== BNX2X_STATE_OPEN
)
2567 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2570 if (bp
->link_vars
.link_up
&& bp
->link_vars
.line_speed
) {
2571 int cmng_fns
= bnx2x_get_cmng_fns_mode(bp
);
2573 if (cmng_fns
!= CMNG_FNS_NONE
) {
2574 bnx2x_cmng_fns_init(bp
, false, cmng_fns
);
2575 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
2577 /* rate shaping and fairness are disabled */
2579 "single function mode without fairness\n");
2582 __bnx2x_link_report(bp
);
2585 bnx2x_link_sync_notify(bp
);
2588 void bnx2x__link_status_update(struct bnx2x
*bp
)
2590 if (bp
->state
!= BNX2X_STATE_OPEN
)
2593 /* read updated dcb configuration */
2595 bnx2x_dcbx_pmf_update(bp
);
2596 bnx2x_link_status_update(&bp
->link_params
, &bp
->link_vars
);
2597 if (bp
->link_vars
.link_up
)
2598 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2600 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
2601 /* indicate link status */
2602 bnx2x_link_report(bp
);
2605 bp
->port
.supported
[0] |= (SUPPORTED_10baseT_Half
|
2606 SUPPORTED_10baseT_Full
|
2607 SUPPORTED_100baseT_Half
|
2608 SUPPORTED_100baseT_Full
|
2609 SUPPORTED_1000baseT_Full
|
2610 SUPPORTED_2500baseX_Full
|
2611 SUPPORTED_10000baseT_Full
|
2616 SUPPORTED_Asym_Pause
);
2617 bp
->port
.advertising
[0] = bp
->port
.supported
[0];
2619 bp
->link_params
.bp
= bp
;
2620 bp
->link_params
.port
= BP_PORT(bp
);
2621 bp
->link_params
.req_duplex
[0] = DUPLEX_FULL
;
2622 bp
->link_params
.req_flow_ctrl
[0] = BNX2X_FLOW_CTRL_NONE
;
2623 bp
->link_params
.req_line_speed
[0] = SPEED_10000
;
2624 bp
->link_params
.speed_cap_mask
[0] = 0x7f0000;
2625 bp
->link_params
.switch_cfg
= SWITCH_CFG_10G
;
2626 bp
->link_vars
.mac_type
= MAC_TYPE_BMAC
;
2627 bp
->link_vars
.line_speed
= SPEED_10000
;
2628 bp
->link_vars
.link_status
=
2629 (LINK_STATUS_LINK_UP
|
2630 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
);
2631 bp
->link_vars
.link_up
= 1;
2632 bp
->link_vars
.duplex
= DUPLEX_FULL
;
2633 bp
->link_vars
.flow_ctrl
= BNX2X_FLOW_CTRL_NONE
;
2634 __bnx2x_link_report(bp
);
2635 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2639 static int bnx2x_afex_func_update(struct bnx2x
*bp
, u16 vifid
,
2640 u16 vlan_val
, u8 allowed_prio
)
2642 struct bnx2x_func_state_params func_params
= {NULL
};
2643 struct bnx2x_func_afex_update_params
*f_update_params
=
2644 &func_params
.params
.afex_update
;
2646 func_params
.f_obj
= &bp
->func_obj
;
2647 func_params
.cmd
= BNX2X_F_CMD_AFEX_UPDATE
;
2649 /* no need to wait for RAMROD completion, so don't
2650 * set RAMROD_COMP_WAIT flag
2653 f_update_params
->vif_id
= vifid
;
2654 f_update_params
->afex_default_vlan
= vlan_val
;
2655 f_update_params
->allowed_priorities
= allowed_prio
;
2657 /* if ramrod can not be sent, response to MCP immediately */
2658 if (bnx2x_func_state_change(bp
, &func_params
) < 0)
2659 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
2664 static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x
*bp
, u8 cmd_type
,
2665 u16 vif_index
, u8 func_bit_map
)
2667 struct bnx2x_func_state_params func_params
= {NULL
};
2668 struct bnx2x_func_afex_viflists_params
*update_params
=
2669 &func_params
.params
.afex_viflists
;
2673 /* validate only LIST_SET and LIST_GET are received from switch */
2674 if ((cmd_type
!= VIF_LIST_RULE_GET
) && (cmd_type
!= VIF_LIST_RULE_SET
))
2675 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2678 func_params
.f_obj
= &bp
->func_obj
;
2679 func_params
.cmd
= BNX2X_F_CMD_AFEX_VIFLISTS
;
2681 /* set parameters according to cmd_type */
2682 update_params
->afex_vif_list_command
= cmd_type
;
2683 update_params
->vif_list_index
= vif_index
;
2684 update_params
->func_bit_map
=
2685 (cmd_type
== VIF_LIST_RULE_GET
) ? 0 : func_bit_map
;
2686 update_params
->func_to_clear
= 0;
2688 (cmd_type
== VIF_LIST_RULE_GET
) ?
2689 DRV_MSG_CODE_AFEX_LISTGET_ACK
:
2690 DRV_MSG_CODE_AFEX_LISTSET_ACK
;
2692 /* if ramrod can not be sent, respond to MCP immediately for
2693 * SET and GET requests (other are not triggered from MCP)
2695 rc
= bnx2x_func_state_change(bp
, &func_params
);
2697 bnx2x_fw_command(bp
, drv_msg_code
, 0);
2702 static void bnx2x_handle_afex_cmd(struct bnx2x
*bp
, u32 cmd
)
2704 struct afex_stats afex_stats
;
2705 u32 func
= BP_ABS_FUNC(bp
);
2712 u32 addr_to_write
, vifid
, addrs
, stats_type
, i
;
2714 if (cmd
& DRV_STATUS_AFEX_LISTGET_REQ
) {
2715 vifid
= SHMEM2_RD(bp
, afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2717 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid
);
2718 bnx2x_afex_handle_vif_list_cmd(bp
, VIF_LIST_RULE_GET
, vifid
, 0);
2721 if (cmd
& DRV_STATUS_AFEX_LISTSET_REQ
) {
2722 vifid
= SHMEM2_RD(bp
, afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2723 addrs
= SHMEM2_RD(bp
, afex_param2_to_driver
[BP_FW_MB_IDX(bp
)]);
2725 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2727 bnx2x_afex_handle_vif_list_cmd(bp
, VIF_LIST_RULE_SET
, vifid
,
2731 if (cmd
& DRV_STATUS_AFEX_STATSGET_REQ
) {
2732 addr_to_write
= SHMEM2_RD(bp
,
2733 afex_scratchpad_addr_to_write
[BP_FW_MB_IDX(bp
)]);
2734 stats_type
= SHMEM2_RD(bp
,
2735 afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2738 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2741 bnx2x_afex_collect_stats(bp
, (void *)&afex_stats
, stats_type
);
2743 /* write response to scratchpad, for MCP */
2744 for (i
= 0; i
< (sizeof(struct afex_stats
)/sizeof(u32
)); i
++)
2745 REG_WR(bp
, addr_to_write
+ i
*sizeof(u32
),
2746 *(((u32
*)(&afex_stats
))+i
));
2748 /* send ack message to MCP */
2749 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_STATSGET_ACK
, 0);
2752 if (cmd
& DRV_STATUS_AFEX_VIFSET_REQ
) {
2753 mf_config
= MF_CFG_RD(bp
, func_mf_config
[func
].config
);
2754 bp
->mf_config
[BP_VN(bp
)] = mf_config
;
2756 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2759 /* if VIF_SET is "enabled" */
2760 if (!(mf_config
& FUNC_MF_CFG_FUNC_DISABLED
)) {
2761 /* set rate limit directly to internal RAM */
2762 struct cmng_init_input cmng_input
;
2763 struct rate_shaping_vars_per_vn m_rs_vn
;
2764 size_t size
= sizeof(struct rate_shaping_vars_per_vn
);
2765 u32 addr
= BAR_XSTRORM_INTMEM
+
2766 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp
));
2768 bp
->mf_config
[BP_VN(bp
)] = mf_config
;
2770 bnx2x_calc_vn_max(bp
, BP_VN(bp
), &cmng_input
);
2771 m_rs_vn
.vn_counter
.rate
=
2772 cmng_input
.vnic_max_rate
[BP_VN(bp
)];
2773 m_rs_vn
.vn_counter
.quota
=
2774 (m_rs_vn
.vn_counter
.rate
*
2775 RS_PERIODIC_TIMEOUT_USEC
) / 8;
2777 __storm_memset_struct(bp
, addr
, size
, (u32
*)&m_rs_vn
);
2779 /* read relevant values from mf_cfg struct in shmem */
2781 (MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
2782 FUNC_MF_CFG_E1HOV_TAG_MASK
) >>
2783 FUNC_MF_CFG_E1HOV_TAG_SHIFT
;
2785 (MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
2786 FUNC_MF_CFG_AFEX_VLAN_MASK
) >>
2787 FUNC_MF_CFG_AFEX_VLAN_SHIFT
;
2788 vlan_prio
= (mf_config
&
2789 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK
) >>
2790 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT
;
2791 vlan_val
|= (vlan_prio
<< VLAN_PRIO_SHIFT
);
2794 func_mf_config
[func
].afex_config
) &
2795 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK
) >>
2796 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT
;
2799 func_mf_config
[func
].afex_config
) &
2800 FUNC_MF_CFG_AFEX_COS_FILTER_MASK
) >>
2801 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT
;
2803 /* send ramrod to FW, return in case of failure */
2804 if (bnx2x_afex_func_update(bp
, vif_id
, vlan_val
,
2808 bp
->afex_def_vlan_tag
= vlan_val
;
2809 bp
->afex_vlan_mode
= vlan_mode
;
2811 /* notify link down because BP->flags is disabled */
2812 bnx2x_link_report(bp
);
2814 /* send INVALID VIF ramrod to FW */
2815 bnx2x_afex_func_update(bp
, 0xFFFF, 0, 0);
2817 /* Reset the default afex VLAN */
2818 bp
->afex_def_vlan_tag
= -1;
2823 static void bnx2x_pmf_update(struct bnx2x
*bp
)
2825 int port
= BP_PORT(bp
);
2829 DP(BNX2X_MSG_MCP
, "pmf %d\n", bp
->port
.pmf
);
2832 * We need the mb() to ensure the ordering between the writing to
2833 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2837 /* queue a periodic task */
2838 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 0);
2840 bnx2x_dcbx_pmf_update(bp
);
2842 /* enable nig attention */
2843 val
= (0xff0f | (1 << (BP_VN(bp
) + 4)));
2844 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
2845 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, val
);
2846 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, val
);
2847 } else if (!CHIP_IS_E1x(bp
)) {
2848 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, val
);
2849 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, val
);
2852 bnx2x_stats_handle(bp
, STATS_EVENT_PMF
);
2860 * General service functions
2863 /* send the MCP a request, block until there is a reply */
2864 u32
bnx2x_fw_command(struct bnx2x
*bp
, u32 command
, u32 param
)
2866 int mb_idx
= BP_FW_MB_IDX(bp
);
2870 u8 delay
= CHIP_REV_IS_SLOW(bp
) ? 100 : 10;
2872 mutex_lock(&bp
->fw_mb_mutex
);
2874 SHMEM_WR(bp
, func_mb
[mb_idx
].drv_mb_param
, param
);
2875 SHMEM_WR(bp
, func_mb
[mb_idx
].drv_mb_header
, (command
| seq
));
2877 DP(BNX2X_MSG_MCP
, "wrote command (%x) to FW MB param 0x%08x\n",
2878 (command
| seq
), param
);
2881 /* let the FW do it's magic ... */
2884 rc
= SHMEM_RD(bp
, func_mb
[mb_idx
].fw_mb_header
);
2886 /* Give the FW up to 5 second (500*10ms) */
2887 } while ((seq
!= (rc
& FW_MSG_SEQ_NUMBER_MASK
)) && (cnt
++ < 500));
2889 DP(BNX2X_MSG_MCP
, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2890 cnt
*delay
, rc
, seq
);
2892 /* is this a reply to our command? */
2893 if (seq
== (rc
& FW_MSG_SEQ_NUMBER_MASK
))
2894 rc
&= FW_MSG_CODE_MASK
;
2897 BNX2X_ERR("FW failed to respond!\n");
2901 mutex_unlock(&bp
->fw_mb_mutex
);
2907 static void storm_memset_func_cfg(struct bnx2x
*bp
,
2908 struct tstorm_eth_function_common_config
*tcfg
,
2911 size_t size
= sizeof(struct tstorm_eth_function_common_config
);
2913 u32 addr
= BAR_TSTRORM_INTMEM
+
2914 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid
);
2916 __storm_memset_struct(bp
, addr
, size
, (u32
*)tcfg
);
2919 void bnx2x_func_init(struct bnx2x
*bp
, struct bnx2x_func_init_params
*p
)
2921 if (CHIP_IS_E1x(bp
)) {
2922 struct tstorm_eth_function_common_config tcfg
= {0};
2924 storm_memset_func_cfg(bp
, &tcfg
, p
->func_id
);
2927 /* Enable the function in the FW */
2928 storm_memset_vf_to_pf(bp
, p
->func_id
, p
->pf_id
);
2929 storm_memset_func_en(bp
, p
->func_id
, 1);
2932 if (p
->func_flgs
& FUNC_FLG_SPQ
) {
2933 storm_memset_spq_addr(bp
, p
->spq_map
, p
->func_id
);
2934 REG_WR(bp
, XSEM_REG_FAST_MEMORY
+
2935 XSTORM_SPQ_PROD_OFFSET(p
->func_id
), p
->spq_prod
);
2940 * bnx2x_get_tx_only_flags - Return common flags
2944 * @zero_stats TRUE if statistics zeroing is needed
2946 * Return the flags that are common for the Tx-only and not normal connections.
2948 static unsigned long bnx2x_get_common_flags(struct bnx2x
*bp
,
2949 struct bnx2x_fastpath
*fp
,
2952 unsigned long flags
= 0;
2954 /* PF driver will always initialize the Queue to an ACTIVE state */
2955 __set_bit(BNX2X_Q_FLG_ACTIVE
, &flags
);
2957 /* tx only connections collect statistics (on the same index as the
2958 * parent connection). The statistics are zeroed when the parent
2959 * connection is initialized.
2962 __set_bit(BNX2X_Q_FLG_STATS
, &flags
);
2964 __set_bit(BNX2X_Q_FLG_ZERO_STATS
, &flags
);
2967 #ifdef BNX2X_STOP_ON_ERROR
2968 __set_bit(BNX2X_Q_FLG_TX_SEC
, &flags
);
2974 static unsigned long bnx2x_get_q_flags(struct bnx2x
*bp
,
2975 struct bnx2x_fastpath
*fp
,
2978 unsigned long flags
= 0;
2980 /* calculate other queue flags */
2982 __set_bit(BNX2X_Q_FLG_OV
, &flags
);
2984 if (IS_FCOE_FP(fp
)) {
2985 __set_bit(BNX2X_Q_FLG_FCOE
, &flags
);
2986 /* For FCoE - force usage of default priority (for afex) */
2987 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI
, &flags
);
2990 if (!fp
->disable_tpa
) {
2991 __set_bit(BNX2X_Q_FLG_TPA
, &flags
);
2992 __set_bit(BNX2X_Q_FLG_TPA_IPV6
, &flags
);
2993 if (fp
->mode
== TPA_MODE_GRO
)
2994 __set_bit(BNX2X_Q_FLG_TPA_GRO
, &flags
);
2998 __set_bit(BNX2X_Q_FLG_LEADING_RSS
, &flags
);
2999 __set_bit(BNX2X_Q_FLG_MCAST
, &flags
);
3002 /* Always set HW VLAN stripping */
3003 __set_bit(BNX2X_Q_FLG_VLAN
, &flags
);
3005 /* configure silent vlan removal */
3007 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM
, &flags
);
3010 return flags
| bnx2x_get_common_flags(bp
, fp
, true);
3013 static void bnx2x_pf_q_prep_general(struct bnx2x
*bp
,
3014 struct bnx2x_fastpath
*fp
, struct bnx2x_general_setup_params
*gen_init
,
3017 gen_init
->stat_id
= bnx2x_stats_id(fp
);
3018 gen_init
->spcl_id
= fp
->cl_id
;
3020 /* Always use mini-jumbo MTU for FCoE L2 ring */
3022 gen_init
->mtu
= BNX2X_FCOE_MINI_JUMBO_MTU
;
3024 gen_init
->mtu
= bp
->dev
->mtu
;
3026 gen_init
->cos
= cos
;
3029 static void bnx2x_pf_rx_q_prep(struct bnx2x
*bp
,
3030 struct bnx2x_fastpath
*fp
, struct rxq_pause_params
*pause
,
3031 struct bnx2x_rxq_setup_params
*rxq_init
)
3035 u16 tpa_agg_size
= 0;
3037 if (!fp
->disable_tpa
) {
3038 pause
->sge_th_lo
= SGE_TH_LO(bp
);
3039 pause
->sge_th_hi
= SGE_TH_HI(bp
);
3041 /* validate SGE ring has enough to cross high threshold */
3042 WARN_ON(bp
->dropless_fc
&&
3043 pause
->sge_th_hi
+ FW_PREFETCH_CNT
>
3044 MAX_RX_SGE_CNT
* NUM_RX_SGE_PAGES
);
3046 tpa_agg_size
= TPA_AGG_SIZE
;
3047 max_sge
= SGE_PAGE_ALIGN(bp
->dev
->mtu
) >>
3049 max_sge
= ((max_sge
+ PAGES_PER_SGE
- 1) &
3050 (~(PAGES_PER_SGE
-1))) >> PAGES_PER_SGE_SHIFT
;
3051 sge_sz
= (u16
)min_t(u32
, SGE_PAGES
, 0xffff);
3054 /* pause - not for e1 */
3055 if (!CHIP_IS_E1(bp
)) {
3056 pause
->bd_th_lo
= BD_TH_LO(bp
);
3057 pause
->bd_th_hi
= BD_TH_HI(bp
);
3059 pause
->rcq_th_lo
= RCQ_TH_LO(bp
);
3060 pause
->rcq_th_hi
= RCQ_TH_HI(bp
);
3062 * validate that rings have enough entries to cross
3065 WARN_ON(bp
->dropless_fc
&&
3066 pause
->bd_th_hi
+ FW_PREFETCH_CNT
>
3068 WARN_ON(bp
->dropless_fc
&&
3069 pause
->rcq_th_hi
+ FW_PREFETCH_CNT
>
3070 NUM_RCQ_RINGS
* MAX_RCQ_DESC_CNT
);
3076 rxq_init
->dscr_map
= fp
->rx_desc_mapping
;
3077 rxq_init
->sge_map
= fp
->rx_sge_mapping
;
3078 rxq_init
->rcq_map
= fp
->rx_comp_mapping
;
3079 rxq_init
->rcq_np_map
= fp
->rx_comp_mapping
+ BCM_PAGE_SIZE
;
3081 /* This should be a maximum number of data bytes that may be
3082 * placed on the BD (not including paddings).
3084 rxq_init
->buf_sz
= fp
->rx_buf_size
- BNX2X_FW_RX_ALIGN_START
-
3085 BNX2X_FW_RX_ALIGN_END
- IP_HEADER_ALIGNMENT_PADDING
;
3087 rxq_init
->cl_qzone_id
= fp
->cl_qzone_id
;
3088 rxq_init
->tpa_agg_sz
= tpa_agg_size
;
3089 rxq_init
->sge_buf_sz
= sge_sz
;
3090 rxq_init
->max_sges_pkt
= max_sge
;
3091 rxq_init
->rss_engine_id
= BP_FUNC(bp
);
3092 rxq_init
->mcast_engine_id
= BP_FUNC(bp
);
3094 /* Maximum number or simultaneous TPA aggregation for this Queue.
3096 * For PF Clients it should be the maximum available number.
3097 * VF driver(s) may want to define it to a smaller value.
3099 rxq_init
->max_tpa_queues
= MAX_AGG_QS(bp
);
3101 rxq_init
->cache_line_log
= BNX2X_RX_ALIGN_SHIFT
;
3102 rxq_init
->fw_sb_id
= fp
->fw_sb_id
;
3105 rxq_init
->sb_cq_index
= HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS
;
3107 rxq_init
->sb_cq_index
= HC_INDEX_ETH_RX_CQ_CONS
;
3108 /* configure silent vlan removal
3109 * if multi function mode is afex, then mask default vlan
3111 if (IS_MF_AFEX(bp
)) {
3112 rxq_init
->silent_removal_value
= bp
->afex_def_vlan_tag
;
3113 rxq_init
->silent_removal_mask
= VLAN_VID_MASK
;
3117 static void bnx2x_pf_tx_q_prep(struct bnx2x
*bp
,
3118 struct bnx2x_fastpath
*fp
, struct bnx2x_txq_setup_params
*txq_init
,
3121 txq_init
->dscr_map
= fp
->txdata_ptr
[cos
]->tx_desc_mapping
;
3122 txq_init
->sb_cq_index
= HC_INDEX_ETH_FIRST_TX_CQ_CONS
+ cos
;
3123 txq_init
->traffic_type
= LLFC_TRAFFIC_TYPE_NW
;
3124 txq_init
->fw_sb_id
= fp
->fw_sb_id
;
3127 * set the tss leading client id for TX classfication ==
3128 * leading RSS client id
3130 txq_init
->tss_leading_cl_id
= bnx2x_fp(bp
, 0, cl_id
);
3132 if (IS_FCOE_FP(fp
)) {
3133 txq_init
->sb_cq_index
= HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS
;
3134 txq_init
->traffic_type
= LLFC_TRAFFIC_TYPE_FCOE
;
3138 static void bnx2x_pf_init(struct bnx2x
*bp
)
3140 struct bnx2x_func_init_params func_init
= {0};
3141 struct event_ring_data eq_data
= { {0} };
3144 if (!CHIP_IS_E1x(bp
)) {
3145 /* reset IGU PF statistics: MSIX + ATTN */
3147 REG_WR(bp
, IGU_REG_STATISTIC_NUM_MESSAGE_SENT
+
3148 BNX2X_IGU_STAS_MSG_VF_CNT
*4 +
3149 (CHIP_MODE_IS_4_PORT(bp
) ?
3150 BP_FUNC(bp
) : BP_VN(bp
))*4, 0);
3152 REG_WR(bp
, IGU_REG_STATISTIC_NUM_MESSAGE_SENT
+
3153 BNX2X_IGU_STAS_MSG_VF_CNT
*4 +
3154 BNX2X_IGU_STAS_MSG_PF_CNT
*4 +
3155 (CHIP_MODE_IS_4_PORT(bp
) ?
3156 BP_FUNC(bp
) : BP_VN(bp
))*4, 0);
3159 /* function setup flags */
3160 flags
= (FUNC_FLG_STATS
| FUNC_FLG_LEADING
| FUNC_FLG_SPQ
);
3162 /* This flag is relevant for E1x only.
3163 * E2 doesn't have a TPA configuration in a function level.
3165 flags
|= (bp
->flags
& TPA_ENABLE_FLAG
) ? FUNC_FLG_TPA
: 0;
3167 func_init
.func_flgs
= flags
;
3168 func_init
.pf_id
= BP_FUNC(bp
);
3169 func_init
.func_id
= BP_FUNC(bp
);
3170 func_init
.spq_map
= bp
->spq_mapping
;
3171 func_init
.spq_prod
= bp
->spq_prod_idx
;
3173 bnx2x_func_init(bp
, &func_init
);
3175 memset(&(bp
->cmng
), 0, sizeof(struct cmng_struct_per_port
));
3178 * Congestion management values depend on the link rate
3179 * There is no active link so initial link rate is set to 10 Gbps.
3180 * When the link comes up The congestion management values are
3181 * re-calculated according to the actual link rate.
3183 bp
->link_vars
.line_speed
= SPEED_10000
;
3184 bnx2x_cmng_fns_init(bp
, true, bnx2x_get_cmng_fns_mode(bp
));
3186 /* Only the PMF sets the HW */
3188 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
3190 /* init Event Queue - PCI bus guarantees correct endianity*/
3191 eq_data
.base_addr
.hi
= U64_HI(bp
->eq_mapping
);
3192 eq_data
.base_addr
.lo
= U64_LO(bp
->eq_mapping
);
3193 eq_data
.producer
= bp
->eq_prod
;
3194 eq_data
.index_id
= HC_SP_INDEX_EQ_CONS
;
3195 eq_data
.sb_id
= DEF_SB_ID
;
3196 storm_memset_eq_data(bp
, &eq_data
, BP_FUNC(bp
));
3200 static void bnx2x_e1h_disable(struct bnx2x
*bp
)
3202 int port
= BP_PORT(bp
);
3204 bnx2x_tx_disable(bp
);
3206 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 0);
3209 static void bnx2x_e1h_enable(struct bnx2x
*bp
)
3211 int port
= BP_PORT(bp
);
3213 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 1);
3215 /* Tx queue should be only reenabled */
3216 netif_tx_wake_all_queues(bp
->dev
);
3219 * Should not call netif_carrier_on since it will be called if the link
3220 * is up when checking for link state
3224 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3226 static void bnx2x_drv_info_ether_stat(struct bnx2x
*bp
)
3228 struct eth_stats_info
*ether_stat
=
3229 &bp
->slowpath
->drv_info_to_mcp
.ether_stat
;
3231 strlcpy(ether_stat
->version
, DRV_MODULE_VERSION
,
3232 ETH_STAT_INFO_VERSION_LEN
);
3234 bp
->sp_objs
[0].mac_obj
.get_n_elements(bp
, &bp
->sp_objs
[0].mac_obj
,
3235 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED
,
3236 ether_stat
->mac_local
);
3238 ether_stat
->mtu_size
= bp
->dev
->mtu
;
3240 if (bp
->dev
->features
& NETIF_F_RXCSUM
)
3241 ether_stat
->feature_flags
|= FEATURE_ETH_CHKSUM_OFFLOAD_MASK
;
3242 if (bp
->dev
->features
& NETIF_F_TSO
)
3243 ether_stat
->feature_flags
|= FEATURE_ETH_LSO_MASK
;
3244 ether_stat
->feature_flags
|= bp
->common
.boot_mode
;
3246 ether_stat
->promiscuous_mode
= (bp
->dev
->flags
& IFF_PROMISC
) ? 1 : 0;
3248 ether_stat
->txq_size
= bp
->tx_ring_size
;
3249 ether_stat
->rxq_size
= bp
->rx_ring_size
;
3252 static void bnx2x_drv_info_fcoe_stat(struct bnx2x
*bp
)
3254 struct bnx2x_dcbx_app_params
*app
= &bp
->dcbx_port_params
.app
;
3255 struct fcoe_stats_info
*fcoe_stat
=
3256 &bp
->slowpath
->drv_info_to_mcp
.fcoe_stat
;
3258 if (!CNIC_LOADED(bp
))
3261 memcpy(fcoe_stat
->mac_local
+ MAC_LEADING_ZERO_CNT
,
3262 bp
->fip_mac
, ETH_ALEN
);
3264 fcoe_stat
->qos_priority
=
3265 app
->traffic_type_priority
[LLFC_TRAFFIC_TYPE_FCOE
];
3267 /* insert FCoE stats from ramrod response */
3269 struct tstorm_per_queue_stats
*fcoe_q_tstorm_stats
=
3270 &bp
->fw_stats_data
->queue_stats
[FCOE_IDX(bp
)].
3271 tstorm_queue_statistics
;
3273 struct xstorm_per_queue_stats
*fcoe_q_xstorm_stats
=
3274 &bp
->fw_stats_data
->queue_stats
[FCOE_IDX(bp
)].
3275 xstorm_queue_statistics
;
3277 struct fcoe_statistics_params
*fw_fcoe_stat
=
3278 &bp
->fw_stats_data
->fcoe
;
3280 ADD_64_LE(fcoe_stat
->rx_bytes_hi
, LE32_0
,
3281 fcoe_stat
->rx_bytes_lo
,
3282 fw_fcoe_stat
->rx_stat0
.fcoe_rx_byte_cnt
);
3284 ADD_64_LE(fcoe_stat
->rx_bytes_hi
,
3285 fcoe_q_tstorm_stats
->rcv_ucast_bytes
.hi
,
3286 fcoe_stat
->rx_bytes_lo
,
3287 fcoe_q_tstorm_stats
->rcv_ucast_bytes
.lo
);
3289 ADD_64_LE(fcoe_stat
->rx_bytes_hi
,
3290 fcoe_q_tstorm_stats
->rcv_bcast_bytes
.hi
,
3291 fcoe_stat
->rx_bytes_lo
,
3292 fcoe_q_tstorm_stats
->rcv_bcast_bytes
.lo
);
3294 ADD_64_LE(fcoe_stat
->rx_bytes_hi
,
3295 fcoe_q_tstorm_stats
->rcv_mcast_bytes
.hi
,
3296 fcoe_stat
->rx_bytes_lo
,
3297 fcoe_q_tstorm_stats
->rcv_mcast_bytes
.lo
);
3299 ADD_64_LE(fcoe_stat
->rx_frames_hi
, LE32_0
,
3300 fcoe_stat
->rx_frames_lo
,
3301 fw_fcoe_stat
->rx_stat0
.fcoe_rx_pkt_cnt
);
3303 ADD_64_LE(fcoe_stat
->rx_frames_hi
, LE32_0
,
3304 fcoe_stat
->rx_frames_lo
,
3305 fcoe_q_tstorm_stats
->rcv_ucast_pkts
);
3307 ADD_64_LE(fcoe_stat
->rx_frames_hi
, LE32_0
,
3308 fcoe_stat
->rx_frames_lo
,
3309 fcoe_q_tstorm_stats
->rcv_bcast_pkts
);
3311 ADD_64_LE(fcoe_stat
->rx_frames_hi
, LE32_0
,
3312 fcoe_stat
->rx_frames_lo
,
3313 fcoe_q_tstorm_stats
->rcv_mcast_pkts
);
3315 ADD_64_LE(fcoe_stat
->tx_bytes_hi
, LE32_0
,
3316 fcoe_stat
->tx_bytes_lo
,
3317 fw_fcoe_stat
->tx_stat
.fcoe_tx_byte_cnt
);
3319 ADD_64_LE(fcoe_stat
->tx_bytes_hi
,
3320 fcoe_q_xstorm_stats
->ucast_bytes_sent
.hi
,
3321 fcoe_stat
->tx_bytes_lo
,
3322 fcoe_q_xstorm_stats
->ucast_bytes_sent
.lo
);
3324 ADD_64_LE(fcoe_stat
->tx_bytes_hi
,
3325 fcoe_q_xstorm_stats
->bcast_bytes_sent
.hi
,
3326 fcoe_stat
->tx_bytes_lo
,
3327 fcoe_q_xstorm_stats
->bcast_bytes_sent
.lo
);
3329 ADD_64_LE(fcoe_stat
->tx_bytes_hi
,
3330 fcoe_q_xstorm_stats
->mcast_bytes_sent
.hi
,
3331 fcoe_stat
->tx_bytes_lo
,
3332 fcoe_q_xstorm_stats
->mcast_bytes_sent
.lo
);
3334 ADD_64_LE(fcoe_stat
->tx_frames_hi
, LE32_0
,
3335 fcoe_stat
->tx_frames_lo
,
3336 fw_fcoe_stat
->tx_stat
.fcoe_tx_pkt_cnt
);
3338 ADD_64_LE(fcoe_stat
->tx_frames_hi
, LE32_0
,
3339 fcoe_stat
->tx_frames_lo
,
3340 fcoe_q_xstorm_stats
->ucast_pkts_sent
);
3342 ADD_64_LE(fcoe_stat
->tx_frames_hi
, LE32_0
,
3343 fcoe_stat
->tx_frames_lo
,
3344 fcoe_q_xstorm_stats
->bcast_pkts_sent
);
3346 ADD_64_LE(fcoe_stat
->tx_frames_hi
, LE32_0
,
3347 fcoe_stat
->tx_frames_lo
,
3348 fcoe_q_xstorm_stats
->mcast_pkts_sent
);
3351 /* ask L5 driver to add data to the struct */
3352 bnx2x_cnic_notify(bp
, CNIC_CTL_FCOE_STATS_GET_CMD
);
3355 static void bnx2x_drv_info_iscsi_stat(struct bnx2x
*bp
)
3357 struct bnx2x_dcbx_app_params
*app
= &bp
->dcbx_port_params
.app
;
3358 struct iscsi_stats_info
*iscsi_stat
=
3359 &bp
->slowpath
->drv_info_to_mcp
.iscsi_stat
;
3361 if (!CNIC_LOADED(bp
))
3364 memcpy(iscsi_stat
->mac_local
+ MAC_LEADING_ZERO_CNT
,
3365 bp
->cnic_eth_dev
.iscsi_mac
, ETH_ALEN
);
3367 iscsi_stat
->qos_priority
=
3368 app
->traffic_type_priority
[LLFC_TRAFFIC_TYPE_ISCSI
];
3370 /* ask L5 driver to add data to the struct */
3371 bnx2x_cnic_notify(bp
, CNIC_CTL_ISCSI_STATS_GET_CMD
);
3374 /* called due to MCP event (on pmf):
3375 * reread new bandwidth configuration
3377 * notify others function about the change
3379 static void bnx2x_config_mf_bw(struct bnx2x
*bp
)
3381 if (bp
->link_vars
.link_up
) {
3382 bnx2x_cmng_fns_init(bp
, true, CMNG_FNS_MINMAX
);
3383 bnx2x_link_sync_notify(bp
);
3385 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
3388 static void bnx2x_set_mf_bw(struct bnx2x
*bp
)
3390 bnx2x_config_mf_bw(bp
);
3391 bnx2x_fw_command(bp
, DRV_MSG_CODE_SET_MF_BW_ACK
, 0);
3394 static void bnx2x_handle_eee_event(struct bnx2x
*bp
)
3396 DP(BNX2X_MSG_MCP
, "EEE - LLDP event\n");
3397 bnx2x_fw_command(bp
, DRV_MSG_CODE_EEE_RESULTS_ACK
, 0);
3400 static void bnx2x_handle_drv_info_req(struct bnx2x
*bp
)
3402 enum drv_info_opcode op_code
;
3403 u32 drv_info_ctl
= SHMEM2_RD(bp
, drv_info_control
);
3405 /* if drv_info version supported by MFW doesn't match - send NACK */
3406 if ((drv_info_ctl
& DRV_INFO_CONTROL_VER_MASK
) != DRV_INFO_CUR_VER
) {
3407 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_NACK
, 0);
3411 op_code
= (drv_info_ctl
& DRV_INFO_CONTROL_OP_CODE_MASK
) >>
3412 DRV_INFO_CONTROL_OP_CODE_SHIFT
;
3414 memset(&bp
->slowpath
->drv_info_to_mcp
, 0,
3415 sizeof(union drv_info_to_mcp
));
3418 case ETH_STATS_OPCODE
:
3419 bnx2x_drv_info_ether_stat(bp
);
3421 case FCOE_STATS_OPCODE
:
3422 bnx2x_drv_info_fcoe_stat(bp
);
3424 case ISCSI_STATS_OPCODE
:
3425 bnx2x_drv_info_iscsi_stat(bp
);
3428 /* if op code isn't supported - send NACK */
3429 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_NACK
, 0);
3433 /* if we got drv_info attn from MFW then these fields are defined in
3436 SHMEM2_WR(bp
, drv_info_host_addr_lo
,
3437 U64_LO(bnx2x_sp_mapping(bp
, drv_info_to_mcp
)));
3438 SHMEM2_WR(bp
, drv_info_host_addr_hi
,
3439 U64_HI(bnx2x_sp_mapping(bp
, drv_info_to_mcp
)));
3441 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_ACK
, 0);
3444 static void bnx2x_dcc_event(struct bnx2x
*bp
, u32 dcc_event
)
3446 DP(BNX2X_MSG_MCP
, "dcc_event 0x%x\n", dcc_event
);
3448 if (dcc_event
& DRV_STATUS_DCC_DISABLE_ENABLE_PF
) {
3451 * This is the only place besides the function initialization
3452 * where the bp->flags can change so it is done without any
3455 if (bp
->mf_config
[BP_VN(bp
)] & FUNC_MF_CFG_FUNC_DISABLED
) {
3456 DP(BNX2X_MSG_MCP
, "mf_cfg function disabled\n");
3457 bp
->flags
|= MF_FUNC_DIS
;
3459 bnx2x_e1h_disable(bp
);
3461 DP(BNX2X_MSG_MCP
, "mf_cfg function enabled\n");
3462 bp
->flags
&= ~MF_FUNC_DIS
;
3464 bnx2x_e1h_enable(bp
);
3466 dcc_event
&= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF
;
3468 if (dcc_event
& DRV_STATUS_DCC_BANDWIDTH_ALLOCATION
) {
3469 bnx2x_config_mf_bw(bp
);
3470 dcc_event
&= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION
;
3473 /* Report results to MCP */
3475 bnx2x_fw_command(bp
, DRV_MSG_CODE_DCC_FAILURE
, 0);
3477 bnx2x_fw_command(bp
, DRV_MSG_CODE_DCC_OK
, 0);
3480 /* must be called under the spq lock */
3481 static struct eth_spe
*bnx2x_sp_get_next(struct bnx2x
*bp
)
3483 struct eth_spe
*next_spe
= bp
->spq_prod_bd
;
3485 if (bp
->spq_prod_bd
== bp
->spq_last_bd
) {
3486 bp
->spq_prod_bd
= bp
->spq
;
3487 bp
->spq_prod_idx
= 0;
3488 DP(BNX2X_MSG_SP
, "end of spq\n");
3496 /* must be called under the spq lock */
3497 static void bnx2x_sp_prod_update(struct bnx2x
*bp
)
3499 int func
= BP_FUNC(bp
);
3502 * Make sure that BD data is updated before writing the producer:
3503 * BD data is written to the memory, the producer is read from the
3504 * memory, thus we need a full memory barrier to ensure the ordering.
3508 REG_WR16(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_PROD_OFFSET(func
),
3514 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3516 * @cmd: command to check
3517 * @cmd_type: command type
3519 static bool bnx2x_is_contextless_ramrod(int cmd
, int cmd_type
)
3521 if ((cmd_type
== NONE_CONNECTION_TYPE
) ||
3522 (cmd
== RAMROD_CMD_ID_ETH_FORWARD_SETUP
) ||
3523 (cmd
== RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES
) ||
3524 (cmd
== RAMROD_CMD_ID_ETH_FILTER_RULES
) ||
3525 (cmd
== RAMROD_CMD_ID_ETH_MULTICAST_RULES
) ||
3526 (cmd
== RAMROD_CMD_ID_ETH_SET_MAC
) ||
3527 (cmd
== RAMROD_CMD_ID_ETH_RSS_UPDATE
))
3536 * bnx2x_sp_post - place a single command on an SP ring
3538 * @bp: driver handle
3539 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3540 * @cid: SW CID the command is related to
3541 * @data_hi: command private data address (high 32 bits)
3542 * @data_lo: command private data address (low 32 bits)
3543 * @cmd_type: command type (e.g. NONE, ETH)
3545 * SP data is handled as if it's always an address pair, thus data fields are
3546 * not swapped to little endian in upper functions. Instead this function swaps
3547 * data as if it's two u32 fields.
3549 int bnx2x_sp_post(struct bnx2x
*bp
, int command
, int cid
,
3550 u32 data_hi
, u32 data_lo
, int cmd_type
)
3552 struct eth_spe
*spe
;
3554 bool common
= bnx2x_is_contextless_ramrod(command
, cmd_type
);
3556 #ifdef BNX2X_STOP_ON_ERROR
3557 if (unlikely(bp
->panic
)) {
3558 BNX2X_ERR("Can't post SP when there is panic\n");
3563 spin_lock_bh(&bp
->spq_lock
);
3566 if (!atomic_read(&bp
->eq_spq_left
)) {
3567 BNX2X_ERR("BUG! EQ ring full!\n");
3568 spin_unlock_bh(&bp
->spq_lock
);
3572 } else if (!atomic_read(&bp
->cq_spq_left
)) {
3573 BNX2X_ERR("BUG! SPQ ring full!\n");
3574 spin_unlock_bh(&bp
->spq_lock
);
3579 spe
= bnx2x_sp_get_next(bp
);
3581 /* CID needs port number to be encoded int it */
3582 spe
->hdr
.conn_and_cmd_data
=
3583 cpu_to_le32((command
<< SPE_HDR_CMD_ID_SHIFT
) |
3586 type
= (cmd_type
<< SPE_HDR_CONN_TYPE_SHIFT
) & SPE_HDR_CONN_TYPE
;
3588 type
|= ((BP_FUNC(bp
) << SPE_HDR_FUNCTION_ID_SHIFT
) &
3589 SPE_HDR_FUNCTION_ID
);
3591 spe
->hdr
.type
= cpu_to_le16(type
);
3593 spe
->data
.update_data_addr
.hi
= cpu_to_le32(data_hi
);
3594 spe
->data
.update_data_addr
.lo
= cpu_to_le32(data_lo
);
3597 * It's ok if the actual decrement is issued towards the memory
3598 * somewhere between the spin_lock and spin_unlock. Thus no
3599 * more explict memory barrier is needed.
3602 atomic_dec(&bp
->eq_spq_left
);
3604 atomic_dec(&bp
->cq_spq_left
);
3608 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3609 bp
->spq_prod_idx
, (u32
)U64_HI(bp
->spq_mapping
),
3610 (u32
)(U64_LO(bp
->spq_mapping
) +
3611 (void *)bp
->spq_prod_bd
- (void *)bp
->spq
), command
, common
,
3612 HW_CID(bp
, cid
), data_hi
, data_lo
, type
,
3613 atomic_read(&bp
->cq_spq_left
), atomic_read(&bp
->eq_spq_left
));
3615 bnx2x_sp_prod_update(bp
);
3616 spin_unlock_bh(&bp
->spq_lock
);
3620 /* acquire split MCP access lock register */
3621 static int bnx2x_acquire_alr(struct bnx2x
*bp
)
3627 for (j
= 0; j
< 1000; j
++) {
3629 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, val
);
3630 val
= REG_RD(bp
, GRCBASE_MCP
+ 0x9c);
3631 if (val
& (1L << 31))
3636 if (!(val
& (1L << 31))) {
3637 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3644 /* release split MCP access lock register */
3645 static void bnx2x_release_alr(struct bnx2x
*bp
)
3647 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, 0);
3650 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3651 #define BNX2X_DEF_SB_IDX 0x0002
3653 static u16
bnx2x_update_dsb_idx(struct bnx2x
*bp
)
3655 struct host_sp_status_block
*def_sb
= bp
->def_status_blk
;
3658 barrier(); /* status block is written to by the chip */
3659 if (bp
->def_att_idx
!= def_sb
->atten_status_block
.attn_bits_index
) {
3660 bp
->def_att_idx
= def_sb
->atten_status_block
.attn_bits_index
;
3661 rc
|= BNX2X_DEF_SB_ATT_IDX
;
3664 if (bp
->def_idx
!= def_sb
->sp_sb
.running_index
) {
3665 bp
->def_idx
= def_sb
->sp_sb
.running_index
;
3666 rc
|= BNX2X_DEF_SB_IDX
;
3669 /* Do not reorder: indecies reading should complete before handling */
3675 * slow path service functions
3678 static void bnx2x_attn_int_asserted(struct bnx2x
*bp
, u32 asserted
)
3680 int port
= BP_PORT(bp
);
3681 u32 aeu_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
3682 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
3683 u32 nig_int_mask_addr
= port
? NIG_REG_MASK_INTERRUPT_PORT1
:
3684 NIG_REG_MASK_INTERRUPT_PORT0
;
3689 if (bp
->attn_state
& asserted
)
3690 BNX2X_ERR("IGU ERROR\n");
3692 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
3693 aeu_mask
= REG_RD(bp
, aeu_addr
);
3695 DP(NETIF_MSG_HW
, "aeu_mask %x newly asserted %x\n",
3696 aeu_mask
, asserted
);
3697 aeu_mask
&= ~(asserted
& 0x3ff);
3698 DP(NETIF_MSG_HW
, "new mask %x\n", aeu_mask
);
3700 REG_WR(bp
, aeu_addr
, aeu_mask
);
3701 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
3703 DP(NETIF_MSG_HW
, "attn_state %x\n", bp
->attn_state
);
3704 bp
->attn_state
|= asserted
;
3705 DP(NETIF_MSG_HW
, "new state %x\n", bp
->attn_state
);
3707 if (asserted
& ATTN_HARD_WIRED_MASK
) {
3708 if (asserted
& ATTN_NIG_FOR_FUNC
) {
3710 bnx2x_acquire_phy_lock(bp
);
3712 /* save nig interrupt mask */
3713 nig_mask
= REG_RD(bp
, nig_int_mask_addr
);
3715 /* If nig_mask is not set, no need to call the update
3719 REG_WR(bp
, nig_int_mask_addr
, 0);
3721 bnx2x_link_attn(bp
);
3724 /* handle unicore attn? */
3726 if (asserted
& ATTN_SW_TIMER_4_FUNC
)
3727 DP(NETIF_MSG_HW
, "ATTN_SW_TIMER_4_FUNC!\n");
3729 if (asserted
& GPIO_2_FUNC
)
3730 DP(NETIF_MSG_HW
, "GPIO_2_FUNC!\n");
3732 if (asserted
& GPIO_3_FUNC
)
3733 DP(NETIF_MSG_HW
, "GPIO_3_FUNC!\n");
3735 if (asserted
& GPIO_4_FUNC
)
3736 DP(NETIF_MSG_HW
, "GPIO_4_FUNC!\n");
3739 if (asserted
& ATTN_GENERAL_ATTN_1
) {
3740 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_1!\n");
3741 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_1
, 0x0);
3743 if (asserted
& ATTN_GENERAL_ATTN_2
) {
3744 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_2!\n");
3745 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_2
, 0x0);
3747 if (asserted
& ATTN_GENERAL_ATTN_3
) {
3748 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_3!\n");
3749 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_3
, 0x0);
3752 if (asserted
& ATTN_GENERAL_ATTN_4
) {
3753 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_4!\n");
3754 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_4
, 0x0);
3756 if (asserted
& ATTN_GENERAL_ATTN_5
) {
3757 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_5!\n");
3758 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_5
, 0x0);
3760 if (asserted
& ATTN_GENERAL_ATTN_6
) {
3761 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_6!\n");
3762 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_6
, 0x0);
3766 } /* if hardwired */
3768 if (bp
->common
.int_block
== INT_BLOCK_HC
)
3769 reg_addr
= (HC_REG_COMMAND_REG
+ port
*32 +
3770 COMMAND_REG_ATTN_BITS_SET
);
3772 reg_addr
= (BAR_IGU_INTMEM
+ IGU_CMD_ATTN_BIT_SET_UPPER
*8);
3774 DP(NETIF_MSG_HW
, "about to mask 0x%08x at %s addr 0x%x\n", asserted
,
3775 (bp
->common
.int_block
== INT_BLOCK_HC
) ? "HC" : "IGU", reg_addr
);
3776 REG_WR(bp
, reg_addr
, asserted
);
3778 /* now set back the mask */
3779 if (asserted
& ATTN_NIG_FOR_FUNC
) {
3780 /* Verify that IGU ack through BAR was written before restoring
3781 * NIG mask. This loop should exit after 2-3 iterations max.
3783 if (bp
->common
.int_block
!= INT_BLOCK_HC
) {
3784 u32 cnt
= 0, igu_acked
;
3786 igu_acked
= REG_RD(bp
,
3787 IGU_REG_ATTENTION_ACK_BITS
);
3788 } while (((igu_acked
& ATTN_NIG_FOR_FUNC
) == 0) &&
3789 (++cnt
< MAX_IGU_ATTN_ACK_TO
));
3792 "Failed to verify IGU ack on time\n");
3795 REG_WR(bp
, nig_int_mask_addr
, nig_mask
);
3796 bnx2x_release_phy_lock(bp
);
3800 static void bnx2x_fan_failure(struct bnx2x
*bp
)
3802 int port
= BP_PORT(bp
);
3804 /* mark the failure */
3807 dev_info
.port_hw_config
[port
].external_phy_config
);
3809 ext_phy_config
&= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK
;
3810 ext_phy_config
|= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE
;
3811 SHMEM_WR(bp
, dev_info
.port_hw_config
[port
].external_phy_config
,
3814 /* log the failure */
3815 netdev_err(bp
->dev
, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3816 "Please contact OEM Support for assistance\n");
3819 * Schedule device reset (unload)
3820 * This is due to some boards consuming sufficient power when driver is
3821 * up to overheat if fan fails.
3823 smp_mb__before_clear_bit();
3824 set_bit(BNX2X_SP_RTNL_FAN_FAILURE
, &bp
->sp_rtnl_state
);
3825 smp_mb__after_clear_bit();
3826 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
3830 static void bnx2x_attn_int_deasserted0(struct bnx2x
*bp
, u32 attn
)
3832 int port
= BP_PORT(bp
);
3836 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
3837 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
3839 if (attn
& AEU_INPUTS_ATTN_BITS_SPIO5
) {
3841 val
= REG_RD(bp
, reg_offset
);
3842 val
&= ~AEU_INPUTS_ATTN_BITS_SPIO5
;
3843 REG_WR(bp
, reg_offset
, val
);
3845 BNX2X_ERR("SPIO5 hw attention\n");
3847 /* Fan failure attention */
3848 bnx2x_hw_reset_phy(&bp
->link_params
);
3849 bnx2x_fan_failure(bp
);
3852 if ((attn
& bp
->link_vars
.aeu_int_mask
) && bp
->port
.pmf
) {
3853 bnx2x_acquire_phy_lock(bp
);
3854 bnx2x_handle_module_detect_int(&bp
->link_params
);
3855 bnx2x_release_phy_lock(bp
);
3858 if (attn
& HW_INTERRUT_ASSERT_SET_0
) {
3860 val
= REG_RD(bp
, reg_offset
);
3861 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_0
);
3862 REG_WR(bp
, reg_offset
, val
);
3864 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3865 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_0
));
3870 static void bnx2x_attn_int_deasserted1(struct bnx2x
*bp
, u32 attn
)
3874 if (attn
& AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT
) {
3876 val
= REG_RD(bp
, DORQ_REG_DORQ_INT_STS_CLR
);
3877 BNX2X_ERR("DB hw attention 0x%x\n", val
);
3878 /* DORQ discard attention */
3880 BNX2X_ERR("FATAL error from DORQ\n");
3883 if (attn
& HW_INTERRUT_ASSERT_SET_1
) {
3885 int port
= BP_PORT(bp
);
3888 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1
:
3889 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1
);
3891 val
= REG_RD(bp
, reg_offset
);
3892 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_1
);
3893 REG_WR(bp
, reg_offset
, val
);
3895 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3896 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_1
));
3901 static void bnx2x_attn_int_deasserted2(struct bnx2x
*bp
, u32 attn
)
3905 if (attn
& AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT
) {
3907 val
= REG_RD(bp
, CFC_REG_CFC_INT_STS_CLR
);
3908 BNX2X_ERR("CFC hw attention 0x%x\n", val
);
3909 /* CFC error attention */
3911 BNX2X_ERR("FATAL error from CFC\n");
3914 if (attn
& AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT
) {
3915 val
= REG_RD(bp
, PXP_REG_PXP_INT_STS_CLR_0
);
3916 BNX2X_ERR("PXP hw attention-0 0x%x\n", val
);
3917 /* RQ_USDMDP_FIFO_OVERFLOW */
3919 BNX2X_ERR("FATAL error from PXP\n");
3921 if (!CHIP_IS_E1x(bp
)) {
3922 val
= REG_RD(bp
, PXP_REG_PXP_INT_STS_CLR_1
);
3923 BNX2X_ERR("PXP hw attention-1 0x%x\n", val
);
3927 if (attn
& HW_INTERRUT_ASSERT_SET_2
) {
3929 int port
= BP_PORT(bp
);
3932 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2
:
3933 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2
);
3935 val
= REG_RD(bp
, reg_offset
);
3936 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_2
);
3937 REG_WR(bp
, reg_offset
, val
);
3939 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3940 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_2
));
3945 static void bnx2x_attn_int_deasserted3(struct bnx2x
*bp
, u32 attn
)
3949 if (attn
& EVEREST_GEN_ATTN_IN_USE_MASK
) {
3951 if (attn
& BNX2X_PMF_LINK_ASSERT
) {
3952 int func
= BP_FUNC(bp
);
3954 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
3955 bnx2x_read_mf_cfg(bp
);
3956 bp
->mf_config
[BP_VN(bp
)] = MF_CFG_RD(bp
,
3957 func_mf_config
[BP_ABS_FUNC(bp
)].config
);
3959 func_mb
[BP_FW_MB_IDX(bp
)].drv_status
);
3960 if (val
& DRV_STATUS_DCC_EVENT_MASK
)
3962 (val
& DRV_STATUS_DCC_EVENT_MASK
));
3964 if (val
& DRV_STATUS_SET_MF_BW
)
3965 bnx2x_set_mf_bw(bp
);
3967 if (val
& DRV_STATUS_DRV_INFO_REQ
)
3968 bnx2x_handle_drv_info_req(bp
);
3970 if (val
& DRV_STATUS_VF_DISABLED
)
3971 bnx2x_vf_handle_flr_event(bp
);
3973 if ((bp
->port
.pmf
== 0) && (val
& DRV_STATUS_PMF
))
3974 bnx2x_pmf_update(bp
);
3977 (val
& DRV_STATUS_DCBX_NEGOTIATION_RESULTS
) &&
3978 bp
->dcbx_enabled
> 0)
3979 /* start dcbx state machine */
3980 bnx2x_dcbx_set_params(bp
,
3981 BNX2X_DCBX_STATE_NEG_RECEIVED
);
3982 if (val
& DRV_STATUS_AFEX_EVENT_MASK
)
3983 bnx2x_handle_afex_cmd(bp
,
3984 val
& DRV_STATUS_AFEX_EVENT_MASK
);
3985 if (val
& DRV_STATUS_EEE_NEGOTIATION_RESULTS
)
3986 bnx2x_handle_eee_event(bp
);
3987 if (bp
->link_vars
.periodic_flags
&
3988 PERIODIC_FLAGS_LINK_EVENT
) {
3989 /* sync with link */
3990 bnx2x_acquire_phy_lock(bp
);
3991 bp
->link_vars
.periodic_flags
&=
3992 ~PERIODIC_FLAGS_LINK_EVENT
;
3993 bnx2x_release_phy_lock(bp
);
3995 bnx2x_link_sync_notify(bp
);
3996 bnx2x_link_report(bp
);
3998 /* Always call it here: bnx2x_link_report() will
3999 * prevent the link indication duplication.
4001 bnx2x__link_status_update(bp
);
4002 } else if (attn
& BNX2X_MC_ASSERT_BITS
) {
4004 BNX2X_ERR("MC assert!\n");
4005 bnx2x_mc_assert(bp
);
4006 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_10
, 0);
4007 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_9
, 0);
4008 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_8
, 0);
4009 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_7
, 0);
4012 } else if (attn
& BNX2X_MCP_ASSERT
) {
4014 BNX2X_ERR("MCP assert!\n");
4015 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_11
, 0);
4019 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn
);
4022 if (attn
& EVEREST_LATCHED_ATTN_IN_USE_MASK
) {
4023 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn
);
4024 if (attn
& BNX2X_GRC_TIMEOUT
) {
4025 val
= CHIP_IS_E1(bp
) ? 0 :
4026 REG_RD(bp
, MISC_REG_GRC_TIMEOUT_ATTN
);
4027 BNX2X_ERR("GRC time-out 0x%08x\n", val
);
4029 if (attn
& BNX2X_GRC_RSV
) {
4030 val
= CHIP_IS_E1(bp
) ? 0 :
4031 REG_RD(bp
, MISC_REG_GRC_RSV_ATTN
);
4032 BNX2X_ERR("GRC reserved 0x%08x\n", val
);
4034 REG_WR(bp
, MISC_REG_AEU_CLR_LATCH_SIGNAL
, 0x7ff);
4040 * 0-7 - Engine0 load counter.
4041 * 8-15 - Engine1 load counter.
4042 * 16 - Engine0 RESET_IN_PROGRESS bit.
4043 * 17 - Engine1 RESET_IN_PROGRESS bit.
4044 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4046 * 19 - Engine1 ONE_IS_LOADED.
4047 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4048 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4049 * just the one belonging to its engine).
4052 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4054 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4055 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4056 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4057 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4058 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4059 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4060 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
4063 * Set the GLOBAL_RESET bit.
4065 * Should be run under rtnl lock
4067 void bnx2x_set_reset_global(struct bnx2x
*bp
)
4070 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4071 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4072 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
| BNX2X_GLOBAL_RESET_BIT
);
4073 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4077 * Clear the GLOBAL_RESET bit.
4079 * Should be run under rtnl lock
4081 static void bnx2x_clear_reset_global(struct bnx2x
*bp
)
4084 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4085 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4086 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
& (~BNX2X_GLOBAL_RESET_BIT
));
4087 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4091 * Checks the GLOBAL_RESET bit.
4093 * should be run under rtnl lock
4095 static bool bnx2x_reset_is_global(struct bnx2x
*bp
)
4097 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4099 DP(NETIF_MSG_HW
, "GEN_REG_VAL=0x%08x\n", val
);
4100 return (val
& BNX2X_GLOBAL_RESET_BIT
) ? true : false;
4104 * Clear RESET_IN_PROGRESS bit for the current engine.
4106 * Should be run under rtnl lock
4108 static void bnx2x_set_reset_done(struct bnx2x
*bp
)
4111 u32 bit
= BP_PATH(bp
) ?
4112 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
4113 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4114 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4118 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4120 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4124 * Set RESET_IN_PROGRESS for the current engine.
4126 * should be run under rtnl lock
4128 void bnx2x_set_reset_in_progress(struct bnx2x
*bp
)
4131 u32 bit
= BP_PATH(bp
) ?
4132 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
4133 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4134 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4138 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4139 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4143 * Checks the RESET_IN_PROGRESS bit for the given engine.
4144 * should be run under rtnl lock
4146 bool bnx2x_reset_is_done(struct bnx2x
*bp
, int engine
)
4148 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4150 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
4152 /* return false if bit is set */
4153 return (val
& bit
) ? false : true;
4157 * set pf load for the current pf.
4159 * should be run under rtnl lock
4161 void bnx2x_set_pf_load(struct bnx2x
*bp
)
4164 u32 mask
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_MASK
:
4165 BNX2X_PATH0_LOAD_CNT_MASK
;
4166 u32 shift
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_SHIFT
:
4167 BNX2X_PATH0_LOAD_CNT_SHIFT
;
4169 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4170 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4172 DP(NETIF_MSG_IFUP
, "Old GEN_REG_VAL=0x%08x\n", val
);
4174 /* get the current counter value */
4175 val1
= (val
& mask
) >> shift
;
4177 /* set bit of that PF */
4178 val1
|= (1 << bp
->pf_num
);
4180 /* clear the old value */
4183 /* set the new one */
4184 val
|= ((val1
<< shift
) & mask
);
4186 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4187 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4191 * bnx2x_clear_pf_load - clear pf load mark
4193 * @bp: driver handle
4195 * Should be run under rtnl lock.
4196 * Decrements the load counter for the current engine. Returns
4197 * whether other functions are still loaded
4199 bool bnx2x_clear_pf_load(struct bnx2x
*bp
)
4202 u32 mask
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_MASK
:
4203 BNX2X_PATH0_LOAD_CNT_MASK
;
4204 u32 shift
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_SHIFT
:
4205 BNX2X_PATH0_LOAD_CNT_SHIFT
;
4207 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4208 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4209 DP(NETIF_MSG_IFDOWN
, "Old GEN_REG_VAL=0x%08x\n", val
);
4211 /* get the current counter value */
4212 val1
= (val
& mask
) >> shift
;
4214 /* clear bit of that PF */
4215 val1
&= ~(1 << bp
->pf_num
);
4217 /* clear the old value */
4220 /* set the new one */
4221 val
|= ((val1
<< shift
) & mask
);
4223 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4224 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4229 * Read the load status for the current engine.
4231 * should be run under rtnl lock
4233 static bool bnx2x_get_load_status(struct bnx2x
*bp
, int engine
)
4235 u32 mask
= (engine
? BNX2X_PATH1_LOAD_CNT_MASK
:
4236 BNX2X_PATH0_LOAD_CNT_MASK
);
4237 u32 shift
= (engine
? BNX2X_PATH1_LOAD_CNT_SHIFT
:
4238 BNX2X_PATH0_LOAD_CNT_SHIFT
);
4239 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4241 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "GLOB_REG=0x%08x\n", val
);
4243 val
= (val
& mask
) >> shift
;
4245 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "load mask for engine %d = 0x%x\n",
4251 static void _print_next_block(int idx
, const char *blk
)
4253 pr_cont("%s%s", idx
? ", " : "", blk
);
4256 static int bnx2x_check_blocks_with_parity0(u32 sig
, int par_num
,
4261 for (i
= 0; sig
; i
++) {
4262 cur_bit
= ((u32
)0x1 << i
);
4263 if (sig
& cur_bit
) {
4265 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR
:
4267 _print_next_block(par_num
++, "BRB");
4269 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR
:
4271 _print_next_block(par_num
++, "PARSER");
4273 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR
:
4275 _print_next_block(par_num
++, "TSDM");
4277 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR
:
4279 _print_next_block(par_num
++,
4282 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR
:
4284 _print_next_block(par_num
++, "TCM");
4286 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR
:
4288 _print_next_block(par_num
++, "TSEMI");
4290 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR
:
4292 _print_next_block(par_num
++, "XPB");
4304 static int bnx2x_check_blocks_with_parity1(u32 sig
, int par_num
,
4305 bool *global
, bool print
)
4309 for (i
= 0; sig
; i
++) {
4310 cur_bit
= ((u32
)0x1 << i
);
4311 if (sig
& cur_bit
) {
4313 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR
:
4315 _print_next_block(par_num
++, "PBF");
4317 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR
:
4319 _print_next_block(par_num
++, "QM");
4321 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR
:
4323 _print_next_block(par_num
++, "TM");
4325 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR
:
4327 _print_next_block(par_num
++, "XSDM");
4329 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR
:
4331 _print_next_block(par_num
++, "XCM");
4333 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR
:
4335 _print_next_block(par_num
++, "XSEMI");
4337 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR
:
4339 _print_next_block(par_num
++,
4342 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR
:
4344 _print_next_block(par_num
++, "NIG");
4346 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR
:
4348 _print_next_block(par_num
++,
4352 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR
:
4354 _print_next_block(par_num
++, "DEBUG");
4356 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR
:
4358 _print_next_block(par_num
++, "USDM");
4360 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR
:
4362 _print_next_block(par_num
++, "UCM");
4364 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR
:
4366 _print_next_block(par_num
++, "USEMI");
4368 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR
:
4370 _print_next_block(par_num
++, "UPB");
4372 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR
:
4374 _print_next_block(par_num
++, "CSDM");
4376 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR
:
4378 _print_next_block(par_num
++, "CCM");
4390 static int bnx2x_check_blocks_with_parity2(u32 sig
, int par_num
,
4395 for (i
= 0; sig
; i
++) {
4396 cur_bit
= ((u32
)0x1 << i
);
4397 if (sig
& cur_bit
) {
4399 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR
:
4401 _print_next_block(par_num
++, "CSEMI");
4403 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR
:
4405 _print_next_block(par_num
++, "PXP");
4407 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
:
4409 _print_next_block(par_num
++,
4410 "PXPPCICLOCKCLIENT");
4412 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR
:
4414 _print_next_block(par_num
++, "CFC");
4416 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR
:
4418 _print_next_block(par_num
++, "CDU");
4420 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR
:
4422 _print_next_block(par_num
++, "DMAE");
4424 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR
:
4426 _print_next_block(par_num
++, "IGU");
4428 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR
:
4430 _print_next_block(par_num
++, "MISC");
4442 static int bnx2x_check_blocks_with_parity3(u32 sig
, int par_num
,
4443 bool *global
, bool print
)
4447 for (i
= 0; sig
; i
++) {
4448 cur_bit
= ((u32
)0x1 << i
);
4449 if (sig
& cur_bit
) {
4451 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY
:
4453 _print_next_block(par_num
++, "MCP ROM");
4456 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY
:
4458 _print_next_block(par_num
++,
4462 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY
:
4464 _print_next_block(par_num
++,
4468 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY
:
4470 _print_next_block(par_num
++,
4484 static int bnx2x_check_blocks_with_parity4(u32 sig
, int par_num
,
4489 for (i
= 0; sig
; i
++) {
4490 cur_bit
= ((u32
)0x1 << i
);
4491 if (sig
& cur_bit
) {
4493 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
:
4495 _print_next_block(par_num
++, "PGLUE_B");
4497 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
:
4499 _print_next_block(par_num
++, "ATC");
4511 static bool bnx2x_parity_attn(struct bnx2x
*bp
, bool *global
, bool print
,
4514 if ((sig
[0] & HW_PRTY_ASSERT_SET_0
) ||
4515 (sig
[1] & HW_PRTY_ASSERT_SET_1
) ||
4516 (sig
[2] & HW_PRTY_ASSERT_SET_2
) ||
4517 (sig
[3] & HW_PRTY_ASSERT_SET_3
) ||
4518 (sig
[4] & HW_PRTY_ASSERT_SET_4
)) {
4520 DP(NETIF_MSG_HW
, "Was parity error: HW block parity attention:\n"
4521 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4522 sig
[0] & HW_PRTY_ASSERT_SET_0
,
4523 sig
[1] & HW_PRTY_ASSERT_SET_1
,
4524 sig
[2] & HW_PRTY_ASSERT_SET_2
,
4525 sig
[3] & HW_PRTY_ASSERT_SET_3
,
4526 sig
[4] & HW_PRTY_ASSERT_SET_4
);
4529 "Parity errors detected in blocks: ");
4530 par_num
= bnx2x_check_blocks_with_parity0(
4531 sig
[0] & HW_PRTY_ASSERT_SET_0
, par_num
, print
);
4532 par_num
= bnx2x_check_blocks_with_parity1(
4533 sig
[1] & HW_PRTY_ASSERT_SET_1
, par_num
, global
, print
);
4534 par_num
= bnx2x_check_blocks_with_parity2(
4535 sig
[2] & HW_PRTY_ASSERT_SET_2
, par_num
, print
);
4536 par_num
= bnx2x_check_blocks_with_parity3(
4537 sig
[3] & HW_PRTY_ASSERT_SET_3
, par_num
, global
, print
);
4538 par_num
= bnx2x_check_blocks_with_parity4(
4539 sig
[4] & HW_PRTY_ASSERT_SET_4
, par_num
, print
);
4550 * bnx2x_chk_parity_attn - checks for parity attentions.
4552 * @bp: driver handle
4553 * @global: true if there was a global attention
4554 * @print: show parity attention in syslog
4556 bool bnx2x_chk_parity_attn(struct bnx2x
*bp
, bool *global
, bool print
)
4558 struct attn_route attn
= { {0} };
4559 int port
= BP_PORT(bp
);
4561 attn
.sig
[0] = REG_RD(bp
,
4562 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+
4564 attn
.sig
[1] = REG_RD(bp
,
4565 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0
+
4567 attn
.sig
[2] = REG_RD(bp
,
4568 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0
+
4570 attn
.sig
[3] = REG_RD(bp
,
4571 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0
+
4574 if (!CHIP_IS_E1x(bp
))
4575 attn
.sig
[4] = REG_RD(bp
,
4576 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0
+
4579 return bnx2x_parity_attn(bp
, global
, print
, attn
.sig
);
4583 static void bnx2x_attn_int_deasserted4(struct bnx2x
*bp
, u32 attn
)
4586 if (attn
& AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT
) {
4588 val
= REG_RD(bp
, PGLUE_B_REG_PGLUE_B_INT_STS_CLR
);
4589 BNX2X_ERR("PGLUE hw attention 0x%x\n", val
);
4590 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR
)
4591 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4592 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR
)
4593 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4594 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN
)
4595 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4596 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN
)
4597 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4599 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN
)
4600 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4602 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN
)
4603 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4604 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN
)
4605 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4606 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN
)
4607 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4608 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW
)
4609 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4611 if (attn
& AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT
) {
4612 val
= REG_RD(bp
, ATC_REG_ATC_INT_STS_CLR
);
4613 BNX2X_ERR("ATC hw attention 0x%x\n", val
);
4614 if (val
& ATC_ATC_INT_STS_REG_ADDRESS_ERROR
)
4615 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4616 if (val
& ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND
)
4617 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4618 if (val
& ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS
)
4619 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4620 if (val
& ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT
)
4621 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4622 if (val
& ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR
)
4623 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4624 if (val
& ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU
)
4625 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4628 if (attn
& (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
|
4629 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
)) {
4630 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4631 (u32
)(attn
& (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
|
4632 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
)));
4637 static void bnx2x_attn_int_deasserted(struct bnx2x
*bp
, u32 deasserted
)
4639 struct attn_route attn
, *group_mask
;
4640 int port
= BP_PORT(bp
);
4645 bool global
= false;
4647 /* need to take HW lock because MCP or other port might also
4648 try to handle this event */
4649 bnx2x_acquire_alr(bp
);
4651 if (bnx2x_chk_parity_attn(bp
, &global
, true)) {
4652 #ifndef BNX2X_STOP_ON_ERROR
4653 bp
->recovery_state
= BNX2X_RECOVERY_INIT
;
4654 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
4655 /* Disable HW interrupts */
4656 bnx2x_int_disable(bp
);
4657 /* In case of parity errors don't handle attentions so that
4658 * other function would "see" parity errors.
4663 bnx2x_release_alr(bp
);
4667 attn
.sig
[0] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+ port
*4);
4668 attn
.sig
[1] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0
+ port
*4);
4669 attn
.sig
[2] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0
+ port
*4);
4670 attn
.sig
[3] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0
+ port
*4);
4671 if (!CHIP_IS_E1x(bp
))
4673 REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0
+ port
*4);
4677 DP(NETIF_MSG_HW
, "attn: %08x %08x %08x %08x %08x\n",
4678 attn
.sig
[0], attn
.sig
[1], attn
.sig
[2], attn
.sig
[3], attn
.sig
[4]);
4680 for (index
= 0; index
< MAX_DYNAMIC_ATTN_GRPS
; index
++) {
4681 if (deasserted
& (1 << index
)) {
4682 group_mask
= &bp
->attn_group
[index
];
4684 DP(NETIF_MSG_HW
, "group[%d]: %08x %08x %08x %08x %08x\n",
4686 group_mask
->sig
[0], group_mask
->sig
[1],
4687 group_mask
->sig
[2], group_mask
->sig
[3],
4688 group_mask
->sig
[4]);
4690 bnx2x_attn_int_deasserted4(bp
,
4691 attn
.sig
[4] & group_mask
->sig
[4]);
4692 bnx2x_attn_int_deasserted3(bp
,
4693 attn
.sig
[3] & group_mask
->sig
[3]);
4694 bnx2x_attn_int_deasserted1(bp
,
4695 attn
.sig
[1] & group_mask
->sig
[1]);
4696 bnx2x_attn_int_deasserted2(bp
,
4697 attn
.sig
[2] & group_mask
->sig
[2]);
4698 bnx2x_attn_int_deasserted0(bp
,
4699 attn
.sig
[0] & group_mask
->sig
[0]);
4703 bnx2x_release_alr(bp
);
4705 if (bp
->common
.int_block
== INT_BLOCK_HC
)
4706 reg_addr
= (HC_REG_COMMAND_REG
+ port
*32 +
4707 COMMAND_REG_ATTN_BITS_CLR
);
4709 reg_addr
= (BAR_IGU_INTMEM
+ IGU_CMD_ATTN_BIT_CLR_UPPER
*8);
4712 DP(NETIF_MSG_HW
, "about to mask 0x%08x at %s addr 0x%x\n", val
,
4713 (bp
->common
.int_block
== INT_BLOCK_HC
) ? "HC" : "IGU", reg_addr
);
4714 REG_WR(bp
, reg_addr
, val
);
4716 if (~bp
->attn_state
& deasserted
)
4717 BNX2X_ERR("IGU ERROR\n");
4719 reg_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
4720 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
4722 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
4723 aeu_mask
= REG_RD(bp
, reg_addr
);
4725 DP(NETIF_MSG_HW
, "aeu_mask %x newly deasserted %x\n",
4726 aeu_mask
, deasserted
);
4727 aeu_mask
|= (deasserted
& 0x3ff);
4728 DP(NETIF_MSG_HW
, "new mask %x\n", aeu_mask
);
4730 REG_WR(bp
, reg_addr
, aeu_mask
);
4731 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
4733 DP(NETIF_MSG_HW
, "attn_state %x\n", bp
->attn_state
);
4734 bp
->attn_state
&= ~deasserted
;
4735 DP(NETIF_MSG_HW
, "new state %x\n", bp
->attn_state
);
4738 static void bnx2x_attn_int(struct bnx2x
*bp
)
4740 /* read local copy of bits */
4741 u32 attn_bits
= le32_to_cpu(bp
->def_status_blk
->atten_status_block
.
4743 u32 attn_ack
= le32_to_cpu(bp
->def_status_blk
->atten_status_block
.
4745 u32 attn_state
= bp
->attn_state
;
4747 /* look for changed bits */
4748 u32 asserted
= attn_bits
& ~attn_ack
& ~attn_state
;
4749 u32 deasserted
= ~attn_bits
& attn_ack
& attn_state
;
4752 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4753 attn_bits
, attn_ack
, asserted
, deasserted
);
4755 if (~(attn_bits
^ attn_ack
) & (attn_bits
^ attn_state
))
4756 BNX2X_ERR("BAD attention state\n");
4758 /* handle bits that were raised */
4760 bnx2x_attn_int_asserted(bp
, asserted
);
4763 bnx2x_attn_int_deasserted(bp
, deasserted
);
4766 void bnx2x_igu_ack_sb(struct bnx2x
*bp
, u8 igu_sb_id
, u8 segment
,
4767 u16 index
, u8 op
, u8 update
)
4769 u32 igu_addr
= bp
->igu_base_addr
;
4770 igu_addr
+= (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
)*8;
4771 bnx2x_igu_ack_sb_gen(bp
, igu_sb_id
, segment
, index
, op
, update
,
4775 static void bnx2x_update_eq_prod(struct bnx2x
*bp
, u16 prod
)
4777 /* No memory barriers */
4778 storm_memset_eq_prod(bp
, prod
, BP_FUNC(bp
));
4779 mmiowb(); /* keep prod updates ordered */
4782 static int bnx2x_cnic_handle_cfc_del(struct bnx2x
*bp
, u32 cid
,
4783 union event_ring_elem
*elem
)
4785 u8 err
= elem
->message
.error
;
4787 if (!bp
->cnic_eth_dev
.starting_cid
||
4788 (cid
< bp
->cnic_eth_dev
.starting_cid
&&
4789 cid
!= bp
->cnic_eth_dev
.iscsi_l2_cid
))
4792 DP(BNX2X_MSG_SP
, "got delete ramrod for CNIC CID %d\n", cid
);
4794 if (unlikely(err
)) {
4796 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4798 bnx2x_panic_dump(bp
, false);
4800 bnx2x_cnic_cfc_comp(bp
, cid
, err
);
4804 static void bnx2x_handle_mcast_eqe(struct bnx2x
*bp
)
4806 struct bnx2x_mcast_ramrod_params rparam
;
4809 memset(&rparam
, 0, sizeof(rparam
));
4811 rparam
.mcast_obj
= &bp
->mcast_obj
;
4813 netif_addr_lock_bh(bp
->dev
);
4815 /* Clear pending state for the last command */
4816 bp
->mcast_obj
.raw
.clear_pending(&bp
->mcast_obj
.raw
);
4818 /* If there are pending mcast commands - send them */
4819 if (bp
->mcast_obj
.check_pending(&bp
->mcast_obj
)) {
4820 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_CONT
);
4822 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4826 netif_addr_unlock_bh(bp
->dev
);
4829 static void bnx2x_handle_classification_eqe(struct bnx2x
*bp
,
4830 union event_ring_elem
*elem
)
4832 unsigned long ramrod_flags
= 0;
4834 u32 cid
= elem
->message
.data
.eth_event
.echo
& BNX2X_SWCID_MASK
;
4835 struct bnx2x_vlan_mac_obj
*vlan_mac_obj
;
4837 /* Always push next commands out, don't wait here */
4838 __set_bit(RAMROD_CONT
, &ramrod_flags
);
4840 switch (le32_to_cpu((__force __le32
)elem
->message
.data
.eth_event
.echo
)
4841 >> BNX2X_SWCID_SHIFT
) {
4842 case BNX2X_FILTER_MAC_PENDING
:
4843 DP(BNX2X_MSG_SP
, "Got SETUP_MAC completions\n");
4844 if (CNIC_LOADED(bp
) && (cid
== BNX2X_ISCSI_ETH_CID(bp
)))
4845 vlan_mac_obj
= &bp
->iscsi_l2_mac_obj
;
4847 vlan_mac_obj
= &bp
->sp_objs
[cid
].mac_obj
;
4850 case BNX2X_FILTER_MCAST_PENDING
:
4851 DP(BNX2X_MSG_SP
, "Got SETUP_MCAST completions\n");
4852 /* This is only relevant for 57710 where multicast MACs are
4853 * configured as unicast MACs using the same ramrod.
4855 bnx2x_handle_mcast_eqe(bp
);
4858 BNX2X_ERR("Unsupported classification command: %d\n",
4859 elem
->message
.data
.eth_event
.echo
);
4863 rc
= vlan_mac_obj
->complete(bp
, vlan_mac_obj
, elem
, &ramrod_flags
);
4866 BNX2X_ERR("Failed to schedule new commands: %d\n", rc
);
4868 DP(BNX2X_MSG_SP
, "Scheduled next pending commands...\n");
4872 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x
*bp
, bool start
);
4874 static void bnx2x_handle_rx_mode_eqe(struct bnx2x
*bp
)
4876 netif_addr_lock_bh(bp
->dev
);
4878 clear_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
);
4880 /* Send rx_mode command again if was requested */
4881 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
))
4882 bnx2x_set_storm_rx_mode(bp
);
4883 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
,
4885 bnx2x_set_iscsi_eth_rx_mode(bp
, true);
4886 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
,
4888 bnx2x_set_iscsi_eth_rx_mode(bp
, false);
4890 netif_addr_unlock_bh(bp
->dev
);
4893 static void bnx2x_after_afex_vif_lists(struct bnx2x
*bp
,
4894 union event_ring_elem
*elem
)
4896 if (elem
->message
.data
.vif_list_event
.echo
== VIF_LIST_RULE_GET
) {
4898 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4899 elem
->message
.data
.vif_list_event
.func_bit_map
);
4900 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_LISTGET_ACK
,
4901 elem
->message
.data
.vif_list_event
.func_bit_map
);
4902 } else if (elem
->message
.data
.vif_list_event
.echo
==
4903 VIF_LIST_RULE_SET
) {
4904 DP(BNX2X_MSG_SP
, "afex: ramrod completed VIF LIST_SET\n");
4905 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_LISTSET_ACK
, 0);
4909 /* called with rtnl_lock */
4910 static void bnx2x_after_function_update(struct bnx2x
*bp
)
4913 struct bnx2x_fastpath
*fp
;
4914 struct bnx2x_queue_state_params queue_params
= {NULL
};
4915 struct bnx2x_queue_update_params
*q_update_params
=
4916 &queue_params
.params
.update
;
4918 /* Send Q update command with afex vlan removal values for all Qs */
4919 queue_params
.cmd
= BNX2X_Q_CMD_UPDATE
;
4921 /* set silent vlan removal values according to vlan mode */
4922 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG
,
4923 &q_update_params
->update_flags
);
4924 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM
,
4925 &q_update_params
->update_flags
);
4926 __set_bit(RAMROD_COMP_WAIT
, &queue_params
.ramrod_flags
);
4928 /* in access mode mark mask and value are 0 to strip all vlans */
4929 if (bp
->afex_vlan_mode
== FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE
) {
4930 q_update_params
->silent_removal_value
= 0;
4931 q_update_params
->silent_removal_mask
= 0;
4933 q_update_params
->silent_removal_value
=
4934 (bp
->afex_def_vlan_tag
& VLAN_VID_MASK
);
4935 q_update_params
->silent_removal_mask
= VLAN_VID_MASK
;
4938 for_each_eth_queue(bp
, q
) {
4939 /* Set the appropriate Queue object */
4941 queue_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
4943 /* send the ramrod */
4944 rc
= bnx2x_queue_state_change(bp
, &queue_params
);
4946 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4951 fp
= &bp
->fp
[FCOE_IDX(bp
)];
4952 queue_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
4954 /* clear pending completion bit */
4955 __clear_bit(RAMROD_COMP_WAIT
, &queue_params
.ramrod_flags
);
4957 /* mark latest Q bit */
4958 smp_mb__before_clear_bit();
4959 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
);
4960 smp_mb__after_clear_bit();
4962 /* send Q update ramrod for FCoE Q */
4963 rc
= bnx2x_queue_state_change(bp
, &queue_params
);
4965 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4968 /* If no FCoE ring - ACK MCP now */
4969 bnx2x_link_report(bp
);
4970 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
4974 static struct bnx2x_queue_sp_obj
*bnx2x_cid_to_q_obj(
4975 struct bnx2x
*bp
, u32 cid
)
4977 DP(BNX2X_MSG_SP
, "retrieving fp from cid %d\n", cid
);
4979 if (CNIC_LOADED(bp
) && (cid
== BNX2X_FCOE_ETH_CID(bp
)))
4980 return &bnx2x_fcoe_sp_obj(bp
, q_obj
);
4982 return &bp
->sp_objs
[CID_TO_FP(cid
, bp
)].q_obj
;
4985 static void bnx2x_eq_int(struct bnx2x
*bp
)
4987 u16 hw_cons
, sw_cons
, sw_prod
;
4988 union event_ring_elem
*elem
;
4992 int rc
, spqe_cnt
= 0;
4993 struct bnx2x_queue_sp_obj
*q_obj
;
4994 struct bnx2x_func_sp_obj
*f_obj
= &bp
->func_obj
;
4995 struct bnx2x_raw_obj
*rss_raw
= &bp
->rss_conf_obj
.raw
;
4997 hw_cons
= le16_to_cpu(*bp
->eq_cons_sb
);
4999 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
5000 * when we get the the next-page we nned to adjust so the loop
5001 * condition below will be met. The next element is the size of a
5002 * regular element and hence incrementing by 1
5004 if ((hw_cons
& EQ_DESC_MAX_PAGE
) == EQ_DESC_MAX_PAGE
)
5007 /* This function may never run in parallel with itself for a
5008 * specific bp, thus there is no need in "paired" read memory
5011 sw_cons
= bp
->eq_cons
;
5012 sw_prod
= bp
->eq_prod
;
5014 DP(BNX2X_MSG_SP
, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
5015 hw_cons
, sw_cons
, atomic_read(&bp
->eq_spq_left
));
5017 for (; sw_cons
!= hw_cons
;
5018 sw_prod
= NEXT_EQ_IDX(sw_prod
), sw_cons
= NEXT_EQ_IDX(sw_cons
)) {
5020 elem
= &bp
->eq_ring
[EQ_DESC(sw_cons
)];
5022 rc
= bnx2x_iov_eq_sp_event(bp
, elem
);
5024 DP(BNX2X_MSG_IOV
, "bnx2x_iov_eq_sp_event returned %d\n",
5029 /* elem CID originates from FW; actually LE */
5030 cid
= SW_CID((__force __le32
)
5031 elem
->message
.data
.cfc_del_event
.cid
);
5032 opcode
= elem
->message
.opcode
;
5034 /* handle eq element */
5036 case EVENT_RING_OPCODE_VF_PF_CHANNEL
:
5037 DP(BNX2X_MSG_IOV
, "vf pf channel element on eq\n");
5038 bnx2x_vf_mbx(bp
, &elem
->message
.data
.vf_pf_event
);
5041 case EVENT_RING_OPCODE_STAT_QUERY
:
5042 DP(BNX2X_MSG_SP
| BNX2X_MSG_STATS
,
5043 "got statistics comp event %d\n",
5045 /* nothing to do with stats comp */
5048 case EVENT_RING_OPCODE_CFC_DEL
:
5049 /* handle according to cid range */
5051 * we may want to verify here that the bp state is
5055 "got delete ramrod for MULTI[%d]\n", cid
);
5057 if (CNIC_LOADED(bp
) &&
5058 !bnx2x_cnic_handle_cfc_del(bp
, cid
, elem
))
5061 q_obj
= bnx2x_cid_to_q_obj(bp
, cid
);
5063 if (q_obj
->complete_cmd(bp
, q_obj
, BNX2X_Q_CMD_CFC_DEL
))
5070 case EVENT_RING_OPCODE_STOP_TRAFFIC
:
5071 DP(BNX2X_MSG_SP
| BNX2X_MSG_DCB
, "got STOP TRAFFIC\n");
5072 if (f_obj
->complete_cmd(bp
, f_obj
,
5073 BNX2X_F_CMD_TX_STOP
))
5075 bnx2x_dcbx_set_params(bp
, BNX2X_DCBX_STATE_TX_PAUSED
);
5078 case EVENT_RING_OPCODE_START_TRAFFIC
:
5079 DP(BNX2X_MSG_SP
| BNX2X_MSG_DCB
, "got START TRAFFIC\n");
5080 if (f_obj
->complete_cmd(bp
, f_obj
,
5081 BNX2X_F_CMD_TX_START
))
5083 bnx2x_dcbx_set_params(bp
, BNX2X_DCBX_STATE_TX_RELEASED
);
5086 case EVENT_RING_OPCODE_FUNCTION_UPDATE
:
5087 echo
= elem
->message
.data
.function_update_event
.echo
;
5088 if (echo
== SWITCH_UPDATE
) {
5089 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
5090 "got FUNC_SWITCH_UPDATE ramrod\n");
5091 if (f_obj
->complete_cmd(
5092 bp
, f_obj
, BNX2X_F_CMD_SWITCH_UPDATE
))
5096 DP(BNX2X_MSG_SP
| BNX2X_MSG_MCP
,
5097 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5098 f_obj
->complete_cmd(bp
, f_obj
,
5099 BNX2X_F_CMD_AFEX_UPDATE
);
5101 /* We will perform the Queues update from
5102 * sp_rtnl task as all Queue SP operations
5103 * should run under rtnl_lock.
5105 smp_mb__before_clear_bit();
5106 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE
,
5107 &bp
->sp_rtnl_state
);
5108 smp_mb__after_clear_bit();
5110 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
5115 case EVENT_RING_OPCODE_AFEX_VIF_LISTS
:
5116 f_obj
->complete_cmd(bp
, f_obj
,
5117 BNX2X_F_CMD_AFEX_VIFLISTS
);
5118 bnx2x_after_afex_vif_lists(bp
, elem
);
5120 case EVENT_RING_OPCODE_FUNCTION_START
:
5121 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
5122 "got FUNC_START ramrod\n");
5123 if (f_obj
->complete_cmd(bp
, f_obj
, BNX2X_F_CMD_START
))
5128 case EVENT_RING_OPCODE_FUNCTION_STOP
:
5129 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
5130 "got FUNC_STOP ramrod\n");
5131 if (f_obj
->complete_cmd(bp
, f_obj
, BNX2X_F_CMD_STOP
))
5137 switch (opcode
| bp
->state
) {
5138 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES
|
5140 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES
|
5141 BNX2X_STATE_OPENING_WAIT4_PORT
):
5142 cid
= elem
->message
.data
.eth_event
.echo
&
5144 DP(BNX2X_MSG_SP
, "got RSS_UPDATE ramrod. CID %d\n",
5146 rss_raw
->clear_pending(rss_raw
);
5149 case (EVENT_RING_OPCODE_SET_MAC
| BNX2X_STATE_OPEN
):
5150 case (EVENT_RING_OPCODE_SET_MAC
| BNX2X_STATE_DIAG
):
5151 case (EVENT_RING_OPCODE_SET_MAC
|
5152 BNX2X_STATE_CLOSING_WAIT4_HALT
):
5153 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
5155 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
5157 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
5158 BNX2X_STATE_CLOSING_WAIT4_HALT
):
5159 DP(BNX2X_MSG_SP
, "got (un)set mac ramrod\n");
5160 bnx2x_handle_classification_eqe(bp
, elem
);
5163 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
5165 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
5167 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
5168 BNX2X_STATE_CLOSING_WAIT4_HALT
):
5169 DP(BNX2X_MSG_SP
, "got mcast ramrod\n");
5170 bnx2x_handle_mcast_eqe(bp
);
5173 case (EVENT_RING_OPCODE_FILTERS_RULES
|
5175 case (EVENT_RING_OPCODE_FILTERS_RULES
|
5177 case (EVENT_RING_OPCODE_FILTERS_RULES
|
5178 BNX2X_STATE_CLOSING_WAIT4_HALT
):
5179 DP(BNX2X_MSG_SP
, "got rx_mode ramrod\n");
5180 bnx2x_handle_rx_mode_eqe(bp
);
5183 /* unknown event log error and continue */
5184 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5185 elem
->message
.opcode
, bp
->state
);
5191 smp_mb__before_atomic_inc();
5192 atomic_add(spqe_cnt
, &bp
->eq_spq_left
);
5194 bp
->eq_cons
= sw_cons
;
5195 bp
->eq_prod
= sw_prod
;
5196 /* Make sure that above mem writes were issued towards the memory */
5199 /* update producer */
5200 bnx2x_update_eq_prod(bp
, bp
->eq_prod
);
5203 static void bnx2x_sp_task(struct work_struct
*work
)
5205 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, sp_task
.work
);
5207 DP(BNX2X_MSG_SP
, "sp task invoked\n");
5209 /* make sure the atomic interupt_occurred has been written */
5211 if (atomic_read(&bp
->interrupt_occurred
)) {
5213 /* what work needs to be performed? */
5214 u16 status
= bnx2x_update_dsb_idx(bp
);
5216 DP(BNX2X_MSG_SP
, "status %x\n", status
);
5217 DP(BNX2X_MSG_SP
, "setting interrupt_occurred to 0\n");
5218 atomic_set(&bp
->interrupt_occurred
, 0);
5221 if (status
& BNX2X_DEF_SB_ATT_IDX
) {
5223 status
&= ~BNX2X_DEF_SB_ATT_IDX
;
5226 /* SP events: STAT_QUERY and others */
5227 if (status
& BNX2X_DEF_SB_IDX
) {
5228 struct bnx2x_fastpath
*fp
= bnx2x_fcoe_fp(bp
);
5230 if (FCOE_INIT(bp
) &&
5231 (bnx2x_has_rx_work(fp
) || bnx2x_has_tx_work(fp
))) {
5232 /* Prevent local bottom-halves from running as
5233 * we are going to change the local NAPI list.
5236 napi_schedule(&bnx2x_fcoe(bp
, napi
));
5240 /* Handle EQ completions */
5242 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
,
5243 le16_to_cpu(bp
->def_idx
), IGU_INT_NOP
, 1);
5245 status
&= ~BNX2X_DEF_SB_IDX
;
5248 /* if status is non zero then perhaps something went wrong */
5249 if (unlikely(status
))
5251 "got an unknown interrupt! (status 0x%x)\n", status
);
5253 /* ack status block only if something was actually handled */
5254 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, ATTENTION_ID
,
5255 le16_to_cpu(bp
->def_att_idx
), IGU_INT_ENABLE
, 1);
5259 /* must be called after the EQ processing (since eq leads to sriov
5260 * ramrod completion flows).
5261 * This flow may have been scheduled by the arrival of a ramrod
5262 * completion, or by the sriov code rescheduling itself.
5264 bnx2x_iov_sp_task(bp
);
5266 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5267 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK
,
5269 bnx2x_link_report(bp
);
5270 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
5274 irqreturn_t
bnx2x_msix_sp_int(int irq
, void *dev_instance
)
5276 struct net_device
*dev
= dev_instance
;
5277 struct bnx2x
*bp
= netdev_priv(dev
);
5279 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
, 0,
5280 IGU_INT_DISABLE
, 0);
5282 #ifdef BNX2X_STOP_ON_ERROR
5283 if (unlikely(bp
->panic
))
5287 if (CNIC_LOADED(bp
)) {
5288 struct cnic_ops
*c_ops
;
5291 c_ops
= rcu_dereference(bp
->cnic_ops
);
5293 c_ops
->cnic_handler(bp
->cnic_data
, NULL
);
5297 /* schedule sp task to perform default status block work, ack
5298 * attentions and enable interrupts.
5300 bnx2x_schedule_sp_task(bp
);
5305 /* end of slow path */
5308 void bnx2x_drv_pulse(struct bnx2x
*bp
)
5310 SHMEM_WR(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_pulse_mb
,
5311 bp
->fw_drv_pulse_wr_seq
);
5314 static void bnx2x_timer(unsigned long data
)
5316 struct bnx2x
*bp
= (struct bnx2x
*) data
;
5318 if (!netif_running(bp
->dev
))
5323 int mb_idx
= BP_FW_MB_IDX(bp
);
5327 ++bp
->fw_drv_pulse_wr_seq
;
5328 bp
->fw_drv_pulse_wr_seq
&= DRV_PULSE_SEQ_MASK
;
5329 /* TBD - add SYSTEM_TIME */
5330 drv_pulse
= bp
->fw_drv_pulse_wr_seq
;
5331 bnx2x_drv_pulse(bp
);
5333 mcp_pulse
= (SHMEM_RD(bp
, func_mb
[mb_idx
].mcp_pulse_mb
) &
5334 MCP_PULSE_SEQ_MASK
);
5335 /* The delta between driver pulse and mcp response
5336 * should be 1 (before mcp response) or 0 (after mcp response)
5338 if ((drv_pulse
!= mcp_pulse
) &&
5339 (drv_pulse
!= ((mcp_pulse
+ 1) & MCP_PULSE_SEQ_MASK
))) {
5340 /* someone lost a heartbeat... */
5341 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5342 drv_pulse
, mcp_pulse
);
5346 if (bp
->state
== BNX2X_STATE_OPEN
)
5347 bnx2x_stats_handle(bp
, STATS_EVENT_UPDATE
);
5349 /* sample pf vf bulletin board for new posts from pf */
5351 bnx2x_sample_bulletin(bp
);
5353 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
5356 /* end of Statistics */
5361 * nic init service functions
5364 static void bnx2x_fill(struct bnx2x
*bp
, u32 addr
, int fill
, u32 len
)
5367 if (!(len
%4) && !(addr
%4))
5368 for (i
= 0; i
< len
; i
+= 4)
5369 REG_WR(bp
, addr
+ i
, fill
);
5371 for (i
= 0; i
< len
; i
++)
5372 REG_WR8(bp
, addr
+ i
, fill
);
5376 /* helper: writes FP SP data to FW - data_size in dwords */
5377 static void bnx2x_wr_fp_sb_data(struct bnx2x
*bp
,
5383 for (index
= 0; index
< data_size
; index
++)
5384 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
5385 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id
) +
5387 *(sb_data_p
+ index
));
5390 static void bnx2x_zero_fp_sb(struct bnx2x
*bp
, int fw_sb_id
)
5394 struct hc_status_block_data_e2 sb_data_e2
;
5395 struct hc_status_block_data_e1x sb_data_e1x
;
5397 /* disable the function first */
5398 if (!CHIP_IS_E1x(bp
)) {
5399 memset(&sb_data_e2
, 0, sizeof(struct hc_status_block_data_e2
));
5400 sb_data_e2
.common
.state
= SB_DISABLED
;
5401 sb_data_e2
.common
.p_func
.vf_valid
= false;
5402 sb_data_p
= (u32
*)&sb_data_e2
;
5403 data_size
= sizeof(struct hc_status_block_data_e2
)/sizeof(u32
);
5405 memset(&sb_data_e1x
, 0,
5406 sizeof(struct hc_status_block_data_e1x
));
5407 sb_data_e1x
.common
.state
= SB_DISABLED
;
5408 sb_data_e1x
.common
.p_func
.vf_valid
= false;
5409 sb_data_p
= (u32
*)&sb_data_e1x
;
5410 data_size
= sizeof(struct hc_status_block_data_e1x
)/sizeof(u32
);
5412 bnx2x_wr_fp_sb_data(bp
, fw_sb_id
, sb_data_p
, data_size
);
5414 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5415 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id
), 0,
5416 CSTORM_STATUS_BLOCK_SIZE
);
5417 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5418 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id
), 0,
5419 CSTORM_SYNC_BLOCK_SIZE
);
5422 /* helper: writes SP SB data to FW */
5423 static void bnx2x_wr_sp_sb_data(struct bnx2x
*bp
,
5424 struct hc_sp_status_block_data
*sp_sb_data
)
5426 int func
= BP_FUNC(bp
);
5428 for (i
= 0; i
< sizeof(struct hc_sp_status_block_data
)/sizeof(u32
); i
++)
5429 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
5430 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func
) +
5432 *((u32
*)sp_sb_data
+ i
));
5435 static void bnx2x_zero_sp_sb(struct bnx2x
*bp
)
5437 int func
= BP_FUNC(bp
);
5438 struct hc_sp_status_block_data sp_sb_data
;
5439 memset(&sp_sb_data
, 0, sizeof(struct hc_sp_status_block_data
));
5441 sp_sb_data
.state
= SB_DISABLED
;
5442 sp_sb_data
.p_func
.vf_valid
= false;
5444 bnx2x_wr_sp_sb_data(bp
, &sp_sb_data
);
5446 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5447 CSTORM_SP_STATUS_BLOCK_OFFSET(func
), 0,
5448 CSTORM_SP_STATUS_BLOCK_SIZE
);
5449 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5450 CSTORM_SP_SYNC_BLOCK_OFFSET(func
), 0,
5451 CSTORM_SP_SYNC_BLOCK_SIZE
);
5456 static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm
*hc_sm
,
5457 int igu_sb_id
, int igu_seg_id
)
5459 hc_sm
->igu_sb_id
= igu_sb_id
;
5460 hc_sm
->igu_seg_id
= igu_seg_id
;
5461 hc_sm
->timer_value
= 0xFF;
5462 hc_sm
->time_to_expire
= 0xFFFFFFFF;
5466 /* allocates state machine ids. */
5467 static void bnx2x_map_sb_state_machines(struct hc_index_data
*index_data
)
5469 /* zero out state machine indices */
5471 index_data
[HC_INDEX_ETH_RX_CQ_CONS
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5474 index_data
[HC_INDEX_OOO_TX_CQ_CONS
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5475 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS0
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5476 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS1
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5477 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS2
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5481 index_data
[HC_INDEX_ETH_RX_CQ_CONS
].flags
|=
5482 SM_RX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5485 index_data
[HC_INDEX_OOO_TX_CQ_CONS
].flags
|=
5486 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5487 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS0
].flags
|=
5488 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5489 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS1
].flags
|=
5490 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5491 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS2
].flags
|=
5492 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5495 void bnx2x_init_sb(struct bnx2x
*bp
, dma_addr_t mapping
, int vfid
,
5496 u8 vf_valid
, int fw_sb_id
, int igu_sb_id
)
5500 struct hc_status_block_data_e2 sb_data_e2
;
5501 struct hc_status_block_data_e1x sb_data_e1x
;
5502 struct hc_status_block_sm
*hc_sm_p
;
5506 if (CHIP_INT_MODE_IS_BC(bp
))
5507 igu_seg_id
= HC_SEG_ACCESS_NORM
;
5509 igu_seg_id
= IGU_SEG_ACCESS_NORM
;
5511 bnx2x_zero_fp_sb(bp
, fw_sb_id
);
5513 if (!CHIP_IS_E1x(bp
)) {
5514 memset(&sb_data_e2
, 0, sizeof(struct hc_status_block_data_e2
));
5515 sb_data_e2
.common
.state
= SB_ENABLED
;
5516 sb_data_e2
.common
.p_func
.pf_id
= BP_FUNC(bp
);
5517 sb_data_e2
.common
.p_func
.vf_id
= vfid
;
5518 sb_data_e2
.common
.p_func
.vf_valid
= vf_valid
;
5519 sb_data_e2
.common
.p_func
.vnic_id
= BP_VN(bp
);
5520 sb_data_e2
.common
.same_igu_sb_1b
= true;
5521 sb_data_e2
.common
.host_sb_addr
.hi
= U64_HI(mapping
);
5522 sb_data_e2
.common
.host_sb_addr
.lo
= U64_LO(mapping
);
5523 hc_sm_p
= sb_data_e2
.common
.state_machine
;
5524 sb_data_p
= (u32
*)&sb_data_e2
;
5525 data_size
= sizeof(struct hc_status_block_data_e2
)/sizeof(u32
);
5526 bnx2x_map_sb_state_machines(sb_data_e2
.index_data
);
5528 memset(&sb_data_e1x
, 0,
5529 sizeof(struct hc_status_block_data_e1x
));
5530 sb_data_e1x
.common
.state
= SB_ENABLED
;
5531 sb_data_e1x
.common
.p_func
.pf_id
= BP_FUNC(bp
);
5532 sb_data_e1x
.common
.p_func
.vf_id
= 0xff;
5533 sb_data_e1x
.common
.p_func
.vf_valid
= false;
5534 sb_data_e1x
.common
.p_func
.vnic_id
= BP_VN(bp
);
5535 sb_data_e1x
.common
.same_igu_sb_1b
= true;
5536 sb_data_e1x
.common
.host_sb_addr
.hi
= U64_HI(mapping
);
5537 sb_data_e1x
.common
.host_sb_addr
.lo
= U64_LO(mapping
);
5538 hc_sm_p
= sb_data_e1x
.common
.state_machine
;
5539 sb_data_p
= (u32
*)&sb_data_e1x
;
5540 data_size
= sizeof(struct hc_status_block_data_e1x
)/sizeof(u32
);
5541 bnx2x_map_sb_state_machines(sb_data_e1x
.index_data
);
5544 bnx2x_setup_ndsb_state_machine(&hc_sm_p
[SM_RX_ID
],
5545 igu_sb_id
, igu_seg_id
);
5546 bnx2x_setup_ndsb_state_machine(&hc_sm_p
[SM_TX_ID
],
5547 igu_sb_id
, igu_seg_id
);
5549 DP(NETIF_MSG_IFUP
, "Init FW SB %d\n", fw_sb_id
);
5551 /* write indices to HW - PCI guarantees endianity of regpairs */
5552 bnx2x_wr_fp_sb_data(bp
, fw_sb_id
, sb_data_p
, data_size
);
5555 static void bnx2x_update_coalesce_sb(struct bnx2x
*bp
, u8 fw_sb_id
,
5556 u16 tx_usec
, u16 rx_usec
)
5558 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
, HC_INDEX_ETH_RX_CQ_CONS
,
5560 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5561 HC_INDEX_ETH_TX_CQ_CONS_COS0
, false,
5563 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5564 HC_INDEX_ETH_TX_CQ_CONS_COS1
, false,
5566 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5567 HC_INDEX_ETH_TX_CQ_CONS_COS2
, false,
5571 static void bnx2x_init_def_sb(struct bnx2x
*bp
)
5573 struct host_sp_status_block
*def_sb
= bp
->def_status_blk
;
5574 dma_addr_t mapping
= bp
->def_status_blk_mapping
;
5575 int igu_sp_sb_index
;
5577 int port
= BP_PORT(bp
);
5578 int func
= BP_FUNC(bp
);
5579 int reg_offset
, reg_offset_en5
;
5582 struct hc_sp_status_block_data sp_sb_data
;
5583 memset(&sp_sb_data
, 0, sizeof(struct hc_sp_status_block_data
));
5585 if (CHIP_INT_MODE_IS_BC(bp
)) {
5586 igu_sp_sb_index
= DEF_SB_IGU_ID
;
5587 igu_seg_id
= HC_SEG_ACCESS_DEF
;
5589 igu_sp_sb_index
= bp
->igu_dsb_id
;
5590 igu_seg_id
= IGU_SEG_ACCESS_DEF
;
5594 section
= ((u64
)mapping
) + offsetof(struct host_sp_status_block
,
5595 atten_status_block
);
5596 def_sb
->atten_status_block
.status_block_id
= igu_sp_sb_index
;
5600 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
5601 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
5602 reg_offset_en5
= (port
? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0
:
5603 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0
);
5604 for (index
= 0; index
< MAX_DYNAMIC_ATTN_GRPS
; index
++) {
5606 /* take care of sig[0]..sig[4] */
5607 for (sindex
= 0; sindex
< 4; sindex
++)
5608 bp
->attn_group
[index
].sig
[sindex
] =
5609 REG_RD(bp
, reg_offset
+ sindex
*0x4 + 0x10*index
);
5611 if (!CHIP_IS_E1x(bp
))
5613 * enable5 is separate from the rest of the registers,
5614 * and therefore the address skip is 4
5615 * and not 16 between the different groups
5617 bp
->attn_group
[index
].sig
[4] = REG_RD(bp
,
5618 reg_offset_en5
+ 0x4*index
);
5620 bp
->attn_group
[index
].sig
[4] = 0;
5623 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
5624 reg_offset
= (port
? HC_REG_ATTN_MSG1_ADDR_L
:
5625 HC_REG_ATTN_MSG0_ADDR_L
);
5627 REG_WR(bp
, reg_offset
, U64_LO(section
));
5628 REG_WR(bp
, reg_offset
+ 4, U64_HI(section
));
5629 } else if (!CHIP_IS_E1x(bp
)) {
5630 REG_WR(bp
, IGU_REG_ATTN_MSG_ADDR_L
, U64_LO(section
));
5631 REG_WR(bp
, IGU_REG_ATTN_MSG_ADDR_H
, U64_HI(section
));
5634 section
= ((u64
)mapping
) + offsetof(struct host_sp_status_block
,
5637 bnx2x_zero_sp_sb(bp
);
5639 /* PCI guarantees endianity of regpairs */
5640 sp_sb_data
.state
= SB_ENABLED
;
5641 sp_sb_data
.host_sb_addr
.lo
= U64_LO(section
);
5642 sp_sb_data
.host_sb_addr
.hi
= U64_HI(section
);
5643 sp_sb_data
.igu_sb_id
= igu_sp_sb_index
;
5644 sp_sb_data
.igu_seg_id
= igu_seg_id
;
5645 sp_sb_data
.p_func
.pf_id
= func
;
5646 sp_sb_data
.p_func
.vnic_id
= BP_VN(bp
);
5647 sp_sb_data
.p_func
.vf_id
= 0xff;
5649 bnx2x_wr_sp_sb_data(bp
, &sp_sb_data
);
5651 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
, 0, IGU_INT_ENABLE
, 0);
5654 void bnx2x_update_coalesce(struct bnx2x
*bp
)
5658 for_each_eth_queue(bp
, i
)
5659 bnx2x_update_coalesce_sb(bp
, bp
->fp
[i
].fw_sb_id
,
5660 bp
->tx_ticks
, bp
->rx_ticks
);
5663 static void bnx2x_init_sp_ring(struct bnx2x
*bp
)
5665 spin_lock_init(&bp
->spq_lock
);
5666 atomic_set(&bp
->cq_spq_left
, MAX_SPQ_PENDING
);
5668 bp
->spq_prod_idx
= 0;
5669 bp
->dsb_sp_prod
= BNX2X_SP_DSB_INDEX
;
5670 bp
->spq_prod_bd
= bp
->spq
;
5671 bp
->spq_last_bd
= bp
->spq_prod_bd
+ MAX_SP_DESC_CNT
;
5674 static void bnx2x_init_eq_ring(struct bnx2x
*bp
)
5677 for (i
= 1; i
<= NUM_EQ_PAGES
; i
++) {
5678 union event_ring_elem
*elem
=
5679 &bp
->eq_ring
[EQ_DESC_CNT_PAGE
* i
- 1];
5681 elem
->next_page
.addr
.hi
=
5682 cpu_to_le32(U64_HI(bp
->eq_mapping
+
5683 BCM_PAGE_SIZE
* (i
% NUM_EQ_PAGES
)));
5684 elem
->next_page
.addr
.lo
=
5685 cpu_to_le32(U64_LO(bp
->eq_mapping
+
5686 BCM_PAGE_SIZE
*(i
% NUM_EQ_PAGES
)));
5689 bp
->eq_prod
= NUM_EQ_DESC
;
5690 bp
->eq_cons_sb
= BNX2X_EQ_INDEX
;
5691 /* we want a warning message before it gets rought... */
5692 atomic_set(&bp
->eq_spq_left
,
5693 min_t(int, MAX_SP_DESC_CNT
- MAX_SPQ_PENDING
, NUM_EQ_DESC
) - 1);
5696 /* called with netif_addr_lock_bh() */
5697 int bnx2x_set_q_rx_mode(struct bnx2x
*bp
, u8 cl_id
,
5698 unsigned long rx_mode_flags
,
5699 unsigned long rx_accept_flags
,
5700 unsigned long tx_accept_flags
,
5701 unsigned long ramrod_flags
)
5703 struct bnx2x_rx_mode_ramrod_params ramrod_param
;
5706 memset(&ramrod_param
, 0, sizeof(ramrod_param
));
5708 /* Prepare ramrod parameters */
5709 ramrod_param
.cid
= 0;
5710 ramrod_param
.cl_id
= cl_id
;
5711 ramrod_param
.rx_mode_obj
= &bp
->rx_mode_obj
;
5712 ramrod_param
.func_id
= BP_FUNC(bp
);
5714 ramrod_param
.pstate
= &bp
->sp_state
;
5715 ramrod_param
.state
= BNX2X_FILTER_RX_MODE_PENDING
;
5717 ramrod_param
.rdata
= bnx2x_sp(bp
, rx_mode_rdata
);
5718 ramrod_param
.rdata_mapping
= bnx2x_sp_mapping(bp
, rx_mode_rdata
);
5720 set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
);
5722 ramrod_param
.ramrod_flags
= ramrod_flags
;
5723 ramrod_param
.rx_mode_flags
= rx_mode_flags
;
5725 ramrod_param
.rx_accept_flags
= rx_accept_flags
;
5726 ramrod_param
.tx_accept_flags
= tx_accept_flags
;
5728 rc
= bnx2x_config_rx_mode(bp
, &ramrod_param
);
5730 BNX2X_ERR("Set rx_mode %d failed\n", bp
->rx_mode
);
5737 static int bnx2x_fill_accept_flags(struct bnx2x
*bp
, u32 rx_mode
,
5738 unsigned long *rx_accept_flags
,
5739 unsigned long *tx_accept_flags
)
5741 /* Clear the flags first */
5742 *rx_accept_flags
= 0;
5743 *tx_accept_flags
= 0;
5746 case BNX2X_RX_MODE_NONE
:
5748 * 'drop all' supersedes any accept flags that may have been
5749 * passed to the function.
5752 case BNX2X_RX_MODE_NORMAL
:
5753 __set_bit(BNX2X_ACCEPT_UNICAST
, rx_accept_flags
);
5754 __set_bit(BNX2X_ACCEPT_MULTICAST
, rx_accept_flags
);
5755 __set_bit(BNX2X_ACCEPT_BROADCAST
, rx_accept_flags
);
5757 /* internal switching mode */
5758 __set_bit(BNX2X_ACCEPT_UNICAST
, tx_accept_flags
);
5759 __set_bit(BNX2X_ACCEPT_MULTICAST
, tx_accept_flags
);
5760 __set_bit(BNX2X_ACCEPT_BROADCAST
, tx_accept_flags
);
5763 case BNX2X_RX_MODE_ALLMULTI
:
5764 __set_bit(BNX2X_ACCEPT_UNICAST
, rx_accept_flags
);
5765 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, rx_accept_flags
);
5766 __set_bit(BNX2X_ACCEPT_BROADCAST
, rx_accept_flags
);
5768 /* internal switching mode */
5769 __set_bit(BNX2X_ACCEPT_UNICAST
, tx_accept_flags
);
5770 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, tx_accept_flags
);
5771 __set_bit(BNX2X_ACCEPT_BROADCAST
, tx_accept_flags
);
5774 case BNX2X_RX_MODE_PROMISC
:
5775 /* According to deffinition of SI mode, iface in promisc mode
5776 * should receive matched and unmatched (in resolution of port)
5779 __set_bit(BNX2X_ACCEPT_UNMATCHED
, rx_accept_flags
);
5780 __set_bit(BNX2X_ACCEPT_UNICAST
, rx_accept_flags
);
5781 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, rx_accept_flags
);
5782 __set_bit(BNX2X_ACCEPT_BROADCAST
, rx_accept_flags
);
5784 /* internal switching mode */
5785 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, tx_accept_flags
);
5786 __set_bit(BNX2X_ACCEPT_BROADCAST
, tx_accept_flags
);
5789 __set_bit(BNX2X_ACCEPT_ALL_UNICAST
, tx_accept_flags
);
5791 __set_bit(BNX2X_ACCEPT_UNICAST
, tx_accept_flags
);
5795 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode
);
5799 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
5800 if (bp
->rx_mode
!= BNX2X_RX_MODE_NONE
) {
5801 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, rx_accept_flags
);
5802 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, tx_accept_flags
);
5808 /* called with netif_addr_lock_bh() */
5809 int bnx2x_set_storm_rx_mode(struct bnx2x
*bp
)
5811 unsigned long rx_mode_flags
= 0, ramrod_flags
= 0;
5812 unsigned long rx_accept_flags
= 0, tx_accept_flags
= 0;
5816 /* Configure rx_mode of FCoE Queue */
5817 __set_bit(BNX2X_RX_MODE_FCOE_ETH
, &rx_mode_flags
);
5819 rc
= bnx2x_fill_accept_flags(bp
, bp
->rx_mode
, &rx_accept_flags
,
5824 __set_bit(RAMROD_RX
, &ramrod_flags
);
5825 __set_bit(RAMROD_TX
, &ramrod_flags
);
5827 return bnx2x_set_q_rx_mode(bp
, bp
->fp
->cl_id
, rx_mode_flags
,
5828 rx_accept_flags
, tx_accept_flags
,
5832 static void bnx2x_init_internal_common(struct bnx2x
*bp
)
5838 * In switch independent mode, the TSTORM needs to accept
5839 * packets that failed classification, since approximate match
5840 * mac addresses aren't written to NIG LLH
5842 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
5843 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET
, 2);
5844 else if (!CHIP_IS_E1(bp
)) /* 57710 doesn't support MF */
5845 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
5846 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET
, 0);
5848 /* Zero this manually as its initialization is
5849 currently missing in the initTool */
5850 for (i
= 0; i
< (USTORM_AGG_DATA_SIZE
>> 2); i
++)
5851 REG_WR(bp
, BAR_USTRORM_INTMEM
+
5852 USTORM_AGG_DATA_OFFSET
+ i
* 4, 0);
5853 if (!CHIP_IS_E1x(bp
)) {
5854 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_IGU_MODE_OFFSET
,
5855 CHIP_INT_MODE_IS_BC(bp
) ?
5856 HC_IGU_BC_MODE
: HC_IGU_NBC_MODE
);
5860 static void bnx2x_init_internal(struct bnx2x
*bp
, u32 load_code
)
5862 switch (load_code
) {
5863 case FW_MSG_CODE_DRV_LOAD_COMMON
:
5864 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
:
5865 bnx2x_init_internal_common(bp
);
5868 case FW_MSG_CODE_DRV_LOAD_PORT
:
5872 case FW_MSG_CODE_DRV_LOAD_FUNCTION
:
5873 /* internal memory per function is
5874 initialized inside bnx2x_pf_init */
5878 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code
);
5883 static inline u8
bnx2x_fp_igu_sb_id(struct bnx2x_fastpath
*fp
)
5885 return fp
->bp
->igu_base_sb
+ fp
->index
+ CNIC_SUPPORT(fp
->bp
);
5888 static inline u8
bnx2x_fp_fw_sb_id(struct bnx2x_fastpath
*fp
)
5890 return fp
->bp
->base_fw_ndsb
+ fp
->index
+ CNIC_SUPPORT(fp
->bp
);
5893 static u8
bnx2x_fp_cl_id(struct bnx2x_fastpath
*fp
)
5895 if (CHIP_IS_E1x(fp
->bp
))
5896 return BP_L_ID(fp
->bp
) + fp
->index
;
5897 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5898 return bnx2x_fp_igu_sb_id(fp
);
5901 static void bnx2x_init_eth_fp(struct bnx2x
*bp
, int fp_idx
)
5903 struct bnx2x_fastpath
*fp
= &bp
->fp
[fp_idx
];
5905 unsigned long q_type
= 0;
5906 u32 cids
[BNX2X_MULTI_TX_COS
] = { 0 };
5907 fp
->rx_queue
= fp_idx
;
5909 fp
->cl_id
= bnx2x_fp_cl_id(fp
);
5910 fp
->fw_sb_id
= bnx2x_fp_fw_sb_id(fp
);
5911 fp
->igu_sb_id
= bnx2x_fp_igu_sb_id(fp
);
5912 /* qZone id equals to FW (per path) client id */
5913 fp
->cl_qzone_id
= bnx2x_fp_qzone_id(fp
);
5916 fp
->ustorm_rx_prods_offset
= bnx2x_rx_ustorm_prods_offset(fp
);
5918 /* Setup SB indicies */
5919 fp
->rx_cons_sb
= BNX2X_RX_SB_INDEX
;
5921 /* Configure Queue State object */
5922 __set_bit(BNX2X_Q_TYPE_HAS_RX
, &q_type
);
5923 __set_bit(BNX2X_Q_TYPE_HAS_TX
, &q_type
);
5925 BUG_ON(fp
->max_cos
> BNX2X_MULTI_TX_COS
);
5928 for_each_cos_in_tx_queue(fp
, cos
) {
5929 bnx2x_init_txdata(bp
, fp
->txdata_ptr
[cos
],
5930 CID_COS_TO_TX_ONLY_CID(fp
->cid
, cos
, bp
),
5931 FP_COS_TO_TXQ(fp
, cos
, bp
),
5932 BNX2X_TX_SB_INDEX_BASE
+ cos
, fp
);
5933 cids
[cos
] = fp
->txdata_ptr
[cos
]->cid
;
5936 /* nothing more for vf to do here */
5940 bnx2x_init_sb(bp
, fp
->status_blk_mapping
, BNX2X_VF_ID_INVALID
, false,
5941 fp
->fw_sb_id
, fp
->igu_sb_id
);
5942 bnx2x_update_fpsb_idx(fp
);
5943 bnx2x_init_queue_obj(bp
, &bnx2x_sp_obj(bp
, fp
).q_obj
, fp
->cl_id
, cids
,
5944 fp
->max_cos
, BP_FUNC(bp
), bnx2x_sp(bp
, q_rdata
),
5945 bnx2x_sp_mapping(bp
, q_rdata
), q_type
);
5948 * Configure classification DBs: Always enable Tx switching
5950 bnx2x_init_vlan_mac_fp_objs(fp
, BNX2X_OBJ_TYPE_RX_TX
);
5953 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5954 fp_idx
, bp
, fp
->status_blk
.e2_sb
, fp
->cl_id
, fp
->fw_sb_id
,
5958 static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata
*txdata
)
5962 for (i
= 1; i
<= NUM_TX_RINGS
; i
++) {
5963 struct eth_tx_next_bd
*tx_next_bd
=
5964 &txdata
->tx_desc_ring
[TX_DESC_CNT
* i
- 1].next_bd
;
5966 tx_next_bd
->addr_hi
=
5967 cpu_to_le32(U64_HI(txdata
->tx_desc_mapping
+
5968 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
5969 tx_next_bd
->addr_lo
=
5970 cpu_to_le32(U64_LO(txdata
->tx_desc_mapping
+
5971 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
5974 SET_FLAG(txdata
->tx_db
.data
.header
.header
, DOORBELL_HDR_DB_TYPE
, 1);
5975 txdata
->tx_db
.data
.zero_fill1
= 0;
5976 txdata
->tx_db
.data
.prod
= 0;
5978 txdata
->tx_pkt_prod
= 0;
5979 txdata
->tx_pkt_cons
= 0;
5980 txdata
->tx_bd_prod
= 0;
5981 txdata
->tx_bd_cons
= 0;
5985 static void bnx2x_init_tx_rings_cnic(struct bnx2x
*bp
)
5989 for_each_tx_queue_cnic(bp
, i
)
5990 bnx2x_init_tx_ring_one(bp
->fp
[i
].txdata_ptr
[0]);
5992 static void bnx2x_init_tx_rings(struct bnx2x
*bp
)
5997 for_each_eth_queue(bp
, i
)
5998 for_each_cos_in_tx_queue(&bp
->fp
[i
], cos
)
5999 bnx2x_init_tx_ring_one(bp
->fp
[i
].txdata_ptr
[cos
]);
6002 void bnx2x_nic_init_cnic(struct bnx2x
*bp
)
6005 bnx2x_init_fcoe_fp(bp
);
6007 bnx2x_init_sb(bp
, bp
->cnic_sb_mapping
,
6008 BNX2X_VF_ID_INVALID
, false,
6009 bnx2x_cnic_fw_sb_id(bp
), bnx2x_cnic_igu_sb_id(bp
));
6011 /* ensure status block indices were read */
6013 bnx2x_init_rx_rings_cnic(bp
);
6014 bnx2x_init_tx_rings_cnic(bp
);
6021 void bnx2x_nic_init(struct bnx2x
*bp
, u32 load_code
)
6025 for_each_eth_queue(bp
, i
)
6026 bnx2x_init_eth_fp(bp
, i
);
6028 /* ensure status block indices were read */
6030 bnx2x_init_rx_rings(bp
);
6031 bnx2x_init_tx_rings(bp
);
6036 /* Initialize MOD_ABS interrupts */
6037 bnx2x_init_mod_abs_int(bp
, &bp
->link_vars
, bp
->common
.chip_id
,
6038 bp
->common
.shmem_base
, bp
->common
.shmem2_base
,
6041 bnx2x_init_def_sb(bp
);
6042 bnx2x_update_dsb_idx(bp
);
6043 bnx2x_init_sp_ring(bp
);
6044 bnx2x_init_eq_ring(bp
);
6045 bnx2x_init_internal(bp
, load_code
);
6047 bnx2x_stats_init(bp
);
6049 /* flush all before enabling interrupts */
6053 bnx2x_int_enable(bp
);
6055 /* Check for SPIO5 */
6056 bnx2x_attn_int_deasserted0(bp
,
6057 REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+ BP_PORT(bp
)*4) &
6058 AEU_INPUTS_ATTN_BITS_SPIO5
);
6061 /* end of nic init */
6064 * gzip service functions
6067 static int bnx2x_gunzip_init(struct bnx2x
*bp
)
6069 bp
->gunzip_buf
= dma_alloc_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
,
6070 &bp
->gunzip_mapping
, GFP_KERNEL
);
6071 if (bp
->gunzip_buf
== NULL
)
6074 bp
->strm
= kmalloc(sizeof(*bp
->strm
), GFP_KERNEL
);
6075 if (bp
->strm
== NULL
)
6078 bp
->strm
->workspace
= vmalloc(zlib_inflate_workspacesize());
6079 if (bp
->strm
->workspace
== NULL
)
6089 dma_free_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
6090 bp
->gunzip_mapping
);
6091 bp
->gunzip_buf
= NULL
;
6094 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
6098 static void bnx2x_gunzip_end(struct bnx2x
*bp
)
6101 vfree(bp
->strm
->workspace
);
6106 if (bp
->gunzip_buf
) {
6107 dma_free_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
6108 bp
->gunzip_mapping
);
6109 bp
->gunzip_buf
= NULL
;
6113 static int bnx2x_gunzip(struct bnx2x
*bp
, const u8
*zbuf
, int len
)
6117 /* check gzip header */
6118 if ((zbuf
[0] != 0x1f) || (zbuf
[1] != 0x8b) || (zbuf
[2] != Z_DEFLATED
)) {
6119 BNX2X_ERR("Bad gzip header\n");
6127 if (zbuf
[3] & FNAME
)
6128 while ((zbuf
[n
++] != 0) && (n
< len
));
6130 bp
->strm
->next_in
= (typeof(bp
->strm
->next_in
))zbuf
+ n
;
6131 bp
->strm
->avail_in
= len
- n
;
6132 bp
->strm
->next_out
= bp
->gunzip_buf
;
6133 bp
->strm
->avail_out
= FW_BUF_SIZE
;
6135 rc
= zlib_inflateInit2(bp
->strm
, -MAX_WBITS
);
6139 rc
= zlib_inflate(bp
->strm
, Z_FINISH
);
6140 if ((rc
!= Z_OK
) && (rc
!= Z_STREAM_END
))
6141 netdev_err(bp
->dev
, "Firmware decompression error: %s\n",
6144 bp
->gunzip_outlen
= (FW_BUF_SIZE
- bp
->strm
->avail_out
);
6145 if (bp
->gunzip_outlen
& 0x3)
6147 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
6149 bp
->gunzip_outlen
>>= 2;
6151 zlib_inflateEnd(bp
->strm
);
6153 if (rc
== Z_STREAM_END
)
6159 /* nic load/unload */
6162 * General service functions
6165 /* send a NIG loopback debug packet */
6166 static void bnx2x_lb_pckt(struct bnx2x
*bp
)
6170 /* Ethernet source and destination addresses */
6171 wb_write
[0] = 0x55555555;
6172 wb_write
[1] = 0x55555555;
6173 wb_write
[2] = 0x20; /* SOP */
6174 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
6176 /* NON-IP protocol */
6177 wb_write
[0] = 0x09000000;
6178 wb_write
[1] = 0x55555555;
6179 wb_write
[2] = 0x10; /* EOP, eop_bvalid = 0 */
6180 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
6183 /* some of the internal memories
6184 * are not directly readable from the driver
6185 * to test them we send debug packets
6187 static int bnx2x_int_mem_test(struct bnx2x
*bp
)
6193 if (CHIP_REV_IS_FPGA(bp
))
6195 else if (CHIP_REV_IS_EMUL(bp
))
6200 /* Disable inputs of parser neighbor blocks */
6201 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
6202 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
6203 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
6204 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x0);
6206 /* Write 0 to parser credits for CFC search request */
6207 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
6209 /* send Ethernet packet */
6212 /* TODO do i reset NIG statistic? */
6213 /* Wait until NIG register shows 1 packet of size 0x10 */
6214 count
= 1000 * factor
;
6217 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
6218 val
= *bnx2x_sp(bp
, wb_data
[0]);
6226 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
6230 /* Wait until PRS register shows 1 packet */
6231 count
= 1000 * factor
;
6233 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
6241 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6245 /* Reset and init BRB, PRS */
6246 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x03);
6248 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x03);
6250 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6251 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6253 DP(NETIF_MSG_HW
, "part2\n");
6255 /* Disable inputs of parser neighbor blocks */
6256 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
6257 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
6258 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
6259 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x0);
6261 /* Write 0 to parser credits for CFC search request */
6262 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
6264 /* send 10 Ethernet packets */
6265 for (i
= 0; i
< 10; i
++)
6268 /* Wait until NIG register shows 10 + 1
6269 packets of size 11*0x10 = 0xb0 */
6270 count
= 1000 * factor
;
6273 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
6274 val
= *bnx2x_sp(bp
, wb_data
[0]);
6282 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
6286 /* Wait until PRS register shows 2 packets */
6287 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
6289 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6291 /* Write 1 to parser credits for CFC search request */
6292 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x1);
6294 /* Wait until PRS register shows 3 packets */
6295 msleep(10 * factor
);
6296 /* Wait until NIG register shows 1 packet of size 0x10 */
6297 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
6299 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6301 /* clear NIG EOP FIFO */
6302 for (i
= 0; i
< 11; i
++)
6303 REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_FIFO
);
6304 val
= REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_EMPTY
);
6306 BNX2X_ERR("clear of NIG failed\n");
6310 /* Reset and init BRB, PRS, NIG */
6311 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x03);
6313 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x03);
6315 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6316 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6317 if (!CNIC_SUPPORT(bp
))
6319 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
6321 /* Enable inputs of parser neighbor blocks */
6322 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x7fffffff);
6323 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x1);
6324 REG_WR(bp
, CFC_REG_DEBUG0
, 0x0);
6325 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x1);
6327 DP(NETIF_MSG_HW
, "done\n");
6332 static void bnx2x_enable_blocks_attention(struct bnx2x
*bp
)
6336 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
6337 if (!CHIP_IS_E1x(bp
))
6338 REG_WR(bp
, PXP_REG_PXP_INT_MASK_1
, 0x40);
6340 REG_WR(bp
, PXP_REG_PXP_INT_MASK_1
, 0);
6341 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
6342 REG_WR(bp
, CFC_REG_CFC_INT_MASK
, 0);
6344 * mask read length error interrupts in brb for parser
6345 * (parsing unit and 'checksum and crc' unit)
6346 * these errors are legal (PU reads fixed length and CAC can cause
6347 * read length error on truncated packets)
6349 REG_WR(bp
, BRB1_REG_BRB1_INT_MASK
, 0xFC00);
6350 REG_WR(bp
, QM_REG_QM_INT_MASK
, 0);
6351 REG_WR(bp
, TM_REG_TM_INT_MASK
, 0);
6352 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_0
, 0);
6353 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_1
, 0);
6354 REG_WR(bp
, XCM_REG_XCM_INT_MASK
, 0);
6355 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6356 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
6357 REG_WR(bp
, USDM_REG_USDM_INT_MASK_0
, 0);
6358 REG_WR(bp
, USDM_REG_USDM_INT_MASK_1
, 0);
6359 REG_WR(bp
, UCM_REG_UCM_INT_MASK
, 0);
6360 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6361 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
6362 REG_WR(bp
, GRCBASE_UPB
+ PB_REG_PB_INT_MASK
, 0);
6363 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_0
, 0);
6364 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_1
, 0);
6365 REG_WR(bp
, CCM_REG_CCM_INT_MASK
, 0);
6366 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6367 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
6369 val
= PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
|
6370 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
|
6371 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
;
6372 if (!CHIP_IS_E1x(bp
))
6373 val
|= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
|
6374 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED
;
6375 REG_WR(bp
, PXP2_REG_PXP2_INT_MASK_0
, val
);
6377 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_0
, 0);
6378 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_1
, 0);
6379 REG_WR(bp
, TCM_REG_TCM_INT_MASK
, 0);
6380 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
6382 if (!CHIP_IS_E1x(bp
))
6383 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6384 REG_WR(bp
, TSEM_REG_TSEM_INT_MASK_1
, 0x07ff);
6386 REG_WR(bp
, CDU_REG_CDU_INT_MASK
, 0);
6387 REG_WR(bp
, DMAE_REG_DMAE_INT_MASK
, 0);
6388 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
6389 REG_WR(bp
, PBF_REG_PBF_INT_MASK
, 0x18); /* bit 3,4 masked */
6392 static void bnx2x_reset_common(struct bnx2x
*bp
)
6397 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
6400 if (CHIP_IS_E3(bp
)) {
6401 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT0
;
6402 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT1
;
6405 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
, val
);
6408 static void bnx2x_setup_dmae(struct bnx2x
*bp
)
6411 spin_lock_init(&bp
->dmae_lock
);
6414 static void bnx2x_init_pxp(struct bnx2x
*bp
)
6417 int r_order
, w_order
;
6419 pcie_capability_read_word(bp
->pdev
, PCI_EXP_DEVCTL
, &devctl
);
6420 DP(NETIF_MSG_HW
, "read 0x%x from devctl\n", devctl
);
6421 w_order
= ((devctl
& PCI_EXP_DEVCTL_PAYLOAD
) >> 5);
6423 r_order
= ((devctl
& PCI_EXP_DEVCTL_READRQ
) >> 12);
6425 DP(NETIF_MSG_HW
, "force read order to %d\n", bp
->mrrs
);
6429 bnx2x_init_pxp_arb(bp
, r_order
, w_order
);
6432 static void bnx2x_setup_fan_failure_detection(struct bnx2x
*bp
)
6442 val
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.config2
) &
6443 SHARED_HW_CFG_FAN_FAILURE_MASK
;
6445 if (val
== SHARED_HW_CFG_FAN_FAILURE_ENABLED
)
6449 * The fan failure mechanism is usually related to the PHY type since
6450 * the power consumption of the board is affected by the PHY. Currently,
6451 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6453 else if (val
== SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE
)
6454 for (port
= PORT_0
; port
< PORT_MAX
; port
++) {
6456 bnx2x_fan_failure_det_req(
6458 bp
->common
.shmem_base
,
6459 bp
->common
.shmem2_base
,
6463 DP(NETIF_MSG_HW
, "fan detection setting: %d\n", is_required
);
6465 if (is_required
== 0)
6468 /* Fan failure is indicated by SPIO 5 */
6469 bnx2x_set_spio(bp
, MISC_SPIO_SPIO5
, MISC_SPIO_INPUT_HI_Z
);
6471 /* set to active low mode */
6472 val
= REG_RD(bp
, MISC_REG_SPIO_INT
);
6473 val
|= (MISC_SPIO_SPIO5
<< MISC_SPIO_INT_OLD_SET_POS
);
6474 REG_WR(bp
, MISC_REG_SPIO_INT
, val
);
6476 /* enable interrupt to signal the IGU */
6477 val
= REG_RD(bp
, MISC_REG_SPIO_EVENT_EN
);
6478 val
|= MISC_SPIO_SPIO5
;
6479 REG_WR(bp
, MISC_REG_SPIO_EVENT_EN
, val
);
6482 void bnx2x_pf_disable(struct bnx2x
*bp
)
6484 u32 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
6485 val
&= ~IGU_PF_CONF_FUNC_EN
;
6487 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
6488 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 0);
6489 REG_WR(bp
, CFC_REG_WEAK_ENABLE_PF
, 0);
6492 static void bnx2x__common_init_phy(struct bnx2x
*bp
)
6494 u32 shmem_base
[2], shmem2_base
[2];
6495 /* Avoid common init in case MFW supports LFA */
6496 if (SHMEM2_RD(bp
, size
) >
6497 (u32
)offsetof(struct shmem2_region
, lfa_host_addr
[BP_PORT(bp
)]))
6499 shmem_base
[0] = bp
->common
.shmem_base
;
6500 shmem2_base
[0] = bp
->common
.shmem2_base
;
6501 if (!CHIP_IS_E1x(bp
)) {
6503 SHMEM2_RD(bp
, other_shmem_base_addr
);
6505 SHMEM2_RD(bp
, other_shmem2_base_addr
);
6507 bnx2x_acquire_phy_lock(bp
);
6508 bnx2x_common_init_phy(bp
, shmem_base
, shmem2_base
,
6509 bp
->common
.chip_id
);
6510 bnx2x_release_phy_lock(bp
);
6514 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6516 * @bp: driver handle
6518 static int bnx2x_init_hw_common(struct bnx2x
*bp
)
6522 DP(NETIF_MSG_HW
, "starting common init func %d\n", BP_ABS_FUNC(bp
));
6525 * take the RESET lock to protect undi_unload flow from accessing
6526 * registers while we're resetting the chip
6528 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
6530 bnx2x_reset_common(bp
);
6531 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0xffffffff);
6534 if (CHIP_IS_E3(bp
)) {
6535 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT0
;
6536 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT1
;
6538 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
, val
);
6540 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
6542 bnx2x_init_block(bp
, BLOCK_MISC
, PHASE_COMMON
);
6544 if (!CHIP_IS_E1x(bp
)) {
6548 * 4-port mode or 2-port mode we need to turn of master-enable
6549 * for everyone, after that, turn it back on for self.
6550 * so, we disregard multi-function or not, and always disable
6551 * for all functions on the given path, this means 0,2,4,6 for
6552 * path 0 and 1,3,5,7 for path 1
6554 for (abs_func_id
= BP_PATH(bp
);
6555 abs_func_id
< E2_FUNC_MAX
*2; abs_func_id
+= 2) {
6556 if (abs_func_id
== BP_ABS_FUNC(bp
)) {
6558 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
,
6563 bnx2x_pretend_func(bp
, abs_func_id
);
6564 /* clear pf enable */
6565 bnx2x_pf_disable(bp
);
6566 bnx2x_pretend_func(bp
, BP_ABS_FUNC(bp
));
6570 bnx2x_init_block(bp
, BLOCK_PXP
, PHASE_COMMON
);
6571 if (CHIP_IS_E1(bp
)) {
6572 /* enable HW interrupt from PXP on USDM overflow
6573 bit 16 on INT_MASK_0 */
6574 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
6577 bnx2x_init_block(bp
, BLOCK_PXP2
, PHASE_COMMON
);
6581 REG_WR(bp
, PXP2_REG_RQ_QM_ENDIAN_M
, 1);
6582 REG_WR(bp
, PXP2_REG_RQ_TM_ENDIAN_M
, 1);
6583 REG_WR(bp
, PXP2_REG_RQ_SRC_ENDIAN_M
, 1);
6584 REG_WR(bp
, PXP2_REG_RQ_CDU_ENDIAN_M
, 1);
6585 REG_WR(bp
, PXP2_REG_RQ_DBG_ENDIAN_M
, 1);
6586 /* make sure this value is 0 */
6587 REG_WR(bp
, PXP2_REG_RQ_HC_ENDIAN_M
, 0);
6589 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6590 REG_WR(bp
, PXP2_REG_RD_QM_SWAP_MODE
, 1);
6591 REG_WR(bp
, PXP2_REG_RD_TM_SWAP_MODE
, 1);
6592 REG_WR(bp
, PXP2_REG_RD_SRC_SWAP_MODE
, 1);
6593 REG_WR(bp
, PXP2_REG_RD_CDURD_SWAP_MODE
, 1);
6596 bnx2x_ilt_init_page_size(bp
, INITOP_SET
);
6598 if (CHIP_REV_IS_FPGA(bp
) && CHIP_IS_E1H(bp
))
6599 REG_WR(bp
, PXP2_REG_PGL_TAGS_LIMIT
, 0x1);
6601 /* let the HW do it's magic ... */
6603 /* finish PXP init */
6604 val
= REG_RD(bp
, PXP2_REG_RQ_CFG_DONE
);
6606 BNX2X_ERR("PXP2 CFG failed\n");
6609 val
= REG_RD(bp
, PXP2_REG_RD_INIT_DONE
);
6611 BNX2X_ERR("PXP2 RD_INIT failed\n");
6615 /* Timers bug workaround E2 only. We need to set the entire ILT to
6616 * have entries with value "0" and valid bit on.
6617 * This needs to be done by the first PF that is loaded in a path
6618 * (i.e. common phase)
6620 if (!CHIP_IS_E1x(bp
)) {
6621 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6622 * (i.e. vnic3) to start even if it is marked as "scan-off".
6623 * This occurs when a different function (func2,3) is being marked
6624 * as "scan-off". Real-life scenario for example: if a driver is being
6625 * load-unloaded while func6,7 are down. This will cause the timer to access
6626 * the ilt, translate to a logical address and send a request to read/write.
6627 * Since the ilt for the function that is down is not valid, this will cause
6628 * a translation error which is unrecoverable.
6629 * The Workaround is intended to make sure that when this happens nothing fatal
6630 * will occur. The workaround:
6631 * 1. First PF driver which loads on a path will:
6632 * a. After taking the chip out of reset, by using pretend,
6633 * it will write "0" to the following registers of
6635 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6636 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6637 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6638 * And for itself it will write '1' to
6639 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6640 * dmae-operations (writing to pram for example.)
6641 * note: can be done for only function 6,7 but cleaner this
6643 * b. Write zero+valid to the entire ILT.
6644 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6645 * VNIC3 (of that port). The range allocated will be the
6646 * entire ILT. This is needed to prevent ILT range error.
6647 * 2. Any PF driver load flow:
6648 * a. ILT update with the physical addresses of the allocated
6650 * b. Wait 20msec. - note that this timeout is needed to make
6651 * sure there are no requests in one of the PXP internal
6652 * queues with "old" ILT addresses.
6653 * c. PF enable in the PGLC.
6654 * d. Clear the was_error of the PF in the PGLC. (could have
6655 * occurred while driver was down)
6656 * e. PF enable in the CFC (WEAK + STRONG)
6657 * f. Timers scan enable
6658 * 3. PF driver unload flow:
6659 * a. Clear the Timers scan_en.
6660 * b. Polling for scan_on=0 for that PF.
6661 * c. Clear the PF enable bit in the PXP.
6662 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6663 * e. Write zero+valid to all ILT entries (The valid bit must
6665 * f. If this is VNIC 3 of a port then also init
6666 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6667 * to the last enrty in the ILT.
6670 * Currently the PF error in the PGLC is non recoverable.
6671 * In the future the there will be a recovery routine for this error.
6672 * Currently attention is masked.
6673 * Having an MCP lock on the load/unload process does not guarantee that
6674 * there is no Timer disable during Func6/7 enable. This is because the
6675 * Timers scan is currently being cleared by the MCP on FLR.
6676 * Step 2.d can be done only for PF6/7 and the driver can also check if
6677 * there is error before clearing it. But the flow above is simpler and
6679 * All ILT entries are written by zero+valid and not just PF6/7
6680 * ILT entries since in the future the ILT entries allocation for
6681 * PF-s might be dynamic.
6683 struct ilt_client_info ilt_cli
;
6684 struct bnx2x_ilt ilt
;
6685 memset(&ilt_cli
, 0, sizeof(struct ilt_client_info
));
6686 memset(&ilt
, 0, sizeof(struct bnx2x_ilt
));
6688 /* initialize dummy TM client */
6690 ilt_cli
.end
= ILT_NUM_PAGE_ENTRIES
- 1;
6691 ilt_cli
.client_num
= ILT_CLIENT_TM
;
6693 /* Step 1: set zeroes to all ilt page entries with valid bit on
6694 * Step 2: set the timers first/last ilt entry to point
6695 * to the entire range to prevent ILT range error for 3rd/4th
6696 * vnic (this code assumes existence of the vnic)
6698 * both steps performed by call to bnx2x_ilt_client_init_op()
6699 * with dummy TM client
6701 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6702 * and his brother are split registers
6704 bnx2x_pretend_func(bp
, (BP_PATH(bp
) + 6));
6705 bnx2x_ilt_client_init_op_ilt(bp
, &ilt
, &ilt_cli
, INITOP_CLEAR
);
6706 bnx2x_pretend_func(bp
, BP_ABS_FUNC(bp
));
6708 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN
, BNX2X_PXP_DRAM_ALIGN
);
6709 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN_RD
, BNX2X_PXP_DRAM_ALIGN
);
6710 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN_SEL
, 1);
6713 REG_WR(bp
, PXP2_REG_RQ_DISABLE_INPUTS
, 0);
6714 REG_WR(bp
, PXP2_REG_RD_DISABLE_INPUTS
, 0);
6716 if (!CHIP_IS_E1x(bp
)) {
6717 int factor
= CHIP_REV_IS_EMUL(bp
) ? 1000 :
6718 (CHIP_REV_IS_FPGA(bp
) ? 400 : 0);
6719 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, PHASE_COMMON
);
6721 bnx2x_init_block(bp
, BLOCK_ATC
, PHASE_COMMON
);
6723 /* let the HW do it's magic ... */
6726 val
= REG_RD(bp
, ATC_REG_ATC_INIT_DONE
);
6727 } while (factor
-- && (val
!= 1));
6730 BNX2X_ERR("ATC_INIT failed\n");
6735 bnx2x_init_block(bp
, BLOCK_DMAE
, PHASE_COMMON
);
6737 bnx2x_iov_init_dmae(bp
);
6739 /* clean the DMAE memory */
6741 bnx2x_init_fill(bp
, TSEM_REG_PRAM
, 0, 8, 1);
6743 bnx2x_init_block(bp
, BLOCK_TCM
, PHASE_COMMON
);
6745 bnx2x_init_block(bp
, BLOCK_UCM
, PHASE_COMMON
);
6747 bnx2x_init_block(bp
, BLOCK_CCM
, PHASE_COMMON
);
6749 bnx2x_init_block(bp
, BLOCK_XCM
, PHASE_COMMON
);
6751 bnx2x_read_dmae(bp
, XSEM_REG_PASSIVE_BUFFER
, 3);
6752 bnx2x_read_dmae(bp
, CSEM_REG_PASSIVE_BUFFER
, 3);
6753 bnx2x_read_dmae(bp
, TSEM_REG_PASSIVE_BUFFER
, 3);
6754 bnx2x_read_dmae(bp
, USEM_REG_PASSIVE_BUFFER
, 3);
6756 bnx2x_init_block(bp
, BLOCK_QM
, PHASE_COMMON
);
6759 /* QM queues pointers table */
6760 bnx2x_qm_init_ptr_table(bp
, bp
->qm_cid_count
, INITOP_SET
);
6762 /* soft reset pulse */
6763 REG_WR(bp
, QM_REG_SOFT_RESET
, 1);
6764 REG_WR(bp
, QM_REG_SOFT_RESET
, 0);
6766 if (CNIC_SUPPORT(bp
))
6767 bnx2x_init_block(bp
, BLOCK_TM
, PHASE_COMMON
);
6769 bnx2x_init_block(bp
, BLOCK_DORQ
, PHASE_COMMON
);
6770 REG_WR(bp
, DORQ_REG_DPM_CID_OFST
, BNX2X_DB_SHIFT
);
6771 if (!CHIP_REV_IS_SLOW(bp
))
6772 /* enable hw interrupt from doorbell Q */
6773 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
6775 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6777 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6778 REG_WR(bp
, PRS_REG_A_PRSU_20
, 0xf);
6780 if (!CHIP_IS_E1(bp
))
6781 REG_WR(bp
, PRS_REG_E1HOV_MODE
, bp
->path_has_ovlan
);
6783 if (!CHIP_IS_E1x(bp
) && !CHIP_IS_E3B0(bp
)) {
6784 if (IS_MF_AFEX(bp
)) {
6785 /* configure that VNTag and VLAN headers must be
6786 * received in afex mode
6788 REG_WR(bp
, PRS_REG_HDRS_AFTER_BASIC
, 0xE);
6789 REG_WR(bp
, PRS_REG_MUST_HAVE_HDRS
, 0xA);
6790 REG_WR(bp
, PRS_REG_HDRS_AFTER_TAG_0
, 0x6);
6791 REG_WR(bp
, PRS_REG_TAG_ETHERTYPE_0
, 0x8926);
6792 REG_WR(bp
, PRS_REG_TAG_LEN_0
, 0x4);
6794 /* Bit-map indicating which L2 hdrs may appear
6795 * after the basic Ethernet header
6797 REG_WR(bp
, PRS_REG_HDRS_AFTER_BASIC
,
6798 bp
->path_has_ovlan
? 7 : 6);
6802 bnx2x_init_block(bp
, BLOCK_TSDM
, PHASE_COMMON
);
6803 bnx2x_init_block(bp
, BLOCK_CSDM
, PHASE_COMMON
);
6804 bnx2x_init_block(bp
, BLOCK_USDM
, PHASE_COMMON
);
6805 bnx2x_init_block(bp
, BLOCK_XSDM
, PHASE_COMMON
);
6807 if (!CHIP_IS_E1x(bp
)) {
6808 /* reset VFC memories */
6809 REG_WR(bp
, TSEM_REG_FAST_MEMORY
+ VFC_REG_MEMORIES_RST
,
6810 VFC_MEMORIES_RST_REG_CAM_RST
|
6811 VFC_MEMORIES_RST_REG_RAM_RST
);
6812 REG_WR(bp
, XSEM_REG_FAST_MEMORY
+ VFC_REG_MEMORIES_RST
,
6813 VFC_MEMORIES_RST_REG_CAM_RST
|
6814 VFC_MEMORIES_RST_REG_RAM_RST
);
6819 bnx2x_init_block(bp
, BLOCK_TSEM
, PHASE_COMMON
);
6820 bnx2x_init_block(bp
, BLOCK_USEM
, PHASE_COMMON
);
6821 bnx2x_init_block(bp
, BLOCK_CSEM
, PHASE_COMMON
);
6822 bnx2x_init_block(bp
, BLOCK_XSEM
, PHASE_COMMON
);
6825 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
6827 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
,
6830 bnx2x_init_block(bp
, BLOCK_UPB
, PHASE_COMMON
);
6831 bnx2x_init_block(bp
, BLOCK_XPB
, PHASE_COMMON
);
6832 bnx2x_init_block(bp
, BLOCK_PBF
, PHASE_COMMON
);
6834 if (!CHIP_IS_E1x(bp
)) {
6835 if (IS_MF_AFEX(bp
)) {
6836 /* configure that VNTag and VLAN headers must be
6839 REG_WR(bp
, PBF_REG_HDRS_AFTER_BASIC
, 0xE);
6840 REG_WR(bp
, PBF_REG_MUST_HAVE_HDRS
, 0xA);
6841 REG_WR(bp
, PBF_REG_HDRS_AFTER_TAG_0
, 0x6);
6842 REG_WR(bp
, PBF_REG_TAG_ETHERTYPE_0
, 0x8926);
6843 REG_WR(bp
, PBF_REG_TAG_LEN_0
, 0x4);
6845 REG_WR(bp
, PBF_REG_HDRS_AFTER_BASIC
,
6846 bp
->path_has_ovlan
? 7 : 6);
6850 REG_WR(bp
, SRC_REG_SOFT_RST
, 1);
6852 bnx2x_init_block(bp
, BLOCK_SRC
, PHASE_COMMON
);
6854 if (CNIC_SUPPORT(bp
)) {
6855 REG_WR(bp
, SRC_REG_KEYSEARCH_0
, 0x63285672);
6856 REG_WR(bp
, SRC_REG_KEYSEARCH_1
, 0x24b8f2cc);
6857 REG_WR(bp
, SRC_REG_KEYSEARCH_2
, 0x223aef9b);
6858 REG_WR(bp
, SRC_REG_KEYSEARCH_3
, 0x26001e3a);
6859 REG_WR(bp
, SRC_REG_KEYSEARCH_4
, 0x7ae91116);
6860 REG_WR(bp
, SRC_REG_KEYSEARCH_5
, 0x5ce5230b);
6861 REG_WR(bp
, SRC_REG_KEYSEARCH_6
, 0x298d8adf);
6862 REG_WR(bp
, SRC_REG_KEYSEARCH_7
, 0x6eb0ff09);
6863 REG_WR(bp
, SRC_REG_KEYSEARCH_8
, 0x1830f82f);
6864 REG_WR(bp
, SRC_REG_KEYSEARCH_9
, 0x01e46be7);
6866 REG_WR(bp
, SRC_REG_SOFT_RST
, 0);
6868 if (sizeof(union cdu_context
) != 1024)
6869 /* we currently assume that a context is 1024 bytes */
6870 dev_alert(&bp
->pdev
->dev
,
6871 "please adjust the size of cdu_context(%ld)\n",
6872 (long)sizeof(union cdu_context
));
6874 bnx2x_init_block(bp
, BLOCK_CDU
, PHASE_COMMON
);
6875 val
= (4 << 24) + (0 << 12) + 1024;
6876 REG_WR(bp
, CDU_REG_CDU_GLOBAL_PARAMS
, val
);
6878 bnx2x_init_block(bp
, BLOCK_CFC
, PHASE_COMMON
);
6879 REG_WR(bp
, CFC_REG_INIT_REG
, 0x7FF);
6880 /* enable context validation interrupt from CFC */
6881 REG_WR(bp
, CFC_REG_CFC_INT_MASK
, 0);
6883 /* set the thresholds to prevent CFC/CDU race */
6884 REG_WR(bp
, CFC_REG_DEBUG0
, 0x20020000);
6886 bnx2x_init_block(bp
, BLOCK_HC
, PHASE_COMMON
);
6888 if (!CHIP_IS_E1x(bp
) && BP_NOMCP(bp
))
6889 REG_WR(bp
, IGU_REG_RESET_MEMORIES
, 0x36);
6891 bnx2x_init_block(bp
, BLOCK_IGU
, PHASE_COMMON
);
6892 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, PHASE_COMMON
);
6894 /* Reset PCIE errors for debug */
6895 REG_WR(bp
, 0x2814, 0xffffffff);
6896 REG_WR(bp
, 0x3820, 0xffffffff);
6898 if (!CHIP_IS_E1x(bp
)) {
6899 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_CONTROL_5
,
6900 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1
|
6901 PXPCS_TL_CONTROL_5_ERR_UNSPPORT
));
6902 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_FUNC345_STAT
,
6903 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4
|
6904 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3
|
6905 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2
));
6906 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_FUNC678_STAT
,
6907 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7
|
6908 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6
|
6909 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5
));
6912 bnx2x_init_block(bp
, BLOCK_NIG
, PHASE_COMMON
);
6913 if (!CHIP_IS_E1(bp
)) {
6914 /* in E3 this done in per-port section */
6915 if (!CHIP_IS_E3(bp
))
6916 REG_WR(bp
, NIG_REG_LLH_MF_MODE
, IS_MF(bp
));
6918 if (CHIP_IS_E1H(bp
))
6919 /* not applicable for E2 (and above ...) */
6920 REG_WR(bp
, NIG_REG_LLH_E1HOV_MODE
, IS_MF_SD(bp
));
6922 if (CHIP_REV_IS_SLOW(bp
))
6925 /* finish CFC init */
6926 val
= reg_poll(bp
, CFC_REG_LL_INIT_DONE
, 1, 100, 10);
6928 BNX2X_ERR("CFC LL_INIT failed\n");
6931 val
= reg_poll(bp
, CFC_REG_AC_INIT_DONE
, 1, 100, 10);
6933 BNX2X_ERR("CFC AC_INIT failed\n");
6936 val
= reg_poll(bp
, CFC_REG_CAM_INIT_DONE
, 1, 100, 10);
6938 BNX2X_ERR("CFC CAM_INIT failed\n");
6941 REG_WR(bp
, CFC_REG_DEBUG0
, 0);
6943 if (CHIP_IS_E1(bp
)) {
6944 /* read NIG statistic
6945 to see if this is our first up since powerup */
6946 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
6947 val
= *bnx2x_sp(bp
, wb_data
[0]);
6949 /* do internal memory self test */
6950 if ((val
== 0) && bnx2x_int_mem_test(bp
)) {
6951 BNX2X_ERR("internal mem self test failed\n");
6956 bnx2x_setup_fan_failure_detection(bp
);
6958 /* clear PXP2 attentions */
6959 REG_RD(bp
, PXP2_REG_PXP2_INT_STS_CLR_0
);
6961 bnx2x_enable_blocks_attention(bp
);
6962 bnx2x_enable_blocks_parity(bp
);
6964 if (!BP_NOMCP(bp
)) {
6965 if (CHIP_IS_E1x(bp
))
6966 bnx2x__common_init_phy(bp
);
6968 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6974 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6976 * @bp: driver handle
6978 static int bnx2x_init_hw_common_chip(struct bnx2x
*bp
)
6980 int rc
= bnx2x_init_hw_common(bp
);
6985 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6987 bnx2x__common_init_phy(bp
);
6992 static int bnx2x_init_hw_port(struct bnx2x
*bp
)
6994 int port
= BP_PORT(bp
);
6995 int init_phase
= port
? PHASE_PORT1
: PHASE_PORT0
;
7000 DP(NETIF_MSG_HW
, "starting port init port %d\n", port
);
7002 REG_WR(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4, 0);
7004 bnx2x_init_block(bp
, BLOCK_MISC
, init_phase
);
7005 bnx2x_init_block(bp
, BLOCK_PXP
, init_phase
);
7006 bnx2x_init_block(bp
, BLOCK_PXP2
, init_phase
);
7008 /* Timers bug workaround: disables the pf_master bit in pglue at
7009 * common phase, we need to enable it here before any dmae access are
7010 * attempted. Therefore we manually added the enable-master to the
7011 * port phase (it also happens in the function phase)
7013 if (!CHIP_IS_E1x(bp
))
7014 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
7016 bnx2x_init_block(bp
, BLOCK_ATC
, init_phase
);
7017 bnx2x_init_block(bp
, BLOCK_DMAE
, init_phase
);
7018 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, init_phase
);
7019 bnx2x_init_block(bp
, BLOCK_QM
, init_phase
);
7021 bnx2x_init_block(bp
, BLOCK_TCM
, init_phase
);
7022 bnx2x_init_block(bp
, BLOCK_UCM
, init_phase
);
7023 bnx2x_init_block(bp
, BLOCK_CCM
, init_phase
);
7024 bnx2x_init_block(bp
, BLOCK_XCM
, init_phase
);
7026 /* QM cid (connection) count */
7027 bnx2x_qm_init_cid_count(bp
, bp
->qm_cid_count
, INITOP_SET
);
7029 if (CNIC_SUPPORT(bp
)) {
7030 bnx2x_init_block(bp
, BLOCK_TM
, init_phase
);
7031 REG_WR(bp
, TM_REG_LIN0_SCAN_TIME
+ port
*4, 20);
7032 REG_WR(bp
, TM_REG_LIN0_MAX_ACTIVE_CID
+ port
*4, 31);
7035 bnx2x_init_block(bp
, BLOCK_DORQ
, init_phase
);
7037 bnx2x_init_block(bp
, BLOCK_BRB1
, init_phase
);
7039 if (CHIP_IS_E1(bp
) || CHIP_IS_E1H(bp
)) {
7042 low
= ((bp
->flags
& ONE_PORT_FLAG
) ? 160 : 246);
7043 else if (bp
->dev
->mtu
> 4096) {
7044 if (bp
->flags
& ONE_PORT_FLAG
)
7048 /* (24*1024 + val*4)/256 */
7049 low
= 96 + (val
/64) +
7050 ((val
% 64) ? 1 : 0);
7053 low
= ((bp
->flags
& ONE_PORT_FLAG
) ? 80 : 160);
7054 high
= low
+ 56; /* 14*1024/256 */
7055 REG_WR(bp
, BRB1_REG_PAUSE_LOW_THRESHOLD_0
+ port
*4, low
);
7056 REG_WR(bp
, BRB1_REG_PAUSE_HIGH_THRESHOLD_0
+ port
*4, high
);
7059 if (CHIP_MODE_IS_4_PORT(bp
))
7060 REG_WR(bp
, (BP_PORT(bp
) ?
7061 BRB1_REG_MAC_GUARANTIED_1
:
7062 BRB1_REG_MAC_GUARANTIED_0
), 40);
7065 bnx2x_init_block(bp
, BLOCK_PRS
, init_phase
);
7066 if (CHIP_IS_E3B0(bp
)) {
7067 if (IS_MF_AFEX(bp
)) {
7068 /* configure headers for AFEX mode */
7069 REG_WR(bp
, BP_PORT(bp
) ?
7070 PRS_REG_HDRS_AFTER_BASIC_PORT_1
:
7071 PRS_REG_HDRS_AFTER_BASIC_PORT_0
, 0xE);
7072 REG_WR(bp
, BP_PORT(bp
) ?
7073 PRS_REG_HDRS_AFTER_TAG_0_PORT_1
:
7074 PRS_REG_HDRS_AFTER_TAG_0_PORT_0
, 0x6);
7075 REG_WR(bp
, BP_PORT(bp
) ?
7076 PRS_REG_MUST_HAVE_HDRS_PORT_1
:
7077 PRS_REG_MUST_HAVE_HDRS_PORT_0
, 0xA);
7079 /* Ovlan exists only if we are in multi-function +
7080 * switch-dependent mode, in switch-independent there
7081 * is no ovlan headers
7083 REG_WR(bp
, BP_PORT(bp
) ?
7084 PRS_REG_HDRS_AFTER_BASIC_PORT_1
:
7085 PRS_REG_HDRS_AFTER_BASIC_PORT_0
,
7086 (bp
->path_has_ovlan
? 7 : 6));
7090 bnx2x_init_block(bp
, BLOCK_TSDM
, init_phase
);
7091 bnx2x_init_block(bp
, BLOCK_CSDM
, init_phase
);
7092 bnx2x_init_block(bp
, BLOCK_USDM
, init_phase
);
7093 bnx2x_init_block(bp
, BLOCK_XSDM
, init_phase
);
7095 bnx2x_init_block(bp
, BLOCK_TSEM
, init_phase
);
7096 bnx2x_init_block(bp
, BLOCK_USEM
, init_phase
);
7097 bnx2x_init_block(bp
, BLOCK_CSEM
, init_phase
);
7098 bnx2x_init_block(bp
, BLOCK_XSEM
, init_phase
);
7100 bnx2x_init_block(bp
, BLOCK_UPB
, init_phase
);
7101 bnx2x_init_block(bp
, BLOCK_XPB
, init_phase
);
7103 bnx2x_init_block(bp
, BLOCK_PBF
, init_phase
);
7105 if (CHIP_IS_E1x(bp
)) {
7106 /* configure PBF to work without PAUSE mtu 9000 */
7107 REG_WR(bp
, PBF_REG_P0_PAUSE_ENABLE
+ port
*4, 0);
7109 /* update threshold */
7110 REG_WR(bp
, PBF_REG_P0_ARB_THRSH
+ port
*4, (9040/16));
7111 /* update init credit */
7112 REG_WR(bp
, PBF_REG_P0_INIT_CRD
+ port
*4, (9040/16) + 553 - 22);
7115 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 1);
7117 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 0);
7120 if (CNIC_SUPPORT(bp
))
7121 bnx2x_init_block(bp
, BLOCK_SRC
, init_phase
);
7123 bnx2x_init_block(bp
, BLOCK_CDU
, init_phase
);
7124 bnx2x_init_block(bp
, BLOCK_CFC
, init_phase
);
7126 if (CHIP_IS_E1(bp
)) {
7127 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
7128 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
7130 bnx2x_init_block(bp
, BLOCK_HC
, init_phase
);
7132 bnx2x_init_block(bp
, BLOCK_IGU
, init_phase
);
7134 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, init_phase
);
7135 /* init aeu_mask_attn_func_0/1:
7136 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
7137 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
7138 * bits 4-7 are used for "per vn group attention" */
7139 val
= IS_MF(bp
) ? 0xF7 : 0x7;
7140 /* Enable DCBX attention for all but E1 */
7141 val
|= CHIP_IS_E1(bp
) ? 0 : 0x10;
7142 REG_WR(bp
, MISC_REG_AEU_MASK_ATTN_FUNC_0
+ port
*4, val
);
7144 bnx2x_init_block(bp
, BLOCK_NIG
, init_phase
);
7146 if (!CHIP_IS_E1x(bp
)) {
7147 /* Bit-map indicating which L2 hdrs may appear after the
7148 * basic Ethernet header
7151 REG_WR(bp
, BP_PORT(bp
) ?
7152 NIG_REG_P1_HDRS_AFTER_BASIC
:
7153 NIG_REG_P0_HDRS_AFTER_BASIC
, 0xE);
7155 REG_WR(bp
, BP_PORT(bp
) ?
7156 NIG_REG_P1_HDRS_AFTER_BASIC
:
7157 NIG_REG_P0_HDRS_AFTER_BASIC
,
7158 IS_MF_SD(bp
) ? 7 : 6);
7161 REG_WR(bp
, BP_PORT(bp
) ?
7162 NIG_REG_LLH1_MF_MODE
:
7163 NIG_REG_LLH_MF_MODE
, IS_MF(bp
));
7165 if (!CHIP_IS_E3(bp
))
7166 REG_WR(bp
, NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 1);
7168 if (!CHIP_IS_E1(bp
)) {
7169 /* 0x2 disable mf_ov, 0x1 enable */
7170 REG_WR(bp
, NIG_REG_LLH0_BRB1_DRV_MASK_MF
+ port
*4,
7171 (IS_MF_SD(bp
) ? 0x1 : 0x2));
7173 if (!CHIP_IS_E1x(bp
)) {
7175 switch (bp
->mf_mode
) {
7176 case MULTI_FUNCTION_SD
:
7179 case MULTI_FUNCTION_SI
:
7180 case MULTI_FUNCTION_AFEX
:
7185 REG_WR(bp
, (BP_PORT(bp
) ? NIG_REG_LLH1_CLS_TYPE
:
7186 NIG_REG_LLH0_CLS_TYPE
), val
);
7189 REG_WR(bp
, NIG_REG_LLFC_ENABLE_0
+ port
*4, 0);
7190 REG_WR(bp
, NIG_REG_LLFC_OUT_EN_0
+ port
*4, 0);
7191 REG_WR(bp
, NIG_REG_PAUSE_ENABLE_0
+ port
*4, 1);
7195 /* If SPIO5 is set to generate interrupts, enable it for this port */
7196 val
= REG_RD(bp
, MISC_REG_SPIO_EVENT_EN
);
7197 if (val
& MISC_SPIO_SPIO5
) {
7198 u32 reg_addr
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
7199 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
7200 val
= REG_RD(bp
, reg_addr
);
7201 val
|= AEU_INPUTS_ATTN_BITS_SPIO5
;
7202 REG_WR(bp
, reg_addr
, val
);
7208 static void bnx2x_ilt_wr(struct bnx2x
*bp
, u32 index
, dma_addr_t addr
)
7214 reg
= PXP2_REG_RQ_ONCHIP_AT
+ index
*8;
7216 reg
= PXP2_REG_RQ_ONCHIP_AT_B0
+ index
*8;
7218 wb_write
[0] = ONCHIP_ADDR1(addr
);
7219 wb_write
[1] = ONCHIP_ADDR2(addr
);
7220 REG_WR_DMAE(bp
, reg
, wb_write
, 2);
7223 void bnx2x_igu_clear_sb_gen(struct bnx2x
*bp
, u8 func
, u8 idu_sb_id
, bool is_pf
)
7225 u32 data
, ctl
, cnt
= 100;
7226 u32 igu_addr_data
= IGU_REG_COMMAND_REG_32LSB_DATA
;
7227 u32 igu_addr_ctl
= IGU_REG_COMMAND_REG_CTRL
;
7228 u32 igu_addr_ack
= IGU_REG_CSTORM_TYPE_0_SB_CLEANUP
+ (idu_sb_id
/32)*4;
7229 u32 sb_bit
= 1 << (idu_sb_id
%32);
7230 u32 func_encode
= func
| (is_pf
? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT
;
7231 u32 addr_encode
= IGU_CMD_E2_PROD_UPD_BASE
+ idu_sb_id
;
7233 /* Not supported in BC mode */
7234 if (CHIP_INT_MODE_IS_BC(bp
))
7237 data
= (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7238 << IGU_REGULAR_CLEANUP_TYPE_SHIFT
) |
7239 IGU_REGULAR_CLEANUP_SET
|
7240 IGU_REGULAR_BCLEANUP
;
7242 ctl
= addr_encode
<< IGU_CTRL_REG_ADDRESS_SHIFT
|
7243 func_encode
<< IGU_CTRL_REG_FID_SHIFT
|
7244 IGU_CTRL_CMD_TYPE_WR
<< IGU_CTRL_REG_TYPE_SHIFT
;
7246 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7247 data
, igu_addr_data
);
7248 REG_WR(bp
, igu_addr_data
, data
);
7251 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7253 REG_WR(bp
, igu_addr_ctl
, ctl
);
7257 /* wait for clean up to finish */
7258 while (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
) && --cnt
)
7262 if (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
)) {
7264 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7265 idu_sb_id
, idu_sb_id
/32, idu_sb_id
%32, cnt
);
7269 static void bnx2x_igu_clear_sb(struct bnx2x
*bp
, u8 idu_sb_id
)
7271 bnx2x_igu_clear_sb_gen(bp
, BP_FUNC(bp
), idu_sb_id
, true /*PF*/);
7274 static void bnx2x_clear_func_ilt(struct bnx2x
*bp
, u32 func
)
7276 u32 i
, base
= FUNC_ILT_BASE(func
);
7277 for (i
= base
; i
< base
+ ILT_PER_FUNC
; i
++)
7278 bnx2x_ilt_wr(bp
, i
, 0);
7282 static void bnx2x_init_searcher(struct bnx2x
*bp
)
7284 int port
= BP_PORT(bp
);
7285 bnx2x_src_init_t2(bp
, bp
->t2
, bp
->t2_mapping
, SRC_CONN_NUM
);
7286 /* T1 hash bits value determines the T1 number of entries */
7287 REG_WR(bp
, SRC_REG_NUMBER_HASH_BITS0
+ port
*4, SRC_HASH_BITS
);
7290 static inline int bnx2x_func_switch_update(struct bnx2x
*bp
, int suspend
)
7293 struct bnx2x_func_state_params func_params
= {NULL
};
7294 struct bnx2x_func_switch_update_params
*switch_update_params
=
7295 &func_params
.params
.switch_update
;
7297 /* Prepare parameters for function state transitions */
7298 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
7299 __set_bit(RAMROD_RETRY
, &func_params
.ramrod_flags
);
7301 func_params
.f_obj
= &bp
->func_obj
;
7302 func_params
.cmd
= BNX2X_F_CMD_SWITCH_UPDATE
;
7304 /* Function parameters */
7305 switch_update_params
->suspend
= suspend
;
7307 rc
= bnx2x_func_state_change(bp
, &func_params
);
7312 static int bnx2x_reset_nic_mode(struct bnx2x
*bp
)
7314 int rc
, i
, port
= BP_PORT(bp
);
7315 int vlan_en
= 0, mac_en
[NUM_MACS
];
7318 /* Close input from network */
7319 if (bp
->mf_mode
== SINGLE_FUNCTION
) {
7320 bnx2x_set_rx_filter(&bp
->link_params
, 0);
7322 vlan_en
= REG_RD(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7323 NIG_REG_LLH0_FUNC_EN
);
7324 REG_WR(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7325 NIG_REG_LLH0_FUNC_EN
, 0);
7326 for (i
= 0; i
< NUM_MACS
; i
++) {
7327 mac_en
[i
] = REG_RD(bp
, port
?
7328 (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7330 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+
7332 REG_WR(bp
, port
? (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7334 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+ 4 * i
), 0);
7338 /* Close BMC to host */
7339 REG_WR(bp
, port
? NIG_REG_P0_TX_MNG_HOST_ENABLE
:
7340 NIG_REG_P1_TX_MNG_HOST_ENABLE
, 0);
7342 /* Suspend Tx switching to the PF. Completion of this ramrod
7343 * further guarantees that all the packets of that PF / child
7344 * VFs in BRB were processed by the Parser, so it is safe to
7345 * change the NIC_MODE register.
7347 rc
= bnx2x_func_switch_update(bp
, 1);
7349 BNX2X_ERR("Can't suspend tx-switching!\n");
7353 /* Change NIC_MODE register */
7354 REG_WR(bp
, PRS_REG_NIC_MODE
, 0);
7356 /* Open input from network */
7357 if (bp
->mf_mode
== SINGLE_FUNCTION
) {
7358 bnx2x_set_rx_filter(&bp
->link_params
, 1);
7360 REG_WR(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7361 NIG_REG_LLH0_FUNC_EN
, vlan_en
);
7362 for (i
= 0; i
< NUM_MACS
; i
++) {
7363 REG_WR(bp
, port
? (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7365 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+ 4 * i
),
7370 /* Enable BMC to host */
7371 REG_WR(bp
, port
? NIG_REG_P0_TX_MNG_HOST_ENABLE
:
7372 NIG_REG_P1_TX_MNG_HOST_ENABLE
, 1);
7374 /* Resume Tx switching to the PF */
7375 rc
= bnx2x_func_switch_update(bp
, 0);
7377 BNX2X_ERR("Can't resume tx-switching!\n");
7381 DP(NETIF_MSG_IFUP
, "NIC MODE disabled\n");
7385 int bnx2x_init_hw_func_cnic(struct bnx2x
*bp
)
7389 bnx2x_ilt_init_op_cnic(bp
, INITOP_SET
);
7391 if (CONFIGURE_NIC_MODE(bp
)) {
7392 /* Configrue searcher as part of function hw init */
7393 bnx2x_init_searcher(bp
);
7395 /* Reset NIC mode */
7396 rc
= bnx2x_reset_nic_mode(bp
);
7398 BNX2X_ERR("Can't change NIC mode!\n");
7405 static int bnx2x_init_hw_func(struct bnx2x
*bp
)
7407 int port
= BP_PORT(bp
);
7408 int func
= BP_FUNC(bp
);
7409 int init_phase
= PHASE_PF0
+ func
;
7410 struct bnx2x_ilt
*ilt
= BP_ILT(bp
);
7413 u32 main_mem_base
, main_mem_size
, main_mem_prty_clr
;
7414 int i
, main_mem_width
, rc
;
7416 DP(NETIF_MSG_HW
, "starting func init func %d\n", func
);
7418 /* FLR cleanup - hmmm */
7419 if (!CHIP_IS_E1x(bp
)) {
7420 rc
= bnx2x_pf_flr_clnup(bp
);
7427 /* set MSI reconfigure capability */
7428 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
7429 addr
= (port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
);
7430 val
= REG_RD(bp
, addr
);
7431 val
|= HC_CONFIG_0_REG_MSI_ATTN_EN_0
;
7432 REG_WR(bp
, addr
, val
);
7435 bnx2x_init_block(bp
, BLOCK_PXP
, init_phase
);
7436 bnx2x_init_block(bp
, BLOCK_PXP2
, init_phase
);
7439 cdu_ilt_start
= ilt
->clients
[ILT_CLIENT_CDU
].start
;
7442 cdu_ilt_start
+= BNX2X_FIRST_VF_CID
/ILT_PAGE_CIDS
;
7443 cdu_ilt_start
= bnx2x_iov_init_ilt(bp
, cdu_ilt_start
);
7445 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7446 * those of the VFs, so start line should be reset
7448 cdu_ilt_start
= ilt
->clients
[ILT_CLIENT_CDU
].start
;
7449 for (i
= 0; i
< L2_ILT_LINES(bp
); i
++) {
7450 ilt
->lines
[cdu_ilt_start
+ i
].page
= bp
->context
[i
].vcxt
;
7451 ilt
->lines
[cdu_ilt_start
+ i
].page_mapping
=
7452 bp
->context
[i
].cxt_mapping
;
7453 ilt
->lines
[cdu_ilt_start
+ i
].size
= bp
->context
[i
].size
;
7456 bnx2x_ilt_init_op(bp
, INITOP_SET
);
7458 if (!CONFIGURE_NIC_MODE(bp
)) {
7459 bnx2x_init_searcher(bp
);
7460 REG_WR(bp
, PRS_REG_NIC_MODE
, 0);
7461 DP(NETIF_MSG_IFUP
, "NIC MODE disabled\n");
7464 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
7465 DP(NETIF_MSG_IFUP
, "NIC MODE configrued\n");
7469 if (!CHIP_IS_E1x(bp
)) {
7470 u32 pf_conf
= IGU_PF_CONF_FUNC_EN
;
7472 /* Turn on a single ISR mode in IGU if driver is going to use
7475 if (!(bp
->flags
& USING_MSIX_FLAG
))
7476 pf_conf
|= IGU_PF_CONF_SINGLE_ISR_EN
;
7478 * Timers workaround bug: function init part.
7479 * Need to wait 20msec after initializing ILT,
7480 * needed to make sure there are no requests in
7481 * one of the PXP internal queues with "old" ILT addresses
7485 * Master enable - Due to WB DMAE writes performed before this
7486 * register is re-initialized as part of the regular function
7489 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
7490 /* Enable the function in IGU */
7491 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, pf_conf
);
7496 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, init_phase
);
7498 if (!CHIP_IS_E1x(bp
))
7499 REG_WR(bp
, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR
, func
);
7501 bnx2x_init_block(bp
, BLOCK_ATC
, init_phase
);
7502 bnx2x_init_block(bp
, BLOCK_DMAE
, init_phase
);
7503 bnx2x_init_block(bp
, BLOCK_NIG
, init_phase
);
7504 bnx2x_init_block(bp
, BLOCK_SRC
, init_phase
);
7505 bnx2x_init_block(bp
, BLOCK_MISC
, init_phase
);
7506 bnx2x_init_block(bp
, BLOCK_TCM
, init_phase
);
7507 bnx2x_init_block(bp
, BLOCK_UCM
, init_phase
);
7508 bnx2x_init_block(bp
, BLOCK_CCM
, init_phase
);
7509 bnx2x_init_block(bp
, BLOCK_XCM
, init_phase
);
7510 bnx2x_init_block(bp
, BLOCK_TSEM
, init_phase
);
7511 bnx2x_init_block(bp
, BLOCK_USEM
, init_phase
);
7512 bnx2x_init_block(bp
, BLOCK_CSEM
, init_phase
);
7513 bnx2x_init_block(bp
, BLOCK_XSEM
, init_phase
);
7515 if (!CHIP_IS_E1x(bp
))
7516 REG_WR(bp
, QM_REG_PF_EN
, 1);
7518 if (!CHIP_IS_E1x(bp
)) {
7519 REG_WR(bp
, TSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7520 REG_WR(bp
, USEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7521 REG_WR(bp
, CSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7522 REG_WR(bp
, XSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7524 bnx2x_init_block(bp
, BLOCK_QM
, init_phase
);
7526 bnx2x_init_block(bp
, BLOCK_TM
, init_phase
);
7527 bnx2x_init_block(bp
, BLOCK_DORQ
, init_phase
);
7529 bnx2x_iov_init_dq(bp
);
7531 bnx2x_init_block(bp
, BLOCK_BRB1
, init_phase
);
7532 bnx2x_init_block(bp
, BLOCK_PRS
, init_phase
);
7533 bnx2x_init_block(bp
, BLOCK_TSDM
, init_phase
);
7534 bnx2x_init_block(bp
, BLOCK_CSDM
, init_phase
);
7535 bnx2x_init_block(bp
, BLOCK_USDM
, init_phase
);
7536 bnx2x_init_block(bp
, BLOCK_XSDM
, init_phase
);
7537 bnx2x_init_block(bp
, BLOCK_UPB
, init_phase
);
7538 bnx2x_init_block(bp
, BLOCK_XPB
, init_phase
);
7539 bnx2x_init_block(bp
, BLOCK_PBF
, init_phase
);
7540 if (!CHIP_IS_E1x(bp
))
7541 REG_WR(bp
, PBF_REG_DISABLE_PF
, 0);
7543 bnx2x_init_block(bp
, BLOCK_CDU
, init_phase
);
7545 bnx2x_init_block(bp
, BLOCK_CFC
, init_phase
);
7547 if (!CHIP_IS_E1x(bp
))
7548 REG_WR(bp
, CFC_REG_WEAK_ENABLE_PF
, 1);
7551 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 1);
7552 REG_WR(bp
, NIG_REG_LLH0_FUNC_VLAN_ID
+ port
*8, bp
->mf_ov
);
7555 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, init_phase
);
7557 /* HC init per function */
7558 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
7559 if (CHIP_IS_E1H(bp
)) {
7560 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
7562 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
7563 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
7565 bnx2x_init_block(bp
, BLOCK_HC
, init_phase
);
7568 int num_segs
, sb_idx
, prod_offset
;
7570 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
7572 if (!CHIP_IS_E1x(bp
)) {
7573 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, 0);
7574 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, 0);
7577 bnx2x_init_block(bp
, BLOCK_IGU
, init_phase
);
7579 if (!CHIP_IS_E1x(bp
)) {
7583 * E2 mode: address 0-135 match to the mapping memory;
7584 * 136 - PF0 default prod; 137 - PF1 default prod;
7585 * 138 - PF2 default prod; 139 - PF3 default prod;
7586 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7587 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7590 * E1.5 mode - In backward compatible mode;
7591 * for non default SB; each even line in the memory
7592 * holds the U producer and each odd line hold
7593 * the C producer. The first 128 producers are for
7594 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7595 * producers are for the DSB for each PF.
7596 * Each PF has five segments: (the order inside each
7597 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7598 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7599 * 144-147 attn prods;
7601 /* non-default-status-blocks */
7602 num_segs
= CHIP_INT_MODE_IS_BC(bp
) ?
7603 IGU_BC_NDSB_NUM_SEGS
: IGU_NORM_NDSB_NUM_SEGS
;
7604 for (sb_idx
= 0; sb_idx
< bp
->igu_sb_cnt
; sb_idx
++) {
7605 prod_offset
= (bp
->igu_base_sb
+ sb_idx
) *
7608 for (i
= 0; i
< num_segs
; i
++) {
7609 addr
= IGU_REG_PROD_CONS_MEMORY
+
7610 (prod_offset
+ i
) * 4;
7611 REG_WR(bp
, addr
, 0);
7613 /* send consumer update with value 0 */
7614 bnx2x_ack_sb(bp
, bp
->igu_base_sb
+ sb_idx
,
7615 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7616 bnx2x_igu_clear_sb(bp
,
7617 bp
->igu_base_sb
+ sb_idx
);
7620 /* default-status-blocks */
7621 num_segs
= CHIP_INT_MODE_IS_BC(bp
) ?
7622 IGU_BC_DSB_NUM_SEGS
: IGU_NORM_DSB_NUM_SEGS
;
7624 if (CHIP_MODE_IS_4_PORT(bp
))
7625 dsb_idx
= BP_FUNC(bp
);
7627 dsb_idx
= BP_VN(bp
);
7629 prod_offset
= (CHIP_INT_MODE_IS_BC(bp
) ?
7630 IGU_BC_BASE_DSB_PROD
+ dsb_idx
:
7631 IGU_NORM_BASE_DSB_PROD
+ dsb_idx
);
7634 * igu prods come in chunks of E1HVN_MAX (4) -
7635 * does not matters what is the current chip mode
7637 for (i
= 0; i
< (num_segs
* E1HVN_MAX
);
7639 addr
= IGU_REG_PROD_CONS_MEMORY
+
7640 (prod_offset
+ i
)*4;
7641 REG_WR(bp
, addr
, 0);
7643 /* send consumer update with 0 */
7644 if (CHIP_INT_MODE_IS_BC(bp
)) {
7645 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7646 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7647 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7648 CSTORM_ID
, 0, IGU_INT_NOP
, 1);
7649 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7650 XSTORM_ID
, 0, IGU_INT_NOP
, 1);
7651 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7652 TSTORM_ID
, 0, IGU_INT_NOP
, 1);
7653 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7654 ATTENTION_ID
, 0, IGU_INT_NOP
, 1);
7656 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7657 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7658 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7659 ATTENTION_ID
, 0, IGU_INT_NOP
, 1);
7661 bnx2x_igu_clear_sb(bp
, bp
->igu_dsb_id
);
7663 /* !!! these should become driver const once
7664 rf-tool supports split-68 const */
7665 REG_WR(bp
, IGU_REG_SB_INT_BEFORE_MASK_LSB
, 0);
7666 REG_WR(bp
, IGU_REG_SB_INT_BEFORE_MASK_MSB
, 0);
7667 REG_WR(bp
, IGU_REG_SB_MASK_LSB
, 0);
7668 REG_WR(bp
, IGU_REG_SB_MASK_MSB
, 0);
7669 REG_WR(bp
, IGU_REG_PBA_STATUS_LSB
, 0);
7670 REG_WR(bp
, IGU_REG_PBA_STATUS_MSB
, 0);
7674 /* Reset PCIE errors for debug */
7675 REG_WR(bp
, 0x2114, 0xffffffff);
7676 REG_WR(bp
, 0x2120, 0xffffffff);
7678 if (CHIP_IS_E1x(bp
)) {
7679 main_mem_size
= HC_REG_MAIN_MEMORY_SIZE
/ 2; /*dwords*/
7680 main_mem_base
= HC_REG_MAIN_MEMORY
+
7681 BP_PORT(bp
) * (main_mem_size
* 4);
7682 main_mem_prty_clr
= HC_REG_HC_PRTY_STS_CLR
;
7685 val
= REG_RD(bp
, main_mem_prty_clr
);
7688 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7691 /* Clear "false" parity errors in MSI-X table */
7692 for (i
= main_mem_base
;
7693 i
< main_mem_base
+ main_mem_size
* 4;
7694 i
+= main_mem_width
) {
7695 bnx2x_read_dmae(bp
, i
, main_mem_width
/ 4);
7696 bnx2x_write_dmae(bp
, bnx2x_sp_mapping(bp
, wb_data
),
7697 i
, main_mem_width
/ 4);
7699 /* Clear HC parity attention */
7700 REG_RD(bp
, main_mem_prty_clr
);
7703 #ifdef BNX2X_STOP_ON_ERROR
7704 /* Enable STORMs SP logging */
7705 REG_WR8(bp
, BAR_USTRORM_INTMEM
+
7706 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7707 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
7708 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7709 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
7710 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7711 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+
7712 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7715 bnx2x_phy_probe(&bp
->link_params
);
7721 void bnx2x_free_mem_cnic(struct bnx2x
*bp
)
7723 bnx2x_ilt_mem_op_cnic(bp
, ILT_MEMOP_FREE
);
7725 if (!CHIP_IS_E1x(bp
))
7726 BNX2X_PCI_FREE(bp
->cnic_sb
.e2_sb
, bp
->cnic_sb_mapping
,
7727 sizeof(struct host_hc_status_block_e2
));
7729 BNX2X_PCI_FREE(bp
->cnic_sb
.e1x_sb
, bp
->cnic_sb_mapping
,
7730 sizeof(struct host_hc_status_block_e1x
));
7732 BNX2X_PCI_FREE(bp
->t2
, bp
->t2_mapping
, SRC_T2_SZ
);
7735 void bnx2x_free_mem(struct bnx2x
*bp
)
7739 BNX2X_PCI_FREE(bp
->def_status_blk
, bp
->def_status_blk_mapping
,
7740 sizeof(struct host_sp_status_block
));
7742 BNX2X_PCI_FREE(bp
->fw_stats
, bp
->fw_stats_mapping
,
7743 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
7745 BNX2X_PCI_FREE(bp
->slowpath
, bp
->slowpath_mapping
,
7746 sizeof(struct bnx2x_slowpath
));
7748 for (i
= 0; i
< L2_ILT_LINES(bp
); i
++)
7749 BNX2X_PCI_FREE(bp
->context
[i
].vcxt
, bp
->context
[i
].cxt_mapping
,
7750 bp
->context
[i
].size
);
7751 bnx2x_ilt_mem_op(bp
, ILT_MEMOP_FREE
);
7753 BNX2X_FREE(bp
->ilt
->lines
);
7755 BNX2X_PCI_FREE(bp
->spq
, bp
->spq_mapping
, BCM_PAGE_SIZE
);
7757 BNX2X_PCI_FREE(bp
->eq_ring
, bp
->eq_mapping
,
7758 BCM_PAGE_SIZE
* NUM_EQ_PAGES
);
7760 bnx2x_iov_free_mem(bp
);
7764 int bnx2x_alloc_mem_cnic(struct bnx2x
*bp
)
7766 if (!CHIP_IS_E1x(bp
))
7767 /* size = the status block + ramrod buffers */
7768 BNX2X_PCI_ALLOC(bp
->cnic_sb
.e2_sb
, &bp
->cnic_sb_mapping
,
7769 sizeof(struct host_hc_status_block_e2
));
7771 BNX2X_PCI_ALLOC(bp
->cnic_sb
.e1x_sb
,
7772 &bp
->cnic_sb_mapping
,
7774 host_hc_status_block_e1x
));
7776 if (CONFIGURE_NIC_MODE(bp
))
7777 /* allocate searcher T2 table, as it wan't allocated before */
7778 BNX2X_PCI_ALLOC(bp
->t2
, &bp
->t2_mapping
, SRC_T2_SZ
);
7780 /* write address to which L5 should insert its values */
7781 bp
->cnic_eth_dev
.addr_drv_info_to_mcp
=
7782 &bp
->slowpath
->drv_info_to_mcp
;
7784 if (bnx2x_ilt_mem_op_cnic(bp
, ILT_MEMOP_ALLOC
))
7790 bnx2x_free_mem_cnic(bp
);
7791 BNX2X_ERR("Can't allocate memory\n");
7795 int bnx2x_alloc_mem(struct bnx2x
*bp
)
7797 int i
, allocated
, context_size
;
7799 if (!CONFIGURE_NIC_MODE(bp
))
7800 /* allocate searcher T2 table */
7801 BNX2X_PCI_ALLOC(bp
->t2
, &bp
->t2_mapping
, SRC_T2_SZ
);
7803 BNX2X_PCI_ALLOC(bp
->def_status_blk
, &bp
->def_status_blk_mapping
,
7804 sizeof(struct host_sp_status_block
));
7806 BNX2X_PCI_ALLOC(bp
->slowpath
, &bp
->slowpath_mapping
,
7807 sizeof(struct bnx2x_slowpath
));
7809 /* Allocate memory for CDU context:
7810 * This memory is allocated separately and not in the generic ILT
7811 * functions because CDU differs in few aspects:
7812 * 1. There are multiple entities allocating memory for context -
7813 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7814 * its own ILT lines.
7815 * 2. Since CDU page-size is not a single 4KB page (which is the case
7816 * for the other ILT clients), to be efficient we want to support
7817 * allocation of sub-page-size in the last entry.
7818 * 3. Context pointers are used by the driver to pass to FW / update
7819 * the context (for the other ILT clients the pointers are used just to
7820 * free the memory during unload).
7822 context_size
= sizeof(union cdu_context
) * BNX2X_L2_CID_COUNT(bp
);
7824 for (i
= 0, allocated
= 0; allocated
< context_size
; i
++) {
7825 bp
->context
[i
].size
= min(CDU_ILT_PAGE_SZ
,
7826 (context_size
- allocated
));
7827 BNX2X_PCI_ALLOC(bp
->context
[i
].vcxt
,
7828 &bp
->context
[i
].cxt_mapping
,
7829 bp
->context
[i
].size
);
7830 allocated
+= bp
->context
[i
].size
;
7832 BNX2X_ALLOC(bp
->ilt
->lines
, sizeof(struct ilt_line
) * ILT_MAX_LINES
);
7834 if (bnx2x_ilt_mem_op(bp
, ILT_MEMOP_ALLOC
))
7837 if (bnx2x_iov_alloc_mem(bp
))
7840 /* Slow path ring */
7841 BNX2X_PCI_ALLOC(bp
->spq
, &bp
->spq_mapping
, BCM_PAGE_SIZE
);
7844 BNX2X_PCI_ALLOC(bp
->eq_ring
, &bp
->eq_mapping
,
7845 BCM_PAGE_SIZE
* NUM_EQ_PAGES
);
7851 BNX2X_ERR("Can't allocate memory\n");
7856 * Init service functions
7859 int bnx2x_set_mac_one(struct bnx2x
*bp
, u8
*mac
,
7860 struct bnx2x_vlan_mac_obj
*obj
, bool set
,
7861 int mac_type
, unsigned long *ramrod_flags
)
7864 struct bnx2x_vlan_mac_ramrod_params ramrod_param
;
7866 memset(&ramrod_param
, 0, sizeof(ramrod_param
));
7868 /* Fill general parameters */
7869 ramrod_param
.vlan_mac_obj
= obj
;
7870 ramrod_param
.ramrod_flags
= *ramrod_flags
;
7872 /* Fill a user request section if needed */
7873 if (!test_bit(RAMROD_CONT
, ramrod_flags
)) {
7874 memcpy(ramrod_param
.user_req
.u
.mac
.mac
, mac
, ETH_ALEN
);
7876 __set_bit(mac_type
, &ramrod_param
.user_req
.vlan_mac_flags
);
7878 /* Set the command: ADD or DEL */
7880 ramrod_param
.user_req
.cmd
= BNX2X_VLAN_MAC_ADD
;
7882 ramrod_param
.user_req
.cmd
= BNX2X_VLAN_MAC_DEL
;
7885 rc
= bnx2x_config_vlan_mac(bp
, &ramrod_param
);
7887 if (rc
== -EEXIST
) {
7888 DP(BNX2X_MSG_SP
, "Failed to schedule ADD operations: %d\n", rc
);
7889 /* do not treat adding same MAC as error */
7892 BNX2X_ERR("%s MAC failed\n", (set
? "Set" : "Del"));
7897 int bnx2x_del_all_macs(struct bnx2x
*bp
,
7898 struct bnx2x_vlan_mac_obj
*mac_obj
,
7899 int mac_type
, bool wait_for_comp
)
7902 unsigned long ramrod_flags
= 0, vlan_mac_flags
= 0;
7904 /* Wait for completion of requested */
7906 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
7908 /* Set the mac type of addresses we want to clear */
7909 __set_bit(mac_type
, &vlan_mac_flags
);
7911 rc
= mac_obj
->delete_all(bp
, mac_obj
, &vlan_mac_flags
, &ramrod_flags
);
7913 BNX2X_ERR("Failed to delete MACs: %d\n", rc
);
7918 int bnx2x_set_eth_mac(struct bnx2x
*bp
, bool set
)
7920 unsigned long ramrod_flags
= 0;
7922 if (is_zero_ether_addr(bp
->dev
->dev_addr
) &&
7923 (IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
))) {
7924 DP(NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
,
7925 "Ignoring Zero MAC for STORAGE SD mode\n");
7929 DP(NETIF_MSG_IFUP
, "Adding Eth MAC\n");
7931 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
7932 /* Eth MAC is set on RSS leading client (fp[0]) */
7933 return bnx2x_set_mac_one(bp
, bp
->dev
->dev_addr
, &bp
->sp_objs
->mac_obj
,
7934 set
, BNX2X_ETH_MAC
, &ramrod_flags
);
7937 int bnx2x_setup_leading(struct bnx2x
*bp
)
7939 return bnx2x_setup_queue(bp
, &bp
->fp
[0], 1);
7943 * bnx2x_set_int_mode - configure interrupt mode
7945 * @bp: driver handle
7947 * In case of MSI-X it will also try to enable MSI-X.
7949 int bnx2x_set_int_mode(struct bnx2x
*bp
)
7953 if (IS_VF(bp
) && int_mode
!= BNX2X_INT_MODE_MSIX
)
7957 case BNX2X_INT_MODE_MSIX
:
7958 /* attempt to enable msix */
7959 rc
= bnx2x_enable_msix(bp
);
7965 /* vfs use only msix */
7966 if (rc
&& IS_VF(bp
))
7969 /* failed to enable multiple MSI-X */
7970 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7972 1 + bp
->num_cnic_queues
);
7974 /* falling through... */
7975 case BNX2X_INT_MODE_MSI
:
7976 bnx2x_enable_msi(bp
);
7978 /* falling through... */
7979 case BNX2X_INT_MODE_INTX
:
7980 bp
->num_ethernet_queues
= 1;
7981 bp
->num_queues
= bp
->num_ethernet_queues
+ bp
->num_cnic_queues
;
7982 BNX2X_DEV_INFO("set number of queues to 1\n");
7985 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
7991 /* must be called prior to any HW initializations */
7992 static inline u16
bnx2x_cid_ilt_lines(struct bnx2x
*bp
)
7995 return (BNX2X_FIRST_VF_CID
+ BNX2X_VF_CIDS
)/ILT_PAGE_CIDS
;
7996 return L2_ILT_LINES(bp
);
7999 void bnx2x_ilt_set_info(struct bnx2x
*bp
)
8001 struct ilt_client_info
*ilt_client
;
8002 struct bnx2x_ilt
*ilt
= BP_ILT(bp
);
8005 ilt
->start_line
= FUNC_ILT_BASE(BP_FUNC(bp
));
8006 DP(BNX2X_MSG_SP
, "ilt starts at line %d\n", ilt
->start_line
);
8009 ilt_client
= &ilt
->clients
[ILT_CLIENT_CDU
];
8010 ilt_client
->client_num
= ILT_CLIENT_CDU
;
8011 ilt_client
->page_size
= CDU_ILT_PAGE_SZ
;
8012 ilt_client
->flags
= ILT_CLIENT_SKIP_MEM
;
8013 ilt_client
->start
= line
;
8014 line
+= bnx2x_cid_ilt_lines(bp
);
8016 if (CNIC_SUPPORT(bp
))
8017 line
+= CNIC_ILT_LINES
;
8018 ilt_client
->end
= line
- 1;
8020 DP(NETIF_MSG_IFUP
, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8023 ilt_client
->page_size
,
8025 ilog2(ilt_client
->page_size
>> 12));
8028 if (QM_INIT(bp
->qm_cid_count
)) {
8029 ilt_client
= &ilt
->clients
[ILT_CLIENT_QM
];
8030 ilt_client
->client_num
= ILT_CLIENT_QM
;
8031 ilt_client
->page_size
= QM_ILT_PAGE_SZ
;
8032 ilt_client
->flags
= 0;
8033 ilt_client
->start
= line
;
8035 /* 4 bytes for each cid */
8036 line
+= DIV_ROUND_UP(bp
->qm_cid_count
* QM_QUEUES_PER_FUNC
* 4,
8039 ilt_client
->end
= line
- 1;
8042 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8045 ilt_client
->page_size
,
8047 ilog2(ilt_client
->page_size
>> 12));
8051 if (CNIC_SUPPORT(bp
)) {
8053 ilt_client
= &ilt
->clients
[ILT_CLIENT_SRC
];
8054 ilt_client
->client_num
= ILT_CLIENT_SRC
;
8055 ilt_client
->page_size
= SRC_ILT_PAGE_SZ
;
8056 ilt_client
->flags
= 0;
8057 ilt_client
->start
= line
;
8058 line
+= SRC_ILT_LINES
;
8059 ilt_client
->end
= line
- 1;
8062 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8065 ilt_client
->page_size
,
8067 ilog2(ilt_client
->page_size
>> 12));
8070 ilt_client
= &ilt
->clients
[ILT_CLIENT_TM
];
8071 ilt_client
->client_num
= ILT_CLIENT_TM
;
8072 ilt_client
->page_size
= TM_ILT_PAGE_SZ
;
8073 ilt_client
->flags
= 0;
8074 ilt_client
->start
= line
;
8075 line
+= TM_ILT_LINES
;
8076 ilt_client
->end
= line
- 1;
8079 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8082 ilt_client
->page_size
,
8084 ilog2(ilt_client
->page_size
>> 12));
8087 BUG_ON(line
> ILT_MAX_LINES
);
8091 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8093 * @bp: driver handle
8094 * @fp: pointer to fastpath
8095 * @init_params: pointer to parameters structure
8097 * parameters configured:
8098 * - HC configuration
8099 * - Queue's CDU context
8101 static void bnx2x_pf_q_prep_init(struct bnx2x
*bp
,
8102 struct bnx2x_fastpath
*fp
, struct bnx2x_queue_init_params
*init_params
)
8106 int cxt_index
, cxt_offset
;
8108 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8109 if (!IS_FCOE_FP(fp
)) {
8110 __set_bit(BNX2X_Q_FLG_HC
, &init_params
->rx
.flags
);
8111 __set_bit(BNX2X_Q_FLG_HC
, &init_params
->tx
.flags
);
8113 /* If HC is supporterd, enable host coalescing in the transition
8116 __set_bit(BNX2X_Q_FLG_HC_EN
, &init_params
->rx
.flags
);
8117 __set_bit(BNX2X_Q_FLG_HC_EN
, &init_params
->tx
.flags
);
8120 init_params
->rx
.hc_rate
= bp
->rx_ticks
?
8121 (1000000 / bp
->rx_ticks
) : 0;
8122 init_params
->tx
.hc_rate
= bp
->tx_ticks
?
8123 (1000000 / bp
->tx_ticks
) : 0;
8126 init_params
->rx
.fw_sb_id
= init_params
->tx
.fw_sb_id
=
8130 * CQ index among the SB indices: FCoE clients uses the default
8131 * SB, therefore it's different.
8133 init_params
->rx
.sb_cq_index
= HC_INDEX_ETH_RX_CQ_CONS
;
8134 init_params
->tx
.sb_cq_index
= HC_INDEX_ETH_FIRST_TX_CQ_CONS
;
8137 /* set maximum number of COSs supported by this queue */
8138 init_params
->max_cos
= fp
->max_cos
;
8140 DP(NETIF_MSG_IFUP
, "fp: %d setting queue params max cos to: %d\n",
8141 fp
->index
, init_params
->max_cos
);
8143 /* set the context pointers queue object */
8144 for (cos
= FIRST_TX_COS_INDEX
; cos
< init_params
->max_cos
; cos
++) {
8145 cxt_index
= fp
->txdata_ptr
[cos
]->cid
/ ILT_PAGE_CIDS
;
8146 cxt_offset
= fp
->txdata_ptr
[cos
]->cid
- (cxt_index
*
8148 init_params
->cxts
[cos
] =
8149 &bp
->context
[cxt_index
].vcxt
[cxt_offset
].eth
;
8153 static int bnx2x_setup_tx_only(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
8154 struct bnx2x_queue_state_params
*q_params
,
8155 struct bnx2x_queue_setup_tx_only_params
*tx_only_params
,
8156 int tx_index
, bool leading
)
8158 memset(tx_only_params
, 0, sizeof(*tx_only_params
));
8160 /* Set the command */
8161 q_params
->cmd
= BNX2X_Q_CMD_SETUP_TX_ONLY
;
8163 /* Set tx-only QUEUE flags: don't zero statistics */
8164 tx_only_params
->flags
= bnx2x_get_common_flags(bp
, fp
, false);
8166 /* choose the index of the cid to send the slow path on */
8167 tx_only_params
->cid_index
= tx_index
;
8169 /* Set general TX_ONLY_SETUP parameters */
8170 bnx2x_pf_q_prep_general(bp
, fp
, &tx_only_params
->gen_params
, tx_index
);
8172 /* Set Tx TX_ONLY_SETUP parameters */
8173 bnx2x_pf_tx_q_prep(bp
, fp
, &tx_only_params
->txq_params
, tx_index
);
8176 "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",
8177 tx_index
, q_params
->q_obj
->cids
[FIRST_TX_COS_INDEX
],
8178 q_params
->q_obj
->cids
[tx_index
], q_params
->q_obj
->cl_id
,
8179 tx_only_params
->gen_params
.spcl_id
, tx_only_params
->flags
);
8181 /* send the ramrod */
8182 return bnx2x_queue_state_change(bp
, q_params
);
8187 * bnx2x_setup_queue - setup queue
8189 * @bp: driver handle
8190 * @fp: pointer to fastpath
8191 * @leading: is leading
8193 * This function performs 2 steps in a Queue state machine
8194 * actually: 1) RESET->INIT 2) INIT->SETUP
8197 int bnx2x_setup_queue(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
8200 struct bnx2x_queue_state_params q_params
= {NULL
};
8201 struct bnx2x_queue_setup_params
*setup_params
=
8202 &q_params
.params
.setup
;
8203 struct bnx2x_queue_setup_tx_only_params
*tx_only_params
=
8204 &q_params
.params
.tx_only
;
8208 DP(NETIF_MSG_IFUP
, "setting up queue %d\n", fp
->index
);
8210 /* reset IGU state skip FCoE L2 queue */
8211 if (!IS_FCOE_FP(fp
))
8212 bnx2x_ack_sb(bp
, fp
->igu_sb_id
, USTORM_ID
, 0,
8215 q_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
8216 /* We want to wait for completion in this context */
8217 __set_bit(RAMROD_COMP_WAIT
, &q_params
.ramrod_flags
);
8219 /* Prepare the INIT parameters */
8220 bnx2x_pf_q_prep_init(bp
, fp
, &q_params
.params
.init
);
8222 /* Set the command */
8223 q_params
.cmd
= BNX2X_Q_CMD_INIT
;
8225 /* Change the state to INIT */
8226 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8228 BNX2X_ERR("Queue(%d) INIT failed\n", fp
->index
);
8232 DP(NETIF_MSG_IFUP
, "init complete\n");
8235 /* Now move the Queue to the SETUP state... */
8236 memset(setup_params
, 0, sizeof(*setup_params
));
8238 /* Set QUEUE flags */
8239 setup_params
->flags
= bnx2x_get_q_flags(bp
, fp
, leading
);
8241 /* Set general SETUP parameters */
8242 bnx2x_pf_q_prep_general(bp
, fp
, &setup_params
->gen_params
,
8243 FIRST_TX_COS_INDEX
);
8245 bnx2x_pf_rx_q_prep(bp
, fp
, &setup_params
->pause_params
,
8246 &setup_params
->rxq_params
);
8248 bnx2x_pf_tx_q_prep(bp
, fp
, &setup_params
->txq_params
,
8249 FIRST_TX_COS_INDEX
);
8251 /* Set the command */
8252 q_params
.cmd
= BNX2X_Q_CMD_SETUP
;
8255 bp
->fcoe_init
= true;
8257 /* Change the state to SETUP */
8258 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8260 BNX2X_ERR("Queue(%d) SETUP failed\n", fp
->index
);
8264 /* loop through the relevant tx-only indices */
8265 for (tx_index
= FIRST_TX_ONLY_COS_INDEX
;
8266 tx_index
< fp
->max_cos
;
8269 /* prepare and send tx-only ramrod*/
8270 rc
= bnx2x_setup_tx_only(bp
, fp
, &q_params
,
8271 tx_only_params
, tx_index
, leading
);
8273 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8274 fp
->index
, tx_index
);
8282 static int bnx2x_stop_queue(struct bnx2x
*bp
, int index
)
8284 struct bnx2x_fastpath
*fp
= &bp
->fp
[index
];
8285 struct bnx2x_fp_txdata
*txdata
;
8286 struct bnx2x_queue_state_params q_params
= {NULL
};
8289 DP(NETIF_MSG_IFDOWN
, "stopping queue %d cid %d\n", index
, fp
->cid
);
8291 q_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
8292 /* We want to wait for completion in this context */
8293 __set_bit(RAMROD_COMP_WAIT
, &q_params
.ramrod_flags
);
8296 /* close tx-only connections */
8297 for (tx_index
= FIRST_TX_ONLY_COS_INDEX
;
8298 tx_index
< fp
->max_cos
;
8301 /* ascertain this is a normal queue*/
8302 txdata
= fp
->txdata_ptr
[tx_index
];
8304 DP(NETIF_MSG_IFDOWN
, "stopping tx-only queue %d\n",
8307 /* send halt terminate on tx-only connection */
8308 q_params
.cmd
= BNX2X_Q_CMD_TERMINATE
;
8309 memset(&q_params
.params
.terminate
, 0,
8310 sizeof(q_params
.params
.terminate
));
8311 q_params
.params
.terminate
.cid_index
= tx_index
;
8313 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8317 /* send halt terminate on tx-only connection */
8318 q_params
.cmd
= BNX2X_Q_CMD_CFC_DEL
;
8319 memset(&q_params
.params
.cfc_del
, 0,
8320 sizeof(q_params
.params
.cfc_del
));
8321 q_params
.params
.cfc_del
.cid_index
= tx_index
;
8322 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8326 /* Stop the primary connection: */
8327 /* ...halt the connection */
8328 q_params
.cmd
= BNX2X_Q_CMD_HALT
;
8329 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8333 /* ...terminate the connection */
8334 q_params
.cmd
= BNX2X_Q_CMD_TERMINATE
;
8335 memset(&q_params
.params
.terminate
, 0,
8336 sizeof(q_params
.params
.terminate
));
8337 q_params
.params
.terminate
.cid_index
= FIRST_TX_COS_INDEX
;
8338 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8341 /* ...delete cfc entry */
8342 q_params
.cmd
= BNX2X_Q_CMD_CFC_DEL
;
8343 memset(&q_params
.params
.cfc_del
, 0,
8344 sizeof(q_params
.params
.cfc_del
));
8345 q_params
.params
.cfc_del
.cid_index
= FIRST_TX_COS_INDEX
;
8346 return bnx2x_queue_state_change(bp
, &q_params
);
8350 static void bnx2x_reset_func(struct bnx2x
*bp
)
8352 int port
= BP_PORT(bp
);
8353 int func
= BP_FUNC(bp
);
8356 /* Disable the function in the FW */
8357 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_FUNC_EN_OFFSET(func
), 0);
8358 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_FUNC_EN_OFFSET(func
), 0);
8359 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_FUNC_EN_OFFSET(func
), 0);
8360 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_FUNC_EN_OFFSET(func
), 0);
8363 for_each_eth_queue(bp
, i
) {
8364 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
8365 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8366 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp
->fw_sb_id
),
8370 if (CNIC_LOADED(bp
))
8372 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8373 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8374 (bnx2x_cnic_fw_sb_id(bp
)), SB_DISABLED
);
8377 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8378 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func
),
8381 for (i
= 0; i
< XSTORM_SPQ_DATA_SIZE
/ 4; i
++)
8382 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_DATA_OFFSET(func
),
8386 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
8387 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
8388 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
8390 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, 0);
8391 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, 0);
8394 if (CNIC_LOADED(bp
)) {
8395 /* Disable Timer scan */
8396 REG_WR(bp
, TM_REG_EN_LINEAR0_TIMER
+ port
*4, 0);
8398 * Wait for at least 10ms and up to 2 second for the timers
8401 for (i
= 0; i
< 200; i
++) {
8403 if (!REG_RD(bp
, TM_REG_LIN0_SCAN_ON
+ port
*4))
8408 bnx2x_clear_func_ilt(bp
, func
);
8410 /* Timers workaround bug for E2: if this is vnic-3,
8411 * we need to set the entire ilt range for this timers.
8413 if (!CHIP_IS_E1x(bp
) && BP_VN(bp
) == 3) {
8414 struct ilt_client_info ilt_cli
;
8415 /* use dummy TM client */
8416 memset(&ilt_cli
, 0, sizeof(struct ilt_client_info
));
8418 ilt_cli
.end
= ILT_NUM_PAGE_ENTRIES
- 1;
8419 ilt_cli
.client_num
= ILT_CLIENT_TM
;
8421 bnx2x_ilt_boundry_init_op(bp
, &ilt_cli
, 0, INITOP_CLEAR
);
8424 /* this assumes that reset_port() called before reset_func()*/
8425 if (!CHIP_IS_E1x(bp
))
8426 bnx2x_pf_disable(bp
);
8431 static void bnx2x_reset_port(struct bnx2x
*bp
)
8433 int port
= BP_PORT(bp
);
8436 /* Reset physical Link */
8437 bnx2x__link_reset(bp
);
8439 REG_WR(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4, 0);
8441 /* Do not rcv packets to BRB */
8442 REG_WR(bp
, NIG_REG_LLH0_BRB1_DRV_MASK
+ port
*4, 0x0);
8443 /* Do not direct rcv packets that are not for MCP to the BRB */
8444 REG_WR(bp
, (port
? NIG_REG_LLH1_BRB1_NOT_MCP
:
8445 NIG_REG_LLH0_BRB1_NOT_MCP
), 0x0);
8448 REG_WR(bp
, MISC_REG_AEU_MASK_ATTN_FUNC_0
+ port
*4, 0);
8451 /* Check for BRB port occupancy */
8452 val
= REG_RD(bp
, BRB1_REG_PORT_NUM_OCC_BLOCKS_0
+ port
*4);
8454 DP(NETIF_MSG_IFDOWN
,
8455 "BRB1 is not empty %d blocks are occupied\n", val
);
8457 /* TODO: Close Doorbell port? */
8460 static int bnx2x_reset_hw(struct bnx2x
*bp
, u32 load_code
)
8462 struct bnx2x_func_state_params func_params
= {NULL
};
8464 /* Prepare parameters for function state transitions */
8465 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
8467 func_params
.f_obj
= &bp
->func_obj
;
8468 func_params
.cmd
= BNX2X_F_CMD_HW_RESET
;
8470 func_params
.params
.hw_init
.load_phase
= load_code
;
8472 return bnx2x_func_state_change(bp
, &func_params
);
8475 static int bnx2x_func_stop(struct bnx2x
*bp
)
8477 struct bnx2x_func_state_params func_params
= {NULL
};
8480 /* Prepare parameters for function state transitions */
8481 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
8482 func_params
.f_obj
= &bp
->func_obj
;
8483 func_params
.cmd
= BNX2X_F_CMD_STOP
;
8486 * Try to stop the function the 'good way'. If fails (in case
8487 * of a parity error during bnx2x_chip_cleanup()) and we are
8488 * not in a debug mode, perform a state transaction in order to
8489 * enable further HW_RESET transaction.
8491 rc
= bnx2x_func_state_change(bp
, &func_params
);
8493 #ifdef BNX2X_STOP_ON_ERROR
8496 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
8497 __set_bit(RAMROD_DRV_CLR_ONLY
, &func_params
.ramrod_flags
);
8498 return bnx2x_func_state_change(bp
, &func_params
);
8506 * bnx2x_send_unload_req - request unload mode from the MCP.
8508 * @bp: driver handle
8509 * @unload_mode: requested function's unload mode
8511 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8513 u32
bnx2x_send_unload_req(struct bnx2x
*bp
, int unload_mode
)
8516 int port
= BP_PORT(bp
);
8518 /* Select the UNLOAD request mode */
8519 if (unload_mode
== UNLOAD_NORMAL
)
8520 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
;
8522 else if (bp
->flags
& NO_WOL_FLAG
)
8523 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
;
8526 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
8527 u8
*mac_addr
= bp
->dev
->dev_addr
;
8531 /* The mac address is written to entries 1-4 to
8532 * preserve entry 0 which is used by the PMF
8534 u8 entry
= (BP_VN(bp
) + 1)*8;
8536 val
= (mac_addr
[0] << 8) | mac_addr
[1];
8537 EMAC_WR(bp
, EMAC_REG_EMAC_MAC_MATCH
+ entry
, val
);
8539 val
= (mac_addr
[2] << 24) | (mac_addr
[3] << 16) |
8540 (mac_addr
[4] << 8) | mac_addr
[5];
8541 EMAC_WR(bp
, EMAC_REG_EMAC_MAC_MATCH
+ entry
+ 4, val
);
8543 /* Enable the PME and clear the status */
8544 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &pmc
);
8545 pmc
|= PCI_PM_CTRL_PME_ENABLE
| PCI_PM_CTRL_PME_STATUS
;
8546 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, pmc
);
8548 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_EN
;
8551 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
;
8553 /* Send the request to the MCP */
8555 reset_code
= bnx2x_fw_command(bp
, reset_code
, 0);
8557 int path
= BP_PATH(bp
);
8559 DP(NETIF_MSG_IFDOWN
, "NO MCP - load counts[%d] %d, %d, %d\n",
8560 path
, load_count
[path
][0], load_count
[path
][1],
8561 load_count
[path
][2]);
8562 load_count
[path
][0]--;
8563 load_count
[path
][1 + port
]--;
8564 DP(NETIF_MSG_IFDOWN
, "NO MCP - new load counts[%d] %d, %d, %d\n",
8565 path
, load_count
[path
][0], load_count
[path
][1],
8566 load_count
[path
][2]);
8567 if (load_count
[path
][0] == 0)
8568 reset_code
= FW_MSG_CODE_DRV_UNLOAD_COMMON
;
8569 else if (load_count
[path
][1 + port
] == 0)
8570 reset_code
= FW_MSG_CODE_DRV_UNLOAD_PORT
;
8572 reset_code
= FW_MSG_CODE_DRV_UNLOAD_FUNCTION
;
8579 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8581 * @bp: driver handle
8582 * @keep_link: true iff link should be kept up
8584 void bnx2x_send_unload_done(struct bnx2x
*bp
, bool keep_link
)
8586 u32 reset_param
= keep_link
? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET
: 0;
8588 /* Report UNLOAD_DONE to MCP */
8590 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
, reset_param
);
8593 static int bnx2x_func_wait_started(struct bnx2x
*bp
)
8596 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
8602 * (assumption: No Attention from MCP at this stage)
8603 * PMF probably in the middle of TXdisable/enable transaction
8604 * 1. Sync IRS for default SB
8605 * 2. Sync SP queue - this guarantes us that attention handling started
8606 * 3. Wait, that TXdisable/enable transaction completes
8608 * 1+2 guranty that if DCBx attention was scheduled it already changed
8609 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8610 * received complettion for the transaction the state is TX_STOPPED.
8611 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8615 /* make sure default SB ISR is done */
8617 synchronize_irq(bp
->msix_table
[0].vector
);
8619 synchronize_irq(bp
->pdev
->irq
);
8621 flush_workqueue(bnx2x_wq
);
8623 while (bnx2x_func_get_state(bp
, &bp
->func_obj
) !=
8624 BNX2X_F_STATE_STARTED
&& tout
--)
8627 if (bnx2x_func_get_state(bp
, &bp
->func_obj
) !=
8628 BNX2X_F_STATE_STARTED
) {
8629 #ifdef BNX2X_STOP_ON_ERROR
8630 BNX2X_ERR("Wrong function state\n");
8634 * Failed to complete the transaction in a "good way"
8635 * Force both transactions with CLR bit
8637 struct bnx2x_func_state_params func_params
= {NULL
};
8639 DP(NETIF_MSG_IFDOWN
,
8640 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
8642 func_params
.f_obj
= &bp
->func_obj
;
8643 __set_bit(RAMROD_DRV_CLR_ONLY
,
8644 &func_params
.ramrod_flags
);
8646 /* STARTED-->TX_ST0PPED */
8647 func_params
.cmd
= BNX2X_F_CMD_TX_STOP
;
8648 bnx2x_func_state_change(bp
, &func_params
);
8650 /* TX_ST0PPED-->STARTED */
8651 func_params
.cmd
= BNX2X_F_CMD_TX_START
;
8652 return bnx2x_func_state_change(bp
, &func_params
);
8659 void bnx2x_chip_cleanup(struct bnx2x
*bp
, int unload_mode
, bool keep_link
)
8661 int port
= BP_PORT(bp
);
8664 struct bnx2x_mcast_ramrod_params rparam
= {NULL
};
8667 /* Wait until tx fastpath tasks complete */
8668 for_each_tx_queue(bp
, i
) {
8669 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
8671 for_each_cos_in_tx_queue(fp
, cos
)
8672 rc
= bnx2x_clean_tx_queue(bp
, fp
->txdata_ptr
[cos
]);
8673 #ifdef BNX2X_STOP_ON_ERROR
8679 /* Give HW time to discard old tx messages */
8680 usleep_range(1000, 2000);
8682 /* Clean all ETH MACs */
8683 rc
= bnx2x_del_all_macs(bp
, &bp
->sp_objs
[0].mac_obj
, BNX2X_ETH_MAC
,
8686 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc
);
8688 /* Clean up UC list */
8689 rc
= bnx2x_del_all_macs(bp
, &bp
->sp_objs
[0].mac_obj
, BNX2X_UC_LIST_MAC
,
8692 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8696 if (!CHIP_IS_E1(bp
))
8697 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 0);
8699 /* Set "drop all" (stop Rx).
8700 * We need to take a netif_addr_lock() here in order to prevent
8701 * a race between the completion code and this code.
8703 netif_addr_lock_bh(bp
->dev
);
8704 /* Schedule the rx_mode command */
8705 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
))
8706 set_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
);
8708 bnx2x_set_storm_rx_mode(bp
);
8710 /* Cleanup multicast configuration */
8711 rparam
.mcast_obj
= &bp
->mcast_obj
;
8712 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_DEL
);
8714 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc
);
8716 netif_addr_unlock_bh(bp
->dev
);
8718 bnx2x_iov_chip_cleanup(bp
);
8722 * Send the UNLOAD_REQUEST to the MCP. This will return if
8723 * this function should perform FUNC, PORT or COMMON HW
8726 reset_code
= bnx2x_send_unload_req(bp
, unload_mode
);
8729 * (assumption: No Attention from MCP at this stage)
8730 * PMF probably in the middle of TXdisable/enable transaction
8732 rc
= bnx2x_func_wait_started(bp
);
8734 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8735 #ifdef BNX2X_STOP_ON_ERROR
8740 /* Close multi and leading connections
8741 * Completions for ramrods are collected in a synchronous way
8743 for_each_eth_queue(bp
, i
)
8744 if (bnx2x_stop_queue(bp
, i
))
8745 #ifdef BNX2X_STOP_ON_ERROR
8751 if (CNIC_LOADED(bp
)) {
8752 for_each_cnic_queue(bp
, i
)
8753 if (bnx2x_stop_queue(bp
, i
))
8754 #ifdef BNX2X_STOP_ON_ERROR
8761 /* If SP settings didn't get completed so far - something
8762 * very wrong has happen.
8764 if (!bnx2x_wait_sp_comp(bp
, ~0x0UL
))
8765 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
8767 #ifndef BNX2X_STOP_ON_ERROR
8770 rc
= bnx2x_func_stop(bp
);
8772 BNX2X_ERR("Function stop failed!\n");
8773 #ifdef BNX2X_STOP_ON_ERROR
8778 /* Disable HW interrupts, NAPI */
8779 bnx2x_netif_stop(bp
, 1);
8780 /* Delete all NAPI objects */
8781 bnx2x_del_all_napi(bp
);
8782 if (CNIC_LOADED(bp
))
8783 bnx2x_del_all_napi_cnic(bp
);
8788 /* Reset the chip */
8789 rc
= bnx2x_reset_hw(bp
, reset_code
);
8791 BNX2X_ERR("HW_RESET failed\n");
8794 /* Report UNLOAD_DONE to MCP */
8795 bnx2x_send_unload_done(bp
, keep_link
);
8798 void bnx2x_disable_close_the_gate(struct bnx2x
*bp
)
8802 DP(NETIF_MSG_IFDOWN
, "Disabling \"close the gates\"\n");
8804 if (CHIP_IS_E1(bp
)) {
8805 int port
= BP_PORT(bp
);
8806 u32 addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
8807 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
8809 val
= REG_RD(bp
, addr
);
8811 REG_WR(bp
, addr
, val
);
8813 val
= REG_RD(bp
, MISC_REG_AEU_GENERAL_MASK
);
8814 val
&= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK
|
8815 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK
);
8816 REG_WR(bp
, MISC_REG_AEU_GENERAL_MASK
, val
);
8820 /* Close gates #2, #3 and #4: */
8821 static void bnx2x_set_234_gates(struct bnx2x
*bp
, bool close
)
8825 /* Gates #2 and #4a are closed/opened for "not E1" only */
8826 if (!CHIP_IS_E1(bp
)) {
8828 REG_WR(bp
, PXP_REG_HST_DISCARD_DOORBELLS
, !!close
);
8830 REG_WR(bp
, PXP_REG_HST_DISCARD_INTERNAL_WRITES
, !!close
);
8834 if (CHIP_IS_E1x(bp
)) {
8835 /* Prevent interrupts from HC on both ports */
8836 val
= REG_RD(bp
, HC_REG_CONFIG_1
);
8837 REG_WR(bp
, HC_REG_CONFIG_1
,
8838 (!close
) ? (val
| HC_CONFIG_1_REG_BLOCK_DISABLE_1
) :
8839 (val
& ~(u32
)HC_CONFIG_1_REG_BLOCK_DISABLE_1
));
8841 val
= REG_RD(bp
, HC_REG_CONFIG_0
);
8842 REG_WR(bp
, HC_REG_CONFIG_0
,
8843 (!close
) ? (val
| HC_CONFIG_0_REG_BLOCK_DISABLE_0
) :
8844 (val
& ~(u32
)HC_CONFIG_0_REG_BLOCK_DISABLE_0
));
8846 /* Prevent incoming interrupts in IGU */
8847 val
= REG_RD(bp
, IGU_REG_BLOCK_CONFIGURATION
);
8849 REG_WR(bp
, IGU_REG_BLOCK_CONFIGURATION
,
8851 (val
| IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE
) :
8852 (val
& ~(u32
)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE
));
8855 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "%s gates #2, #3 and #4\n",
8856 close
? "closing" : "opening");
8860 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8862 static void bnx2x_clp_reset_prep(struct bnx2x
*bp
, u32
*magic_val
)
8864 /* Do some magic... */
8865 u32 val
= MF_CFG_RD(bp
, shared_mf_config
.clp_mb
);
8866 *magic_val
= val
& SHARED_MF_CLP_MAGIC
;
8867 MF_CFG_WR(bp
, shared_mf_config
.clp_mb
, val
| SHARED_MF_CLP_MAGIC
);
8871 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
8873 * @bp: driver handle
8874 * @magic_val: old value of the `magic' bit.
8876 static void bnx2x_clp_reset_done(struct bnx2x
*bp
, u32 magic_val
)
8878 /* Restore the `magic' bit value... */
8879 u32 val
= MF_CFG_RD(bp
, shared_mf_config
.clp_mb
);
8880 MF_CFG_WR(bp
, shared_mf_config
.clp_mb
,
8881 (val
& (~SHARED_MF_CLP_MAGIC
)) | magic_val
);
8885 * bnx2x_reset_mcp_prep - prepare for MCP reset.
8887 * @bp: driver handle
8888 * @magic_val: old value of 'magic' bit.
8890 * Takes care of CLP configurations.
8892 static void bnx2x_reset_mcp_prep(struct bnx2x
*bp
, u32
*magic_val
)
8895 u32 validity_offset
;
8897 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "Starting\n");
8899 /* Set `magic' bit in order to save MF config */
8900 if (!CHIP_IS_E1(bp
))
8901 bnx2x_clp_reset_prep(bp
, magic_val
);
8903 /* Get shmem offset */
8904 shmem
= REG_RD(bp
, MISC_REG_SHARED_MEM_ADDR
);
8906 offsetof(struct shmem_region
, validity_map
[BP_PORT(bp
)]);
8908 /* Clear validity map flags */
8910 REG_WR(bp
, shmem
+ validity_offset
, 0);
8913 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8914 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
8917 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
8919 * @bp: driver handle
8921 static void bnx2x_mcp_wait_one(struct bnx2x
*bp
)
8923 /* special handling for emulation and FPGA,
8924 wait 10 times longer */
8925 if (CHIP_REV_IS_SLOW(bp
))
8926 msleep(MCP_ONE_TIMEOUT
*10);
8928 msleep(MCP_ONE_TIMEOUT
);
8932 * initializes bp->common.shmem_base and waits for validity signature to appear
8934 static int bnx2x_init_shmem(struct bnx2x
*bp
)
8940 bp
->common
.shmem_base
= REG_RD(bp
, MISC_REG_SHARED_MEM_ADDR
);
8941 if (bp
->common
.shmem_base
) {
8942 val
= SHMEM_RD(bp
, validity_map
[BP_PORT(bp
)]);
8943 if (val
& SHR_MEM_VALIDITY_MB
)
8947 bnx2x_mcp_wait_one(bp
);
8949 } while (cnt
++ < (MCP_TIMEOUT
/ MCP_ONE_TIMEOUT
));
8951 BNX2X_ERR("BAD MCP validity signature\n");
8956 static int bnx2x_reset_mcp_comp(struct bnx2x
*bp
, u32 magic_val
)
8958 int rc
= bnx2x_init_shmem(bp
);
8960 /* Restore the `magic' bit value */
8961 if (!CHIP_IS_E1(bp
))
8962 bnx2x_clp_reset_done(bp
, magic_val
);
8967 static void bnx2x_pxp_prep(struct bnx2x
*bp
)
8969 if (!CHIP_IS_E1(bp
)) {
8970 REG_WR(bp
, PXP2_REG_RD_START_INIT
, 0);
8971 REG_WR(bp
, PXP2_REG_RQ_RBC_DONE
, 0);
8977 * Reset the whole chip except for:
8979 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8982 * - MISC (including AEU)
8986 static void bnx2x_process_kill_chip_reset(struct bnx2x
*bp
, bool global
)
8988 u32 not_reset_mask1
, reset_mask1
, not_reset_mask2
, reset_mask2
;
8989 u32 global_bits2
, stay_reset2
;
8992 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8993 * (per chip) blocks.
8996 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU
|
8997 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE
;
8999 /* Don't reset the following blocks.
9000 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9001 * reset, as in 4 port device they might still be owned
9002 * by the MCP (there is only one leader per path).
9005 MISC_REGISTERS_RESET_REG_1_RST_HC
|
9006 MISC_REGISTERS_RESET_REG_1_RST_PXPV
|
9007 MISC_REGISTERS_RESET_REG_1_RST_PXP
;
9010 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO
|
9011 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE
|
9012 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE
|
9013 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE
|
9014 MISC_REGISTERS_RESET_REG_2_RST_RBCN
|
9015 MISC_REGISTERS_RESET_REG_2_RST_GRC
|
9016 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE
|
9017 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B
|
9018 MISC_REGISTERS_RESET_REG_2_RST_ATC
|
9019 MISC_REGISTERS_RESET_REG_2_PGLC
|
9020 MISC_REGISTERS_RESET_REG_2_RST_BMAC0
|
9021 MISC_REGISTERS_RESET_REG_2_RST_BMAC1
|
9022 MISC_REGISTERS_RESET_REG_2_RST_EMAC0
|
9023 MISC_REGISTERS_RESET_REG_2_RST_EMAC1
|
9024 MISC_REGISTERS_RESET_REG_2_UMAC0
|
9025 MISC_REGISTERS_RESET_REG_2_UMAC1
;
9028 * Keep the following blocks in reset:
9029 * - all xxMACs are handled by the bnx2x_link code.
9032 MISC_REGISTERS_RESET_REG_2_XMAC
|
9033 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT
;
9035 /* Full reset masks according to the chip */
9036 reset_mask1
= 0xffffffff;
9039 reset_mask2
= 0xffff;
9040 else if (CHIP_IS_E1H(bp
))
9041 reset_mask2
= 0x1ffff;
9042 else if (CHIP_IS_E2(bp
))
9043 reset_mask2
= 0xfffff;
9044 else /* CHIP_IS_E3 */
9045 reset_mask2
= 0x3ffffff;
9047 /* Don't reset global blocks unless we need to */
9049 reset_mask2
&= ~global_bits2
;
9052 * In case of attention in the QM, we need to reset PXP
9053 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9054 * because otherwise QM reset would release 'close the gates' shortly
9055 * before resetting the PXP, then the PSWRQ would send a write
9056 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9057 * read the payload data from PSWWR, but PSWWR would not
9058 * respond. The write queue in PGLUE would stuck, dmae commands
9059 * would not return. Therefore it's important to reset the second
9060 * reset register (containing the
9061 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9062 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9065 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
9066 reset_mask2
& (~not_reset_mask2
));
9068 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
9069 reset_mask1
& (~not_reset_mask1
));
9074 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
,
9075 reset_mask2
& (~stay_reset2
));
9080 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, reset_mask1
);
9085 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9086 * It should get cleared in no more than 1s.
9088 * @bp: driver handle
9090 * It should get cleared in no more than 1s. Returns 0 if
9091 * pending writes bit gets cleared.
9093 static int bnx2x_er_poll_igu_vq(struct bnx2x
*bp
)
9099 pend_bits
= REG_RD(bp
, IGU_REG_PENDING_BITS_STATUS
);
9104 usleep_range(1000, 2000);
9105 } while (cnt
-- > 0);
9108 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9116 static int bnx2x_process_kill(struct bnx2x
*bp
, bool global
)
9120 u32 sr_cnt
, blk_cnt
, port_is_idle_0
, port_is_idle_1
, pgl_exp_rom2
;
9123 /* Empty the Tetris buffer, wait for 1s */
9125 sr_cnt
= REG_RD(bp
, PXP2_REG_RD_SR_CNT
);
9126 blk_cnt
= REG_RD(bp
, PXP2_REG_RD_BLK_CNT
);
9127 port_is_idle_0
= REG_RD(bp
, PXP2_REG_RD_PORT_IS_IDLE_0
);
9128 port_is_idle_1
= REG_RD(bp
, PXP2_REG_RD_PORT_IS_IDLE_1
);
9129 pgl_exp_rom2
= REG_RD(bp
, PXP2_REG_PGL_EXP_ROM2
);
9131 tags_63_32
= REG_RD(bp
, PGLUE_B_REG_TAGS_63_32
);
9133 if ((sr_cnt
== 0x7e) && (blk_cnt
== 0xa0) &&
9134 ((port_is_idle_0
& 0x1) == 0x1) &&
9135 ((port_is_idle_1
& 0x1) == 0x1) &&
9136 (pgl_exp_rom2
== 0xffffffff) &&
9137 (!CHIP_IS_E3(bp
) || (tags_63_32
== 0xffffffff)))
9139 usleep_range(1000, 2000);
9140 } while (cnt
-- > 0);
9143 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9144 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",
9145 sr_cnt
, blk_cnt
, port_is_idle_0
, port_is_idle_1
,
9152 /* Close gates #2, #3 and #4 */
9153 bnx2x_set_234_gates(bp
, true);
9155 /* Poll for IGU VQs for 57712 and newer chips */
9156 if (!CHIP_IS_E1x(bp
) && bnx2x_er_poll_igu_vq(bp
))
9160 /* TBD: Indicate that "process kill" is in progress to MCP */
9162 /* Clear "unprepared" bit */
9163 REG_WR(bp
, MISC_REG_UNPREPARED
, 0);
9166 /* Make sure all is written to the chip before the reset */
9169 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9170 * PSWHST, GRC and PSWRD Tetris buffer.
9172 usleep_range(1000, 2000);
9174 /* Prepare to chip reset: */
9177 bnx2x_reset_mcp_prep(bp
, &val
);
9183 /* reset the chip */
9184 bnx2x_process_kill_chip_reset(bp
, global
);
9187 /* Recover after reset: */
9189 if (global
&& bnx2x_reset_mcp_comp(bp
, val
))
9192 /* TBD: Add resetting the NO_MCP mode DB here */
9194 /* Open the gates #2, #3 and #4 */
9195 bnx2x_set_234_gates(bp
, false);
9197 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9198 * reset state, re-enable attentions. */
9203 static int bnx2x_leader_reset(struct bnx2x
*bp
)
9206 bool global
= bnx2x_reset_is_global(bp
);
9209 /* if not going to reset MCP - load "fake" driver to reset HW while
9210 * driver is owner of the HW
9212 if (!global
&& !BP_NOMCP(bp
)) {
9213 load_code
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_REQ
,
9214 DRV_MSG_CODE_LOAD_REQ_WITH_LFA
);
9216 BNX2X_ERR("MCP response failure, aborting\n");
9218 goto exit_leader_reset
;
9220 if ((load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
) &&
9221 (load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON
)) {
9222 BNX2X_ERR("MCP unexpected resp, aborting\n");
9224 goto exit_leader_reset2
;
9226 load_code
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
9228 BNX2X_ERR("MCP response failure, aborting\n");
9230 goto exit_leader_reset2
;
9234 /* Try to recover after the failure */
9235 if (bnx2x_process_kill(bp
, global
)) {
9236 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9239 goto exit_leader_reset2
;
9243 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9246 bnx2x_set_reset_done(bp
);
9248 bnx2x_clear_reset_global(bp
);
9251 /* unload "fake driver" if it was loaded */
9252 if (!global
&& !BP_NOMCP(bp
)) {
9253 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
, 0);
9254 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
, 0);
9258 bnx2x_release_leader_lock(bp
);
9263 static void bnx2x_recovery_failed(struct bnx2x
*bp
)
9265 netdev_err(bp
->dev
, "Recovery has failed. Power cycle is needed.\n");
9267 /* Disconnect this device */
9268 netif_device_detach(bp
->dev
);
9271 * Block ifup for all function on this engine until "process kill"
9274 bnx2x_set_reset_in_progress(bp
);
9276 /* Shut down the power */
9277 bnx2x_set_power_state(bp
, PCI_D3hot
);
9279 bp
->recovery_state
= BNX2X_RECOVERY_FAILED
;
9285 * Assumption: runs under rtnl lock. This together with the fact
9286 * that it's called only from bnx2x_sp_rtnl() ensure that it
9287 * will never be called when netif_running(bp->dev) is false.
9289 static void bnx2x_parity_recover(struct bnx2x
*bp
)
9291 bool global
= false;
9292 u32 error_recovered
, error_unrecovered
;
9295 DP(NETIF_MSG_HW
, "Handling parity\n");
9297 switch (bp
->recovery_state
) {
9298 case BNX2X_RECOVERY_INIT
:
9299 DP(NETIF_MSG_HW
, "State is BNX2X_RECOVERY_INIT\n");
9300 is_parity
= bnx2x_chk_parity_attn(bp
, &global
, false);
9301 WARN_ON(!is_parity
);
9303 /* Try to get a LEADER_LOCK HW lock */
9304 if (bnx2x_trylock_leader_lock(bp
)) {
9305 bnx2x_set_reset_in_progress(bp
);
9307 * Check if there is a global attention and if
9308 * there was a global attention, set the global
9313 bnx2x_set_reset_global(bp
);
9318 /* Stop the driver */
9319 /* If interface has been removed - break */
9320 if (bnx2x_nic_unload(bp
, UNLOAD_RECOVERY
, false))
9323 bp
->recovery_state
= BNX2X_RECOVERY_WAIT
;
9325 /* Ensure "is_leader", MCP command sequence and
9326 * "recovery_state" update values are seen on other
9332 case BNX2X_RECOVERY_WAIT
:
9333 DP(NETIF_MSG_HW
, "State is BNX2X_RECOVERY_WAIT\n");
9334 if (bp
->is_leader
) {
9335 int other_engine
= BP_PATH(bp
) ? 0 : 1;
9336 bool other_load_status
=
9337 bnx2x_get_load_status(bp
, other_engine
);
9339 bnx2x_get_load_status(bp
, BP_PATH(bp
));
9340 global
= bnx2x_reset_is_global(bp
);
9343 * In case of a parity in a global block, let
9344 * the first leader that performs a
9345 * leader_reset() reset the global blocks in
9346 * order to clear global attentions. Otherwise
9347 * the the gates will remain closed for that
9351 (global
&& other_load_status
)) {
9352 /* Wait until all other functions get
9355 schedule_delayed_work(&bp
->sp_rtnl_task
,
9359 /* If all other functions got down -
9360 * try to bring the chip back to
9361 * normal. In any case it's an exit
9362 * point for a leader.
9364 if (bnx2x_leader_reset(bp
)) {
9365 bnx2x_recovery_failed(bp
);
9369 /* If we are here, means that the
9370 * leader has succeeded and doesn't
9371 * want to be a leader any more. Try
9372 * to continue as a none-leader.
9376 } else { /* non-leader */
9377 if (!bnx2x_reset_is_done(bp
, BP_PATH(bp
))) {
9378 /* Try to get a LEADER_LOCK HW lock as
9379 * long as a former leader may have
9380 * been unloaded by the user or
9381 * released a leadership by another
9384 if (bnx2x_trylock_leader_lock(bp
)) {
9385 /* I'm a leader now! Restart a
9392 schedule_delayed_work(&bp
->sp_rtnl_task
,
9398 * If there was a global attention, wait
9399 * for it to be cleared.
9401 if (bnx2x_reset_is_global(bp
)) {
9402 schedule_delayed_work(
9409 bp
->eth_stats
.recoverable_error
;
9411 bp
->eth_stats
.unrecoverable_error
;
9412 bp
->recovery_state
=
9413 BNX2X_RECOVERY_NIC_LOADING
;
9414 if (bnx2x_nic_load(bp
, LOAD_NORMAL
)) {
9415 error_unrecovered
++;
9417 "Recovery failed. Power cycle needed\n");
9418 /* Disconnect this device */
9419 netif_device_detach(bp
->dev
);
9420 /* Shut down the power */
9421 bnx2x_set_power_state(
9425 bp
->recovery_state
=
9426 BNX2X_RECOVERY_DONE
;
9430 bp
->eth_stats
.recoverable_error
=
9432 bp
->eth_stats
.unrecoverable_error
=
9444 static int bnx2x_close(struct net_device
*dev
);
9446 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9447 * scheduled on a general queue in order to prevent a dead lock.
9449 static void bnx2x_sp_rtnl_task(struct work_struct
*work
)
9451 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, sp_rtnl_task
.work
);
9455 if (!netif_running(bp
->dev
)) {
9460 /* if stop on error is defined no recovery flows should be executed */
9461 #ifdef BNX2X_STOP_ON_ERROR
9462 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9463 "you will need to reboot when done\n");
9464 goto sp_rtnl_not_reset
;
9467 if (unlikely(bp
->recovery_state
!= BNX2X_RECOVERY_DONE
)) {
9469 * Clear all pending SP commands as we are going to reset the
9472 bp
->sp_rtnl_state
= 0;
9475 bnx2x_parity_recover(bp
);
9481 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT
, &bp
->sp_rtnl_state
)) {
9483 * Clear all pending SP commands as we are going to reset the
9486 bp
->sp_rtnl_state
= 0;
9489 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
, true);
9490 bnx2x_nic_load(bp
, LOAD_NORMAL
);
9495 #ifdef BNX2X_STOP_ON_ERROR
9498 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC
, &bp
->sp_rtnl_state
))
9499 bnx2x_setup_tc(bp
->dev
, bp
->dcbx_port_params
.ets
.num_of_cos
);
9500 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE
, &bp
->sp_rtnl_state
))
9501 bnx2x_after_function_update(bp
);
9503 * in case of fan failure we need to reset id if the "stop on error"
9504 * debug flag is set, since we trying to prevent permanent overheating
9507 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE
, &bp
->sp_rtnl_state
)) {
9508 DP(NETIF_MSG_HW
, "fan failure detected. Unloading driver\n");
9509 netif_device_detach(bp
->dev
);
9510 bnx2x_close(bp
->dev
);
9515 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST
, &bp
->sp_rtnl_state
)) {
9517 "sending set mcast vf pf channel message from rtnl sp-task\n");
9518 bnx2x_vfpf_set_mcast(bp
->dev
);
9521 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE
,
9522 &bp
->sp_rtnl_state
)) {
9524 "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
9525 bnx2x_vfpf_storm_rx_mode(bp
);
9528 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9529 * can be called from other contexts as well)
9533 /* enable SR-IOV if applicable */
9534 if (IS_SRIOV(bp
) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV
,
9535 &bp
->sp_rtnl_state
))
9536 bnx2x_enable_sriov(bp
);
9539 static void bnx2x_period_task(struct work_struct
*work
)
9541 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, period_task
.work
);
9543 if (!netif_running(bp
->dev
))
9544 goto period_task_exit
;
9546 if (CHIP_REV_IS_SLOW(bp
)) {
9547 BNX2X_ERR("period task called on emulation, ignoring\n");
9548 goto period_task_exit
;
9551 bnx2x_acquire_phy_lock(bp
);
9553 * The barrier is needed to ensure the ordering between the writing to
9554 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9559 bnx2x_period_func(&bp
->link_params
, &bp
->link_vars
);
9561 /* Re-queue task in 1 sec */
9562 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 1*HZ
);
9565 bnx2x_release_phy_lock(bp
);
9571 * Init service functions
9574 u32
bnx2x_get_pretend_reg(struct bnx2x
*bp
)
9576 u32 base
= PXP2_REG_PGL_PRETEND_FUNC_F0
;
9577 u32 stride
= PXP2_REG_PGL_PRETEND_FUNC_F1
- base
;
9578 return base
+ (BP_ABS_FUNC(bp
)) * stride
;
9581 static void bnx2x_prev_unload_close_mac(struct bnx2x
*bp
,
9582 struct bnx2x_mac_vals
*vals
)
9584 u32 val
, base_addr
, offset
, mask
, reset_reg
;
9585 bool mac_stopped
= false;
9586 u8 port
= BP_PORT(bp
);
9588 /* reset addresses as they also mark which values were changed */
9589 vals
->bmac_addr
= 0;
9590 vals
->umac_addr
= 0;
9591 vals
->xmac_addr
= 0;
9592 vals
->emac_addr
= 0;
9594 reset_reg
= REG_RD(bp
, MISC_REG_RESET_REG_2
);
9596 if (!CHIP_IS_E3(bp
)) {
9597 val
= REG_RD(bp
, NIG_REG_BMAC0_REGS_OUT_EN
+ port
* 4);
9598 mask
= MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
;
9599 if ((mask
& reset_reg
) && val
) {
9601 BNX2X_DEV_INFO("Disable bmac Rx\n");
9602 base_addr
= BP_PORT(bp
) ? NIG_REG_INGRESS_BMAC1_MEM
9603 : NIG_REG_INGRESS_BMAC0_MEM
;
9604 offset
= CHIP_IS_E2(bp
) ? BIGMAC2_REGISTER_BMAC_CONTROL
9605 : BIGMAC_REGISTER_BMAC_CONTROL
;
9608 * use rd/wr since we cannot use dmae. This is safe
9609 * since MCP won't access the bus due to the request
9610 * to unload, and no function on the path can be
9611 * loaded at this time.
9613 wb_data
[0] = REG_RD(bp
, base_addr
+ offset
);
9614 wb_data
[1] = REG_RD(bp
, base_addr
+ offset
+ 0x4);
9615 vals
->bmac_addr
= base_addr
+ offset
;
9616 vals
->bmac_val
[0] = wb_data
[0];
9617 vals
->bmac_val
[1] = wb_data
[1];
9618 wb_data
[0] &= ~BMAC_CONTROL_RX_ENABLE
;
9619 REG_WR(bp
, vals
->bmac_addr
, wb_data
[0]);
9620 REG_WR(bp
, vals
->bmac_addr
+ 0x4, wb_data
[1]);
9623 BNX2X_DEV_INFO("Disable emac Rx\n");
9624 vals
->emac_addr
= NIG_REG_NIG_EMAC0_EN
+ BP_PORT(bp
)*4;
9625 vals
->emac_val
= REG_RD(bp
, vals
->emac_addr
);
9626 REG_WR(bp
, vals
->emac_addr
, 0);
9629 if (reset_reg
& MISC_REGISTERS_RESET_REG_2_XMAC
) {
9630 BNX2X_DEV_INFO("Disable xmac Rx\n");
9631 base_addr
= BP_PORT(bp
) ? GRCBASE_XMAC1
: GRCBASE_XMAC0
;
9632 val
= REG_RD(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
);
9633 REG_WR(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
,
9635 REG_WR(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
,
9637 vals
->xmac_addr
= base_addr
+ XMAC_REG_CTRL
;
9638 vals
->xmac_val
= REG_RD(bp
, vals
->xmac_addr
);
9639 REG_WR(bp
, vals
->xmac_addr
, 0);
9642 mask
= MISC_REGISTERS_RESET_REG_2_UMAC0
<< port
;
9643 if (mask
& reset_reg
) {
9644 BNX2X_DEV_INFO("Disable umac Rx\n");
9645 base_addr
= BP_PORT(bp
) ? GRCBASE_UMAC1
: GRCBASE_UMAC0
;
9646 vals
->umac_addr
= base_addr
+ UMAC_REG_COMMAND_CONFIG
;
9647 vals
->umac_val
= REG_RD(bp
, vals
->umac_addr
);
9648 REG_WR(bp
, vals
->umac_addr
, 0);
9658 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9659 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9660 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9661 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9663 static void bnx2x_prev_unload_undi_inc(struct bnx2x
*bp
, u8 port
, u8 inc
)
9666 u32 tmp_reg
= REG_RD(bp
, BNX2X_PREV_UNDI_PROD_ADDR(port
));
9668 rcq
= BNX2X_PREV_UNDI_RCQ(tmp_reg
) + inc
;
9669 bd
= BNX2X_PREV_UNDI_BD(tmp_reg
) + inc
;
9671 tmp_reg
= BNX2X_PREV_UNDI_PROD(rcq
, bd
);
9672 REG_WR(bp
, BNX2X_PREV_UNDI_PROD_ADDR(port
), tmp_reg
);
9674 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9678 static int bnx2x_prev_mcp_done(struct bnx2x
*bp
)
9680 u32 rc
= bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
,
9681 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET
);
9683 BNX2X_ERR("MCP response failure, aborting\n");
9690 static struct bnx2x_prev_path_list
*
9691 bnx2x_prev_path_get_entry(struct bnx2x
*bp
)
9693 struct bnx2x_prev_path_list
*tmp_list
;
9695 list_for_each_entry(tmp_list
, &bnx2x_prev_list
, list
)
9696 if (PCI_SLOT(bp
->pdev
->devfn
) == tmp_list
->slot
&&
9697 bp
->pdev
->bus
->number
== tmp_list
->bus
&&
9698 BP_PATH(bp
) == tmp_list
->path
)
9704 static bool bnx2x_prev_is_path_marked(struct bnx2x
*bp
)
9706 struct bnx2x_prev_path_list
*tmp_list
;
9709 if (down_trylock(&bnx2x_prev_sem
))
9712 list_for_each_entry(tmp_list
, &bnx2x_prev_list
, list
) {
9713 if (PCI_SLOT(bp
->pdev
->devfn
) == tmp_list
->slot
&&
9714 bp
->pdev
->bus
->number
== tmp_list
->bus
&&
9715 BP_PATH(bp
) == tmp_list
->path
) {
9717 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9723 up(&bnx2x_prev_sem
);
9728 static int bnx2x_prev_mark_path(struct bnx2x
*bp
, bool after_undi
)
9730 struct bnx2x_prev_path_list
*tmp_list
;
9733 tmp_list
= kmalloc(sizeof(struct bnx2x_prev_path_list
), GFP_KERNEL
);
9735 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9739 tmp_list
->bus
= bp
->pdev
->bus
->number
;
9740 tmp_list
->slot
= PCI_SLOT(bp
->pdev
->devfn
);
9741 tmp_list
->path
= BP_PATH(bp
);
9742 tmp_list
->undi
= after_undi
? (1 << BP_PORT(bp
)) : 0;
9744 rc
= down_interruptible(&bnx2x_prev_sem
);
9746 BNX2X_ERR("Received %d when tried to take lock\n", rc
);
9749 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9751 list_add(&tmp_list
->list
, &bnx2x_prev_list
);
9752 up(&bnx2x_prev_sem
);
9758 static int bnx2x_do_flr(struct bnx2x
*bp
)
9762 struct pci_dev
*dev
= bp
->pdev
;
9765 if (CHIP_IS_E1x(bp
)) {
9766 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9770 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9771 if (bp
->common
.bc_ver
< REQ_BC_VER_4_INITIATE_FLR
) {
9772 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9777 /* Wait for Transaction Pending bit clean */
9778 for (i
= 0; i
< 4; i
++) {
9780 msleep((1 << (i
- 1)) * 100);
9782 pcie_capability_read_word(dev
, PCI_EXP_DEVSTA
, &status
);
9783 if (!(status
& PCI_EXP_DEVSTA_TRPND
))
9788 "transaction is not cleared; proceeding with reset anyway\n");
9792 BNX2X_DEV_INFO("Initiating FLR\n");
9793 bnx2x_fw_command(bp
, DRV_MSG_CODE_INITIATE_FLR
, 0);
9798 static int bnx2x_prev_unload_uncommon(struct bnx2x
*bp
)
9802 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9804 /* Test if previous unload process was already finished for this path */
9805 if (bnx2x_prev_is_path_marked(bp
))
9806 return bnx2x_prev_mcp_done(bp
);
9808 BNX2X_DEV_INFO("Path is unmarked\n");
9810 /* If function has FLR capabilities, and existing FW version matches
9811 * the one required, then FLR will be sufficient to clean any residue
9812 * left by previous driver
9814 rc
= bnx2x_nic_load_analyze_req(bp
, FW_MSG_CODE_DRV_LOAD_FUNCTION
);
9817 /* fw version is good */
9818 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9819 rc
= bnx2x_do_flr(bp
);
9823 /* FLR was performed */
9824 BNX2X_DEV_INFO("FLR successful\n");
9828 BNX2X_DEV_INFO("Could not FLR\n");
9830 /* Close the MCP request, return failure*/
9831 rc
= bnx2x_prev_mcp_done(bp
);
9833 rc
= BNX2X_PREV_WAIT_NEEDED
;
9838 static int bnx2x_prev_unload_common(struct bnx2x
*bp
)
9840 u32 reset_reg
, tmp_reg
= 0, rc
;
9841 bool prev_undi
= false;
9842 struct bnx2x_mac_vals mac_vals
;
9844 /* It is possible a previous function received 'common' answer,
9845 * but hasn't loaded yet, therefore creating a scenario of
9846 * multiple functions receiving 'common' on the same path.
9848 BNX2X_DEV_INFO("Common unload Flow\n");
9850 memset(&mac_vals
, 0, sizeof(mac_vals
));
9852 if (bnx2x_prev_is_path_marked(bp
))
9853 return bnx2x_prev_mcp_done(bp
);
9855 reset_reg
= REG_RD(bp
, MISC_REG_RESET_REG_1
);
9857 /* Reset should be performed after BRB is emptied */
9858 if (reset_reg
& MISC_REGISTERS_RESET_REG_1_RST_BRB1
) {
9859 u32 timer_count
= 1000;
9861 /* Close the MAC Rx to prevent BRB from filling up */
9862 bnx2x_prev_unload_close_mac(bp
, &mac_vals
);
9864 /* close LLH filters towards the BRB */
9865 bnx2x_set_rx_filter(&bp
->link_params
, 0);
9867 /* Check if the UNDI driver was previously loaded
9868 * UNDI driver initializes CID offset for normal bell to 0x7
9870 if (reset_reg
& MISC_REGISTERS_RESET_REG_1_RST_DORQ
) {
9871 tmp_reg
= REG_RD(bp
, DORQ_REG_NORM_CID_OFST
);
9872 if (tmp_reg
== 0x7) {
9873 BNX2X_DEV_INFO("UNDI previously loaded\n");
9875 /* clear the UNDI indication */
9876 REG_WR(bp
, DORQ_REG_NORM_CID_OFST
, 0);
9877 /* clear possible idle check errors */
9878 REG_RD(bp
, NIG_REG_NIG_INT_STS_CLR_0
);
9881 /* wait until BRB is empty */
9882 tmp_reg
= REG_RD(bp
, BRB1_REG_NUM_OF_FULL_BLOCKS
);
9883 while (timer_count
) {
9884 u32 prev_brb
= tmp_reg
;
9886 tmp_reg
= REG_RD(bp
, BRB1_REG_NUM_OF_FULL_BLOCKS
);
9890 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg
);
9892 /* reset timer as long as BRB actually gets emptied */
9893 if (prev_brb
> tmp_reg
)
9898 /* If UNDI resides in memory, manually increment it */
9900 bnx2x_prev_unload_undi_inc(bp
, BP_PORT(bp
), 1);
9906 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9910 /* No packets are in the pipeline, path is ready for reset */
9911 bnx2x_reset_common(bp
);
9913 if (mac_vals
.xmac_addr
)
9914 REG_WR(bp
, mac_vals
.xmac_addr
, mac_vals
.xmac_val
);
9915 if (mac_vals
.umac_addr
)
9916 REG_WR(bp
, mac_vals
.umac_addr
, mac_vals
.umac_val
);
9917 if (mac_vals
.emac_addr
)
9918 REG_WR(bp
, mac_vals
.emac_addr
, mac_vals
.emac_val
);
9919 if (mac_vals
.bmac_addr
) {
9920 REG_WR(bp
, mac_vals
.bmac_addr
, mac_vals
.bmac_val
[0]);
9921 REG_WR(bp
, mac_vals
.bmac_addr
+ 4, mac_vals
.bmac_val
[1]);
9924 rc
= bnx2x_prev_mark_path(bp
, prev_undi
);
9926 bnx2x_prev_mcp_done(bp
);
9930 return bnx2x_prev_mcp_done(bp
);
9933 /* previous driver DMAE transaction may have occurred when pre-boot stage ended
9934 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9935 * the addresses of the transaction, resulting in was-error bit set in the pci
9936 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9937 * to clear the interrupt which detected this from the pglueb and the was done
9940 static void bnx2x_prev_interrupted_dmae(struct bnx2x
*bp
)
9942 if (!CHIP_IS_E1x(bp
)) {
9943 u32 val
= REG_RD(bp
, PGLUE_B_REG_PGLUE_B_INT_STS
);
9944 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN
) {
9946 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
9947 REG_WR(bp
, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR
,
9953 static int bnx2x_prev_unload(struct bnx2x
*bp
)
9955 int time_counter
= 10;
9956 u32 rc
, fw
, hw_lock_reg
, hw_lock_val
;
9957 struct bnx2x_prev_path_list
*prev_list
;
9958 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9960 /* clear hw from errors which may have resulted from an interrupted
9963 bnx2x_prev_interrupted_dmae(bp
);
9965 /* Release previously held locks */
9966 hw_lock_reg
= (BP_FUNC(bp
) <= 5) ?
9967 (MISC_REG_DRIVER_CONTROL_1
+ BP_FUNC(bp
) * 8) :
9968 (MISC_REG_DRIVER_CONTROL_7
+ (BP_FUNC(bp
) - 6) * 8);
9970 hw_lock_val
= (REG_RD(bp
, hw_lock_reg
));
9972 if (hw_lock_val
& HW_LOCK_RESOURCE_NVRAM
) {
9973 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9974 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
9975 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1
<< BP_PORT(bp
)));
9978 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9979 REG_WR(bp
, hw_lock_reg
, 0xffffffff);
9981 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9983 if (MCPR_ACCESS_LOCK_LOCK
& REG_RD(bp
, MCP_REG_MCPR_ACCESS_LOCK
)) {
9984 BNX2X_DEV_INFO("Release previously held alr\n");
9985 REG_WR(bp
, MCP_REG_MCPR_ACCESS_LOCK
, 0);
9989 /* Lock MCP using an unload request */
9990 fw
= bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
, 0);
9992 BNX2X_ERR("MCP response failure, aborting\n");
9997 if (fw
== FW_MSG_CODE_DRV_UNLOAD_COMMON
) {
9998 rc
= bnx2x_prev_unload_common(bp
);
10002 /* non-common reply from MCP night require looping */
10003 rc
= bnx2x_prev_unload_uncommon(bp
);
10004 if (rc
!= BNX2X_PREV_WAIT_NEEDED
)
10008 } while (--time_counter
);
10010 if (!time_counter
|| rc
) {
10011 BNX2X_ERR("Failed unloading previous driver, aborting\n");
10015 /* Mark function if its port was used to boot from SAN */
10016 prev_list
= bnx2x_prev_path_get_entry(bp
);
10017 if (prev_list
&& (prev_list
->undi
& (1 << BP_PORT(bp
))))
10018 bp
->link_params
.feature_config_flags
|=
10019 FEATURE_CONFIG_BOOT_FROM_SAN
;
10021 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc
);
10026 static void bnx2x_get_common_hwinfo(struct bnx2x
*bp
)
10028 u32 val
, val2
, val3
, val4
, id
, boot_mode
;
10031 /* Get the chip revision id and number. */
10032 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10033 val
= REG_RD(bp
, MISC_REG_CHIP_NUM
);
10034 id
= ((val
& 0xffff) << 16);
10035 val
= REG_RD(bp
, MISC_REG_CHIP_REV
);
10036 id
|= ((val
& 0xf) << 12);
10037 val
= REG_RD(bp
, MISC_REG_CHIP_METAL
);
10038 id
|= ((val
& 0xff) << 4);
10039 val
= REG_RD(bp
, MISC_REG_BOND_ID
);
10041 bp
->common
.chip_id
= id
;
10043 /* force 57811 according to MISC register */
10044 if (REG_RD(bp
, MISC_REG_CHIP_TYPE
) & MISC_REG_CHIP_TYPE_57811_MASK
) {
10045 if (CHIP_IS_57810(bp
))
10046 bp
->common
.chip_id
= (CHIP_NUM_57811
<< 16) |
10047 (bp
->common
.chip_id
& 0x0000FFFF);
10048 else if (CHIP_IS_57810_MF(bp
))
10049 bp
->common
.chip_id
= (CHIP_NUM_57811_MF
<< 16) |
10050 (bp
->common
.chip_id
& 0x0000FFFF);
10051 bp
->common
.chip_id
|= 0x1;
10054 /* Set doorbell size */
10055 bp
->db_size
= (1 << BNX2X_DB_SHIFT
);
10057 if (!CHIP_IS_E1x(bp
)) {
10058 val
= REG_RD(bp
, MISC_REG_PORT4MODE_EN_OVWR
);
10059 if ((val
& 1) == 0)
10060 val
= REG_RD(bp
, MISC_REG_PORT4MODE_EN
);
10062 val
= (val
>> 1) & 1;
10063 BNX2X_DEV_INFO("chip is in %s\n", val
? "4_PORT_MODE" :
10065 bp
->common
.chip_port_mode
= val
? CHIP_4_PORT_MODE
:
10068 if (CHIP_MODE_IS_4_PORT(bp
))
10069 bp
->pfid
= (bp
->pf_num
>> 1); /* 0..3 */
10071 bp
->pfid
= (bp
->pf_num
& 0x6); /* 0, 2, 4, 6 */
10073 bp
->common
.chip_port_mode
= CHIP_PORT_MODE_NONE
; /* N/A */
10074 bp
->pfid
= bp
->pf_num
; /* 0..7 */
10077 BNX2X_DEV_INFO("pf_id: %x", bp
->pfid
);
10079 bp
->link_params
.chip_id
= bp
->common
.chip_id
;
10080 BNX2X_DEV_INFO("chip ID is 0x%x\n", id
);
10082 val
= (REG_RD(bp
, 0x2874) & 0x55);
10083 if ((bp
->common
.chip_id
& 0x1) ||
10084 (CHIP_IS_E1(bp
) && val
) || (CHIP_IS_E1H(bp
) && (val
== 0x55))) {
10085 bp
->flags
|= ONE_PORT_FLAG
;
10086 BNX2X_DEV_INFO("single port device\n");
10089 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_CFG4
);
10090 bp
->common
.flash_size
= (BNX2X_NVRAM_1MB_SIZE
<<
10091 (val
& MCPR_NVM_CFG4_FLASH_SIZE
));
10092 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10093 bp
->common
.flash_size
, bp
->common
.flash_size
);
10095 bnx2x_init_shmem(bp
);
10099 bp
->common
.shmem2_base
= REG_RD(bp
, (BP_PATH(bp
) ?
10100 MISC_REG_GENERIC_CR_1
:
10101 MISC_REG_GENERIC_CR_0
));
10103 bp
->link_params
.shmem_base
= bp
->common
.shmem_base
;
10104 bp
->link_params
.shmem2_base
= bp
->common
.shmem2_base
;
10105 if (SHMEM2_RD(bp
, size
) >
10106 (u32
)offsetof(struct shmem2_region
, lfa_host_addr
[BP_PORT(bp
)]))
10107 bp
->link_params
.lfa_base
=
10108 REG_RD(bp
, bp
->common
.shmem2_base
+
10109 (u32
)offsetof(struct shmem2_region
,
10110 lfa_host_addr
[BP_PORT(bp
)]));
10112 bp
->link_params
.lfa_base
= 0;
10113 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10114 bp
->common
.shmem_base
, bp
->common
.shmem2_base
);
10116 if (!bp
->common
.shmem_base
) {
10117 BNX2X_DEV_INFO("MCP not active\n");
10118 bp
->flags
|= NO_MCP_FLAG
;
10122 bp
->common
.hw_config
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.config
);
10123 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp
->common
.hw_config
);
10125 bp
->link_params
.hw_led_mode
= ((bp
->common
.hw_config
&
10126 SHARED_HW_CFG_LED_MODE_MASK
) >>
10127 SHARED_HW_CFG_LED_MODE_SHIFT
);
10129 bp
->link_params
.feature_config_flags
= 0;
10130 val
= SHMEM_RD(bp
, dev_info
.shared_feature_config
.config
);
10131 if (val
& SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED
)
10132 bp
->link_params
.feature_config_flags
|=
10133 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED
;
10135 bp
->link_params
.feature_config_flags
&=
10136 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED
;
10138 val
= SHMEM_RD(bp
, dev_info
.bc_rev
) >> 8;
10139 bp
->common
.bc_ver
= val
;
10140 BNX2X_DEV_INFO("bc_ver %X\n", val
);
10141 if (val
< BNX2X_BC_VER
) {
10142 /* for now only warn
10143 * later we might need to enforce this */
10144 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10145 BNX2X_BC_VER
, val
);
10147 bp
->link_params
.feature_config_flags
|=
10148 (val
>= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL
) ?
10149 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY
: 0;
10151 bp
->link_params
.feature_config_flags
|=
10152 (val
>= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL
) ?
10153 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY
: 0;
10154 bp
->link_params
.feature_config_flags
|=
10155 (val
>= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED
) ?
10156 FEATURE_CONFIG_BC_SUPPORTS_AFEX
: 0;
10157 bp
->link_params
.feature_config_flags
|=
10158 (val
>= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED
) ?
10159 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED
: 0;
10161 bp
->link_params
.feature_config_flags
|=
10162 (val
>= REQ_BC_VER_4_MT_SUPPORTED
) ?
10163 FEATURE_CONFIG_MT_SUPPORT
: 0;
10165 bp
->flags
|= (val
>= REQ_BC_VER_4_PFC_STATS_SUPPORTED
) ?
10166 BC_SUPPORTS_PFC_STATS
: 0;
10168 bp
->flags
|= (val
>= REQ_BC_VER_4_FCOE_FEATURES
) ?
10169 BC_SUPPORTS_FCOE_FEATURES
: 0;
10171 bp
->flags
|= (val
>= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF
) ?
10172 BC_SUPPORTS_DCBX_MSG_NON_PMF
: 0;
10173 boot_mode
= SHMEM_RD(bp
,
10174 dev_info
.port_feature_config
[BP_PORT(bp
)].mba_config
) &
10175 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK
;
10176 switch (boot_mode
) {
10177 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE
:
10178 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_PXE
;
10180 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB
:
10181 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_ISCSI
;
10183 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT
:
10184 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_FCOE
;
10186 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE
:
10187 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_NONE
;
10191 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_PMC
, &pmc
);
10192 bp
->flags
|= (pmc
& PCI_PM_CAP_PME_D3cold
) ? 0 : NO_WOL_FLAG
;
10194 BNX2X_DEV_INFO("%sWoL capable\n",
10195 (bp
->flags
& NO_WOL_FLAG
) ? "not " : "");
10197 val
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
);
10198 val2
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[4]);
10199 val3
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[8]);
10200 val4
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[12]);
10202 dev_info(&bp
->pdev
->dev
, "part number %X-%X-%X-%X\n",
10203 val
, val2
, val3
, val4
);
10206 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10207 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10209 static int bnx2x_get_igu_cam_info(struct bnx2x
*bp
)
10211 int pfid
= BP_FUNC(bp
);
10214 u8 fid
, igu_sb_cnt
= 0;
10216 bp
->igu_base_sb
= 0xff;
10217 if (CHIP_INT_MODE_IS_BC(bp
)) {
10218 int vn
= BP_VN(bp
);
10219 igu_sb_cnt
= bp
->igu_sb_cnt
;
10220 bp
->igu_base_sb
= (CHIP_MODE_IS_4_PORT(bp
) ? pfid
: vn
) *
10223 bp
->igu_dsb_id
= E1HVN_MAX
* FP_SB_MAX_E1x
+
10224 (CHIP_MODE_IS_4_PORT(bp
) ? pfid
: vn
);
10229 /* IGU in normal mode - read CAM */
10230 for (igu_sb_id
= 0; igu_sb_id
< IGU_REG_MAPPING_MEMORY_SIZE
;
10232 val
= REG_RD(bp
, IGU_REG_MAPPING_MEMORY
+ igu_sb_id
* 4);
10233 if (!(val
& IGU_REG_MAPPING_MEMORY_VALID
))
10235 fid
= IGU_FID(val
);
10236 if ((fid
& IGU_FID_ENCODE_IS_PF
)) {
10237 if ((fid
& IGU_FID_PF_NUM_MASK
) != pfid
)
10239 if (IGU_VEC(val
) == 0)
10240 /* default status block */
10241 bp
->igu_dsb_id
= igu_sb_id
;
10243 if (bp
->igu_base_sb
== 0xff)
10244 bp
->igu_base_sb
= igu_sb_id
;
10250 #ifdef CONFIG_PCI_MSI
10251 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10252 * optional that number of CAM entries will not be equal to the value
10253 * advertised in PCI.
10254 * Driver should use the minimal value of both as the actual status
10257 bp
->igu_sb_cnt
= min_t(int, bp
->igu_sb_cnt
, igu_sb_cnt
);
10260 if (igu_sb_cnt
== 0) {
10261 BNX2X_ERR("CAM configuration error\n");
10268 static void bnx2x_link_settings_supported(struct bnx2x
*bp
, u32 switch_cfg
)
10270 int cfg_size
= 0, idx
, port
= BP_PORT(bp
);
10272 /* Aggregation of supported attributes of all external phys */
10273 bp
->port
.supported
[0] = 0;
10274 bp
->port
.supported
[1] = 0;
10275 switch (bp
->link_params
.num_phys
) {
10277 bp
->port
.supported
[0] = bp
->link_params
.phy
[INT_PHY
].supported
;
10281 bp
->port
.supported
[0] = bp
->link_params
.phy
[EXT_PHY1
].supported
;
10285 if (bp
->link_params
.multi_phy_config
&
10286 PORT_HW_CFG_PHY_SWAPPED_ENABLED
) {
10287 bp
->port
.supported
[1] =
10288 bp
->link_params
.phy
[EXT_PHY1
].supported
;
10289 bp
->port
.supported
[0] =
10290 bp
->link_params
.phy
[EXT_PHY2
].supported
;
10292 bp
->port
.supported
[0] =
10293 bp
->link_params
.phy
[EXT_PHY1
].supported
;
10294 bp
->port
.supported
[1] =
10295 bp
->link_params
.phy
[EXT_PHY2
].supported
;
10301 if (!(bp
->port
.supported
[0] || bp
->port
.supported
[1])) {
10302 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
10304 dev_info
.port_hw_config
[port
].external_phy_config
),
10306 dev_info
.port_hw_config
[port
].external_phy_config2
));
10310 if (CHIP_IS_E3(bp
))
10311 bp
->port
.phy_addr
= REG_RD(bp
, MISC_REG_WC0_CTRL_PHY_ADDR
);
10313 switch (switch_cfg
) {
10314 case SWITCH_CFG_1G
:
10315 bp
->port
.phy_addr
= REG_RD(
10316 bp
, NIG_REG_SERDES0_CTRL_PHY_ADDR
+ port
*0x10);
10318 case SWITCH_CFG_10G
:
10319 bp
->port
.phy_addr
= REG_RD(
10320 bp
, NIG_REG_XGXS0_CTRL_PHY_ADDR
+ port
*0x18);
10323 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10324 bp
->port
.link_config
[0]);
10328 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp
->port
.phy_addr
);
10329 /* mask what we support according to speed_cap_mask per configuration */
10330 for (idx
= 0; idx
< cfg_size
; idx
++) {
10331 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10332 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF
))
10333 bp
->port
.supported
[idx
] &= ~SUPPORTED_10baseT_Half
;
10335 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10336 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL
))
10337 bp
->port
.supported
[idx
] &= ~SUPPORTED_10baseT_Full
;
10339 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10340 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF
))
10341 bp
->port
.supported
[idx
] &= ~SUPPORTED_100baseT_Half
;
10343 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10344 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL
))
10345 bp
->port
.supported
[idx
] &= ~SUPPORTED_100baseT_Full
;
10347 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10348 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
))
10349 bp
->port
.supported
[idx
] &= ~(SUPPORTED_1000baseT_Half
|
10350 SUPPORTED_1000baseT_Full
);
10352 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10353 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G
))
10354 bp
->port
.supported
[idx
] &= ~SUPPORTED_2500baseX_Full
;
10356 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10357 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
))
10358 bp
->port
.supported
[idx
] &= ~SUPPORTED_10000baseT_Full
;
10362 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp
->port
.supported
[0],
10363 bp
->port
.supported
[1]);
10366 static void bnx2x_link_settings_requested(struct bnx2x
*bp
)
10368 u32 link_config
, idx
, cfg_size
= 0;
10369 bp
->port
.advertising
[0] = 0;
10370 bp
->port
.advertising
[1] = 0;
10371 switch (bp
->link_params
.num_phys
) {
10380 for (idx
= 0; idx
< cfg_size
; idx
++) {
10381 bp
->link_params
.req_duplex
[idx
] = DUPLEX_FULL
;
10382 link_config
= bp
->port
.link_config
[idx
];
10383 switch (link_config
& PORT_FEATURE_LINK_SPEED_MASK
) {
10384 case PORT_FEATURE_LINK_SPEED_AUTO
:
10385 if (bp
->port
.supported
[idx
] & SUPPORTED_Autoneg
) {
10386 bp
->link_params
.req_line_speed
[idx
] =
10388 bp
->port
.advertising
[idx
] |=
10389 bp
->port
.supported
[idx
];
10390 if (bp
->link_params
.phy
[EXT_PHY1
].type
==
10391 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833
)
10392 bp
->port
.advertising
[idx
] |=
10393 (SUPPORTED_100baseT_Half
|
10394 SUPPORTED_100baseT_Full
);
10396 /* force 10G, no AN */
10397 bp
->link_params
.req_line_speed
[idx
] =
10399 bp
->port
.advertising
[idx
] |=
10400 (ADVERTISED_10000baseT_Full
|
10406 case PORT_FEATURE_LINK_SPEED_10M_FULL
:
10407 if (bp
->port
.supported
[idx
] & SUPPORTED_10baseT_Full
) {
10408 bp
->link_params
.req_line_speed
[idx
] =
10410 bp
->port
.advertising
[idx
] |=
10411 (ADVERTISED_10baseT_Full
|
10414 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10416 bp
->link_params
.speed_cap_mask
[idx
]);
10421 case PORT_FEATURE_LINK_SPEED_10M_HALF
:
10422 if (bp
->port
.supported
[idx
] & SUPPORTED_10baseT_Half
) {
10423 bp
->link_params
.req_line_speed
[idx
] =
10425 bp
->link_params
.req_duplex
[idx
] =
10427 bp
->port
.advertising
[idx
] |=
10428 (ADVERTISED_10baseT_Half
|
10431 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10433 bp
->link_params
.speed_cap_mask
[idx
]);
10438 case PORT_FEATURE_LINK_SPEED_100M_FULL
:
10439 if (bp
->port
.supported
[idx
] &
10440 SUPPORTED_100baseT_Full
) {
10441 bp
->link_params
.req_line_speed
[idx
] =
10443 bp
->port
.advertising
[idx
] |=
10444 (ADVERTISED_100baseT_Full
|
10447 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10449 bp
->link_params
.speed_cap_mask
[idx
]);
10454 case PORT_FEATURE_LINK_SPEED_100M_HALF
:
10455 if (bp
->port
.supported
[idx
] &
10456 SUPPORTED_100baseT_Half
) {
10457 bp
->link_params
.req_line_speed
[idx
] =
10459 bp
->link_params
.req_duplex
[idx
] =
10461 bp
->port
.advertising
[idx
] |=
10462 (ADVERTISED_100baseT_Half
|
10465 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10467 bp
->link_params
.speed_cap_mask
[idx
]);
10472 case PORT_FEATURE_LINK_SPEED_1G
:
10473 if (bp
->port
.supported
[idx
] &
10474 SUPPORTED_1000baseT_Full
) {
10475 bp
->link_params
.req_line_speed
[idx
] =
10477 bp
->port
.advertising
[idx
] |=
10478 (ADVERTISED_1000baseT_Full
|
10481 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10483 bp
->link_params
.speed_cap_mask
[idx
]);
10488 case PORT_FEATURE_LINK_SPEED_2_5G
:
10489 if (bp
->port
.supported
[idx
] &
10490 SUPPORTED_2500baseX_Full
) {
10491 bp
->link_params
.req_line_speed
[idx
] =
10493 bp
->port
.advertising
[idx
] |=
10494 (ADVERTISED_2500baseX_Full
|
10497 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10499 bp
->link_params
.speed_cap_mask
[idx
]);
10504 case PORT_FEATURE_LINK_SPEED_10G_CX4
:
10505 if (bp
->port
.supported
[idx
] &
10506 SUPPORTED_10000baseT_Full
) {
10507 bp
->link_params
.req_line_speed
[idx
] =
10509 bp
->port
.advertising
[idx
] |=
10510 (ADVERTISED_10000baseT_Full
|
10513 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10515 bp
->link_params
.speed_cap_mask
[idx
]);
10519 case PORT_FEATURE_LINK_SPEED_20G
:
10520 bp
->link_params
.req_line_speed
[idx
] = SPEED_20000
;
10524 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
10526 bp
->link_params
.req_line_speed
[idx
] =
10528 bp
->port
.advertising
[idx
] =
10529 bp
->port
.supported
[idx
];
10533 bp
->link_params
.req_flow_ctrl
[idx
] = (link_config
&
10534 PORT_FEATURE_FLOW_CONTROL_MASK
);
10535 if (bp
->link_params
.req_flow_ctrl
[idx
] ==
10536 BNX2X_FLOW_CTRL_AUTO
) {
10537 if (!(bp
->port
.supported
[idx
] & SUPPORTED_Autoneg
))
10538 bp
->link_params
.req_flow_ctrl
[idx
] =
10539 BNX2X_FLOW_CTRL_NONE
;
10541 bnx2x_set_requested_fc(bp
);
10544 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
10545 bp
->link_params
.req_line_speed
[idx
],
10546 bp
->link_params
.req_duplex
[idx
],
10547 bp
->link_params
.req_flow_ctrl
[idx
],
10548 bp
->port
.advertising
[idx
]);
10552 static void bnx2x_set_mac_buf(u8
*mac_buf
, u32 mac_lo
, u16 mac_hi
)
10554 __be16 mac_hi_be
= cpu_to_be16(mac_hi
);
10555 __be32 mac_lo_be
= cpu_to_be32(mac_lo
);
10556 memcpy(mac_buf
, &mac_hi_be
, sizeof(mac_hi_be
));
10557 memcpy(mac_buf
+ sizeof(mac_hi_be
), &mac_lo_be
, sizeof(mac_lo_be
));
10560 static void bnx2x_get_port_hwinfo(struct bnx2x
*bp
)
10562 int port
= BP_PORT(bp
);
10564 u32 ext_phy_type
, ext_phy_config
, eee_mode
;
10566 bp
->link_params
.bp
= bp
;
10567 bp
->link_params
.port
= port
;
10569 bp
->link_params
.lane_config
=
10570 SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].lane_config
);
10572 bp
->link_params
.speed_cap_mask
[0] =
10574 dev_info
.port_hw_config
[port
].speed_capability_mask
);
10575 bp
->link_params
.speed_cap_mask
[1] =
10577 dev_info
.port_hw_config
[port
].speed_capability_mask2
);
10578 bp
->port
.link_config
[0] =
10579 SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].link_config
);
10581 bp
->port
.link_config
[1] =
10582 SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].link_config2
);
10584 bp
->link_params
.multi_phy_config
=
10585 SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].multi_phy_config
);
10586 /* If the device is capable of WoL, set the default state according
10589 config
= SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].config
);
10590 bp
->wol
= (!(bp
->flags
& NO_WOL_FLAG
) &&
10591 (config
& PORT_FEATURE_WOL_ENABLED
));
10593 if ((config
& PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK
) ==
10594 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE
&& !IS_MF(bp
))
10595 bp
->flags
|= NO_ISCSI_FLAG
;
10596 if ((config
& PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK
) ==
10597 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI
&& !(IS_MF(bp
)))
10598 bp
->flags
|= NO_FCOE_FLAG
;
10600 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
10601 bp
->link_params
.lane_config
,
10602 bp
->link_params
.speed_cap_mask
[0],
10603 bp
->port
.link_config
[0]);
10605 bp
->link_params
.switch_cfg
= (bp
->port
.link_config
[0] &
10606 PORT_FEATURE_CONNECTED_SWITCH_MASK
);
10607 bnx2x_phy_probe(&bp
->link_params
);
10608 bnx2x_link_settings_supported(bp
, bp
->link_params
.switch_cfg
);
10610 bnx2x_link_settings_requested(bp
);
10613 * If connected directly, work with the internal PHY, otherwise, work
10614 * with the external PHY
10618 dev_info
.port_hw_config
[port
].external_phy_config
);
10619 ext_phy_type
= XGXS_EXT_PHY_TYPE(ext_phy_config
);
10620 if (ext_phy_type
== PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
)
10621 bp
->mdio
.prtad
= bp
->port
.phy_addr
;
10623 else if ((ext_phy_type
!= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE
) &&
10624 (ext_phy_type
!= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN
))
10626 XGXS_EXT_PHY_ADDR(ext_phy_config
);
10628 /* Configure link feature according to nvram value */
10629 eee_mode
= (((SHMEM_RD(bp
, dev_info
.
10630 port_feature_config
[port
].eee_power_mode
)) &
10631 PORT_FEAT_CFG_EEE_POWER_MODE_MASK
) >>
10632 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT
);
10633 if (eee_mode
!= PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED
) {
10634 bp
->link_params
.eee_mode
= EEE_MODE_ADV_LPI
|
10635 EEE_MODE_ENABLE_LPI
|
10636 EEE_MODE_OUTPUT_TIME
;
10638 bp
->link_params
.eee_mode
= 0;
10642 void bnx2x_get_iscsi_info(struct bnx2x
*bp
)
10644 u32 no_flags
= NO_ISCSI_FLAG
;
10645 int port
= BP_PORT(bp
);
10646 u32 max_iscsi_conn
= FW_ENCODE_32BIT_PATTERN
^ SHMEM_RD(bp
,
10647 drv_lic_key
[port
].max_iscsi_conn
);
10649 if (!CNIC_SUPPORT(bp
)) {
10650 bp
->flags
|= no_flags
;
10654 /* Get the number of maximum allowed iSCSI connections */
10655 bp
->cnic_eth_dev
.max_iscsi_conn
=
10656 (max_iscsi_conn
& BNX2X_MAX_ISCSI_INIT_CONN_MASK
) >>
10657 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT
;
10659 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10660 bp
->cnic_eth_dev
.max_iscsi_conn
);
10663 * If maximum allowed number of connections is zero -
10664 * disable the feature.
10666 if (!bp
->cnic_eth_dev
.max_iscsi_conn
)
10667 bp
->flags
|= no_flags
;
10671 static void bnx2x_get_ext_wwn_info(struct bnx2x
*bp
, int func
)
10674 bp
->cnic_eth_dev
.fcoe_wwn_port_name_hi
=
10675 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_port_name_upper
);
10676 bp
->cnic_eth_dev
.fcoe_wwn_port_name_lo
=
10677 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_port_name_lower
);
10680 bp
->cnic_eth_dev
.fcoe_wwn_node_name_hi
=
10681 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_node_name_upper
);
10682 bp
->cnic_eth_dev
.fcoe_wwn_node_name_lo
=
10683 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_node_name_lower
);
10685 static void bnx2x_get_fcoe_info(struct bnx2x
*bp
)
10687 int port
= BP_PORT(bp
);
10688 int func
= BP_ABS_FUNC(bp
);
10689 u32 max_fcoe_conn
= FW_ENCODE_32BIT_PATTERN
^ SHMEM_RD(bp
,
10690 drv_lic_key
[port
].max_fcoe_conn
);
10692 if (!CNIC_SUPPORT(bp
)) {
10693 bp
->flags
|= NO_FCOE_FLAG
;
10697 /* Get the number of maximum allowed FCoE connections */
10698 bp
->cnic_eth_dev
.max_fcoe_conn
=
10699 (max_fcoe_conn
& BNX2X_MAX_FCOE_INIT_CONN_MASK
) >>
10700 BNX2X_MAX_FCOE_INIT_CONN_SHIFT
;
10702 /* Read the WWN: */
10705 bp
->cnic_eth_dev
.fcoe_wwn_port_name_hi
=
10707 dev_info
.port_hw_config
[port
].
10708 fcoe_wwn_port_name_upper
);
10709 bp
->cnic_eth_dev
.fcoe_wwn_port_name_lo
=
10711 dev_info
.port_hw_config
[port
].
10712 fcoe_wwn_port_name_lower
);
10715 bp
->cnic_eth_dev
.fcoe_wwn_node_name_hi
=
10717 dev_info
.port_hw_config
[port
].
10718 fcoe_wwn_node_name_upper
);
10719 bp
->cnic_eth_dev
.fcoe_wwn_node_name_lo
=
10721 dev_info
.port_hw_config
[port
].
10722 fcoe_wwn_node_name_lower
);
10723 } else if (!IS_MF_SD(bp
)) {
10725 * Read the WWN info only if the FCoE feature is enabled for
10728 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp
) && !CHIP_IS_E1x(bp
))
10729 bnx2x_get_ext_wwn_info(bp
, func
);
10731 } else if (IS_MF_FCOE_SD(bp
) && !CHIP_IS_E1x(bp
)) {
10732 bnx2x_get_ext_wwn_info(bp
, func
);
10735 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp
->cnic_eth_dev
.max_fcoe_conn
);
10738 * If maximum allowed number of connections is zero -
10739 * disable the feature.
10741 if (!bp
->cnic_eth_dev
.max_fcoe_conn
)
10742 bp
->flags
|= NO_FCOE_FLAG
;
10745 static void bnx2x_get_cnic_info(struct bnx2x
*bp
)
10748 * iSCSI may be dynamically disabled but reading
10749 * info here we will decrease memory usage by driver
10750 * if the feature is disabled for good
10752 bnx2x_get_iscsi_info(bp
);
10753 bnx2x_get_fcoe_info(bp
);
10756 static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x
*bp
)
10759 int func
= BP_ABS_FUNC(bp
);
10760 int port
= BP_PORT(bp
);
10761 u8
*iscsi_mac
= bp
->cnic_eth_dev
.iscsi_mac
;
10762 u8
*fip_mac
= bp
->fip_mac
;
10765 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
10766 * FCoE MAC then the appropriate feature should be disabled.
10767 * In non SD mode features configuration comes from struct
10770 if (!IS_MF_SD(bp
) && !CHIP_IS_E1x(bp
)) {
10771 u32 cfg
= MF_CFG_RD(bp
, func_ext_config
[func
].func_cfg
);
10772 if (cfg
& MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD
) {
10773 val2
= MF_CFG_RD(bp
, func_ext_config
[func
].
10774 iscsi_mac_addr_upper
);
10775 val
= MF_CFG_RD(bp
, func_ext_config
[func
].
10776 iscsi_mac_addr_lower
);
10777 bnx2x_set_mac_buf(iscsi_mac
, val
, val2
);
10779 ("Read iSCSI MAC: %pM\n", iscsi_mac
);
10781 bp
->flags
|= NO_ISCSI_OOO_FLAG
| NO_ISCSI_FLAG
;
10784 if (cfg
& MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD
) {
10785 val2
= MF_CFG_RD(bp
, func_ext_config
[func
].
10786 fcoe_mac_addr_upper
);
10787 val
= MF_CFG_RD(bp
, func_ext_config
[func
].
10788 fcoe_mac_addr_lower
);
10789 bnx2x_set_mac_buf(fip_mac
, val
, val2
);
10791 ("Read FCoE L2 MAC: %pM\n", fip_mac
);
10793 bp
->flags
|= NO_FCOE_FLAG
;
10796 bp
->mf_ext_config
= cfg
;
10798 } else { /* SD MODE */
10799 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp
)) {
10800 /* use primary mac as iscsi mac */
10801 memcpy(iscsi_mac
, bp
->dev
->dev_addr
, ETH_ALEN
);
10803 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10805 ("Read iSCSI MAC: %pM\n", iscsi_mac
);
10806 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp
)) {
10807 /* use primary mac as fip mac */
10808 memcpy(fip_mac
, bp
->dev
->dev_addr
, ETH_ALEN
);
10809 BNX2X_DEV_INFO("SD FCoE MODE\n");
10811 ("Read FIP MAC: %pM\n", fip_mac
);
10815 if (IS_MF_STORAGE_SD(bp
))
10816 /* Zero primary MAC configuration */
10817 memset(bp
->dev
->dev_addr
, 0, ETH_ALEN
);
10819 if (IS_MF_FCOE_AFEX(bp
) || IS_MF_FCOE_SD(bp
))
10820 /* use FIP MAC as primary MAC */
10821 memcpy(bp
->dev
->dev_addr
, fip_mac
, ETH_ALEN
);
10824 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10826 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10828 bnx2x_set_mac_buf(iscsi_mac
, val
, val2
);
10830 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10831 fcoe_fip_mac_upper
);
10832 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10833 fcoe_fip_mac_lower
);
10834 bnx2x_set_mac_buf(fip_mac
, val
, val2
);
10837 /* Disable iSCSI OOO if MAC configuration is invalid. */
10838 if (!is_valid_ether_addr(iscsi_mac
)) {
10839 bp
->flags
|= NO_ISCSI_OOO_FLAG
| NO_ISCSI_FLAG
;
10840 memset(iscsi_mac
, 0, ETH_ALEN
);
10843 /* Disable FCoE if MAC configuration is invalid. */
10844 if (!is_valid_ether_addr(fip_mac
)) {
10845 bp
->flags
|= NO_FCOE_FLAG
;
10846 memset(bp
->fip_mac
, 0, ETH_ALEN
);
10850 static void bnx2x_get_mac_hwinfo(struct bnx2x
*bp
)
10853 int func
= BP_ABS_FUNC(bp
);
10854 int port
= BP_PORT(bp
);
10856 /* Zero primary MAC configuration */
10857 memset(bp
->dev
->dev_addr
, 0, ETH_ALEN
);
10859 if (BP_NOMCP(bp
)) {
10860 BNX2X_ERROR("warning: random MAC workaround active\n");
10861 eth_hw_addr_random(bp
->dev
);
10862 } else if (IS_MF(bp
)) {
10863 val2
= MF_CFG_RD(bp
, func_mf_config
[func
].mac_upper
);
10864 val
= MF_CFG_RD(bp
, func_mf_config
[func
].mac_lower
);
10865 if ((val2
!= FUNC_MF_CFG_UPPERMAC_DEFAULT
) &&
10866 (val
!= FUNC_MF_CFG_LOWERMAC_DEFAULT
))
10867 bnx2x_set_mac_buf(bp
->dev
->dev_addr
, val
, val2
);
10869 if (CNIC_SUPPORT(bp
))
10870 bnx2x_get_cnic_mac_hwinfo(bp
);
10872 /* in SF read MACs from port configuration */
10873 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_upper
);
10874 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_lower
);
10875 bnx2x_set_mac_buf(bp
->dev
->dev_addr
, val
, val2
);
10877 if (CNIC_SUPPORT(bp
))
10878 bnx2x_get_cnic_mac_hwinfo(bp
);
10881 memcpy(bp
->link_params
.mac_addr
, bp
->dev
->dev_addr
, ETH_ALEN
);
10883 if (!bnx2x_is_valid_ether_addr(bp
, bp
->dev
->dev_addr
))
10884 dev_err(&bp
->pdev
->dev
,
10885 "bad Ethernet MAC address configuration: %pM\n"
10886 "change it manually before bringing up the appropriate network interface\n",
10887 bp
->dev
->dev_addr
);
10890 static bool bnx2x_get_dropless_info(struct bnx2x
*bp
)
10895 if (IS_MF(bp
) && !CHIP_IS_E1x(bp
)) {
10896 /* Take function: tmp = func */
10897 tmp
= BP_ABS_FUNC(bp
);
10898 cfg
= MF_CFG_RD(bp
, func_ext_config
[tmp
].func_cfg
);
10899 cfg
= !!(cfg
& MACP_FUNC_CFG_PAUSE_ON_HOST_RING
);
10901 /* Take port: tmp = port */
10904 dev_info
.port_hw_config
[tmp
].generic_features
);
10905 cfg
= !!(cfg
& PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED
);
10910 static int bnx2x_get_hwinfo(struct bnx2x
*bp
)
10912 int /*abs*/func
= BP_ABS_FUNC(bp
);
10917 bnx2x_get_common_hwinfo(bp
);
10920 * initialize IGU parameters
10922 if (CHIP_IS_E1x(bp
)) {
10923 bp
->common
.int_block
= INT_BLOCK_HC
;
10925 bp
->igu_dsb_id
= DEF_SB_IGU_ID
;
10926 bp
->igu_base_sb
= 0;
10928 bp
->common
.int_block
= INT_BLOCK_IGU
;
10930 /* do not allow device reset during IGU info preocessing */
10931 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
10933 val
= REG_RD(bp
, IGU_REG_BLOCK_CONFIGURATION
);
10935 if (val
& IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
) {
10938 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10940 val
&= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
);
10941 REG_WR(bp
, IGU_REG_BLOCK_CONFIGURATION
, val
);
10942 REG_WR(bp
, IGU_REG_RESET_MEMORIES
, 0x7f);
10944 while (tout
&& REG_RD(bp
, IGU_REG_RESET_MEMORIES
)) {
10946 usleep_range(1000, 2000);
10949 if (REG_RD(bp
, IGU_REG_RESET_MEMORIES
)) {
10950 dev_err(&bp
->pdev
->dev
,
10951 "FORCING Normal Mode failed!!!\n");
10952 bnx2x_release_hw_lock(bp
,
10953 HW_LOCK_RESOURCE_RESET
);
10958 if (val
& IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
) {
10959 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
10960 bp
->common
.int_block
|= INT_BLOCK_MODE_BW_COMP
;
10962 BNX2X_DEV_INFO("IGU Normal Mode\n");
10964 rc
= bnx2x_get_igu_cam_info(bp
);
10965 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
10971 * set base FW non-default (fast path) status block id, this value is
10972 * used to initialize the fw_sb_id saved on the fp/queue structure to
10973 * determine the id used by the FW.
10975 if (CHIP_IS_E1x(bp
))
10976 bp
->base_fw_ndsb
= BP_PORT(bp
) * FP_SB_MAX_E1x
+ BP_L_ID(bp
);
10978 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10979 * the same queue are indicated on the same IGU SB). So we prefer
10980 * FW and IGU SBs to be the same value.
10982 bp
->base_fw_ndsb
= bp
->igu_base_sb
;
10984 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10985 "base_fw_ndsb %d\n", bp
->igu_dsb_id
, bp
->igu_base_sb
,
10986 bp
->igu_sb_cnt
, bp
->base_fw_ndsb
);
10989 * Initialize MF configuration
10996 if (!CHIP_IS_E1(bp
) && !BP_NOMCP(bp
)) {
10997 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10998 bp
->common
.shmem2_base
, SHMEM2_RD(bp
, size
),
10999 (u32
)offsetof(struct shmem2_region
, mf_cfg_addr
));
11001 if (SHMEM2_HAS(bp
, mf_cfg_addr
))
11002 bp
->common
.mf_cfg_base
= SHMEM2_RD(bp
, mf_cfg_addr
);
11004 bp
->common
.mf_cfg_base
= bp
->common
.shmem_base
+
11005 offsetof(struct shmem_region
, func_mb
) +
11006 E1H_FUNC_MAX
* sizeof(struct drv_func_mb
);
11008 * get mf configuration:
11009 * 1. existence of MF configuration
11010 * 2. MAC address must be legal (check only upper bytes)
11011 * for Switch-Independent mode;
11012 * OVLAN must be legal for Switch-Dependent mode
11013 * 3. SF_MODE configures specific MF mode
11015 if (bp
->common
.mf_cfg_base
!= SHMEM_MF_CFG_ADDR_NONE
) {
11016 /* get mf configuration */
11018 dev_info
.shared_feature_config
.config
);
11019 val
&= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK
;
11022 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT
:
11023 val
= MF_CFG_RD(bp
, func_mf_config
[func
].
11025 /* check for legal mac (upper bytes)*/
11026 if (val
!= 0xffff) {
11027 bp
->mf_mode
= MULTI_FUNCTION_SI
;
11028 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
11029 func_mf_config
[func
].config
);
11031 BNX2X_DEV_INFO("illegal MAC address for SI\n");
11033 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE
:
11034 if ((!CHIP_IS_E1x(bp
)) &&
11035 (MF_CFG_RD(bp
, func_mf_config
[func
].
11036 mac_upper
) != 0xffff) &&
11038 afex_driver_support
))) {
11039 bp
->mf_mode
= MULTI_FUNCTION_AFEX
;
11040 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
11041 func_mf_config
[func
].config
);
11043 BNX2X_DEV_INFO("can not configure afex mode\n");
11046 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED
:
11047 /* get OV configuration */
11048 val
= MF_CFG_RD(bp
,
11049 func_mf_config
[FUNC_0
].e1hov_tag
);
11050 val
&= FUNC_MF_CFG_E1HOV_TAG_MASK
;
11052 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
) {
11053 bp
->mf_mode
= MULTI_FUNCTION_SD
;
11054 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
11055 func_mf_config
[func
].config
);
11057 BNX2X_DEV_INFO("illegal OV for SD\n");
11060 /* Unknown configuration: reset mf_config */
11061 bp
->mf_config
[vn
] = 0;
11062 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val
);
11066 BNX2X_DEV_INFO("%s function mode\n",
11067 IS_MF(bp
) ? "multi" : "single");
11069 switch (bp
->mf_mode
) {
11070 case MULTI_FUNCTION_SD
:
11071 val
= MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
11072 FUNC_MF_CFG_E1HOV_TAG_MASK
;
11073 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
) {
11075 bp
->path_has_ovlan
= true;
11077 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11078 func
, bp
->mf_ov
, bp
->mf_ov
);
11080 dev_err(&bp
->pdev
->dev
,
11081 "No valid MF OV for func %d, aborting\n",
11086 case MULTI_FUNCTION_AFEX
:
11087 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func
);
11089 case MULTI_FUNCTION_SI
:
11090 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11095 dev_err(&bp
->pdev
->dev
,
11096 "VN %d is in a single function mode, aborting\n",
11103 /* check if other port on the path needs ovlan:
11104 * Since MF configuration is shared between ports
11105 * Possible mixed modes are only
11106 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11108 if (CHIP_MODE_IS_4_PORT(bp
) &&
11109 !bp
->path_has_ovlan
&&
11111 bp
->common
.mf_cfg_base
!= SHMEM_MF_CFG_ADDR_NONE
) {
11112 u8 other_port
= !BP_PORT(bp
);
11113 u8 other_func
= BP_PATH(bp
) + 2*other_port
;
11114 val
= MF_CFG_RD(bp
,
11115 func_mf_config
[other_func
].e1hov_tag
);
11116 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
)
11117 bp
->path_has_ovlan
= true;
11121 /* adjust igu_sb_cnt to MF for E1x */
11122 if (CHIP_IS_E1x(bp
) && IS_MF(bp
))
11123 bp
->igu_sb_cnt
/= E1HVN_MAX
;
11126 bnx2x_get_port_hwinfo(bp
);
11128 /* Get MAC addresses */
11129 bnx2x_get_mac_hwinfo(bp
);
11131 bnx2x_get_cnic_info(bp
);
11136 static void bnx2x_read_fwinfo(struct bnx2x
*bp
)
11138 int cnt
, i
, block_end
, rodi
;
11139 char vpd_start
[BNX2X_VPD_LEN
+1];
11140 char str_id_reg
[VENDOR_ID_LEN
+1];
11141 char str_id_cap
[VENDOR_ID_LEN
+1];
11143 char *vpd_extended_data
= NULL
;
11146 cnt
= pci_read_vpd(bp
->pdev
, 0, BNX2X_VPD_LEN
, vpd_start
);
11147 memset(bp
->fw_ver
, 0, sizeof(bp
->fw_ver
));
11149 if (cnt
< BNX2X_VPD_LEN
)
11150 goto out_not_found
;
11152 /* VPD RO tag should be first tag after identifier string, hence
11153 * we should be able to find it in first BNX2X_VPD_LEN chars
11155 i
= pci_vpd_find_tag(vpd_start
, 0, BNX2X_VPD_LEN
,
11156 PCI_VPD_LRDT_RO_DATA
);
11158 goto out_not_found
;
11160 block_end
= i
+ PCI_VPD_LRDT_TAG_SIZE
+
11161 pci_vpd_lrdt_size(&vpd_start
[i
]);
11163 i
+= PCI_VPD_LRDT_TAG_SIZE
;
11165 if (block_end
> BNX2X_VPD_LEN
) {
11166 vpd_extended_data
= kmalloc(block_end
, GFP_KERNEL
);
11167 if (vpd_extended_data
== NULL
)
11168 goto out_not_found
;
11170 /* read rest of vpd image into vpd_extended_data */
11171 memcpy(vpd_extended_data
, vpd_start
, BNX2X_VPD_LEN
);
11172 cnt
= pci_read_vpd(bp
->pdev
, BNX2X_VPD_LEN
,
11173 block_end
- BNX2X_VPD_LEN
,
11174 vpd_extended_data
+ BNX2X_VPD_LEN
);
11175 if (cnt
< (block_end
- BNX2X_VPD_LEN
))
11176 goto out_not_found
;
11177 vpd_data
= vpd_extended_data
;
11179 vpd_data
= vpd_start
;
11181 /* now vpd_data holds full vpd content in both cases */
11183 rodi
= pci_vpd_find_info_keyword(vpd_data
, i
, block_end
,
11184 PCI_VPD_RO_KEYWORD_MFR_ID
);
11186 goto out_not_found
;
11188 len
= pci_vpd_info_field_size(&vpd_data
[rodi
]);
11190 if (len
!= VENDOR_ID_LEN
)
11191 goto out_not_found
;
11193 rodi
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
11195 /* vendor specific info */
11196 snprintf(str_id_reg
, VENDOR_ID_LEN
+ 1, "%04x", PCI_VENDOR_ID_DELL
);
11197 snprintf(str_id_cap
, VENDOR_ID_LEN
+ 1, "%04X", PCI_VENDOR_ID_DELL
);
11198 if (!strncmp(str_id_reg
, &vpd_data
[rodi
], VENDOR_ID_LEN
) ||
11199 !strncmp(str_id_cap
, &vpd_data
[rodi
], VENDOR_ID_LEN
)) {
11201 rodi
= pci_vpd_find_info_keyword(vpd_data
, i
, block_end
,
11202 PCI_VPD_RO_KEYWORD_VENDOR0
);
11204 len
= pci_vpd_info_field_size(&vpd_data
[rodi
]);
11206 rodi
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
11208 if (len
< 32 && (len
+ rodi
) <= BNX2X_VPD_LEN
) {
11209 memcpy(bp
->fw_ver
, &vpd_data
[rodi
], len
);
11210 bp
->fw_ver
[len
] = ' ';
11213 kfree(vpd_extended_data
);
11217 kfree(vpd_extended_data
);
11221 static void bnx2x_set_modes_bitmap(struct bnx2x
*bp
)
11225 if (CHIP_REV_IS_FPGA(bp
))
11226 SET_FLAGS(flags
, MODE_FPGA
);
11227 else if (CHIP_REV_IS_EMUL(bp
))
11228 SET_FLAGS(flags
, MODE_EMUL
);
11230 SET_FLAGS(flags
, MODE_ASIC
);
11232 if (CHIP_MODE_IS_4_PORT(bp
))
11233 SET_FLAGS(flags
, MODE_PORT4
);
11235 SET_FLAGS(flags
, MODE_PORT2
);
11237 if (CHIP_IS_E2(bp
))
11238 SET_FLAGS(flags
, MODE_E2
);
11239 else if (CHIP_IS_E3(bp
)) {
11240 SET_FLAGS(flags
, MODE_E3
);
11241 if (CHIP_REV(bp
) == CHIP_REV_Ax
)
11242 SET_FLAGS(flags
, MODE_E3_A0
);
11243 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11244 SET_FLAGS(flags
, MODE_E3_B0
| MODE_COS3
);
11248 SET_FLAGS(flags
, MODE_MF
);
11249 switch (bp
->mf_mode
) {
11250 case MULTI_FUNCTION_SD
:
11251 SET_FLAGS(flags
, MODE_MF_SD
);
11253 case MULTI_FUNCTION_SI
:
11254 SET_FLAGS(flags
, MODE_MF_SI
);
11256 case MULTI_FUNCTION_AFEX
:
11257 SET_FLAGS(flags
, MODE_MF_AFEX
);
11261 SET_FLAGS(flags
, MODE_SF
);
11263 #if defined(__LITTLE_ENDIAN)
11264 SET_FLAGS(flags
, MODE_LITTLE_ENDIAN
);
11265 #else /*(__BIG_ENDIAN)*/
11266 SET_FLAGS(flags
, MODE_BIG_ENDIAN
);
11268 INIT_MODE_FLAGS(bp
) = flags
;
11271 static int bnx2x_init_bp(struct bnx2x
*bp
)
11276 mutex_init(&bp
->port
.phy_mutex
);
11277 mutex_init(&bp
->fw_mb_mutex
);
11278 spin_lock_init(&bp
->stats_lock
);
11281 INIT_DELAYED_WORK(&bp
->sp_task
, bnx2x_sp_task
);
11282 INIT_DELAYED_WORK(&bp
->sp_rtnl_task
, bnx2x_sp_rtnl_task
);
11283 INIT_DELAYED_WORK(&bp
->period_task
, bnx2x_period_task
);
11285 rc
= bnx2x_get_hwinfo(bp
);
11289 random_ether_addr(bp
->dev
->dev_addr
);
11292 bnx2x_set_modes_bitmap(bp
);
11294 rc
= bnx2x_alloc_mem_bp(bp
);
11298 bnx2x_read_fwinfo(bp
);
11300 func
= BP_FUNC(bp
);
11302 /* need to reset chip if undi was active */
11303 if (IS_PF(bp
) && !BP_NOMCP(bp
)) {
11306 SHMEM_RD(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_mb_header
) &
11307 DRV_MSG_SEQ_NUMBER_MASK
;
11308 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp
->fw_seq
);
11310 bnx2x_prev_unload(bp
);
11314 if (CHIP_REV_IS_FPGA(bp
))
11315 dev_err(&bp
->pdev
->dev
, "FPGA detected\n");
11317 if (BP_NOMCP(bp
) && (func
== 0))
11318 dev_err(&bp
->pdev
->dev
, "MCP disabled, must load devices in order!\n");
11320 bp
->disable_tpa
= disable_tpa
;
11321 bp
->disable_tpa
|= IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
);
11323 /* Set TPA flags */
11324 if (bp
->disable_tpa
) {
11325 bp
->flags
&= ~(TPA_ENABLE_FLAG
| GRO_ENABLE_FLAG
);
11326 bp
->dev
->features
&= ~NETIF_F_LRO
;
11328 bp
->flags
|= (TPA_ENABLE_FLAG
| GRO_ENABLE_FLAG
);
11329 bp
->dev
->features
|= NETIF_F_LRO
;
11332 if (CHIP_IS_E1(bp
))
11333 bp
->dropless_fc
= 0;
11335 bp
->dropless_fc
= dropless_fc
| bnx2x_get_dropless_info(bp
);
11339 bp
->tx_ring_size
= IS_MF_FCOE_AFEX(bp
) ? 0 : MAX_TX_AVAIL
;
11341 bp
->rx_ring_size
= MAX_RX_AVAIL
;
11343 /* make sure that the numbers are in the right granularity */
11344 bp
->tx_ticks
= (50 / BNX2X_BTR
) * BNX2X_BTR
;
11345 bp
->rx_ticks
= (25 / BNX2X_BTR
) * BNX2X_BTR
;
11347 bp
->current_interval
= CHIP_REV_IS_SLOW(bp
) ? 5*HZ
: HZ
;
11349 init_timer(&bp
->timer
);
11350 bp
->timer
.expires
= jiffies
+ bp
->current_interval
;
11351 bp
->timer
.data
= (unsigned long) bp
;
11352 bp
->timer
.function
= bnx2x_timer
;
11354 if (SHMEM2_HAS(bp
, dcbx_lldp_params_offset
) &&
11355 SHMEM2_HAS(bp
, dcbx_lldp_dcbx_stat_offset
) &&
11356 SHMEM2_RD(bp
, dcbx_lldp_params_offset
) &&
11357 SHMEM2_RD(bp
, dcbx_lldp_dcbx_stat_offset
)) {
11358 bnx2x_dcbx_set_state(bp
, true, BNX2X_DCBX_ENABLED_ON_NEG_ON
);
11359 bnx2x_dcbx_init_params(bp
);
11361 bnx2x_dcbx_set_state(bp
, false, BNX2X_DCBX_ENABLED_OFF
);
11364 if (CHIP_IS_E1x(bp
))
11365 bp
->cnic_base_cl_id
= FP_SB_MAX_E1x
;
11367 bp
->cnic_base_cl_id
= FP_SB_MAX_E2
;
11369 /* multiple tx priority */
11372 else if (CHIP_IS_E1x(bp
))
11373 bp
->max_cos
= BNX2X_MULTI_TX_COS_E1X
;
11374 else if (CHIP_IS_E2(bp
) || CHIP_IS_E3A0(bp
))
11375 bp
->max_cos
= BNX2X_MULTI_TX_COS_E2_E3A0
;
11376 else if (CHIP_IS_E3B0(bp
))
11377 bp
->max_cos
= BNX2X_MULTI_TX_COS_E3B0
;
11379 BNX2X_ERR("unknown chip %x revision %x\n",
11380 CHIP_NUM(bp
), CHIP_REV(bp
));
11381 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp
->max_cos
);
11383 /* We need at least one default status block for slow-path events,
11384 * second status block for the L2 queue, and a third status block for
11385 * CNIC if supproted.
11387 if (CNIC_SUPPORT(bp
))
11388 bp
->min_msix_vec_cnt
= 3;
11390 bp
->min_msix_vec_cnt
= 2;
11391 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp
->min_msix_vec_cnt
);
11397 /****************************************************************************
11398 * General service functions
11399 ****************************************************************************/
11402 * net_device service functions
11405 static int bnx2x_open_epilog(struct bnx2x
*bp
)
11407 /* Enable sriov via delayed work. This must be done via delayed work
11408 * because it causes the probe of the vf devices to be run, which invoke
11409 * register_netdevice which must have rtnl lock taken. As we are holding
11410 * the lock right now, that could only work if the probe would not take
11411 * the lock. However, as the probe of the vf may be called from other
11412 * contexts as well (such as passthrough to vm failes) it can't assume
11413 * the lock is being held for it. Using delayed work here allows the
11414 * probe code to simply take the lock (i.e. wait for it to be released
11415 * if it is being held).
11417 smp_mb__before_clear_bit();
11418 set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV
, &bp
->sp_rtnl_state
);
11419 smp_mb__after_clear_bit();
11420 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
11425 /* called with rtnl_lock */
11426 static int bnx2x_open(struct net_device
*dev
)
11428 struct bnx2x
*bp
= netdev_priv(dev
);
11429 bool global
= false;
11430 int other_engine
= BP_PATH(bp
) ? 0 : 1;
11431 bool other_load_status
, load_status
;
11434 bp
->stats_init
= true;
11436 netif_carrier_off(dev
);
11438 bnx2x_set_power_state(bp
, PCI_D0
);
11440 /* If parity had happen during the unload, then attentions
11441 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11442 * want the first function loaded on the current engine to
11443 * complete the recovery.
11444 * Parity recovery is only relevant for PF driver.
11447 other_load_status
= bnx2x_get_load_status(bp
, other_engine
);
11448 load_status
= bnx2x_get_load_status(bp
, BP_PATH(bp
));
11449 if (!bnx2x_reset_is_done(bp
, BP_PATH(bp
)) ||
11450 bnx2x_chk_parity_attn(bp
, &global
, true)) {
11452 /* If there are attentions and they are in a
11453 * global blocks, set the GLOBAL_RESET bit
11454 * regardless whether it will be this function
11455 * that will complete the recovery or not.
11458 bnx2x_set_reset_global(bp
);
11460 /* Only the first function on the current
11461 * engine should try to recover in open. In case
11462 * of attentions in global blocks only the first
11463 * in the chip should try to recover.
11465 if ((!load_status
&&
11466 (!global
|| !other_load_status
)) &&
11467 bnx2x_trylock_leader_lock(bp
) &&
11468 !bnx2x_leader_reset(bp
)) {
11469 netdev_info(bp
->dev
,
11470 "Recovered in open\n");
11474 /* recovery has failed... */
11475 bnx2x_set_power_state(bp
, PCI_D3hot
);
11476 bp
->recovery_state
= BNX2X_RECOVERY_FAILED
;
11478 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11479 "If you still see this message after a few retries then power cycle is required.\n");
11486 bp
->recovery_state
= BNX2X_RECOVERY_DONE
;
11487 rc
= bnx2x_nic_load(bp
, LOAD_OPEN
);
11490 return bnx2x_open_epilog(bp
);
11493 /* called with rtnl_lock */
11494 static int bnx2x_close(struct net_device
*dev
)
11496 struct bnx2x
*bp
= netdev_priv(dev
);
11498 /* Unload the driver, release IRQs */
11499 bnx2x_nic_unload(bp
, UNLOAD_CLOSE
, false);
11502 bnx2x_set_power_state(bp
, PCI_D3hot
);
11507 static int bnx2x_init_mcast_macs_list(struct bnx2x
*bp
,
11508 struct bnx2x_mcast_ramrod_params
*p
)
11510 int mc_count
= netdev_mc_count(bp
->dev
);
11511 struct bnx2x_mcast_list_elem
*mc_mac
=
11512 kzalloc(sizeof(*mc_mac
) * mc_count
, GFP_ATOMIC
);
11513 struct netdev_hw_addr
*ha
;
11518 INIT_LIST_HEAD(&p
->mcast_list
);
11520 netdev_for_each_mc_addr(ha
, bp
->dev
) {
11521 mc_mac
->mac
= bnx2x_mc_addr(ha
);
11522 list_add_tail(&mc_mac
->link
, &p
->mcast_list
);
11526 p
->mcast_list_len
= mc_count
;
11531 static void bnx2x_free_mcast_macs_list(
11532 struct bnx2x_mcast_ramrod_params
*p
)
11534 struct bnx2x_mcast_list_elem
*mc_mac
=
11535 list_first_entry(&p
->mcast_list
, struct bnx2x_mcast_list_elem
,
11543 * bnx2x_set_uc_list - configure a new unicast MACs list.
11545 * @bp: driver handle
11547 * We will use zero (0) as a MAC type for these MACs.
11549 static int bnx2x_set_uc_list(struct bnx2x
*bp
)
11552 struct net_device
*dev
= bp
->dev
;
11553 struct netdev_hw_addr
*ha
;
11554 struct bnx2x_vlan_mac_obj
*mac_obj
= &bp
->sp_objs
->mac_obj
;
11555 unsigned long ramrod_flags
= 0;
11557 /* First schedule a cleanup up of old configuration */
11558 rc
= bnx2x_del_all_macs(bp
, mac_obj
, BNX2X_UC_LIST_MAC
, false);
11560 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc
);
11564 netdev_for_each_uc_addr(ha
, dev
) {
11565 rc
= bnx2x_set_mac_one(bp
, bnx2x_uc_addr(ha
), mac_obj
, true,
11566 BNX2X_UC_LIST_MAC
, &ramrod_flags
);
11567 if (rc
== -EEXIST
) {
11569 "Failed to schedule ADD operations: %d\n", rc
);
11570 /* do not treat adding same MAC as error */
11573 } else if (rc
< 0) {
11575 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11581 /* Execute the pending commands */
11582 __set_bit(RAMROD_CONT
, &ramrod_flags
);
11583 return bnx2x_set_mac_one(bp
, NULL
, mac_obj
, false /* don't care */,
11584 BNX2X_UC_LIST_MAC
, &ramrod_flags
);
11587 static int bnx2x_set_mc_list(struct bnx2x
*bp
)
11589 struct net_device
*dev
= bp
->dev
;
11590 struct bnx2x_mcast_ramrod_params rparam
= {NULL
};
11593 rparam
.mcast_obj
= &bp
->mcast_obj
;
11595 /* first, clear all configured multicast MACs */
11596 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_DEL
);
11598 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc
);
11602 /* then, configure a new MACs list */
11603 if (netdev_mc_count(dev
)) {
11604 rc
= bnx2x_init_mcast_macs_list(bp
, &rparam
);
11606 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11611 /* Now add the new MACs */
11612 rc
= bnx2x_config_mcast(bp
, &rparam
,
11613 BNX2X_MCAST_CMD_ADD
);
11615 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11618 bnx2x_free_mcast_macs_list(&rparam
);
11624 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
11625 void bnx2x_set_rx_mode(struct net_device
*dev
)
11627 struct bnx2x
*bp
= netdev_priv(dev
);
11628 u32 rx_mode
= BNX2X_RX_MODE_NORMAL
;
11630 if (bp
->state
!= BNX2X_STATE_OPEN
) {
11631 DP(NETIF_MSG_IFUP
, "state is %x, returning\n", bp
->state
);
11635 DP(NETIF_MSG_IFUP
, "dev->flags = %x\n", bp
->dev
->flags
);
11637 if (dev
->flags
& IFF_PROMISC
)
11638 rx_mode
= BNX2X_RX_MODE_PROMISC
;
11639 else if ((dev
->flags
& IFF_ALLMULTI
) ||
11640 ((netdev_mc_count(dev
) > BNX2X_MAX_MULTICAST
) &&
11642 rx_mode
= BNX2X_RX_MODE_ALLMULTI
;
11645 /* some multicasts */
11646 if (bnx2x_set_mc_list(bp
) < 0)
11647 rx_mode
= BNX2X_RX_MODE_ALLMULTI
;
11649 if (bnx2x_set_uc_list(bp
) < 0)
11650 rx_mode
= BNX2X_RX_MODE_PROMISC
;
11652 /* configuring mcast to a vf involves sleeping (when we
11653 * wait for the pf's response). Since this function is
11654 * called from non sleepable context we must schedule
11655 * a work item for this purpose
11657 smp_mb__before_clear_bit();
11658 set_bit(BNX2X_SP_RTNL_VFPF_MCAST
,
11659 &bp
->sp_rtnl_state
);
11660 smp_mb__after_clear_bit();
11661 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
11665 bp
->rx_mode
= rx_mode
;
11666 /* handle ISCSI SD mode */
11667 if (IS_MF_ISCSI_SD(bp
))
11668 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
11670 /* Schedule the rx_mode command */
11671 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
)) {
11672 set_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
);
11677 bnx2x_set_storm_rx_mode(bp
);
11679 /* configuring rx mode to storms in a vf involves sleeping (when
11680 * we wait for the pf's response). Since this function is
11681 * called from non sleepable context we must schedule
11682 * a work item for this purpose
11684 smp_mb__before_clear_bit();
11685 set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE
,
11686 &bp
->sp_rtnl_state
);
11687 smp_mb__after_clear_bit();
11688 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
11692 /* called with rtnl_lock */
11693 static int bnx2x_mdio_read(struct net_device
*netdev
, int prtad
,
11694 int devad
, u16 addr
)
11696 struct bnx2x
*bp
= netdev_priv(netdev
);
11700 DP(NETIF_MSG_LINK
, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11701 prtad
, devad
, addr
);
11703 /* The HW expects different devad if CL22 is used */
11704 devad
= (devad
== MDIO_DEVAD_NONE
) ? DEFAULT_PHY_DEV_ADDR
: devad
;
11706 bnx2x_acquire_phy_lock(bp
);
11707 rc
= bnx2x_phy_read(&bp
->link_params
, prtad
, devad
, addr
, &value
);
11708 bnx2x_release_phy_lock(bp
);
11709 DP(NETIF_MSG_LINK
, "mdio_read_val 0x%x rc = 0x%x\n", value
, rc
);
11716 /* called with rtnl_lock */
11717 static int bnx2x_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
11718 u16 addr
, u16 value
)
11720 struct bnx2x
*bp
= netdev_priv(netdev
);
11724 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11725 prtad
, devad
, addr
, value
);
11727 /* The HW expects different devad if CL22 is used */
11728 devad
= (devad
== MDIO_DEVAD_NONE
) ? DEFAULT_PHY_DEV_ADDR
: devad
;
11730 bnx2x_acquire_phy_lock(bp
);
11731 rc
= bnx2x_phy_write(&bp
->link_params
, prtad
, devad
, addr
, value
);
11732 bnx2x_release_phy_lock(bp
);
11736 /* called with rtnl_lock */
11737 static int bnx2x_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
11739 struct bnx2x
*bp
= netdev_priv(dev
);
11740 struct mii_ioctl_data
*mdio
= if_mii(ifr
);
11742 DP(NETIF_MSG_LINK
, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11743 mdio
->phy_id
, mdio
->reg_num
, mdio
->val_in
);
11745 if (!netif_running(dev
))
11748 return mdio_mii_ioctl(&bp
->mdio
, mdio
, cmd
);
11751 #ifdef CONFIG_NET_POLL_CONTROLLER
11752 static void poll_bnx2x(struct net_device
*dev
)
11754 struct bnx2x
*bp
= netdev_priv(dev
);
11757 for_each_eth_queue(bp
, i
) {
11758 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
11759 napi_schedule(&bnx2x_fp(bp
, fp
->index
, napi
));
11764 static int bnx2x_validate_addr(struct net_device
*dev
)
11766 struct bnx2x
*bp
= netdev_priv(dev
);
11768 if (!bnx2x_is_valid_ether_addr(bp
, dev
->dev_addr
)) {
11769 BNX2X_ERR("Non-valid Ethernet address\n");
11770 return -EADDRNOTAVAIL
;
11775 static const struct net_device_ops bnx2x_netdev_ops
= {
11776 .ndo_open
= bnx2x_open
,
11777 .ndo_stop
= bnx2x_close
,
11778 .ndo_start_xmit
= bnx2x_start_xmit
,
11779 .ndo_select_queue
= bnx2x_select_queue
,
11780 .ndo_set_rx_mode
= bnx2x_set_rx_mode
,
11781 .ndo_set_mac_address
= bnx2x_change_mac_addr
,
11782 .ndo_validate_addr
= bnx2x_validate_addr
,
11783 .ndo_do_ioctl
= bnx2x_ioctl
,
11784 .ndo_change_mtu
= bnx2x_change_mtu
,
11785 .ndo_fix_features
= bnx2x_fix_features
,
11786 .ndo_set_features
= bnx2x_set_features
,
11787 .ndo_tx_timeout
= bnx2x_tx_timeout
,
11788 #ifdef CONFIG_NET_POLL_CONTROLLER
11789 .ndo_poll_controller
= poll_bnx2x
,
11791 .ndo_setup_tc
= bnx2x_setup_tc
,
11792 #ifdef CONFIG_BNX2X_SRIOV
11793 .ndo_set_vf_mac
= bnx2x_set_vf_mac
,
11795 #ifdef NETDEV_FCOE_WWNN
11796 .ndo_fcoe_get_wwn
= bnx2x_fcoe_get_wwn
,
11800 static int bnx2x_set_coherency_mask(struct bnx2x
*bp
)
11802 struct device
*dev
= &bp
->pdev
->dev
;
11804 if (dma_set_mask(dev
, DMA_BIT_MASK(64)) == 0) {
11805 bp
->flags
|= USING_DAC_FLAG
;
11806 if (dma_set_coherent_mask(dev
, DMA_BIT_MASK(64)) != 0) {
11807 dev_err(dev
, "dma_set_coherent_mask failed, aborting\n");
11810 } else if (dma_set_mask(dev
, DMA_BIT_MASK(32)) != 0) {
11811 dev_err(dev
, "System does not support DMA, aborting\n");
11818 static int bnx2x_init_dev(struct bnx2x
*bp
, struct pci_dev
*pdev
,
11819 struct net_device
*dev
, unsigned long board_type
)
11823 bool chip_is_e1x
= (board_type
== BCM57710
||
11824 board_type
== BCM57711
||
11825 board_type
== BCM57711E
);
11827 SET_NETDEV_DEV(dev
, &pdev
->dev
);
11832 rc
= pci_enable_device(pdev
);
11834 dev_err(&bp
->pdev
->dev
,
11835 "Cannot enable PCI device, aborting\n");
11839 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
11840 dev_err(&bp
->pdev
->dev
,
11841 "Cannot find PCI device base address, aborting\n");
11843 goto err_out_disable
;
11846 if (IS_PF(bp
) && !(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
11847 dev_err(&bp
->pdev
->dev
, "Cannot find second PCI device base address, aborting\n");
11849 goto err_out_disable
;
11852 pci_read_config_dword(pdev
, PCICFG_REVISION_ID_OFFSET
, &pci_cfg_dword
);
11853 if ((pci_cfg_dword
& PCICFG_REVESION_ID_MASK
) ==
11854 PCICFG_REVESION_ID_ERROR_VAL
) {
11855 pr_err("PCI device error, probably due to fan failure, aborting\n");
11857 goto err_out_disable
;
11860 if (atomic_read(&pdev
->enable_cnt
) == 1) {
11861 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
11863 dev_err(&bp
->pdev
->dev
,
11864 "Cannot obtain PCI resources, aborting\n");
11865 goto err_out_disable
;
11868 pci_set_master(pdev
);
11869 pci_save_state(pdev
);
11873 bp
->pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
11874 if (bp
->pm_cap
== 0) {
11875 dev_err(&bp
->pdev
->dev
,
11876 "Cannot find power management capability, aborting\n");
11878 goto err_out_release
;
11882 if (!pci_is_pcie(pdev
)) {
11883 dev_err(&bp
->pdev
->dev
, "Not PCI Express, aborting\n");
11885 goto err_out_release
;
11888 rc
= bnx2x_set_coherency_mask(bp
);
11890 goto err_out_release
;
11892 dev
->mem_start
= pci_resource_start(pdev
, 0);
11893 dev
->base_addr
= dev
->mem_start
;
11894 dev
->mem_end
= pci_resource_end(pdev
, 0);
11896 dev
->irq
= pdev
->irq
;
11898 bp
->regview
= pci_ioremap_bar(pdev
, 0);
11899 if (!bp
->regview
) {
11900 dev_err(&bp
->pdev
->dev
,
11901 "Cannot map register space, aborting\n");
11903 goto err_out_release
;
11906 /* In E1/E1H use pci device function given by kernel.
11907 * In E2/E3 read physical function from ME register since these chips
11908 * support Physical Device Assignment where kernel BDF maybe arbitrary
11909 * (depending on hypervisor).
11912 bp
->pf_num
= PCI_FUNC(pdev
->devfn
);
11915 pci_read_config_dword(bp
->pdev
,
11916 PCICFG_ME_REGISTER
, &pci_cfg_dword
);
11917 bp
->pf_num
= (u8
)((pci_cfg_dword
& ME_REG_ABS_PF_NUM
) >>
11918 ME_REG_ABS_PF_NUM_SHIFT
);
11920 BNX2X_DEV_INFO("me reg PF num: %d\n", bp
->pf_num
);
11922 bnx2x_set_power_state(bp
, PCI_D0
);
11924 /* clean indirect addresses */
11925 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
11926 PCICFG_VENDOR_ID_OFFSET
);
11928 * Clean the following indirect addresses for all functions since it
11929 * is not used by the driver.
11932 REG_WR(bp
, PXP2_REG_PGL_ADDR_88_F0
, 0);
11933 REG_WR(bp
, PXP2_REG_PGL_ADDR_8C_F0
, 0);
11934 REG_WR(bp
, PXP2_REG_PGL_ADDR_90_F0
, 0);
11935 REG_WR(bp
, PXP2_REG_PGL_ADDR_94_F0
, 0);
11938 REG_WR(bp
, PXP2_REG_PGL_ADDR_88_F1
, 0);
11939 REG_WR(bp
, PXP2_REG_PGL_ADDR_8C_F1
, 0);
11940 REG_WR(bp
, PXP2_REG_PGL_ADDR_90_F1
, 0);
11941 REG_WR(bp
, PXP2_REG_PGL_ADDR_94_F1
, 0);
11944 /* Enable internal target-read (in case we are probed after PF
11945 * FLR). Must be done prior to any BAR read access. Only for
11950 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ
, 1);
11953 dev
->watchdog_timeo
= TX_TIMEOUT
;
11955 dev
->netdev_ops
= &bnx2x_netdev_ops
;
11956 bnx2x_set_ethtool_ops(dev
);
11958 dev
->priv_flags
|= IFF_UNICAST_FLT
;
11960 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
11961 NETIF_F_TSO
| NETIF_F_TSO_ECN
| NETIF_F_TSO6
|
11962 NETIF_F_RXCSUM
| NETIF_F_LRO
| NETIF_F_GRO
|
11963 NETIF_F_RXHASH
| NETIF_F_HW_VLAN_TX
;
11965 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
11966 NETIF_F_TSO
| NETIF_F_TSO_ECN
| NETIF_F_TSO6
| NETIF_F_HIGHDMA
;
11968 dev
->features
|= dev
->hw_features
| NETIF_F_HW_VLAN_RX
;
11969 if (bp
->flags
& USING_DAC_FLAG
)
11970 dev
->features
|= NETIF_F_HIGHDMA
;
11972 /* Add Loopback capability to the device */
11973 dev
->hw_features
|= NETIF_F_LOOPBACK
;
11976 dev
->dcbnl_ops
= &bnx2x_dcbnl_ops
;
11979 /* get_port_hwinfo() will set prtad and mmds properly */
11980 bp
->mdio
.prtad
= MDIO_PRTAD_NONE
;
11982 bp
->mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
11983 bp
->mdio
.dev
= dev
;
11984 bp
->mdio
.mdio_read
= bnx2x_mdio_read
;
11985 bp
->mdio
.mdio_write
= bnx2x_mdio_write
;
11990 if (atomic_read(&pdev
->enable_cnt
) == 1)
11991 pci_release_regions(pdev
);
11994 pci_disable_device(pdev
);
11995 pci_set_drvdata(pdev
, NULL
);
12001 static void bnx2x_get_pcie_width_speed(struct bnx2x
*bp
, int *width
, int *speed
)
12005 pci_read_config_dword(bp
->pdev
, PCICFG_LINK_CONTROL
, &val
);
12006 *width
= (val
& PCICFG_LINK_WIDTH
) >> PCICFG_LINK_WIDTH_SHIFT
;
12008 /* return value of 1=2.5GHz 2=5GHz */
12009 *speed
= (val
& PCICFG_LINK_SPEED
) >> PCICFG_LINK_SPEED_SHIFT
;
12012 static int bnx2x_check_firmware(struct bnx2x
*bp
)
12014 const struct firmware
*firmware
= bp
->firmware
;
12015 struct bnx2x_fw_file_hdr
*fw_hdr
;
12016 struct bnx2x_fw_file_section
*sections
;
12017 u32 offset
, len
, num_ops
;
12018 __be16
*ops_offsets
;
12022 if (firmware
->size
< sizeof(struct bnx2x_fw_file_hdr
)) {
12023 BNX2X_ERR("Wrong FW size\n");
12027 fw_hdr
= (struct bnx2x_fw_file_hdr
*)firmware
->data
;
12028 sections
= (struct bnx2x_fw_file_section
*)fw_hdr
;
12030 /* Make sure none of the offsets and sizes make us read beyond
12031 * the end of the firmware data */
12032 for (i
= 0; i
< sizeof(*fw_hdr
) / sizeof(*sections
); i
++) {
12033 offset
= be32_to_cpu(sections
[i
].offset
);
12034 len
= be32_to_cpu(sections
[i
].len
);
12035 if (offset
+ len
> firmware
->size
) {
12036 BNX2X_ERR("Section %d length is out of bounds\n", i
);
12041 /* Likewise for the init_ops offsets */
12042 offset
= be32_to_cpu(fw_hdr
->init_ops_offsets
.offset
);
12043 ops_offsets
= (__force __be16
*)(firmware
->data
+ offset
);
12044 num_ops
= be32_to_cpu(fw_hdr
->init_ops
.len
) / sizeof(struct raw_op
);
12046 for (i
= 0; i
< be32_to_cpu(fw_hdr
->init_ops_offsets
.len
) / 2; i
++) {
12047 if (be16_to_cpu(ops_offsets
[i
]) > num_ops
) {
12048 BNX2X_ERR("Section offset %d is out of bounds\n", i
);
12053 /* Check FW version */
12054 offset
= be32_to_cpu(fw_hdr
->fw_version
.offset
);
12055 fw_ver
= firmware
->data
+ offset
;
12056 if ((fw_ver
[0] != BCM_5710_FW_MAJOR_VERSION
) ||
12057 (fw_ver
[1] != BCM_5710_FW_MINOR_VERSION
) ||
12058 (fw_ver
[2] != BCM_5710_FW_REVISION_VERSION
) ||
12059 (fw_ver
[3] != BCM_5710_FW_ENGINEERING_VERSION
)) {
12060 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12061 fw_ver
[0], fw_ver
[1], fw_ver
[2], fw_ver
[3],
12062 BCM_5710_FW_MAJOR_VERSION
,
12063 BCM_5710_FW_MINOR_VERSION
,
12064 BCM_5710_FW_REVISION_VERSION
,
12065 BCM_5710_FW_ENGINEERING_VERSION
);
12072 static void be32_to_cpu_n(const u8
*_source
, u8
*_target
, u32 n
)
12074 const __be32
*source
= (const __be32
*)_source
;
12075 u32
*target
= (u32
*)_target
;
12078 for (i
= 0; i
< n
/4; i
++)
12079 target
[i
] = be32_to_cpu(source
[i
]);
12083 Ops array is stored in the following format:
12084 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12086 static void bnx2x_prep_ops(const u8
*_source
, u8
*_target
, u32 n
)
12088 const __be32
*source
= (const __be32
*)_source
;
12089 struct raw_op
*target
= (struct raw_op
*)_target
;
12092 for (i
= 0, j
= 0; i
< n
/8; i
++, j
+= 2) {
12093 tmp
= be32_to_cpu(source
[j
]);
12094 target
[i
].op
= (tmp
>> 24) & 0xff;
12095 target
[i
].offset
= tmp
& 0xffffff;
12096 target
[i
].raw_data
= be32_to_cpu(source
[j
+ 1]);
12100 /* IRO array is stored in the following format:
12101 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12103 static void bnx2x_prep_iro(const u8
*_source
, u8
*_target
, u32 n
)
12105 const __be32
*source
= (const __be32
*)_source
;
12106 struct iro
*target
= (struct iro
*)_target
;
12109 for (i
= 0, j
= 0; i
< n
/sizeof(struct iro
); i
++) {
12110 target
[i
].base
= be32_to_cpu(source
[j
]);
12112 tmp
= be32_to_cpu(source
[j
]);
12113 target
[i
].m1
= (tmp
>> 16) & 0xffff;
12114 target
[i
].m2
= tmp
& 0xffff;
12116 tmp
= be32_to_cpu(source
[j
]);
12117 target
[i
].m3
= (tmp
>> 16) & 0xffff;
12118 target
[i
].size
= tmp
& 0xffff;
12123 static void be16_to_cpu_n(const u8
*_source
, u8
*_target
, u32 n
)
12125 const __be16
*source
= (const __be16
*)_source
;
12126 u16
*target
= (u16
*)_target
;
12129 for (i
= 0; i
< n
/2; i
++)
12130 target
[i
] = be16_to_cpu(source
[i
]);
12133 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12135 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12136 bp->arr = kmalloc(len, GFP_KERNEL); \
12139 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12140 (u8 *)bp->arr, len); \
12143 static int bnx2x_init_firmware(struct bnx2x
*bp
)
12145 const char *fw_file_name
;
12146 struct bnx2x_fw_file_hdr
*fw_hdr
;
12152 if (CHIP_IS_E1(bp
))
12153 fw_file_name
= FW_FILE_NAME_E1
;
12154 else if (CHIP_IS_E1H(bp
))
12155 fw_file_name
= FW_FILE_NAME_E1H
;
12156 else if (!CHIP_IS_E1x(bp
))
12157 fw_file_name
= FW_FILE_NAME_E2
;
12159 BNX2X_ERR("Unsupported chip revision\n");
12162 BNX2X_DEV_INFO("Loading %s\n", fw_file_name
);
12164 rc
= request_firmware(&bp
->firmware
, fw_file_name
, &bp
->pdev
->dev
);
12166 BNX2X_ERR("Can't load firmware file %s\n",
12168 goto request_firmware_exit
;
12171 rc
= bnx2x_check_firmware(bp
);
12173 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name
);
12174 goto request_firmware_exit
;
12177 fw_hdr
= (struct bnx2x_fw_file_hdr
*)bp
->firmware
->data
;
12179 /* Initialize the pointers to the init arrays */
12181 BNX2X_ALLOC_AND_SET(init_data
, request_firmware_exit
, be32_to_cpu_n
);
12184 BNX2X_ALLOC_AND_SET(init_ops
, init_ops_alloc_err
, bnx2x_prep_ops
);
12187 BNX2X_ALLOC_AND_SET(init_ops_offsets
, init_offsets_alloc_err
,
12190 /* STORMs firmware */
12191 INIT_TSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
12192 be32_to_cpu(fw_hdr
->tsem_int_table_data
.offset
);
12193 INIT_TSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
12194 be32_to_cpu(fw_hdr
->tsem_pram_data
.offset
);
12195 INIT_USEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
12196 be32_to_cpu(fw_hdr
->usem_int_table_data
.offset
);
12197 INIT_USEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
12198 be32_to_cpu(fw_hdr
->usem_pram_data
.offset
);
12199 INIT_XSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
12200 be32_to_cpu(fw_hdr
->xsem_int_table_data
.offset
);
12201 INIT_XSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
12202 be32_to_cpu(fw_hdr
->xsem_pram_data
.offset
);
12203 INIT_CSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
12204 be32_to_cpu(fw_hdr
->csem_int_table_data
.offset
);
12205 INIT_CSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
12206 be32_to_cpu(fw_hdr
->csem_pram_data
.offset
);
12208 BNX2X_ALLOC_AND_SET(iro_arr
, iro_alloc_err
, bnx2x_prep_iro
);
12213 kfree(bp
->init_ops_offsets
);
12214 init_offsets_alloc_err
:
12215 kfree(bp
->init_ops
);
12216 init_ops_alloc_err
:
12217 kfree(bp
->init_data
);
12218 request_firmware_exit
:
12219 release_firmware(bp
->firmware
);
12220 bp
->firmware
= NULL
;
12225 static void bnx2x_release_firmware(struct bnx2x
*bp
)
12227 kfree(bp
->init_ops_offsets
);
12228 kfree(bp
->init_ops
);
12229 kfree(bp
->init_data
);
12230 release_firmware(bp
->firmware
);
12231 bp
->firmware
= NULL
;
12235 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv
= {
12236 .init_hw_cmn_chip
= bnx2x_init_hw_common_chip
,
12237 .init_hw_cmn
= bnx2x_init_hw_common
,
12238 .init_hw_port
= bnx2x_init_hw_port
,
12239 .init_hw_func
= bnx2x_init_hw_func
,
12241 .reset_hw_cmn
= bnx2x_reset_common
,
12242 .reset_hw_port
= bnx2x_reset_port
,
12243 .reset_hw_func
= bnx2x_reset_func
,
12245 .gunzip_init
= bnx2x_gunzip_init
,
12246 .gunzip_end
= bnx2x_gunzip_end
,
12248 .init_fw
= bnx2x_init_firmware
,
12249 .release_fw
= bnx2x_release_firmware
,
12252 void bnx2x__init_func_obj(struct bnx2x
*bp
)
12254 /* Prepare DMAE related driver resources */
12255 bnx2x_setup_dmae(bp
);
12257 bnx2x_init_func_obj(bp
, &bp
->func_obj
,
12258 bnx2x_sp(bp
, func_rdata
),
12259 bnx2x_sp_mapping(bp
, func_rdata
),
12260 bnx2x_sp(bp
, func_afex_rdata
),
12261 bnx2x_sp_mapping(bp
, func_afex_rdata
),
12262 &bnx2x_func_sp_drv
);
12265 /* must be called after sriov-enable */
12266 static int bnx2x_set_qm_cid_count(struct bnx2x
*bp
)
12268 int cid_count
= BNX2X_L2_MAX_CID(bp
);
12271 cid_count
+= BNX2X_VF_CIDS
;
12273 if (CNIC_SUPPORT(bp
))
12274 cid_count
+= CNIC_CID_MAX
;
12276 return roundup(cid_count
, QM_CID_ROUND
);
12280 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
12285 static int bnx2x_get_num_non_def_sbs(struct pci_dev
*pdev
,
12286 int cnic_cnt
, bool is_vf
)
12291 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
12294 * If MSI-X is not supported - return number of SBs needed to support
12295 * one fast path queue: one FP queue + SB for CNIC
12298 dev_info(&pdev
->dev
, "no msix capability found\n");
12299 return 1 + cnic_cnt
;
12301 dev_info(&pdev
->dev
, "msix capability found\n");
12304 * The value in the PCI configuration space is the index of the last
12305 * entry, namely one less than the actual size of the table, which is
12306 * exactly what we want to return from this function: number of all SBs
12307 * without the default SB.
12308 * For VFs there is no default SB, then we return (index+1).
12310 pci_read_config_word(pdev
, pos
+ PCI_MSI_FLAGS
, &control
);
12312 index
= control
& PCI_MSIX_FLAGS_QSIZE
;
12314 return is_vf
? index
+ 1 : index
;
12317 static int set_max_cos_est(int chip_id
)
12323 return BNX2X_MULTI_TX_COS_E1X
;
12327 return BNX2X_MULTI_TX_COS_E2_E3A0
;
12333 case BCM57840_4_10
:
12334 case BCM57840_2_20
:
12343 return BNX2X_MULTI_TX_COS_E3B0
;
12346 pr_err("Unknown board_type (%d), aborting\n", chip_id
);
12351 static int set_is_vf(int chip_id
)
12365 struct cnic_eth_dev
*bnx2x_cnic_probe(struct net_device
*dev
);
12367 static int bnx2x_init_one(struct pci_dev
*pdev
,
12368 const struct pci_device_id
*ent
)
12370 struct net_device
*dev
= NULL
;
12372 int pcie_width
, pcie_speed
;
12373 int rc
, max_non_def_sbs
;
12374 int rx_count
, tx_count
, rss_count
, doorbell_size
;
12379 /* An estimated maximum supported CoS number according to the chip
12381 * We will try to roughly estimate the maximum number of CoSes this chip
12382 * may support in order to minimize the memory allocated for Tx
12383 * netdev_queue's. This number will be accurately calculated during the
12384 * initialization of bp->max_cos based on the chip versions AND chip
12385 * revision in the bnx2x_init_bp().
12387 max_cos_est
= set_max_cos_est(ent
->driver_data
);
12388 if (max_cos_est
< 0)
12389 return max_cos_est
;
12390 is_vf
= set_is_vf(ent
->driver_data
);
12391 cnic_cnt
= is_vf
? 0 : 1;
12393 max_non_def_sbs
= bnx2x_get_num_non_def_sbs(pdev
, cnic_cnt
, is_vf
);
12395 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
12396 rss_count
= is_vf
? 1 : max_non_def_sbs
- cnic_cnt
;
12401 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
12402 rx_count
= rss_count
+ cnic_cnt
;
12404 /* Maximum number of netdev Tx queues:
12405 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
12407 tx_count
= rss_count
* max_cos_est
+ cnic_cnt
;
12409 /* dev zeroed in init_etherdev */
12410 dev
= alloc_etherdev_mqs(sizeof(*bp
), tx_count
, rx_count
);
12414 bp
= netdev_priv(dev
);
12418 bp
->flags
|= IS_VF_FLAG
;
12420 bp
->igu_sb_cnt
= max_non_def_sbs
;
12421 bp
->igu_base_addr
= IS_VF(bp
) ? PXP_VF_ADDR_IGU_START
: BAR_IGU_INTMEM
;
12422 bp
->msg_enable
= debug
;
12423 bp
->cnic_support
= cnic_cnt
;
12424 bp
->cnic_probe
= bnx2x_cnic_probe
;
12426 pci_set_drvdata(pdev
, dev
);
12428 rc
= bnx2x_init_dev(bp
, pdev
, dev
, ent
->driver_data
);
12434 BNX2X_DEV_INFO("This is a %s function\n",
12435 IS_PF(bp
) ? "physical" : "virtual");
12436 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp
) ? "on" : "off");
12437 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs
);
12438 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
12439 tx_count
, rx_count
);
12441 rc
= bnx2x_init_bp(bp
);
12443 goto init_one_exit
;
12445 /* Map doorbells here as we need the real value of bp->max_cos which
12446 * is initialized in bnx2x_init_bp() to determine the number of
12450 bnx2x_vf_map_doorbells(bp
);
12451 rc
= bnx2x_vf_pci_alloc(bp
);
12453 goto init_one_exit
;
12455 doorbell_size
= BNX2X_L2_MAX_CID(bp
) * (1 << BNX2X_DB_SHIFT
);
12456 if (doorbell_size
> pci_resource_len(pdev
, 2)) {
12457 dev_err(&bp
->pdev
->dev
,
12458 "Cannot map doorbells, bar size too small, aborting\n");
12460 goto init_one_exit
;
12462 bp
->doorbells
= ioremap_nocache(pci_resource_start(pdev
, 2),
12465 if (!bp
->doorbells
) {
12466 dev_err(&bp
->pdev
->dev
,
12467 "Cannot map doorbell space, aborting\n");
12469 goto init_one_exit
;
12473 rc
= bnx2x_vfpf_acquire(bp
, tx_count
, rx_count
);
12475 goto init_one_exit
;
12478 /* Enable SRIOV if capability found in configuration space.
12479 * Once the generic SR-IOV framework makes it in from the
12480 * pci tree this will be revised, to allow dynamic control
12481 * over the number of VFs. Right now, change the num of vfs
12482 * param below to enable SR-IOV.
12484 rc
= bnx2x_iov_init_one(bp
, int_mode
, 0/*num vfs*/);
12486 goto init_one_exit
;
12488 /* calc qm_cid_count */
12489 bp
->qm_cid_count
= bnx2x_set_qm_cid_count(bp
);
12490 BNX2X_DEV_INFO("qm_cid_count %d\n", bp
->qm_cid_count
);
12492 /* disable FCOE L2 queue for E1x*/
12493 if (CHIP_IS_E1x(bp
))
12494 bp
->flags
|= NO_FCOE_FLAG
;
12496 /* disable FCOE for 57840 device, until FW supports it */
12497 switch (ent
->driver_data
) {
12499 case BCM57840_4_10
:
12500 case BCM57840_2_20
:
12503 bp
->flags
|= NO_FCOE_FLAG
;
12506 /* Set bp->num_queues for MSI-X mode*/
12507 bnx2x_set_num_queues(bp
);
12509 /* Configure interrupt mode: try to enable MSI-X/MSI if
12512 rc
= bnx2x_set_int_mode(bp
);
12514 dev_err(&pdev
->dev
, "Cannot set interrupts\n");
12515 goto init_one_exit
;
12517 BNX2X_DEV_INFO("set interrupts successfully\n");
12519 /* register the net device */
12520 rc
= register_netdev(dev
);
12522 dev_err(&pdev
->dev
, "Cannot register net device\n");
12523 goto init_one_exit
;
12525 BNX2X_DEV_INFO("device name after netdev register %s\n", dev
->name
);
12528 if (!NO_FCOE(bp
)) {
12529 /* Add storage MAC address */
12531 dev_addr_add(bp
->dev
, bp
->fip_mac
, NETDEV_HW_ADDR_T_SAN
);
12535 bnx2x_get_pcie_width_speed(bp
, &pcie_width
, &pcie_speed
);
12536 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12537 pcie_width
, pcie_speed
);
12540 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
12541 board_info
[ent
->driver_data
].name
,
12542 (CHIP_REV(bp
) >> 12) + 'A', (CHIP_METAL(bp
) >> 4),
12544 ((!CHIP_IS_E2(bp
) && pcie_speed
== 2) ||
12545 (CHIP_IS_E2(bp
) && pcie_speed
== 1)) ?
12546 "5GHz (Gen2)" : "2.5GHz",
12547 dev
->base_addr
, bp
->pdev
->irq
, dev
->dev_addr
);
12553 iounmap(bp
->regview
);
12555 if (IS_PF(bp
) && bp
->doorbells
)
12556 iounmap(bp
->doorbells
);
12560 if (atomic_read(&pdev
->enable_cnt
) == 1)
12561 pci_release_regions(pdev
);
12563 pci_disable_device(pdev
);
12564 pci_set_drvdata(pdev
, NULL
);
12569 static void bnx2x_remove_one(struct pci_dev
*pdev
)
12571 struct net_device
*dev
= pci_get_drvdata(pdev
);
12575 dev_err(&pdev
->dev
, "BAD net device from bnx2x_init_one\n");
12578 bp
= netdev_priv(dev
);
12580 /* Delete storage MAC address */
12581 if (!NO_FCOE(bp
)) {
12583 dev_addr_del(bp
->dev
, bp
->fip_mac
, NETDEV_HW_ADDR_T_SAN
);
12588 /* Delete app tlvs from dcbnl */
12589 bnx2x_dcbnl_update_applist(bp
, true);
12592 unregister_netdev(dev
);
12594 /* Power on: we can't let PCI layer write to us while we are in D3 */
12596 bnx2x_set_power_state(bp
, PCI_D0
);
12598 /* Disable MSI/MSI-X */
12599 bnx2x_disable_msi(bp
);
12603 bnx2x_set_power_state(bp
, PCI_D3hot
);
12605 /* Make sure RESET task is not scheduled before continuing */
12606 cancel_delayed_work_sync(&bp
->sp_rtnl_task
);
12608 bnx2x_iov_remove_one(bp
);
12610 /* send message via vfpf channel to release the resources of this vf */
12612 bnx2x_vfpf_release(bp
);
12615 iounmap(bp
->regview
);
12617 /* for vf doorbells are part of the regview and were unmapped along with
12618 * it. FW is only loaded by PF.
12622 iounmap(bp
->doorbells
);
12624 bnx2x_release_firmware(bp
);
12626 bnx2x_free_mem_bp(bp
);
12630 if (atomic_read(&pdev
->enable_cnt
) == 1)
12631 pci_release_regions(pdev
);
12633 pci_disable_device(pdev
);
12634 pci_set_drvdata(pdev
, NULL
);
12637 static int bnx2x_eeh_nic_unload(struct bnx2x
*bp
)
12641 bp
->state
= BNX2X_STATE_ERROR
;
12643 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
12645 if (CNIC_LOADED(bp
))
12646 bnx2x_cnic_notify(bp
, CNIC_CTL_STOP_CMD
);
12649 bnx2x_tx_disable(bp
);
12651 bnx2x_netif_stop(bp
, 0);
12652 /* Delete all NAPI objects */
12653 bnx2x_del_all_napi(bp
);
12654 if (CNIC_LOADED(bp
))
12655 bnx2x_del_all_napi_cnic(bp
);
12657 del_timer_sync(&bp
->timer
);
12659 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
12662 bnx2x_free_irq(bp
);
12664 /* Free SKBs, SGEs, TPA pool and driver internals */
12665 bnx2x_free_skbs(bp
);
12667 for_each_rx_queue(bp
, i
)
12668 bnx2x_free_rx_sge_range(bp
, bp
->fp
+ i
, NUM_RX_SGE
);
12670 bnx2x_free_mem(bp
);
12672 bp
->state
= BNX2X_STATE_CLOSED
;
12674 netif_carrier_off(bp
->dev
);
12679 static void bnx2x_eeh_recover(struct bnx2x
*bp
)
12683 mutex_init(&bp
->port
.phy_mutex
);
12686 val
= SHMEM_RD(bp
, validity_map
[BP_PORT(bp
)]);
12687 if ((val
& (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
12688 != (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
12689 BNX2X_ERR("BAD MCP validity signature\n");
12693 * bnx2x_io_error_detected - called when PCI error is detected
12694 * @pdev: Pointer to PCI device
12695 * @state: The current pci connection state
12697 * This function is called after a PCI bus error affecting
12698 * this device has been detected.
12700 static pci_ers_result_t
bnx2x_io_error_detected(struct pci_dev
*pdev
,
12701 pci_channel_state_t state
)
12703 struct net_device
*dev
= pci_get_drvdata(pdev
);
12704 struct bnx2x
*bp
= netdev_priv(dev
);
12708 netif_device_detach(dev
);
12710 if (state
== pci_channel_io_perm_failure
) {
12712 return PCI_ERS_RESULT_DISCONNECT
;
12715 if (netif_running(dev
))
12716 bnx2x_eeh_nic_unload(bp
);
12718 pci_disable_device(pdev
);
12722 /* Request a slot reset */
12723 return PCI_ERS_RESULT_NEED_RESET
;
12727 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12728 * @pdev: Pointer to PCI device
12730 * Restart the card from scratch, as if from a cold-boot.
12732 static pci_ers_result_t
bnx2x_io_slot_reset(struct pci_dev
*pdev
)
12734 struct net_device
*dev
= pci_get_drvdata(pdev
);
12735 struct bnx2x
*bp
= netdev_priv(dev
);
12739 if (pci_enable_device(pdev
)) {
12740 dev_err(&pdev
->dev
,
12741 "Cannot re-enable PCI device after reset\n");
12743 return PCI_ERS_RESULT_DISCONNECT
;
12746 pci_set_master(pdev
);
12747 pci_restore_state(pdev
);
12749 if (netif_running(dev
))
12750 bnx2x_set_power_state(bp
, PCI_D0
);
12754 return PCI_ERS_RESULT_RECOVERED
;
12758 * bnx2x_io_resume - called when traffic can start flowing again
12759 * @pdev: Pointer to PCI device
12761 * This callback is called when the error recovery driver tells us that
12762 * its OK to resume normal operation.
12764 static void bnx2x_io_resume(struct pci_dev
*pdev
)
12766 struct net_device
*dev
= pci_get_drvdata(pdev
);
12767 struct bnx2x
*bp
= netdev_priv(dev
);
12769 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
12770 netdev_err(bp
->dev
, "Handling parity error recovery. Try again later\n");
12776 bnx2x_eeh_recover(bp
);
12778 if (netif_running(dev
))
12779 bnx2x_nic_load(bp
, LOAD_NORMAL
);
12781 netif_device_attach(dev
);
12786 static const struct pci_error_handlers bnx2x_err_handler
= {
12787 .error_detected
= bnx2x_io_error_detected
,
12788 .slot_reset
= bnx2x_io_slot_reset
,
12789 .resume
= bnx2x_io_resume
,
12792 static struct pci_driver bnx2x_pci_driver
= {
12793 .name
= DRV_MODULE_NAME
,
12794 .id_table
= bnx2x_pci_tbl
,
12795 .probe
= bnx2x_init_one
,
12796 .remove
= bnx2x_remove_one
,
12797 .suspend
= bnx2x_suspend
,
12798 .resume
= bnx2x_resume
,
12799 .err_handler
= &bnx2x_err_handler
,
12802 static int __init
bnx2x_init(void)
12806 pr_info("%s", version
);
12808 bnx2x_wq
= create_singlethread_workqueue("bnx2x");
12809 if (bnx2x_wq
== NULL
) {
12810 pr_err("Cannot create workqueue\n");
12814 ret
= pci_register_driver(&bnx2x_pci_driver
);
12816 pr_err("Cannot register driver\n");
12817 destroy_workqueue(bnx2x_wq
);
12822 static void __exit
bnx2x_cleanup(void)
12824 struct list_head
*pos
, *q
;
12825 pci_unregister_driver(&bnx2x_pci_driver
);
12827 destroy_workqueue(bnx2x_wq
);
12829 /* Free globablly allocated resources */
12830 list_for_each_safe(pos
, q
, &bnx2x_prev_list
) {
12831 struct bnx2x_prev_path_list
*tmp
=
12832 list_entry(pos
, struct bnx2x_prev_path_list
, list
);
12838 void bnx2x_notify_link_changed(struct bnx2x
*bp
)
12840 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ BP_FUNC(bp
)*sizeof(u32
), 1);
12843 module_init(bnx2x_init
);
12844 module_exit(bnx2x_cleanup
);
12847 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12849 * @bp: driver handle
12850 * @set: set or clear the CAM entry
12852 * This function will wait until the ramdord completion returns.
12853 * Return 0 if success, -ENODEV if ramrod doesn't return.
12855 static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x
*bp
)
12857 unsigned long ramrod_flags
= 0;
12859 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
12860 return bnx2x_set_mac_one(bp
, bp
->cnic_eth_dev
.iscsi_mac
,
12861 &bp
->iscsi_l2_mac_obj
, true,
12862 BNX2X_ISCSI_ETH_MAC
, &ramrod_flags
);
12865 /* count denotes the number of new completions we have seen */
12866 static void bnx2x_cnic_sp_post(struct bnx2x
*bp
, int count
)
12868 struct eth_spe
*spe
;
12869 int cxt_index
, cxt_offset
;
12871 #ifdef BNX2X_STOP_ON_ERROR
12872 if (unlikely(bp
->panic
))
12876 spin_lock_bh(&bp
->spq_lock
);
12877 BUG_ON(bp
->cnic_spq_pending
< count
);
12878 bp
->cnic_spq_pending
-= count
;
12881 for (; bp
->cnic_kwq_pending
; bp
->cnic_kwq_pending
--) {
12882 u16 type
= (le16_to_cpu(bp
->cnic_kwq_cons
->hdr
.type
)
12883 & SPE_HDR_CONN_TYPE
) >>
12884 SPE_HDR_CONN_TYPE_SHIFT
;
12885 u8 cmd
= (le32_to_cpu(bp
->cnic_kwq_cons
->hdr
.conn_and_cmd_data
)
12886 >> SPE_HDR_CMD_ID_SHIFT
) & 0xff;
12888 /* Set validation for iSCSI L2 client before sending SETUP
12891 if (type
== ETH_CONNECTION_TYPE
) {
12892 if (cmd
== RAMROD_CMD_ID_ETH_CLIENT_SETUP
) {
12893 cxt_index
= BNX2X_ISCSI_ETH_CID(bp
) /
12895 cxt_offset
= BNX2X_ISCSI_ETH_CID(bp
) -
12896 (cxt_index
* ILT_PAGE_CIDS
);
12897 bnx2x_set_ctx_validation(bp
,
12898 &bp
->context
[cxt_index
].
12899 vcxt
[cxt_offset
].eth
,
12900 BNX2X_ISCSI_ETH_CID(bp
));
12905 * There may be not more than 8 L2, not more than 8 L5 SPEs
12906 * and in the air. We also check that number of outstanding
12907 * COMMON ramrods is not more than the EQ and SPQ can
12910 if (type
== ETH_CONNECTION_TYPE
) {
12911 if (!atomic_read(&bp
->cq_spq_left
))
12914 atomic_dec(&bp
->cq_spq_left
);
12915 } else if (type
== NONE_CONNECTION_TYPE
) {
12916 if (!atomic_read(&bp
->eq_spq_left
))
12919 atomic_dec(&bp
->eq_spq_left
);
12920 } else if ((type
== ISCSI_CONNECTION_TYPE
) ||
12921 (type
== FCOE_CONNECTION_TYPE
)) {
12922 if (bp
->cnic_spq_pending
>=
12923 bp
->cnic_eth_dev
.max_kwqe_pending
)
12926 bp
->cnic_spq_pending
++;
12928 BNX2X_ERR("Unknown SPE type: %d\n", type
);
12933 spe
= bnx2x_sp_get_next(bp
);
12934 *spe
= *bp
->cnic_kwq_cons
;
12936 DP(BNX2X_MSG_SP
, "pending on SPQ %d, on KWQ %d count %d\n",
12937 bp
->cnic_spq_pending
, bp
->cnic_kwq_pending
, count
);
12939 if (bp
->cnic_kwq_cons
== bp
->cnic_kwq_last
)
12940 bp
->cnic_kwq_cons
= bp
->cnic_kwq
;
12942 bp
->cnic_kwq_cons
++;
12944 bnx2x_sp_prod_update(bp
);
12945 spin_unlock_bh(&bp
->spq_lock
);
12948 static int bnx2x_cnic_sp_queue(struct net_device
*dev
,
12949 struct kwqe_16
*kwqes
[], u32 count
)
12951 struct bnx2x
*bp
= netdev_priv(dev
);
12954 #ifdef BNX2X_STOP_ON_ERROR
12955 if (unlikely(bp
->panic
)) {
12956 BNX2X_ERR("Can't post to SP queue while panic\n");
12961 if ((bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) &&
12962 (bp
->recovery_state
!= BNX2X_RECOVERY_NIC_LOADING
)) {
12963 BNX2X_ERR("Handling parity error recovery. Try again later\n");
12967 spin_lock_bh(&bp
->spq_lock
);
12969 for (i
= 0; i
< count
; i
++) {
12970 struct eth_spe
*spe
= (struct eth_spe
*)kwqes
[i
];
12972 if (bp
->cnic_kwq_pending
== MAX_SP_DESC_CNT
)
12975 *bp
->cnic_kwq_prod
= *spe
;
12977 bp
->cnic_kwq_pending
++;
12979 DP(BNX2X_MSG_SP
, "L5 SPQE %x %x %x:%x pos %d\n",
12980 spe
->hdr
.conn_and_cmd_data
, spe
->hdr
.type
,
12981 spe
->data
.update_data_addr
.hi
,
12982 spe
->data
.update_data_addr
.lo
,
12983 bp
->cnic_kwq_pending
);
12985 if (bp
->cnic_kwq_prod
== bp
->cnic_kwq_last
)
12986 bp
->cnic_kwq_prod
= bp
->cnic_kwq
;
12988 bp
->cnic_kwq_prod
++;
12991 spin_unlock_bh(&bp
->spq_lock
);
12993 if (bp
->cnic_spq_pending
< bp
->cnic_eth_dev
.max_kwqe_pending
)
12994 bnx2x_cnic_sp_post(bp
, 0);
12999 static int bnx2x_cnic_ctl_send(struct bnx2x
*bp
, struct cnic_ctl_info
*ctl
)
13001 struct cnic_ops
*c_ops
;
13004 mutex_lock(&bp
->cnic_mutex
);
13005 c_ops
= rcu_dereference_protected(bp
->cnic_ops
,
13006 lockdep_is_held(&bp
->cnic_mutex
));
13008 rc
= c_ops
->cnic_ctl(bp
->cnic_data
, ctl
);
13009 mutex_unlock(&bp
->cnic_mutex
);
13014 static int bnx2x_cnic_ctl_send_bh(struct bnx2x
*bp
, struct cnic_ctl_info
*ctl
)
13016 struct cnic_ops
*c_ops
;
13020 c_ops
= rcu_dereference(bp
->cnic_ops
);
13022 rc
= c_ops
->cnic_ctl(bp
->cnic_data
, ctl
);
13029 * for commands that have no data
13031 int bnx2x_cnic_notify(struct bnx2x
*bp
, int cmd
)
13033 struct cnic_ctl_info ctl
= {0};
13037 return bnx2x_cnic_ctl_send(bp
, &ctl
);
13040 static void bnx2x_cnic_cfc_comp(struct bnx2x
*bp
, int cid
, u8 err
)
13042 struct cnic_ctl_info ctl
= {0};
13044 /* first we tell CNIC and only then we count this as a completion */
13045 ctl
.cmd
= CNIC_CTL_COMPLETION_CMD
;
13046 ctl
.data
.comp
.cid
= cid
;
13047 ctl
.data
.comp
.error
= err
;
13049 bnx2x_cnic_ctl_send_bh(bp
, &ctl
);
13050 bnx2x_cnic_sp_post(bp
, 0);
13054 /* Called with netif_addr_lock_bh() taken.
13055 * Sets an rx_mode config for an iSCSI ETH client.
13057 * Completion should be checked outside.
13059 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x
*bp
, bool start
)
13061 unsigned long accept_flags
= 0, ramrod_flags
= 0;
13062 u8 cl_id
= bnx2x_cnic_eth_cl_id(bp
, BNX2X_ISCSI_ETH_CL_ID_IDX
);
13063 int sched_state
= BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
;
13066 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13067 * because it's the only way for UIO Queue to accept
13068 * multicasts (in non-promiscuous mode only one Queue per
13069 * function will receive multicast packets (leading in our
13072 __set_bit(BNX2X_ACCEPT_UNICAST
, &accept_flags
);
13073 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &accept_flags
);
13074 __set_bit(BNX2X_ACCEPT_BROADCAST
, &accept_flags
);
13075 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, &accept_flags
);
13077 /* Clear STOP_PENDING bit if START is requested */
13078 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
, &bp
->sp_state
);
13080 sched_state
= BNX2X_FILTER_ISCSI_ETH_START_SCHED
;
13082 /* Clear START_PENDING bit if STOP is requested */
13083 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
, &bp
->sp_state
);
13085 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
))
13086 set_bit(sched_state
, &bp
->sp_state
);
13088 __set_bit(RAMROD_RX
, &ramrod_flags
);
13089 bnx2x_set_q_rx_mode(bp
, cl_id
, 0, accept_flags
, 0,
13095 static int bnx2x_drv_ctl(struct net_device
*dev
, struct drv_ctl_info
*ctl
)
13097 struct bnx2x
*bp
= netdev_priv(dev
);
13100 switch (ctl
->cmd
) {
13101 case DRV_CTL_CTXTBL_WR_CMD
: {
13102 u32 index
= ctl
->data
.io
.offset
;
13103 dma_addr_t addr
= ctl
->data
.io
.dma_addr
;
13105 bnx2x_ilt_wr(bp
, index
, addr
);
13109 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD
: {
13110 int count
= ctl
->data
.credit
.credit_count
;
13112 bnx2x_cnic_sp_post(bp
, count
);
13116 /* rtnl_lock is held. */
13117 case DRV_CTL_START_L2_CMD
: {
13118 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13119 unsigned long sp_bits
= 0;
13121 /* Configure the iSCSI classification object */
13122 bnx2x_init_mac_obj(bp
, &bp
->iscsi_l2_mac_obj
,
13123 cp
->iscsi_l2_client_id
,
13124 cp
->iscsi_l2_cid
, BP_FUNC(bp
),
13125 bnx2x_sp(bp
, mac_rdata
),
13126 bnx2x_sp_mapping(bp
, mac_rdata
),
13127 BNX2X_FILTER_MAC_PENDING
,
13128 &bp
->sp_state
, BNX2X_OBJ_TYPE_RX
,
13131 /* Set iSCSI MAC address */
13132 rc
= bnx2x_set_iscsi_eth_mac_addr(bp
);
13139 /* Start accepting on iSCSI L2 ring */
13141 netif_addr_lock_bh(dev
);
13142 bnx2x_set_iscsi_eth_rx_mode(bp
, true);
13143 netif_addr_unlock_bh(dev
);
13145 /* bits to wait on */
13146 __set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &sp_bits
);
13147 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
, &sp_bits
);
13149 if (!bnx2x_wait_sp_comp(bp
, sp_bits
))
13150 BNX2X_ERR("rx_mode completion timed out!\n");
13155 /* rtnl_lock is held. */
13156 case DRV_CTL_STOP_L2_CMD
: {
13157 unsigned long sp_bits
= 0;
13159 /* Stop accepting on iSCSI L2 ring */
13160 netif_addr_lock_bh(dev
);
13161 bnx2x_set_iscsi_eth_rx_mode(bp
, false);
13162 netif_addr_unlock_bh(dev
);
13164 /* bits to wait on */
13165 __set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &sp_bits
);
13166 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
, &sp_bits
);
13168 if (!bnx2x_wait_sp_comp(bp
, sp_bits
))
13169 BNX2X_ERR("rx_mode completion timed out!\n");
13174 /* Unset iSCSI L2 MAC */
13175 rc
= bnx2x_del_all_macs(bp
, &bp
->iscsi_l2_mac_obj
,
13176 BNX2X_ISCSI_ETH_MAC
, true);
13179 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD
: {
13180 int count
= ctl
->data
.credit
.credit_count
;
13182 smp_mb__before_atomic_inc();
13183 atomic_add(count
, &bp
->cq_spq_left
);
13184 smp_mb__after_atomic_inc();
13187 case DRV_CTL_ULP_REGISTER_CMD
: {
13188 int ulp_type
= ctl
->data
.register_data
.ulp_type
;
13190 if (CHIP_IS_E3(bp
)) {
13191 int idx
= BP_FW_MB_IDX(bp
);
13192 u32 cap
= SHMEM2_RD(bp
, drv_capabilities_flag
[idx
]);
13193 int path
= BP_PATH(bp
);
13194 int port
= BP_PORT(bp
);
13196 u32 scratch_offset
;
13199 /* first write capability to shmem2 */
13200 if (ulp_type
== CNIC_ULP_ISCSI
)
13201 cap
|= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI
;
13202 else if (ulp_type
== CNIC_ULP_FCOE
)
13203 cap
|= DRV_FLAGS_CAPABILITIES_LOADED_FCOE
;
13204 SHMEM2_WR(bp
, drv_capabilities_flag
[idx
], cap
);
13206 if ((ulp_type
!= CNIC_ULP_FCOE
) ||
13207 (!SHMEM2_HAS(bp
, ncsi_oem_data_addr
)) ||
13208 (!(bp
->flags
& BC_SUPPORTS_FCOE_FEATURES
)))
13211 /* if reached here - should write fcoe capabilities */
13212 scratch_offset
= SHMEM2_RD(bp
, ncsi_oem_data_addr
);
13213 if (!scratch_offset
)
13215 scratch_offset
+= offsetof(struct glob_ncsi_oem_data
,
13216 fcoe_features
[path
][port
]);
13217 host_addr
= (u32
*) &(ctl
->data
.register_data
.
13219 for (i
= 0; i
< sizeof(struct fcoe_capabilities
);
13221 REG_WR(bp
, scratch_offset
+ i
,
13222 *(host_addr
+ i
/4));
13227 case DRV_CTL_ULP_UNREGISTER_CMD
: {
13228 int ulp_type
= ctl
->data
.ulp_type
;
13230 if (CHIP_IS_E3(bp
)) {
13231 int idx
= BP_FW_MB_IDX(bp
);
13234 cap
= SHMEM2_RD(bp
, drv_capabilities_flag
[idx
]);
13235 if (ulp_type
== CNIC_ULP_ISCSI
)
13236 cap
&= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI
;
13237 else if (ulp_type
== CNIC_ULP_FCOE
)
13238 cap
&= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE
;
13239 SHMEM2_WR(bp
, drv_capabilities_flag
[idx
], cap
);
13245 BNX2X_ERR("unknown command %x\n", ctl
->cmd
);
13252 void bnx2x_setup_cnic_irq_info(struct bnx2x
*bp
)
13254 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13256 if (bp
->flags
& USING_MSIX_FLAG
) {
13257 cp
->drv_state
|= CNIC_DRV_STATE_USING_MSIX
;
13258 cp
->irq_arr
[0].irq_flags
|= CNIC_IRQ_FL_MSIX
;
13259 cp
->irq_arr
[0].vector
= bp
->msix_table
[1].vector
;
13261 cp
->drv_state
&= ~CNIC_DRV_STATE_USING_MSIX
;
13262 cp
->irq_arr
[0].irq_flags
&= ~CNIC_IRQ_FL_MSIX
;
13264 if (!CHIP_IS_E1x(bp
))
13265 cp
->irq_arr
[0].status_blk
= (void *)bp
->cnic_sb
.e2_sb
;
13267 cp
->irq_arr
[0].status_blk
= (void *)bp
->cnic_sb
.e1x_sb
;
13269 cp
->irq_arr
[0].status_blk_num
= bnx2x_cnic_fw_sb_id(bp
);
13270 cp
->irq_arr
[0].status_blk_num2
= bnx2x_cnic_igu_sb_id(bp
);
13271 cp
->irq_arr
[1].status_blk
= bp
->def_status_blk
;
13272 cp
->irq_arr
[1].status_blk_num
= DEF_SB_ID
;
13273 cp
->irq_arr
[1].status_blk_num2
= DEF_SB_IGU_ID
;
13278 void bnx2x_setup_cnic_info(struct bnx2x
*bp
)
13280 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13283 cp
->ctx_tbl_offset
= FUNC_ILT_BASE(BP_FUNC(bp
)) +
13284 bnx2x_cid_ilt_lines(bp
);
13285 cp
->starting_cid
= bnx2x_cid_ilt_lines(bp
) * ILT_PAGE_CIDS
;
13286 cp
->fcoe_init_cid
= BNX2X_FCOE_ETH_CID(bp
);
13287 cp
->iscsi_l2_cid
= BNX2X_ISCSI_ETH_CID(bp
);
13289 if (NO_ISCSI_OOO(bp
))
13290 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI_OOO
;
13293 static int bnx2x_register_cnic(struct net_device
*dev
, struct cnic_ops
*ops
,
13296 struct bnx2x
*bp
= netdev_priv(dev
);
13297 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13300 DP(NETIF_MSG_IFUP
, "Register_cnic called\n");
13303 BNX2X_ERR("NULL ops received\n");
13307 if (!CNIC_SUPPORT(bp
)) {
13308 BNX2X_ERR("Can't register CNIC when not supported\n");
13309 return -EOPNOTSUPP
;
13312 if (!CNIC_LOADED(bp
)) {
13313 rc
= bnx2x_load_cnic(bp
);
13315 BNX2X_ERR("CNIC-related load failed\n");
13321 bp
->cnic_enabled
= true;
13323 bp
->cnic_kwq
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
13327 bp
->cnic_kwq_cons
= bp
->cnic_kwq
;
13328 bp
->cnic_kwq_prod
= bp
->cnic_kwq
;
13329 bp
->cnic_kwq_last
= bp
->cnic_kwq
+ MAX_SP_DESC_CNT
;
13331 bp
->cnic_spq_pending
= 0;
13332 bp
->cnic_kwq_pending
= 0;
13334 bp
->cnic_data
= data
;
13337 cp
->drv_state
|= CNIC_DRV_STATE_REGD
;
13338 cp
->iro_arr
= bp
->iro_arr
;
13340 bnx2x_setup_cnic_irq_info(bp
);
13342 rcu_assign_pointer(bp
->cnic_ops
, ops
);
13347 static int bnx2x_unregister_cnic(struct net_device
*dev
)
13349 struct bnx2x
*bp
= netdev_priv(dev
);
13350 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13352 mutex_lock(&bp
->cnic_mutex
);
13354 RCU_INIT_POINTER(bp
->cnic_ops
, NULL
);
13355 mutex_unlock(&bp
->cnic_mutex
);
13357 kfree(bp
->cnic_kwq
);
13358 bp
->cnic_kwq
= NULL
;
13363 struct cnic_eth_dev
*bnx2x_cnic_probe(struct net_device
*dev
)
13365 struct bnx2x
*bp
= netdev_priv(dev
);
13366 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13368 /* If both iSCSI and FCoE are disabled - return NULL in
13369 * order to indicate CNIC that it should not try to work
13370 * with this device.
13372 if (NO_ISCSI(bp
) && NO_FCOE(bp
))
13375 cp
->drv_owner
= THIS_MODULE
;
13376 cp
->chip_id
= CHIP_ID(bp
);
13377 cp
->pdev
= bp
->pdev
;
13378 cp
->io_base
= bp
->regview
;
13379 cp
->io_base2
= bp
->doorbells
;
13380 cp
->max_kwqe_pending
= 8;
13381 cp
->ctx_blk_size
= CDU_ILT_PAGE_SZ
;
13382 cp
->ctx_tbl_offset
= FUNC_ILT_BASE(BP_FUNC(bp
)) +
13383 bnx2x_cid_ilt_lines(bp
);
13384 cp
->ctx_tbl_len
= CNIC_ILT_LINES
;
13385 cp
->starting_cid
= bnx2x_cid_ilt_lines(bp
) * ILT_PAGE_CIDS
;
13386 cp
->drv_submit_kwqes_16
= bnx2x_cnic_sp_queue
;
13387 cp
->drv_ctl
= bnx2x_drv_ctl
;
13388 cp
->drv_register_cnic
= bnx2x_register_cnic
;
13389 cp
->drv_unregister_cnic
= bnx2x_unregister_cnic
;
13390 cp
->fcoe_init_cid
= BNX2X_FCOE_ETH_CID(bp
);
13391 cp
->iscsi_l2_client_id
=
13392 bnx2x_cnic_eth_cl_id(bp
, BNX2X_ISCSI_ETH_CL_ID_IDX
);
13393 cp
->iscsi_l2_cid
= BNX2X_ISCSI_ETH_CID(bp
);
13395 if (NO_ISCSI_OOO(bp
))
13396 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI_OOO
;
13399 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI
;
13402 cp
->drv_state
|= CNIC_DRV_STATE_NO_FCOE
;
13405 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
13407 cp
->ctx_tbl_offset
,
13413 u32
bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath
*fp
)
13415 struct bnx2x
*bp
= fp
->bp
;
13416 u32 offset
= BAR_USTRORM_INTMEM
;
13419 return bnx2x_vf_ustorm_prods_offset(bp
, fp
);
13420 else if (!CHIP_IS_E1x(bp
))
13421 offset
+= USTORM_RX_PRODS_E2_OFFSET(fp
->cl_qzone_id
);
13423 offset
+= USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp
), fp
->cl_id
);
13428 /* called only on E1H or E2.
13429 * When pretending to be PF, the pretend value is the function number 0...7
13430 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13433 int bnx2x_pretend_func(struct bnx2x
*bp
, u16 pretend_func_val
)
13437 if (CHIP_IS_E1H(bp
) && pretend_func_val
>= E1H_FUNC_MAX
)
13440 /* get my own pretend register */
13441 pretend_reg
= bnx2x_get_pretend_reg(bp
);
13442 REG_WR(bp
, pretend_reg
, pretend_func_val
);
13443 REG_RD(bp
, pretend_reg
);